Don't trust # of entries from ListAttributes
[openafs.git] / src / libadmin / vos / vosutils.c
index 2ce3643..9f18ab6 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
 #include "vosutils.h"
 #include "vsprocs.h"
 #include "lockprocs.h"
 #include <afs/afs_AdminErrors.h>
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-
-/*
- * Functions that aren't prototyped, but that we use
- */
-
-extern int VL_CreateEntryN(), VL_CreateEntry(), VL_GetEntryByIDN(),
-VL_GetEntryByID(), VL_GetEntryByNameN(), VL_GetEntryByNameO(),
-VL_ReplaceEntryN(), VL_ReplaceEntry(), VL_ListAttributesN(),
-VL_ListAttributes(), VL_GetAddrsU();
 
 /*
  * VLDB entry conversion routines.
@@ -44,7 +28,7 @@ static int
 OldVLDB_to_NewVLDB(struct vldbentry *source, struct nvldbentry *dest,
                   afs_status_p st)
 {
-    register int i;
+    int i;
     int rc = 0;
     afs_status_t tst = 0;
 
@@ -79,7 +63,7 @@ static int
 NewVLDB_to_OldVLDB(struct nvldbentry *source, struct vldbentry *dest,
                   afs_status_p st)
 {
-    register int i;
+    int i;
     afs_status_t tst = 0;
     int rc = 0;
 
@@ -117,7 +101,7 @@ VLDB_CreateEntry(afs_cell_handle_p cellHandle, struct nvldbentry *entryp,
 
     do {
        if (cellHandle->vos_new) {
-           tst = ubik_Call(VL_CreateEntryN, cellHandle->vos, 0, entryp);
+           tst = ubik_VL_CreateEntryN(cellHandle->vos, 0, entryp);
            if (tst) {
                if (tst == RXGEN_OPCODE) {
                    cellHandle->vos_new = 0;
@@ -127,7 +111,7 @@ VLDB_CreateEntry(afs_cell_handle_p cellHandle, struct nvldbentry *entryp,
            }
        } else {
            if (NewVLDB_to_OldVLDB(entryp, &oentry, &tst)) {
-               tst = ubik_Call(VL_CreateEntry, cellHandle->vos, 0, &oentry);
+               tst = ubik_VL_CreateEntry(cellHandle->vos, 0, &oentry);
                if (!tst) {
                    rc = 1;
                }
@@ -142,7 +126,7 @@ VLDB_CreateEntry(afs_cell_handle_p cellHandle, struct nvldbentry *entryp,
 }
 
 int
-VLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_int32 volid,
+aVLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_uint32 volid,
                  afs_int32 voltype, struct nvldbentry *entryp,
                  afs_status_p st)
 {
@@ -153,7 +137,7 @@ VLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_int32 volid,
     do {
        if (cellHandle->vos_new) {
            tst =
-               ubik_Call(VL_GetEntryByIDN, cellHandle->vos, 0, volid,
+               ubik_VL_GetEntryByIDN(cellHandle->vos, 0, volid,
                          voltype, entryp);
            if (tst) {
                if (tst == RXGEN_OPCODE) {
@@ -164,7 +148,7 @@ VLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_int32 volid,
            }
        } else {
            tst =
-               ubik_Call(VL_GetEntryByID, cellHandle->vos, 0, volid, voltype,
+               ubik_VL_GetEntryByID(cellHandle->vos, 0, volid, voltype,
                          &oentry);
            if (tst == 0) {
                rc = OldVLDB_to_NewVLDB(&oentry, entryp, &tst);
@@ -180,7 +164,7 @@ VLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_int32 volid,
 }
 
 int
-VLDB_GetEntryByName(afs_cell_handle_p cellHandle, const char *namep,
+aVLDB_GetEntryByName(afs_cell_handle_p cellHandle, char *namep,
                    struct nvldbentry *entryp, afs_status_p st)
 {
     struct vldbentry oentry;
@@ -190,7 +174,7 @@ VLDB_GetEntryByName(afs_cell_handle_p cellHandle, const char *namep,
     do {
        if (cellHandle->vos_new) {
            tst =
-               ubik_Call(VL_GetEntryByNameN, cellHandle->vos, 0, namep,
+               ubik_VL_GetEntryByNameN(cellHandle->vos, 0, namep,
                          entryp);
            if (tst) {
                if (tst == RXGEN_OPCODE) {
@@ -201,7 +185,7 @@ VLDB_GetEntryByName(afs_cell_handle_p cellHandle, const char *namep,
            }
        } else {
            tst =
-               ubik_Call(VL_GetEntryByNameO, cellHandle->vos, 0, namep,
+               ubik_VL_GetEntryByNameO(cellHandle->vos, 0, namep,
                          &oentry);
            if (tst == 0) {
                rc = OldVLDB_to_NewVLDB(&oentry, entryp, &tst);
@@ -217,7 +201,7 @@ VLDB_GetEntryByName(afs_cell_handle_p cellHandle, const char *namep,
 }
 
 int
-VLDB_ReplaceEntry(afs_cell_handle_p cellHandle, afs_int32 volid,
+VLDB_ReplaceEntry(afs_cell_handle_p cellHandle, afs_uint32 volid,
                  afs_int32 voltype, struct nvldbentry *entryp,
                  afs_int32 releasetype, afs_status_p st)
 {
@@ -228,7 +212,7 @@ VLDB_ReplaceEntry(afs_cell_handle_p cellHandle, afs_int32 volid,
     do {
        if (cellHandle->vos_new) {
            tst =
-               ubik_Call(VL_ReplaceEntryN, cellHandle->vos, 0, volid,
+               ubik_VL_ReplaceEntryN(cellHandle->vos, 0, volid,
                          voltype, entryp, releasetype);
            if (tst) {
                if (tst == RXGEN_OPCODE) {
@@ -240,7 +224,7 @@ VLDB_ReplaceEntry(afs_cell_handle_p cellHandle, afs_int32 volid,
        } else {
            if (NewVLDB_to_OldVLDB(entryp, &oentry, &tst)) {
                tst =
-                   ubik_Call(VL_ReplaceEntry, cellHandle->vos, 0, volid,
+                   ubik_VL_ReplaceEntry(cellHandle->vos, 0, volid,
                              voltype, &oentry, releasetype);
                if (!tst) {
                    rc = 1;
@@ -268,21 +252,31 @@ VLDB_ListAttributes(afs_cell_handle_p cellHandle,
     do {
        if (cellHandle->vos_new) {
            tst =
-               ubik_Call(VL_ListAttributesN, cellHandle->vos, 0, attrp,
+               ubik_VL_ListAttributesN(cellHandle->vos, 0, attrp,
                          entriesp, blkentriesp);
            if (tst) {
                if (tst == RXGEN_OPCODE) {
                    cellHandle->vos_new = 0;
                }
            } else {
+               if (*entriesp < 0)
+                   *entriesp = 0;
+               if (*entriesp > blkentriesp->nbulkentries_len)
+                   *entriesp = blkentriesp->nbulkentries_len;
                rc = 1;
            }
        } else {
            memset((void *)&arrayEntries, 0, sizeof(arrayEntries));
            tst =
-               ubik_Call(VL_ListAttributes, cellHandle->vos, 0, attrp,
-                         entriesp, arrayEntries);
+               ubik_VL_ListAttributes(cellHandle->vos, 0, attrp,
+                         entriesp, &arrayEntries);
            if (tst == 0) {
+
+               if (*entriesp < 0)
+                   *entriesp = 0;
+               if (*entriesp > arrayEntries.bulkentries_len)
+                   *entriesp = arrayEntries.bulkentries_len;
+
                blkentriesp->nbulkentries_val =
                    (nvldbentry *) malloc(*entriesp * sizeof(*blkentriesp));
                if (blkentriesp->nbulkentries_val != NULL) {
@@ -298,6 +292,7 @@ VLDB_ListAttributes(afs_cell_handle_p cellHandle,
                if (arrayEntries.bulkentries_val) {
                    free(arrayEntries.bulkentries_val);
                }
+
                rc = 1;
            }
        }
@@ -321,7 +316,7 @@ VLDB_ListAttributesN2(afs_cell_handle_p cellHandle,
     afs_status_t tst = 0;
 
     tst =
-       ubik_Call(VL_ListAttributesN2, cellHandle->vos, 0, attrp,
+       ubik_VL_ListAttributesN2(cellHandle->vos, 0, attrp,
                  (name ? name : ""), thisindex, nentriesp, blkentriesp,
                  nextindexp);
     if (!tst) {
@@ -343,7 +338,8 @@ VLDB_IsSameAddrs(afs_cell_handle_p cellHandle, afs_int32 serv1,
 
     ListAddrByAttributes attrs;
     bulkaddrs addrs;
-    afs_uint32 *addrp, nentries, unique, i;
+    afs_uint32 *addrp;
+    afs_int32 nentries, unique, i;
     afsUUID uuid;
 
     *equal = 0;
@@ -360,7 +356,7 @@ VLDB_IsSameAddrs(afs_cell_handle_p cellHandle, afs_int32 serv1,
     memset(&addrs, 0, sizeof(addrs));
     memset(&uuid, 0, sizeof(uuid));
     tst =
-       ubik_Call(VL_GetAddrsU, cellHandle->vos, 0, &attrs, &uuid, &unique,
+       ubik_VL_GetAddrsU(cellHandle->vos, 0, &attrs, &uuid, &unique,
                  &nentries, &addrs);
     if (tst) {
        *equal = 0;
@@ -413,7 +409,7 @@ VLDB_IsSameAddrs(afs_cell_handle_p cellHandle, afs_int32 serv1,
  */
 
 int
-GetVolumeInfo(afs_cell_handle_p cellHandle, unsigned int volid,
+GetVolumeInfo(afs_cell_handle_p cellHandle, afs_uint32 volid,
              struct nvldbentry *rentry, afs_int32 * server,
              afs_int32 * partition, afs_int32 * voltype, afs_status_p st)
 {
@@ -421,7 +417,7 @@ GetVolumeInfo(afs_cell_handle_p cellHandle, unsigned int volid,
     afs_status_t tst;
     int i, index = -1;
 
-    if (!VLDB_GetEntryByID(cellHandle, volid, -1, rentry, &tst)) {
+    if (!aVLDB_GetEntryByID(cellHandle, volid, -1, rentry, &tst)) {
        rc = 0;
        goto fail_GetVolumeInfo;
     }
@@ -526,7 +522,8 @@ vsu_ExtractName(char *rname, char *name)
     char sname[32];
     size_t total;
 
-    strcpy(sname, name);
+    strncpy(sname, name, 32);
+    sname[31] ='\0';
     total = strlen(sname);
     if ((total > 9) && (!strcmp(&sname[total - 9], ".readonly"))) {
        /*discard the last 8 chars */
@@ -628,7 +625,7 @@ badaddr_once(void)
 
 #ifdef AFS_NT40_ENV
 
-#define cszREG_IGNORE_KEY "Software\\TransarcCorporation\\AFS Control Center"
+#define cszREG_IGNORE_KEY "Software\\OpenAFS\\AFS Control Center"
 #define cszREG_IGNORE_VALUE "IgnoreBadAddrs"
 
     /*