From 89b7b67a13ebb7965cc7f13ad0595e2194a2d34c Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:48:04 +0200 Subject: add sqmail-4.2.29a --- src/instcheck.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/instcheck.c (limited to 'src/instcheck.c') diff --git a/src/instcheck.c b/src/instcheck.c new file mode 100644 index 0000000..e47da87 --- /dev/null +++ b/src/instcheck.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include "logmsg.h" +#include "exit.h" +#include "hier.h" + +extern void hier(); + +#define WHO "instcheck" + +void perm(char *prefix1,char *prefix2,char *prefix3,char *file,int type,int uid,int gid,int mode) +{ + struct stat st; + + if (stat(file,&st) == -1) { + if (errno == ENOENT) + logmsg(WHO,0,WARN,B("file does nost exist:",prefix1,prefix2,prefix3,file)); + else + logmsg(WHO,errno,WARN,B("unable to stat: ../",file)); + return; + } + + if ((uid != -1) && (st.st_uid != uid)) + logmsg(WHO,0,WARN,B("file has wrong owner: ",prefix1,prefix2,prefix3,file)); + if ((gid != -1) && (st.st_gid != gid)) + logmsg(WHO,0,WARN,B("file has wrong group: ",prefix1,prefix2,prefix3,file)); + if ((st.st_mode & 07777) != mode) + logmsg(WHO,0,WARN,B("file has wrong permissions: ",prefix1,prefix2,prefix3,file)); + if ((st.st_mode & S_IFMT) != type) + logmsg(WHO,0,WARN,B("file has wrong type: ",prefix1,prefix2,prefix3,file)); +} + +void h(char *home,int uid,int gid,int mode) +{ + perm("","","",home,S_IFDIR,uid,gid,mode); +} + +void d(char *home,char *subdir,int uid,int gid,int mode) +{ + if (chdir(home) == -1) + logmsg(WHO,111,FATAL,B("unable to switch to: ",home)); + perm("",home,"/",subdir,S_IFDIR,uid,gid,mode); +} + +void p(char *home,char *fifo,int uid,int gid,int mode) +{ + if (chdir(home) == -1) + logmsg(WHO,111,FATAL,B("unable to switch to: ",home)); + perm("",home,"/",fifo,S_IFIFO,uid,gid,mode); +} + +void c(char *home,char *subdir,char *file,int uid,int gid,int mode) +{ + if (chdir(home) == -1) + logmsg(WHO,111,FATAL,B("unable to switch to: ",home)); + if (chdir(subdir) == -1) + logmsg(WHO,111,FATAL,B("unable to switch to: ",home,"/",subdir)); + perm(".../",subdir,"/",file,S_IFREG,uid,gid,mode); +} + +void z(char *home,char *file,int len,int uid,int gid,int mode) +{ + if (chdir(home) == -1) + logmsg(WHO,111,FATAL,B("unable to switch to: ",home)); + perm("",home,"/",file,S_IFREG,uid,gid,mode); +} + +int main() +{ + hier(); + _exit(0); +} -- cgit v1.2.3