ptserver-debug-flag-20090603
[openafs.git] / src / ptserver / ptserver.c
index 463f5d9..f7cf0b5 100644 (file)
@@ -129,13 +129,7 @@ RCSID
 #include <netdb.h>
 #include <netinet/in.h>
 #endif
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rx_globals.h>
@@ -145,10 +139,12 @@ RCSID
 #include <afs/auth.h>
 #include <afs/keys.h>
 #include "ptserver.h"
+#include "ptprototypes.h"
 #include "error_macros.h"
 #include "afs/audit.h"
 #include <afs/afsutil.h>
-
+#include <afs/com_err.h>
+#include <rx/rxstat.h>
 
 /* make        all of these into a structure if you want */
 struct prheader cheader;
@@ -159,15 +155,14 @@ struct afsconf_dir *prdir;
 extern afs_int32 depthsg;
 #endif
 
-extern int afsconf_ServerAuth();
-extern int afsconf_CheckAuth();
-
 int pr_realmNameLen;
 char *pr_realmName;
 
+int debuglevel = 0;
 int restricted = 0;
 int rxMaxMTU = -1;
 int rxBind = 0;
+int rxkadDisableDotCheck = 0;
 
 #define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
 afs_uint32 SHostAddrs[ADDRSPERSITE];
@@ -180,8 +175,7 @@ extern int prp_user_default;
 #include "AFS_component_version_number.c"
 
 int
-prp_access_mask(s)
-    char *s;
+prp_access_mask(char *s)
 {
     int r;
     if (*s >= '0' && *s <= '9') {
@@ -219,7 +213,6 @@ main(int argc, char **argv)
     struct rx_service *tservice;
     struct rx_securityClass *sc[3];
     extern int RXSTATS_ExecuteRequest();
-    extern int PR_ExecuteRequest();
 #if 0
     struct ktc_encryptionKey tkey;
 #endif
@@ -281,7 +274,14 @@ main(int argc, char **argv)
        int alen;
        lcstring(arg, argv[a], sizeof(arg));
        alen = strlen(arg);
-       if ((strncmp(arg, "-database", alen) == 0)
+       if (strcmp(argv[a], "-d") == 0) {
+           if ((a + 1) >= argc) {
+               fprintf(stderr, "missing argument for -d\n"); 
+               return -1; 
+           }
+           debuglevel = atoi(argv[++a]);
+           LogLevel = debuglevel;
+       } else if ((strncmp(arg, "-database", alen) == 0)
            || (strncmp(arg, "-db", alen) == 0)) {
            pr_dbaseName = argv[++a];   /* specify a database */
        } else if (strncmp(arg, "-p", alen) == 0) {
@@ -313,6 +313,9 @@ main(int argc, char **argv)
        else if (strncmp(arg, "-rxbind", alen) == 0) {
            rxBind = 1;
        }
+       else if (strncmp(arg, "-allow-dotted-principals", alen) == 0) {
+           rxkadDisableDotCheck = 1;
+       }
        else if (strncmp(arg, "-enable_peer_stats", alen) == 0) {
            rx_enablePeerRPCStats();
        } else if (strncmp(arg, "-enable_process_stats", alen) == 0) {
@@ -328,35 +331,10 @@ main(int argc, char **argv)
        }
 #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);
+            osi_audit_file(fileName);
+            osi_audit(PTS_StartEvent, 0, AUD_END);
        }
        else if (!strncmp(arg, "-rxmaxmtu", alen)) {
            if ((a + 1) >= argc) {
@@ -366,7 +344,7 @@ main(int argc, char **argv)
            rxMaxMTU = atoi(argv[++a]);
            if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
                 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
-               printf("rxMaxMTU %d% invalid; must be between %d-%d\n",
+               printf("rxMaxMTU %lu invalid; must be between %d-%d\n",
                        rxMaxMTU, RX_MIN_PACKET_SIZE,
                        RX_MAX_PACKET_DATA_SIZE);
                PT_EXIT(1);
@@ -379,17 +357,19 @@ main(int argc, char **argv)
 #ifndef AFS_NT40_ENV
            printf("Usage: ptserver [-database <db path>] "
                   "[-auditlog <log path>] "
-                  "[-syslog[=FACILITY]] "
+                  "[-syslog[=FACILITY]] [-d <debug level>] "
                   "[-p <number of processes>] [-rebuild] "
                   "[-groupdepth <depth>] "
                   "[-restricted] [-rxmaxmtu <bytes>] [-rxbind] "
+                  "[-allow-dotted-principals] "
                   "[-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>] "
+                  "[-auditlog <log path>] [-d <debug level>] "
                   "[-p <number of processes>] [-rebuild] [-rxbind] "
+                  "[-allow-dotted-principals] "
                   "[-default_access default_user_access default_group_access] "
                   "[-restricted] [-rxmaxmtu <bytes>] [-rxbind] "
                   "[-groupdepth <depth>] " "[-help]\n");
@@ -397,18 +377,20 @@ main(int argc, char **argv)
 #else
 #ifndef AFS_NT40_ENV
            printf("Usage: ptserver [-database <db path>] "
-                  "[-auditlog <log path>] "
+                  "[-auditlog <log path>] [-d <debug level>] "
                   "[-syslog[=FACILITY]] "
                   "[-p <number of processes>] [-rebuild] "
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-default_access default_user_access default_group_access] "
                   "[-restricted] [-rxmaxmtu <bytes>] [-rxbind] "
+                  "[-allow-dotted-principals] "
                   "[-help]\n");
 #else /* AFS_NT40_ENV */
            printf("Usage: ptserver [-database <db path>] "
-                  "[-auditlog <log path>] "
+                  "[-auditlog <log path>] [-d <debug level>] "
                   "[-default_access default_user_access default_group_access] "
                   "[-restricted] [-rxmaxmtu <bytes>] [-rxbind] "
+                  "[-allow-dotted-principals] "
                   "[-p <number of processes>] [-rebuild] " "[-help]\n");
 #endif
 #endif
@@ -459,7 +441,7 @@ main(int argc, char **argv)
     code =
        afsconf_GetExtendedCellInfo(prdir, NULL, "afsprot", &info, &clones);
     if (code) {
-       com_err(whoami, code, "Couldn't get server list");
+       afs_com_err(whoami, code, "Couldn't get server list");
        PT_EXIT(2);
     }
     pr_realmName = info.name;
@@ -469,7 +451,7 @@ main(int argc, char **argv)
     /* get keys */
     code = afsconf_GetKey(prdir, 999, &tkey);
     if (code) {
-       com_err(whoami, code,
+       afs_com_err(whoami, code,
                "couldn't get bcrypt keys from key file, ignoring.");
     }
 #endif
@@ -486,11 +468,11 @@ main(int argc, char **argv)
     if (kerberosKeys) {
        /* initialize ubik */
        ubik_CRXSecurityProc = afsconf_ClientAuth;
-       ubik_CRXSecurityRock = (char *)prdir;
+       ubik_CRXSecurityRock = prdir;
        ubik_SRXSecurityProc = afsconf_ServerAuth;
-       ubik_SRXSecurityRock = (char *)prdir;
+       ubik_SRXSecurityRock = prdir;
        ubik_CheckRXSecurityProc = afsconf_CheckAuth;
-       ubik_CheckRXSecurityRock = (char *)prdir;
+       ubik_CheckRXSecurityRock = prdir;
     }
     /* The max needed is when deleting an entry.  A full CoEntry deletion
      * required removal from 39 entries.  Each of which may refers to the entry
@@ -504,7 +486,6 @@ main(int argc, char **argv)
 
     if (rxBind) {
        afs_int32 ccode;
-#ifndef AFS_NT40_ENV
        if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || 
            AFSDIR_SERVER_NETINFO_FILEPATH) {
            char reason[1024];
@@ -513,21 +494,24 @@ main(int argc, char **argv)
                                           AFSDIR_SERVER_NETINFO_FILEPATH,
                                           AFSDIR_SERVER_NETRESTRICT_FILEPATH);
        } else 
-#endif
        {
            ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
        }
        if (ccode == 1) {
            host = SHostAddrs[0];
+           /* the following call is idempotent so if/when it gets called
+            * again by the ubik init stuff, it doesn't really matter
+            * -- klm
+            */
            rx_InitHost(host, htons(AFSCONF_PROTPORT));
        }
     }
 
     code =
-       ubik_ServerInitByInfo(myHost, htons(AFSCONF_PROTPORT), &info, &clones,
+       ubik_ServerInitByInfo(myHost, htons(AFSCONF_PROTPORT), &info, clones,
                              pr_dbaseName, &dbase);
     if (code) {
-       com_err(whoami, code, "Ubik init failed");
+       afs_com_err(whoami, code, "Ubik init failed");
        PT_EXIT(2);
     }
 #if defined(SUPERGROUPS)
@@ -557,6 +541,10 @@ main(int argc, char **argv)
     }
     rx_SetMinProcs(tservice, 2);
     rx_SetMaxProcs(tservice, lwps);
+    if (rxkadDisableDotCheck) {
+        rx_SetSecurityConfiguration(tservice, RXS_CONFIG_FLAGS,
+                                    (void *)RXS_CONFIG_FLAGS_DISABLE_DOTCHECK);
+    }
 
     tservice =
        rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,