audit-consolidate-open-20081217
[openafs.git] / src / budb / server.c
index 6dddc8a..feb99d0 100644 (file)
@@ -24,15 +24,7 @@ RCSID
 #include <sys/time.h>
 #include <netdb.h>
 #endif
-
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-
 #include <afs/stds.h>
 #include <sys/types.h>
 #include <time.h>
@@ -45,7 +37,6 @@ RCSID
 #include <rx/rxkad.h>
 #include <rx/rx_globals.h>
 #include <afs/cellconfig.h>
-#include <afs/auth.h>
 #include <afs/bubasics.h>
 #include <afs/afsutil.h>
 #include <afs/com_err.h>
@@ -62,6 +53,8 @@ RCSID
 struct ubik_dbase *BU_dbase;
 struct afsconf_dir *BU_conf;   /* for getting cell info */
 
+int argHandler(struct cmd_syndesc *, void *);
+
 char lcell[MAXKTCREALMLEN];
 afs_int32 myHost = 0;
 int helpOption;
@@ -76,6 +69,15 @@ char dbDir[AFSDIR_PATH_MAX], cellConfDir[AFSDIR_PATH_MAX];
 /* debugging control */
 int debugging = 0;
 
+int rxBind = 0;
+int lwps   = 3;
+
+#define MINLWP  3
+#define MAXLWP 16
+
+#define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
+afs_uint32 SHostAddrs[ADDRSPERSITE];
+
 #if defined(AFS_PTHREAD_ENV)
 char *
 threadNum(void)
@@ -126,8 +128,7 @@ convert_cell_to_ubik(cellinfo, myHost, serverList)
  *      If it were, this routine would never have been called.
  */
 static int
-MyBeforeProc(as)
-     register struct cmd_syndesc *as;
+MyBeforeProc(register struct cmd_syndesc *as, void *arock)
 {
     helpOption = 0;
     return 0;
@@ -137,12 +138,11 @@ MyBeforeProc(as)
  *     initialize all the supported commands and their arguments
  */
 
+void
 initializeArgHandler()
 {
     struct cmd_syndesc *cptr;
 
-    int argHandler();
-
     cmd_SetBeforeProc(MyBeforeProc, NULL);
 
     cptr = cmd_CreateSyntax(NULL, argHandler, NULL, "Backup database server");
@@ -171,12 +171,16 @@ initializeArgHandler()
     cmd_AddParm(cptr, "-auditlog", CMD_SINGLE, CMD_OPTIONAL,
                "audit log path");
 
+    cmd_AddParm(cptr, "-p", CMD_SINGLE, CMD_OPTIONAL,
+               "number of processes");
+
+    cmd_AddParm(cptr, "-rxbind", CMD_FLAG, CMD_OPTIONAL,
+               "bind the Rx socket (primary interface only)");
+
 }
 
 int
-argHandler(as, arock)
-     struct cmd_syndesc *as;
-     char *arock;
+argHandler(struct cmd_syndesc *as, void *arock)
 {
 
     /* globalConfPtr provides the handle for the configuration information */
@@ -225,33 +229,29 @@ argHandler(as, arock)
        ubik_nBuffers = 0;
 
     if (as->parms[7].items != 0) {
-       int tempfd, flags;
-       FILE *auditout;
-       char oldName[MAXPATHLEN];
        char *fileName = as->parms[7].items->data;
-#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;
+        osi_audit_file(fileName);
+    }
+
+    /* user provided the number of threads    */
+    if (as->parms[8].items != 0) {
+       lwps = atoi(as->parms[8].items->data);
+       if (lwps > MAXLWP) {
+           printf ("Warning: '-p %d' is too big; using %d instead\n",
+               lwps, MAXLWP);
+           lwps = MAXLWP;
        }
-       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);
+       if (lwps < MINLWP) {
+           printf ("Warning: '-p %d' is too small; using %d instead\n",
+               lwps, MINLWP);
+           lwps = MINLWP;
+       }
+    }
+
+    /* user provided rxbind option    */
+    if (as->parms[9].items != 0) {
+       rxBind = 1;
     }
 
     return 0;
@@ -357,11 +357,10 @@ main(argc, argv)
     struct afsconf_cell cellinfo;
     time_t currentTime;
     afs_int32 code = 0;
+    afs_uint32 host = ntohl(INADDR_ANY);
 
     char  clones[MAXHOSTSPERCELL];
 
-       
-       
     struct rx_service *tservice;
     struct rx_securityClass *sca[3];
 
@@ -395,6 +394,7 @@ main(argc, argv)
     sigaction(SIGSEGV, &nsa, NULL);
     sigaction(SIGABRT, &nsa, NULL);
 #endif
+    osi_audit_init();
     osi_audit(BUDB_StartEvent, 0, AUD_END);
 
     initialize_BUDB_error_table();
@@ -405,7 +405,7 @@ main(argc, argv)
 #ifdef AFS_NT40_ENV
        ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
 #endif
-       com_err(whoami, errno, "; Unable to obtain AFS server directory.");
+       afs_com_err(whoami, errno, "; Unable to obtain AFS server directory.");
        exit(2);
     }
 
@@ -463,7 +463,7 @@ main(argc, argv)
     BU_conf = afsconf_Open(globalConfPtr->cellConfigdir);
     if (BU_conf == 0) {
        LogError(code, "Failed getting cell info\n");
-       com_err(whoami, code, "Failed getting cell info");
+       afs_com_err(whoami, code, "Failed getting cell info");
        ERROR(BUDB_NOCELLS);
     }
 
@@ -516,6 +516,25 @@ main(argc, argv)
 
     rx_SetRxDeadTime(60);      /* 60 seconds inactive before timeout */
 
+    if (rxBind) {
+       afs_int32 ccode;
+        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 
+       {
+            ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
+        }
+        if (ccode == 1) {
+            host = SHostAddrs[0];
+           rx_InitHost(host, htons(AFSCONF_BUDBPORT));
+       }
+    }
+
     code = ubik_ServerInitByInfo (globalConfPtr->myHost,
                                  htons(AFSCONF_BUDBPORT), 
                                  &cellinfo,
@@ -525,7 +544,7 @@ main(argc, argv)
 
     if (code) {
        LogError(code, "Ubik init failed\n");
-       com_err(whoami, code, "Ubik init failed");
+       afs_com_err(whoami, code, "Ubik init failed");
        ERROR(code);
     }
 
@@ -539,7 +558,7 @@ main(argc, argv)
     rx_SetNoJumbo();
 
     tservice =
-       rx_NewService(0, BUDB_SERVICE, "BackupDatabase", sca, 3,
+       rx_NewServiceHost(host, 0, BUDB_SERVICE, "BackupDatabase", sca, 3,
                      BUDB_ExecuteRequest);
     if (tservice == (struct rx_service *)0) {
        LogError(0, "Could not create backup database rx service\n");
@@ -547,7 +566,7 @@ main(argc, argv)
        BUDB_EXIT(3);
     }
     rx_SetMinProcs(tservice, 1);
-    rx_SetMaxProcs(tservice, 3);
+    rx_SetMaxProcs(tservice, lwps);
     rx_SetStackSize(tservice, 10000);
 
     /* allow super users to manage RX statistics */
@@ -569,14 +588,14 @@ main(argc, argv)
     currentTime = time(0);
     LogError(0, "Ready to process requests at %s\n", ctime(&currentTime));
 
-    rx_ServerProc();           /* donate this LWP */
+    rx_ServerProc(NULL);               /* donate this LWP */
 
   error_exit:
     osi_audit(BUDB_FinishEvent, code, AUD_END);
     return (code);
 }
 
-
+void
 consistencyCheckDb()
 {
     /* do consistency checks on structure sizes */
@@ -616,7 +635,7 @@ TimeStamp(time_t t)
     static char timestamp[20];
 
     lt = localtime(&t);
-    strftime(timestamp, 20, "%m/%d/%Y %T", lt);
+    strftime(timestamp, 20, "%m/%d/%Y %H:%M:%S", lt);
     return timestamp;
 }
 
@@ -652,8 +671,8 @@ LogError(code, a, b, c, d, e, f, g, h, i)
        fprintf(globalConfPtr->log, "%s ", TimeStamp(now));
 
        if (code)
-           fprintf(globalConfPtr->log, "%s: %s\n", error_table_name(code),
-                   error_message(code));
+           fprintf(globalConfPtr->log, "%s: %s\n", afs_error_table_name(code),
+                   afs_error_message(code));
        fprintf(globalConfPtr->log, a, b, c, d, e, f, g, h, i);
        fflush(globalConfPtr->log);
        fclose(globalConfPtr->log);