X-Git-Url: https://git.distorted.org.uk/~mdw/qmail/blobdiff_plain/2117e02ec495fdfd6e96b39778b701a5bcff8aa5..212b6f5da7c68d4577de2855da3c57ecf476dc96:/instcheck.c diff --git a/instcheck.c b/instcheck.c index 48db531..d41efda 100644 --- a/instcheck.c +++ b/instcheck.c @@ -1,120 +1,108 @@ #include #include -#include "substdio.h" -#include "stralloc.h" -#include "getln.h" +#include "strerr.h" +#include "error.h" #include "readwrite.h" #include "exit.h" -#include "error.h" -#include "strerr.h" -#include "byte.h" -stralloc target = {0}; -char *to; +extern void hier(); -#define WARNING "instcheck: warning: " #define FATAL "instcheck: fatal: " -void nomem() { strerr_die2x(111,FATAL,"out of memory"); } +#define WARNING "instcheck: warning: " -void doit(line) -stralloc *line; +void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode) +char *prefix1; +char *prefix2; +char *prefix3; +char *file; +int type; +int uid; +int gid; +int mode; { struct stat st; - char *x; - unsigned int xlen; - unsigned int i; - char *type; - char *uidstr; - char *gidstr; - char *modestr; - char *mid; - char *name; - unsigned long uid; - unsigned long gid; - unsigned long mode; - int ftype; - - x = line->s; xlen = line->len; - - type = x; - i = byte_chr(x,xlen,':'); if (i == xlen) return; - x[i++] = 0; x += i; xlen -= i; - - uidstr = x; - i = byte_chr(x,xlen,':'); if (i == xlen) return; - x[i++] = 0; x += i; xlen -= i; - - gidstr = x; - i = byte_chr(x,xlen,':'); if (i == xlen) return; - x[i++] = 0; x += i; xlen -= i; - - modestr = x; - i = byte_chr(x,xlen,':'); if (i == xlen) return; - x[i++] = 0; x += i; xlen -= i; - - mid = x; - i = byte_chr(x,xlen,':'); if (i == xlen) return; - x[i++] = 0; x += i; xlen -= i; - - name = x; - i = byte_chr(x,xlen,':'); if (i == xlen) return; - x[i++] = 0; x += i; xlen -= i; - - if (!stralloc_copys(&target,to)) nomem(); - if (!stralloc_cats(&target,mid)) nomem(); - if (!stralloc_cats(&target,name)) nomem(); - if (!stralloc_0(&target)) nomem(); - - uid = -1; if (*uidstr) scan_ulong(uidstr,&uid); - gid = -1; if (*gidstr) scan_ulong(gidstr,&gid); - scan_8long(modestr,&mode); - switch(*type) { - case 'd': ftype = S_IFDIR; break; - case 'c': ftype = S_IFREG; break; - case 'z': ftype = S_IFREG; break; - case 'p': ftype = S_IFIFO; break; - default: return; - } - - if (stat(target.s,&st) == -1) { + if (stat(file,&st) == -1) { if (errno == error_noent) - strerr_warn3(WARNING,target.s," does not exist",0); + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," does not exist",0); else - strerr_warn4(WARNING,"unable to stat ",target.s,": ",&strerr_sys); + strerr_warn4(WARNING,"unable to stat .../",file,": ",&strerr_sys); return; } if ((uid != -1) && (st.st_uid != uid)) - strerr_warn3(WARNING,target.s," has wrong owner",0); + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong owner",0); if ((gid != -1) && (st.st_gid != gid)) - strerr_warn3(WARNING,target.s," has wrong group",0); + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong group",0); if ((st.st_mode & 07777) != mode) - strerr_warn3(WARNING,target.s," has wrong permissions",0); - if ((st.st_mode & S_IFMT) != ftype) - strerr_warn3(WARNING,target.s," has wrong type",0); + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong permissions",0); + if ((st.st_mode & S_IFMT) != type) + strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong type",0); } -char buf[256]; -substdio in = SUBSTDIO_FDBUF(read,0,buf,sizeof(buf)); -stralloc line = {0}; +void h(home,uid,gid,mode) +char *home; +int uid; +int gid; +int mode; +{ + perm("","","",home,S_IFDIR,uid,gid,mode); +} + +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,": "); + perm("",home,"/",subdir,S_IFDIR,uid,gid,mode); +} -void main(argc,argv) -int argc; -char **argv; +void p(home,fifo,uid,gid,mode) +char *home; +char *fifo; +int uid; +int gid; +int mode; { - int match; + if (chdir(home) == -1) + strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); + perm("",home,"/",fifo,S_IFIFO,uid,gid,mode); +} - umask(077); +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,": "); + perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode); +} - to = argv[1]; - if (!to) strerr_die2x(100,FATAL,"instcheck: usage: instcheck dir"); +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,": "); + perm("",home,"/",file,S_IFREG,uid,gid,mode); +} - for (;;) { - if (getln(&in,&line,&match,'\n') == -1) - strerr_die2sys(111,FATAL,"unable to read input: "); - doit(&line); - if (!match) - _exit(0); - } +void main() +{ + hier(); + _exit(0); }