nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 580bf26e8a211fdff3ad3083e5e771662a921e3a
parent 1fabc9dcfa3e670875895d60fd5432318cb0e5ff
Author: Alan Post <adp@prgmr.com>
Date:   Tue,  9 Jul 2019 02:47:39 +0000

detect qmail system uid/gid at runtime.

rename and extend auto_usera.h to auto_users.h and include all system
accounts, not just the alias user.

Instead of looking up the uid/gid of each account in conf-users at
build time, record their names in the same manner as the alias user.

remove auto-gid.c and auto-uid.c, replacing them with runtime
equivalent gid.c and uid.c.  Look up the uid and gid values in or
about the main function of the five qmail programs that use user
or group ids, and the installer.

Link substdio.a in to qmail-start, as runtime error messages are
produced when an account cannot be found.

This allows qmail to be built on a host that does not have user and
group system accounts.

Diffstat:
MCHANGES | 1+
MMakefile | 213+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
MTARGETS | 35++++++++++++++++++++++++++++++-----
Dauto-gid.c | 51---------------------------------------------------
Dauto-uid.c | 51---------------------------------------------------
Dauto_usera.h | 6------
Aauto_users.h | 16++++++++++++++++
Agid.c | 22++++++++++++++++++++++
Minstall.c | 2++
Minstcheck.c | 2++
Ainstuidgid.c | 23+++++++++++++++++++++++
Mqmail-getpw.c | 2+-
Mqmail-lspawn.c | 12++++++++++++
Mqmail-pw2u.c | 2+-
Mqmail-queue.c | 10++++++++++
Mqmail-rspawn.c | 6++++++
Mqmail-showctl.c | 26++++++++++++++++++++++++++
Mqmail-start.c | 19+++++++++++++++++++
Auid.c | 22++++++++++++++++++++++
Auidgid.h | 7+++++++
20 files changed, 343 insertions(+), 185 deletions(-)

diff --git a/CHANGES b/CHANGES @@ -1,3 +1,4 @@ +20190708 code: lookup uid/gid at runtime. 20190711 portability problem: explicitly initialize strerr_sys and define BIND_8_COMPAT to work around Mac OS X. 20190709 doc: rename INSTALL, SENDMAIL to INSTALL.md, SENDMAIL.md to diff --git a/Makefile b/Makefile @@ -29,15 +29,6 @@ conf-cc conf-ld warn-auto.sh echo LD=\'`head -1 conf-ld`\' \ ) > auto-ccld.sh -auto-gid: \ -load auto-gid.o substdio.a error.a str.a fs.a - ./load auto-gid substdio.a error.a str.a fs.a - -auto-gid.o: \ -compile auto-gid.c subfd.h substdio.h substdio.h readwrite.h exit.h \ -scan.h fmt.h - ./compile auto-gid.c - auto-int: \ load auto-int.o substdio.a error.a str.a fs.a ./load auto-int substdio.a error.a str.a fs.a @@ -112,24 +103,6 @@ auto_split.o: \ compile auto_split.c ./compile auto_split.c -auto_uids.c: \ -auto-uid auto-gid conf-users conf-groups - ( ./auto-uid auto_uida `head -1 conf-users` \ - &&./auto-uid auto_uidd `head -2 conf-users | tail -1` \ - &&./auto-uid auto_uidl `head -3 conf-users | tail -1` \ - &&./auto-uid auto_uido `head -4 conf-users | tail -1` \ - &&./auto-uid auto_uidp `head -5 conf-users | tail -1` \ - &&./auto-uid auto_uidq `head -6 conf-users | tail -1` \ - &&./auto-uid auto_uidr `head -7 conf-users | tail -1` \ - &&./auto-uid auto_uids `head -8 conf-users | tail -1` \ - &&./auto-gid auto_gidq `head -1 conf-groups` \ - &&./auto-gid auto_gidn `head -2 conf-groups | tail -1` \ - ) > auto_uids.c.tmp && mv auto_uids.c.tmp auto_uids.c - -auto_uids.o: \ -compile auto_uids.c - ./compile auto_uids.c - auto_usera.c: \ auto-str conf-users ./auto-str auto_usera `head -1 conf-users` > auto_usera.c @@ -138,6 +111,78 @@ auto_usera.o: \ compile auto_usera.c ./compile auto_usera.c +auto_userd.c: \ +auto-str conf-users + ./auto-str auto_userd `head -2 conf-users | tail -1` > auto_userd.c + +auto_userd.o: \ +compile auto_userd.c + ./compile auto_userd.c + +auto_userl.c: \ +auto-str conf-users + ./auto-str auto_userl `head -3 conf-users | tail -1` > auto_userl.c + +auto_userl.o: \ +compile auto_userl.c + ./compile auto_userl.c + +auto_usero.c: \ +auto-str conf-users + ./auto-str auto_usero `head -4 conf-users | tail -1` > auto_usero.c + +auto_usero.o: \ +compile auto_usero.c + ./compile auto_usero.c + +auto_userp.c: \ +auto-str conf-users + ./auto-str auto_userp `head -5 conf-users | tail -1` > auto_userp.c + +auto_userp.o: \ +compile auto_userp.c + ./compile auto_userp.c + +auto_userq.c: \ +auto-str conf-users + ./auto-str auto_userq `head -6 conf-users | tail -1` > auto_userq.c + +auto_userq.o: \ +compile auto_userq.c + ./compile auto_userq.c + +auto_userr.c: \ +auto-str conf-users + ./auto-str auto_userr `head -7 conf-users | tail -1` > auto_userr.c + +auto_userr.o: \ +compile auto_userr.c + ./compile auto_userr.c + +auto_users.c: \ +auto-str conf-users + ./auto-str auto_users `head -8 conf-users | tail -1` > auto_users.c + +auto_users.o: \ +compile auto_users.c + ./compile auto_users.c + +auto_groupn.c: \ +auto-str conf-groups + ./auto-str auto_groupn `head -2 conf-groups | tail -1` > auto_groupn.c + +auto_groupn.o: \ +compile auto_groupn.c + ./compile auto_groupn.c + +auto_groupq.c: \ +auto-str conf-groups + ./auto-str auto_groupq `head -1 conf-groups` > auto_groupq.c + +auto_groupq.o: \ +compile auto_groupq.c + ./compile auto_groupq.c + binm1: \ binm1.sh conf-qmail cat binm1.sh \ @@ -635,6 +680,10 @@ gfrom.o: \ compile gfrom.c str.h gfrom.h ./compile gfrom.c +gid.o: \ +compile gid.c uidgid.h subfd.h substdio.h exit.h + ./compile gid.c + hasflock.h: \ tryflock.c compile load ( ( ./compile tryflock.c && ./load tryflock ) >/dev/null \ @@ -742,19 +791,24 @@ seek.h fork.h ./compile idedit.c install: \ -load install.o fifo.o hier.o auto_qmail.o auto_split.o auto_uids.o \ -strerr.a substdio.a open.a error.a env.a str.a fs.a stralloc.a alloc.a - ./load install fifo.o hier.o auto_qmail.o auto_split.o \ - auto_uids.o strerr.a substdio.a open.a error.a env.a str.a fs.a \ - stralloc.a alloc.a +load install.o instuidgid.o fifo.o hier.o auto_qmail.o auto_split.o uid.o \ +gid.o auto_usera.o auto_usero.o auto_userp.o auto_userq.o auto_userr.o \ +auto_users.o auto_groupq.o strerr.a substdio.a open.a error.a env.a \ +str.a fs.a stralloc.a alloc.a + ./load install instuidgid.o fifo.o hier.o auto_qmail.o auto_split.o \ + uid.o gid.o auto_usera.o auto_usero.o auto_userp.o auto_userq.o \ + auto_userr.o auto_users.o auto_groupq.o strerr.a substdio.a open.a \ + error.a env.a str.a fs.a stralloc.a alloc.a install-big: \ -load install-big.o fifo.o install.o auto_qmail.o auto_split.o \ -auto_uids.o strerr.a substdio.a open.a error.a env.a str.a fs.a stralloc.a \ -alloc.a - ./load install-big fifo.o install.o auto_qmail.o \ - auto_split.o auto_uids.o strerr.a substdio.a open.a error.a \ - env.a str.a fs.a stralloc.a alloc.a +load install-big.o fifo.o install.o instuidgid.o auto_qmail.o auto_split.o \ +uid.o gid.o auto_usera.o auto_usero.o auto_userp.o auto_userq.o auto_userr.o \ +auto_users.o auto_groupq.o strerr.a substdio.a open.a error.a env.a str.a fs.a \ +stralloc.a alloc.a + ./load install-big instuidgid.o fifo.o install.o auto_qmail.o \ + auto_split.o uid.o gid.o auto_usera.o auto_usero.o auto_userp.o \ + auto_userq.o auto_userr.o auto_users.o auto_groupq.o strerr.a \ + substdio.a open.a error.a env.a str.a fs.a stralloc.a alloc.a install-big.o: \ compile install-big.c auto_qmail.h auto_split.h auto_uids.h fmt.h \ @@ -767,15 +821,22 @@ readwrite.h exit.h alloc.h str.h stralloc.h ./compile install.c instcheck: \ -load instcheck.o fifo.o hier.o auto_qmail.o auto_split.o auto_uids.o \ -strerr.a substdio.a error.a str.a fs.a - ./load instcheck fifo.o hier.o auto_qmail.o auto_split.o \ - auto_uids.o strerr.a substdio.a error.a str.a fs.a +load instcheck.o instuidgid.o fifo.o hier.o auto_qmail.o auto_split.o uid.o \ +gid.o auto_usera.o auto_usero.o auto_userp.o auto_userq.o auto_userr.o \ +auto_users.o auto_groupq.o strerr.a substdio.a error.a str.a fs.a + ./load instcheck instuidgid.o fifo.o hier.o auto_qmail.o auto_split.o \ + uid.o gid.o auto_usera.o auto_usero.o auto_userp.o auto_userq.o \ + auto_userr.o auto_users.o auto_groupq.o strerr.a substdio.a error.a \ + str.a fs.a instcheck.o: \ compile instcheck.c strerr.h error.h readwrite.h exit.h ./compile instcheck.c +instuidgid.o: \ +compile instuidgid.c uidgid.h auto_uids.h auto_users.h + ./compile instuidgid.c + ip.o: \ compile ip.c fmt.h scan.h ip.h ./compile ip.c @@ -1131,7 +1192,7 @@ qmail-getpw.9 conf-break conf-spawn qmail-getpw.o: \ compile qmail-getpw.c readwrite.h substdio.h subfd.h substdio.h \ -error.h exit.h byte.h str.h case.h fmt.h auto_usera.h auto_break.h \ +error.h exit.h byte.h str.h case.h fmt.h auto_users.h auto_break.h \ qlx.h ./compile qmail-getpw.c @@ -1204,11 +1265,12 @@ qmail-log.5 qmail-lspawn: \ load qmail-lspawn.o spawn.o prot.o slurpclose.o coe.o sig.a wait.a \ case.a cdb.a fd.a open.a stralloc.a alloc.a substdio.a error.a str.a \ -fs.a auto_qmail.o auto_uids.o auto_spawn.o - ./load qmail-lspawn spawn.o prot.o slurpclose.o coe.o \ - sig.a wait.a case.a cdb.a fd.a open.a stralloc.a alloc.a \ - substdio.a error.a str.a fs.a auto_qmail.o auto_uids.o \ - auto_spawn.o +fs.a auto_qmail.o uid.o gid.o auto_userp.o auto_userq.o auto_groupn.o \ +auto_spawn.o + ./load qmail-lspawn spawn.o prot.o slurpclose.o coe.o sig.a wait.a \ + case.a cdb.a fd.a open.a stralloc.a alloc.a auto_qmail.o uid.o gid.o \ + auto_userp.o auto_userq.o auto_groupn.o auto_spawn.o substdio.a \ + error.a str.a fs.a qmail-lspawn.0: \ qmail-lspawn.8 @@ -1217,7 +1279,8 @@ qmail-lspawn.8 qmail-lspawn.o: \ compile qmail-lspawn.c fd.h wait.h prot.h substdio.h stralloc.h \ gen_alloc.h scan.h exit.h fork.h error.h cdb.h uint32.h case.h \ -slurpclose.h auto_qmail.h auto_uids.h qlx.h byte.h open.h +slurpclose.h uidgid.h auto_qmail.h auto_uids.h auto_users.h qlx.h byte.h \ +open.h ./compile qmail-lspawn.c qmail-newmrh: \ @@ -1332,7 +1395,7 @@ qmail-pw2u.o: \ compile qmail-pw2u.c substdio.h readwrite.h subfd.h substdio.h \ sgetopt.h subgetopt.h control.h constmap.h stralloc.h gen_alloc.h \ fmt.h str.h scan.h open.h error.h getln.h auto_break.h auto_qmail.h \ -auto_usera.h +auto_users.h ./compile qmail-pw2u.c qmail-qmqpc: \ @@ -1425,11 +1488,12 @@ qmail-qstat.8 qmail-queue: \ load qmail-queue.o triggerpull.o fmtqfn.o now.o date822fmt.o \ datetime.a seek.a ndelay.a open.a sig.a alloc.a substdio.a error.a \ -str.a fs.a auto_qmail.o auto_split.o auto_uids.o +str.a fs.a auto_qmail.o auto_split.o uid.o auto_usera.o auto_userd.o \ +auto_users.o ./load qmail-queue triggerpull.o fmtqfn.o now.o \ date822fmt.o datetime.a seek.a ndelay.a open.a sig.a \ - alloc.a substdio.a error.a str.a fs.a auto_qmail.o \ - auto_split.o auto_uids.o + alloc.a auto_qmail.o auto_split.o uid.o auto_usera.o \ + auto_userd.o auto_users.o substdio.a error.a str.a fs.a qmail-queue.0: \ qmail-queue.8 @@ -1438,7 +1502,7 @@ qmail-queue.8 qmail-queue.o: \ compile qmail-queue.c readwrite.h sig.h exit.h open.h seek.h fmt.h \ alloc.h substdio.h datetime.h now.h datetime.h triggerpull.h extra.h \ -auto_qmail.h auto_uids.h date822fmt.h fmtqfn.h +uidgid.h auto_qmail.h auto_uids.h auto_users.h date822fmt.h fmtqfn.h ./compile qmail-queue.c qmail-remote: \ @@ -1467,11 +1531,11 @@ tcpto.h readwrite.h timeoutconn.h timeoutread.h timeoutwrite.h qmail-rspawn: \ load qmail-rspawn.o spawn.o tcpto_clean.o now.o coe.o sig.a open.a \ seek.a lock.a wait.a fd.a stralloc.a alloc.a substdio.a error.a str.a \ -auto_qmail.o auto_uids.o auto_spawn.o +auto_qmail.o uid.o auto_userq.o auto_spawn.o ./load qmail-rspawn spawn.o tcpto_clean.o now.o coe.o \ sig.a open.a seek.a lock.a wait.a fd.a stralloc.a alloc.a \ - substdio.a error.a str.a auto_qmail.o auto_uids.o \ - auto_spawn.o + auto_qmail.o uid.o auto_userq.o substdio.a error.a str.a \ + auto_spawn.o qmail-rspawn.0: \ qmail-rspawn.8 @@ -1516,13 +1580,15 @@ fmtqfn.h readsubdir.h direntry.h ./compile qmail-send.c qmail-showctl: \ -load qmail-showctl.o auto_uids.o control.o open.a getln.a stralloc.a \ -alloc.a substdio.a error.a str.a fs.a auto_qmail.o auto_break.o \ -auto_patrn.o auto_spawn.o auto_split.o - ./load qmail-showctl auto_uids.o control.o open.a getln.a \ - stralloc.a alloc.a substdio.a error.a str.a fs.a \ - auto_qmail.o auto_break.o auto_patrn.o auto_spawn.o \ - auto_split.o +load qmail-showctl.o uid.o gid.o auto_usera.o auto_userd.o auto_userl.o \ +auto_usero.o auto_userp.o auto_userq.o auto_userr.o auto_users.o auto_groupn.o \ +auto_groupq.o control.o open.a getln.a stralloc.a alloc.a substdio.a error.a \ +str.a fs.a auto_qmail.o auto_break.o auto_patrn.o auto_spawn.o auto_split.o + ./load qmail-showctl uid.o gid.o auto_usera.o auto_userd.o \ + auto_userl.o auto_usero.o auto_userp.o auto_userq.o auto_userr.o \ + auto_users.o auto_groupn.o auto_groupq.o control.o open.a getln.a \ + stralloc.a alloc.a substdio.a error.a str.a fs.a auto_qmail.o \ + auto_break.o auto_patrn.o auto_spawn.o auto_split.o qmail-showctl.0: \ qmail-showctl.8 @@ -1530,9 +1596,9 @@ qmail-showctl.8 qmail-showctl.o: \ compile qmail-showctl.c substdio.h subfd.h substdio.h exit.h fmt.h \ -str.h control.h constmap.h stralloc.h gen_alloc.h direntry.h \ -auto_uids.h auto_qmail.h auto_break.h auto_patrn.h auto_spawn.h \ -auto_split.h +str.h control.h constmap.h stralloc.h gen_alloc.h direntry.h uidgid.h \ +auto_uids.h auto_users.h auto_qmail.h auto_break.h auto_patrn.h \ +auto_spawn.h auto_split.h ./compile qmail-showctl.c qmail-smtpd: \ @@ -1561,8 +1627,11 @@ exit.h rcpthosts.h timeoutread.h timeoutwrite.h commands.h ./compile qmail-smtpd.c qmail-start: \ -load qmail-start.o prot.o fd.a auto_uids.o - ./load qmail-start prot.o fd.a auto_uids.o +load qmail-start.o prot.o fd.a uid.o gid.o auto_userl.o auto_userq.o \ +auto_userr.o auto_users.o auto_groupn.o auto_groupq.o substdio.a error.a str.a + ./load qmail-start prot.o fd.a uid.o gid.o auto_userl.o auto_userq.o \ + auto_userr.o auto_users.o auto_groupn.o auto_groupq.o substdio.a \ + error.a str.a qmail-start.0: \ qmail-start.8 @@ -1577,7 +1646,7 @@ qmail-start.9 conf-break conf-spawn > qmail-start.8 qmail-start.o: \ -compile qmail-start.c fd.h prot.h exit.h fork.h auto_uids.h +compile qmail-start.c fd.h prot.h exit.h fork.h uidgid.h auto_uids.h auto_users.h ./compile qmail-start.c qmail-tcpok: \ @@ -2051,6 +2120,10 @@ triggerpull.o: \ compile triggerpull.c ndelay.h open.h triggerpull.h ./compile triggerpull.c +uid.o: \ +compile uid.c uidgid.h subfd.h substdio.h exit.h + ./compile uid.c + uint32.h: \ tryulong32.c compile load uint32.h1 uint32.h2 ( ( ./compile tryulong32.c && ./load tryulong32 && \ diff --git a/TARGETS b/TARGETS @@ -150,18 +150,42 @@ cdb_hash.o cdb_unpack.o cdb_seek.o cdb.a -auto-uid.o -auto-uid -auto-gid.o -auto-gid -auto_uids.c +uid.o +gid.o +auto_uida.o +auto_uidd.o +auto_uidl.o +auto_uido.o +auto_uidp.o +auto_uidq.o +auto_uidr.o auto_uids.o +auto_gidn.o +auto_gidq.o qmail-lspawn qmail-getpw.o auto_break.c auto_break.o auto_usera.c auto_usera.o +auto_userd.c +auto_userd.o +auto_userl.c +auto_userl.o +auto_usero.c +auto_usero.o +auto_userp.c +auto_userp.o +auto_userq.c +auto_userq.o +auto_userr.c +auto_userr.o +auto_users.c +auto_users.o +auto_groupn.c +auto_groupn.o +auto_groupq.c +auto_groupq.o qmail-getpw qmail-remote.o control.o @@ -310,6 +334,7 @@ hier.o install instcheck.o instcheck +instuidgid.o home home+df proc diff --git a/auto-gid.c b/auto-gid.c @@ -1,51 +0,0 @@ -#include <sys/types.h> -#include <grp.h> -#include "subfd.h" -#include "substdio.h" -#include "readwrite.h" -#include "exit.h" -#include "scan.h" -#include "fmt.h" - -char buf1[256]; -substdio ss1 = SUBSTDIO_FDBUF(write,1,buf1,sizeof(buf1)); - -void outs(s) -char *s; -{ - if (substdio_puts(&ss1,s) == -1) _exit(111); -} - -void main(argc,argv) -int argc; -char **argv; -{ - char *name; - char *value; - struct group *gr; - char strnum[FMT_ULONG]; - - name = argv[1]; - if (!name) _exit(100); - value = argv[2]; - if (!value) _exit(100); - - gr = getgrnam(value); - if (!gr) { - substdio_puts(subfderr,"fatal: unable to find group "); - substdio_puts(subfderr,value); - substdio_puts(subfderr,"\n"); - substdio_flush(subfderr); - _exit(111); - } - - strnum[fmt_ulong(strnum,(unsigned long) gr->gr_gid)] = 0; - - outs("int "); - outs(name); - outs(" = "); - outs(strnum); - outs(";\n"); - if (substdio_flush(&ss1) == -1) _exit(111); - _exit(0); -} diff --git a/auto-uid.c b/auto-uid.c @@ -1,51 +0,0 @@ -#include <sys/types.h> -#include <pwd.h> -#include "subfd.h" -#include "substdio.h" -#include "readwrite.h" -#include "exit.h" -#include "scan.h" -#include "fmt.h" - -char buf1[256]; -substdio ss1 = SUBSTDIO_FDBUF(write,1,buf1,sizeof(buf1)); - -void outs(s) /* was named puts, but Solaris pwd.h includes stdio.h. dorks. */ -char *s; -{ - if (substdio_puts(&ss1,s) == -1) _exit(111); -} - -void main(argc,argv) -int argc; -char **argv; -{ - char *name; - char *value; - struct passwd *pw; - char strnum[FMT_ULONG]; - - name = argv[1]; - if (!name) _exit(100); - value = argv[2]; - if (!value) _exit(100); - - pw = getpwnam(value); - if (!pw) { - substdio_puts(subfderr,"fatal: unable to find user "); - substdio_puts(subfderr,value); - substdio_puts(subfderr,"\n"); - substdio_flush(subfderr); - _exit(111); - } - - strnum[fmt_ulong(strnum,(unsigned long) pw->pw_uid)] = 0; - - outs("int "); - outs(name); - outs(" = "); - outs(strnum); - outs(";\n"); - if (substdio_flush(&ss1) == -1) _exit(111); - _exit(0); -} diff --git a/auto_usera.h b/auto_usera.h @@ -1,6 +0,0 @@ -#ifndef AUTO_USERA_H -#define AUTO_USERA_H - -extern char auto_usera[]; - -#endif diff --git a/auto_users.h b/auto_users.h @@ -0,0 +1,16 @@ +#ifndef AUTO_USERS_H +#define AUTO_USERS_H + +extern char auto_usera[]; +extern char auto_userd[]; +extern char auto_userl[]; +extern char auto_usero[]; +extern char auto_userp[]; +extern char auto_userq[]; +extern char auto_userr[]; +extern char auto_users[]; + +extern char auto_groupn[]; +extern char auto_groupq[]; + +#endif diff --git a/gid.c b/gid.c @@ -0,0 +1,22 @@ +#include <sys/types.h> +#include <grp.h> +#include "uidgid.h" +#include "subfd.h" +#include "substdio.h" +#include "exit.h" + +int +initgid(group) + char *group; +{ + struct group *gr; + gr = getgrnam(group); + if (!gr) { + substdio_puts(subfderr,"fatal: unable to find group "); + substdio_puts(subfderr,group); + substdio_puts(subfderr,"\n"); + substdio_flush(subfderr); + _exit(111); + } + return gr->gr_gid; +} diff --git a/install.c b/install.c @@ -10,6 +10,7 @@ #include "str.h" #include "stralloc.h" +extern void init_uidgid(); extern void hier(); #define FATAL "install: fatal: " @@ -223,6 +224,7 @@ void main() strerr_die2sys(111,FATAL,"unable to open current directory: "); umask(077); + init_uidgid(); hier(); _exit(0); } diff --git a/instcheck.c b/instcheck.c @@ -5,6 +5,7 @@ #include "readwrite.h" #include "exit.h" +extern void init_uidgid(); extern void hier(); #define FATAL "instcheck: fatal: " @@ -103,6 +104,7 @@ int mode; void main() { + init_uidgid(); hier(); _exit(0); } diff --git a/instuidgid.c b/instuidgid.c @@ -0,0 +1,23 @@ +#include "uidgid.h" +#include "auto_uids.h" +#include "auto_users.h" + +int auto_uida; +int auto_uido; +int auto_uidq; +int auto_uidr; +int auto_uids; + +int auto_gidq; + +void +init_uidgid() +{ + auto_uida = inituid(auto_usera); + auto_uido = inituid(auto_usero); + auto_uidq = inituid(auto_userq); + auto_uidr = inituid(auto_userr); + auto_uids = inituid(auto_users); + + auto_gidq = initgid(auto_groupq); +} diff --git a/qmail-getpw.c b/qmail-getpw.c @@ -10,7 +10,7 @@ #include "str.h" #include "case.h" #include "fmt.h" -#include "auto_usera.h" +#include "auto_users.h" #include "auto_break.h" #include "qlx.h" diff --git a/qmail-lspawn.c b/qmail-lspawn.c @@ -12,18 +12,30 @@ #include "case.h" #include "open.h" #include "slurpclose.h" +#include "uidgid.h" #include "auto_qmail.h" #include "auto_uids.h" +#include "auto_users.h" #include "qlx.h" char *aliasempty; +int auto_uidp; +int auto_uidq; + +int auto_gidn; + void initialize(argc,argv) int argc; char **argv; { aliasempty = argv[1]; if (!aliasempty) _exit(100); + + auto_uidp = inituid(auto_userp); + auto_uidq = inituid(auto_userq); + + auto_gidn = initgid(auto_groupn); } int truncreport = 3000; diff --git a/qmail-pw2u.c b/qmail-pw2u.c @@ -15,7 +15,7 @@ #include "getln.h" #include "auto_break.h" #include "auto_qmail.h" -#include "auto_usera.h" +#include "auto_users.h" void die_chdir() { diff --git a/qmail-queue.c b/qmail-queue.c @@ -12,8 +12,10 @@ #include "now.h" #include "triggerpull.h" #include "extra.h" +#include "uidgid.h" #include "auto_qmail.h" #include "auto_uids.h" +#include "auto_users.h" #include "date822fmt.h" #include "fmtqfn.h" @@ -40,6 +42,10 @@ int intdfd; int flagmademess = 0; int flagmadeintd = 0; +int auto_uida; +int auto_uidd; +int auto_uids; + void cleanup() { if (flagmadeintd) @@ -166,6 +172,10 @@ void main() starttime = now(); datetime_tai(&dt,starttime); + auto_uida = inituid(auto_usera); + auto_uidd = inituid(auto_userd); + auto_uids = inituid(auto_users); + received_setup(); sig_pipeignore(); diff --git a/qmail-rspawn.c b/qmail-rspawn.c @@ -5,11 +5,17 @@ #include "fork.h" #include "error.h" #include "tcpto.h" +#include "uidgid.h" +#include "auto_uids.h" +#include "auto_users.h" + +int auto_uidq; void initialize(argc,argv) int argc; char **argv; { + auto_uidq = inituid(auto_userq); tcpto_clean(); } diff --git a/qmail-showctl.c b/qmail-showctl.c @@ -9,7 +9,9 @@ #include "constmap.h" #include "stralloc.h" #include "direntry.h" +#include "uidgid.h" #include "auto_uids.h" +#include "auto_users.h" #include "auto_qmail.h" #include "auto_break.h" #include "auto_patrn.h" @@ -22,6 +24,18 @@ int meok; stralloc line = {0}; char num[FMT_ULONG]; +int auto_uida; +int auto_uidd; +int auto_uidl; +int auto_uido; +int auto_uidp; +int auto_uidq; +int auto_uidr; +int auto_uids; + +int auto_gidn; +int auto_gidq; + void safeput(buf,len) char *buf; unsigned int len; @@ -143,6 +157,18 @@ void main() struct stat stmrh; struct stat stmrhcdb; + auto_uida = inituid(auto_usera); + auto_uidd = inituid(auto_userd); + auto_uidl = inituid(auto_userl); + auto_uido = inituid(auto_usero); + auto_uidp = inituid(auto_userp); + auto_uidq = inituid(auto_userq); + auto_uidr = inituid(auto_userr); + auto_uids = inituid(auto_users); + + auto_gidn = initgid(auto_groupn); + auto_gidq = initgid(auto_groupq); + substdio_puts(subfdout,"qmail home directory: "); substdio_puts(subfdout,auto_qmail); substdio_puts(subfdout,".\n"); diff --git a/qmail-start.c b/qmail-start.c @@ -2,7 +2,9 @@ #include "prot.h" #include "exit.h" #include "fork.h" +#include "uidgid.h" #include "auto_uids.h" +#include "auto_users.h" char *(qsargs[]) = { "qmail-send", 0 }; char *(qcargs[]) = { "qmail-clean", 0 }; @@ -19,6 +21,14 @@ int pi4[2]; int pi5[2]; int pi6[2]; +int auto_uidl; +int auto_uidq; +int auto_uidr; +int auto_uids; + +int auto_gidn; +int auto_gidq; + void close23456() { close(2); close(3); close(4); close(5); close(6); } void closepipes() { @@ -33,6 +43,15 @@ char **argv; { if (chdir("/") == -1) die(); umask(077); + + auto_uidl = inituid(auto_userl); + auto_uidq = inituid(auto_userq); + auto_uidr = inituid(auto_userr); + auto_uids = inituid(auto_users); + + auto_gidn = initgid(auto_groupn); + auto_gidq = initgid(auto_groupq); + if (prot_gid(auto_gidq) == -1) die(); if (fd_copy(2,0) == -1) die(); diff --git a/uid.c b/uid.c @@ -0,0 +1,22 @@ +#include <sys/types.h> +#include <pwd.h> +#include "uidgid.h" +#include "subfd.h" +#include "substdio.h" +#include "exit.h" + +int +inituid(user) + char *user; +{ + struct passwd *pw; + pw = getpwnam(user); + if (!pw) { + substdio_puts(subfderr,"fatal: unable to find user "); + substdio_puts(subfderr,user); + substdio_puts(subfderr,"\n"); + substdio_flush(subfderr); + _exit(111); + } + return pw->pw_uid; +} diff --git a/uidgid.h b/uidgid.h @@ -0,0 +1,7 @@ +#ifndef UIDGID_H +#define UIDGID_H + +extern int inituid(); +extern int initgid(); + +#endif