djbdnscurve6  38
djbdnscurve6
instcheck.c
Go to the documentation of this file.
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <unistd.h>
4 #include "logmsg.h"
5 #include "exit.h"
6 
7 extern void hier();
8 
9 #define WHO "instcheck"
10 
11 void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode)
12 char *prefix1;
13 char *prefix2;
14 char *prefix3;
15 char *file;
16 int type;
17 int uid;
18 int gid;
19 int mode;
20 {
21  struct stat st;
22 
23  if (stat(file,&st) == -1) {
24  if (errno == ENOENT)
25  logmsg(WHO,-99,WARN,B(prefix1,prefix2,prefix3,file," does not exist"));
26  else
27  logmsg(WHO,-99,WARN,B("unable to stat: .../",file));
28  return;
29  }
30 
31  if ((uid != -1) && (st.st_uid != uid))
32  logmsg(WHO,-99,WARN,B(prefix1,prefix2,prefix3,file," has wrong owner"));
33  if ((gid != -1) && (st.st_gid != gid))
34  logmsg(WHO,-99,WARN,B(prefix1,prefix2,prefix3,file," has wrong group"));
35  if ((st.st_mode & 07777) != mode)
36  logmsg(WHO,-99,WARN,B(prefix1,prefix2,prefix3,file," has wrong permissions"));
37  if ((st.st_mode & S_IFMT) != type)
38  logmsg(WHO,-99,WARN,B(prefix1,prefix2,prefix3,file," has wrong type"));
39 }
40 
41 void h(home,uid,gid,mode)
42 char *home;
43 int uid;
44 int gid;
45 int mode;
46 {
47  perm("","","",home,S_IFDIR,uid,gid,mode);
48 }
49 
50 void d(home,subdir,uid,gid,mode)
51 char *home;
52 char *subdir;
53 int uid;
54 int gid;
55 int mode;
56 {
57  if (chdir(home) == -1)
58  logmsg(WHO,111,FATAL,B("unable to switch to: ",home));
59  perm("",home,"/",subdir,S_IFDIR,uid,gid,mode);
60 }
61 
62 void p(home,fifo,uid,gid,mode)
63 char *home;
64 char *fifo;
65 int uid;
66 int gid;
67 int mode;
68 {
69  if (chdir(home) == -1)
70  logmsg(WHO,111,FATAL,B("unable to switch to: ",home));
71  perm("",home,"/",fifo,S_IFIFO,uid,gid,mode);
72 }
73 
74 void c(home,subdir,file,uid,gid,mode)
75 char *home;
76 char *subdir;
77 char *file;
78 int uid;
79 int gid;
80 int mode;
81 {
82  if (chdir(home) == -1)
83  logmsg(WHO,111,FATAL,B("unable to switch to: ",home));
84  if (chdir(subdir) == -1)
85  logmsg(WHO,111,FATAL,B("unable to switch to: ",home,"/",subdir));
86  perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode);
87 }
88 
89 void z(home,file,len,uid,gid,mode)
90 char *home;
91 char *file;
92 int len;
93 int uid;
94 int gid;
95 int mode;
96 {
97  if (chdir(home) == -1)
98  logmsg(WHO,111,FATAL,B("unable to switch to; ",home));
99  perm("",home,"/",file,S_IFREG,uid,gid,mode);
100 }
101 
102 int main()
103 {
104  hier();
105  _exit(0);
106 }
uint16 len
Definition: axfrdns.c:302
char type[2]
Definition: dnsq.c:56
void p(char *home, char *fifo, int uid, int gid, int mode)
Definition: instcheck.c:62
void perm(char *prefix1, char *prefix2, char *prefix3, char *file, int type, int uid, int gid, int mode)
Definition: instcheck.c:11
void d(char *home, char *subdir, int uid, int gid, int mode)
Definition: instcheck.c:50
void c(char *home, char *subdir, char *file, int uid, int gid, int mode)
Definition: instcheck.c:74
void hier()
Definition: hier.c:7
void h(char *home, int uid, int gid, int mode)
Definition: instcheck.c:41
void z(char *home, char *file, int len, int uid, int gid, int mode)
Definition: instcheck.c:89
#define WHO
Definition: instcheck.c:9
int main()
Definition: instcheck.c:102
char mode
Definition: tinydns-edit.c:43