/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include <afsconfig.h>
#include <afs/param.h>
+#include <afs/stds.h>
-RCSID
- ("$Header$");
+#include <roken.h>
-#include <afs/stds.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#include <winsock2.h>
-#else
-#include <sys/types.h>
-#include <sys/file.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#endif /* AFS_NT40_ENV */
-#include <sys/stat.h>
+#include <ctype.h>
#ifdef AFS_AIX_ENV
#include <sys/statfs.h>
#endif
-#include <errno.h>
#include <lock.h>
#include <rx/xdr.h>
#include <rx/rx.h>
#include <afs/afsint.h>
#include <afs/cmd.h>
#include <rx/rxkad.h>
+
#include "volser.h"
#include "volint.h"
#include "lockdata.h"
+#include "vsutils_prototypes.h"
+
struct ubik_client *cstruct;
-static rxkad_level vsu_rxkad_level = rxkad_clear;
static void
-ovlentry_to_nvlentry(oentryp, nentryp)
- struct vldbentry *oentryp;
- struct nvldbentry *nentryp;
+ovlentry_to_nvlentry(struct vldbentry *oentryp,
+ struct nvldbentry *nentryp)
{
- register int i;
+ int i;
memset(nentryp, 0, sizeof(struct nvldbentry));
strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name));
nentryp->flags = oentryp->flags;
}
-static
-nvlentry_to_ovlentry(nentryp, oentryp)
- struct nvldbentry *nentryp;
- struct vldbentry *oentryp;
+static int
+nvlentry_to_ovlentry(struct nvldbentry *nentryp,
+ struct vldbentry *oentryp)
{
- register int i;
+ int i;
memset(oentryp, 0, sizeof(struct vldbentry));
strncpy(oentryp->name, nentryp->name, sizeof(oentryp->name));
return 0;
}
-static int newvlserver = 0;
+enum _vlserver_type {
+ vltype_unknown = 0,
+ vltype_old = 1,
+ vltype_new = 2,
+ vltype_uuid = 3
+};
+
+static enum _vlserver_type newvlserver = vltype_unknown;
-VLDB_CreateEntry(entryp)
- struct nvldbentry *entryp;
+int
+VLDB_CreateEntry(struct nvldbentry *entryp)
{
struct vldbentry oentry;
- register int code;
+ int code;
- if (newvlserver == 1) {
+ if (newvlserver == vltype_old) {
tryold:
code = nvlentry_to_ovlentry(entryp, &oentry);
if (code)
return code;
}
code = ubik_VL_CreateEntryN(cstruct, 0, entryp);
- if (!newvlserver) {
+ if (newvlserver == vltype_unknown) {
if (code == RXGEN_OPCODE) {
- newvlserver = 1; /* Doesn't support new interface */
+ newvlserver = vltype_old; /* Doesn't support new interface */
goto tryold;
} else if (!code) {
- newvlserver = 2;
+ newvlserver = vltype_new;
}
}
return code;
}
-VLDB_GetEntryByID(volid, voltype, entryp)
- afs_int32 volid, voltype;
- struct nvldbentry *entryp;
+int
+VLDB_GetEntryByID(afs_uint32 volid, afs_int32 voltype, struct nvldbentry *entryp)
{
struct vldbentry oentry;
- register int code;
+ int code;
- if (newvlserver == 1) {
+ if (newvlserver == vltype_old) {
tryold:
code =
ubik_VL_GetEntryByID(cstruct, 0, volid, voltype, &oentry);
return code;
}
code = ubik_VL_GetEntryByIDN(cstruct, 0, volid, voltype, entryp);
- if (!newvlserver) {
+ if (newvlserver == vltype_unknown) {
if (code == RXGEN_OPCODE) {
- newvlserver = 1; /* Doesn't support new interface */
+ newvlserver = vltype_old; /* Doesn't support new interface */
goto tryold;
} else if (!code) {
- newvlserver = 2;
+ newvlserver = vltype_new;
}
}
return code;
}
-VLDB_GetEntryByName(namep, entryp)
- char *namep;
- struct nvldbentry *entryp;
+int
+VLDB_GetEntryByName(char *namep, struct nvldbentry *entryp)
{
struct vldbentry oentry;
- register int code;
+ int code;
- if (newvlserver == 1) {
+ if (newvlserver == vltype_old) {
tryold:
code = ubik_VL_GetEntryByNameO(cstruct, 0, namep, &oentry);
if (!code)
return code;
}
code = ubik_VL_GetEntryByNameN(cstruct, 0, namep, entryp);
- if (!newvlserver) {
+ if (newvlserver == vltype_unknown) {
if (code == RXGEN_OPCODE) {
- newvlserver = 1; /* Doesn't support new interface */
+ newvlserver = vltype_old; /* Doesn't support new interface */
goto tryold;
} else if (!code) {
- newvlserver = 2;
+ newvlserver = vltype_new;
}
}
return code;
}
-VLDB_ReplaceEntry(volid, voltype, entryp, releasetype)
- afs_int32 volid, voltype, releasetype;
- struct nvldbentry *entryp;
+int
+VLDB_ReplaceEntry(afs_uint32 volid, afs_int32 voltype, struct nvldbentry *entryp, afs_int32 releasetype)
{
struct vldbentry oentry;
- register int code;
+ int code;
- if (newvlserver == 1) {
+ if (newvlserver == vltype_old) {
tryold:
code = nvlentry_to_ovlentry(entryp, &oentry);
if (code)
code =
ubik_VL_ReplaceEntryN(cstruct, 0, volid, voltype, entryp,
releasetype);
- if (!newvlserver) {
+ if (newvlserver == vltype_unknown) {
if (code == RXGEN_OPCODE) {
- newvlserver = 1; /* Doesn't support new interface */
+ newvlserver = vltype_old; /* Doesn't support new interface */
goto tryold;
} else if (!code) {
- newvlserver = 2;
+ newvlserver = vltype_new;
}
}
return code;
}
+static void
+convertBulkToNBulk(bulkentries *bulk, nbulkentries *nbulk) {
+ unsigned int i;
+
+ if (bulk->bulkentries_len == 0)
+ return;
+ nbulk->nbulkentries_len = bulk->bulkentries_len;
+ nbulk->nbulkentries_val =
+ xdr_alloc(bulk->bulkentries_len * sizeof(struct nvldbentry));
-VLDB_ListAttributes(attrp, entriesp, blkentriesp)
- VldbListByAttributes *attrp;
- afs_int32 *entriesp;
- nbulkentries *blkentriesp;
+ for (i = 0; i < bulk->bulkentries_len; i++) {
+ ovlentry_to_nvlentry(&bulk->bulkentries_val[i],
+ &nbulk->nbulkentries_val[i]);
+ }
+}
+
+int
+VLDB_ListAttributes(VldbListByAttributes *attrp,
+ afs_int32 *entriesp,
+ nbulkentries *blkentriesp)
{
bulkentries arrayEntries;
- register int code, i;
+ int code;
- if (newvlserver == 1) {
+ if (newvlserver == vltype_old) {
tryold:
- memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
+ memset(&arrayEntries, 0, sizeof(arrayEntries));
code =
ubik_VL_ListAttributes(cstruct, 0, attrp, entriesp,
&arrayEntries);
- if (!code) {
- blkentriesp->nbulkentries_val =
- (nvldbentry *) malloc(*entriesp * sizeof(struct nvldbentry));
- for (i = 0; i < *entriesp; i++) { /* process each entry */
- ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i],
- &blkentriesp->nbulkentries_val[i]);
- }
- }
- if (arrayEntries.bulkentries_val)
- free(arrayEntries.bulkentries_val);
+
+ if (code)
+ return code;
+
+ /* Ensure the number of entries claimed matches the no. returned */
+ if (*entriesp < 0)
+ *entriesp = 0;
+ if (*entriesp > arrayEntries.bulkentries_len)
+ *entriesp = arrayEntries.bulkentries_len;
+
+ convertBulkToNBulk(&arrayEntries, blkentriesp);
+
+ xdr_free((xdrproc_t) xdr_bulkentries, &arrayEntries);
return code;
}
code =
- ubik_VL_ListAttributesN(cstruct, 0, attrp, entriesp,
- blkentriesp);
- if (!newvlserver) {
+ ubik_VL_ListAttributesN(cstruct, 0, attrp, entriesp, blkentriesp);
+ if (newvlserver == vltype_unknown) {
if (code == RXGEN_OPCODE) {
- newvlserver = 1; /* Doesn't support new interface */
+ newvlserver = vltype_old; /* Doesn't support new interface */
goto tryold;
} else if (!code) {
- newvlserver = 2;
+ newvlserver = vltype_new;
}
}
+
+ /* Ensure the number of entries claimed matches the no. returned */
+ if (*entriesp < 0)
+ *entriesp = 0;
+ if (*entriesp > blkentriesp->nbulkentries_len)
+ *entriesp = blkentriesp->nbulkentries_len;
+
return code;
}
-VLDB_ListAttributesN2(attrp, name, thisindex, nentriesp, blkentriesp,
- nextindexp)
- VldbListByAttributes *attrp;
- char *name;
- afs_int32 thisindex;
- afs_int32 *nentriesp;
- nbulkentries *blkentriesp;
- afs_int32 *nextindexp;
+int
+VLDB_ListAttributesN2(VldbListByAttributes *attrp,
+ char *name,
+ afs_int32 thisindex,
+ afs_int32 *nentriesp,
+ nbulkentries *blkentriesp,
+ afs_int32 *nextindexp)
{
- afs_int32 code;
+ afs_int32 code = RXGEN_OPCODE;
- code =
- ubik_VL_ListAttributesN2(cstruct, 0, attrp, (name ? name : ""),
- thisindex, nentriesp, blkentriesp, nextindexp);
+ if (newvlserver != vltype_old) {
+ code =
+ ubik_VL_ListAttributesN2(cstruct, 0, attrp, (name ? name : ""),
+ thisindex, nentriesp, blkentriesp, nextindexp);
+ if (code)
+ return code;
+
+ /* Ensure the number of entries claimed matches the no. returned */
+ if (*nentriesp < 0)
+ *nentriesp = 0;
+ if (*nentriesp > blkentriesp->nbulkentries_len)
+ *nentriesp = blkentriesp->nbulkentries_len;
+ }
return code;
}
-
-static int vlserverv4 = -1;
struct cacheips {
- afs_int32 server;
- afs_int32 count;
+ afs_uint32 server;
+ afs_uint32 count;
afs_uint32 addrs[16];
};
/*
struct cacheips cacheips[GETADDRUCACHESIZE];
int cacheip_index = 0;
-VLDB_IsSameAddrs(serv1, serv2, errorp)
- afs_int32 serv1, serv2, *errorp;
+int
+VLDB_IsSameAddrs(afs_uint32 serv1, afs_uint32 serv2, afs_int32 *errorp)
{
- register int code;
+ int code;
ListAddrByAttributes attrs;
bulkaddrs addrs;
- afs_uint32 *addrp, nentries, unique, i, j, f1, f2;
+ afs_uint32 *addrp, j, f1, f2;
+ afs_int32 unique, nentries, i;
afsUUID uuid;
static int initcache = 0;
if (serv1 == serv2)
return 1;
- if (vlserverv4 == 1) {
+ if (newvlserver == vltype_old || newvlserver == vltype_new) {
return 0;
}
if (!initcache) {
code =
ubik_VL_GetAddrsU(cstruct, 0, &attrs, &uuid, &unique, &nentries,
&addrs);
- if (vlserverv4 == -1) {
+ if (newvlserver == vltype_unknown) {
if (code == RXGEN_OPCODE) {
- vlserverv4 = 1; /* Doesn't support new interface */
return 0;
} else if (!code) {
- vlserverv4 = 2;
+ newvlserver = vltype_uuid;
}
}
if (code == VL_NOENT)
return code;
}
-
-/*
- Set encryption. If 'cryptflag' is nonzero, encrpytion is turned on
- for authenticated connections; if zero, encryption is turned off.
- Calling this function always results in a level of at least rxkad_auth;
- to get a rxkad_clear connection, simply don't call this.
-*/
-void
-vsu_SetCrypt(cryptflag)
- int cryptflag;
-{
- if (cryptflag) {
- vsu_rxkad_level = rxkad_crypt;
- } else {
- vsu_rxkad_level = rxkad_auth;
- }
-}
-
-
/*
Get the appropriate type of ubik client structure out from the system.
*/
-afs_int32
-vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc)
- int noAuthFlag;
- int (*secproc) ();
- char *cellName;
- struct ubik_client **uclientp;
- char *confDir;
- afs_int32 sauth;
+int
+vsu_ClientInit(const char *confDir, char *cellName, int secFlags,
+ ugen_secproc_func secproc,
+ struct ubik_client **uclientp)
{
- return ugen_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp,
- secproc, "vsu_ClientInit", vsu_rxkad_level,
- VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 90,
- 0, 0, USER_SERVICE_ID);
+ return ugen_ClientInitFlags(confDir, cellName, secFlags, uclientp,
+ secproc, VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE,
+ 90);
}
-
/*extract the name of volume <name> without readonly or backup suffixes
* and return the result as <rname>.
*/
int
-vsu_ExtractName(rname, name)
- char rname[], name[];
+vsu_ExtractName(char rname[], char name[])
{
char sname[VOLSER_OLDMAXVOLNAME + 1];
- int total;
+ size_t total;
strncpy(sname, name, sizeof(sname));
sname[sizeof(sname) - 1] = '\0';
}
}
-
/* returns 0 if failed */
afs_uint32
-vsu_GetVolumeID(astring, acstruct, errp)
- struct ubik_client *acstruct;
- afs_int32 *errp;
- char *astring;
+vsu_GetVolumeID(char *astring, struct ubik_client *acstruct, afs_int32 *errp)
{
- afs_uint32 value;
char volname[VOLSER_OLDMAXVOLNAME + 1];
struct nvldbentry entry;
afs_int32 vcode = 0;
- int total;
+ size_t total;
*errp = 0;
char *end;
afs_uint32 result;
result = strtoul(astring, &end, 10);
- if (result != ULONG_MAX && *end == '\0')
+ if (result != UINT_MAX && *end == '\0')
return result;
}
vsu_ExtractName(volname, astring);
vcode = VLDB_GetEntryByName(volname, &entry);
if (!vcode) {
- if (!strcmp(&astring[total - 9], ".readonly"))
+ if ((total >= 9) && (!strcmp(&astring[total - 9], ".readonly")))
return entry.volumeId[ROVOL];
- else if ((!strcmp(&astring[total - 7], ".backup")))
+ else if ((total >= 7) && (!strcmp(&astring[total - 7], ".backup")))
return entry.volumeId[BACKVOL];
else
return (entry.volumeId[RWVOL]);