Use asprintf for string construction
[openafs.git] / src / bozo / bosoprocs.c
index 66e10f5..54dda55 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
@@ -9,34 +9,24 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
+#include <roken.h>
 
-#include <afs/stds.h>
-#include <sys/types.h>
 #ifdef AFS_NT40_ENV
-#include <io.h>
-#include <fcntl.h>
 #include <sys/utime.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
 #endif /* AFS_NT40_ENV */
+
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rxkad.h>
-#include <errno.h>
 #include <afs/cellconfig.h>
 #include <afs/keys.h>
-#include <sys/stat.h>
-#include <des.h>
-#include <dirent.h>
-#include <stdio.h>
 #include <afs/afsutil.h>
 #include <afs/fileutil.h>
 #include <afs/ktime.h>
 #include <afs/audit.h>
 #include <afs/kautils.h>
-#include <string.h>
 
 #include "bnode.h"
 #include "bosint.h"
@@ -52,7 +42,7 @@ extern int bozo_isrestricted;
 afs_int32
 SBOZO_GetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTime *aktime)
 {
-    register afs_int32 code;
+    afs_int32 code;
 
     code = 0;                  /* assume success */
     switch (atype) {
@@ -75,7 +65,7 @@ SBOZO_GetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTim
 afs_int32
 SBOZO_SetRestartTime(struct rx_call *acall, afs_int32 atype, struct bozo_netKTime *aktime)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     /* check for proper permissions */
@@ -140,7 +130,7 @@ SBOZO_Exec(struct rx_call *acall, char *acmd)
 }
 
 afs_int32
-SBOZO_GetDates(struct rx_call *acall, char *aname, afs_int32 *atime, 
+SBOZO_GetDates(struct rx_call *acall, char *aname, afs_int32 *atime,
               afs_int32 *abakTime, afs_int32 *aoldTime)
 {
     struct stat tstat;
@@ -175,7 +165,7 @@ SBOZO_GetDates(struct rx_call *acall, char *aname, afs_int32 *atime,
 }
 
 afs_int32
-SBOZO_UnInstall(struct rx_call *acall, register char *aname)
+SBOZO_UnInstall(struct rx_call *acall, char *aname)
 {
     char *filepath;
     char fpOld[AFSDIR_PATH_MAX], fpBak[AFSDIR_PATH_MAX];
@@ -231,10 +221,10 @@ SBOZO_UnInstall(struct rx_call *acall, register char *aname)
 static void
 SaveOldFiles(char *aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char bbuffer[AFSDIR_PATH_MAX], obuffer[AFSDIR_PATH_MAX];
     struct stat tstat;
-    register afs_int32 now;
+    afs_int32 now;
     afs_int32 oldTime, bakTime;
 
     strcpy(bbuffer, aname);
@@ -361,7 +351,7 @@ afs_int32
 SBOZO_SetCellName(struct rx_call *acall, char *aname)
 {
     struct afsconf_cell tcell;
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
     char clones[MAXHOSTSPERCELL];
 
@@ -400,7 +390,7 @@ SBOZO_SetCellName(struct rx_call *acall, char *aname)
 afs_int32
 SBOZO_GetCellName(struct rx_call *acall, char **aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char tname[MAXCELLCHARS];
 
     code = afsconf_GetLocalCell(bozo_confdir, tname, sizeof(tname));
@@ -409,8 +399,7 @@ SBOZO_GetCellName(struct rx_call *acall, char **aname)
        *aname = (char *)malloc(1);
        **aname = 0;
     } else {
-       *aname = (char *)malloc(strlen(tname) + 1);
-       strcpy(*aname, tname);
+       *aname = strdup(tname);
     }
 
     return code;
@@ -419,9 +408,9 @@ SBOZO_GetCellName(struct rx_call *acall, char **aname)
 afs_int32
 SBOZO_GetCellHost(struct rx_call *acall, afs_uint32 awhich, char **aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct afsconf_cell tcell;
-    register char *tp;
+    char *tp;
     char clones[MAXHOSTSPERCELL];
 
     code =
@@ -436,13 +425,10 @@ SBOZO_GetCellHost(struct rx_call *acall, afs_uint32 awhich, char **aname)
     }
 
     tp = tcell.hostName[awhich];
-    *aname = (char *)malloc(strlen(tp) + 3);
     if (clones[awhich]) {
-       strcpy(*aname, "[");
-       strcat(*aname, tp);
-       strcat(*aname, "]");
+       asprintf(aname, "[%s]", tp);
     } else
-       strcpy(*aname, tp);
+       *aname = strdup(tp);
     goto done;
 
   fail:
@@ -456,10 +442,10 @@ SBOZO_GetCellHost(struct rx_call *acall, afs_uint32 awhich, char **aname)
 afs_int32
 SBOZO_DeleteCellHost(struct rx_call *acall, char *aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct afsconf_cell tcell;
     afs_int32 which;
-    register int i;
+    int i;
     char caller[MAXKTCNAMELEN];
     char clones[MAXHOSTSPERCELL];
 
@@ -503,10 +489,10 @@ SBOZO_DeleteCellHost(struct rx_call *acall, char *aname)
 afs_int32
 SBOZO_AddCellHost(struct rx_call *acall, char *aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct afsconf_cell tcell;
     afs_int32 which;
-    register int i;
+    int i;
     char caller[MAXKTCNAMELEN];
     char clones[MAXHOSTSPERCELL];
     char *n;
@@ -582,11 +568,11 @@ SBOZO_AddCellHost(struct rx_call *acall, char *aname)
 }
 
 afs_int32
-SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno, 
+SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno,
               struct bozo_key *akey, struct bozo_keyInfo *akeyinfo)
 {
     struct afsconf_keys tkeys;
-    register afs_int32 code;
+    afs_int32 code;
     struct stat tstat;
     int noauth = 0;
     char caller[MAXKTCNAMELEN];
@@ -611,8 +597,8 @@ SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno,
     memset(akeyinfo, 0, sizeof(struct bozo_keyInfo));
 
     noauth = afsconf_GetNoAuthFlag(bozo_confdir);
-    rxkad_GetServerInfo(acall->conn, &enc_level, 0, 0, 0, 0, 0);
-    /* 
+    rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
+    /*
      * only return actual keys in noauth or if this is an encrypted connection
      */
 
@@ -638,7 +624,7 @@ SBOZO_ListKeys(struct rx_call *acall, afs_int32 an, afs_int32 *akvno,
 afs_int32
 SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
     rxkad_level enc_level = rxkad_clear;
     int noauth;
@@ -648,7 +634,7 @@ SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey)
        goto fail;
     }
     noauth = afsconf_GetNoAuthFlag(bozo_confdir);
-    rxkad_GetServerInfo(acall->conn, &enc_level, 0, 0, 0, 0, 0);
+    rxkad_GetServerInfo(rx_ConnectionOf(acall), &enc_level, 0, 0, 0, 0, 0);
     if ((!noauth) && (enc_level != rxkad_crypt)) {
        code = BZENCREQ;
        goto fail;
@@ -665,9 +651,9 @@ SBOZO_AddKey(struct rx_call *acall, afs_int32 an, struct bozo_key *akey)
 }
 
 afs_int32
-SBOZO_SetNoAuthFlag(register struct rx_call *acall, afs_int32 aflag)
+SBOZO_SetNoAuthFlag(struct rx_call *acall, afs_int32 aflag)
 {
-    register afs_int32 code = 0;
+    afs_int32 code = 0;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -687,7 +673,7 @@ SBOZO_SetNoAuthFlag(register struct rx_call *acall, afs_int32 aflag)
 afs_int32
 SBOZO_DeleteKey(struct rx_call *acall, afs_int32 an)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -706,10 +692,10 @@ SBOZO_DeleteKey(struct rx_call *acall, afs_int32 an)
 
 
 afs_int32
-SBOZO_ListSUsers(struct rx_call *acall, afs_int32 an, register char **aname)
+SBOZO_ListSUsers(struct rx_call *acall, afs_int32 an, char **aname)
 {
-    register afs_int32 code;
-    register char *tp;
+    afs_int32 code;
+    char *tp;
 
     tp = *aname = (char *)malloc(256);
     *tp = 0;                   /* in case getnthuser doesn't null-terminate the string */
@@ -723,7 +709,7 @@ SBOZO_ListSUsers(struct rx_call *acall, afs_int32 an, register char **aname)
 afs_int32
 SBOZO_AddSUser(struct rx_call *acall, char *aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -743,7 +729,7 @@ SBOZO_AddSUser(struct rx_call *acall, char *aname)
 afs_int32
 SBOZO_DeleteSUser(struct rx_call *acall, char *aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -762,7 +748,7 @@ SBOZO_DeleteSUser(struct rx_call *acall, char *aname)
 }
 
 afs_int32
-SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance, 
+SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance,
                  char *ap1, char *ap2, char *ap3, char *ap4, char *ap5,
                   char *notifier)
 {
@@ -775,10 +761,16 @@ SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance,
        goto fail;
     }
     if (bozo_isrestricted) {
+       const char *salvpath = AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH;
+       /* for DAFS, 'bos salvage' will pass "salvageserver -client" instead */
+       const char *salsrvpath = AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH " -client ";
+
+       /* still allow 'bos salvage' to work */
        if (strcmp(atype, "cron") || strcmp(ainstance, "salvage-tmp")
            || strcmp(ap2, "now")
-           || strncmp(ap1, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH,
-                      strlen(AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH))) {
+           || (strncmp(ap1, salvpath, strlen(salvpath))
+               && strncmp(ap1, salsrvpath, strlen(salsrvpath)))) {
+
            code = BZACCESS;
            goto fail;
        }
@@ -796,9 +788,9 @@ SBOZO_CreateBnode(struct rx_call *acall, char *atype, char *ainstance,
 }
 
 afs_int32
-SBOZO_WaitAll(register struct rx_call *acall)
+SBOZO_WaitAll(struct rx_call *acall)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -819,7 +811,7 @@ SBOZO_WaitAll(register struct rx_call *acall)
 afs_int32
 SBOZO_DeleteBnode(struct rx_call *acall, char *ainstance)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -842,7 +834,7 @@ SBOZO_DeleteBnode(struct rx_call *acall, char *ainstance)
 }
 
 static int
-swproc(register struct bnode *abnode, void *arock)
+swproc(struct bnode *abnode, void *arock)
 {
     if (abnode->goal == BSTAT_NORMAL)
        return 0;               /* this one's not shutting down */
@@ -860,6 +852,7 @@ stproc(struct bnode *abnode, void *arock)
        return 0;               /* don't do these guys */
 
     bnode_Hold(abnode);
+    bnode_ResetErrorCount(abnode);
     bnode_SetStat(abnode, BSTAT_NORMAL);
     bnode_Release(abnode);
     return 0;
@@ -879,7 +872,7 @@ afs_int32
 SBOZO_ShutdownAll(struct rx_call *acall)
 {
     /* iterate over all bnodes, setting the status to temporarily disabled */
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     /* check for authorization */
@@ -901,7 +894,7 @@ SBOZO_ShutdownAll(struct rx_call *acall)
 afs_int32
 SBOZO_RestartAll(struct rx_call *acall)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -932,7 +925,7 @@ SBOZO_RestartAll(struct rx_call *acall)
 afs_int32
 SBOZO_ReBozo(struct rx_call *acall)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     /* acall is null if called internally to restart bosserver */
@@ -976,7 +969,7 @@ SBOZO_ReBozo(struct rx_call *acall)
 afs_int32
 SBOZO_StartupAll(struct rx_call *acall)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -993,10 +986,10 @@ SBOZO_StartupAll(struct rx_call *acall)
 }
 
 afs_int32
-SBOZO_Restart(struct rx_call *acall, register char *ainstance)
+SBOZO_Restart(struct rx_call *acall, char *ainstance)
 {
-    register struct bnode *tb;
-    register afs_int32 code;
+    struct bnode *tb;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -1018,6 +1011,7 @@ SBOZO_Restart(struct rx_call *acall, register char *ainstance)
     bnode_Hold(tb);
     bnode_SetStat(tb, BSTAT_SHUTDOWN);
     code = bnode_WaitStatus(tb, BSTAT_SHUTDOWN);       /* this can fail */
+    bnode_ResetErrorCount(tb);
     bnode_SetStat(tb, BSTAT_NORMAL);
     bnode_Release(tb);
 
@@ -1030,8 +1024,8 @@ SBOZO_Restart(struct rx_call *acall, register char *ainstance)
 afs_int32
 SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
 {
-    register struct bnode *tb;
-    register afs_int32 code;
+    struct bnode *tb;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -1047,6 +1041,7 @@ SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
        goto fail;
     }
     bnode_Hold(tb);
+    bnode_ResetErrorCount(tb);
     code = bnode_SetStat(tb, astatus);
     bnode_Release(tb);
 
@@ -1059,8 +1054,8 @@ SBOZO_SetTStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
 afs_int32
 SBOZO_SetStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
 {
-    register struct bnode *tb;
-    register afs_int32 code;
+    struct bnode *tb;
+    afs_int32 code;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -1087,11 +1082,11 @@ SBOZO_SetStatus(struct rx_call *acall, char *ainstance, afs_int32 astatus)
 }
 
 afs_int32
-SBOZO_GetStatus(struct rx_call *acall, char *ainstance, afs_int32 *astat, 
+SBOZO_GetStatus(struct rx_call *acall, char *ainstance, afs_int32 *astat,
                char **astatDescr)
 {
-    register struct bnode *tb;
-    register afs_int32 code;
+    struct bnode *tb;
+    afs_int32 code;
 
     tb = bnode_FindInstance(ainstance);
     if (!tb) {
@@ -1128,7 +1123,7 @@ static int
 eifunc(struct bnode *abnode, void *param)
 {
     struct eidata *arock = (struct eidata *)param;
-    
+
     if (arock->counter-- == 0) {
        /* done */
        strcpy(arock->iname, abnode->name);
@@ -1152,10 +1147,10 @@ ZapFile(const char *adir, const char *aname)
 afs_int32
 SBOZO_Prune(struct rx_call *acall, afs_int32 aflags)
 {
-    register afs_int32 code;
+    afs_int32 code;
     DIR *dirp;
-    register struct dirent *tde;
-    register int i;
+    struct dirent *tde;
+    int i;
     char caller[MAXKTCNAMELEN];
 
     if (!afsconf_SuperUser(bozo_confdir, acall, caller)) {
@@ -1205,7 +1200,7 @@ SBOZO_Prune(struct rx_call *acall, afs_int32 aflags)
 }
 
 afs_int32
-SBOZO_EnumerateInstance(struct rx_call *acall, afs_int32 anum, 
+SBOZO_EnumerateInstance(struct rx_call *acall, afs_int32 anum,
                        char **ainstance)
 {
     struct eidata tdata;
@@ -1236,7 +1231,7 @@ int bozo_nbosEntryStats =
     sizeof(bozo_bosEntryStats) / sizeof(bozo_bosEntryStats[0]);
 
 /* This function performs initialization of the bozo_bosEntrystats[]
- * array. This array contains the list of dirs that the bosserver 
+ * array. This array contains the list of dirs that the bosserver
  * is interested in along with their recommended permissions
  * NOTE: This initialization is a bit ugly. This was caused because
  * the path names require procedural as opposed to static initialization.
@@ -1312,8 +1307,8 @@ DirAccessOK(void)
        if (!StatEachEntry(e)) {
            bozo_Log("unhappy with %s which is a %s that should "
                     "have at least rights %o, at most rights %o %s\n",
-                    e->path, e->dir ? "dir" : "file", e->reqPerm, 
-                    (~e->proPerm & 0777), 
+                    e->path, e->dir ? "dir" : "file", e->reqPerm,
+                    (~e->proPerm & 0777),
                     e->rootOwner ? ", owned by root" : "");
            result = 0;
            break;
@@ -1345,7 +1340,7 @@ SBOZO_GetInstanceInfo(IN struct rx_call *acall,
                      OUT char **atype,
                      OUT struct bozo_status *astatus)
 {
-    register struct bnode *tb;
+    struct bnode *tb;
 
     tb = bnode_FindInstance(ainstance);
     *atype = (char *)malloc(BOZO_BSSIZE);
@@ -1380,9 +1375,9 @@ SBOZO_GetInstanceParm(struct rx_call *acall,
                      afs_int32 anum,
                      char **aparm)
 {
-    register struct bnode *tb;
-    register char *tp;
-    register afs_int32 code;
+    struct bnode *tb;
+    char *tp;
+    afs_int32 code;
 
     tp = (char *)malloc(BOZO_BSSIZE);
     *aparm = tp;
@@ -1406,9 +1401,9 @@ SBOZO_GetInstanceParm(struct rx_call *acall,
 }
 
 afs_int32
-SBOZO_GetLog(register struct rx_call *acall, char *aname)
+SBOZO_GetLog(struct rx_call *acall, char *aname)
 {
-    register afs_int32 code;
+    afs_int32 code;
     FILE *tfile;
     int tc;
     char *logpath;
@@ -1470,10 +1465,10 @@ SBOZO_GetLog(register struct rx_call *acall, char *aname)
 }
 
 afs_int32
-SBOZO_GetInstanceStrings(struct rx_call *acall, char *abnodeName, 
+SBOZO_GetInstanceStrings(struct rx_call *acall, char *abnodeName,
                         char **as1, char **as2, char **as3, char **as4)
 {
-    register struct bnode *tb;
+    struct bnode *tb;
 
     *as2 = (char *)malloc(1);
     **as2 = 0;
@@ -1487,8 +1482,7 @@ SBOZO_GetInstanceStrings(struct rx_call *acall, char *abnodeName,
 
     /* now, return the appropriate error string, if any */
     if (tb->lastErrorName) {
-       *as1 = (char *)malloc(strlen(tb->lastErrorName) + 1);
-       strcpy(*as1, tb->lastErrorName);
+       *as1 = strdup(tb->lastErrorName);
     } else {
        *as1 = (char *)malloc(1);
        **as1 = 0;