OPENAFS-SA-2018-001 butc: remove dummy osi_audit() routine
[openafs.git] / src / butc / tcmain.c
index 67d4088..89b711a 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>
 
+#include <afs/procmgmt.h>
+
+#include <roken.h>
+#include <afs/opr.h>
+
 #ifdef IGNORE_SOME_GCC_WARNINGS
 # pragma GCC diagnostic warning "-Wimplicit-function-declaration"
 #endif
 
-#include <sys/types.h>
-#include <sys/stat.h>
 #ifdef AFS_NT40_ENV
-#include <winsock2.h>
 #include <WINNT/afsevent.h>
-#else
-#include <netinet/in.h>
-#include <sys/time.h>
 #endif
-#include <afs/procmgmt.h>
+
+#include <ctype.h>
+
+#include <rx/rx.h>
+#include <rx/rx_globals.h>
+#include <rx/rxkad.h>
 #include <rx/xdr.h>
+
 #include <afs/afsint.h>
-#include <stdio.h>
-#ifdef AFS_PTHREAD_ENV
-#include <assert.h>
-#else
-#include <afs/assert.h>
-#endif
 #include <afs/prs_fs.h>
 #include <afs/nfs.h>
-#include <string.h>
 #include <afs/vlserver.h>
 #include <lwp.h>
 #include <lock.h>
 #include <afs/afsutil.h>
-#include <rx/rx.h>
-#include <rx/rx_globals.h>
-#include <rx/rxkad.h>
 #include <afs/cellconfig.h>
 #include <afs/keys.h>
 #include <afs/volser.h>
 #include <ubik.h>
 #include <afs/com_err.h>
-#include <errno.h>
 #include <afs/cmd.h>
 #include <afs/tcdata.h>
 #include <afs/bubasics.h>
-#include <ctype.h>
-#include "error_macros.h"
 #include <afs/budb_errs.h>
 #include <afs/budb_client.h>
 #include <afs/bucoord_prototypes.h>
-#include "afs/butx.h"
+#include <afs/butx.h>
+#include <afs/kautils.h>
+#include <afs/bc.h>
+
+#include "error_macros.h"
 #define XBSA_TCMAIN
 #include "butc_xbsa.h"
 #include "butc_prototypes.h"
-#include <afs/kautils.h>
-#include <afs/bc.h>
+#include "butc_internal.h"
 
 #define N_SECURITY_OBJECTS 3
 #define ERRCODE_RANGE 8                /* from error_table.h */
@@ -114,19 +109,11 @@ int rxBind = 0;
 #define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
 afs_uint32 SHostAddrs[ADDRSPERSITE];
 
-/* dummy routine for the audit work.  It should do nothing since audits */
-/* occur at the server level and bos is not a server. */
-int
-osi_audit(void)
-{
-    return 0;
-}
-
 static afs_int32
-SafeATOL(register char *anum)
+SafeATOL(char *anum)
 {
-    register afs_int32 total;
-    register int tc;
+    afs_int32 total;
+    int tc;
 
     total = 0;
     while ((tc = *anum)) {
@@ -294,10 +281,9 @@ stringNowReplace(char *logFile, char *deviceName)
        *pos = '_';
     strcat(logFile, deviceName);
     /* now put back deviceName to the way it was */
-    if (mvFlag) {
-       mvFlag = 0;
+    if (mvFlag)
        deviceName -= devPrefLen;
-    }
+
     strcpy(deviceName, storeDevice);
 
     return (0);
@@ -520,8 +506,7 @@ GetConfigParams(char *filename, afs_int32 port)
                continue;
            }
 
-           opencallout = (char *)malloc(strlen(value) + 1);
-           strcpy(opencallout, value);
+           opencallout = strdup(value);
            printf("Tape mount callout routine is %s\n", opencallout);
        }
 
@@ -533,8 +518,7 @@ GetConfigParams(char *filename, afs_int32 port)
                continue;
            }
 
-           closecallout = (char *)malloc(strlen(value) + 1);
-           strcpy(closecallout, value);
+           closecallout = strdup(value);
            printf("Tape unmount callout routine is %s\n", closecallout);
        }
 
@@ -667,8 +651,7 @@ GetConfigParams(char *filename, afs_int32 port)
                     cmd);
                continue;
            }
-           xbsaObjectOwner = malloc(strlen(value) + 1);
-           strcpy(xbsaObjectOwner, value);
+           xbsaObjectOwner = strdup(value);
            printf("XBSA node is %s\n", xbsaObjectOwner);
        }
 
@@ -679,8 +662,7 @@ GetConfigParams(char *filename, afs_int32 port)
                     cmd);
                continue;
            }
-           adsmServerName = malloc(strlen(value) + 1);
-           strcpy(adsmServerName, value);
+           adsmServerName = strdup(value);
            printf("XBSA server is %s\n", adsmServerName);
        }
 
@@ -698,8 +680,7 @@ GetConfigParams(char *filename, afs_int32 port)
                continue;
            }
 
-           xbsaSecToken = malloc(strlen(value) + 1);
-           strcpy(xbsaSecToken, value);
+           xbsaSecToken = strdup(value);
            printf("XBSA Password has been read\n");
        }
 
@@ -742,8 +723,7 @@ GetConfigParams(char *filename, afs_int32 port)
                     cmd);
                continue;
            }
-           xbsalGName = malloc(strlen(value) + 1);
-           strcpy(xbsalGName, value);
+           xbsalGName = strdup(value);
            printf("XBSA management class is %s\n", xbsalGName);
        }
 #endif
@@ -777,8 +757,7 @@ GetConfigParams(char *filename, afs_int32 port)
        }
 
        else if (!strcmp(cmd, "CENTRALLOG")) {
-           centralLogFile = malloc(strlen(value) + 1);
-           strcpy(centralLogFile, value);
+           centralLogFile = strdup(value);
            printf("Central log file is %s\n", centralLogFile);
        }
 
@@ -835,11 +814,20 @@ GetConfigParams(char *filename, afs_int32 port)
     return (code);
 }
 
+#ifdef xbsa
+static void
+xbsa_shutdown(int x)
+{
+    xbsa_Finalize(&butxInfo);
+    exit(0);
+}
+#endif
+
 static int
 WorkerBee(struct cmd_syndesc *as, void *arock)
 {
-    register afs_int32 code;
-    struct rx_securityClass *(securityObjects[3]);
+    afs_int32 code;
+    struct rx_securityClass *(securityObjects[1]);
     struct rx_service *service;
     time_t tokenExpires;
     char cellName[64];
@@ -909,9 +897,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
     }
 
     if (as->parms[6].items) {  /* -restoretofile */
-       int s = strlen(as->parms[6].items->data);
-       restoretofile = malloc(s + 1);
-       strncpy(restoretofile, as->parms[6].items->data, s + 1);
+       restoretofile = strdup(as->parms[6].items->data);
        printf("Restore to file '%s'\n", restoretofile);
     }
 
@@ -961,7 +947,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
        struct stat sbuf;
        afs_int32 statcode;
 #ifndef AFS_NT40_ENV
-       char path[AFSDIR_PATH_MAX];
+       char *path;
 #endif
 
        statcode = stat(centralLogFile, &sbuf);
@@ -973,7 +959,8 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
        }
 #ifndef AFS_NT40_ENV
        /* Make sure it is not in AFS, has to have been created first */
-       if (!realpath(centralLogFile, path)) {
+       path = malloc(AFSDIR_PATH_MAX);
+       if (path == NULL || !realpath(centralLogFile, path)) {
            fprintf(stderr,
                    "Warning: can't determine real path of '%s' (%d)\n",
                    centralLogFile, errno);
@@ -984,6 +971,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
                exit(1);
            }
        }
+       free(path);
 #endif
 
        /* Write header if created it */
@@ -1023,6 +1011,8 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
        rc = InitToServer(0 /*taskid */ , &butxInfo, adsmServerName);
        if (rc != XBSA_SUCCESS)
            return (1);
+       (void)signal(SIGINT, xbsa_shutdown);
+       (void)signal(SIGHUP, xbsa_shutdown);
     }
 #endif /*xbsa */
 
@@ -1040,18 +1030,18 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
 
     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 
+            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) 
+        if (ccode == 1)
             host = SHostAddrs[0];
     }
 
@@ -1075,8 +1065,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
     /*initialize the dumpNode list */
     InitNodeList(portOffset);
 
-    deviceLatch =
-       (struct deviceSyncNode *)(malloc(sizeof(struct deviceSyncNode)));
+    deviceLatch = malloc(sizeof(struct deviceSyncNode));
     Lock_Init(&(deviceLatch->lock));
     deviceLatch->flags = 0;
 
@@ -1084,18 +1073,17 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
 
     /* Create a single security object, in this case the null security
      * object, for unauthenticated connections, which will be used to control
-     * security on connections made to this server 
+     * security on connections made to this server
      */
 
-    securityObjects[0] = rxnull_NewServerSecurityObject();
-    securityObjects[1] = (struct rx_securityClass *)0; /* don't bother with rxvab */
-    if (!securityObjects[0]) {
+    securityObjects[RX_SECIDX_NULL] = rxnull_NewServerSecurityObject();
+    if (!securityObjects[RX_SECIDX_NULL]) {
        TLog(0, "rxnull_NewServerSecurityObject");
        exit(1);
     }
 
     service =
-       rx_NewServiceHost(host, 0, 1, "BUTC", securityObjects, 3, TC_ExecuteRequest);
+       rx_NewServiceHost(host, 0, 1, "BUTC", securityObjects, 1, TC_ExecuteRequest);
     if (!service) {
        TLog(0, "rx_NewService");
        exit(1);
@@ -1109,7 +1097,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
        exit(1);
     }
     /* This call is here to verify that we are authentiated.
-     * The call does nothing and will return BUDB_NOTPERMITTED 
+     * The call does nothing and will return BUDB_NOTPERMITTED
      * if we don't belong.
      */
     code = bcdb_deleteDump(0, 0, 0, 0);
@@ -1161,13 +1149,13 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
 int
 main(int argc, char **argv)
 {
-    register struct cmd_syndesc *ts;
-    register struct cmd_item *ti;
+    struct cmd_syndesc *ts;
+    struct cmd_item *ti;
 
 #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.
      */
@@ -1182,7 +1170,7 @@ main(int argc, char **argv)
 
     setlinebuf(stdout);
 
-    ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "tape coordinator");
+    ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, 0, "tape coordinator");
     cmd_AddParm(ts, "-port", CMD_SINGLE, CMD_OPTIONAL, "port offset");
     cmd_AddParm(ts, "-debuglevel", CMD_SINGLE, CMD_OPTIONAL, "0 | 1 | 2");
     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
@@ -1210,32 +1198,31 @@ main(int argc, char **argv)
 
     /* setup the file paths */
     strcompose(eFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
-              TE_PREFIX, NULL);
+              TE_PREFIX, (char *)NULL);
     strcompose(lFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
-              TL_PREFIX, NULL);
+              TL_PREFIX, (char *)NULL);
     strcompose(pFile, AFSDIR_PATH_MAX, AFSDIR_SERVER_BACKUP_DIRPATH, "/",
-              CFG_PREFIX, NULL);
+              CFG_PREFIX, (char *)NULL);
     strcpy(tapeConfigFile, AFSDIR_SERVER_TAPECONFIG_FILEPATH);
 
     /* special case "no args" case since cmd_dispatch gives help message
      * instead
      */
     if (argc == 1) {
-       ts = (struct cmd_syndesc *)malloc(sizeof(struct cmd_syndesc));
-       memset(ts, 0, sizeof(*ts));
+       ts = calloc(1, sizeof(struct cmd_syndesc));
 
-       ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
+       ti = malloc(sizeof(struct cmd_item));
        ti->next = 0;
        ti->data = "0";
        ts->parms[0].items = ti;
-       ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
+       ti = malloc(sizeof(struct cmd_item));
        ti->next = 0;
        ti->data = "0";
        ts->parms[1].items = ti;
-       ts->parms[2].items = (struct cmd_item *)NULL;
-       ts->parms[3].items = (struct cmd_item *)NULL;
-       ts->parms[4].items = (struct cmd_item *)NULL;
-       ts->parms[5].items = (struct cmd_item *)NULL;
+       ts->parms[2].items = NULL;
+       ts->parms[3].items = NULL;
+       ts->parms[4].items = NULL;
+       ts->parms[5].items = NULL;
        return WorkerBee(ts, NULL);
     } else
        return cmd_Dispatch(argc, argv);