release
[hcoop/zz_old/debian/djbdns.git] / instcheck.c
CommitLineData
dc0d77d7
CE
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <unistd.h>
4#include "strerr.h"
5#include "error.h"
6#include "exit.h"
7
8extern void hier();
9
10#define FATAL "instcheck: fatal: "
11#define WARNING "instcheck: warning: "
12
13void perm(prefix1,prefix2,prefix3,file,type,uid,gid,mode)
14char *prefix1;
15char *prefix2;
16char *prefix3;
17char *file;
18int type;
19int uid;
20int gid;
21int mode;
22{
23 struct stat st;
24
25 if (stat(file,&st) == -1) {
26 if (errno == error_noent)
27 strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," does not exist",0);
28 else
29 strerr_warn4(WARNING,"unable to stat .../",file,": ",&strerr_sys);
30 return;
31 }
32
33 if ((uid != -1) && (st.st_uid != uid))
34 strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong owner",0);
35 if ((gid != -1) && (st.st_gid != gid))
36 strerr_warn6(WARNING,prefix1,prefix2,prefix3,file," has wrong group",0);
37 if ((st.st_mode & 07777) != mode)
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);
41}
42
43void h(home,uid,gid,mode)
44char *home;
45int uid;
46int gid;
47int mode;
48{
49 perm("","","",home,S_IFDIR,uid,gid,mode);
50}
51
52void d(home,subdir,uid,gid,mode)
53char *home;
54char *subdir;
55int uid;
56int gid;
57int mode;
58{
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}
63
64void p(home,fifo,uid,gid,mode)
65char *home;
66char *fifo;
67int uid;
68int gid;
69int mode;
70{
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}
75
76void c(home,subdir,file,uid,gid,mode)
77char *home;
78char *subdir;
79char *file;
80int uid;
81int gid;
82int 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}
90
91void z(home,file,len,uid,gid,mode)
92char *home;
93char *file;
94int len;
95int uid;
96int gid;
97int 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}
103
104int main()
105{
106 hier();
107 _exit(0);
108}