nightmaremail

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

instcheck.c (2512B)


      1 #include <sys/types.h>
      2 #include <sys/stat.h>
      3 #include <string.h>
      4 #include "strerr.h"
      5 #include "error.h"
      6 #include "readwrite.h"
      7 #include "hier.h"
      8 
      9 extern void init_uidgid();
     10 
     11 #define FATAL "instcheck: fatal: "
     12 #define WARNING "instcheck: warning: "
     13 
     14 void perm(char *prefix1, char *prefix2, char *prefix3, char *file, int type,
     15           uid_t uid, gid_t gid, int mode)
     16 {
     17   struct stat st;
     18 
     19   if (stat(file,&st) == -1) {
     20     if (errno == error_noent) {
     21       /* assume cat man pages are simply not installed */
     22       if (strncmp(prefix2, "man/cat", 7) != 0 && strncmp(file, "man/cat", 7) != 0)
     23         strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," does not exist",0);
     24     } else
     25       strerr_warn4(WARNING,"unable to stat .../",file,": ",&strerr_sys);
     26     return;
     27   }
     28 
     29   if ((uid != -1) && (st.st_uid != uid))
     30     strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong owner",0);
     31   if ((gid != -1) && (st.st_gid != gid))
     32     strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong group",0);
     33   if ((st.st_mode & 07777) != mode)
     34     strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong permissions",0);
     35   if ((st.st_mode & S_IFMT) != type)
     36     strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong type",0);
     37 }
     38 
     39 void h(char *home, uid_t uid, gid_t gid, int mode)
     40 {
     41   perm("","","",home,S_IFDIR,uid,gid,mode);
     42 }
     43 
     44 void d(char *home, char *subdir, uid_t uid, gid_t gid, int mode)
     45 {
     46   if (chdir(home) == -1)
     47     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     48   perm("",home,"/",subdir,S_IFDIR,uid,gid,mode);
     49 }
     50 
     51 void p(char *home, char *fifo, uid_t uid, gid_t gid, int mode)
     52 {
     53   if (chdir(home) == -1)
     54     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     55   perm("",home,"/",fifo,S_IFIFO,uid,gid,mode);
     56 }
     57 
     58 void c(char *home, char *subdir, char *fromdir, char *file, uid_t uid, gid_t gid, int mode)
     59 {
     60   if (chdir(home) == -1)
     61     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     62   if (chdir(subdir) == -1) {
     63     /* assume cat man pages are simply not installed */
     64     if (errno == error_noent && strncmp(subdir, "man/cat", 7) == 0)
     65       return;
     66     strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": ");
     67   }
     68   perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode);
     69 }
     70 
     71 void z(char *home, char *file, int len, uid_t uid, gid_t gid, int mode)
     72 {
     73   if (chdir(home) == -1)
     74     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     75   perm("",home,"/",file,S_IFREG,uid,gid,mode);
     76 }
     77 
     78 int main(void)
     79 {
     80   init_uidgid();
     81   hier();
     82   return 0;
     83 }