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>
16 #include <afs/pthread_glock.h>
18 #include "../afs/sysincludes.h"
19 #include "../afs/afsincludes.h"
21 #include <sys/types.h>
24 #include <sys/utime.h>
26 #include <WINNT/afssw.h>
29 #endif /* AFS_AFSDB_ENV */
31 #include <sys/socket.h>
32 #include <netinet/in.h>
37 #include <arpa/nameser.h>
39 #endif /* AFS_AFSDB_ENV */
40 #endif /* AFS_NT40_ENV */
59 #include <afs/afsutil.h>
60 #include "cellconfig.h"
62 #include <afs/afsint.h>
64 static ParseHostLine();
65 static ParseCellLine();
66 static afsconf_OpenInternal();
67 static afsconf_CloseInternal();
68 static afsconf_Reopen();
70 static struct afsconf_servPair serviceTable [] = {
75 { "afskauth", 7004, },
77 { "afserror", 7006, },
78 { "afsnanny", 7007, },
79 { "afsupdate", 7008, },
80 { "afsrmtsys", 7009, },
81 { "afsres", 7010, }, /* residency database for MR-AFS */
82 { "afsremio", 7011, }, /* remote I/O interface for MR-AFS */
83 { 0, 0 } /* insert new services before this spot */
87 * Basic Rule: we touch "<AFSCONF_DIR>/CellServDB" every time we change anything, so
88 * our code can tell if there is new info in the key files, the cell server db
89 * files or any of the other files (and reopen the thing) if the date on
93 /* return port number in network byte order in the low 16 bits of a long; return -1 if not found */
94 static afs_int32 afsconf_FindService(aname)
95 register char *aname; {
96 /* lookup a service name */
98 register struct afsconf_servPair *tsp;
100 #if defined(AFS_OSF_ENV) || defined(AFS_DEC_ENV)
101 ts = getservbyname(aname, "");
103 ts = getservbyname(aname, (char *) 0);
106 /* we found it in /etc/services, so we use this value */
107 return ts->s_port; /* already in network byte order */
110 /* not found in /etc/services, see if it is one of ours */
111 for(tsp = serviceTable;; tsp++) {
112 if (tsp->name == (char *) 0) return -1;
113 if (!strcmp(tsp->name, aname)) return htons(tsp->port);
117 static int TrimLine(abuffer)
125 if (!isspace(tc)) break;
129 strcpy(abuffer, tbuffer);
135 * IsClientConfigDirectory() -- determine if path matches well-known
136 * client configuration directory.
138 static int IsClientConfigDirectory(const char *path)
140 const char *cdir = AFSDIR_CLIENT_ETC_DIRPATH;
143 for (i = 0; cdir[i] != '\0' && path[i] != '\0'; i++) {
144 int cc = tolower(cdir[i]);
145 int pc = tolower(path[i]);
158 /* hit end of one or both; allow mismatch in existence of trailing slash */
159 if (cdir[i] != '\0') {
160 if ((cdir[i] != '\\' && cdir[i] != '/') || (cdir[i + 1] != '\0')) {
164 if (path[i] != '\0') {
165 if ((path[i] != '\\' && path[i] != '/') || (path[i + 1] != '\0')) {
171 #endif /* AFS_NT40_ENV */
174 static int afsconf_Check(adir)
175 register struct afsconf_dir *adir; {
178 register afs_int32 code;
181 /* NT client CellServDB has different file name than NT server or Unix */
182 if (IsClientConfigDirectory(adir->name)) {
183 strcompose(tbuffer, 256,
184 adir->name, "/", AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL);
186 strcompose(tbuffer, 256,
187 adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
190 strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
191 #endif /* AFS_NT40_ENV */
193 code = stat(tbuffer, &tstat);
197 /* did file change? */
198 if (tstat.st_mtime == adir->timeRead) {
201 /* otherwise file has changed, so reopen it */
202 return afsconf_Reopen(adir);
205 /* set modtime on file */
206 static afsconf_Touch(adir)
207 register struct afsconf_dir *adir; {
210 struct timeval tvp[2];
213 adir->timeRead = 0; /* just in case */
216 /* NT client CellServDB has different file name than NT server or Unix */
218 if (IsClientConfigDirectory(adir->name)) {
219 strcompose(tbuffer, 256,
220 adir->name, "/", AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL);
222 strcompose(tbuffer, 256,
223 adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
226 return _utime(tbuffer, NULL);
229 strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
230 gettimeofday(&tvp[0], NULL);
232 return utimes(tbuffer, tvp);
233 #endif /* AFS_NT40_ENV */
236 struct afsconf_dir *afsconf_Open(adir)
237 register char *adir; {
238 register struct afsconf_dir *tdir;
239 register afs_int32 code;
242 /* zero structure and fill in name; rest is done by internal routine */
243 tdir = (struct afsconf_dir *) malloc(sizeof(struct afsconf_dir));
244 memset(tdir, 0, sizeof(struct afsconf_dir));
245 tdir->name = (char *) malloc(strlen(adir)+1);
246 strcpy(tdir->name, adir);
248 code = afsconf_OpenInternal(tdir, 0, 0);
250 char *afsconf_path, *getenv(), afs_confdir[128];
253 /* Check global place only when local Open failed for whatever reason */
254 if (!(afsconf_path = getenv("AFSCONF"))) {
255 /* The "AFSCONF" environment (or contents of "/.AFSCONF") will be typically set to something like "/afs/<cell>/common/etc" where, by convention, the default files for "ThisCell" and "CellServDB" will reside; note that a major drawback is that a given afs client on that cell may NOT contain the same contents... */
260 if (!(home_dir = getenv("HOME"))) {
261 /* Our last chance is the "/.AFSCONF" file */
262 fp = fopen("/.AFSCONF", "r");
266 return (struct afsconf_dir *) 0;
268 fgets(afs_confdir, 128, fp);
273 sprintf(pathname, "%s/%s", home_dir, ".AFSCONF");
274 fp = fopen(pathname, "r");
276 /* Our last chance is the "/.AFSCONF" file */
277 fp = fopen("/.AFSCONF", "r");
281 return (struct afsconf_dir *) 0;
283 fgets(afs_confdir, 128, fp);
286 fgets(afs_confdir, 128, fp);
289 len = strlen(afs_confdir);
293 return (struct afsconf_dir *) 0;
295 if (afs_confdir[len-1] == '\n') {
296 afs_confdir[len-1] = 0;
298 afsconf_path = afs_confdir;
300 tdir->name = (char *) malloc(strlen(afsconf_path)+1);
301 strcpy(tdir->name, afsconf_path);
302 code = afsconf_OpenInternal(tdir, 0, 0);
307 return (struct afsconf_dir *) 0;
315 static int GetCellUnix(struct afsconf_dir *adir)
321 strcompose(tbuffer, 256, adir->name, "/", AFSDIR_THISCELL_FILE, NULL);
322 tf = fopen(tbuffer, "r");
324 rc = fscanf(tf, "%s", tbuffer);
326 adir->cellName = (char *) malloc(strlen(tbuffer)+1);
327 strcpy(adir->cellName, tbuffer);
339 static int GetCellNT(struct afsconf_dir *adir)
341 if (IsClientConfigDirectory(adir->name)) {
342 /* NT client config dir; ThisCell is in registry (no file). */
343 return afssw_GetClientCellName(&adir->cellName);
345 /* NT server config dir; works just like Unix */
346 return GetCellUnix(adir);
349 #endif /* AFS_NT40_ENV */
352 static int afsconf_OpenInternal(adir, cell, clones)
353 register struct afsconf_dir *adir;
358 register char *tp, *bp;
359 register struct afsconf_entry *curEntry;
360 register afs_int32 code;
362 char tbuffer[256], tbuf1[256];
365 /* figure out the cell name */
369 i = GetCellUnix(adir);
372 #ifndef AFS_FREELANCE_CLIENT /* no local cell not fatal in freelance */
378 /* now parse the individual lines */
382 /* NT client/server have a CellServDB that is the same format as Unix.
383 * However, the NT client uses a different file name
385 if (IsClientConfigDirectory(adir->name)) {
386 /* NT client config dir */
387 strcompose(tbuffer, 256,
388 adir->name, "/", AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL);
390 /* NT server config dir */
391 strcompose(tbuffer, 256,
392 adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
395 strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
396 #endif /* AFS_NT40_ENV */
398 if (!stat(tbuffer, &tstat)) {
399 adir->timeRead = tstat.st_mtime;
404 strcpy(tbuf1, tbuffer);
405 tf = fopen(tbuffer, "r");
410 tp = fgets(tbuffer, sizeof(tbuffer), tf);
412 TrimLine(tbuffer); /* remove white space */
413 if (tbuffer[0] == 0 || tbuffer[0] == '\n') continue; /* empty line */
414 if (tbuffer[0] == '>') {
415 char linkedcell[MAXCELLCHARS];
416 /* start new cell item */
418 /* thread this guy on the list */
419 curEntry->next = adir->entries;
420 adir->entries = curEntry;
423 curEntry = (struct afsconf_entry *) malloc(sizeof(struct afsconf_entry));
424 memset(curEntry, 0, sizeof(struct afsconf_entry));
425 code = ParseCellLine(tbuffer, curEntry->cellInfo.name, linkedcell);
427 afsconf_CloseInternal(adir);
431 if (linkedcell[0] != '\0') {
432 curEntry->cellInfo.linkedCell =
433 (char *) malloc(strlen(linkedcell) + 1);
434 strcpy(curEntry->cellInfo.linkedCell, linkedcell);
438 /* new host in the current cell */
440 afsconf_CloseInternal(adir);
444 i = curEntry->cellInfo.numServers;
445 if (cell && !strcmp(cell, curEntry->cellInfo.name))
446 code = ParseHostLine(tbuffer, (char *) &curEntry->cellInfo.hostAddr[i], curEntry->cellInfo.hostName[i], &clones[i]);
448 code = ParseHostLine(tbuffer, (char *) &curEntry->cellInfo.hostAddr[i], curEntry->cellInfo.hostName[i], 0);
450 if (code == AFSCONF_SYNTAX) {
451 for (bp=tbuffer; *bp != '\n'; bp++) { /* Take out the <cr> from the buffer */
455 fprintf(stderr, "Can't properly parse host line \"%s\" in configuration file %s\n", tbuffer, tbuf1);
459 afsconf_CloseInternal(adir);
462 curEntry->cellInfo.numServers = ++i;
465 fclose(tf); /* close the file now */
467 /* end the last partially-completed cell */
469 curEntry->next = adir->entries;
470 adir->entries = curEntry;
473 /* now read the fs keys, if possible */
474 adir->keystr = (struct afsconf_keys *) 0;
475 afsconf_IntGetKeys(adir);
480 /* parse a line of the form
481 *"128.2.1.3 #hostname" or
482 *"[128.2.1.3] #hostname" for clones
483 * into the appropriate pieces.
485 static ParseHostLine(aline, addr, aname, aclone)
487 register struct sockaddr_in *addr;
491 register afs_int32 code;
495 if (aclone) *aclone = 1;
496 code = sscanf(aline, "[%d.%d.%d.%d] #%s", &c1, &c2, &c3, &c4, aname);
498 if (aclone) *aclone = 0;
499 code = sscanf(aline, "%d.%d.%d.%d #%s", &c1, &c2, &c3, &c4, aname);
501 if (code != 5) return AFSCONF_SYNTAX;
502 addr->sin_family = AF_INET;
504 tp = (char *) &addr->sin_addr;
512 /* parse a line of the form
513 * ">cellname [linkedcellname] [#comments]"
514 * into the appropriate pieces.
516 static ParseCellLine(aline, aname, alname)
517 register char *aline, *aname, *alname; {
519 code = sscanf(aline, ">%s %s", aname, alname);
520 if (code == 1) *alname = '\0';
522 if (*alname == '#') {
526 return (code > 0 ? 0 : AFSCONF_SYNTAX);
529 /* call aproc(entry, arock, adir) for all cells. Proc must return 0, or we'll stop early and return the code it returns */
530 afsconf_CellApply(adir, aproc, arock)
531 struct afsconf_dir *adir;
534 register struct afsconf_entry *tde;
535 register afs_int32 code;
537 for(tde=adir->entries; tde; tde=tde->next) {
538 code = (*aproc)(&tde->cellInfo, arock, adir);
548 afs_int32 afsconf_SawCell = 0;
550 afsconf_GetExtendedCellInfo(adir, acellName, aservice, acellInfo, clones)
551 struct afsconf_dir *adir;
554 struct afsconf_cell *acellInfo;
560 code = afsconf_GetCellInfo(adir, acellName, aservice, acellInfo);
567 cell = (char *) &acellInfo->name;
569 code = afsconf_OpenInternal(adir, cell, clones);
574 #if !defined(AFS_NT40_ENV)
575 afsconf_GetAfsdbInfo(acellName, aservice, acellInfo)
578 struct afsconf_cell *acellInfo;
583 unsigned char answer[1024];
589 /* The resolver isn't always MT-safe.. Perhaps this ought to be
590 * replaced with a more fine-grained lock just for the resolver
594 len = res_search(acellName, C_IN, T_AFSDB, answer, sizeof(answer));
598 return AFSCONF_NOTFOUND;
600 p = answer + sizeof(HEADER); /* Skip header */
601 code = dn_expand(answer, answer + len, p, host, sizeof(host));
603 return AFSCONF_NOTFOUND;
604 strncpy(acellInfo->name, host, sizeof(acellInfo->name));
606 p += code + QFIXEDSZ; /* Skip name */
608 while (p < answer + len) {
611 code = dn_expand(answer, answer + len, p, host, sizeof(host));
613 return AFSCONF_NOTFOUND;
615 p += code; /* Skip the name */
616 type = (p[0] << 8) | p[1];
617 p += 4; /* Skip type and class */
618 ttl = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
619 p += 4; /* Skip the TTL */
620 size = (p[0] << 8) | p[1];
621 p += 2; /* Skip the size */
623 if (type == T_AFSDB) {
627 afsdb_type = (p[0] << 8) | p[1];
628 code = dn_expand(answer, answer+len, p+2, host, sizeof(host));
630 return AFSCONF_NOTFOUND;
632 if ((afsdb_type == 1) &&
633 (server_num < MAXHOSTSPERCELL) &&
634 /* Do we want to get TTL data for the A record as well? */
635 (he = gethostbyname(host))) {
637 memcpy(&ipaddr, he->h_addr, he->h_length);
638 acellInfo->hostAddr[server_num].sin_addr.s_addr = ipaddr;
639 strncpy(acellInfo->hostName[server_num], host,
640 sizeof(acellInfo->hostName[server_num]));
643 if (!minttl || ttl < minttl) minttl = ttl;
650 if (server_num == 0) /* No AFSDB records */
651 return AFSCONF_NOTFOUND;
652 acellInfo->numServers = server_num;
655 tservice = afsconf_FindService(aservice);
657 return AFSCONF_NOTFOUND; /* service not found */
658 for (i=0; i<acellInfo->numServers; i++) {
659 acellInfo->hostAddr[i].sin_port = tservice;
663 acellInfo->timeout = minttl ? (time(0) + minttl) : 0;
668 int afsconf_GetAfsdbInfo(acellName, aservice, acellInfo)
671 struct afsconf_cell *acellInfo;
673 register afs_int32 i;
675 struct afsconf_entry DNSce;
676 char *DNStmpStrp; /* a temp string pointer */
678 afs_int32 cellHosts[AFSMAXCELLHOSTS];
683 DNSce.cellInfo.numServers=0;
685 rc = getAFSServer(acellName, cellHosts, &numServers, &ttl);
686 /* ignore the ttl here since this code is only called by transitory programs
693 for (i = 0; i < numServers; i++)
695 memcpy(&acellInfo->hostAddr[i].sin_addr.s_addr, &cellHosts[i], sizeof(long));
696 acellInfo->hostAddr[i].sin_family = AF_INET;
698 /* sin_port supplied by connection code */
701 acellInfo->numServers = numServers;
702 strcpy(acellInfo->name, acellName);
705 tservice = afsconf_FindService(aservice);
708 return AFSCONF_NOTFOUND; /* service not found */
710 for(i=0; i< acellInfo->numServers; i++) {
711 acellInfo->hostAddr[i].sin_port = tservice;
714 acellInfo->linkedCell = NULL; /* no linked cell */
715 acellInfo->flags = 0;
719 #endif /* AFS_AFSDB_ENV */
721 afsconf_GetCellInfo(adir, acellName, aservice, acellInfo)
722 struct afsconf_dir *adir;
725 struct afsconf_cell *acellInfo; {
726 register struct afsconf_entry *tce;
727 struct afsconf_entry *bestce;
728 register afs_int32 i;
736 if (adir) afsconf_Check(adir);
739 cnLen = strlen(tcell)+1;
740 lcstring (tcell, tcell, cnLen);
741 afsconf_SawCell = 1; /* will ignore the AFSCELL switch on future */
742 /* call to afsconf_GetLocalCell: like klog */
744 i = afsconf_GetLocalCell(adir, tbuffer, sizeof(tbuffer));
751 cnLen = strlen(tcell);
752 bestce = (struct afsconf_entry *) 0;
758 for(tce=adir->entries;tce;tce=tce->next) {
759 if (strcasecmp(tce->cellInfo.name, tcell) == 0) {
765 if (strlen(tce->cellInfo.name) < cnLen) continue; /* clearly wrong */
766 if (strncasecmp(tce->cellInfo.name, tcell, cnLen) == 0) {
767 if (bestce) ambig = 1; /* ambiguous unless we get exact match */
771 if (!ambig && bestce) {
772 *acellInfo = bestce->cellInfo; /* structure assignment */
774 tservice = afsconf_FindService(aservice);
777 return AFSCONF_NOTFOUND; /* service not found */
779 for(i=0;i<acellInfo->numServers;i++) {
780 acellInfo->hostAddr[i].sin_port = tservice;
783 acellInfo->timeout = 0;
790 return afsconf_GetAfsdbInfo(acellName, aservice, acellInfo);
792 return AFSCONF_NOTFOUND;
793 #endif /* AFS_AFSDB_ENV */
797 afsconf_GetLocalCell(adir, aname, alen)
798 register struct afsconf_dir *adir;
801 static int afsconf_showcell = 0;
808 * If a cell switch was specified in a command, then it should override the
809 * AFSCELL variable. If a cell was specified, then the afsconf_SawCell flag
810 * is set and the cell name in the adir structure is used.
811 * Read the AFSCELL var each time: in case it changes (unsetenv AFSCELL).
813 if ( !afsconf_SawCell && (afscell_path= getenv("AFSCELL")) ) {
814 if ( !afsconf_showcell ) {
815 fprintf(stderr, "Note: Operation is performed on cell %s\n", afscell_path);
816 afsconf_showcell = 1;
818 strncpy(aname, afscell_path, alen);
821 if (adir->cellName) {
822 strncpy(aname, adir->cellName, alen);
824 else code = AFSCONF_UNKNOWN;
832 struct afsconf_dir *adir; {
834 afsconf_CloseInternal(adir);
835 if (adir->name) free(adir->name);
841 static int afsconf_CloseInternal(adir)
842 register struct afsconf_dir *adir; {
843 register struct afsconf_entry *td, *nd;
844 register char *tname;
846 tname = adir->name; /* remember name, since that's all we preserve */
848 /* free everything we can find */
849 if (adir->cellName) free(adir->cellName);
850 for(td=adir->entries;td;td=nd) {
852 if (td->cellInfo.linkedCell)
853 free(td->cellInfo.linkedCell);
856 if (adir->keystr) free(adir->keystr);
859 memset(adir, 0, sizeof(struct afsconf_dir));
860 adir->name = tname; /* restore it */
864 static int afsconf_Reopen(adir)
865 register struct afsconf_dir *adir; {
866 register afs_int32 code;
867 code = afsconf_CloseInternal(adir);
868 if (code) return code;
869 code = afsconf_OpenInternal(adir, 0, 0);
873 /* called during opening of config file */
874 afsconf_IntGetKeys(adir)
875 struct afsconf_dir *adir;
879 struct afsconf_keys *tstr;
880 register afs_int32 code;
883 /* NT client config dir has no KeyFile; don't risk attempting open
884 * because there might be a random file of this name if dir is shared.
886 if (IsClientConfigDirectory(adir->name)) {
887 adir->keystr = ((struct afsconf_keys *)
888 malloc(sizeof(struct afsconf_keys)));
889 adir->keystr->nkeys = 0;
892 #endif /* AFS_NT40_ENV */
895 /* compute the key name and other setup */
897 strcompose(tbuffer, 256, adir->name, "/", AFSDIR_KEY_FILE, NULL);
898 tstr = (struct afsconf_keys *) malloc(sizeof (struct afsconf_keys));
902 fd = open(tbuffer, O_RDONLY);
908 code = read(fd, tstr, sizeof(struct afsconf_keys));
910 if (code < sizeof(afs_int32)) {
916 /* convert key structure to host order */
917 tstr->nkeys = ntohl(tstr->nkeys);
918 for(fd=0;fd<tstr->nkeys;fd++)
919 tstr->key[fd].kvno = ntohl(tstr->key[fd].kvno);
925 /* get keys structure */
926 afsconf_GetKeys(adir, astr)
927 struct afsconf_dir *adir;
928 struct afsconf_keys *astr;
930 register afs_int32 code;
933 code = afsconf_Check(adir);
935 return AFSCONF_FAILURE;
936 memcpy(astr, adir->keystr, sizeof(struct afsconf_keys));
942 afs_int32 afsconf_GetLatestKey(adir, avno, akey)
943 IN struct afsconf_dir *adir;
949 register struct afsconf_key *tk;
950 register afs_int32 best;
951 struct afsconf_key *bestk;
952 register afs_int32 code;
955 code = afsconf_Check(adir);
957 return AFSCONF_FAILURE;
958 maxa = adir->keystr->nkeys;
960 best = -1; /* highest kvno we've seen yet */
961 bestk = (struct afsconf_key *) 0; /* ptr to structure providing best */
962 for(tk = adir->keystr->key,i=0;i<maxa;i++,tk++) {
963 if (tk->kvno == 999) continue; /* skip bcrypt keys */
964 if (tk->kvno > best) {
969 if (bestk) { /* found any */
970 if (akey) memcpy(akey, bestk->key, 8); /* copy out latest key */
971 if (avno) *avno = bestk->kvno; /* and kvno to caller */
976 return AFSCONF_NOTFOUND; /* didn't find any keys */
979 /* get a particular key */
980 afsconf_GetKey(adir, avno, akey)
981 struct afsconf_dir *adir;
985 register int i, maxa;
986 register struct afsconf_key *tk;
987 register afs_int32 code;
990 code = afsconf_Check(adir);
992 return AFSCONF_FAILURE;
993 maxa = adir->keystr->nkeys;
995 for(tk = adir->keystr->key,i=0;i<maxa;i++,tk++) {
996 if (tk->kvno == avno) {
997 memcpy(akey, tk->key, 8);
1004 return AFSCONF_NOTFOUND;
1007 /* save the key structure in the appropriate file */
1008 static SaveKeys(adir)
1009 struct afsconf_dir *adir;
1011 struct afsconf_keys tkeys;
1013 register afs_int32 i;
1016 memcpy(&tkeys, adir->keystr, sizeof(struct afsconf_keys));
1018 /* convert it to net byte order */
1019 for(i = 0; i<tkeys.nkeys; i++ )
1020 tkeys.key[i].kvno = htonl(tkeys.key[i].kvno);
1021 tkeys.nkeys = htonl(tkeys.nkeys);
1023 /* rewrite keys file */
1024 strcompose(tbuffer, 256, adir->name, "/", AFSDIR_KEY_FILE, NULL);
1025 fd = open(tbuffer, O_RDWR | O_CREAT | O_TRUNC, 0600);
1026 if (fd < 0) return AFSCONF_FAILURE;
1027 i = write(fd, &tkeys, sizeof(tkeys));
1028 if (i != sizeof(tkeys)) {
1030 return AFSCONF_FAILURE;
1032 if (close(fd) < 0) return AFSCONF_FAILURE;
1036 afsconf_AddKey(adir, akvno, akey, overwrite)
1037 struct afsconf_dir *adir;
1038 afs_int32 akvno, overwrite;
1041 register struct afsconf_keys *tk;
1042 register struct afsconf_key *tkey;
1043 register afs_int32 i;
1050 if (akvno < 0 || akvno > 255) {
1056 for(i=0, tkey = tk->key; i<tk->nkeys; i++, tkey++) {
1057 if (tkey->kvno == akvno) {
1060 return AFSCONF_KEYINUSE;
1067 if (tk->nkeys >= AFSCONF_MAXKEYS) {
1069 return AFSCONF_FULL;
1071 tkey = &tk->key[tk->nkeys++];
1074 memcpy(tkey->key, akey, 8);
1076 afsconf_Touch(adir);
1081 /* this proc works by sliding the other guys down, rather than using a funny
1082 kvno value, so that callers can count on getting a good key in key[0].
1084 afsconf_DeleteKey(adir, akvno)
1085 struct afsconf_dir *adir;
1088 register struct afsconf_keys *tk;
1089 register struct afsconf_key *tkey;
1096 for(i=0, tkey = tk->key; i<tk->nkeys; i++, tkey++) {
1097 if (tkey->kvno == akvno) {
1104 return AFSCONF_NOTFOUND;
1107 /* otherwise slide the others down. i and tkey point at the guy to delete */
1108 for(;i<tk->nkeys-1; i++,tkey++) {
1109 tkey->kvno = (tkey+1)->kvno;
1110 memcpy(tkey->key, (tkey+1)->key, 8);
1114 afsconf_Touch(adir);