nightmaremail

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

instchown.c (2400B)


      1 #include <sys/stat.h>
      2 #include <sys/types.h>
      3 #include <string.h>
      4 #include <unistd.h>
      5 #include "strerr.h"
      6 #include "error.h"
      7 #include "hier.h"
      8 
      9 extern void init_uidgid();
     10 
     11 #define FATAL "instchown: fatal: "
     12 
     13 void h(char *home, uid_t uid, gid_t gid, int mode)
     14 {
     15   if (chown(home,uid,gid) == -1)
     16     strerr_die4sys(111,FATAL,"unable to chown ",home,": ");
     17   if (chmod(home,mode) == -1)
     18     strerr_die4sys(111,FATAL,"unable to chmod ",home,": ");
     19 }
     20 
     21 void d(char *home, char *subdir, uid_t uid, gid_t gid, int mode)
     22 {
     23   if (chdir(home) == -1)
     24     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     25   if (chown(subdir,uid,gid) == -1)
     26     strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": ");
     27   if (chmod(subdir,mode) == -1)
     28     strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": ");
     29 }
     30 
     31 void p(char *home, char *fifo, uid_t uid, gid_t gid, int mode)
     32 {
     33   if (chdir(home) == -1)
     34     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     35   if (chown(fifo,uid,gid) == -1)
     36     strerr_die6sys(111,FATAL,"unable to chown ",home,"/",fifo,": ");
     37   if (chmod(fifo,mode) == -1)
     38     strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",fifo,": ");
     39 }
     40 
     41 void c(char *home, char *subdir, char *fromdir, char *file, uid_t uid, gid_t gid, int mode)
     42 {
     43   if (chdir(home) == -1)
     44     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     45   if (chdir(subdir) == -1) {
     46     /* assume cat man pages are simply not installed */
     47     if (errno == error_noent && strncmp(subdir, "man/cat", 7) == 0)
     48       return;
     49     strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": ");
     50   }
     51   if (chown(file,uid,gid) == -1) {
     52     /* assume cat man pages are simply not installed */
     53     if (errno == error_noent && strncmp(subdir, "man/cat", 7) == 0)
     54       return;
     55     strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": ");
     56   }
     57   if (chmod(file,mode) == -1)
     58     strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": ");
     59 }
     60 
     61 void z(char *home, char *file, int len, uid_t uid, gid_t gid, int mode)
     62 {
     63   if (chdir(home) == -1)
     64     strerr_die4sys(111,FATAL,"unable to switch to ",home,": ");
     65   if (chown(file,uid,gid) == -1)
     66     strerr_die6sys(111,FATAL,"unable to chown ",home,"/",file,": ");
     67   if (chmod(file,mode) == -1)
     68     strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",file,": ");
     69 }
     70 
     71 int main(void)
     72 {
     73   umask(077);
     74   init_uidgid();
     75   hier();
     76   return 0;
     77 }