bos: Don't overflow cellname buffer
[openafs.git] / src / bozo / bos.c
index fe9ea21..5e951a9 100644 (file)
@@ -21,7 +21,6 @@
 #include <afs/afsutil.h>
 #include <afs/cellconfig.h>
 #include <rx/rx.h>
-#include <sys/stat.h>
 #include <rx/xdr.h>
 #include <afs/auth.h>
 #include <afs/cellconfig.h>
@@ -30,6 +29,7 @@
 #include <ubik.h>
 #include <afs/ktime.h>
 #include <afs/kautils.h>
+#include <afs/afsint.h>
 #include <afs/volser.h>
 
 static int IStatServer(struct cmd_syndesc *as, int int32p);
@@ -37,6 +37,7 @@ static int DoStat(char *aname, struct rx_connection *aconn,
                  int aint32p, int firstTime);
 
 #include "bosint.h"
+#include "bnode_internal.h"
 #include "bosprototypes.h"
 
 /* command offsets for bos salvage command */
@@ -787,8 +788,6 @@ AddKey(struct cmd_syndesc *as, void *arock)
     afs_int32 code;
     struct ktc_encryptionKey tkey;
     afs_int32 temp;
-    char *tcell;
-    char cellBuffer[256];
     char buf[BUFSIZ], ver[BUFSIZ];
 
     tconn = GetConn(as, 1);
@@ -823,24 +822,30 @@ AddKey(struct cmd_syndesc *as, void *arock)
 */
        strcpy((char *)&tkey, buf);
     } else {                   /* kerberos key */
+       char *tcell;
        if (as->parms[ADDPARMOFFSET].items) {
-           strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
+           tcell = strdup(as->parms[ADDPARMOFFSET].items->data);
+           if (tcell == NULL) {
+               fprintf(stderr, "bos: Unable to allocate memory for cellname\n");
+               exit(1);
+           }
 
            /* string to key needs upper-case cell names */
 
            /* I don't believe this is true.  The string to key function
             * actually expands the cell name, then LOWER-CASES it.  Perhaps it
             * didn't use to??? */
-           ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
-           tcell = cellBuffer;
+           ucstring(tcell, tcell, strlen(tcell));
        } else
            tcell = NULL;       /* no cell specified, use current */
 /*
        ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
 */
        ka_StringToKey(buf, tcell, &tkey);
+
+       if (tcell)
+           free(tcell);
     }
-    tconn = GetConn(as, 1);
     code = BOZO_AddKey(tconn, temp, ktc_to_bozoptr(&tkey));
     if (code) {
        printf("bos: failed to set key %d (%s)\n", temp, em(code));
@@ -888,9 +893,10 @@ ListKeys(struct cmd_syndesc *as, void *arock)
            break;
        everWorked = 1;
        /* first check if key is returned */
-       if ((!ka_KeyIsZero(ktc_to_charptr(&tkey), sizeof(tkey))) && (as->parms[1].items)) {
+       if ((!ka_KeyIsZero((char *)&tkey, sizeof(tkey)))
+           && (as->parms[1].items)) {
            printf("key %d is '", kvno);
-           ka_PrintBytes(ktc_to_charptr(&tkey), sizeof(tkey));
+           ka_PrintBytes((char *)&tkey, sizeof(tkey));
            printf("'\n");
        } else {
            if (keyInfo.keyCheckSum == 0)       /* shouldn't happen */
@@ -1144,6 +1150,7 @@ DoSalvage(struct rx_connection * aconn, char * aparm1, char * aparm2,
     char pbuffer[PARMBUFFERSSIZE];
     afs_int32 partNumber;
     char *notifier = NONOTIFIER;
+    int count;
 
     /* if a partition was specified, canonicalize the name, since
      * the salvager has a stupid partition ID parser */
@@ -1314,13 +1321,15 @@ DoSalvage(struct rx_connection * aconn, char * aparm1, char * aparm2,
        goto done;
     }
     /* now wait for bnode to disappear */
+    count = 0;
     while (1) {
-       IOMGR_Sleep(5);
+       IOMGR_Sleep(1);
        tp = tbuffer;
        code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
        if (code)
            break;
-       printf("bos: waiting for salvage to complete.\n");
+       if ((++count % 5) == 0)
+           printf("bos: waiting for salvage to complete.\n");
     }
     if (code != BZNOENT) {
        printf("bos: salvage failed (%s)\n", em(code));
@@ -1674,8 +1683,12 @@ SalvageCmd(struct cmd_syndesc *as, void *arock)
        confdir =
            (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
             AFSDIR_CLIENT_ETC_DIRPATH);
-       code = vsu_ClientInit( /* noauth */ 1, confdir, tmpname,
-                             /* server auth */ 0, &cstruct, (int (*)())0);
+
+       code = vsu_ClientInit(confdir, tmpname,
+                             AFSCONF_SECOPTS_FALLBACK_NULL |
+                             AFSCONF_SECOPTS_NOAUTH,
+                             NULL, &cstruct);
+
        if (code == 0) {
            newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
            if (newID == 0) {