Приемы профессиональной работы в UNIX

         

ТЕКСТ ПРОГРАММЫ


1 : 2 # @(#) access v1.0 Show all free access logins Author: Russ Sage

4 if [ "$#" -gt "0" ] 5 then echo "access: too many arguments" >&2 6 echo "usage: access" >&2 7 exit 1 8 fi

10 grep '^[^:]*::' /etc/passwd echo "All logins protected"


1 : 2 # @(#) chkset v1.0 Check for set bits on Author: Russ Sage

4 FORM="-print" 5 SORT="sort"

7 if [ "`echo $1 | cut -c1`" = "-" ] 8 then case $1 in 9 -l) shift 10 FORM="-exec ls -ld {} ;" 11 SORT="sort +7";; 12 *) echo "usage: chkset [-l][file/dir ...]" >&2 13 exit 1;; 14 esac 15 fi

17 if [ "$#" -gt 0 ] 18 then SRC="$*" 19 else SRC="/" 20 fi

22 find $SRC \( -perm -4000 -o -perm -2000 \) $FORM | $SORT




1 static char id[]="@(#)suw v1.0 Author: Russ Sage"; 3 # include   5 # define FALSE 0 6 # define TRUE 1 7 # define MATCH 0 8 # define BSIZ 80   10 main(argc,argv) 11 int argc; 12 char *argv[]; 13 { 14 register int alert, c, mail, n; 15 FILE *fp1, *fp2; 16 char *p, *uname, line[BSIZ], tmp[BSIZ], 17 *log = "/usr/adm/sulog";   19 static char *legal[] = {sage-root\n","root-root\n",NULL}; 20 static char *adm[] = {"sage",NULL};   23 mail = FALSE;   25 if (argc > 1 && argv[1][0] == '-') 26 switch (argv[1][1]) 27 { 28 case 'm': 29 mail = TRUE; 30 --argc; 31 ++argv; 32 break; 33 default: 34 fprintf(stderr,"suw: invalid argument %s\n", argv[1]); 35 fprintf(stderr,"usage: suw [-m] [sulog]\n"); 36 exit(1); 37 }   39 if (argc == 2) 40 log = *++argv;   42 if ((fp1 = fopen(log,"r")) == NULL) 43 { 44 fprintf(stderr,"suw: error opening %s\n",log); 45 fprintf(stderr,"usage: suw [-m] [sulog]\n"); 46 exit(1); 47 }   49 sprintf(tmp,"/tmp/suw%d",getpid()); 50 if ((fp2 = fopen(tmp,"w+")) == NULL) 51 { 52 fprintf(stderr,"suw: error opening %s\n",tmp); 53 fprintf(stderr,"usage: suw [-m] [sulog]\n"); 54 exit(1); 55 }   57 while (fgets(line,sizeof(line),fp1) != NULL) 58 { 59 p = line + 15; 60 if (*p == '+') 61 { 62 p = p + 2; 63 while (*p != ' ') p++; 64 p++; 65 uname = p; 66 while (*p && *p++ != '-') 67 continue;   69 if (strcmp (p,"root\n") == MATCH) 70 { 71 alert = TRUE; 72 for (n=0; legal[n] != NULL; n++) 73 if (strcmp (uname,legal[n]) == MATCH) 74 { 75 alert = FALSE; 76 break; 77 } 78 if (alert) 79 fprintf(fp2,"Illegal --> %s", line); 80 } 81 } 82 }   84 if (mail) 85 { 86 fclose(fp2); 87 for (n=0; adm[n] != NULL; n++) 88 { 89 sprintf(line,"cat %s | mail %s",tmp,adm[n]); 90 system(line); 91 } 92 } 93 else 94 { 95 rewind(fp2); 96 while ((c = getc(fp2)) != EOF) 97 putc(c, stdout); 98 fclose(fp2); 99 }   101 fclose(fp1); 102 unlink(tmp); 103 }



Содержание раздела