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 <afsconfig.h>
11 #include <afs/param.h>
20 #include <sys/types.h>
23 #include <netinet/in.h>
24 #endif /* AFS_NT40_ENV */
27 #include <sys/statfs.h>
33 #include <rx/rx_globals.h>
35 #include <afs/vlserver.h>
37 #include <afs/cellconfig.h>
40 #include <afs/afsint.h>
47 struct ubik_client *cstruct;
48 extern int VL_CreateEntry(), VL_CreateEntryN();
49 extern int VL_GetEntryByID(), VL_GetEntryByIDN();
50 extern int VL_GetEntryByNameO(), VL_GetEntryByNameN();
51 extern int VL_ReplaceEntry(), VL_ReplaceEntryN();
52 extern int VL_ListAttributes(), VL_ListAttributesN(), VL_ListAttributesN2();
54 static void ovlentry_to_nvlentry(oentryp, nentryp)
55 struct vldbentry *oentryp;
56 struct nvldbentry *nentryp;
60 memset(nentryp, 0, sizeof(struct nvldbentry));
61 strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name));
62 for (i=0; i < oentryp->nServers; i++) {
63 nentryp->serverNumber[i] = oentryp->serverNumber[i];
64 nentryp->serverPartition[i] = oentryp->serverPartition[i];
65 nentryp->serverFlags[i] = oentryp->serverFlags[i];
67 nentryp->nServers = oentryp->nServers;
68 for (i=0; i<MAXTYPES; i++)
69 nentryp->volumeId[i] = oentryp->volumeId[i];
70 nentryp->cloneId = oentryp->cloneId;
71 nentryp->flags = oentryp->flags;
74 static nvlentry_to_ovlentry(nentryp, oentryp)
75 struct nvldbentry *nentryp;
76 struct vldbentry *oentryp;
80 memset(oentryp, 0, sizeof(struct vldbentry));
81 strncpy(oentryp->name, nentryp->name, sizeof(oentryp->name));
82 if (nentryp->nServers > OMAXNSERVERS) {
84 * The alternative is to store OMAXSERVERS but it's always better
85 * to know what's going on...
89 for (i=0; i < nentryp->nServers; i++) {
90 oentryp->serverNumber[i] = nentryp->serverNumber[i];
91 oentryp->serverPartition[i] = nentryp->serverPartition[i];
92 oentryp->serverFlags[i] = nentryp->serverFlags[i];
94 oentryp->nServers = i;
95 for (i=0; i<MAXTYPES; i++)
96 oentryp->volumeId[i] = nentryp->volumeId[i];
97 oentryp->cloneId = nentryp->cloneId;
98 oentryp->flags = nentryp->flags;
102 static int newvlserver=0;
104 VLDB_CreateEntry(entryp)
105 struct nvldbentry *entryp;
107 struct vldbentry oentry;
108 register int code, (*nproc)();
110 if (newvlserver == 1) {
112 code = nvlentry_to_ovlentry(entryp, &oentry);
115 code = ubik_Call(VL_CreateEntry, cstruct, 0, &oentry);
118 code = ubik_Call(VL_CreateEntryN, cstruct, 0, entryp);
120 if (code == RXGEN_OPCODE) {
121 newvlserver = 1; /* Doesn't support new interface */
130 VLDB_GetEntryByID(volid, voltype, entryp)
131 afs_int32 volid, voltype;
132 struct nvldbentry *entryp;
134 struct vldbentry oentry;
135 register int code, (*nproc)();
137 if (newvlserver == 1) {
139 code = ubik_Call(VL_GetEntryByID, cstruct, 0, volid, voltype, &oentry);
141 ovlentry_to_nvlentry(&oentry, entryp);
144 code = ubik_Call(VL_GetEntryByIDN, cstruct, 0, volid, voltype, entryp);
146 if (code == RXGEN_OPCODE) {
147 newvlserver = 1; /* Doesn't support new interface */
156 VLDB_GetEntryByName(namep, entryp)
158 struct nvldbentry *entryp;
160 struct vldbentry oentry;
161 register int code, (*nproc)();
163 if (newvlserver == 1) {
165 code = ubik_Call(VL_GetEntryByNameO, cstruct, 0, namep, &oentry);
167 ovlentry_to_nvlentry(&oentry, entryp);
170 code = ubik_Call(VL_GetEntryByNameN, cstruct, 0, namep, entryp);
172 if (code == RXGEN_OPCODE) {
173 newvlserver = 1; /* Doesn't support new interface */
182 VLDB_ReplaceEntry(volid, voltype, entryp, releasetype)
183 afs_int32 volid, voltype, releasetype;
184 struct nvldbentry *entryp;
186 struct vldbentry oentry;
187 register int code, (*nproc)();
189 if (newvlserver == 1) {
191 code = nvlentry_to_ovlentry(entryp, &oentry);
194 code = ubik_Call(VL_ReplaceEntry, cstruct, 0, volid, voltype, &oentry, releasetype);
197 code = ubik_Call(VL_ReplaceEntryN, cstruct, 0, volid, voltype, entryp, releasetype);
199 if (code == RXGEN_OPCODE) {
200 newvlserver = 1; /* Doesn't support new interface */
211 VLDB_ListAttributes(attrp, entriesp, blkentriesp)
212 VldbListByAttributes *attrp;
214 nbulkentries *blkentriesp;
216 bulkentries arrayEntries;
217 register int code, i;
219 if (newvlserver == 1) {
221 memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */
222 code = ubik_Call(VL_ListAttributes, cstruct, 0, attrp, entriesp, &arrayEntries);
224 blkentriesp->nbulkentries_val = (nvldbentry *)malloc(*entriesp * sizeof(struct nvldbentry));
225 for (i = 0; i < *entriesp; i++) { /* process each entry */
226 ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i], &blkentriesp->nbulkentries_val[i]);
229 if (arrayEntries.bulkentries_val) free(arrayEntries.bulkentries_val);
232 code = ubik_Call(VL_ListAttributesN, cstruct, 0, attrp, entriesp, blkentriesp);
234 if (code == RXGEN_OPCODE) {
235 newvlserver = 1; /* Doesn't support new interface */
244 VLDB_ListAttributesN2(attrp, name, thisindex, nentriesp, blkentriesp, nextindexp)
245 VldbListByAttributes *attrp;
248 afs_int32 *nentriesp;
249 nbulkentries *blkentriesp;
250 afs_int32 *nextindexp;
254 code = ubik_Call(VL_ListAttributesN2, cstruct, 0,
255 attrp, (name?name:""), thisindex,
256 nentriesp, blkentriesp, nextindexp);
261 static int vlserverv4=-1;
265 afs_uint32 addrs[16];
267 struct cacheips cacheips[16];
269 extern int VL_GetAddrsU();
270 VLDB_IsSameAddrs(serv1, serv2, errorp)
271 afs_int32 serv1, serv2, *errorp;
273 struct vldbentry oentry;
274 register int code, (*nproc)();
275 ListAddrByAttributes attrs;
277 afs_uint32 *addrp, nentries, unique, i, j, f1, f2;
279 static int initcache = 0;
285 if (vlserverv4 == 1) {
289 for (i=0; i<16; i++) {
290 cacheips[i].server = cacheips[i].count = 0;
295 /* See if it's cached */
296 for (i=0; i<16; i++) {
298 for (j=0; j < cacheips[i].count; j++) {
299 if (serv1 == cacheips[i].addrs[j]) f1 = 1;
300 else if (serv2 == cacheips[i].addrs[j]) f2 = 1;
309 memset(&attrs, 0, sizeof(attrs));
310 attrs.Mask = VLADDR_IPADDR;
311 attrs.ipaddr = serv1;
312 memset(&addrs, 0, sizeof(addrs));
313 memset(&uuid, 0, sizeof(uuid));
314 code = ubik_Call(VL_GetAddrsU, cstruct, 0, &attrs, &uuid, &unique, &nentries, &addrs);
315 if (vlserverv4 == -1) {
316 if (code == RXGEN_OPCODE) {
317 vlserverv4 = 1; /* Doesn't support new interface */
323 if (code == VL_NOENT)
331 if (++cacheip_index >= 16) cacheip_index = 0;
332 cacheips[cacheip_index].server = serv1;
333 cacheips[cacheip_index].count = nentries;
334 addrp = addrs.bulkaddrs_val;
335 for (i=0; i<nentries; i++, addrp++) {
336 cacheips[cacheip_index].addrs[i] = *addrp;
337 if (serv2 == *addrp) {
346 afs_int32 subik_Call(aproc, aclient, aflags, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16)
347 register struct ubik_client *aclient;
350 afs_int32 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16;
352 struct vldbentry vldbentry;
353 register int code, (*nproc)();
355 if (newvlserver == 1) {
357 code = ubik_Call(aproc, aclient, aflags, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16);
359 if (code == RXGEN_OPCODE) {
360 newvlserver = 1; /* Doesn't support new interface */
370 Get the appropriate type of ubik client structure out from the system.
372 afs_int32 vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc)
376 struct ubik_client **uclientp;
380 afs_int32 code, scIndex, i;
381 struct afsconf_cell info;
382 struct afsconf_dir *tdir;
383 struct ktc_principal sname;
384 struct ktc_token ttoken;
385 struct rx_securityClass *sc;
386 static struct rx_connection *serverconns[VLDB_MAXSERVERS];
392 fprintf(STDERR,"vsu_ClientInit: could not initialize rx.\n");
395 rx_SetRxDeadTime(90);
397 if (sauth) { /* -localauth */
398 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
400 fprintf(STDERR, "vsu_ClientInit: Could not process files in configuration directory (%s).\n",
401 AFSDIR_SERVER_ETC_DIRPATH);
404 code = afsconf_ClientAuth(tdir, &sc, &scIndex); /* sets sc,scIndex */
406 fprintf(STDERR, "vsu_ClientInit: Could not get security object for -localAuth\n");
409 code = afsconf_GetCellInfo(tdir, tdir->cellName, AFSCONF_VLDBSERVICE,
412 fprintf(STDERR, "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n",
413 cellName, AFSDIR_SERVER_ETC_DIRPATH,AFSDIR_CELLSERVDB_FILE);
417 else { /* not -localauth */
418 tdir = afsconf_Open(confDir);
420 fprintf(STDERR, "vsu_ClientInit: Could not process files in configuration directory (%s).\n",
426 code = afsconf_GetLocalCell(tdir, cellstr, sizeof(cellstr));
428 fprintf(STDERR, "vsu_ClientInit: can't get local cellname, check %s/%s\n",
429 confDir, AFSDIR_THISCELL_FILE);
435 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, &info);
437 fprintf(STDERR, "vsu_ClientInit: can't find cell %s's hosts in %s/%s\n",
438 cellName, confDir,AFSDIR_CELLSERVDB_FILE);
441 if (noAuthFlag) /* -noauth */
443 else { /* not -noauth */
444 strcpy(sname.cell, info.name);
445 sname.instance[0] = 0;
446 strcpy(sname.name, "afs");
447 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
448 if (code) { /* did not get ticket */
449 fprintf(STDERR, "vsu_ClientInit: Could not get afs tokens, running unauthenticated.\n");
452 else { /* got a ticket */
454 if ((ttoken.kvno < 0) || (ttoken.kvno > 255)) {
455 fprintf(STDERR, "vsu_ClientInit: funny kvno (%d) in ticket, proceeding\n",
463 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
466 sc = (struct rx_securityClass *)rxkad_NewClientSecurityObject(
467 rxkad_clear, &ttoken.sessionKey, ttoken.kvno,
468 ttoken.ticketLen, ttoken.ticket);
471 fprintf(STDERR, "vsu_ClientInit: unsupported security index %d\n",
478 if (secproc) /* tell UV module about default authentication */
479 (*secproc) (sc, scIndex);
480 if (info.numServers > VLDB_MAXSERVERS) {
481 fprintf(STDERR, "vsu_ClientInit: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
482 info.numServers, VLDB_MAXSERVERS);
485 for (i=0; i<info.numServers; i++) {
486 serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
487 info.hostAddr[i].sin_port, USER_SERVICE_ID,
491 code = ubik_ClientInit(serverconns, uclientp);
493 fprintf(STDERR, "vsu_ClientInit: ubik client init failed.\n");
500 /*extract the name of volume <name> without readonly or backup suffixes
501 * and return the result as <rname>.
503 vsu_ExtractName(rname,name)
509 total = strlen(sname);
510 if(!strcmp(&sname[total - 9],".readonly")) {
511 /*discard the last 8 chars */
512 sname[total - 9] = '\0';
516 else if(!strcmp(&sname[total - 7 ],".backup")) {
517 /*discard last 6 chars */
518 sname[total - 7] = '\0';
523 strncpy(rname,name,VOLSER_OLDMAXVOLNAME);
529 /* returns 0 if failed */
530 afs_uint32 vsu_GetVolumeID(astring, acstruct, errp)
531 struct ubik_client *acstruct;
534 afs_uint32 tc, value;
536 char *str,*ptr, volname[VOLSER_OLDMAXVOLNAME+1];
538 struct nvldbentry entry;
543 total = strlen(astring);
547 while (curval = *str++){
548 if(curval < '0' || curval > '9')
553 vsu_ExtractName(volname,astring);
554 vcode = VLDB_GetEntryByName(volname, &entry);
556 if(!strcmp(&astring[total - 9],".readonly"))
557 return entry.volumeId[ROVOL];
558 else if ((!strcmp(&astring[total - 7 ],".backup")))
559 return entry.volumeId[BACKVOL];
561 return (entry.volumeId[RWVOL]);
564 return 0; /* can't find volume */
569 while (tc = *astring++) {
571 if(!tryname) fprintf(STDERR,"goofed in volid \n");
572 else {fprintf(STDERR,"Could not get entry from vldb for %s\n",ptr);PrintError("",vcode);}
576 if (tc < '0' || tc > '9'){
577 if(!tryname) fprintf(STDERR,"internal error: out of range char in vol ID\n");
578 else {fprintf(STDERR,"Could not get entry from vldb for %s\n",ptr);PrintError("",vcode);}