|
|
Power 6/32 Unix version 1.2b
/*
* $Header: /var/lib/cvsd/repos/cci/cci/usr/src/etc/auditon.c,v 1.1.1.1 2019/07/28 12:24:19 root Exp $
*
* $Log: auditon.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 08:29:15 root
* Initial revision
*
* Revision 1.4 84/10/08 16:33:44 guy
* Changed to print the reason a system call failed.
*
* Revision 1.3 84/03/28 09:38:25 root
* Added a -q (query) option to allow the user to ask the current audit trail
* log file. Also made it complain about attempts to log to a directory.
*
* Revision 1.2 84/03/10 17:00:28 brian
* Added code to log the currentldy active log file.
*
*/
static char rcsid[] = "$Header: /var/lib/cvsd/repos/cci/cci/usr/src/etc/auditon.c,v 1.1.1.1 2019/07/28 12:24:19 root Exp $";
/*
* auditon - calls 'audon' syscall with super-user privileges
*/
#include <stdio.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include <errno.h>
#define ROOT 0
#define ERROR -1
#define PATHLEN 512
#define DEFLTAUD "/usr/adm/audit"
#define AUDFILELOG "/usr/adm/audfile.log"
char *audfile;
struct stat buf;
int uid;
struct stat d, dd;
struct direct dir;
char dot[] = ".";
char dotdot[] = "..";
char result[PATHLEN];
char name[PATHLEN];
int file;
int off = 0;
int optind;
main(argc,argv)
int argc;
char **argv;
{
register int fd;
register char c;
extern int errno;
char *getwd();
if( (uid=getuid()) != ROOT)
{
fprintf(stderr,"%s: must be superuser\n",argv[0]);
exit(1);
}
while((c = getopt(argc,argv,"q")) != EOF)
{
switch (c)
{
case 'q':
query();
exit(0);
default:
printf("usage: auditon [-q] [file]\n");
exit(1);
}
}
if(optind < argc )
{
if(*(argv[optind]) != '/')
{
audfile = getwd(name);
if(strcmp(audfile,"/") != 0)
strncat(audfile,"/",PATHLEN);
strncat(audfile,argv[optind],PATHLEN);
}
else
audfile = argv[optind];
}
else
audfile = DEFLTAUD;
if(stat(audfile,&buf) == ERROR) {
if(errno == ENOENT){
if(creat(audfile,0600) == ERROR){
fprintf(stderr,"%s: cannot create %s\n",
argv[0],audfile);
exit(8);
}
}
else{
fprintf(stderr,"%s: cannot open ",argv[0]);
perror(audfile);
exit(1);
}
}
if((buf.st_mode & S_IFMT) == S_IFDIR)
{
fprintf(stderr,"%s: %s is a directory\n",argv[0],audfile);
exit(1);
}
if(audon(audfile) == ERROR) {
if(errno == EBUSY)
fprintf(stderr,"%s: already logging to %s\n",argv[0],audfile);
else
{
perror(argv[0]);
fprintf(stderr,"%s: auditing not enabled\n",argv[0]);
}
exit(1);
}
if((fd = creat(AUDFILELOG,0600)) == ERROR){
fprintf(stderr,"%s: cannot create %s\n",
argv[0],AUDFILELOG);
audon((char *) NULL);
fprintf(stderr,"%s: auditing not enabled\n",argv[0]);
exit(8);
}
if(write(fd,audfile,strlen(audfile)) < strlen(audfile))
{
fprintf(stderr,"%s: cannot write to %s\n",
argv[0],AUDFILELOG);
audon((char *) NULL);
fprintf(stderr,"%s: auditing not enabled\n",argv[0]);
exit(8);
}
fprintf(stderr,"%s: auditing ON.\tFile used = %s\n\n",argv[0],audfile);
}
/*
* Report currently active audit trail logfile
*/
query()
{
register int fd, cnt;
extern int errno;
char buf[PATHLEN];
if((fd = open(AUDFILELOG,0)) == ERROR)
{
if(errno == ENOENT)
{
printf("auditon: Audit trail facility currently not enabled\n");
return;
}
else
{
fprintf(stderr,"auditon: cannot open %s\n", AUDFILELOG);
exit(8);
}
}
if((cnt = read(fd,buf,PATHLEN)) == ERROR)
{
fprintf(stderr,"auditon: cannot read %s\n", AUDFILELOG);
exit(8);
}
buf[cnt] = '\0'; /* terminate string with null */
printf("auditon: The current audit trail log file is %s\n",buf);
return;
}
cat(path)
register char *path;
{
register i, j;
i = -1;
while ((dir.d_name[++i] != 0) && (i < 14));
if ((off+i+2) > (PATHLEN-1))
return;
for(j=off+1; j>=0; --j)
path[j+i+1] = path[j];
off=i+off+1;
path[i] = '/';
for(--i; i>=0; --i)
path[i] = dir.d_name[i];
}
/* @(#)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 optopt;
int optind = 1;
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) {
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);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.