warn when starting without keys
[openafs.git] / src / budb / server.c
index b61d3df..f35f47f 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
@@ -9,33 +9,13 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
 #ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#include <fcntl.h>
 #include <WINNT/afsevent.h>
-#else
-#include <netinet/in.h>
-#include <sys/file.h>
-#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>
-#include <stdio.h>
 #include <afs/cmd.h>
 #include <lwp.h>
 #include <ubik.h>
@@ -44,30 +24,28 @@ 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>
-#include <errno.h>
-#ifdef AFS_AIX32_ENV
-#include <signal.h>
-#endif
+#include <afs/audit.h>
+
 #include "budb_errs.h"
 #include "database.h"
 #include "error_macros.h"
+#include "budb_internal.h"
 #include "globals.h"
-#include "afs/audit.h"
-
-
-extern afs_int32 ubik_lastYesTime;
-extern afs_int32 ubik_nBuffers;
 
 struct ubik_dbase *BU_dbase;
 struct afsconf_dir *BU_conf;   /* for getting cell info */
 
+int argHandler(struct cmd_syndesc *, void *);
+int truncateDatabase(void);
+int parseServerList(struct cmd_item *);
+
 char lcell[MAXKTCREALMLEN];
-afs_int32 myHost = 0;
+afs_uint32 myHost = 0;
 int helpOption;
+static struct logOptions logopts;
 
 /* server's global configuration information. This is exported to other
  * files/routines
@@ -79,19 +57,43 @@ 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];
+
 /* check whether caller is authorized to manage RX statistics */
 int
-BU_rxstat_userok(call)
-     struct rx_call *call;
+BU_rxstat_userok(struct rx_call *call)
 {
     return afsconf_SuperUser(BU_conf, call, NULL);
 }
 
+/**
+ * Return true if this name is a member of the local realm.
+ */
+int
+BU_IsLocalRealmMatch(void *rock, char *name, char *inst, char *cell)
+{
+    struct afsconf_dir *dir = (struct afsconf_dir *)rock;
+    afs_int32 islocal = 0;     /* default to no */
+    int code;
+
+    code = afsconf_IsLocalRealmMatch(dir, &islocal, name, inst, cell);
+    if (code) {
+       LogError(code, "Failed local realm check; name=%s, inst=%s, cell=%s\n",
+                name, inst, cell);
+    }
+    return islocal;
+}
+
 int
-convert_cell_to_ubik(cellinfo, myHost, serverList)
-     struct afsconf_cell *cellinfo;
-     afs_int32 *myHost;
-     afs_int32 *serverList;
+convert_cell_to_ubik(struct afsconf_cell *cellinfo, afs_uint32 *myHost,
+                    afs_uint32 *serverList)
 {
     int i;
     char hostname[64];
@@ -104,7 +106,7 @@ convert_cell_to_ubik(cellinfo, myHost, serverList)
        printf("prserver: couldn't get address of this host.\n");
        BUDB_EXIT(1);
     }
-    memcpy(myHost, th->h_addr, sizeof(afs_int32));
+    memcpy(myHost, th->h_addr, sizeof(afs_uint32));
 
     for (i = 0; i < cellinfo->numServers; i++)
        /* omit my host from serverList */
@@ -121,8 +123,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(struct cmd_syndesc *as, void *arock)
 {
     helpOption = 0;
     return 0;
@@ -132,15 +133,14 @@ MyBeforeProc(as)
  *     initialize all the supported commands and their arguments
  */
 
-initializeArgHandler()
+void
+initializeArgHandler(void)
 {
     struct cmd_syndesc *cptr;
 
-    int argHandler();
-
     cmd_SetBeforeProc(MyBeforeProc, NULL);
 
-    cptr = cmd_CreateSyntax(NULL, argHandler, NULL, "Backup database server");
+    cptr = cmd_CreateSyntax(NULL, argHandler, NULL, 0, "Backup database server");
 
     cmd_AddParm(cptr, "-database", CMD_SINGLE, CMD_OPTIONAL,
                "database directory");
@@ -163,34 +163,41 @@ initializeArgHandler()
     cmd_AddParm(cptr, "-ubikbuffers", CMD_SINGLE, CMD_OPTIONAL,
                "the number of ubik buffers");
 
+    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)");
+
+    cmd_AddParm(cptr, "-audit-interface", CMD_SINGLE, CMD_OPTIONAL,
+               "audit interface (file or sysvmq)");
+
+    cmd_AddParm(cptr, "-transarc-logs", CMD_FLAG, CMD_OPTIONAL,
+               "enable Transarc style logging");
 }
 
 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 */
 
     /* database directory */
     if (as->parms[0].items != 0) {
-       globalConfPtr->databaseDirectory =
-           (char *)malloc(strlen(as->parms[0].items->data) + 1);
+       globalConfPtr->databaseDirectory = strdup(as->parms[0].items->data);
        if (globalConfPtr->databaseDirectory == 0)
            BUDB_EXIT(-1);
-       strcpy(globalConfPtr->databaseDirectory, as->parms[0].items->data);
     }
 
     /* -cellservdb, cell configuration directory */
     if (as->parms[1].items != 0) {
-       globalConfPtr->cellConfigdir =
-           (char *)malloc(strlen(as->parms[1].items->data) + 1);
+       globalConfPtr->cellConfigdir = strdup(as->parms[1].items->data);
        if (globalConfPtr->cellConfigdir == 0)
            BUDB_EXIT(-1);
 
-       strcpy(globalConfPtr->cellConfigdir, as->parms[1].items->data);
-
        globalConfPtr->debugFlags |= DF_RECHECKNOAUTH;
     }
 
@@ -216,13 +223,59 @@ argHandler(as, arock)
     else
        ubik_nBuffers = 0;
 
+    /* param 7 (-auditlog) handled below */
+
+    /* 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;
+       }
+       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;
+    }
+
+    /* -audit-interface */
+    if (as->parms[10].items != 0) {
+       char *interface = as->parms[10].items->data;
+
+       if (osi_audit_interface(interface)) {
+           printf("Invalid audit interface '%s'\n", interface);
+           BUDB_EXIT(-1);
+       }
+    }
+    /* -transarc-logs */
+    if (as->parms[11].items != 0) {
+       logopts.lopt_rotateOnOpen = 1;
+       logopts.lopt_rotateStyle = logRotate_old;
+    }
+
+    /* -auditlog */
+    /* needs to be after -audit-interface, so we osi_audit_interface
+     * before we osi_audit_file */
+    if (as->parms[7].items != 0) {
+       char *fileName = as->parms[7].items->data;
+
+        osi_audit_file(fileName);
+    }
+
     return 0;
 }
 
 /* --- */
 
-parseServerList(itemPtr)
-     struct cmd_item *itemPtr;
+int
+parseServerList(struct cmd_item *itemPtr)
 {
     struct cmd_item *save;
     char **serverArgs;
@@ -241,7 +294,7 @@ parseServerList(itemPtr)
     LogDebug(3, "%d servers\n", nservers);
 
     /* now can allocate the space for the server arguments */
-    serverArgs = (char **)malloc((nservers + 2) * sizeof(char *));
+    serverArgs = malloc((nservers + 2) * sizeof(char *));
     if (serverArgs == 0)
        ERROR(-1);
 
@@ -263,7 +316,7 @@ parseServerList(itemPtr)
        ERROR(code);
 
     /* free space for the server args */
-    free((char *)serverArgs);
+    free(serverArgs);
 
   error_exit:
     return (code);
@@ -273,24 +326,20 @@ parseServerList(itemPtr)
  *     truncates just the database file.
  */
 
-truncateDatabase()
+int
+truncateDatabase(void)
 {
     char *path;
     afs_int32 code = 0;
-    int fd;
+    int fd,r;
 
-    path =
-       (char *)malloc(strlen(globalConfPtr->databaseDirectory) +
-                      strlen(globalConfPtr->databaseName) +
-                      strlen(globalConfPtr->databaseExtension) + 1);
-    if (path == 0)
+    r = asprintf(&path, "%s%s%s",
+                globalConfPtr->databaseDirectory,
+                globalConfPtr->databaseName,
+                globalConfPtr->databaseExtension);
+    if (r < 0 || path == NULL)
        ERROR(-1);
 
-    /* construct the database name */
-    strcpy(path, globalConfPtr->databaseDirectory);
-    strcat(path, globalConfPtr->databaseName);
-    strcat(path, globalConfPtr->databaseExtension);
-
     fd = open(path, O_RDWR, 0755);
     if (!fd) {
        code = errno;
@@ -301,6 +350,8 @@ truncateDatabase()
            close(fd);
     }
 
+    free(path);
+
   error_exit:
     return (code);
 }
@@ -310,24 +361,26 @@ truncateDatabase()
 
 #include "AFS_component_version_number.c"
 
-main(argc, argv)
-     int argc;
-     char *argv[];
+int
+main(int argc, char **argv)
 {
     char *whoami = argv[0];
     char *dbNamePtr = 0;
-    struct afsconf_cell cellinfo;
+    struct afsconf_cell cellinfo_s;
+    struct afsconf_cell *cellinfo = NULL;
     time_t currentTime;
     afs_int32 code = 0;
+    char hoststr[16];
+    afs_uint32 host = ntohl(INADDR_ANY);
+    int r;
 
-    struct rx_service *tservice;
-    struct rx_securityClass *sca[3];
+    char  clones[MAXHOSTSPERCELL];
 
-    extern int afsconf_ServerAuth();
-    extern int afsconf_CheckAuth();
+    struct rx_service *tservice;
+    struct rx_securityClass **securityClasses;
+    afs_int32 numClasses;
 
     extern int rx_stackSize;
-    extern int BUDB_ExecuteRequest();
 
 #ifdef AFS_NT40_ENV
     /* initialize winsock */
@@ -340,8 +393,8 @@ main(argc, argv)
 
 #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.
      */
@@ -353,6 +406,15 @@ main(argc, argv)
     sigaction(SIGSEGV, &nsa, NULL);
     sigaction(SIGABRT, &nsa, NULL);
 #endif
+
+    memset(&cellinfo_s, 0, sizeof(cellinfo_s));
+    memset(clones, 0, sizeof(clones));
+
+    memset(&logopts, 0, sizeof(logopts));
+    logopts.lopt_dest = logDest_file;
+    logopts.lopt_filename = AFSDIR_SERVER_BUDBLOG_FILEPATH;
+
+    osi_audit_init();
     osi_audit(BUDB_StartEvent, 0, AUD_END);
 
     initialize_BUDB_error_table();
@@ -363,7 +425,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);
     }
 
@@ -377,18 +439,12 @@ main(argc, argv)
     strcpy(cellConfDir, AFSDIR_SERVER_ETC_DIRPATH);
     globalConfPtr->cellConfigdir = cellConfDir;
 
-    /* open the log file */
-/*
-    globalConfPtr->log = fopen(DEFAULT_LOGNAME,"a");
-    if ( globalConfPtr->log == NULL )
-    {   
-       printf("Can't open log file %s - aborting\n", DEFAULT_LOGNAME);
-       BUDB_EXIT(-1);
-    }
-*/
-
     srandom(1);
 
+#ifdef AFS_PTHREAD_ENV
+    SetLogThreadNumProgram( rx_GetThreadNum );
+#endif
+
     /* process the user supplied args */
     helpOption = 1;
     code = cmd_Dispatch(argc, argv);
@@ -400,16 +456,7 @@ main(argc, argv)
        BUDB_EXIT(0);
 
     /* open the log file */
-    globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
-    if (globalConfPtr->log == NULL) {
-       printf("Can't open log file %s - aborting\n",
-              AFSDIR_SERVER_BUDBLOG_FILEPATH);
-       BUDB_EXIT(-1);
-    }
-
-    /* keep log closed so can remove it */
-
-    fclose(globalConfPtr->log);
+    OpenLog(&logopts);
 
     /* open the cell's configuration directory */
     LogDebug(4, "opening %s\n", globalConfPtr->cellConfigdir);
@@ -417,10 +464,16 @@ 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);
     }
 
+    if (afsconf_CountKeys(BU_conf) == 0) {
+       LogError(0, "WARNING: No encryption keys found! "
+                   "All authenticated accesses will fail. "
+                   "Run akeyconvert or asetkey to import encryption keys.\n");
+    }
+
     code = afsconf_GetLocalCell(BU_conf, lcell, sizeof(lcell));
     if (code) {
        LogError(0, "** Can't determine local cell name!\n");
@@ -432,70 +485,107 @@ main(argc, argv)
         * list from the cell's database
         */
 
+       cellinfo = &cellinfo_s;
+
        LogDebug(1, "Using server list from %s cell database.\n", lcell);
 
-       code = afsconf_GetCellInfo(BU_conf, lcell, 0, &cellinfo);
+       code = afsconf_GetExtendedCellInfo (BU_conf, lcell, 0, cellinfo,
+                                           clones);
+       if (code) {
+           LogError(0, "Can't read cell information\n");
+           ERROR(code);
+       }
+
        code =
-           convert_cell_to_ubik(&cellinfo, &globalConfPtr->myHost,
+           convert_cell_to_ubik(cellinfo, &globalConfPtr->myHost,
                                 globalConfPtr->serverList);
        if (code)
            ERROR(code);
     }
 
-    /* initialize ubik */
-    ubik_CRXSecurityProc = afsconf_ClientAuth;
-    ubik_CRXSecurityRock = (char *)BU_conf;
-
-    ubik_SRXSecurityProc = afsconf_ServerAuth;
-    ubik_SRXSecurityRock = (char *)BU_conf;
+    /* initialize audit user check */
+    osi_audit_set_user_check(BU_conf, BU_IsLocalRealmMatch);
 
-    ubik_CheckRXSecurityProc = afsconf_CheckAuth;
-    ubik_CheckRXSecurityRock = (char *)BU_conf;
+    /* initialize ubik */
+    ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, BU_conf);
+    ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects,
+                               afsconf_CheckAuth, BU_conf);
 
     if (ubik_nBuffers == 0)
        ubik_nBuffers = 400;
 
     LogError(0, "Will allocate %d ubik buffers\n", ubik_nBuffers);
 
-    dbNamePtr =
-       (char *)malloc(strlen(globalConfPtr->databaseDirectory) +
-                      strlen(globalConfPtr->databaseName) + 1);
-    if (dbNamePtr == 0)
+    r = asprintf(&dbNamePtr, "%s%s", globalConfPtr->databaseDirectory,
+                globalConfPtr->databaseName);
+    if (r < 0 || dbNamePtr == 0)
        ERROR(-1);
 
-    /* construct the database name */
-    strcpy(dbNamePtr, globalConfPtr->databaseDirectory);
-    strcat(dbNamePtr, globalConfPtr->databaseName);    /* name prefix */
-
     rx_SetRxDeadTime(60);      /* 60 seconds inactive before timeout */
 
-    code = ubik_ServerInit(globalConfPtr->myHost, htons(AFSCONF_BUDBPORT), globalConfPtr->serverList, dbNamePtr,       /* name prefix */
-                          &BU_dbase);
+    if (rxBind) {
+       afs_int32 ccode;
+        if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
+            AFSDIR_SERVER_NETINFO_FILEPATH) {
+            char reason[1024];
+            ccode = afsconf_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];
+       }
+    }
+
+    Log("buserver binding rx to %s:%d\n",
+        afs_inet_ntoa_r(host, hoststr), AFSCONF_BUDBPORT);
+    code = rx_InitHost(host, htons(AFSCONF_BUDBPORT));
     if (code) {
-       LogError(code, "Ubik init failed\n");
-       com_err(whoami, code, "Ubik init failed");
+       LogError(code, "rx init failed\n");
+       afs_com_err(whoami, code, "rx init failed");
        ERROR(code);
     }
 
-    sca[RX_SCINDEX_NULL] = rxnull_NewServerSecurityObject();
-    sca[RX_SCINDEX_VAB] = 0;
-    sca[RX_SCINDEX_KAD] =
-       rxkad_NewServerSecurityObject(rxkad_clear, BU_conf, afsconf_GetKey,
-                                     NULL);
-
     /* Disable jumbograms */
     rx_SetNoJumbo();
 
+    if (cellinfo) {
+       code = ubik_ServerInitByInfo(globalConfPtr->myHost,
+                                    htons(AFSCONF_BUDBPORT),
+                                    cellinfo,
+                                    clones,
+                                    dbNamePtr,           /* name prefix */
+                                    &BU_dbase);
+    } else {
+       code = ubik_ServerInit(globalConfPtr->myHost, htons(AFSCONF_BUDBPORT),
+                              globalConfPtr->serverList,
+                              dbNamePtr,  /* name prefix */
+                              &BU_dbase);
+    }
+
+    if (code) {
+       LogError(code, "Ubik init failed\n");
+       afs_com_err(whoami, code, "Ubik init failed");
+       ERROR(code);
+    }
+
+    afsconf_BuildServerSecurityObjects(BU_conf, &securityClasses, &numClasses);
+
     tservice =
-       rx_NewService(0, BUDB_SERVICE, "BackupDatabase", sca, 3,
-                     BUDB_ExecuteRequest);
+       rx_NewServiceHost(host, 0, BUDB_SERVICE, "BackupDatabase",
+                         securityClasses, numClasses, BUDB_ExecuteRequest);
+
     if (tservice == (struct rx_service *)0) {
        LogError(0, "Could not create backup database rx service\n");
        printf("Could not create backup database rx service\n");
        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 */
@@ -517,15 +607,15 @@ 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);
 }
 
-
-consistencyCheckDb()
+void
+consistencyCheckDb(void)
 {
     /* do consistency checks on structure sizes */
     if ((sizeof(struct htBlock) > BLOCKSIZE)
@@ -539,91 +629,46 @@ consistencyCheckDb()
     }
 }
 
- /*VARARGS*/
-LogDebug(level, a, b, c, d, e, f, g, h, i)
-     int level;
-     char *a, *b, *c, *d, *e, *f, *g, *h, *i;
+void
+LogDebug(int level, char *fmt, ... )
 {
-
     if (debugging >= level) {
-       /* log normally closed so can remove it */
-       globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
-       if (globalConfPtr->log != NULL) {
-           fprintf(globalConfPtr->log, a, b, c, d, e, f, g, h, i);
-           fflush(globalConfPtr->log);
-           fclose(globalConfPtr->log);
-       }
+       va_list ap;
+       va_start(ap, fmt);
+       vFSLog(fmt, ap);
+       va_end(ap);
     }
 }
 
-static char *
-TimeStamp(time_t t)
+void
+Log(char *fmt, ...)
 {
-    struct tm *lt;
-    static char timestamp[20];
+    va_list ap;
 
-    lt = localtime(&t);
-    strftime(timestamp, 20, "%m/%d/%Y %T", lt);
-    return timestamp;
+    va_start(ap, fmt);
+    vFSLog(fmt, ap);
+    va_end(ap);
 }
 
- /*VARARGS*/
-Log(a, b, c, d, e, f, g, h, i)
-     char *a, *b, *c, *d, *e, *f, *g, *h, *i;
+void
+LogError(long code, char *fmt, ... )
 {
-    time_t now;
-
-    globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
-    if (globalConfPtr->log != NULL) {
-       now = time(0);
-       fprintf(globalConfPtr->log, "%s ", TimeStamp(now));
-
-       fprintf(globalConfPtr->log, a, b, c, d, e, f, g, h, i);
-       fflush(globalConfPtr->log);
-       fclose(globalConfPtr->log);
-    }
-}
-
- /*VARARGS*/
-LogError(code, a, b, c, d, e, f, g, h, i)
-     long code;
-     char *a, *b, *c, *d, *e, *f, *g, *h, *i;
-{
-    time_t now;
-
-    globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
-
-    if (globalConfPtr->log != NULL) {
-       now = time(0);
-       fprintf(globalConfPtr->log, "%s ", TimeStamp(now));
-
-       if (code)
-           fprintf(globalConfPtr->log, "%s: %s\n", error_table_name(code),
-                   error_message(code));
-       fprintf(globalConfPtr->log, a, b, c, d, e, f, g, h, i);
-       fflush(globalConfPtr->log);
-       fclose(globalConfPtr->log);
+    va_list ap;
+    int len;
+    char buffer[1024];
+
+    va_start(ap, fmt);
+    len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
+    va_end(ap);
+    if (len >= 1024) {
+       len = 1023;
+       buffer[1023] = '\0';
     }
-}
-
-
-/*  ----------------
- * debug
- * ----------------
- */
-
-
-LogNetDump(dumpPtr)
-     struct dump *dumpPtr;
-{
-    struct dump hostDump;
-    extern buServerConfP globalConfPtr;
-
-    dump_ntoh(dumpPtr, &hostDump);
-
-    globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a");
-    if (globalConfPtr->log != NULL) {
-       printDump(globalConfPtr->log, &hostDump);
-       fclose(globalConfPtr->log);
+    /* Be consistent with (unintentional?) historic behavior. */
+    if (code) {
+       FSLog("%s: %s\n", afs_error_table_name(code), afs_error_message(code));
+       WriteLogBuffer(buffer, len);
+    } else {
+       FSLog("%s", buffer);
     }
 }