Annotation of cci/usr/src/usr.bin/audit.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *
        !             3:  *$Header: audit.c,v 1.1 85/07/08 10:24:31 root Exp $
        !             4:  *
        !             5:  *$Log:        audit.c,v $
        !             6:  * Revision 1.1  85/07/08  10:24:31  root
        !             7:  * Initial revision
        !             8:  * 
        !             9:  * Revision 1.2  84/03/28  10:01:09  brian
        !            10:  * Added more detailed error messages dealing with auditing of directories
        !            11:  * 
        !            12:  * 
        !            13:  * Revision 1.1  84/01/26  09:48:52  brian
        !            14:  * Initial revision
        !            15:  * 
        !            16:  */
        !            17: 
        !            18: static char rcsid[] = "$Header: audit.c,v 1.1 85/07/08 10:24:31 root Exp $";
        !            19: 
        !            20: #include <sys/param.h>
        !            21: #include <sys/dir.h>
        !            22: #include <sys/stat.h>
        !            23: #include <stdio.h>
        !            24: #include <sys/audit.h>
        !            25: #include <errno.h>
        !            26: 
        !            27: main(argc,argv)
        !            28: register int argc;
        !            29: register char **argv;
        !            30: {
        !            31:     register int i,n;
        !            32:     register char c,*cp;
        !            33:     int aflg = QUERY;
        !            34:     int status = 0;
        !            35:     struct stat sbuf;
        !            36:     extern int optind,errno;   /* globals returned from sys routines */
        !            37: 
        !            38:     if(argc < 2)
        !            39:     {
        !            40:        
        !            41:        printf("usage: audit [-u] [-s] [-m] file...\n");
        !            42:        exit(8);
        !            43:     }
        !            44:     while((c = getopt(argc,argv,"mus")) != EOF)
        !            45:     {
        !            46:         switch (c) 
        !            47:         {
        !            48:            case 'u':                   /* set file(s) to UNSECURE */
        !            49:                if(aflg != QUERY)
        !            50:                {
        !            51:                    printf("usage: audit [-u] [-s] [-m] file...\n");
        !            52:                    exit(8);
        !            53:                }
        !            54:                aflg = UNSECURE;
        !            55:                break;
        !            56: 
        !            57:            case 's':                   /* set file(s) to SECURE */
        !            58:                if(aflg != QUERY)
        !            59:                {
        !            60:                    printf("usage: audit [-u] [-s] [-m] file...\n");
        !            61:                    exit(8);
        !            62:                }
        !            63:                aflg = SECURE;
        !            64:                break;
        !            65: 
        !            66:            case 'm':                   /* set file(s) with umask */
        !            67:                if(aflg != QUERY)
        !            68:                {
        !            69:                    printf("usage: audit [-u] [-s] [-m] file...\n");
        !            70:                    exit(8);
        !            71:                }
        !            72:                aflg = MASK;
        !            73:                break;
        !            74:     
        !            75:            default:
        !            76:                printf("usage: audit [-u] [-s] [-m] file...\n");
        !            77:                exit(8);
        !            78:         }
        !            79:     }
        !            80: 
        !            81:     if(optind == argc)                 /* assure a file name is specified */
        !            82:     {
        !            83:        printf("usage: audit [-u] [-s] [-m] file...\n");
        !            84:         exit(8);
        !            85:     }
        !            86:        
        !            87:     for (i=optind; i<argc; i++)        /* process all specified files */
        !            88:     {
        !            89:         cp = argv[i];
        !            90:        if(stat(cp,&sbuf) == -1)
        !            91:        {
        !            92:                fprintf(stderr,"%s: cannot stat %s\n",argv[0],cp);
        !            93:                continue;
        !            94:        }
        !            95:        else
        !            96:        {
        !            97:                if((sbuf.st_mode & S_IFMT) == S_IFDIR)
        !            98:                {
        !            99:                        fprintf(stderr,"%s: Audit trail security can not be applied to directories (%s)\n",argv[0],cp);
        !           100:                        continue;
        !           101:                }
        !           102:        }
        !           103:         if ((n = audit(cp,aflg)) < 0)
        !           104:         {
        !           105:            if(errno == EACCES)
        !           106:                fprintf(stderr,"audit: permission denied - %s\n",cp);
        !           107:            else
        !           108:                perror("audit");
        !           109:            status++;
        !           110:            continue;
        !           111:         }
        !           112:         else
        !           113:         {
        !           114:            if(aflg == QUERY)           /* display current status */
        !           115:            {
        !           116:                switch (n)
        !           117:                {
        !           118:                        case SECURE:
        !           119:                            printf("%s has logging enabled\n",cp);
        !           120:                            break;
        !           121:     
        !           122:                        case UNSECURE:
        !           123:                            printf("%s has logging disabled\n",cp);
        !           124:                            break;
        !           125:                }
        !           126:            }
        !           127:        }
        !           128:     }
        !           129:     exit(status);
        !           130: }
        !           131: /*     @(#)getopt.c    1.5     */
        !           132: /*     3.0 SID #       1.2     */
        !           133: /*LINTLIBRARY*/
        !           134: #define NULL   0
        !           135: #define EOF    (-1)
        !           136: #define ERR(s, c)      if(opterr){\
        !           137:        extern int strlen(), write();\
        !           138:        char errbuf[2];\
        !           139:        errbuf[0] = c; errbuf[1] = '\n';\
        !           140:        (void) write(2, argv[0], (unsigned)strlen(argv[0]));\
        !           141:        (void) write(2, s, (unsigned)strlen(s));\
        !           142:        (void) write(2, errbuf, 2);}
        !           143: 
        !           144: extern int strcmp();
        !           145: extern char *strchr();
        !           146: 
        !           147: int    opterr = 1;
        !           148: int    optind = 1;
        !           149: int    optopt;
        !           150: char   *optarg;
        !           151: 
        !           152: int
        !           153: getopt(argc, argv, opts)
        !           154: int    argc;
        !           155: char   **argv, *opts;
        !           156: {
        !           157:        static int sp = 1;
        !           158:        register int c;
        !           159:        register char *cp;
        !           160: 
        !           161:        if(sp == 1)
        !           162:                if(optind >= argc ||
        !           163:                   argv[optind][0] != '-' || argv[optind][1] == '\0')
        !           164:                        return(EOF);
        !           165:                else if(strcmp(argv[optind], "--") == NULL) {
        !           166:                printf("NULL \n");
        !           167:                        optind++;
        !           168:                        return(EOF);
        !           169:                }
        !           170:        optopt = c = argv[optind][sp];
        !           171:        if(c == ':' || (cp=strchr(opts, c)) == NULL) {
        !           172:                ERR(": illegal option -- ", c);
        !           173:                if(argv[optind][++sp] == '\0') {
        !           174:                        optind++;
        !           175:                        sp = 1;
        !           176:                }
        !           177:                return('?');
        !           178:        }
        !           179:        if(*++cp == ':') {
        !           180:                if(argv[optind][sp+1] != '\0')
        !           181:                        optarg = &argv[optind++][sp+1];
        !           182:                else if(++optind >= argc) {
        !           183:                        ERR(": option requires an argument -- ", c);
        !           184:                        sp = 1;
        !           185:                        return('?');
        !           186:                } else
        !           187:                        optarg = argv[optind++];
        !           188:                sp = 1;
        !           189:        } else {
        !           190:                if(argv[optind][++sp] == '\0') {
        !           191:                        sp = 1;
        !           192:                        optind++;
        !           193:                }
        !           194:                optarg = NULL;
        !           195:        }
        !           196:        return(c);
        !           197: }
        !           198: /*     @(#)strchr.c    1.2     */
        !           199: /*     3.0 SID #       1.2     */
        !           200: /*LINTLIBRARY*/
        !           201: /*
        !           202:  * Return the ptr in sp at which the character c appears;
        !           203:  * NULL if not found
        !           204:  */
        !           205: 
        !           206: #define        NULL    0
        !           207: 
        !           208: char *
        !           209: strchr(sp, c)
        !           210: register char *sp, c;
        !           211: {
        !           212:        do {
        !           213:                if(*sp == c)
        !           214:                        return(sp);
        !           215:        } while(*sp++);
        !           216:        return(NULL);
        !           217: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.