commit de6a762737e86ae714b38d5323b9d5c9237f9a8b
parent 2f552835c907eee2db06cda5a6b7cfe09cb319ee
Author: Alan Post <adp@prgmr.com>
Date: Tue, 9 Jul 2019 14:58:38 -0600
split install in to instpackage, instchown.
Introduce a new phony target, package, that runs instpackage.
Unlike the setup target, which runs install, this target will
ignore the qmail system accounts and install all files and
directories as the current (i.e., non-root) user.
It is intended to be run on a build host, which may not have
the qmail system accounts, for the purpose of packaging a
release.
instchown sets the user, group, and mode of the files and
directories in a qmail install. Along with instpackage, it
splits the install program in to the part run on the build host
(instpackage) and the part run on the install host (instchown).
Diffstat:
M | CHANGES | | | 2 | ++ |
M | Makefile | | | 49 | +++++++++++++++++++++++++++++++++---------------- |
M | TARGETS | | | 5 | ++++- |
D | install.c | | | 230 | ------------------------------------------------------------------------------- |
A | instchown.c | | | 92 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | instpackage.c | | | 227 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 files changed, 358 insertions(+), 247 deletions(-)
diff --git a/CHANGES b/CHANGES
@@ -1,3 +1,5 @@
+20190710 code: add instchown to set ownership and mode on installed files.
+20190709 code: add instpackage to install without root access.
20190714 code: removed idedit, install-big. var-qmail packages are no more.
20190708 code: lookup uid/gid at runtime.
20190711 portability problem: explicitly initialize strerr_sys and
diff --git a/Makefile b/Makefile
@@ -779,20 +779,9 @@ hostname.o: \
compile hostname.c substdio.h subfd.h substdio.h readwrite.h exit.h
./compile hostname.c
-install: \
-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.o: \
-compile install.c substdio.h strerr.h env.h error.h fifo.h open.h \
-readwrite.h exit.h alloc.h str.h stralloc.h
- ./compile install.c
+install:
+ echo './instpackage && ./instchown' > install
+ chmod 755 install
instcheck: \
load instcheck.o instuidgid.o fifo.o hier.o auto_qmail.o auto_split.o uid.o \
@@ -807,6 +796,29 @@ instcheck.o: \
compile instcheck.c strerr.h error.h readwrite.h exit.h
./compile instcheck.c
+instchown: \
+load instchown.o instuidgid.o fifo.o hier.o auto_qmail.o auto_split.o uid.o \
+gid.o auto_usera.o auto_usero.o auto_userq.o auto_userr.o auto_users.o \
+auto_groupq.o strerr.a substdio.a error.a str.a fs.a
+ ./load instchown instuidgid.o fifo.o hier.o auto_qmail.o auto_split.o \
+ uid.o gid.o auto_usera.o auto_usero.o auto_userq.o auto_userr.o \
+ auto_users.o auto_groupq.o strerr.a substdio.a error.a str.a fs.a
+
+instchown.o: \
+compile instchown.c strerr.h error.h exit.h
+ ./compile instchown.c
+
+instpackage: \
+load instpackage.o fifo.o hier.o auto_qmail.o auto_split.o strerr.a \
+substdio.a open.a error.a env.a str.a fs.a stralloc.a alloc.a
+ ./load instpackage fifo.o hier.o auto_qmail.o auto_split.o \
+ strerr.a substdio.a open.a error.a env.a str.a fs.a stralloc.a alloc.a
+
+instpackage.o: \
+compile instpackage.c substdio.h strerr.h env.h error.h fifo.h open.h \
+readwrite.h exit.h alloc.h str.h stralloc.h
+ ./compile instpackage.c
+
instuidgid.o: \
compile instuidgid.c uidgid.h auto_uids.h auto_users.h
./compile instuidgid.c
@@ -845,7 +857,7 @@ qmail-pop3d qmail-popup qmail-qmqpc qmail-qmqpd qmail-qmtpd \
qmail-smtpd sendmail tcp-env qmail-newmrh config config-fast dnscname \
dnsptr dnsip dnsmxip dnsfq hostname ipmeprint qreceipt qsmhook qbiff \
forward preline condredirect bouncesaying except maildirmake \
-maildir2mbox maildirwatch qail elq pinq install \
+maildir2mbox maildirwatch qail elq pinq install instpackage instchown \
instcheck home home+df proc proc+df binm1 binm1+df binm2 binm2+df \
binm3 binm3+df
@@ -1031,6 +1043,10 @@ open_write.o: \
compile open_write.c open.h
./compile open_write.c
+package: \
+it man
+ ./instpackage
+
pinq: \
warn-auto.sh pinq.sh conf-qmail conf-break conf-split
cat warn-auto.sh pinq.sh \
@@ -1797,7 +1813,8 @@ substdio.h alloc.h auto_qmail.h exit.h env.h str.h
setup: \
it man
- ./install
+ ./instpackage
+ ./instchown
sgetopt.o: \
compile sgetopt.c substdio.h subfd.h substdio.h sgetopt.h subgetopt.h \
diff --git a/TARGETS b/TARGETS
@@ -325,11 +325,14 @@ maildirwatch
qail
elq
pinq
-install.o
hier.o
install
instcheck.o
instcheck
+instchown.o
+instchown
+instpackage.o
+instpackage
instuidgid.o
home
home+df
diff --git a/install.c b/install.c
@@ -1,230 +0,0 @@
-#include "substdio.h"
-#include "strerr.h"
-#include "env.h"
-#include "error.h"
-#include "fifo.h"
-#include "open.h"
-#include "readwrite.h"
-#include "exit.h"
-#include "alloc.h"
-#include "str.h"
-#include "stralloc.h"
-
-extern void init_uidgid();
-extern void hier();
-
-#define FATAL "install: fatal: "
-
-int fdsourcedir = -1;
-
-static void die_nomem()
-{
- strerr_die2sys(111,FATAL,"out of memory");
-}
-
-static void ddhome(dd,home)
-stralloc *dd;
-char *home;
-{
- const char *denv = env_get("DESTDIR");
- if (denv)
- if (!stralloc_copys(dd,denv)) die_nomem();
-
- if (!stralloc_catb(dd,home,str_len(home))) die_nomem();
- if (!stralloc_0(dd)) die_nomem();
-}
-
-static int mkdir_p(home,mode)
-char *home;
-int mode;
-{
- stralloc parent = { 0 };
- unsigned int sl;
- int r = mkdir(home,mode);
- if (!r || errno != error_noent)
- return r;
-
- /* try parent first */
- sl = str_rchr(home, '/');
- if (!stralloc_copyb(&parent,home,sl)) die_nomem();
- if (!stralloc_0(&parent)) die_nomem();
- r = mkdir_p(parent.s,mode);
- alloc_free(parent.s);
- if (r && errno != error_exist)
- return r;
-
- return mkdir(home,mode);
-}
-
-void h(home,uid,gid,mode)
-char *home;
-int uid;
-int gid;
-int mode;
-{
- stralloc dh = { 0 };
- ddhome(&dh, home);
- home=dh.s;
- if (mkdir_p(home,mode) == -1)
- if (errno != error_exist)
- strerr_die4sys(111,FATAL,"unable to mkdir ",home,": ");
- if (chown(home,uid,gid) == -1)
- strerr_die4sys(111,FATAL,"unable to chown ",home,": ");
- if (chmod(home,mode) == -1)
- strerr_die4sys(111,FATAL,"unable to chmod ",home,": ");
- alloc_free(dh.s);
-}
-
-void d(home,subdir,uid,gid,mode)
-char *home;
-char *subdir;
-int uid;
-int gid;
-int mode;
-{
- stralloc dh = { 0 };
- ddhome(&dh, home);
- home=dh.s;
- if (chdir(home) == -1)
- strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
- if (mkdir(subdir,0700) == -1)
- if (errno != error_exist)
- strerr_die6sys(111,FATAL,"unable to mkdir ",home,"/",subdir,": ");
- if (chown(subdir,uid,gid) == -1)
- strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": ");
- if (chmod(subdir,mode) == -1)
- strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": ");
- alloc_free(dh.s);
-}
-
-void p(home,fifo,uid,gid,mode)
-char *home;
-char *fifo;
-int uid;
-int gid;
-int mode;
-{
- stralloc dh = { 0 };
- ddhome(&dh, home);
- home=dh.s;
- if (chdir(home) == -1)
- strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
- if (fifo_make(fifo,0700) == -1)
- if (errno != error_exist)
- strerr_die6sys(111,FATAL,"unable to mkfifo ",home,"/",fifo,": ");
- if (chown(fifo,uid,gid) == -1)
- strerr_die6sys(111,FATAL,"unable to chown ",home,"/",fifo,": ");
- if (chmod(fifo,mode) == -1)
- strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",fifo,": ");
- alloc_free(dh.s);
-}
-
-char inbuf[SUBSTDIO_INSIZE];
-char outbuf[SUBSTDIO_OUTSIZE];
-substdio ssin;
-substdio ssout;
-
-void c(home,subdir,file,uid,gid,mode)
-char *home;
-char *subdir;
-char *file;
-int uid;
-int gid;
-int mode;
-{
- int fdin;
- int fdout;
- stralloc dh = { 0 };
-
- ddhome(&dh, home);
- home=dh.s;
- if (fchdir(fdsourcedir) == -1)
- strerr_die2sys(111,FATAL,"unable to switch back to source directory: ");
-
- fdin = open_read(file);
- if (fdin == -1)
- strerr_die4sys(111,FATAL,"unable to read ",file,": ");
- substdio_fdbuf(&ssin,read,fdin,inbuf,sizeof inbuf);
-
- if (chdir(home) == -1)
- strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
- if (chdir(subdir) == -1)
- strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": ");
-
- fdout = open_trunc(file);
- if (fdout == -1)
- strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
- substdio_fdbuf(&ssout,write,fdout,outbuf,sizeof outbuf);
-
- switch(substdio_copy(&ssout,&ssin)) {
- case -2:
- strerr_die4sys(111,FATAL,"unable to read ",file,": ");
- case -3:
- strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
- }
-
- close(fdin);
- if (substdio_flush(&ssout) == -1)
- strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
- if (fsync(fdout) == -1)
- strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
- if (close(fdout) == -1) /* NFS silliness */
- strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
-
- if (chown(file,uid,gid) == -1)
- strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": ");
- if (chmod(file,mode) == -1)
- strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": ");
- alloc_free(dh.s);
-}
-
-void z(home,file,len,uid,gid,mode)
-char *home;
-char *file;
-int len;
-int uid;
-int gid;
-int mode;
-{
- int fdout;
- stralloc dh = { 0 };
-
- ddhome(&dh, home);
- home=dh.s;
- if (chdir(home) == -1)
- strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
-
- fdout = open_trunc(file);
- if (fdout == -1)
- strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
- substdio_fdbuf(&ssout,write,fdout,outbuf,sizeof outbuf);
-
- while (len-- > 0)
- if (substdio_put(&ssout,"",1) == -1)
- strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
-
- if (substdio_flush(&ssout) == -1)
- strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
- if (fsync(fdout) == -1)
- strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
- if (close(fdout) == -1) /* NFS silliness */
- strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
-
- if (chown(file,uid,gid) == -1)
- strerr_die6sys(111,FATAL,"unable to chown ",home,"/",file,": ");
- if (chmod(file,mode) == -1)
- strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",file,": ");
- alloc_free(dh.s);
-}
-
-void main()
-{
- fdsourcedir = open_read(".");
- if (fdsourcedir == -1)
- strerr_die2sys(111,FATAL,"unable to open current directory: ");
-
- umask(077);
- init_uidgid();
- hier();
- _exit(0);
-}
diff --git a/instchown.c b/instchown.c
@@ -0,0 +1,92 @@
+#include "strerr.h"
+#include "error.h"
+#include "exit.h"
+
+extern void init_uidgid();
+extern void hier();
+
+#define FATAL "instchown: fatal: "
+
+void h(home,uid,gid,mode)
+char *home;
+int uid;
+int gid;
+int mode;
+{
+ if (chown(home,uid,gid) == -1)
+ strerr_die4sys(111,FATAL,"unable to chown ",home,": ");
+ if (chmod(home,mode) == -1)
+ strerr_die4sys(111,FATAL,"unable to chmod ",home,": ");
+}
+
+void d(home,subdir,uid,gid,mode)
+char *home;
+char *subdir;
+int uid;
+int gid;
+int mode;
+{
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+ if (chown(subdir,uid,gid) == -1)
+ strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": ");
+ if (chmod(subdir,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": ");
+}
+
+void p(home,fifo,uid,gid,mode)
+char *home;
+char *fifo;
+int uid;
+int gid;
+int mode;
+{
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+ if (chown(fifo,uid,gid) == -1)
+ strerr_die6sys(111,FATAL,"unable to chown ",home,"/",fifo,": ");
+ if (chmod(fifo,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",fifo,": ");
+}
+
+void c(home,subdir,file,uid,gid,mode)
+char *home;
+char *subdir;
+char *file;
+int uid;
+int gid;
+int mode;
+{
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+ if (chdir(subdir) == -1)
+ strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": ");
+ if (chown(file,uid,gid) == -1)
+ strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": ");
+ if (chmod(file,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": ");
+}
+
+void z(home,file,len,uid,gid,mode)
+char *home;
+char *file;
+int len;
+int uid;
+int gid;
+int mode;
+{
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+ if (chown(file,uid,gid) == -1)
+ strerr_die6sys(111,FATAL,"unable to chown ",home,"/",file,": ");
+ if (chmod(file,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",file,": ");
+}
+
+void main()
+{
+ umask(077);
+ init_uidgid();
+ hier();
+ _exit(0);
+}
diff --git a/instpackage.c b/instpackage.c
@@ -0,0 +1,227 @@
+#include "substdio.h"
+#include "strerr.h"
+#include "env.h"
+#include "error.h"
+#include "fifo.h"
+#include "open.h"
+#include "readwrite.h"
+#include "exit.h"
+#include "alloc.h"
+#include "str.h"
+#include "stralloc.h"
+
+extern void hier();
+
+#define FATAL "instpackage: fatal: "
+
+int fdsourcedir = -1;
+
+static void die_nomem()
+{
+ strerr_die2sys(111,FATAL,"out of memory");
+}
+
+static void ddhome(dd,home)
+stralloc *dd;
+char *home;
+{
+ const char *denv = env_get("DESTDIR");
+ if (denv)
+ if (!stralloc_copys(dd,denv)) die_nomem();
+
+ if (!stralloc_catb(dd,home,str_len(home))) die_nomem();
+ if (!stralloc_0(dd)) die_nomem();
+}
+
+static int mkdir_p(home,mode)
+char *home;
+int mode;
+{
+ stralloc parent = { 0 };
+ unsigned int sl;
+ int r = mkdir(home,mode);
+ if (!r || errno != error_noent)
+ return r;
+
+ /* try parent first */
+ sl = str_rchr(home, '/');
+ if (!stralloc_copyb(&parent,home,sl)) die_nomem();
+ if (!stralloc_0(&parent)) die_nomem();
+ r = mkdir_p(parent.s,mode);
+ alloc_free(parent.s);
+ if (r && errno != error_exist)
+ return r;
+
+ return mkdir(home,mode);
+}
+
+void h(home,uid,gid,mode)
+char *home;
+int uid;
+int gid;
+int mode;
+{
+ stralloc dh = { 0 };
+ ddhome(&dh, home);
+ home=dh.s;
+ if (mkdir_p(home,mode) == -1)
+ if (errno != error_exist)
+ strerr_die4sys(111,FATAL,"unable to mkdir ",home,": ");
+ if (chmod(home,mode) == -1)
+ strerr_die4sys(111,FATAL,"unable to chmod ",home,": ");
+ alloc_free(dh.s);
+}
+
+void d(home,subdir,uid,gid,mode)
+char *home;
+char *subdir;
+int uid;
+int gid;
+int mode;
+{
+ stralloc dh = { 0 };
+ ddhome(&dh, home);
+ home=dh.s;
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+ if (mkdir(subdir,0700) == -1)
+ if (errno != error_exist)
+ strerr_die6sys(111,FATAL,"unable to mkdir ",home,"/",subdir,": ");
+ if (chmod(subdir,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": ");
+ alloc_free(dh.s);
+}
+
+void p(home,fifo,uid,gid,mode)
+char *home;
+char *fifo;
+int uid;
+int gid;
+int mode;
+{
+ stralloc dh = { 0 };
+ ddhome(&dh, home);
+ home=dh.s;
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+ if (fifo_make(fifo,0700) == -1)
+ if (errno != error_exist)
+ strerr_die6sys(111,FATAL,"unable to mkfifo ",home,"/",fifo,": ");
+ if (chmod(fifo,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",fifo,": ");
+ alloc_free(dh.s);
+}
+
+char inbuf[SUBSTDIO_INSIZE];
+char outbuf[SUBSTDIO_OUTSIZE];
+substdio ssin;
+substdio ssout;
+
+void c(home,subdir,file,uid,gid,mode)
+char *home;
+char *subdir;
+char *file;
+int uid;
+int gid;
+int mode;
+{
+ int fdin;
+ int fdout;
+ stralloc dh = { 0 };
+
+ ddhome(&dh, home);
+ home=dh.s;
+ if (fchdir(fdsourcedir) == -1)
+ strerr_die2sys(111,FATAL,"unable to switch back to source directory: ");
+
+ fdin = open_read(file);
+ if (fdin == -1)
+ strerr_die4sys(111,FATAL,"unable to read ",file,": ");
+ substdio_fdbuf(&ssin,read,fdin,inbuf,sizeof inbuf);
+
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+ if (chdir(subdir) == -1)
+ strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": ");
+
+ fdout = open_trunc(file);
+ if (fdout == -1)
+ strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
+ substdio_fdbuf(&ssout,write,fdout,outbuf,sizeof outbuf);
+
+ switch(substdio_copy(&ssout,&ssin)) {
+ case -2:
+ strerr_die4sys(111,FATAL,"unable to read ",file,": ");
+ case -3:
+ strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
+ }
+
+ close(fdin);
+ if (substdio_flush(&ssout) == -1)
+ strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
+ if (fsync(fdout) == -1)
+ strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
+ if (close(fdout) == -1) /* NFS silliness */
+ strerr_die6sys(111,FATAL,"unable to write .../",subdir,"/",file,": ");
+
+ if (chmod(file,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": ");
+ alloc_free(dh.s);
+}
+
+void z(home,file,len,uid,gid,mode)
+char *home;
+char *file;
+int len;
+int uid;
+int gid;
+int mode;
+{
+ int fdout;
+ stralloc dh = { 0 };
+
+ ddhome(&dh, home);
+ home=dh.s;
+ if (chdir(home) == -1)
+ strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
+
+ fdout = open_trunc(file);
+ if (fdout == -1)
+ strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
+ substdio_fdbuf(&ssout,write,fdout,outbuf,sizeof outbuf);
+
+ while (len-- > 0)
+ if (substdio_put(&ssout,"",1) == -1)
+ strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
+
+ if (substdio_flush(&ssout) == -1)
+ strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
+ if (fsync(fdout) == -1)
+ strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
+ if (close(fdout) == -1) /* NFS silliness */
+ strerr_die6sys(111,FATAL,"unable to write ",home,"/",file,": ");
+
+ if (chmod(file,mode) == -1)
+ strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",file,": ");
+ alloc_free(dh.s);
+}
+
+/* these are ignored, but hier() passes them to h() and friends */
+int auto_uida = -1;
+int auto_uido = -1;
+int auto_uidq = -1;
+int auto_uidr = -1;
+int auto_uids = -1;
+
+int auto_gidq = -1;
+
+void main()
+{
+ fdsourcedir = open_read(".");
+ if (fdsourcedir == -1)
+ strerr_die2sys(111,FATAL,"unable to open current directory: ");
+
+ umask(077);
+ hier();
+ _exit(0);
+}