Commit | Line | Data |
---|---|---|
2117e02e MW |
1 | #include <sys/types.h> |
2 | #include <sys/stat.h> | |
212b6f5d MW |
3 | #include "strerr.h" |
4 | #include "error.h" | |
2117e02e MW |
5 | #include "readwrite.h" |
6 | #include "exit.h" | |
2117e02e | 7 | |
212b6f5d | 8 | extern void hier(); |
2117e02e | 9 | |
2117e02e | 10 | #define FATAL "instcheck: fatal: " |
212b6f5d | 11 | #define WARNING "instcheck: warning: " |
2117e02e | 12 | |
212b6f5d MW |
13 | void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode) |
14 | char *prefix1; | |
15 | char *prefix2; | |
16 | char *prefix3; | |
17 | char *file; | |
18 | int type; | |
19 | int uid; | |
20 | int gid; | |
21 | int mode; | |
2117e02e MW |
22 | { |
23 | struct stat st; | |
2117e02e | 24 | |
212b6f5d | 25 | if (stat(file,&st) == -1) { |
2117e02e | 26 | if (errno == error_noent) |
212b6f5d | 27 | strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," does not exist",0); |
2117e02e | 28 | else |
212b6f5d | 29 | strerr_warn4(WARNING,"unable to stat .../",file,": ",&strerr_sys); |
2117e02e MW |
30 | return; |
31 | } | |
32 | ||
33 | if ((uid != -1) && (st.st_uid != uid)) | |
212b6f5d | 34 | strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong owner",0); |
2117e02e | 35 | if ((gid != -1) && (st.st_gid != gid)) |
212b6f5d | 36 | strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong group",0); |
2117e02e | 37 | if ((st.st_mode & 07777) != mode) |
212b6f5d MW |
38 | strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong permissions",0); |
39 | if ((st.st_mode & S_IFMT) != type) | |
40 | strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong type",0); | |
2117e02e MW |
41 | } |
42 | ||
212b6f5d MW |
43 | void h(home,uid,gid,mode) |
44 | char *home; | |
45 | int uid; | |
46 | int gid; | |
47 | int mode; | |
48 | { | |
49 | perm("","","",home,S_IFDIR,uid,gid,mode); | |
50 | } | |
2117e02e | 51 | |
212b6f5d MW |
52 | void d(home,subdir,uid,gid,mode) |
53 | char *home; | |
54 | char *subdir; | |
55 | int uid; | |
56 | int gid; | |
57 | int mode; | |
2117e02e | 58 | { |
212b6f5d MW |
59 | if (chdir(home) == -1) |
60 | strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); | |
61 | perm("",home,"/",subdir,S_IFDIR,uid,gid,mode); | |
62 | } | |
2117e02e | 63 | |
212b6f5d MW |
64 | void p(home,fifo,uid,gid,mode) |
65 | char *home; | |
66 | char *fifo; | |
67 | int uid; | |
68 | int gid; | |
69 | int mode; | |
2117e02e | 70 | { |
212b6f5d MW |
71 | if (chdir(home) == -1) |
72 | strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); | |
73 | perm("",home,"/",fifo,S_IFIFO,uid,gid,mode); | |
74 | } | |
2117e02e | 75 | |
212b6f5d MW |
76 | void c(home,subdir,file,uid,gid,mode) |
77 | char *home; | |
78 | char *subdir; | |
79 | char *file; | |
80 | int uid; | |
81 | int gid; | |
82 | int mode; | |
83 | { | |
84 | if (chdir(home) == -1) | |
85 | strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); | |
86 | if (chdir(subdir) == -1) | |
87 | strerr_die6sys(111,FATAL,"unable to switch to ",home,"/",subdir,": "); | |
88 | perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode); | |
89 | } | |
2117e02e | 90 | |
212b6f5d MW |
91 | void z(home,file,len,uid,gid,mode) |
92 | char *home; | |
93 | char *file; | |
94 | int len; | |
95 | int uid; | |
96 | int gid; | |
97 | int mode; | |
98 | { | |
99 | if (chdir(home) == -1) | |
100 | strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); | |
101 | perm("",home,"/",file,S_IFREG,uid,gid,mode); | |
102 | } | |
2117e02e | 103 | |
ed442cdc MW |
104 | void main(argc,argv) |
105 | int argc; | |
106 | char *argv[]; | |
212b6f5d | 107 | { |
ed442cdc MW |
108 | char *home = 0; |
109 | if (argc > 1) | |
110 | home = argv[1]; | |
111 | hier(home); | |
212b6f5d | 112 | _exit(0); |
2117e02e | 113 | } |