bozo: Remove dead code and minor cleanup
[openafs.git] / src / bozo / bos.c
index 5399ed9..880936a 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 */
@@ -84,60 +85,15 @@ em(afs_int32 acode)
        return (char *)afs_error_message(acode);
 }
 
-/* get partition id from a name */
-/* XXX - unused code - could be removed? */
-#if 0
-static afs_int32
-GetPartitionID(char *aname)
-{
-    char tc;
-    char ascii[3];
-
-    tc = *aname;
-    if (tc == 0)
-       return -1;              /* unknown */
-    /* numbers go straight through */
-    if (tc >= '0' && tc <= '9') {
-       return atoi(aname);
-    }
-    /* otherwise check for vicepa or /vicepa, or just plain "a" */
-    ascii[2] = 0;
-    if (strlen(aname) <= 2) {
-       strcpy(ascii, aname);
-    } else if (!strncmp(aname, "/vicep", 6)) {
-       strncpy(ascii, aname + 6, 2);
-    } else if (!strncmp(aname, "vicep", 5)) {
-       strncpy(ascii, aname + 5, 2);
-    } else
-       return -1;              /* bad partition name */
-    /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
-     * .../vicepzz, and are numbered from 0.  Do the appropriate conversion */
-    if (ascii[1] == 0) {
-       /* one char name, 0..25 */
-       if (ascii[0] < 'a' || ascii[0] > 'z')
-           return -1;          /* wrongo */
-       return ascii[0] - 'a';
-    } else {
-       /* two char name, 26 .. <whatever> */
-       if (ascii[0] < 'a' || ascii[0] > 'z')
-           return -1;          /* wrongo */
-       if (ascii[1] < 'a' || ascii[1] > 'z')
-           return -1;          /* just as bad */
-       return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
-    }
-}
-#endif
-
 /* make ctime easier to use */
 static char *
-DateOf(afs_int32 atime)
+DateOf(time_t atime)
 {
     static char tbuffer[30];
     char *tp;
-    time_t t = (time_t) atime;
-    tp = ctime(&t);
+    tp = ctime(&atime);
     if (tp) {
-       strcpy(tbuffer, tp);
+       strlcpy(tbuffer, tp, sizeof(tbuffer));
        tbuffer[24] = 0;        /* get rid of new line */
     } else
        strcpy(tbuffer, "BAD TIME");
@@ -171,7 +127,11 @@ GetConn(struct cmd_syndesc *as, int aencrypt)
     }
     memcpy(&addr, th->h_addr, sizeof(afs_int32));
 
-    secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
+    if (aencrypt)
+       secFlags = AFSCONF_SECOPTS_ALWAYSENCRYPT;
+    else
+       secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
+
 
     if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
        secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
@@ -787,16 +747,17 @@ 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);
     memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
 
-    if (as->parms[1].items)
-       strcpy(buf, as->parms[1].items->data);
-    else {
+    if (as->parms[1].items) {
+       if (strlcpy(buf, as->parms[1].items->data, sizeof(buf)) >= sizeof(buf)) {
+           fprintf(stderr, "Key data too long for buffer\n");
+           exit(1);
+       }
+    } else {
        /* prompt for key */
        code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
        if (code || strlen(buf) == 0) {
@@ -823,24 +784,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));
@@ -1145,6 +1112,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 */
@@ -1315,13 +1283,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));
@@ -1675,8 +1645,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) {
@@ -1889,6 +1863,9 @@ main(int argc, char **argv)
 {
     afs_int32 code;
     struct cmd_syndesc *ts;
+#ifdef AFS_NT40_ENV
+    __declspec(dllimport)
+#endif
     extern int afsconf_SawCell;
 
 #ifdef AFS_AIX32_ENV