File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / usr.bin / audit.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:24:19 2019 UTC (6 years, 11 months ago) by root
Branches: bsd, MAIN
CVS tags: v12b, v121, HEAD
Power 6/32 Unix version 1.2b

/*
 *
 *$Header: /var/lib/cvsd/repos/cci/cci/usr/src/usr.bin/audit.c,v 1.1.1.1 2019/07/28 12:24:19 root Exp $
 *
 *$Log: audit.c,v $
 *Revision 1.1.1.1  2019/07/28 12:24:19  root
 *Power 6/32 Unix version 1.2b
 *
 * Revision 1.1  85/07/08  10:24:31  root
 * Initial revision
 * 
 * Revision 1.2  84/03/28  10:01:09  brian
 * Added more detailed error messages dealing with auditing of directories
 * 
 * 
 * Revision 1.1  84/01/26  09:48:52  brian
 * Initial revision
 * 
 */

static char rcsid[] = "$Header: /var/lib/cvsd/repos/cci/cci/usr/src/usr.bin/audit.c,v 1.1.1.1 2019/07/28 12:24:19 root Exp $";

#include <sys/param.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <stdio.h>
#include <sys/audit.h>
#include <errno.h>

main(argc,argv)
register int argc;
register char **argv;
{
    register int i,n;
    register char c,*cp;
    int aflg = QUERY;
    int status = 0;
    struct stat sbuf;
    extern int optind,errno;	/* globals returned from sys routines */

    if(argc < 2)
    {
	
	printf("usage: audit [-u] [-s] [-m] file...\n");
	exit(8);
    }
    while((c = getopt(argc,argv,"mus")) != EOF)
    {
        switch (c) 
        {
	    case 'u':			/* set file(s) to UNSECURE */
	        if(aflg != QUERY)
	        {
		    printf("usage: audit [-u] [-s] [-m] file...\n");
		    exit(8);
	        }
	        aflg = UNSECURE;
	        break;

	    case 's':			/* set file(s) to SECURE */
	        if(aflg != QUERY)
	        {
		    printf("usage: audit [-u] [-s] [-m] file...\n");
		    exit(8);
	        }
	        aflg = SECURE;
	        break;

	    case 'm':			/* set file(s) with umask */
	        if(aflg != QUERY)
	        {
		    printf("usage: audit [-u] [-s] [-m] file...\n");
		    exit(8);
	        }
	        aflg = MASK;
	        break;
    
	    default:
		printf("usage: audit [-u] [-s] [-m] file...\n");
	        exit(8);
        }
    }

    if(optind == argc)			/* assure a file name is specified */
    {
	printf("usage: audit [-u] [-s] [-m] file...\n");
        exit(8);
    }
	
    for (i=optind; i<argc; i++) 	/* process all specified files */
    {
        cp = argv[i];
	if(stat(cp,&sbuf) == -1)
	{
		fprintf(stderr,"%s: cannot stat %s\n",argv[0],cp);
		continue;
	}
	else
	{
		if((sbuf.st_mode & S_IFMT) == S_IFDIR)
		{
			fprintf(stderr,"%s: Audit trail security can not be applied to directories (%s)\n",argv[0],cp);
			continue;
		}
	}
        if ((n = audit(cp,aflg)) < 0)
        {
	    if(errno == EACCES)
		fprintf(stderr,"audit: permission denied - %s\n",cp);
	    else
	        perror("audit");
	    status++;
	    continue;
        }
        else
        {
	    if(aflg == QUERY)		/* display current status */
	    {
	        switch (n)
	        {
		        case SECURE:
			    printf("%s has logging enabled\n",cp);
			    break;
    
		        case UNSECURE:
			    printf("%s has logging disabled\n",cp);
			    break;
		}
	    }
	}
    }
    exit(status);
}
/*	@(#)getopt.c	1.5	*/
/*	3.0 SID #	1.2	*/
/*LINTLIBRARY*/
#define NULL	0
#define EOF	(-1)
#define ERR(s, c)	if(opterr){\
	extern int strlen(), write();\
	char errbuf[2];\
	errbuf[0] = c; errbuf[1] = '\n';\
	(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
	(void) write(2, s, (unsigned)strlen(s));\
	(void) write(2, errbuf, 2);}

extern int strcmp();
extern char *strchr();

int	opterr = 1;
int	optind = 1;
int	optopt;
char	*optarg;

int
getopt(argc, argv, opts)
int	argc;
char	**argv, *opts;
{
	static int sp = 1;
	register int c;
	register char *cp;

	if(sp == 1)
		if(optind >= argc ||
		   argv[optind][0] != '-' || argv[optind][1] == '\0')
			return(EOF);
		else if(strcmp(argv[optind], "--") == NULL) {
		printf("NULL \n");
			optind++;
			return(EOF);
		}
	optopt = c = argv[optind][sp];
	if(c == ':' || (cp=strchr(opts, c)) == NULL) {
		ERR(": illegal option -- ", c);
		if(argv[optind][++sp] == '\0') {
			optind++;
			sp = 1;
		}
		return('?');
	}
	if(*++cp == ':') {
		if(argv[optind][sp+1] != '\0')
			optarg = &argv[optind++][sp+1];
		else if(++optind >= argc) {
			ERR(": option requires an argument -- ", c);
			sp = 1;
			return('?');
		} else
			optarg = argv[optind++];
		sp = 1;
	} else {
		if(argv[optind][++sp] == '\0') {
			sp = 1;
			optind++;
		}
		optarg = NULL;
	}
	return(c);
}
/*	@(#)strchr.c	1.2	*/
/*	3.0 SID #	1.2	*/
/*LINTLIBRARY*/
/*
 * Return the ptr in sp at which the character c appears;
 * NULL if not found
 */

#define	NULL	0

char *
strchr(sp, c)
register char *sp, c;
{
	do {
		if(*sp == c)
			return(sp);
	} while(*sp++);
	return(NULL);
}

unix.superglobalmegacorp.com

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