2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
16 #include <sys/types.h>
19 #include <netinet/in.h>
20 #endif /* AFS_NT40_ENV */
23 #include <sys/statfs.h>
29 #include <rx/rx_globals.h>
31 #include <afs/vlserver.h>
33 #include <afs/cellconfig.h>
36 #include <afs/afsint.h>
43 struct ubik_client *cstruct;
44 extern int VL_CreateEntry(), VL_CreateEntryN();
45 extern int VL_GetEntryByID(), VL_GetEntryByIDN();
46 extern int VL_GetEntryByNameO(), VL_GetEntryByNameN();
47 extern int VL_ReplaceEntry(), VL_ReplaceEntryN();
48 extern int VL_ListAttributes(), VL_ListAttributesN(), VL_ListAttributesN2();
50 static void ovlentry_to_nvlentry(oentryp, nentryp)
51 struct vldbentry *oentryp;
52 struct nvldbentry *nentryp;
56 bzero(nentryp, sizeof(struct nvldbentry));
57 strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name));
58 for (i=0; i < oentryp->nServers; i++) {
59 nentryp->serverNumber[i] = oentryp->serverNumber[i];
60 nentryp->serverPartition[i] = oentryp->serverPartition[i];
61 nentryp->serverFlags[i] = oentryp->serverFlags[i];
63 nentryp->nServers = oentryp->nServers;
64 for (i=0; i<MAXTYPES; i++)
65 nentryp->volumeId[i] = oentryp->volumeId[i];
66 nentryp->cloneId = oentryp->cloneId;
67 nentryp->flags = oentryp->flags;
70 static nvlentry_to_ovlentry(nentryp, oentryp)
71 struct nvldbentry *nentryp;
72 struct vldbentry *oentryp;
76 bzero(oentryp, sizeof(struct vldbentry));
77 strncpy(oentryp->name, nentryp->name, sizeof(oentryp->name));
78 if (nentryp->nServers > OMAXNSERVERS) {
80 * The alternative is to store OMAXSERVERS but it's always better
81 * to know what's going on...
85 for (i=0; i < nentryp->nServers; i++) {
86 oentryp->serverNumber[i] = nentryp->serverNumber[i];
87 oentryp->serverPartition[i] = nentryp->serverPartition[i];
88 oentryp->serverFlags[i] = nentryp->serverFlags[i];
90 oentryp->nServers = i;
91 for (i=0; i<MAXTYPES; i++)
92 oentryp->volumeId[i] = nentryp->volumeId[i];
93 oentryp->cloneId = nentryp->cloneId;
94 oentryp->flags = nentryp->flags;
98 static int newvlserver=0;
100 VLDB_CreateEntry(entryp)
101 struct nvldbentry *entryp;
103 struct vldbentry oentry;
104 register int code, (*nproc)();
106 if (newvlserver == 1) {
108 code = nvlentry_to_ovlentry(entryp, &oentry);
111 code = ubik_Call(VL_CreateEntry, cstruct, 0, &oentry);
114 code = ubik_Call(VL_CreateEntryN, cstruct, 0, entryp);
116 if (code == RXGEN_OPCODE) {
117 newvlserver = 1; /* Doesn't support new interface */
126 VLDB_GetEntryByID(volid, voltype, entryp)
127 afs_int32 volid, voltype;
128 struct nvldbentry *entryp;
130 struct vldbentry oentry;
131 register int code, (*nproc)();
133 if (newvlserver == 1) {
135 code = ubik_Call(VL_GetEntryByID, cstruct, 0, volid, voltype, &oentry);
137 ovlentry_to_nvlentry(&oentry, entryp);
140 code = ubik_Call(VL_GetEntryByIDN, cstruct, 0, volid, voltype, entryp);
142 if (code == RXGEN_OPCODE) {
143 newvlserver = 1; /* Doesn't support new interface */
152 VLDB_GetEntryByName(namep, entryp)
154 struct nvldbentry *entryp;
156 struct vldbentry oentry;
157 register int code, (*nproc)();
159 if (newvlserver == 1) {
161 code = ubik_Call(VL_GetEntryByNameO, cstruct, 0, namep, &oentry);
163 ovlentry_to_nvlentry(&oentry, entryp);
166 code = ubik_Call(VL_GetEntryByNameN, cstruct, 0, namep, entryp);
168 if (code == RXGEN_OPCODE) {
169 newvlserver = 1; /* Doesn't support new interface */
178 VLDB_ReplaceEntry(volid, voltype, entryp, releasetype)
179 afs_int32 volid, voltype, releasetype;
180 struct nvldbentry *entryp;
182 struct vldbentry oentry;
183 register int code, (*nproc)();
185 if (newvlserver == 1) {
187 code = nvlentry_to_ovlentry(entryp, &oentry);
190 code = ubik_Call(VL_ReplaceEntry, cstruct, 0, volid, voltype, &oentry, releasetype);
193 code = ubik_Call(VL_ReplaceEntryN, cstruct, 0, volid, voltype, entryp, releasetype);
195 if (code == RXGEN_OPCODE) {
196 newvlserver = 1; /* Doesn't support new interface */
207 VLDB_ListAttributes(attrp, entriesp, blkentriesp)
208 VldbListByAttributes *attrp;
210 nbulkentries *blkentriesp;
212 bulkentries arrayEntries;
213 register int code, i;
215 if (newvlserver == 1) {
217 bzero(&arrayEntries, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
218 code = ubik_Call(VL_ListAttributes, cstruct, 0, attrp, entriesp, &arrayEntries);
220 blkentriesp->nbulkentries_val = (nvldbentry *)malloc(*entriesp * sizeof(struct nvldbentry));
221 for (i = 0; i < *entriesp; i++) { /* process each entry */
222 ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i], &blkentriesp->nbulkentries_val[i]);
225 if (arrayEntries.bulkentries_val) free(arrayEntries.bulkentries_val);
228 code = ubik_Call(VL_ListAttributesN, cstruct, 0, attrp, entriesp, blkentriesp);
230 if (code == RXGEN_OPCODE) {
231 newvlserver = 1; /* Doesn't support new interface */
240 VLDB_ListAttributesN2(attrp, name, thisindex, nentriesp, blkentriesp, nextindexp)
241 VldbListByAttributes *attrp;
244 afs_int32 *nentriesp;
245 nbulkentries *blkentriesp;
246 afs_int32 *nextindexp;
250 code = ubik_Call(VL_ListAttributesN2, cstruct, 0,
251 attrp, (name?name:""), thisindex,
252 nentriesp, blkentriesp, nextindexp);
257 static int vlserverv4=-1;
261 afs_uint32 addrs[16];
263 struct cacheips cacheips[16];
265 extern int VL_GetAddrsU();
266 VLDB_IsSameAddrs(serv1, serv2, errorp)
267 afs_int32 serv1, serv2, *errorp;
269 struct vldbentry oentry;
270 register int code, (*nproc)();
271 ListAddrByAttributes attrs;
273 afs_uint32 *addrp, nentries, unique, i, j, f1, f2;
275 static int initcache = 0;
281 if (vlserverv4 == 1) {
285 for (i=0; i<16; i++) {
286 cacheips[i].server = cacheips[i].count = 0;
291 /* See if it's cached */
292 for (i=0; i<16; i++) {
294 for (j=0; j < cacheips[i].count; j++) {
295 if (serv1 == cacheips[i].addrs[j]) f1 = 1;
296 else if (serv2 == cacheips[i].addrs[j]) f2 = 1;
305 bzero(&attrs, sizeof(attrs));
306 attrs.Mask = VLADDR_IPADDR;
307 attrs.ipaddr = serv1;
308 bzero(&addrs, sizeof(addrs));
309 bzero(&uuid, sizeof(uuid));
310 code = ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid, &unique, &nentries, &addrs);
311 if (vlserverv4 == -1) {
312 if (code == RXGEN_OPCODE) {
313 vlserverv4 = 1; /* Doesn't support new interface */
319 if (code == VL_NOENT)
327 if (++cacheip_index >= 16) cacheip_index = 0;
328 cacheips[cacheip_index].server = serv1;
329 cacheips[cacheip_index].count = nentries;
330 addrp = addrs.bulkaddrs_val;
331 for (i=0; i<nentries; i++, addrp++) {
332 cacheips[cacheip_index].addrs[i] = *addrp;
333 if (serv2 == *addrp) {
342 afs_int32 subik_Call(aproc, aclient, aflags, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16)
343 register struct ubik_client *aclient;
346 afs_int32 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16;
348 struct vldbentry vldbentry;
349 register int code, (*nproc)();
351 if (newvlserver == 1) {
353 code = ubik_Call(aproc, aclient, aflags, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16);
355 if (code == RXGEN_OPCODE) {
356 newvlserver = 1; /* Doesn't support new interface */
366 Get the appropriate type of ubik client structure out from the system.
368 afs_int32 vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc)
372 struct ubik_client **uclientp;
376 afs_int32 code, scIndex, i;
377 struct afsconf_cell info;
378 struct afsconf_dir *tdir;
379 struct ktc_principal sname;
380 struct ktc_token ttoken;
381 struct rx_securityClass *sc;
382 static struct rx_connection *serverconns[VLDB_MAXSERVERS];
388 fprintf(STDERR,"vsu_ClientInit: could not initialize rx.\n");
391 rx_SetRxDeadTime(90);
393 if (sauth) { /* -localauth */
394 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
396 fprintf(STDERR, "vsu_ClientInit: Could not process files in configuration directory (%s).\n",
397 AFSDIR_SERVER_ETC_DIRPATH);
400 code = afsconf_ClientAuth(tdir, &sc, &scIndex); /* sets sc,scIndex */
402 fprintf(STDERR, "vsu_ClientInit: Could not get security object for -localAuth %\n");
405 code = afsconf_GetCellInfo(tdir, tdir->cellName, AFSCONF_VLDBSERVICE,
408 fprintf(STDERR, "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n",
409 cellName, AFSDIR_SERVER_ETC_DIRPATH,AFSDIR_CELLSERVDB_FILE);
413 else { /* not -localauth */
414 tdir = afsconf_Open(confDir);
416 fprintf(STDERR, "vsu_ClientInit: Could not process files in configuration directory (%s).\n",
422 code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr));
424 fprintf(STDERR, "vsu_ClientInit: can't get local cellname, check %s/%s\n",
425 confDir, AFSDIR_THISCELL_FILE);
431 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, &info);
433 fprintf(STDERR, "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n",
434 cellName, confDir,AFSDIR_CELLSERVDB_FILE);
437 if (noAuthFlag) /* -noauth */
439 else { /* not -noauth */
440 strcpy(sname.cell, info.name);
441 sname.instance[0] = 0;
442 strcpy(sname.name, "afs");
443 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
444 if (code) { /* did not get ticket */
445 fprintf(STDERR, "vsu_ClientInit: Could not get afs tokens, running unauthenticated.\n");
448 else { /* got a ticket */
450 if ((ttoken.kvno < 0) || (ttoken.kvno > 255)) {
451 fprintf(STDERR, "vsu_ClientInit: funny kvno (%d) in ticket, proceeding\n",
459 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
462 sc = (struct rx_securityClass *)rxkad_NewClientSecurityObject(
463 rxkad_clear, &ttoken.sessionKey, ttoken.kvno,
464 ttoken.ticketLen, ttoken.ticket);
467 fprintf(STDERR, "vsu_ClientInit: unsupported security index %d\n",
474 if (secproc) /* tell UV module about default authentication */
475 (*secproc) (sc, scIndex);
476 if (info.numServers > VLDB_MAXSERVERS) {
477 fprintf(STDERR, "vsu_ClientInit: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
478 info.numServers, VLDB_MAXSERVERS);
481 for (i=0; i<info.numServers; i++) {
482 serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
483 info.hostAddr[i].sin_port, USER_SERVICE_ID,
487 code = ubik_ClientInit(serverconns, uclientp);
489 fprintf(STDERR, "vsu_ClientInit: ubik client init failed.\n");
496 /*extract the name of volume <name> without readonly or backup suffixes
497 * and return the result as <rname>.
499 vsu_ExtractName(rname,name)
505 total = strlen(sname);
506 if(!strcmp(&sname[total - 9],".readonly")) {
507 /*discard the last 8 chars */
508 sname[total - 9] = '\0';
512 else if(!strcmp(&sname[total - 7 ],".backup")) {
513 /*discard last 6 chars */
514 sname[total - 7] = '\0';
519 strncpy(rname,name,VOLSER_OLDMAXVOLNAME);
525 /* returns 0 if failed */
526 afs_uint32 vsu_GetVolumeID(astring, acstruct, errp)
527 struct ubik_client *acstruct;
530 afs_uint32 tc, value;
532 char *str,*ptr, volname[VOLSER_OLDMAXVOLNAME+1];
534 struct nvldbentry entry;
539 total = strlen(astring);
543 while (curval = *str++){
544 if(curval < '0' || curval > '9')
549 vsu_ExtractName(volname,astring);
550 vcode = VLDB_GetEntryByName(volname, &entry);
552 if(!strcmp(&astring[total - 9],".readonly"))
553 return entry.volumeId[ROVOL];
554 else if ((!strcmp(&astring[total - 7 ],".backup")))
555 return entry.volumeId[BACKVOL];
557 return (entry.volumeId[RWVOL]);
560 return 0; /* can't find volume */
565 while (tc = *astring++) {
567 if(!tryname) fprintf(STDERR,"goofed in volid \n");
568 else {fprintf(STDERR,"Could not get entry from vldb for %s\n",ptr);PrintError("",vcode);}
572 if (tc < '0' || tc > '9'){
573 if(!tryname) fprintf(STDERR,"internal error: out of range char in vol ID\n");
574 else {fprintf(STDERR,"Could not get entry from vldb for %s\n",ptr);PrintError("",vcode);}