afsconf: Rework security flags
[openafs.git] / src / vlserver / vlserver.c
index e0a2319..93fa6d1 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
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
 #include <afs/stds.h>
 #include <sys/types.h>
 #include <signal.h>
 #include <sys/stat.h>
+#include <string.h>
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
@@ -35,26 +35,24 @@ RCSID
 #include <netinet/in.h>
 #endif
 #include <stdio.h>
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
 #endif
 
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rx_globals.h>
+#include <rx/rxstat.h>
 #include <afs/cellconfig.h>
 #include <afs/keys.h>
 #include <afs/auth.h>
+#include <afs/audit.h>
+#include <afs/com_err.h>
 #include <lock.h>
 #include <ubik.h>
 #include <afs/afsutil.h>
 #include "vlserver.h"
-
+#include "vlserver_internal.h"
 
 #define MAXLWP 16
 const char *vl_dbaseName;
@@ -63,50 +61,55 @@ int lwps = 9;
 
 struct vldstats dynamic_statistics;
 struct ubik_dbase *VL_dbase;
-afs_uint32 HostAddress[MAXSERVERID + 1];
-extern int afsconf_CheckAuth();
-extern int afsconf_ServerAuth();
+afs_uint32 rd_HostAddress[MAXSERVERID + 1];
+afs_uint32 wr_HostAddress[MAXSERVERID + 1];
 
-static CheckSignal();
+static void *CheckSignal(void*);
 int LogLevel = 0;
 int smallMem = 0;
-int rxJumbograms = 1;          /* default is to send and receive jumbo grams */
+int rxJumbograms = 0;          /* default is to not send and receive jumbo grams */
 int rxMaxMTU = -1;
 afs_int32 rxBind = 0;
+int rxkadDisableDotCheck = 0;
+int debuglevel = 0;
 
 #define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
 afs_uint32 SHostAddrs[ADDRSPERSITE];
 
 static void
-CheckSignal_Signal()
+CheckSignal_Signal(int unused)
 {
+#if defined(AFS_PTHREAD_ENV)
+    CheckSignal(0);
+#else
     IOMGR_SoftSig(CheckSignal, 0);
+#endif
 }
 
-static
-CheckSignal()
+static void *
+CheckSignal(void *unused)
 {
-    register int i, errorcode;
-    struct ubik_trans *trans;
+    int i, errorcode;
+    struct vl_ctx ctx;
 
-    if (errorcode =
-       Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))
-       return errorcode;
+    if ((errorcode =
+       Init_VLdbase(&ctx, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE)))
+       return (void *)(intptr_t)errorcode;
     VLog(0, ("Dump name hash table out\n"));
     for (i = 0; i < HASHSIZE; i++) {
-       HashNDump(trans, i);
+       HashNDump(&ctx, i);
     }
     VLog(0, ("Dump id hash table out\n"));
     for (i = 0; i < HASHSIZE; i++) {
-       HashIdDump(trans, i);
+       HashIdDump(&ctx, i);
     }
-    return (ubik_EndTrans(trans));
+    return ((void *)(intptr_t)ubik_EndTrans(ctx.trans));
 }                              /*CheckSignal */
 
 
 /* Initialize the stats for the opcodes */
 void
-initialize_dstats()
+initialize_dstats(void)
 {
     int i;
 
@@ -119,8 +122,7 @@ initialize_dstats()
 
 /* check whether caller is authorized to manage RX statistics */
 int
-vldb_rxstat_userok(call)
-     struct rx_call *call;
+vldb_rxstat_userok(struct rx_call *call)
 {
     return afsconf_SuperUser(vldb_confdir, call, NULL);
 }
@@ -129,31 +131,28 @@ vldb_rxstat_userok(call)
 
 #include "AFS_component_version_number.c"
 
-main(argc, argv)
-     int argc;
-     char **argv;
+int
+main(int argc, char **argv)
 {
-    register afs_int32 code;
-    afs_int32 myHost;
+    afs_int32 code;
+    afs_uint32 myHost;
     struct rx_service *tservice;
-    struct rx_securityClass *sc[3];
-    extern int VL_ExecuteRequest();
-    extern int RXSTATS_ExecuteRequest();
+    struct rx_securityClass **securityClasses;
+    afs_int32 numClasses;
     struct afsconf_dir *tdir;
     struct ktc_encryptionKey tkey;
     struct afsconf_cell info;
     struct hostent *th;
     char hostname[VL_MAXNAMELEN];
-    int noAuth = 0, index, i;
-    extern int rx_extraPackets;
-    char commandLine[150];
+    int noAuth = 0, index;
     char clones[MAXHOSTSPERCELL];
+    char *auditFileName = NULL;
     afs_uint32 host = ntohl(INADDR_ANY);
 
 #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.
      */
@@ -172,7 +171,6 @@ main(argc, argv)
     for (index = 1; index < argc; index++) {
        if (strcmp(argv[index], "-noauth") == 0) {
            noAuth = 1;
-
        } else if (strcmp(argv[index], "-p") == 0) {
            lwps = atoi(argv[++index]);
            if (lwps > MAXLWP) {
@@ -180,23 +178,31 @@ main(argc, argv)
                       lwps, MAXLWP);
                lwps = MAXLWP;
            }
-
+       } else if (strcmp(argv[index], "-d") == 0) {
+           if ((index + 1) >= argc) {
+               fprintf(stderr, "missing argument for -d\n");
+               return -1;
+           }
+           debuglevel = atoi(argv[++index]);
+           LogLevel = debuglevel;
        } else if (strcmp(argv[index], "-nojumbo") == 0) {
            rxJumbograms = 0;
-
+       } else if (strcmp(argv[index], "-jumbo") == 0) {
+           rxJumbograms = 1;
        } else if (strcmp(argv[index], "-rxbind") == 0) {
            rxBind = 1;
-
+       } else if (strcmp(argv[index], "-allow-dotted-principals") == 0) {
+           rxkadDisableDotCheck = 1;
        } else if (!strcmp(argv[index], "-rxmaxmtu")) {
            if ((index + 1) >= argc) {
-               fprintf(stderr, "missing argument for -rxmaxmtu\n"); 
-               return -1; 
+               fprintf(stderr, "missing argument for -rxmaxmtu\n");
+               return -1;
            }
-           rxMaxMTU = atoi(argv[++i]);
-           if ((rxMaxMTU < RX_MIN_PACKET_SIZE) || 
+           rxMaxMTU = atoi(argv[++index]);
+           if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
                (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
-               printf("rxMaxMTU %d% invalid; must be between %d-%d\n",
-                      rxMaxMTU, RX_MIN_PACKET_SIZE, 
+               printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n",
+                      rxMaxMTU, RX_MIN_PACKET_SIZE,
                       RX_MAX_PACKET_DATA_SIZE);
                return -1;
            }
@@ -208,35 +214,17 @@ main(argc, argv)
            extern char rxi_tracename[80];
            strcpy(rxi_tracename, argv[++index]);
 
-       } else if (strcmp(argv[index], "-auditlog") == 0) {
-          int tempfd, flags;
-           FILE *auditout;
-           char oldName[MAXPATHLEN];
-           char *fileName = argv[++index];
+       } else if (strcmp(argv[index], "-auditlog") == 0) {
+           auditFileName = argv[++index];
 
-#ifndef AFS_NT40_ENV
-           struct stat statbuf;
+       } else if (strcmp(argv[index], "-audit-interface") == 0) {
+           char *interface = argv[++index];
+
+           if (osi_audit_interface(interface)) {
+               printf("Invalid audit interface '%s'\n", interface);
+               return -1;
+           }
 
-           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);
-               } else
-                   printf("Warning: auditlog %s not writable, ignored.\n", fileName);
-           } else
-               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
        } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
            rx_enablePeerRPCStats();
        } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
@@ -253,15 +241,15 @@ main(argc, argv)
            /* support help flag */
 #ifndef AFS_NT40_ENV
            printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
-                  "[-rxmaxmtu <bytes>] [-rxbind] "
-                  "[-auditlog <log path>] "
+                  "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
+                  "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
                   "[-syslog[=FACILITY]] "
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-help]\n");
 #else
            printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
-                  "[-rxmaxmtu <bytes>] [-rxbind] "
-                  "[-auditlog <log path>] "
+                  "[-rxmaxmtu <bytes>] [-rxbind] [-allow-dotted-principals] "
+                  "[-auditlog <log path>] [-jumbo] [-d <debug level>] "
                   "[-enable_peer_stats] [-enable_process_stats] "
                   "[-help]\n");
 #endif
@@ -270,6 +258,10 @@ main(argc, argv)
        }
     }
 
+    if (auditFileName) {
+       osi_audit_file(auditFileName);
+    }
+
     /* Initialize dirpaths */
     if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
 #ifdef AFS_NT40_ENV
@@ -310,15 +302,15 @@ main(argc, argv)
               hostname);
        exit(1);
     }
-    memcpy(&myHost, th->h_addr, sizeof(afs_int32));
+    memcpy(&myHost, th->h_addr, sizeof(afs_uint32));
 
-#if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_DJGPP_ENV)
+#if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV)
     signal(SIGXCPU, CheckSignal_Signal);
 #endif
     /* get list of servers */
     code =
        afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
-                                   &clones);
+                                   clones);
     if (code) {
        printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
        exit(2);
@@ -333,14 +325,17 @@ main(argc, argv)
 
     if (rxBind) {
        afs_int32 ccode;
-        if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || 
+#ifndef AFS_NT40_ENV
+        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
+#endif
+       {
             ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
         }
         if (ccode == 1) {
@@ -350,17 +345,17 @@ main(argc, argv)
     }
 
     ubik_nBuffers = 512;
-    ubik_CRXSecurityProc = afsconf_ClientAuth;
-    ubik_CRXSecurityRock = (char *)tdir;
+    ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, tdir);
     ubik_SRXSecurityProc = afsconf_ServerAuth;
     ubik_SRXSecurityRock = (char *)tdir;
     ubik_CheckRXSecurityProc = afsconf_CheckAuth;
     ubik_CheckRXSecurityRock = (char *)tdir;
+    ubik_SyncWriterCacheProc = vlsynccache;
     code =
-       ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones,
+       ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, clones,
                              vl_dbaseName, &VL_dbase);
     if (code) {
-       printf("vlserver: Ubik init failed with code %d\n", code);
+       printf("vlserver: Ubik init failed: %s\n", afs_error_message(code));
        exit(2);
     }
     if (!rxJumbograms) {
@@ -371,16 +366,16 @@ main(argc, argv)
     }
     rx_SetRxDeadTime(50);
 
-    memset(HostAddress, 0, sizeof(HostAddress));
+    memset(rd_HostAddress, 0, sizeof(rd_HostAddress));
+    memset(wr_HostAddress, 0, sizeof(wr_HostAddress));
     initialize_dstats();
 
-    sc[0] = rxnull_NewServerSecurityObject();
-    sc[1] = (struct rx_securityClass *)0;
-    sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
+    afsconf_BuildServerSecurityObjects(tdir, &securityClasses, &numClasses);
 
     tservice =
-       rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", sc, 3,
-                     VL_ExecuteRequest);
+       rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server",
+                         securityClasses, numClasses,
+                         VL_ExecuteRequest);
     if (tservice == (struct rx_service *)0) {
        printf("vlserver: Could not create VLDB_SERVICE rx service\n");
        exit(3);
@@ -390,9 +385,15 @@ main(argc, argv)
        lwps = 4;
     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,
-                     RXSTATS_ExecuteRequest);
+       rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats",
+                         securityClasses, numClasses,
+                         RXSTATS_ExecuteRequest);
     if (tservice == (struct rx_service *)0) {
        printf("vlserver: Could not create rpc stats rx service\n");
        exit(3);
@@ -400,17 +401,13 @@ main(argc, argv)
     rx_SetMinProcs(tservice, 2);
     rx_SetMaxProcs(tservice, 4);
 
-    for (commandLine[0] = '\0', i = 0; i < argc; i++) {
-       if (i > 0)
-           strcat(commandLine, " ");
-       strcat(commandLine, argv[i]);
-    }
-    ViceLog(0,
-           ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
+    LogCommandLine(argc, argv, "vlserver", VldbVersion, "Starting AFS", FSLog);
     printf("%s\n", cml_version_number);        /* Goes to the log */
 
     /* allow super users to manage RX statistics */
     rx_SetRxStatUserOk(vldb_rxstat_userok);
 
     rx_StartServer(1);         /* Why waste this idle process?? */
+
+    return 0; /* not reachable */
 }