* directory or online at http://www.openafs.org/dl/license10.html
*/
+#include <afsconfig.h>
+#include <afs/param.h>
+
+#include <roken.h>
+
#include "vosutils.h"
#include "vsprocs.h"
#include "lockprocs.h"
#include <afs/afs_AdminErrors.h>
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#ifdef HAVE_STRING_H
#include <string.h>
-#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.
* two types "old" and "new".
*/
-static int OldVLDB_to_NewVLDB(
- struct vldbentry *source,
- struct nvldbentry *dest,
- afs_status_p st)
+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;
- bzero(dest, sizeof(struct nvldbentry));
+ memset(dest, 0, sizeof(struct nvldbentry));
strncpy(dest->name, source->name, sizeof(dest->name));
for (i = 0; i < source->nServers; i++) {
dest->serverNumber[i] = source->serverNumber[i];
for (i = 0; i < MAXTYPES; i++)
dest->volumeId[i] = source->volumeId[i];
dest->cloneId = source->cloneId;
- dest->flags = source->flags;
+ dest->flags = source->flags;
rc = 1;
* return an error.
*/
-static int NewVLDB_to_OldVLDB(
- struct nvldbentry *source,
- struct vldbentry *dest,
- afs_status_p st)
+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;
- bzero(dest, sizeof(struct vldbentry));
+ memset(dest, 0, sizeof(struct vldbentry));
strncpy(dest->name, source->name, sizeof(dest->name));
if (source->nServers <= OMAXNSERVERS) {
for (i = 0; i < source->nServers; i++) {
return rc;
}
-int VLDB_CreateEntry(
- afs_cell_handle_p cellHandle,
- struct nvldbentry *entryp,
- afs_status_p st)
+int
+VLDB_CreateEntry(afs_cell_handle_p cellHandle, struct nvldbentry *entryp,
+ afs_status_p st)
{
struct vldbentry oentry;
afs_status_t tst = 0;
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;
}
} 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;
}
if (st != NULL) {
*st = tst;
- }
+ }
return rc;
}
-int VLDB_GetEntryByID(
- afs_cell_handle_p cellHandle,
- afs_int32 volid,
- afs_int32 voltype,
- struct nvldbentry *entryp,
- afs_status_p st)
+int
+aVLDB_GetEntryByID(afs_cell_handle_p cellHandle, afs_uint32 volid,
+ afs_int32 voltype, struct nvldbentry *entryp,
+ afs_status_p st)
{
struct vldbentry oentry;
afs_status_t tst = 0;
do {
if (cellHandle->vos_new) {
- tst = ubik_Call(VL_GetEntryByIDN, cellHandle->vos, 0, volid,
- voltype, entryp);
+ tst =
+ ubik_VL_GetEntryByIDN(cellHandle->vos, 0, volid,
+ voltype, entryp);
if (tst) {
if (tst == RXGEN_OPCODE) {
cellHandle->vos_new = 0;
rc = 1;
}
} else {
- tst = ubik_Call(VL_GetEntryByID, cellHandle->vos, 0, volid,
- voltype, &oentry);
+ tst =
+ ubik_VL_GetEntryByID(cellHandle->vos, 0, volid, voltype,
+ &oentry);
if (tst == 0) {
rc = OldVLDB_to_NewVLDB(&oentry, entryp, &tst);
}
if (st != NULL) {
*st = tst;
- }
+ }
return rc;
}
-int VLDB_GetEntryByName(
- afs_cell_handle_p cellHandle,
- const char *namep,
- struct nvldbentry *entryp,
- afs_status_p st)
+int
+aVLDB_GetEntryByName(afs_cell_handle_p cellHandle, char *namep,
+ struct nvldbentry *entryp, afs_status_p st)
{
struct vldbentry oentry;
afs_status_t tst = 0;
do {
if (cellHandle->vos_new) {
- tst = ubik_Call(VL_GetEntryByNameN, cellHandle->vos, 0, namep,
- entryp);
+ tst =
+ ubik_VL_GetEntryByNameN(cellHandle->vos, 0, namep,
+ entryp);
if (tst) {
if (tst == RXGEN_OPCODE) {
cellHandle->vos_new = 0;
rc = 1;
}
} else {
- tst = ubik_Call(VL_GetEntryByNameO, cellHandle->vos, 0, namep,
- &oentry);
+ tst =
+ ubik_VL_GetEntryByNameO(cellHandle->vos, 0, namep,
+ &oentry);
if (tst == 0) {
rc = OldVLDB_to_NewVLDB(&oentry, entryp, &tst);
}
if (st != NULL) {
*st = tst;
- }
+ }
return rc;
}
-int VLDB_ReplaceEntry(
- afs_cell_handle_p cellHandle,
- afs_int32 volid,
- afs_int32 voltype,
- struct nvldbentry *entryp,
- afs_int32 releasetype,
- afs_status_p st)
+int
+VLDB_ReplaceEntry(afs_cell_handle_p cellHandle, afs_uint32 volid,
+ afs_int32 voltype, struct nvldbentry *entryp,
+ afs_int32 releasetype, afs_status_p st)
{
struct vldbentry oentry;
afs_status_t tst = 0;
do {
if (cellHandle->vos_new) {
- tst = ubik_Call(VL_ReplaceEntryN, cellHandle->vos, 0, volid,
- voltype, entryp, releasetype);
+ tst =
+ ubik_VL_ReplaceEntryN(cellHandle->vos, 0, volid,
+ voltype, entryp, releasetype);
if (tst) {
if (tst == RXGEN_OPCODE) {
cellHandle->vos_new = 0;
}
} else {
if (NewVLDB_to_OldVLDB(entryp, &oentry, &tst)) {
- tst = ubik_Call(VL_ReplaceEntry, cellHandle->vos, 0, volid,
- voltype, &oentry, releasetype);
+ tst =
+ ubik_VL_ReplaceEntry(cellHandle->vos, 0, volid,
+ voltype, &oentry, releasetype);
if (!tst) {
rc = 1;
}
if (st != NULL) {
*st = tst;
- }
+ }
return rc;
}
-int VLDB_ListAttributes(
- afs_cell_handle_p cellHandle,
- VldbListByAttributes *attrp,
- afs_int32 *entriesp,
- nbulkentries *blkentriesp,
- afs_status_p st)
+int
+VLDB_ListAttributes(afs_cell_handle_p cellHandle,
+ VldbListByAttributes * attrp, afs_int32 * entriesp,
+ nbulkentries * blkentriesp, afs_status_p st)
{
bulkentries arrayEntries;
int i;
do {
if (cellHandle->vos_new) {
- tst = ubik_Call(VL_ListAttributesN, cellHandle->vos, 0, attrp,
- entriesp, blkentriesp);
+ tst =
+ 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);
+ memset((void *)&arrayEntries, 0, sizeof(arrayEntries));
+ tst =
+ ubik_VL_ListAttributes(cellHandle->vos, 0, attrp,
+ entriesp, &arrayEntries);
if (tst == 0) {
- blkentriesp->nbulkentries_val = (nvldbentry *) malloc(*entriesp * sizeof(*blkentriesp));
+
+ 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) {
- for(i=0;i< *entriesp;i++) {
- OldVLDB_to_NewVLDB((struct vldbentry *) &arrayEntries.bulkentries_val[i], (struct nvldbentry *) &blkentriesp->nbulkentries_val[i], &tst);
+ for (i = 0; i < *entriesp; i++) {
+ OldVLDB_to_NewVLDB((struct vldbentry *)&arrayEntries.
+ bulkentries_val[i],
+ (struct nvldbentry *)&blkentriesp->
+ nbulkentries_val[i], &tst);
}
} else {
tst = ADMNOMEM;
if (arrayEntries.bulkentries_val) {
free(arrayEntries.bulkentries_val);
}
+
rc = 1;
}
}
if (st != NULL) {
*st = tst;
- }
+ }
return rc;
}
-int VLDB_ListAttributesN2(
- afs_cell_handle_p cellHandle,
- VldbListByAttributes *attrp,
- char *name,
- afs_int32 thisindex,
- afs_int32 *nentriesp,
- nbulkentries *blkentriesp,
- afs_int32 *nextindexp,
- afs_status_p st)
+int
+VLDB_ListAttributesN2(afs_cell_handle_p cellHandle,
+ VldbListByAttributes * attrp, char *name,
+ afs_int32 thisindex, afs_int32 * nentriesp,
+ nbulkentries * blkentriesp, afs_int32 * nextindexp,
+ afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
- tst = ubik_Call(VL_ListAttributesN2, cellHandle->vos, 0,
- attrp, (name ? name : ""), thisindex,
- nentriesp, blkentriesp, nextindexp);
+ tst =
+ ubik_VL_ListAttributesN2(cellHandle->vos, 0, attrp,
+ (name ? name : ""), thisindex, nentriesp, blkentriesp,
+ nextindexp);
if (!tst) {
rc = 1;
}
return rc;
}
-int VLDB_IsSameAddrs(
- afs_cell_handle_p cellHandle,
- afs_int32 serv1,
- afs_int32 serv2,
- int *equal,
- afs_status_p st)
+int
+VLDB_IsSameAddrs(afs_cell_handle_p cellHandle, afs_int32 serv1,
+ afs_int32 serv2, int *equal, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
ListAddrByAttributes attrs;
bulkaddrs addrs;
- afs_uint32 *addrp,
- nentries,
- unique,
- i;
+ afs_uint32 *addrp;
+ afs_int32 nentries, unique, i;
afsUUID uuid;
*equal = 0;
goto fail_VLDB_IsSameAddrs;
}
- bzero(&attrs, sizeof(attrs));
+ memset(&attrs, 0, sizeof(attrs));
attrs.Mask = VLADDR_IPADDR;
attrs.ipaddr = serv1;
- bzero(&addrs, sizeof(addrs));
- bzero(&uuid, sizeof(uuid));
- tst = ubik_Call(VL_GetAddrsU, cellHandle->vos, 0, &attrs, &uuid,
- &unique, &nentries, &addrs);
+ memset(&addrs, 0, sizeof(addrs));
+ memset(&uuid, 0, sizeof(uuid));
+ tst =
+ ubik_VL_GetAddrsU(cellHandle->vos, 0, &attrs, &uuid, &unique,
+ &nentries, &addrs);
if (tst) {
*equal = 0;
goto fail_VLDB_IsSameAddrs;
}
rc = 1;
-fail_VLDB_IsSameAddrs:
-
+ fail_VLDB_IsSameAddrs:
+
if (st != NULL) {
*st = tst;
}
* Returns != 0 upon successful completion.
*/
-int GetVolumeInfo(
- afs_cell_handle_p cellHandle,
- unsigned int volid,
- struct nvldbentry *rentry,
- afs_int32 *server,
- afs_int32 *partition,
- afs_int32 *voltype,
- afs_status_p st)
+int
+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)
{
int rc = 0;
afs_status_t tst;
- int i,index = -1;
-
- if (!VLDB_GetEntryByID(cellHandle, volid, -1, rentry, &tst)) {
+ int i, index = -1;
+
+ if (!aVLDB_GetEntryByID(cellHandle, volid, -1, rentry, &tst)) {
rc = 0;
goto fail_GetVolumeInfo;
}
- if(volid == rentry->volumeId[ROVOL]){
- *voltype = ROVOL;
- for (i = 0; i < rentry->nServers; i++) {
- if ( (index == -1) && (rentry->serverFlags[i] & ITSROVOL) &&
- !(rentry->serverFlags[i] & RO_DONTUSE) )
- index = i;
- }
- if(index == -1) {
+ if (volid == rentry->volumeId[ROVOL]) {
+ *voltype = ROVOL;
+ for (i = 0; i < rentry->nServers; i++) {
+ if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL)
+ && !(rentry->serverFlags[i] & RO_DONTUSE))
+ index = i;
+ }
+ if (index == -1) {
tst = 1;
goto fail_GetVolumeInfo;
}
- *server = rentry->serverNumber[index];
- *partition = rentry->serverPartition[index];
+ *server = rentry->serverNumber[index];
+ *partition = rentry->serverPartition[index];
rc = 1;
goto fail_GetVolumeInfo;
}
-
- if ((index = Lp_GetRwIndex(cellHandle, rentry, &tst))<0) {
+
+ if ((index = Lp_GetRwIndex(cellHandle, rentry, &tst)) < 0) {
goto fail_GetVolumeInfo;
}
- if(volid == rentry->volumeId[RWVOL]){
- *voltype = RWVOL;
- *server = rentry->serverNumber[index];
- *partition = rentry->serverPartition[index];
- } else if(volid == rentry->volumeId[BACKVOL]){
- *voltype = BACKVOL;
- *server = rentry->serverNumber[index];
- *partition = rentry->serverPartition[index];
+ if (volid == rentry->volumeId[RWVOL]) {
+ *voltype = RWVOL;
+ *server = rentry->serverNumber[index];
+ *partition = rentry->serverPartition[index];
+ } else if (volid == rentry->volumeId[BACKVOL]) {
+ *voltype = BACKVOL;
+ *server = rentry->serverNumber[index];
+ *partition = rentry->serverPartition[index];
}
- rc = 1;
+ rc = 1;
-fail_GetVolumeInfo:
+ fail_GetVolumeInfo:
if (st != NULL) {
*st = tst;
* Returns != 0 upon successful completion.
*/
-int ValidateVolumeName(
- const char *volumeName,
- afs_status_p st)
+int
+ValidateVolumeName(const char *volumeName, afs_status_p st)
{
int rc = 0;
afs_status_t tst = 0;
len = strlen(volumeName);
- if (((len > 8) && (!strcmp(&volumeName[len - 9], ".readonly"))) ||
- ((len > 6) && (!strcmp(&volumeName[len - 7], ".backup")))) {
+ if (((len > 8) && (!strcmp(&volumeName[len - 9], ".readonly")))
+ || ((len > 6) && (!strcmp(&volumeName[len - 7], ".backup")))) {
tst = ADMVOSVOLUMENAMEINVALID;
goto fail_ValidateVolumeName;
}
rc = 1;
-fail_ValidateVolumeName:
+ fail_ValidateVolumeName:
if (st != NULL) {
*st = tst;
/*extract the name of volume <name> without readonly or backup suffixes
* and return the result as <rname>.
*/
-int vsu_ExtractName(
- char *rname,
- char *name)
+int
+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 */
- sname[total - 9] = '\0';
- strcpy(rname,sname);
- return 0;
- }
- else if((total > 7) && (!strcmp(&sname[total - 7 ],".backup"))) {
- /*discard last 6 chars */
- sname[total - 7] = '\0';
- strcpy(rname,sname);
- return 0;
- }
- else {
- strncpy(rname,name,VOLSER_OLDMAXVOLNAME);
- return -1;
+ if ((total > 9) && (!strcmp(&sname[total - 9], ".readonly"))) {
+ /*discard the last 8 chars */
+ sname[total - 9] = '\0';
+ strcpy(rname, sname);
+ return 0;
+ } else if ((total > 7) && (!strcmp(&sname[total - 7], ".backup"))) {
+ /*discard last 6 chars */
+ sname[total - 7] = '\0';
+ strcpy(rname, sname);
+ return 0;
+ } else {
+ strncpy(rname, name, VOLSER_OLDMAXVOLNAME);
+ return -1;
}
}
* (where 255 in any byte in the pattern indicates a wildcard).
*/
-int AddressMatch (
- int addrTest,
- int addrPattern)
+int
+AddressMatch(int addrTest, int addrPattern)
{
int bTest;
int bPattern;
static pthread_once_t badaddr_init_once = PTHREAD_ONCE_INIT;
static int addr_to_skip;
-static void badaddr_once (void)
+static void
+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"
/*
*/
HKEY hk;
- addr_to_skip = 0; /* don't ignore any addrs unless we find otherwise */
- if (RegOpenKey (HKEY_LOCAL_MACHINE, cszREG_IGNORE_KEY, &hk) == 0) {
+ addr_to_skip = 0; /* don't ignore any addrs unless we find otherwise */
+ if (RegOpenKey(HKEY_LOCAL_MACHINE, cszREG_IGNORE_KEY, &hk) == 0) {
DWORD dwType = REG_DWORD;
DWORD dwSize = sizeof(addr_to_skip);
- RegQueryValueEx (hk, cszREG_IGNORE_VALUE, 0,
- &dwType, (PBYTE)&addr_to_skip, &dwSize);
- RegCloseKey (hk);
+ RegQueryValueEx(hk, cszREG_IGNORE_VALUE, 0, &dwType,
+ (PBYTE) & addr_to_skip, &dwSize);
+ RegCloseKey(hk);
}
-
#else
/*
*
*/
- addr_to_skip = 0; /* don't skip any addresses */
+ addr_to_skip = 0; /* don't skip any addresses */
#endif
}
-int RemoveBadAddresses(
- afs_int32 *totalp,
- bulkaddrs *addrsp)
+int
+RemoveBadAddresses(afs_int32 * totalp, bulkaddrs * addrsp)
{
- pthread_once (&badaddr_init_once, badaddr_once);
+ pthread_once(&badaddr_init_once, badaddr_once);
/*
* If we've been requested to skip anything, addr_to_skip will be
if (addr_to_skip && addrsp && addrsp->bulkaddrs_val) {
size_t iiWrite = 0;
size_t iiRead = 0;
- for ( ; iiRead < addrsp->bulkaddrs_len; ++iiRead) {
+ for (; iiRead < addrsp->bulkaddrs_len; ++iiRead) {
/*
* Check this IP address to see if it should be skipped.
*/
- if (!AddressMatch(addrsp->bulkaddrs_val[iiRead],addr_to_skip)) {
+ if (!AddressMatch(addrsp->bulkaddrs_val[iiRead], addr_to_skip)) {
/*
* The address is okay; make sure it stays in the list.
if (iiWrite != iiRead) {
addrsp->bulkaddrs_val[iiWrite] =
- addrsp->bulkaddrs_val[iiRead];
+ addrsp->bulkaddrs_val[iiRead];
}
++iiWrite;
}
}
- *totalp = (afs_int32)iiWrite;
+ *totalp = (afs_int32) iiWrite;
addrsp->bulkaddrs_len = iiWrite;
}
return TRUE;
}
-