OPENAFS-SA-2018-001 backup: use authenticated connection to butc
[openafs.git] / src / bucoord / dump.c
index 09c364d..e0b3ced 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#include <sys/types.h>
 #include <afs/cmd.h>
-#ifdef HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <sys/time.h>
-#endif
+#include <afs/cellconfig.h>
 #include <lwp.h>
 #include <rx/rx.h>
 #include <afs/bubasics.h>
@@ -63,7 +52,7 @@ bc_Dumper(int aindex)
     struct rx_connection *tconn;
     struct bc_volumeDump *tde;
     afs_int32 count, port;
-    struct tc_dumpDesc *volDesc = 0;
+    struct tc_dumpDesc *volDesc = NULL;
     struct tc_dumpArray volArray;
     char *baseNamePtr;
     statusP statusPtr;
@@ -90,8 +79,12 @@ bc_Dumper(int aindex)
      */
     for (count = 0, tde = dumpTaskPtr->volumes; tde;
         tde = tde->next, count++);
-    volDesc =
-       (struct tc_dumpDesc *)malloc(count * sizeof(struct tc_dumpDesc));
+
+    /* Nothing to dump, so just return success */
+    if (count == 0)
+       goto error_exit;
+
+    volDesc = malloc(count * sizeof(struct tc_dumpDesc));
     if (!volDesc) {
        afs_com_err(whoami, BC_NOMEM, NULL);
        ERROR(BC_NOMEM);
@@ -249,7 +242,7 @@ bc_StartDmpRst(struct bc_config *aconfig, char *adname, char *avname,
 {
     int i;
     afs_int32 code;
-    void *junk = NULL;
+    PROCESS junk;
 
     for (i = 0; i < BC_MAXSIMDUMPS; i++)
        if (!(bc_dumpTasks[i].flags & BC_DI_INUSE))
@@ -292,7 +285,7 @@ bc_StartDmpRst(struct bc_config *aconfig, char *adname, char *avname,
 
     code =
        LWP_CreateProcess(bc_DmpRstStart, 20480, LWP_NORMAL_PRIORITY,
-                         (void *)(intptr_t)i, "helper", junk);
+                         (void *)(intptr_t)i, "helper", &junk);
     if (code) {
        bc_HandleMisc(code);
        afs_com_err(whoami, code, "; Can't start thread");
@@ -478,15 +471,40 @@ bc_GetConn(struct bc_config *aconfig, afs_int32 aport,
           struct rx_connection **tconn)
 {
     afs_uint32 host;
+    afs_int32 code;
     unsigned short port;
     static struct rx_securityClass *rxsc;
+    static afs_int32 scIndex;
     struct bc_hostEntry *te;
 
     *tconn = (struct rx_connection *)0;
 
     /* use non-secure connections to butc */
-    if (!rxsc)
-       rxsc = rxnull_NewClientSecurityObject();
+    if (!rxsc) {
+       struct afsconf_dir *dir;
+       afsconf_secflags flags = AFSCONF_SECOPTS_FALLBACK_NULL;
+       char *cname;
+
+       if (nobutcauth)
+           flags |= AFSCONF_SECOPTS_NOAUTH;
+       if (localauth) {
+           flags |= AFSCONF_SECOPTS_LOCALAUTH;
+           dir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
+       } else {
+           dir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
+       }
+       if (tcell[0] == '\0')
+           cname = NULL;
+       else
+           cname = tcell;
+       /* No need for cell info since butc is not a registered service */
+       code = afsconf_PickClientSecObj(dir, flags, NULL, cname, &rxsc, &scIndex,
+                                       NULL);
+       if (dir)
+           afsconf_Close(dir);
+       if (code)
+           return -1;
+    }
     if (!rxsc || !aconfig)
        return (-1);
 
@@ -499,8 +517,8 @@ bc_GetConn(struct bc_config *aconfig, afs_int32 aport,
 
            port = htons(BC_TAPEPORT + aport);
 
-           /* servers is 1; sec index is 0 */
-           *tconn = rx_NewConnection(host, port, 1, rxsc, 0);
+           /* servers is 1 */
+           *tconn = rx_NewConnection(host, port, 1, rxsc, scIndex);
            return ((*tconn ? 0 : -1));
        }
     }