12 #include "slurpclose.h"
13 #include "auto_qmail.h"
14 #include "auto_uids.h"
19 void initialize(argc
,argv
)
24 if (!aliasempty
) _exit(100);
27 int truncreport
= 3000;
29 void report(ss
,wstat
,s
,len
)
36 if (wait_crashed(wstat
))
37 { substdio_puts(ss
,"Zqmail-local crashed.\n"); return; }
38 switch(wait_exitcode(wstat
))
41 substdio_puts(ss
,"ZTrouble reading users/cdb in qmail-lspawn.\n"); return;
43 substdio_puts(ss
,"ZOut of memory in qmail-lspawn.\n"); return;
45 substdio_puts(ss
,"ZTemporary failure in qmail-lspawn.\n"); return;
47 substdio_puts(ss
,"ZUnable to find alias user!\n"); return;
49 substdio_puts(ss
,"ZNot allowed to perform deliveries as root.\n"); return;
51 substdio_puts(ss
,"ZInternal qmail-lspawn bug.\n"); return;
53 substdio_puts(ss
,"ZNFS failure in qmail-local.\n"); return;
55 substdio_puts(ss
,"DUnable to run qmail-local.\n"); return;
57 substdio_puts(ss
,"ZUnable to run qmail-local.\n"); return;
59 substdio_puts(ss
,"ZUnable to run qmail-getpw.\n"); return;
60 case 111: case 71: case 74: case 75:
61 substdio_put(ss
,"Z",1); break;
63 substdio_put(ss
,"K",1); break;
66 substdio_put(ss
,"D",1); break;
69 for (i
= 0;i
< len
;++i
) if (!s
[i
]) break;
74 stralloc nughde
= {0};
75 stralloc wildchars
= {0};
77 void nughde_get(local
)
88 if (!stralloc_copys(&lower
,"!")) _exit(QLX_NOMEM
);
89 if (!stralloc_cats(&lower
,local
)) _exit(QLX_NOMEM
);
90 if (!stralloc_0(&lower
)) _exit(QLX_NOMEM
);
91 case_lowerb(lower
.s
,lower
.len
);
93 if (!stralloc_copys(&nughde
,"")) _exit(QLX_NOMEM
);
95 fd
= open_read("users/cdb");
97 if (errno
!= error_noent
)
105 r
= cdb_seek(fd
,"",0,&dlen
);
106 if (r
!= 1) _exit(QLX_CDB
);
107 if (!stralloc_ready(&wildchars
,(unsigned int) dlen
)) _exit(QLX_NOMEM
);
108 wildchars
.len
= dlen
;
109 if (cdb_bread(fd
,wildchars
.s
,wildchars
.len
) == -1) _exit(QLX_CDB
);
117 if (!flagwild
|| (i
== 1) || (byte_chr(wildchars
.s
,wildchars
.len
,lower
.s
[i
- 1]) < wildchars
.len
))
119 r
= cdb_seek(fd
,lower
.s
,i
,&dlen
);
120 if (r
== -1) _exit(QLX_CDB
);
123 if (!stralloc_ready(&nughde
,(unsigned int) dlen
)) _exit(QLX_NOMEM
);
125 if (cdb_bread(fd
,nughde
.s
,nughde
.len
) == -1) _exit(QLX_CDB
);
127 if (!stralloc_cats(&nughde
,local
+ i
- 1)) _exit(QLX_NOMEM
);
128 if (!stralloc_0(&nughde
)) _exit(QLX_NOMEM
);
141 if (pipe(pi
) == -1) _exit(QLX_SYS
);
142 args
[0] = "/usr/sbin/qmail-getpw";
145 switch(gpwpid
= vfork())
150 if (prot_gid(auto_gidn
) == -1) _exit(QLX_USAGE
);
151 if (prot_uid(auto_uidp
) == -1) _exit(QLX_USAGE
);
153 if (fd_move(1,pi
[1]) == -1) _exit(QLX_SYS
);
159 if (slurpclose(pi
[0],&nughde
,128) == -1) _exit(QLX_SYS
);
161 if (wait_pid(&gpwstat
,gpwpid
) != -1)
163 if (wait_crashed(gpwstat
)) _exit(QLX_SYS
);
164 if (wait_exitcode(gpwstat
) != 0) _exit(wait_exitcode(gpwstat
));
168 int spawn(fdmess
,fdout
,s
,r
,at
)
169 int fdmess
; int fdout
;
170 char *s
; char *r
; int at
;
185 if (!r
[0]) _exit(0); /* <> */
187 if (chdir(auto_qmail
) == -1) _exit(QLX_USAGE
);
194 args
[0] = "/usr/sbin/qmail-local";
197 n
= byte_chr(x
,xlen
,0); if (n
++ == xlen
) _exit(QLX_USAGE
); x
+= n
; xlen
-= n
;
201 n
= byte_chr(x
,xlen
,0); if (n
++ == xlen
) _exit(QLX_USAGE
); x
+= n
; xlen
-= n
;
205 n
= byte_chr(x
,xlen
,0); if (n
++ == xlen
) _exit(QLX_USAGE
); x
+= n
; xlen
-= n
;
208 n
= byte_chr(x
,xlen
,0); if (n
++ == xlen
) _exit(QLX_USAGE
); x
+= n
; xlen
-= n
;
212 n
= byte_chr(x
,xlen
,0); if (n
++ == xlen
) _exit(QLX_USAGE
); x
+= n
; xlen
-= n
;
215 n
= byte_chr(x
,xlen
,0); if (n
++ == xlen
) _exit(QLX_USAGE
); x
+= n
; xlen
-= n
;
217 args
[7] = r
+ at
+ 1;
219 args
[9] = aliasempty
;
222 if (fd_move(0,fdmess
) == -1) _exit(QLX_SYS
);
223 if (fd_move(1,fdout
) == -1) _exit(QLX_SYS
);
224 if (fd_copy(2,1) == -1) _exit(QLX_SYS
);
225 if (prot_gid(gid
) == -1) _exit(QLX_USAGE
);
226 if (prot_uid(uid
) == -1) _exit(QLX_USAGE
);
227 if (!getuid()) _exit(QLX_ROOT
);
230 if (error_temp(errno
)) _exit(QLX_EXECSOFT
);