vlserver: fix missing read-only entries from ListAttributesN2
[openafs.git] / src / vlserver / vlprocs.c
index 9741964..89f8760 100644 (file)
@@ -30,6 +30,7 @@
 #endif
 
 extern int smallMem;
+extern int restrictedQueryLevel;
 extern int extent_mod;
 extern struct afsconf_dir *vldb_confdir;
 extern struct ubik_dbase *VL_dbase;
@@ -38,11 +39,6 @@ int maxnservers;
     code = (c); \
     goto abort; \
 } while (0)
-#undef END
-#define END(c) do { \
-    code = (c); \
-    goto end; \
-} while (0)
 
 #define VLDBALLOCLIMIT 10000
 #define VLDBALLOCINCR  2048
@@ -72,15 +68,15 @@ static int get_vldbupdateentry(struct vl_ctx *ctx, afs_int32 blockindex,
                               struct nvlentry *VlEntry);
 static int repsite_exists(struct nvlentry *VlEntry, int server, int partition);
 static void repsite_compress(struct nvlentry *VlEntry, int offset);
-static void vlentry_to_vldbentry(struct vl_ctx *ctx,
+static int vlentry_to_vldbentry(struct vl_ctx *ctx,
+                               struct nvlentry *VlEntry,
+                               struct vldbentry *VldbEntry);
+static int vlentry_to_nvldbentry(struct vl_ctx *ctx,
                                 struct nvlentry *VlEntry,
-                                struct vldbentry *VldbEntry);
-static void vlentry_to_nvldbentry(struct vl_ctx *ctx,
-                                 struct nvlentry *VlEntry,
-                                 struct nvldbentry *VldbEntry);
-static void vlentry_to_uvldbentry(struct vl_ctx *ctx,
-                                 struct nvlentry *VlEntry,
-                                 struct uvldbentry *VldbEntry);
+                                struct nvldbentry *VldbEntry);
+static int vlentry_to_uvldbentry(struct vl_ctx *ctx,
+                                struct nvlentry *VlEntry,
+                                struct uvldbentry *VldbEntry);
 static int InvalidVolname(char *volname);
 static int InvalidVoltype(afs_int32 voltype);
 static int InvalidOperation(afs_int32 voloper);
@@ -105,34 +101,98 @@ countAbort(int opcode)
     }
 }
 
-#define AFS_RXINFO_LEN 128
+
+static_inline int
+multiHomedExtentBase(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp,
+                    int *basePtr)
+{
+    int base;
+    int index;
+
+    *exp = NULL;
+    *basePtr = 0;
+
+    if ((ctx->hostaddress[srvidx] & 0xff000000) == 0xff000000) {
+       base = (ctx->hostaddress[srvidx] >> 16) & 0xff;
+       index = ctx->hostaddress[srvidx] & 0x0000ffff;
+       if (base >= VL_MAX_ADDREXTBLKS) {
+           VLog(0, ("Internal error: Multihome extent base is too large. "
+                    "Base %d index %d\n", base, index));
+           return VL_IO;
+       }
+       if (index >= VL_MHSRV_PERBLK) {
+           VLog(0, ("Internal error: Multihome extent index is too large. "
+                    "Base %d index %d\n", base, index));
+           return VL_IO;
+       }
+       if (!ctx->ex_addr[base]) {
+           VLog(0, ("Internal error: Multihome extent does not exist. "
+                    "Base %d\n", base));
+           return VL_IO;
+       }
+
+       *basePtr = base;
+       *exp = &ctx->ex_addr[base][index];
+    }
+
+    return 0;
+}
+
+static_inline int
+multiHomedExtent(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp)
+{
+    int base;
+
+    return multiHomedExtentBase(ctx, srvidx, exp, &base);
+}
+
+#define AFS_RXINFO_LEN 217
 static char *
-rxinfo(char * str, struct rx_call *rxcall)
+rxkadInfo(char *str, struct rx_connection *conn, struct in_addr hostAddr)
 {
     int code;
-    struct rx_connection *tconn;
     char tname[64] = "";
     char tinst[64] = "";
     char tcell[64] = "";
     afs_uint32 exp;
-    struct in_addr hostAddr;
 
-    tconn = rx_ConnectionOf(rxcall);
-    hostAddr.s_addr = rx_HostOf(rx_PeerOf(tconn));
-    code =
-       rxkad_GetServerInfo(rxcall->conn, NULL, &exp, tname, tinst, tcell,
-                           NULL);
+    code = rxkad_GetServerInfo(conn, NULL, &exp, tname, tinst, tcell,
+                              NULL);
     if (!code)
-       sprintf(str, "%s %s%s%s%s%s", inet_ntoa(hostAddr), tname,
+       snprintf(str, AFS_RXINFO_LEN,
+                "%s rxkad:%s%s%s%s%s", inet_ntoa(hostAddr), tname,
                (tinst[0] == '\0') ? "" : ".",
                (tinst[0] == '\0') ? "" : tinst,
                (tcell[0] == '\0') ? "" : "@",
                (tcell[0] == '\0') ? "" : tcell);
     else
-       sprintf(str, "%s noauth", inet_ntoa(hostAddr));
+       snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
     return (str);
 }
 
+static char *
+rxinfo(char *str, struct rx_call *rxcall)
+{
+    struct rx_connection *conn;
+    struct in_addr hostAddr;
+    rx_securityIndex authClass;
+
+    conn = rx_ConnectionOf(rxcall);
+    authClass = rx_SecurityClassOf(conn);
+    hostAddr.s_addr = rx_HostOf(rx_PeerOf(conn));
+
+    switch(authClass) {
+    case RX_SECIDX_KAD:
+       return rxkadInfo(str, conn, hostAddr);
+    default:
+       ;
+    }
+
+    snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
+    return str;
+}
+
+
 /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */
 int
 Init_VLdbase(struct vl_ctx *ctx,
@@ -146,8 +206,11 @@ Init_VLdbase(struct vl_ctx *ctx,
            code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
            wl = 1;
        } else if (locktype == LOCKREAD) {
-           code =
-               ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
+#ifdef UBIK_READ_WHILE_WRITE
+           code = ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
+#else
+           code = ubik_BeginTransReadAny(VL_dbase, UBIK_READTRANS, &ctx->trans);
+#endif
            wl = 0;
        } else {
            code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
@@ -179,7 +242,12 @@ Init_VLdbase(struct vl_ctx *ctx,
                return code;
        } else {                /* No code */
            if (pass == 2) {
-               ubik_EndTrans(ctx->trans);      /* Rebuilt db. End trans, then retake original lock */
+               /* The database header was rebuilt; end the write transaction.
+                * This will call vlsynccache() to copy the write header buffers
+                * to the read header buffers, before calling vlsetache().
+                * Do a third pass to re-acquire the original lock, which
+                * may be a read lock. */
+               ubik_EndTrans(ctx->trans);
            } else {
                break;          /* didn't rebuild and successful - exit */
            }
@@ -196,8 +264,8 @@ Init_VLdbase(struct vl_ctx *ctx,
  * (non-existant in vldb).
  */
 
-afs_int32
-SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
+static afs_int32
+CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
 {
     int this_op = VLCREATEENTRY;
     struct vl_ctx ctx;
@@ -207,14 +275,13 @@ SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
-       code = VL_PERM;
-       goto end;
+       return VL_PERM;
     }
 
     /* Do some validity tests on new entry */
     if ((code = check_vldbentry(newentry))
        || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1,
         ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL],
@@ -255,23 +322,28 @@ SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
        FreeBlock(&ctx, blockindex);
        goto abort;
     } else {
-       code = ubik_EndTrans(ctx.trans);
-       goto end;
+       return ubik_EndTrans(ctx.trans);
     }
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
+
+afs_int32
+SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
+{
+    afs_int32 code;
 
-  end:
+    code = CreateEntry(rxcall, newentry);
     osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
               (newentry ? newentry->name : NULL), AUD_END);
     return code;
 }
 
-
-afs_int32
-SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
+static afs_int32
+CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
 {
     int this_op = VLCREATEENTRYN;
     struct vl_ctx ctx;
@@ -281,14 +353,13 @@ SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
-       code = VL_PERM;
-       goto end;
+       return VL_PERM;
     }
 
     /* Do some validity tests on new entry */
     if ((code = check_nvldbentry(newentry))
        || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1,
         ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
@@ -329,23 +400,28 @@ SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
        FreeBlock(&ctx, blockindex);
        goto abort;
     } else {
-       code = ubik_EndTrans(ctx.trans);
-       goto end;
+       return ubik_EndTrans(ctx.trans);
     }
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
+
+afs_int32
+SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
+{
+    afs_int32 code;
 
-  end:
+    code = CreateEntryN(rxcall, newentry);
     osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
               (newentry ? newentry->name : NULL), AUD_END);
     return code;
 }
 
-
-afs_int32
-SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
+static afs_int32
+ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
 {
     int this_op = VLCHANGEADDR;
     struct vl_ctx ctx;
@@ -354,34 +430,40 @@ SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
-       code = VL_PERM;
-       goto end;
+       return VL_PERM;
     }
 
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxstr, rxcall)));
     if ((code = ChangeIPAddr(&ctx, ip1, ip2)))
        goto abort;
     else {
        code = ubik_EndTrans(ctx.trans);
-       goto end;
+       return code;
     }
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
 
-  end:
+afs_int32
+SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
+{
+    afs_int32 code;
+
+    code = ChangeAddr(rxcall, ip1, ip2);
     osi_auditU(rxcall, VLChangeAddrEvent, code, AUD_LONG, ip1, AUD_LONG,
               ip2, AUD_END);
     return code;
 }
 
 /* Delete a vldb entry given the volume id. */
-afs_int32
-SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
+static afs_int32
+DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
 {
     int this_op = VLDELETEENTRY;
     struct vl_ctx ctx;
@@ -391,13 +473,13 @@ SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
 
     if ((voltype != -1) && (InvalidVoltype(voltype)))
-       END(VL_BADVOLTYPE);
+       return VL_BADVOLTYPE;
 
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
@@ -413,14 +495,20 @@ SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
     if ((code = RemoveEntry(&ctx, blockindex, &tentry))) {
        goto abort;
     }
-    code = (ubik_EndTrans(ctx.trans));
-    goto end;
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
+
+afs_int32
+SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
+{
+    afs_int32 code;
 
-  end:
+    code = DeleteEntry(rxcall, volid, voltype);
     osi_auditU(rxcall, VLDeleteEntryEvent, code, AUD_LONG, volid,
               AUD_END);
     return code;
@@ -428,7 +516,7 @@ SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
 
 
 /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */
-int
+static int
 GetEntryByID(struct rx_call *rxcall,
             afs_uint32 volid,
             afs_int32 voltype,
@@ -462,11 +550,15 @@ GetEntryByID(struct rx_call *rxcall,
     }
     /* Convert from the internal to external form */
     if (new == 1)
-       vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
+       code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
     else if (new == 2)
-       vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
+       code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
     else
-       vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+       code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+
+    if (code)
+       goto abort;
+
     return (ubik_EndTrans(ctx.trans));
 
 abort:
@@ -520,7 +612,7 @@ NameIsId(char *aname)
 
 /* Get a vldb entry given the volume's name; of course, very similar to
  * VLGetEntryByID() above. */
-afs_int32
+static afs_int32
 GetEntryByName(struct rx_call *rxcall,
               char *volname,
               char *aentry,            /* entry data copied here */
@@ -533,8 +625,11 @@ GetEntryByName(struct rx_call *rxcall,
     char rxstr[AFS_RXINFO_LEN];
 
     if (NameIsId(volname)) {
-       return GetEntryByID(rxcall, atoi(volname), -1, aentry, new, this_op);
+       return GetEntryByID(rxcall, strtoul(volname, NULL, 10), -1, aentry, new, this_op);
     }
+
+    countRequest(this_op);
+
     if (InvalidVolname(volname))
        return VL_BADNAME;
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
@@ -552,11 +647,15 @@ GetEntryByName(struct rx_call *rxcall,
     }
     /* Convert to external entry representation */
     if (new == 1)
-       vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
+       code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
     else if (new == 2)
-       vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
+       code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
     else
-       vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+       code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+
+    if (code)
+       goto abort;
+
     return (ubik_EndTrans(ctx.trans));
 
 abort:
@@ -575,7 +674,6 @@ SVL_GetEntryByNameO(struct rx_call *rxcall,
                           VLGETENTRYBYNAME));
 }
 
-
 afs_int32
 SVL_GetEntryByNameN(struct rx_call *rxcall,
                    char *volname,
@@ -594,11 +692,9 @@ SVL_GetEntryByNameU(struct rx_call *rxcall,
                           VLGETENTRYBYNAMEU));
 }
 
-
-
 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
-afs_int32
-SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
+static afs_int32
+getNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
                   afs_uint32 *newvolumeid)
 {
     int this_op = VLGETNEWVOLUMEID;
@@ -609,13 +705,13 @@ SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
 
-    if (Maxvolidbump < 0 || Maxvolidbump > MAXBUMPCOUNT)
-       END(VL_BADVOLIDBUMP);
+    if (Maxvolidbump > MAXBUMPCOUNT)
+       return VL_BADVOLIDBUMP;
 
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     *newvolumeid = maxvolumeid = NextUnusedID(&ctx,
        ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &code);
@@ -629,14 +725,21 @@ SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
     if (write_vital_vlheader(&ctx)) {
        ABORT(VL_IO);
     }
-    code = (ubik_EndTrans(ctx.trans));
-    goto end;
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
 
-  end:
+afs_int32
+SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
+                  afs_uint32 *newvolumeid)
+{
+    afs_int32 code;
+
+    code = getNewVolumeId(rxcall, Maxvolidbump, newvolumeid);
     osi_auditU(rxcall, VLGetNewVolumeIdEvent, code, AUD_END);
     return code;
 }
@@ -646,8 +749,8 @@ SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
  * newentry. No individual checking/updating per field (alike
  * VLUpdateEntry) is done. */
 
-afs_int32
-SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+static afs_int32
+ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
                 struct vldbentry *newentry, afs_int32 releasetype)
 {
     int this_op = VLREPLACEENTRY;
@@ -664,18 +767,18 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
        hashVol[typeindex] = 0;
     hashnewname = 0;
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
 
     if ((code = check_vldbentry(newentry)))
-       goto end;
+       return code;
 
     if (voltype != -1 && InvalidVoltype(voltype))
-       END(VL_BADVOLTYPE);
+       return VL_BADVOLTYPE;
 
     if (releasetype && InvalidReleasetype(releasetype))
-       END(VL_BADRELLOCKTYPE);
+       return VL_BADRELLOCKTYPE;
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     /* find vlentry we're changing */
@@ -760,20 +863,27 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
        ABORT(VL_IO);
     }
 
-    END(ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
-
-  end:
-    osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
-              AUD_END);
     return code;
 }
 
 afs_int32
-SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+                struct vldbentry *newentry, afs_int32 releasetype)
+{
+    afs_int32 code;
+
+    code = ReplaceEntry(rxcall, volid, voltype, newentry, releasetype);
+    osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid, AUD_END);
+    return code;
+}
+
+static afs_int32
+ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
                  struct nvldbentry *newentry, afs_int32 releasetype)
 {
     int this_op = VLREPLACEENTRYN;
@@ -789,18 +899,18 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
        hashVol[typeindex] = 0;
     hashnewname = 0;
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
 
     if ((code = check_nvldbentry(newentry)))
-       goto end;
+       return code;
 
     if (voltype != -1 && InvalidVoltype(voltype))
-       END(VL_BADVOLTYPE);
+       return VL_BADVOLTYPE;
 
     if (releasetype && InvalidReleasetype(releasetype))
-       END(VL_BADRELLOCKTYPE);
+       return VL_BADRELLOCKTYPE;
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     /* find vlentry we're changing */
@@ -862,15 +972,22 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
        ABORT(VL_IO);
     }
 
-    END(ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
 
-  end:
-    osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
-              AUD_END);
+afs_int32
+SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+                 struct nvldbentry *newentry, afs_int32 releasetype)
+{
+    afs_int32 code;
+
+    code = ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype);
+    osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid, AUD_END);
     return code;
 }
 
@@ -880,12 +997,12 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
  * appropriate bits in the Mask field in VldbUpdateentry. */
 /* this routine may never have been tested; use replace entry instead
  * unless you're brave */
-afs_int32
-SVL_UpdateEntry(struct rx_call *rxcall,
-               afs_uint32 volid,
-               afs_int32 voltype,
-               struct VldbUpdateEntry *updateentry,    /* Update entry copied here */
-               afs_int32 releasetype)
+static afs_int32
+UpdateEntry(struct rx_call *rxcall,
+           afs_uint32 volid,
+           afs_int32 voltype,
+           struct VldbUpdateEntry *updateentry,        /* Update entry copied here */
+           afs_int32 releasetype)
 {
     int this_op = VLUPDATEENTRY;
     struct vl_ctx ctx;
@@ -895,13 +1012,13 @@ SVL_UpdateEntry(struct rx_call *rxcall,
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
     if ((voltype != -1) && (InvalidVoltype(voltype)))
-       END(VL_BADVOLTYPE);
+       return VL_BADVOLTYPE;
     if (releasetype && InvalidReleasetype(releasetype))
-       END(VL_BADRELLOCKTYPE);
+       return VL_BADRELLOCKTYPE;
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
@@ -921,24 +1038,33 @@ SVL_UpdateEntry(struct rx_call *rxcall,
     if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
        ABORT(VL_IO);
     }
-    END(ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
-
-  end:
-    osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid,
-              AUD_END);
     return code;
 }
 
-
 afs_int32
-SVL_UpdateEntryByName(struct rx_call *rxcall,
-                     char *volname,
-                     struct VldbUpdateEntry *updateentry, /* Update entry copied here */
-                     afs_int32 releasetype)
+SVL_UpdateEntry(struct rx_call *rxcall,
+               afs_uint32 volid,
+               afs_int32 voltype,
+               struct VldbUpdateEntry *updateentry,
+               afs_int32 releasetype)
+{
+    afs_int32 code;
+
+    code = UpdateEntry(rxcall, volid, voltype, updateentry, releasetype);
+    osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid, AUD_END);
+    return code;
+}
+
+static afs_int32
+UpdateEntryByName(struct rx_call *rxcall,
+                 char *volname,
+                 struct VldbUpdateEntry *updateentry, /* Update entry copied here */
+                 afs_int32 releasetype)
 {
     int this_op = VLUPDATEENTRYBYNAME;
     struct vl_ctx ctx;
@@ -947,11 +1073,11 @@ SVL_UpdateEntryByName(struct rx_call *rxcall,
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
     if (releasetype && InvalidReleasetype(releasetype))
-       END(VL_BADRELLOCKTYPE);
+       return VL_BADRELLOCKTYPE;
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     blockindex = FindByName(&ctx, volname, &tentry, &code);
     if (blockindex == 0) {     /* entry not found */
@@ -970,22 +1096,31 @@ SVL_UpdateEntryByName(struct rx_call *rxcall,
     if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
        ABORT(VL_IO);
     }
-    END(ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
+
+afs_int32
+SVL_UpdateEntryByName(struct rx_call *rxcall,
+                     char *volname,
+                     struct VldbUpdateEntry *updateentry, /* Update entry copied here */
+                     afs_int32 releasetype)
+{
+    afs_int32 code;
 
-  end:
+    code = UpdateEntryByName(rxcall, volname, updateentry, releasetype);
     osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, -1, AUD_END);
     return code;
 }
 
-
 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
-afs_int32
-SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
-           afs_int32 voloper)
+static afs_int32
+SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+       afs_int32 voloper)
 {
     int this_op = VLSETLOCK;
     afs_int32 timestamp, blockindex, code;
@@ -995,13 +1130,13 @@ SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
     if ((voltype != -1) && (InvalidVoltype(voltype)))
-       END(VL_BADVOLTYPE);
+       return VL_BADVOLTYPE;
     if (InvalidOperation(voloper))
-       END(VL_BADVOLOPER);
+       return VL_BADVOLOPER;
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
@@ -1035,25 +1170,32 @@ SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
        ABORT(VL_IO);
     }
-    END(ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
+    return code;
+}
+
+afs_int32
+SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+           afs_int32 voloper)
+{
+    afs_int32 code;
 
-  end:
+    code = SetLock(rxcall, volid, voltype, voloper);
     osi_auditU(rxcall, VLSetLockEvent, code, AUD_LONG, volid, AUD_END);
     return code;
 }
 
-
 /* Release an already locked vldb entry. Releasetype determines what
  * fields (afsid and/or volume operation) will be cleared along with
  * the lock time stamp. */
 
-afs_int32
-SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
-               afs_int32 releasetype)
+static afs_int32
+ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+           afs_int32 releasetype)
 {
     int this_op = VLRELEASELOCK;
     afs_int32 blockindex, code;
@@ -1063,13 +1205,13 @@ SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
-       END(VL_PERM);
+       return VL_PERM;
     if ((voltype != -1) && (InvalidVoltype(voltype)))
-       END(VL_BADVOLTYPE);
+       return VL_BADVOLTYPE;
     if (releasetype && InvalidReleasetype(releasetype))
-       END(VL_BADRELLOCKTYPE);
+       return VL_BADRELLOCKTYPE;
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
-       goto end;
+       return code;
 
     VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
@@ -1086,27 +1228,33 @@ SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     if (vlentrywrite(ctx.trans, blockindex, &tentry, sizeof(tentry))) {
        ABORT(VL_IO);
     }
-    END(ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
   abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
-
-  end:
-    osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid,
-              AUD_END);
     return code;
 }
 
+afs_int32
+SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+               afs_int32 releasetype)
+{
+    afs_int32 code;
+
+    code = ReleaseLock(rxcall, volid, voltype, releasetype);
+    osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid, AUD_END);
+    return code;
+}
 
 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
  * the remaining parameters (i.e. next_index) are used so that sequential
  * calls to this routine will get the next (all) vldb entries.
  */
-afs_int32
-SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
-             afs_int32 *count, afs_int32 *next_index,
-             struct vldbentry *aentry)
+static afs_int32
+ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
+         afs_int32 *count, afs_int32 *next_index,
+         struct vldbentry *aentry)
 {
     int this_op = VLLISTENTRY;
     int code;
@@ -1115,24 +1263,47 @@ SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
     char rxstr[AFS_RXINFO_LEN];
 
     countRequest(this_op);
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
+       return VL_PERM;
+
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
        return code;
     VLog(25, ("OListEntry index=%d %s\n", previous_index,
               rxinfo(rxstr, rxcall)));
     *next_index = NextEntry(&ctx, previous_index, &tentry, count);
-    if (*next_index)
-       vlentry_to_vldbentry(&ctx, &tentry, aentry);
-    return (ubik_EndTrans(ctx.trans));
+    if (*next_index) {
+       code = vlentry_to_vldbentry(&ctx, &tentry, aentry);
+       if (code) {
+           countAbort(this_op);
+           ubik_AbortTrans(ctx.trans);
+           return code;
+       }
+    }
+    return ubik_EndTrans(ctx.trans);
+}
+
+afs_int32
+SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
+             afs_int32 *count, afs_int32 *next_index,
+             struct vldbentry *aentry)
+{
+    afs_int32 code;
+
+    code = ListEntry(rxcall, previous_index, count, next_index, aentry);
+    osi_auditU(rxcall, VLListEntryEvent, code, AUD_LONG, previous_index, AUD_END);
+    return code;
 }
 
 /* ListEntry returns a single vldb entry, aentry, with offset previous_index;
  * the remaining parameters (i.e. next_index) are used so that sequential
  * calls to this routine will get the next (all) vldb entries.
  */
-afs_int32
-SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
-              afs_int32 *count, afs_int32 *next_index,
-              struct nvldbentry *aentry)
+static afs_int32
+ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
+          afs_int32 *count, afs_int32 *next_index,
+          struct nvldbentry *aentry)
 {
     int this_op = VLLISTENTRYN;
     int code;
@@ -1141,15 +1312,38 @@ SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
     char rxstr[AFS_RXINFO_LEN];
 
     countRequest(this_op);
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
+       return VL_PERM;
+
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
        return code;
     VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall)));
     *next_index = NextEntry(&ctx, previous_index, &tentry, count);
-    if (*next_index)
-       vlentry_to_nvldbentry(&ctx, &tentry, aentry);
-    return (ubik_EndTrans(ctx.trans));
+    if (*next_index) {
+       code = vlentry_to_nvldbentry(&ctx, &tentry, aentry);
+       if (code) {
+           countAbort(this_op);
+           ubik_AbortTrans(ctx.trans);
+           return code;
+       }
+    }
+
+    return ubik_EndTrans(ctx.trans);
 }
 
+afs_int32
+SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
+              afs_int32 *count, afs_int32 *next_index,
+              struct nvldbentry *aentry)
+{
+    afs_int32 code;
+
+    code = ListEntryN(rxcall, previous_index, count, next_index, aentry);
+    osi_auditU(rxcall, VLListEntryEventN, code, AUD_LONG, previous_index, AUD_END);
+    return code;
+}
 
 /* Retrieves in vldbentries all vldb entries that match the specified
  * attributes (by server number, partition, volume type, and flag); if volume
@@ -1157,11 +1351,11 @@ SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
  * CAUTION: This could be a very expensive call since in most cases
  * sequential search of all vldb entries is performed.
  */
-afs_int32
-SVL_ListAttributes(struct rx_call *rxcall,
-                  struct VldbListByAttributes *attributes,
-                  afs_int32 *nentries,
-                  bulkentries *vldbentries)
+static afs_int32
+ListAttributes(struct rx_call *rxcall,
+              struct VldbListByAttributes *attributes,
+              afs_int32 *nentries,
+              bulkentries *vldbentries)
 {
     int this_op = VLLISTATTRIBUTES;
     int code, allocCount = 0;
@@ -1172,13 +1366,18 @@ SVL_ListAttributes(struct rx_call *rxcall,
     char rxstr[AFS_RXINFO_LEN];
 
     countRequest(this_op);
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
+       return VL_PERM;
+
     vldbentries->bulkentries_val = 0;
     vldbentries->bulkentries_len = *nentries = 0;
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
        return code;
     allocCount = VLDBALLOCCOUNT;
     Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
-       (vldbentry *) malloc(allocCount * sizeof(vldbentry));
+       malloc(allocCount * sizeof(vldbentry));
     if (Vldbentry == NULL) {
        code = VL_NOMEM;
        goto abort;
@@ -1263,9 +1462,8 @@ SVL_ListAttributes(struct rx_call *rxcall,
        && (allocCount > vldbentries->bulkentries_len)) {
 
        vldbentries->bulkentries_val =
-           (vldbentry *) realloc(vldbentries->bulkentries_val,
-                                 vldbentries->bulkentries_len *
-                                 sizeof(vldbentry));
+           realloc(vldbentries->bulkentries_val,
+                   vldbentries->bulkentries_len * sizeof(vldbentry));
        if (vldbentries->bulkentries_val == NULL) {
            code = VL_NOMEM;
            goto abort;
@@ -1274,7 +1472,7 @@ SVL_ListAttributes(struct rx_call *rxcall,
     VLog(5,
         ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
          rxinfo(rxstr, rxcall)));
-    return (ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
 abort:
     if (vldbentries->bulkentries_val)
@@ -1284,15 +1482,27 @@ abort:
 
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
-
     return code;
 }
 
 afs_int32
-SVL_ListAttributesN(struct rx_call *rxcall,
-                   struct VldbListByAttributes *attributes,
-                   afs_int32 *nentries,
-                   nbulkentries *vldbentries)
+SVL_ListAttributes(struct rx_call *rxcall,
+                  struct VldbListByAttributes *attributes,
+                  afs_int32 *nentries,
+                  bulkentries *vldbentries)
+{
+    afs_int32 code;
+
+    code = ListAttributes(rxcall, attributes, nentries, vldbentries);
+    osi_auditU(rxcall, VLListAttributesEvent, code, AUD_END);
+    return code;
+}
+
+static afs_int32
+ListAttributesN(struct rx_call *rxcall,
+               struct VldbListByAttributes *attributes,
+               afs_int32 *nentries,
+               nbulkentries *vldbentries)
 {
     int this_op = VLLISTATTRIBUTESN;
     int code, allocCount = 0;
@@ -1303,13 +1513,18 @@ SVL_ListAttributesN(struct rx_call *rxcall,
     char rxstr[AFS_RXINFO_LEN];
 
     countRequest(this_op);
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
+       return VL_PERM;
+
     vldbentries->nbulkentries_val = 0;
     vldbentries->nbulkentries_len = *nentries = 0;
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
        return code;
     allocCount = VLDBALLOCCOUNT;
     Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
-       (nvldbentry *) malloc(allocCount * sizeof(nvldbentry));
+       malloc(allocCount * sizeof(nvldbentry));
     if (Vldbentry == NULL) {
        code = VL_NOMEM;
        goto abort;
@@ -1395,9 +1610,8 @@ SVL_ListAttributesN(struct rx_call *rxcall,
        && (allocCount > vldbentries->nbulkentries_len)) {
 
        vldbentries->nbulkentries_val =
-           (nvldbentry *) realloc(vldbentries->nbulkentries_val,
-                                  vldbentries->nbulkentries_len *
-                                  sizeof(nvldbentry));
+           realloc(vldbentries->nbulkentries_val,
+                   vldbentries->nbulkentries_len * sizeof(nvldbentry));
        if (vldbentries->nbulkentries_val == NULL) {
            code = VL_NOMEM;
            goto abort;
@@ -1406,7 +1620,7 @@ SVL_ListAttributesN(struct rx_call *rxcall,
     VLog(5,
         ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
          rxinfo(rxstr, rxcall)));
-    return (ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
 abort:
     countAbort(this_op);
@@ -1418,15 +1632,27 @@ abort:
     return code;
 }
 
-
 afs_int32
-SVL_ListAttributesN2(struct rx_call *rxcall,
-                    struct VldbListByAttributes *attributes,
-                    char *name,                /* Wildcarded volume name */
-                    afs_int32 startindex,
-                    afs_int32 *nentries,
-                    nbulkentries *vldbentries,
-                    afs_int32 *nextstartindex)
+SVL_ListAttributesN(struct rx_call *rxcall,
+                   struct VldbListByAttributes *attributes,
+                   afs_int32 *nentries,
+                   nbulkentries *vldbentries)
+{
+    afs_int32 code;
+
+    code = ListAttributesN(rxcall, attributes, nentries, vldbentries);
+    osi_auditU(rxcall, VLListAttributesNEvent, code, AUD_END);
+    return code;
+}
+
+static afs_int32
+ListAttributesN2(struct rx_call *rxcall,
+                struct VldbListByAttributes *attributes,
+                char *name,            /* Wildcarded volume name */
+                afs_int32 startindex,
+                afs_int32 *nentries,
+                nbulkentries *vldbentries,
+                afs_int32 *nextstartindex)
 {
     int this_op = VLLISTATTRIBUTESN2;
     int code = 0, maxCount = VLDBALLOCCOUNT;
@@ -1440,7 +1666,8 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
     int pollcount = 0;
     int namematchRWBK, namematchRO, thismatch;
     int matchtype = 0;
-    char volumename[VL_MAXNAMELEN+2]; /* regex anchors */
+    int size;
+    char volumename[VL_MAXNAMELEN+3]; /* regex anchors */
     char rxstr[AFS_RXINFO_LEN];
 #ifdef HAVE_POSIX_REGEX
     regex_t re;
@@ -1450,6 +1677,11 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
 #endif
 
     countRequest(this_op);
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
+       return VL_PERM;
+
     vldbentries->nbulkentries_val = 0;
     vldbentries->nbulkentries_len = 0;
     *nentries = 0;
@@ -1460,7 +1692,7 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
        return code;
 
     Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
-       (nvldbentry *) malloc(maxCount * sizeof(nvldbentry));
+       malloc(maxCount * sizeof(nvldbentry));
     if (Vldbentry == NULL) {
        countAbort(this_op);
        ubik_AbortTrans(ctx.trans);
@@ -1504,7 +1736,15 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
        findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
        findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
        if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
-           sprintf(volumename, "^%s$", name);
+           if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
+               code = VL_PERM;
+               goto done;
+           }
+           size = snprintf(volumename, sizeof(volumename), "^%s$", name);
+           if (size < 0 || size >= sizeof(volumename)) {
+               code = VL_BADNAME;
+               goto done;
+           }
 #ifdef HAVE_POSIX_REGEX
            if (regcomp(&re, volumename, REG_NOSUB) != 0) {
                code = VL_BADNAME;
@@ -1549,7 +1789,12 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
                    /* Does the name match the RW name */
                    if (tentry.flags & VLF_RWEXISTS) {
                        if (findname) {
-                           sprintf(volumename, "%s", tentry.name);
+                           size = snprintf(volumename, sizeof(volumename),
+                                           "%s", tentry.name);
+                           if (size < 0 || size >= sizeof(volumename)) {
+                               code = VL_BADNAME;
+                               goto done;
+                           }
 #ifdef HAVE_POSIX_REGEX
                            if (regexec(&re, volumename, 0, NULL, 0) == 0) {
                                thismatch = VLSF_RWVOL;
@@ -1567,7 +1812,13 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
                    /* Does the name match the BK name */
                    if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
                        if (findname) {
-                           sprintf(volumename, "%s.backup", tentry.name);
+                           /* If this fails, the tentry.name is invalid */
+                           size = snprintf(volumename, sizeof(volumename),
+                                           "%s.backup", tentry.name);
+                           if (size < 0 || size >= sizeof(volumename)) {
+                               code = VL_BADNAME;
+                               goto done;
+                           }
 #ifdef HAVE_POSIX_REGEX
                            if (regexec(&re, volumename, 0, NULL, 0) == 0) {
                                thismatch = VLSF_BACKVOL;
@@ -1590,14 +1841,19 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
                 * pick up entries marked NEWREPSITEs and DONTUSE.
                 */
                else {
-                   if (tentry.flags & VLF_ROEXISTS) {
+                   if ((tentry.serverFlags[k] & VLSF_ROVOL) != 0) {
                        if (findname) {
                            if (namematchRO) {
                                thismatch =
                                    ((namematchRO == 1) ? VLSF_ROVOL : 0);
                            } else {
-                               sprintf(volumename, "%s.readonly",
-                                       tentry.name);
+                               /* If this fails, the tentry.name is invalid */
+                               size = snprintf(volumename, sizeof(volumename),
+                                               "%s.readonly", tentry.name);
+                               if (size < 0 || size >= sizeof(volumename)) {
+                                   code = VL_BADNAME;
+                                   goto done;
+                               }
 #ifdef HAVE_POSIX_REGEX
                            if (regexec(&re, volumename, 0, NULL, 0) == 0) {
                                thismatch = VLSF_ROVOL;
@@ -1675,19 +1931,36 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
        countAbort(this_op);
        ubik_AbortTrans(ctx.trans);
        if (vldbentries->nbulkentries_val)
-           free((char *)vldbentries->nbulkentries_val);
+           free(vldbentries->nbulkentries_val);
        vldbentries->nbulkentries_val = 0;
        vldbentries->nbulkentries_len = 0;
        *nextstartindex = -1;
-       return code;
     } else {
        VLog(5,
             ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
              rxinfo(rxstr, rxcall)));
-       return (ubik_EndTrans(ctx.trans));
+       code = ubik_EndTrans(ctx.trans);
     }
+
+    return code;
 }
 
+afs_int32
+SVL_ListAttributesN2(struct rx_call *rxcall,
+                    struct VldbListByAttributes *attributes,
+                    char *name,                /* Wildcarded volume name */
+                    afs_int32 startindex,
+                    afs_int32 *nentries,
+                    nbulkentries *vldbentries,
+                    afs_int32 *nextstartindex)
+{
+    afs_int32 code;
+
+    code = ListAttributesN2(rxcall, attributes, name, startindex,
+                           nentries, vldbentries, nextstartindex);
+    osi_auditU(rxcall, VLListAttributesN2Event, code, AUD_END);
+    return code;
+}
 
 /* Retrieves in vldbentries all vldb entries that match the specified
  * attributes (by server number, partition, volume type, and flag); if
@@ -1695,11 +1968,11 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
  * returned. CAUTION: This could be a very expensive call since in most
  * cases sequential search of all vldb entries is performed.
  */
-afs_int32
-SVL_LinkedList(struct rx_call *rxcall,
-              struct VldbListByAttributes *attributes,
-              afs_int32 *nentries,
-              vldb_list *vldbentries)
+static afs_int32
+LinkedList(struct rx_call *rxcall,
+          struct VldbListByAttributes *attributes,
+          afs_int32 *nentries,
+          vldb_list *vldbentries)
 {
     int this_op = VLLINKEDLIST;
     int code;
@@ -1712,6 +1985,11 @@ SVL_LinkedList(struct rx_call *rxcall,
     int pollcount = 0;
 
     countRequest(this_op);
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
+       return VL_PERM;
+
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
        return code;
 
@@ -1729,12 +2007,15 @@ SVL_LinkedList(struct rx_call *rxcall,
            goto abort;
        }
 
-       vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
+       vllist = malloc(sizeof(single_vldbentry));
        if (vllist == NULL) {
            code = VL_NOMEM;
            goto abort;
        }
-       vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       if (code)
+           goto abort;
+
        vllist->next_vldb = NULL;
 
        *vllistptr = vllist;    /* Thread onto list */
@@ -1799,12 +2080,15 @@ SVL_LinkedList(struct rx_call *rxcall,
                    continue;
            }
 
-           vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
+           vllist = malloc(sizeof(single_vldbentry));
            if (vllist == NULL) {
                code = VL_NOMEM;
                goto abort;
            }
-           vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           if (code)
+               goto abort;
+
            vllist->next_vldb = NULL;
 
            *vllistptr = vllist;        /* Thread onto list */
@@ -1817,7 +2101,7 @@ SVL_LinkedList(struct rx_call *rxcall,
        }
     }
     *vllistptr = NULL;
-    return (ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
 abort:
     countAbort(this_op);
@@ -1826,10 +2110,23 @@ abort:
 }
 
 afs_int32
-SVL_LinkedListN(struct rx_call *rxcall,
-               struct VldbListByAttributes *attributes,
-               afs_int32 *nentries,
-               nvldb_list *vldbentries)
+SVL_LinkedList(struct rx_call *rxcall,
+              struct VldbListByAttributes *attributes,
+              afs_int32 *nentries,
+              vldb_list *vldbentries)
+{
+    afs_int32 code;
+
+    code = LinkedList(rxcall, attributes, nentries, vldbentries);
+    osi_auditU(rxcall, VLLinkedListEvent, code, AUD_END);
+    return code;
+}
+
+static afs_int32
+LinkedListN(struct rx_call *rxcall,
+           struct VldbListByAttributes *attributes,
+           afs_int32 *nentries,
+           nvldb_list *vldbentries)
 {
     int this_op = VLLINKEDLISTN;
     int code;
@@ -1842,6 +2139,11 @@ SVL_LinkedListN(struct rx_call *rxcall,
     int pollcount = 0;
 
     countRequest(this_op);
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
+       return VL_PERM;
+
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
        return code;
 
@@ -1859,12 +2161,15 @@ SVL_LinkedListN(struct rx_call *rxcall,
            goto abort;
        }
 
-       vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
+       vllist = malloc(sizeof(single_nvldbentry));
        if (vllist == NULL) {
            code = VL_NOMEM;
            goto abort;
        }
-       vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       if (code)
+           goto abort;
+
        vllist->next_vldb = NULL;
 
        *vllistptr = vllist;    /* Thread onto list */
@@ -1929,12 +2234,15 @@ SVL_LinkedListN(struct rx_call *rxcall,
                    continue;
            }
 
-           vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
+           vllist = malloc(sizeof(single_nvldbentry));
            if (vllist == NULL) {
                code = VL_NOMEM;
                goto abort;
            }
-           vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           if (code)
+               goto abort;
+
            vllist->next_vldb = NULL;
 
            *vllistptr = vllist;        /* Thread onto list */
@@ -1947,7 +2255,7 @@ SVL_LinkedListN(struct rx_call *rxcall,
        }
     }
     *vllistptr = NULL;
-    return (ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
 
 abort:
     countAbort(this_op);
@@ -1955,14 +2263,27 @@ abort:
     return code;
 }
 
+afs_int32
+SVL_LinkedListN(struct rx_call *rxcall,
+               struct VldbListByAttributes *attributes,
+               afs_int32 *nentries,
+               nvldb_list *vldbentries)
+{
+    afs_int32 code;
+
+    code = LinkedListN(rxcall, attributes, nentries, vldbentries);
+    osi_auditU(rxcall, VLLinkedListNEvent, code, AUD_END);
+    return code;
+}
+
 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
  * totalentries, etc) and dynamic statistics (number of requests and/or
  * aborts per remote procedure call, etc)
  */
-afs_int32
-SVL_GetStats(struct rx_call *rxcall,
-            vldstats *stats,
-            vital_vlheader *vital_header)
+static afs_int32
+GetStats(struct rx_call *rxcall,
+        vldstats *stats,
+        vital_vlheader *vital_header)
 {
     int this_op = VLGETSTATS;
     afs_int32 code;
@@ -1970,18 +2291,30 @@ SVL_GetStats(struct rx_call *rxcall,
     char rxstr[AFS_RXINFO_LEN];
 
     countRequest(this_op);
-#ifdef notdef
-    /* Allow users to get statistics freely */
-    if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))        /* Must be in 'UserList' to use */
+
+    if (!afsconf_CheckRestrictedQuery(vldb_confdir, rxcall,
+                                     restrictedQueryLevel))
        return VL_PERM;
-#endif
+
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
        return code;
     VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
     memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
           sizeof(vital_vlheader));
     memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
-    return (ubik_EndTrans(ctx.trans));
+    return ubik_EndTrans(ctx.trans);
+}
+
+afs_int32
+SVL_GetStats(struct rx_call *rxcall,
+            vldstats *stats,
+            vital_vlheader *vital_header)
+{
+    afs_int32 code;
+
+    code = GetStats(rxcall, stats, vital_header);
+    osi_auditU(rxcall, VLGetStatsEvent, code, AUD_END);
+    return code;
 }
 
 /* Get the list of file server addresses from the VLDB.  Currently it's pretty
@@ -2012,7 +2345,7 @@ SVL_GetAddrs(struct rx_call *rxcall,
 
     VLog(5, ("GetAddrs\n"));
     addrsp->bulkaddrs_val = taddrp =
-       (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
+       malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
     nservers = *nentries = addrsp->bulkaddrs_len = 0;
 
     if (!taddrp) {
@@ -2036,7 +2369,16 @@ abort:
     return code;
 }
 
-#define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
+static_inline void
+append_addr(char *buffer, afs_uint32 addr, size_t buffer_size)
+{
+    int n = strlen(buffer);
+    if (buffer_size > n) {
+       snprintf(buffer + n, buffer_size - n, "%u.%u.%u.%u",
+                (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
+                addr & 0xff);
+    }
+}
 
 afs_int32
 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
@@ -2045,11 +2387,12 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
     int this_op = VLREGADDR;
     afs_int32 code;
     struct vl_ctx ctx;
-    int cnt, h, i, j, k, m, base, index;
+    int cnt, h, i, j, k, m;
     struct extentaddr *exp = 0, *tex;
+    char addrbuf[256];
     afsUUID tuuid;
     afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
-    afs_int32 fbase;
+    int base;
     int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
     int WillReplaceEntry, WillChange[MAXSERVERID + 1];
     int FoundUuid = 0;
@@ -2093,31 +2436,12 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
     for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
        willChangeEntry = 0;
        WillReplaceEntry = 1;
-       if ((ctx.hostaddress[srvidx] & 0xff000000) == 0xff000000) {
-           /* The server is registered as a multihomed */
-           base = (ctx.hostaddress[srvidx] >> 16) & 0xff;
-           index = ctx.hostaddress[srvidx] & 0x0000ffff;
-           if (base >= VL_MAX_ADDREXTBLKS) {
-               VLog(0,
-                    ("Internal error: Multihome extent base is too large. Base %d index %d\n",
-                     base, index));
-               continue;
-           }
-           if (index >= VL_MHSRV_PERBLK) {
-               VLog(0,
-                    ("Internal error: Multihome extent index is too large. Base %d index %d\n",
-                     base, index));
-               continue;
-           }
-           if (!ctx.ex_addr[base]) {
-               VLog(0,
-                    ("Internal error: Multihome extent does not exist. Base %d\n",
-                     base));
-               continue;
-           }
+       code = multiHomedExtent(&ctx, srvidx, &exp);
+       if (code)
+            continue;
 
+       if (exp) {
            /* See if the addresses to register will change this server entry */
-           exp = &ctx.ex_addr[base][index];
            tuuid = exp->ex_hostuuid;
            afs_ntohuuid(&tuuid);
            if (afs_uuid_equal(uuidp, &tuuid)) {
@@ -2170,29 +2494,27 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        || (!foundUuidEntry && (count > 1))) {
        VLog(0,
             ("The following fileserver is being registered in the VLDB:\n"));
-       VLog(0, ("      ["));
-       for (k = 0; k < cnt; k++) {
+       for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
            if (k > 0)
-               VLog(0,(" "));
-           PADDR(addrs[k]);
+               strlcat(addrbuf, " ", sizeof(addrbuf));
+           append_addr(addrbuf, addrs[k], sizeof(addrbuf));
        }
-       VLog(0,("]\n"));
+       VLog(0, ("      [%s]\n", addrbuf));
 
        if (foundUuidEntry) {
-           VLog(0,
-                ("   It would have replaced the existing VLDB server entry:\n"));
-           VLog(0, ("      entry %d: [", FoundUuid));
-           base = (ctx.hostaddress[FoundUuid] >> 16) & 0xff;
-           index = ctx.hostaddress[FoundUuid] & 0x0000ffff;
-           exp = &ctx.ex_addr[base][index];
-           for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
-               if (!exp->ex_addrs[mhidx])
-                   continue;
-               if (mhidx > 0)
-                   VLog(0,(" "));
-               PADDR(ntohl(exp->ex_addrs[mhidx]));
+           code = multiHomedExtent(&ctx, FoundUuid, &exp);
+           if (code == 0) {
+               VLog(0, ("   It would have replaced the existing VLDB server "
+                        "entry:\n"));
+               for (addrbuf[0] = '\0', mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
+                   if (!exp->ex_addrs[mhidx])
+                       continue;
+                   if (mhidx > 0)
+                       strlcat(addrbuf, " ", sizeof(addrbuf));
+                   append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
+               }
+               VLog(0, ("      entry %d: [%s]\n", FoundUuid, addrbuf));
            }
-           VLog(0, ("]\n"));
        }
 
        if (count == 1)
@@ -2202,23 +2524,24 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        for (j = 0; j < count; j++) {
            srvidx = WillChange[j];
            VLog(0, ("      entry %d: ", srvidx));
-           if ((ctx.hostaddress[srvidx] & 0xff000000) == 0xff000000) {
-               VLog(0, ("["));
-               base = (ctx.hostaddress[srvidx] >> 16) & 0xff;
-               index = ctx.hostaddress[srvidx] & 0x0000ffff;
-               exp = &ctx.ex_addr[base][index];
+
+           code = multiHomedExtent(&ctx, srvidx, &exp);
+           if (code)
+               goto abort;
+
+           addrbuf[0] = '\0';
+           if (exp) {
                for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
                    if (!exp->ex_addrs[mhidx])
                        continue;
                    if (mhidx > 0)
-                       VLog(0, (" "));
-                   PADDR(ntohl(exp->ex_addrs[mhidx]));
+                       strlcat(addrbuf, " ", sizeof(addrbuf));
+                   append_addr(addrbuf, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf));
                }
-               VLog(0, ("]"));
            } else {
-               PADDR(ctx.hostaddress[srvidx]);
+               append_addr(addrbuf, ctx.hostaddress[srvidx], sizeof(addrbuf));
            }
-           VLog(0, ("\n"));
+           VLog(0, ("      entry %d: [%s]\n", srvidx, addrbuf));
        }
 
        if (count == 1)
@@ -2242,9 +2565,9 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        /* Found the entry with same uuid. See if we need to change it */
        int change = 0;
 
-       fbase = (ctx.hostaddress[FoundUuid] >> 16) & 0xff;
-       index = ctx.hostaddress[FoundUuid] & 0x0000ffff;
-       exp = &ctx.ex_addr[fbase][index];
+       code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
+       if (code)
+           goto abort;
 
        /* Determine if the entry has changed */
        for (k = 0; ((k < cnt) && !change); k++) {
@@ -2261,26 +2584,24 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
     }
 
     VLog(0, ("The following fileserver is being registered in the VLDB:\n"));
-    VLog(0, ("      ["));
-    for (k = 0; k < cnt; k++) {
+    for (addrbuf[0] = '\0', k = 0; k < cnt; k++) {
        if (k > 0)
-           VLog(0, (" "));
-       PADDR(addrs[k]);
+           strlcat(addrbuf, " ", sizeof(addrbuf));
+       append_addr(addrbuf, addrs[k], sizeof(addrbuf));
     }
-    VLog(0, ("]\n"));
+    VLog(0, ("      [%s]\n", addrbuf));
 
     if (foundUuidEntry) {
        VLog(0,
            ("   It will replace the following existing entry in the VLDB (same uuid):\n"));
-       VLog(0, ("      entry %d: [", FoundUuid));
-       for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
+       for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
            if (exp->ex_addrs[k] == 0)
                continue;
            if (k > 0)
-               VLog(0, (" "));
-           PADDR(ntohl(exp->ex_addrs[k]));
+               strlcat(addrbuf, " ", sizeof(addrbuf));
+           append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
        }
-       VLog(0, ("]\n"));
+       VLog(0, ("      entry %d: [%s]\n", FoundUuid, addrbuf));
     } else if (willReplaceCnt || (count == 1)) {
        /* If we are not replacing an entry and there is only one entry to change,
         * then we will replace that entry.
@@ -2291,32 +2612,31 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        }
 
        /* Have an entry that needs to be replaced */
-       if ((ctx.hostaddress[ReplaceEntry] & 0xff000000) == 0xff000000) {
-           fbase = (ctx.hostaddress[ReplaceEntry] >> 16) & 0xff;
-           index = ctx.hostaddress[ReplaceEntry] & 0x0000ffff;
-           exp = &ctx.ex_addr[fbase][index];
+       code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
+       if (code)
+           goto abort;
 
+       if (exp) {
            VLog(0,
                ("   It will replace the following existing entry in the VLDB (new uuid):\n"));
-           VLog(0, ("      entry %d: [", ReplaceEntry));
-           for (k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
+           for (addrbuf[0] = '\0', k = 0; k < VL_MAXIPADDRS_PERMH; k++) {
                if (exp->ex_addrs[k] == 0)
                    continue;
                if (k > 0)
-                   VLog(0, (" "));
-               PADDR(ntohl(exp->ex_addrs[k]));
+                   strlcat(addrbuf, " ", sizeof(addrbuf));
+               append_addr(addrbuf, ntohl(exp->ex_addrs[k]), sizeof(addrbuf));
            }
-           VLog(0, ("]\n"));
+           VLog(0, ("      entry %d: [%s]\n", ReplaceEntry, addrbuf));
        } else {
            /* Not a mh entry. So we have to create a new mh entry and
             * put it on the ReplaceEntry slot of the ctx.hostaddress array.
             */
-           VLog(0, ("   It will replace existing entry %d, ", ReplaceEntry));
-           PADDR(ctx.hostaddress[ReplaceEntry]);
-           VLog(0,(", in the VLDB (new uuid):\n"));
-
+           addrbuf[0] = '\0';
+           append_addr(addrbuf, ctx.hostaddress[ReplaceEntry], sizeof(addrbuf));
+           VLog(0, ("   It will replace existing entry %d, %s,"
+                    " in the VLDB (new uuid):\n", ReplaceEntry, addrbuf));
            code =
-               FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &fbase);
+               FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
            if (code || !exp) {
                if (!code)
                    code = VL_IO;
@@ -2328,7 +2648,7 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
         * well as use a new slot of the ctx.hostaddress array.
         */
        VLog(0, ("   It will create a new entry in the VLDB.\n"));
-       code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &fbase);
+       code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
        if (code || !exp) {
            if (!code)
                code = VL_IO;
@@ -2353,8 +2673,8 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
     /* Write the new mh entry out */
     if (vlwrite
        (ctx.trans,
-        DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[fbase]),
-                (char *)ctx.ex_addr[fbase], (char *)exp), (char *)exp,
+        DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
+                (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
         sizeof(*exp))) {
        code = VL_IO;
        goto abort;
@@ -2371,20 +2691,19 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
            continue;
 
-       base = (ctx.hostaddress[WillChange[i]] >> 16) & 0xff;
-       index = ctx.hostaddress[WillChange[i]] & 0x0000ffff;
-       tex = &ctx.ex_addr[base][index];
+       code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
+       if (code)
+           goto abort;
 
        if (++m == 1)
            VLog(0,
                ("   The following existing entries in the VLDB will be updated:\n"));
 
-       VLog(0, ("      entry %d: [", WillChange[i]));
-       for (h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
+       for (addrbuf[0] = '\0', h = j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
            if (tex->ex_addrs[j]) {
                if (j > 0)
-                   printf(" ");
-               PADDR(ntohl(tex->ex_addrs[j]));
+                   strlcat(addrbuf, " ", sizeof(addrbuf));
+               append_addr(addrbuf, ntohl(tex->ex_addrs[j]), sizeof(addrbuf));
            }
 
            for (k = 0; k < cnt; k++) {
@@ -2400,7 +2719,7 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        for (j = h; j < VL_MAXIPADDRS_PERMH; j++) {
            tex->ex_addrs[j] = 0;       /* zero rest of mh entry */
        }
-       VLog(0, ("]\n"));
+       VLog(0, ("      entry %d: [%s]\n", WillChange[i], addrbuf));
 
        /* Write out the modified mh entry */
        tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1);
@@ -2408,8 +2727,8 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
            DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
                    (char *)ctx.ex_addr[base], (char *)tex);
        if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) {
-           ubik_AbortTrans(ctx.trans);
-           return VL_IO;
+           code = VL_IO;
+           goto abort;
        }
     }
 
@@ -2419,7 +2738,6 @@ abort:
     countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
     return code;
-
 }
 
 afs_int32
@@ -2431,7 +2749,7 @@ SVL_GetAddrsU(struct rx_call *rxcall,
              bulkaddrs *addrsp)
 {
     int this_op = VLGETADDRSU;
-    afs_int32 code, index = -1, offset;
+    afs_int32 code, index;
     struct vl_ctx ctx;
     int nservers, i, j, base = 0;
     struct extentaddr *exp = 0;
@@ -2451,15 +2769,13 @@ SVL_GetAddrsU(struct rx_call *rxcall,
            code = VL_BADMASK;
            goto abort;
        }
-       for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
-           if (!ctx.ex_addr[base])
-               break;
-           for (i = 1; i < VL_MHSRV_PERBLK; i++) {
-               exp = &ctx.ex_addr[base][i];
-               tuuid = exp->ex_hostuuid;
-               afs_ntohuuid(&tuuid);
-               if (afs_uuid_is_nil(&tuuid))
-                   continue;
+       /* Search for a server registered with the VLDB with this ip address. */
+       for (index = 0; index <= MAXSERVERID; index++) {
+           code = multiHomedExtent(&ctx, index, &exp);
+           if (code)
+               continue;
+
+           if (exp) {
                for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
                    if (exp->ex_addrs[j]
                        && (ntohl(exp->ex_addrs[j]) == attributes->ipaddr)) {
@@ -2469,10 +2785,8 @@ SVL_GetAddrsU(struct rx_call *rxcall,
                if (j < VL_MAXIPADDRS_PERMH)
                    break;
            }
-           if (i < VL_MHSRV_PERBLK)
-               break;
        }
-       if (base >= VL_MAX_ADDREXTBLKS) {
+       if (index > MAXSERVERID) {
            code = VL_NOENT;
            goto abort;
        }
@@ -2481,22 +2795,17 @@ SVL_GetAddrsU(struct rx_call *rxcall,
            code = VL_BADMASK;
            goto abort;
        }
-       index = attributes->index;
-       if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) {
+       /* VLADDR_INDEX index is one based */
+       if (attributes->index < 1 || attributes->index > MAXSERVERID) {
            code = VL_INDEXERANGE;
            goto abort;
        }
-       base = index / VL_MHSRV_PERBLK;
-       offset = index % VL_MHSRV_PERBLK;
-       if (offset == 0) {
+       index = attributes->index - 1;
+       code = multiHomedExtent(&ctx, index, &exp);
+       if (code) {
            code = VL_NOENT;
            goto abort;
        }
-       if (!ctx.ex_addr[base]) {
-           code = VL_INDEXERANGE;
-           goto abort;
-       }
-       exp = &ctx.ex_addr[base][offset];
     } else if (attributes->Mask & VLADDR_UUID) {
        if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) {
            code = VL_BADMASK;
@@ -2519,7 +2828,7 @@ SVL_GetAddrsU(struct rx_call *rxcall,
        goto abort;
     }
     addrsp->bulkaddrs_val = taddrp =
-       (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
+       malloc(sizeof(afs_uint32) * (MAXSERVERID + 1));
     nservers = *nentries = addrsp->bulkaddrs_len = 0;
     if (!taddrp) {
        code = VL_NOMEM;
@@ -2574,6 +2883,7 @@ put_attributeentry(struct vl_ctx *ctx,
 {
     vldbentry *reall;
     afs_int32 allo;
+    int code;
 
     if (*Vldbentry == *VldbentryLast) {
        if (smallMem)
@@ -2584,9 +2894,8 @@ put_attributeentry(struct vl_ctx *ctx,
         * then grow in increments of VLDBALLOCINCR.
         */
        allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
-       reall =
-           (vldbentry *) realloc(*VldbentryFirst,
-                                 (*alloccnt + allo) * sizeof(vldbentry));
+       reall = realloc(*VldbentryFirst,
+                       (*alloccnt + allo) * sizeof(vldbentry));
        if (reall == NULL)
            return VL_NOMEM;
 
@@ -2595,7 +2904,11 @@ put_attributeentry(struct vl_ctx *ctx,
        *VldbentryLast = *Vldbentry + allo;
        *alloccnt += allo;
     }
-    vlentry_to_vldbentry(ctx, entry, *Vldbentry);
+
+    code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
+    if (code)
+       return code;
+
     (*Vldbentry)++;
     (*nentries)++;
     vldbentries->bulkentries_len++;
@@ -2616,6 +2929,7 @@ put_nattributeentry(struct vl_ctx *ctx,
 {
     nvldbentry *reall;
     afs_int32 allo;
+    int code;
 
     if (*Vldbentry == *VldbentryLast) {
        if (smallMem)
@@ -2626,9 +2940,8 @@ put_nattributeentry(struct vl_ctx *ctx,
         * then grow in increments of VLDBALLOCINCR.
         */
        allo = (*alloccnt > VLDBALLOCLIMIT) ? VLDBALLOCINCR : *alloccnt;
-       reall =
-           (nvldbentry *) realloc(*VldbentryFirst,
-                                  (*alloccnt + allo) * sizeof(nvldbentry));
+       reall = realloc(*VldbentryFirst,
+                       (*alloccnt + allo) * sizeof(nvldbentry));
        if (reall == NULL)
            return VL_NOMEM;
 
@@ -2637,7 +2950,10 @@ put_nattributeentry(struct vl_ctx *ctx,
        *VldbentryLast = *Vldbentry + allo;
        *alloccnt += allo;
     }
-    vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
+    code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
+    if (code)
+       return code;
+
     (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
     (*Vldbentry)++;
     (*nentries)++;
@@ -2738,7 +3054,7 @@ vldbentry_to_vlentry(struct vl_ctx *ctx,
        VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
        VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
     }
-    for (; i < OMAXNSERVERS; i++)
+    for (; i < NMAXNSERVERS; i++)
        VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
            VlEntry->serverFlags[i] = BADSERVERID;
     for (i = 0; i < MAXTYPES; i++)
@@ -3012,25 +3328,22 @@ repsite_compress(struct nvlentry *VlEntry, int offset)
 
 /* Convert from the internal (compacted) vldb entry to the external
  * representation used by the interface. */
-static void
+static int
 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
                      struct vldbentry *VldbEntry)
 {
-    int i, j;
+    int i, j, code;
+    struct extentaddr *exp;
 
     memset(VldbEntry, 0, sizeof(struct vldbentry));
     strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
     for (i = 0; i < OMAXNSERVERS; i++) {
        if (VlEntry->serverNumber[i] == BADSERVERID)
            break;
-       if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
-           0xff000000) {
-           struct extentaddr *exp;
-           int base, index;
-
-           base = (ctx->hostaddress[j] >> 16) & 0xff;
-           index = ctx->hostaddress[j] & 0x0000ffff;
-           exp = &ctx->ex_addr[base][index];
+       code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
+       if (code)
+           return code;
+       if (exp) {
            /* For now return the first ip address back */
            for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
                if (exp->ex_addrs[j]) {
@@ -3049,30 +3362,30 @@ vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
        VldbEntry->volumeId[i] = VlEntry->volumeId[i];
     VldbEntry->cloneId = VlEntry->cloneId;
     VldbEntry->flags = VlEntry->flags;
+
+    return 0;
 }
 
 
 /* Convert from the internal (compacted) vldb entry to the external
  * representation used by the interface. */
-static void
+static int
 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
                       struct nvldbentry *VldbEntry)
 {
-    int i, j;
+    int i, j, code;
+    struct extentaddr *exp;
 
-    memset(VldbEntry, 0, sizeof(struct vldbentry));
+    memset(VldbEntry, 0, sizeof(struct nvldbentry));
     strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
     for (i = 0; i < NMAXNSERVERS; i++) {
        if (VlEntry->serverNumber[i] == BADSERVERID)
            break;
-       if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
-           0xff000000) {
-           struct extentaddr *exp;
-           int base, index;
-
-           base = (ctx->hostaddress[j] >> 16) & 0xff;
-           index = ctx->hostaddress[j] & 0x0000ffff;
-           exp = &ctx->ex_addr[base][index];
+       code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
+       if (code)
+           return code;
+
+       if (exp) {
            /* For now return the first ip address back */
            for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
                if (exp->ex_addrs[j]) {
@@ -3091,33 +3404,34 @@ vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
        VldbEntry->volumeId[i] = VlEntry->volumeId[i];
     VldbEntry->cloneId = VlEntry->cloneId;
     VldbEntry->flags = VlEntry->flags;
+
+    return 0;
 }
 
-static void
+static int
 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
                       struct uvldbentry *VldbEntry)
 {
-    int i, j;
+    int i, code;
+    struct extentaddr *exp;
 
-    memset(VldbEntry, 0, sizeof(struct vldbentry));
+    memset(VldbEntry, 0, sizeof(struct uvldbentry));
     strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
     for (i = 0; i < NMAXNSERVERS; i++) {
        if (VlEntry->serverNumber[i] == BADSERVERID)
            break;
        VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
        VldbEntry->serverUnique[i] = 0;
-       if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
-           0xff000000) {
-           struct extentaddr *exp;
-           int base, index;
+       code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
+       if (code)
+           return code;
+
+       if (exp) {
            afsUUID tuuid;
 
-           base = (ctx->hostaddress[j] >> 16) & 0xff;
-           index = ctx->hostaddress[j] & 0x0000ffff;
-           exp = &ctx->ex_addr[base][index];
            tuuid = exp->ex_hostuuid;
            afs_ntohuuid(&tuuid);
-           VldbEntry->serverFlags[i] |= VLSERVER_FLAG_UUID;
+           VldbEntry->serverFlags[i] |= VLSF_UUID;
            VldbEntry->serverNumber[i] = tuuid;
            VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
        } else {
@@ -3132,6 +3446,8 @@ vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
        VldbEntry->volumeId[i] = VlEntry->volumeId[i];
     VldbEntry->cloneId = VlEntry->cloneId;
     VldbEntry->flags = VlEntry->flags;
+
+    return 0;
 }
 
 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
@@ -3185,34 +3501,16 @@ static int
 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
 {
     int i, j;
-    afs_int32 code, base, index;
+    afs_int32 code;
     struct extentaddr *exp;
 
     for (i = 0; i <= MAXSERVERID; i++) {
        if (ctx->hostaddress[i] == ipaddr)
            return i;
-       if ((ctx->hostaddress[i] & 0xff000000) == 0xff000000) {
-           base = (ctx->hostaddress[i] >> 16) & 0xff;
-           index = ctx->hostaddress[i] & 0x0000ffff;
-           if (base >= VL_MAX_ADDREXTBLKS) {
-               VLog(0,
-                    ("Internal error: Multihome extent base is too large. Base %d index %d\n",
-                     base, index));
-               return -1;      /* EINVAL */
-           }
-           if (index >= VL_MHSRV_PERBLK) {
-               VLog(0,
-                    ("Internal error: Multihome extent index is too large. Base %d index %d\n",
-                     base, index));
-               return -1;      /* EINVAL */
-           }
-           if (!ctx->ex_addr[base]) {
-               VLog(0,
-                    ("Internal error: Multihome extent does not exist. Base %d\n",
-                     base));
-               return -1;      /* EINVAL */
-           }
-           exp = &ctx->ex_addr[base][index];
+       code = multiHomedExtent(ctx, i, &exp);
+       if (code)
+           return -1;
+       if (exp) {
            for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
                if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
                    return i;
@@ -3247,15 +3545,17 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
     int i, j;
     afs_int32 code;
     struct extentaddr *exp = NULL;
-    int base = 0;
-    int index, mhidx;
+    int base = -1;
+    int mhidx;
     afsUUID tuuid;
     afs_int32 blockindex, count;
     int pollcount = 0;
     struct nvlentry tentry;
     int ipaddr1_id = -1, ipaddr2_id = -1;
+    char addrbuf1[256];
+    char addrbuf2[256];
 
-    /* Don't let addr change to 256.*.*.* : Causes internal error below */
+    /* Don't let addr change to 255.*.*.* : Causes internal error below */
     if ((ipaddr2 & 0xff000000) == 0xff000000)
        return (VL_BADSERVER);
 
@@ -3271,30 +3571,30 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
     }
 
     for (i = 0; i <= MAXSERVERID; i++) {
-       if ((ctx->hostaddress[i] & 0xff000000) == 0xff000000) {
-           base = (ctx->hostaddress[i] >> 16) & 0xff;
-           index = ctx->hostaddress[i] & 0x0000ffff;
-           if ((base >= VL_MAX_ADDREXTBLKS) || (index >= VL_MHSRV_PERBLK)) {
-               VLog(0,
-                    ("Internal error: Multihome extent addr is too large. Base %d index %d\n",
-                     base, index));
-               return -1;      /* EINVAL */
-           }
+       struct extentaddr *texp = NULL;
+       int tbase;
 
-           exp = &ctx->ex_addr[base][index];
+       code = multiHomedExtentBase(ctx, i, &texp, &tbase);
+       if (code)
+           return code;
+
+       if (texp) {
            for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
-               if (!exp->ex_addrs[mhidx])
+               if (!texp->ex_addrs[mhidx])
                    continue;
-               if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1) {
+               if (ntohl(texp->ex_addrs[mhidx]) == ipaddr1) {
                    ipaddr1_id = i;
+                   exp = texp;
+                   base = tbase;
                }
-               if (ipaddr2 != 0 && ntohl(exp->ex_addrs[mhidx]) == ipaddr2) {
+               if (ipaddr2 != 0 && ntohl(texp->ex_addrs[mhidx]) == ipaddr2) {
                    ipaddr2_id = i;
                }
            }
        } else {
            if (ctx->hostaddress[i] == ipaddr1) {
                exp = NULL;
+               base = -1;
                ipaddr1_id = i;
            }
            if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) {
@@ -3344,34 +3644,40 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
                }
            }
        }
+    } else if (exp) {
+       /* Do not allow changing addresses in multi-homed entries.
+          Older versions of this RPC would silently "downgrade" mh entries
+          to single-homed entries and orphan the mh enties. */
+       addrbuf1[0] = '\0';
+       append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
+       VLog(0, ("Refusing to change address %s in multi-homed entry; "
+                "use RegisterAddrs instead.\n", addrbuf1));
+       return VL_NOENT;        /* single-homed entry not found */
     }
 
     /* Log a message saying we are changing/removing an IP address */
     VLog(0,
         ("The following IP address is being %s:\n",
          (ipaddr2 ? "changed" : "removed")));
-    VLog(0, ("      entry %d: ", i));
+    addrbuf1[0] = addrbuf2[0] = '\0';
     if (exp) {
-       VLog(0, ("["));
        for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
            if (!exp->ex_addrs[mhidx])
                continue;
            if (mhidx > 0)
-               VLog(0, (" "));
-           PADDR(ntohl(exp->ex_addrs[mhidx]));
+               strlcat(addrbuf1, " ", sizeof(addrbuf1));
+           append_addr(addrbuf1, ntohl(exp->ex_addrs[mhidx]), sizeof(addrbuf1));
        }
-       VLog(0, ("]"));
     } else {
-       PADDR(ipaddr1);
+       append_addr(addrbuf1, ipaddr1, sizeof(addrbuf1));
     }
     if (ipaddr2) {
-       VLog(0, (" -> "));
-       PADDR(ipaddr2);
+       append_addr(addrbuf2, ipaddr2, sizeof(addrbuf2));
     }
-    VLog(0, ("\n"));
+    VLog(0, ("      entry %d: [%s] -> [%s]\n", ipaddr1_id, addrbuf1, addrbuf2));
 
     /* Change the registered uuuid addresses */
-    if (exp) {
+    if (exp && base != -1) {
        memset(&tuuid, 0, sizeof(afsUUID));
        afs_htonuuid(&tuuid);
        exp->ex_hostuuid = tuuid;