afsconf: Rework security flags
[openafs.git] / src / ptserver / ptserver.c
index 43c206a..997688b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  *                      is a member of (since the entries field is used to
  *                      list it's members). This new field is supergroups and
  *                      has two entries. If more are required, a continuation
- *                      record is formed. 
+ *                      record is formed.
  *                      There are two additional fields required, nextsg is
  *                      an address of the next continuation record for this
- *                      group, and countsg is the count for the number of 
+ *                      group, and countsg is the count for the number of
  *                      groups this group is a member of.
- *                   
+ *
  *
  *
  *      09/18/95 jjm    Add mdw's changes to afs-3.3a Changes:
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
 #include <afs/stds.h>
 #ifdef AFS_AIX32_ENV
@@ -153,7 +154,6 @@ struct afsconf_dir *prdir;
 extern afs_int32 depthsg;
 #endif
 
-int pr_realmNameLen;
 char *pr_realmName;
 
 int debuglevel = 0;
@@ -204,17 +204,13 @@ pr_rxstat_userok(struct rx_call *call)
 int
 main(int argc, char **argv)
 {
-    register afs_int32 code;
-    afs_int32 myHost;
-    register struct hostent *th;
+    afs_int32 code;
+    afs_uint32 myHost;
+    struct hostent *th;
     char hostname[64];
     struct rx_service *tservice;
-    struct rx_securityClass *sc[3];
-    extern int RXSTATS_ExecuteRequest();
-#if 0
-    struct ktc_encryptionKey tkey;
-#endif
-    int kerberosKeys;          /* set if found some keys */
+    struct rx_securityClass **securityClasses;
+    afs_int32 numClasses;
     int lwps = 3;
     char clones[MAXHOSTSPERCELL];
     afs_uint32 host = htonl(INADDR_ANY);
@@ -225,10 +221,12 @@ main(int argc, char **argv)
     int a;
     char arg[100];
 
+    char *auditFileName = NULL;
+
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
@@ -261,7 +259,8 @@ main(int argc, char **argv)
        || (sizeof(struct prentryg) != ENTRYSIZE)) {
        fprintf(stderr,
                "The structures for the database records are different"
-               " sizes\n" "struct prentry = %d\n" "struct prentryg = %d\n"
+               " sizes\n" "struct prentry = %" AFS_SIZET_FMT "\n"
+                "struct prentryg = %" AFS_SIZET_FMT "\n"
                "ENTRYSIZE = %d\n", sizeof(struct prentry),
                sizeof(struct prentryg), ENTRYSIZE);
        PT_EXIT(1);
@@ -274,8 +273,8 @@ main(int argc, char **argv)
        alen = strlen(arg);
        if (strcmp(argv[a], "-d") == 0) {
            if ((a + 1) >= argc) {
-               fprintf(stderr, "missing argument for -d\n"); 
-               return -1; 
+               fprintf(stderr, "missing argument for -d\n");
+               return -1;
            }
            debuglevel = atoi(argv[++a]);
            LogLevel = debuglevel;
@@ -293,15 +292,12 @@ main(int argc, char **argv)
                       lwps, 3);
                lwps = 3;
            }
-       } else if (strncmp(arg, "-rebuild", alen) == 0) /* rebuildDB++ */
-           ;
 #if defined(SUPERGROUPS)
-       else if ((strncmp(arg, "-groupdepth", alen) == 0)
+       } else if ((strncmp(arg, "-groupdepth", alen) == 0)
                 || (strncmp(arg, "-depth", alen) == 0)) {
            depthsg = atoi(argv[++a]);  /* Max search depth for supergroups */
-       }
 #endif
-       else if (strncmp(arg, "-default_access", alen) == 0) {
+       } else if (strncmp(arg, "-default_access", alen) == 0) {
            prp_user_default = prp_access_mask(argv[++a]);
            prp_group_default = prp_access_mask(argv[++a]);
        }
@@ -329,10 +325,14 @@ main(int argc, char **argv)
        }
 #endif
        else if (strncmp(arg, "-auditlog", alen) == 0) {
-           char *fileName = argv[++a];
+           auditFileName = argv[++a];
 
-            osi_audit_file(fileName);
-            osi_audit(PTS_StartEvent, 0, AUD_END);
+       } else if (strncmp(arg, "-audit-interface", alen) == 0) {
+           char *interface = argv[++a];
+           if (osi_audit_interface(interface)) {
+               printf("Invalid audit interface '%s'\n", interface);
+               PT_EXIT(1);
+           }
        }
        else if (!strncmp(arg, "-rxmaxmtu", alen)) {
            if ((a + 1) >= argc) {
@@ -342,12 +342,12 @@ main(int argc, char **argv)
            rxMaxMTU = atoi(argv[++a]);
            if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
                 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
-               printf("rxMaxMTU %lu invalid; must be between %d-%d\n",
+               printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
                        rxMaxMTU, RX_MIN_PACKET_SIZE,
                        RX_MAX_PACKET_DATA_SIZE);
                PT_EXIT(1);
            }
-       } 
+       }
        else if (*arg == '-') {
            /* hack in help flag support */
 
@@ -355,6 +355,7 @@ main(int argc, char **argv)
 #ifndef AFS_NT40_ENV
            printf("Usage: ptserver [-database <db path>] "
                   "[-auditlog <log path>] "
+                  "[-audit-interface <file|sysvmq> (default is file)] "
                   "[-syslog[=FACILITY]] [-d <debug level>] "
                   "[-p <number of processes>] [-rebuild] "
                   "[-groupdepth <depth>] "
@@ -365,7 +366,9 @@ main(int argc, char **argv)
                   "[-help]\n");
 #else /* AFS_NT40_ENV */
            printf("Usage: ptserver [-database <db path>] "
-                  "[-auditlog <log path>] [-d <debug level>] "
+                  "[-auditlog <log path>] "
+                  "[-audit-interface <file|sysvmq> (default is file)] "
+                  "[-d <debug level>] "
                   "[-p <number of processes>] [-rebuild] [-rxbind] "
                   "[-allow-dotted-principals] "
                   "[-default_access default_user_access default_group_access] "
@@ -375,7 +378,9 @@ main(int argc, char **argv)
 #else
 #ifndef AFS_NT40_ENV
            printf("Usage: ptserver [-database <db path>] "
-                  "[-auditlog <log path>] [-d <debug level>] "
+                  "[-auditlog <log path>] "
+                  "[-audit-interface <file|sysvmq> (default is file)] "
+                  "[-d <debug level>] "
                   "[-syslog[=FACILITY]] "
                   "[-p <number of processes>] [-rebuild] "
                   "[-enable_peer_stats] [-enable_process_stats] "
@@ -403,6 +408,11 @@ main(int argc, char **argv)
 #endif
     }
 
+    if (auditFileName) {
+       osi_audit_file(auditFileName);
+       osi_audit(PTS_StartEvent, 0, AUD_END);
+    }
+
 #ifndef AFS_NT40_ENV
     serverLogSyslogTag = "ptserver";
 #endif
@@ -433,45 +443,24 @@ main(int argc, char **argv)
        fprintf(stderr, "ptserver: couldn't get address of this host.\n");
        PT_EXIT(1);
     }
-    memcpy(&myHost, th->h_addr, sizeof(afs_int32));
+    memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
 
     /* get list of servers */
     code =
-       afsconf_GetExtendedCellInfo(prdir, NULL, "afsprot", &info, &clones);
+       afsconf_GetExtendedCellInfo(prdir, NULL, "afsprot", &info, clones);
     if (code) {
        afs_com_err(whoami, code, "Couldn't get server list");
        PT_EXIT(2);
     }
     pr_realmName = info.name;
-    pr_realmNameLen = strlen(pr_realmName);
 
-#if 0
-    /* get keys */
-    code = afsconf_GetKey(prdir, 999, &tkey);
-    if (code) {
-       afs_com_err(whoami, code,
-               "couldn't get bcrypt keys from key file, ignoring.");
-    }
-#endif
-    {
-       afs_int32 kvno;         /* see if there is a KeyFile here */
-       struct ktc_encryptionKey key;
-       code = afsconf_GetLatestKey(prdir, &kvno, &key);
-       kerberosKeys = (code == 0);
-       if (!kerberosKeys)
-           printf
-               ("ptserver: can't find any Kerberos keys, code = %d, ignoring\n",
-                code);
-    }
-    if (kerberosKeys) {
-       /* initialize ubik */
-       ubik_CRXSecurityProc = afsconf_ClientAuth;
-       ubik_CRXSecurityRock = prdir;
-       ubik_SRXSecurityProc = afsconf_ServerAuth;
-       ubik_SRXSecurityRock = prdir;
-       ubik_CheckRXSecurityProc = afsconf_CheckAuth;
-       ubik_CheckRXSecurityRock = prdir;
-    }
+    /* initialize ubik */
+    ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, prdir);
+    ubik_SRXSecurityProc = afsconf_ServerAuth;
+    ubik_SRXSecurityRock = prdir;
+    ubik_CheckRXSecurityProc = afsconf_CheckAuth;
+    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
      * being deleted in one of its CoEntries.  If a CoEntry is freed its
@@ -484,14 +473,14 @@ main(int argc, char **argv)
 
     if (rxBind) {
        afs_int32 ccode;
-       if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || 
+       if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
            AFSDIR_SERVER_NETINFO_FILEPATH) {
            char reason[1024];
            ccode = parseNetFiles(SHostAddrs, NULL, NULL,
                                           ADDRSPERSITE, reason,
                                           AFSDIR_SERVER_NETINFO_FILEPATH,
                                           AFSDIR_SERVER_NETRESTRICT_FILEPATH);
-       } else 
+       } else
        {
            ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
        }
@@ -516,12 +505,7 @@ main(int argc, char **argv)
     pt_hook_write();
 #endif
 
-    sc[0] = rxnull_NewServerSecurityObject();
-    sc[1] = 0;
-    if (kerberosKeys) {
-       sc[2] = rxkad_NewServerSecurityObject(0, prdir, afsconf_GetKey, NULL);
-    } else
-       sc[2] = sc[0];
+    afsconf_BuildServerSecurityObjects(prdir, &securityClasses, &numClasses);
 
     /* Disable jumbograms */
     rx_SetNoJumbo();
@@ -531,8 +515,8 @@ main(int argc, char **argv)
     }
 
     tservice =
-       rx_NewServiceHost(host, 0, PRSRV, "Protection Server", sc, 3,
-                     PR_ExecuteRequest);
+       rx_NewServiceHost(host, 0, PRSRV, "Protection Server", securityClasses,
+                         numClasses, PR_ExecuteRequest);
     if (tservice == (struct rx_service *)0) {
        fprintf(stderr, "ptserver: Could not create new rx service.\n");
        PT_EXIT(3);
@@ -545,8 +529,8 @@ main(int argc, char **argv)
     }
 
     tservice =
-       rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
-                     RXSTATS_ExecuteRequest);
+       rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
+                         securityClasses, numClasses, RXSTATS_ExecuteRequest);
     if (tservice == (struct rx_service *)0) {
        fprintf(stderr, "ptserver: Could not create new rx service.\n");
        PT_EXIT(3);
@@ -557,6 +541,14 @@ main(int argc, char **argv)
     /* allow super users to manage RX statistics */
     rx_SetRxStatUserOk(pr_rxstat_userok);
 
+    LogCommandLine(argc, argv, "ptserver",
+#if defined(SUPERGROUPS)
+                  "1.1",
+#else
+                  "1.0",
+#endif
+                  "Starting AFS", FSLog);
+
     rx_StartServer(1);
     osi_audit(PTS_FinishEvent, -1, AUD_END);
     exit(0);