1/************************************************************************ 2 * recommend Analyses the installation, and makes * 3 * recommendations about suid/sgid modes * 4 ************************************************************************/ 5/*$Id: recommend.c,v 1.16 1999/10/20 04:47:45 guenther Exp $*/ 6#include "includes.h" 7 8#define PERMIS (S_IRWXU|S_IRWXG&~S_IWGRP|S_IRWXO&~S_IWOTH) 9 10char mailspooldir[]=MAILSPOOLDIR; 11const char dirsep[]=DIRSEP, 12 *const checkf[]={"/bin/mail","/bin/lmail","/usr/lib/sendmail", 13 "/usr/lib/smail",0}; 14 15int main(argc,argv)const int argc;const char*const argv[]; 16{ struct group*grp;struct stat stbuf;gid_t gid=(gid_t)-1; 17 const char*const*p;mode_t sgid=0;int chmdir=0; 18 if(argc!=3) 19 { fprintf(stderr,"Please run this program via 'make recommend'\n"); 20 return EX_USAGE; 21 } 22 strchr(mailspooldir,'\0')[-1]='\0'; /* strip last character */ 23 for(p=checkf;*p;p++) 24 if(!stat(*p,&stbuf)&&stbuf.st_mode&S_ISGID) 25 { if(stbuf.st_mode&S_ISGID) 26 sgid=S_ISGID,gid=stbuf.st_gid; 27 break; 28 } 29 if(!stat(mailspooldir,&stbuf)&&!(stbuf.st_mode&S_IWOTH)) 30 if(stbuf.st_mode&S_ISVTX) 31 chmdir=2; 32 else 33 { if(!(stbuf.st_mode&S_IWGRP)) 34 chmdir=1; 35 sgid=S_ISGID;gid=stbuf.st_gid; 36 } 37 if(gid!=stbuf.st_gid) 38 sgid=0; 39 printf("chown root %s\n",argv[1]); 40 if(sgid) 41 if(grp=getgrgid(gid)) 42 printf("chgrp %s %s %s\n",grp->gr_name,argv[1],argv[2]); 43 else 44 printf("chgrp %u %s %s\n",(unsigned)gid,argv[1],argv[2]); 45 printf("chmod %lo %s\n",(unsigned long)(sgid|S_ISUID|PERMIS),argv[1]); 46 if(sgid) 47 printf("chmod %lo %s\n",(unsigned long)(sgid|PERMIS),argv[2]); 48 else if(chmdir==1) 49 goto nogchmod; 50#ifndef __APPLE__ 51 if(chmdir) 52 printf("chmod %c+w %s/.\n",chmdir==1?'g':'a',mailspooldir); 53#endif 54nogchmod: 55 return EXIT_SUCCESS; 56} 57