Download | Plain Text | No Line Numbers


  1. we want to support authentification with aliases but still need to know the real
  2. username. checkpassword will write us the real user back on fd4. we need to read
  3. that and update the smtp auth username accordingly
  4. --- qmail-smtpd.c.orig 2009-01-31 01:43:01.000000000 +0100
  5. +++ qmail-smtpd.c 2010-10-05 14:10:54.000000000 +0200
  6. @@ -859,7 +859,9 @@
  7.  
  8. char **childargs;
  9. char ssauthbuf[512];
  10. +char ssauth2buf[512];
  11. substdio ssauth = SUBSTDIO_FDBUF(safewrite,3,ssauthbuf,sizeof(ssauthbuf));
  12. +substdio ssauth2 = SUBSTDIO_FDBUF(saferead,4,ssauth2buf,sizeof(ssauth2buf));
  13.  
  14. int authgetl(void) {
  15. int i;
  16. @@ -885,6 +887,9 @@
  17. int child;
  18. int wstat;
  19. int pi[2];
  20. + int piauth[2], i, len;
  21. + char *arg;
  22. + static stralloc authout = {0}, authparams = {0};
  23.  
  24. if (!stralloc_0(&user)) die_nomem();
  25. if (!stralloc_0(&pass)) die_nomem();
  26. @@ -893,19 +898,24 @@
  27. #endif
  28.  
  29. if (pipe(pi) == -1) return err_pipe();
  30. + if (pipe(piauth) == -1) return err_pipe();
  31. switch(child = fork()) {
  32. case -1:
  33. return err_fork();
  34. case 0:
  35. close(pi[1]);
  36. + close(piauth[0]);
  37. if(fd_copy(3,pi[0]) == -1) return err_pipe();
  38. + if(fd_copy(4,piauth[1]) == -1) return err_pipe();
  39. sig_pipedefault();
  40. execvp(*childargs, childargs);
  41. _exit(1);
  42. }
  43. close(pi[0]);
  44. + close(piauth[1]);
  45.  
  46. substdio_fdbuf(&ssauth,write,pi[1],ssauthbuf,sizeof ssauthbuf);
  47. + substdio_fdbuf(&ssauth2,read,piauth[0],ssauth2buf,sizeof ssauth2buf);
  48. if (substdio_put(&ssauth,user.s,user.len) == -1) return err_write();
  49. if (substdio_put(&ssauth,pass.s,pass.len) == -1) return err_write();
  50. #ifdef CRAM_MD5
  51. @@ -914,11 +924,43 @@
  52. if (substdio_flush(&ssauth) == -1) return err_write();
  53.  
  54. close(pi[1]);
  55. +
  56. + if (!stralloc_copys(&authout, "")) die_nomem();
  57. + for (;;) {
  58. + if (!stralloc_readyplus(&authout, 1)) die_nomem();
  59. + i = substdio_get(&ssauth2, authout.s + authout.len, 1);
  60. + if (i == 0) break;
  61. + ++authout.len;
  62. + }
  63. + authout.s[authout.len] = 0;
  64. + if (substdio_flush(&ssauth2) == -1) return err_write();
  65. + close(piauth[0]);
  66. +
  67. + if (authout.len > 0) {
  68. + len = authout.len;
  69. + arg = authout.s;
  70. + if (!stralloc_copys(&authparams, "")) die_nomem;
  71. + while (len) {
  72. + if (*arg == '\0') {
  73. + if (case_starts(authparams.s, "USER=") && (authparams.len - 5) > 0) {
  74. + if (!stralloc_copyb(&user, authparams.s + 5, authparams.len - 5)) die_nomem();
  75. + if (!stralloc_0(&user)) die_nomem();
  76. + }
  77. + if (!stralloc_copys(&authparams, "")) die_nomem;
  78. + }
  79. + else
  80. + if (!stralloc_catb(&authparams, arg, 1)) die_nomem;
  81. + arg++;
  82. + len--;
  83. + }
  84. + }
  85. +
  86. #ifdef CRAM_MD5
  87. if (!stralloc_copys(&chal,"")) die_nomem();
  88. if (!stralloc_copys(&slop,"")) die_nomem();
  89. #endif
  90. byte_zero(ssauthbuf,sizeof ssauthbuf);
  91. + byte_zero(ssauth2buf,sizeof ssauth2buf);
  92. if (wait_pid(&wstat,child) == -1) return err_child();
  93. if (wait_crashed(wstat)) return err_child();
  94. if (wait_exitcode(wstat)) { sleep(AUTHSLEEP); return 1; } /* no */
  95.