osi-audit-locking-fix-20060201
[openafs.git] / src / ptserver / ptserver.c
index 8d39d10..9567dbd 100644 (file)
@@ -120,6 +120,8 @@ RCSID
 #endif
 #include <sys/types.h>
 #include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
 #include <WINNT/afsevent.h>
@@ -163,6 +165,8 @@ extern int afsconf_CheckAuth();
 int pr_realmNameLen;
 char *pr_realmName;
 
+int restricted = 0;
+
 static struct afsconf_cell info;
 
 extern int prp_group_default;
@@ -195,8 +199,7 @@ prp_access_mask(s)
 
 /* check whether caller is authorized to manage RX statistics */
 int
-pr_rxstat_userok(call)
-     struct rx_call *call;
+pr_rxstat_userok(struct rx_call *call)
 {
     return afsconf_SuperUser(prdir, call, NULL);
 }
@@ -240,6 +243,7 @@ main(int argc, char **argv)
     sigaction(SIGABRT, &nsa, NULL);
     sigaction(SIGSEGV, &nsa, NULL);
 #endif
+    osi_audit_init();
     osi_audit(PTS_StartEvent, 0, AUD_END);
 
     /* Initialize dirpaths */
@@ -297,6 +301,9 @@ main(int argc, char **argv)
            prp_user_default = prp_access_mask(argv[++a]);
            prp_group_default = prp_access_mask(argv[++a]);
        }
+       else if (strncmp(arg, "-restricted", alen) == 0) {
+           restricted = 1;
+       }
        else if (strncmp(arg, "-enable_peer_stats", alen) == 0) {
            rx_enablePeerRPCStats();
        } else if (strncmp(arg, "-enable_process_stats", alen) == 0) {
@@ -311,35 +318,74 @@ main(int argc, char **argv)
            serverLogSyslogFacility = atoi(arg + 8);
        }
 #endif
+       else if (strncmp(arg, "-auditlog", alen) == 0) {
+           int tempfd, flags;
+           FILE *auditout;
+           char oldName[MAXPATHLEN];
+           char *fileName = argv[++a];
+
+#ifndef AFS_NT40_ENV
+           struct stat statbuf;
+
+           if ((lstat(fileName, &statbuf) == 0) 
+               && (S_ISFIFO(statbuf.st_mode))) {
+               flags = O_WRONLY | O_NONBLOCK;
+           } else 
+#endif
+           {
+               strcpy(oldName, fileName);
+               strcat(oldName, ".old");
+               renamefile(fileName, oldName);
+               flags = O_WRONLY | O_TRUNC | O_CREAT;
+           }
+           tempfd = open(fileName, flags, 0666);
+           if (tempfd > -1) {
+               auditout = fdopen(tempfd, "a");
+               if (auditout) {
+                   osi_audit_file(auditout);
+                   osi_audit(PTS_StartEvent, 0, AUD_END);
+               } else
+                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+           } else
+               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+       }
        else if (*arg == '-') {
            /* hack in help flag support */
 
 #if defined(SUPERGROUPS)
 #ifndef AFS_NT40_ENV
            printf("Usage: ptserver [-database <db path>] "
+                  "[-auditlog <log path>] "
                   "[-syslog[=FACILITY]] "
                   "[-p <number of processes>] [-rebuild] "
                   "[-groupdepth <depth>] "
+                  "[-restricted] "
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-default_access default_user_access default_group_access] "
                   "[-help]\n");
 #else /* AFS_NT40_ENV */
            printf("Usage: ptserver [-database <db path>] "
+                  "[-auditlog <log path>] "
                   "[-p <number of processes>] [-rebuild] "
                   "[-default_access default_user_access default_group_access] "
+                  "[-restricted] "
                   "[-groupdepth <depth>] " "[-help]\n");
 #endif
 #else
 #ifndef AFS_NT40_ENV
            printf("Usage: ptserver [-database <db path>] "
+                  "[-auditlog <log path>] "
                   "[-syslog[=FACILITY]] "
                   "[-p <number of processes>] [-rebuild] "
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-default_access default_user_access default_group_access] "
+                  "[-restricted] "
                   "[-help]\n");
 #else /* AFS_NT40_ENV */
            printf("Usage: ptserver [-database <db path>] "
+                  "[-auditlog <log path>] "
                   "[-default_access default_user_access default_group_access] "
+                  "[-restricted] "
                   "[-p <number of processes>] [-rebuild] " "[-help]\n");
 #endif
 #endif