OPENAFS-SA-2018-002 butc: Initialize OUT scalar value
[openafs.git] / src / butc / tcprocs.c
index 4bb4f23..cc19e53 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 <afs/procmgmt.h>
+#include <roken.h>
 
-#include <sys/types.h>
-#include <errno.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
-#endif
-#include <rx/xdr.h>
+#include <afs/opr.h>
 #include <rx/rx.h>
 #include <afs/afsint.h>
-#include <stdio.h>
-#include <string.h>
-#include <afs/procmgmt.h>
-#include <afs/assert.h>
 #include <afs/prs_fs.h>
-#include <sys/stat.h>
 #include <afs/nfs.h>
 #include <lwp.h>
 #include <lock.h>
@@ -39,20 +26,27 @@ RCSID
 #include <afs/keys.h>
 #include <ubik.h>
 #include <afs/tcdata.h>
+#include <afs/budb_client.h>
+#include <afs/bucoord_prototypes.h>
+
 #include "error_macros.h"
 #include "butc_xbsa.h"
+#include "butc_prototypes.h"
+#include "butc_internal.h"
 
-static CopyDumpDesc();
-static CopyRestoreDesc();
-static CopyTapeSetDesc();
-
+static int CopyDumpDesc(struct tc_dumpDesc *, tc_dumpArray *);
+static int CopyRestoreDesc(struct tc_restoreDesc *, tc_restoreArray *);
+static int CopyTapeSetDesc(struct tc_tapeSet *, struct tc_tapeSet *);
 
 int
 callPermitted(struct rx_call *call)
 {
-    /* before this code can be used, the rx connection, on the bucoord side, must */
-    /* be changed so that it will set up for token passing instead of using  a    */
-    /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
+    /*
+     * Before this code can be used, the rx connection, on the bucoord side,
+     * must be changed so that it will set up for token passing instead of
+     * using a simple rx connection that, below, returns a value of
+     * RX_SECIDX_NULL from rx_SecurityClassOf.
+     */
     return 1;
 }
 
@@ -147,10 +141,6 @@ STC_LabelTape(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *task
     statusP statusPtr = NULL;
     afs_int32 code;
 
-    extern int Labeller();
-    extern statusP createStatusNode();
-    extern afs_int32 allocTaskId();
-
 #ifdef xbsa
     if (CONF_XBSA)
        return (TC_BADTASK);    /* LabelTape does not apply if XBSA */
@@ -159,7 +149,7 @@ STC_LabelTape(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *task
     if (callPermitted(acid) == 0)
        return (TC_NOTPERMITTED);
 
-    ptr = (struct labelTapeIf *)malloc(sizeof(*ptr));
+    ptr = malloc(sizeof(*ptr));
     if (!ptr)
        ERROR_EXIT(TC_NOMEMORY);
     memcpy(&ptr->label, label, sizeof(ptr->label));
@@ -227,9 +217,6 @@ STC_PerformDump(struct rx_call *rxCallId, struct tc_dumpInterface *tcdiPtr, tc_d
 #endif
     afs_int32 code = 0;
 
-    extern statusP createStatusNode();
-    extern Dumper();
-
     if (callPermitted(rxCallId) == 0)
        return (TC_NOTPERMITTED);
 
@@ -242,18 +229,13 @@ STC_PerformDump(struct rx_call *rxCallId, struct tc_dumpInterface *tcdiPtr, tc_d
     /*set up the parameters in the node, to be used by LWP */
     strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
 
-    newNode->dumpName = (char *)malloc(strlen(tcdiPtr->dumpPath) + 1);
-    strcpy(newNode->dumpName, tcdiPtr->dumpPath);
-
-    newNode->volumeSetName =
-       (char *)malloc(strlen(tcdiPtr->volumeSetName) + 1);
-    strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
+    newNode->dumpName = strdup(tcdiPtr->dumpPath);
+    newNode->volumeSetName = strdup(tcdiPtr->volumeSetName);
 
     CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
 
-    newNode->dumps = (struct tc_dumpDesc *)
-       malloc(sizeof(struct tc_dumpDesc) *
-              tc_dumpArrayPtr->tc_dumpArray_len);
+    newNode->dumps = malloc(sizeof(struct tc_dumpDesc) *
+                           tc_dumpArrayPtr->tc_dumpArray_len);
     newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
     CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
 
@@ -326,9 +308,6 @@ STC_PerformRestore(struct rx_call *acid, char *dumpSetName, tc_restoreArray *are
     PROCESS pid;
 #endif
 
-    extern int Restorer();
-    extern statusP createStatusNode();
-
     if (callPermitted(acid) == 0)
        return (TC_NOTPERMITTED);
 
@@ -337,9 +316,8 @@ STC_PerformRestore(struct rx_call *acid, char *dumpSetName, tc_restoreArray *are
     /* this creates a node in list, alots an id for it and prepares it for locking */
     CreateNode(&newNode);
 
-    newNode->restores = (struct tc_restoreDesc *)
-       malloc(sizeof(struct tc_restoreDesc) *
-              arestores->tc_restoreArray_len);
+    newNode->restores = malloc(sizeof(struct tc_restoreDesc) *
+                              arestores->tc_restoreArray_len);
     newNode->arraySize = arestores->tc_restoreArray_len;
     CopyRestoreDesc(newNode->restores, arestores);
     *taskID = newNode->taskID;
@@ -394,8 +372,9 @@ STC_ReadLabel(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *task
 {
     afs_int32 code;
 
-    extern int ReadLabel();
-
+    memset(label, 0, sizeof(*label));
+    /* Synchronous, so no "real" ID; don't send stack garbage on the wire */
+    *taskId = 0;
 #ifdef xbsa
     if (CONF_XBSA)
        return (TC_BADTASK);    /* ReadLabel does not apply if XBSA */
@@ -425,10 +404,6 @@ STC_RestoreDb(struct rx_call *rxCall, afs_uint32 *taskId)
     statusP statusPtr;
     afs_int32 code = 0;
 
-    extern afs_int32 restoreDbFromTape();
-    extern statusP createStatusNode();
-    extern afs_int32 allocTaskId();
-
 #ifdef xbsa
     if (CONF_XBSA)
        return (TC_BADTASK);    /* LabelTape does not apply if XBSA */
@@ -461,11 +436,11 @@ STC_RestoreDb(struct rx_call *rxCall, afs_uint32 *taskId)
        ERROR_EXIT(code);
 
     AFS_SIGSET_CLEAR();
-    code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
+    code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)(intptr_t)*taskId);
     AFS_SIGSET_RESTORE();
 #else
     code =
-       LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)*taskId,
+       LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)(intptr_t)*taskId,
                          "Db restore", &pid);
 #endif
 
@@ -496,10 +471,6 @@ STC_SaveDb(struct rx_call *rxCall, Date archiveTime, afs_uint32 *taskId)
     afs_int32 code = 0;
     struct saveDbIf *ptr;
 
-    extern afs_int32 saveDbToTape();
-    extern statusP createStatusNode();
-    extern afs_int32 allocTaskId();
-
 #ifdef xbsa
     if (CONF_XBSA)
        return (TC_BADTASK);    /* LabelTape does not apply if XBSA */
@@ -510,7 +481,7 @@ STC_SaveDb(struct rx_call *rxCall, Date archiveTime, afs_uint32 *taskId)
 
     *taskId = allocTaskId();
 
-    ptr = (struct saveDbIf *)malloc(sizeof(struct saveDbIf));
+    ptr = malloc(sizeof(struct saveDbIf));
     if (!ptr)
        ERROR_EXIT(TC_NOMEMORY);
     ptr->archiveTime = archiveTime;
@@ -576,13 +547,9 @@ STC_ScanDumps(struct rx_call *acid, afs_int32 addDbFlag, afs_uint32 *taskId)
     PROCESS pid;
 #endif
     struct scanTapeIf *ptr;
-    statusP statusPtr;
+    statusP statusPtr = NULL;
     afs_int32 code = 0;
 
-    extern afs_int32 ScanDumps();
-    extern afs_int32 allocTaskId();
-    extern statusP createStatusNode();
-
 #ifdef xbsa
     if (CONF_XBSA)
        return (TC_BADTASK);    /* ScanDumps does not apply if XBSA */
@@ -593,7 +560,7 @@ STC_ScanDumps(struct rx_call *acid, afs_int32 addDbFlag, afs_uint32 *taskId)
 
     *taskId = allocTaskId();
 
-    ptr = (struct scanTapeIf *)malloc(sizeof(*ptr));
+    ptr = malloc(sizeof(*ptr));
     if (!ptr)
        ERROR_EXIT(TC_NOMEMORY);
     ptr->addDbFlag = addDbFlag;
@@ -659,10 +626,10 @@ STC_TCInfo(struct rx_call *acid, struct tc_tcInfo *tciptr)
 afs_int32
 STC_DeleteDump(struct rx_call *acid, afs_uint32 dumpID, afs_uint32 *taskId)
 {
-    struct deleteDumpIf *ptr = 0;
-    statusP statusPtr = 0;
     afs_int32 code = TC_BADTASK;       /* If not compiled -Dxbsa then fail */
 #ifdef xbsa
+    struct deleteDumpIf *ptr = 0;
+    statusP statusPtr = 0;
 #ifdef AFS_PTHREAD_ENV
     pthread_t pid;
     pthread_attr_t tattr;
@@ -671,9 +638,6 @@ STC_DeleteDump(struct rx_call *acid, afs_uint32 dumpID, afs_uint32 *taskId)
     PROCESS pid;
 #endif
 #endif
-    extern afs_int32 DeleteDump();
-    extern statusP createStatusNode();
-    extern afs_int32 allocTaskId();
 
     *taskId = 0;
     if (!CONF_XBSA)
@@ -684,7 +648,7 @@ STC_DeleteDump(struct rx_call *acid, afs_uint32 dumpID, afs_uint32 *taskId)
     if (callPermitted(acid) == 0)
        return (TC_NOTPERMITTED);
 
-    ptr = (struct deleteDumpIf *)malloc(sizeof(*ptr));
+    ptr = malloc(sizeof(*ptr));
     if (!ptr)
        ERROR_EXIT(TC_NOMEMORY);