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>
14 #include <sys/types.h>
18 #include <netinet/in.h>
24 #include <afs/afsutil.h>
29 extern Date cheaderReadTime; /* time cheader last read in */
31 #define set_header_word(tt,field,value) kawrite ((tt), ((char *)&(cheader.field) - (char *)&cheader), ((cheader.field = (value)), (char *)&(cheader.field)), sizeof(afs_int32))
33 #define inc_header_word(tt,field) kawrite ((tt), ((char *)&(cheader.field) - (char *)&cheader), ((cheader.field = (htonl(ntohl(cheader.field)+1))), (char *)&(cheader.field)), sizeof(afs_int32))
35 static int index_OK(afs_int32);
38 NameHash(char *aname, char *ainstance)
43 /* stolen directly from the HashString function in the vol package */
45 for (i = strlen(aname), aname += i - 1; i--; aname--)
46 hash = (hash * 31) + (*((unsigned char *)aname) - 31);
47 for (i = strlen(ainstance), ainstance += i - 1; i--; ainstance--)
48 hash = (hash * 31) + (*((unsigned char *)ainstance) - 31);
49 return (hash % HASHSIZE);
52 /* package up seek and write into one procedure for ease of use */
55 kawrite(struct ubik_trans *tt, afs_int32 pos, char *buff, afs_int32 len)
59 code = ubik_Seek(tt, 0, pos);
62 code = ubik_Write(tt, buff, len);
66 /* same thing for read */
69 karead(struct ubik_trans *tt, afs_int32 pos, char *buff, afs_int32 len)
73 code = ubik_Seek(tt, 0, pos);
76 code = ubik_Read(tt, buff, len);
80 static struct Lock keycache_lock;
82 static int maxCachedKeys;
84 static struct cachedKey {
86 int superseded; /* NEVERDATE => this is current key */
88 struct ktc_encryptionKey key;
89 char name[MAXKTCNAMELEN];
90 char inst[MAXKTCNAMELEN];
92 static afs_int32 keyCacheVersion = 0;
94 static afs_int32 maxKeyLifetime;
95 static int dbfixup = 0;
98 init_kadatabase(int initFlags)
100 Lock_Init(&keycache_lock);
104 (struct cachedKey *)malloc(maxCachedKeys * sizeof(struct cachedKey));
109 maxKeyLifetime = MAXKTCTICKETLIFETIME;
115 /* check that the database has been initialized. Be careful to fail in a safe
116 manner, to avoid bogusly reinitializing the db. */
118 * reads in db cache from ubik.
120 * @param[in] ut ubik transaction
121 * @param[in] rock opaque pointer to an int (*) (struct ubik_trans *), which
122 * will be called on rebuilding the database (or NULL to not
125 * @return operation status
129 UpdateCache(struct ubik_trans *at, void *rock)
131 int (*db_init) (struct ubik_trans *) = rock;
136 if ((code = karead(at, 0, (char *)&iversion, sizeof(iversion)))
138 karead(at, sizeof(cheader) - sizeof(afs_int32), (char *)&tversion,
139 sizeof(afs_int32)))) {
141 printf("No data base\n");
143 printf("I/O Error\n");
145 iversion = ntohl(iversion); /* convert to host order */
146 tversion = ntohl(tversion);
147 if ((iversion == KADBVERSION) && (tversion == KADBVERSION)) {
148 code = karead(at, 0, (char *)&cheader, sizeof(cheader));
150 printf("SetupHeader failed\n");
153 cheaderReadTime = time(0);
156 printf("DB version should be %d; Initial = %d; Terminal = %d\n",
157 KADBVERSION, iversion, tversion);
164 /* if here, we have no version number or the wrong version number in the
166 if ((code == UEOF) || ((iversion == 0) && (tversion == 0)))
171 if ((db_init == 0) || (code == KAIO))
174 printf("Error discovered in header, rebuilding.\n");
176 /* try to write a good header */
177 memset(&cheader, 0, sizeof(cheader));
178 cheader.version = htonl(KADBVERSION);
179 cheader.checkVersion = htonl(KADBVERSION);
180 cheader.headerSize = htonl(sizeof(cheader));
182 cheader.eofPtr = htonl(sizeof(cheader));
184 cheader.specialKeysVersion = htonl(time(0)); /* anything non-zero will do */
185 cheader.stats.cpws = cheader.stats.allocs = cheader.stats.frees = 0;
186 cheader.admin_accounts = 0;
187 cheader.hashsize = htonl(HASHSIZE);
188 code = kawrite(at, 0, (char *)&cheader, sizeof(cheader));
190 return KAIO; /* return the error code */
192 return db_init(at); /* initialize the db */
196 CheckInit(struct ubik_trans *at,
197 int (*db_init) (struct ubik_trans *)) /* procedure to call if rebuilding DB */
199 return ubik_CheckCache(at, UpdateCache, db_init);
202 /* Allocate a free block of storage for entry, returning address of a new
203 zeroed entry. If zero is returned, a Ubik I/O error can be assumed. */
206 AllocBlock(struct ubik_trans *at, struct kaentry *tentry)
211 if (cheader.freePtr) {
212 /* allocate this dude */
213 temp = ntohl(cheader.freePtr);
214 code = karead(at, temp, (char *)tentry, sizeof(kaentry));
216 return 0; /* can't read block */
217 code = set_header_word(at, freePtr, tentry->next);
219 /* hosed, nothing on free list, grow file */
220 temp = ntohl(cheader.eofPtr); /* remember this guy */
221 code = set_header_word(at, eofPtr, htonl(temp + sizeof(kaentry)));
226 code = inc_header_word(at, stats.allocs);
229 memset(tentry, 0, sizeof(kaentry)); /* zero new entry */
233 /* Free a block given its index. It must already have been unthreaded.
234 Returns zero for success or an error code on failure. */
237 FreeBlock(struct ubik_trans *at, afs_int32 index)
239 struct kaentry tentry;
242 /* check index just to be on the safe side */
243 if (!index_OK(index))
246 memset(&tentry, 0, sizeof(kaentry));
247 tentry.next = cheader.freePtr;
248 tentry.flags = htonl(KAFFREE);
249 code = set_header_word(at, freePtr, htonl(index));
252 code = kawrite(at, index, (char *)&tentry, sizeof(kaentry));
256 code = inc_header_word(at, stats.frees);
262 /* Look for a block by name and instance. If found read the block's contents
263 into the area pointed to by tentry and return the block's index. If not
264 found offset is set to zero. If an error is encountered a non-zero code is
268 FindBlock(struct ubik_trans *at, char *aname, char *ainstance, afs_int32 *toP,
269 struct kaentry *tentry)
275 i = NameHash(aname, ainstance);
276 for (to = ntohl(cheader.nameHash[i]); to != NULLO;
277 to = ntohl(tentry->next)) {
278 code = karead(at, to, (char *)tentry, sizeof(kaentry));
281 /* see if the name matches */
282 if (!strcmp(aname, tentry->userID.name)
283 && (ainstance == (char *)0
284 || !strcmp(ainstance, tentry->userID.instance))) {
285 *toP = to; /* found it */
289 *toP = 0; /* no such entry */
293 /* Add a block to the hash table given a pointer to the block and its index.
294 The block is threaded onto the hash table and written to disk. The routine
295 returns zero if there were no errors. */
298 ThreadBlock(struct ubik_trans *at, afs_int32 index,
299 struct kaentry *tentry)
302 int hi; /* hash index */
304 if (!index_OK(index))
306 hi = NameHash(tentry->userID.name, tentry->userID.instance);
307 tentry->next = cheader.nameHash[hi];
308 code = set_header_word(at, nameHash[hi], htonl(index));
311 code = kawrite(at, index, (char *)tentry, sizeof(kaentry));
317 /* Remove a block from the hash table. If success return 0, else return an
321 UnthreadBlock(struct ubik_trans *at, struct kaentry *aentry)
326 struct kaentry tentry;
328 i = NameHash(aentry->userID.name, aentry->userID.instance);
330 for (to = ntohl(cheader.nameHash[i]); to != NULLO;
331 to = ntohl(tentry.next)) {
332 code = karead(at, to, (char *)&tentry, sizeof(kaentry));
335 /* see if the name matches */
336 if (!strcmp(aentry->userID.name, tentry.userID.name)
337 && !strcmp(aentry->userID.instance, tentry.userID.instance)) {
339 if (lo) { /* unthread from last block */
341 kawrite(at, lo, (char *)&tentry.next, sizeof(afs_int32));
344 } else { /* unthread from hash table */
345 code = set_header_word(at, nameHash[i], tentry.next);
349 aentry->next = 0; /* just to be sure */
352 lo = DOFFSET(to, &tentry, &tentry.next);
357 /* Given an index to the last block (or zero the first time) read the contents
358 of the next block and return its index. The last argument is a pointer to
359 an estimate of the number of remaining blocks to read out. The remaining
360 count is an estimate because it may include free blocks that are not
361 returned. If there are no more blocks remaining is zero and the returned
362 index is zero. A non-zero index indicates that tentry has been filled with
363 valid data. If an error is encountered the returned index is zero and the
364 remaining count is negative. */
367 NextBlock(struct ubik_trans *at, afs_int32 index, struct kaentry *tentry,
368 afs_int32 *remaining)
373 if (index == 0) /* get first one */
374 index = sizeof(cheader);
376 if (!index_OK(index)) {
377 *remaining = -1; /* error */
380 index += sizeof(kaentry);
382 /* now search for the first entry that isn't free */
383 for (last = ntohl(cheader.eofPtr); index < last; index += sizeof(kaentry)) {
384 code = karead(at, index, (char *)tentry, sizeof(kaentry));
389 if (!(ntohl(tentry->flags) & (KAFFREE | KAFOLDKEYS))) {
390 /* estimate remaining number of entries, not including this one */
391 *remaining = (last - index) / sizeof(kaentry) - 1;
395 *remaining = 0; /* no more entries */
399 /* These are a collections of routines that deal with externally known keys.
400 They maintain a database of key version numbers and the corresponding key
401 and pointer to the user entry. */
404 ka_NewKey(struct ubik_trans *tt, afs_int32 tentryaddr,
405 struct kaentry *tentry, struct ktc_encryptionKey *key)
407 struct kaOldKeys okeys; /* old keys block */
408 afs_int32 okeysaddr, nextaddr; /* offset of old keys block */
409 afs_int32 prevptr, nextprevptr;
412 afs_int32 newkeyver; /* new key version number */
413 afs_int32 newtotalkeyentries = 0, oldtotalkeyentries = 0, keyentries;
414 int foundcurrentkey = 0, addednewkey = 0, modified;
416 es_Report("Newkey for %s.%s\n", tentry->userID.name,
417 tentry->userID.instance);
419 newkeyver = ntohl(tentry->key_version) + 1;
420 if ((newkeyver < 1) || (newkeyver >= MAXKAKVNO))
423 /* An entry may have more than one oldkeys blocks. The entry
424 * points to the most current, but all the oldkeys blocks for an
425 * entry are not linked together. All oldkeys blocks for all
426 * entries are linked together off of the header. So we follow
429 for (prevptr = 0, okeysaddr = ntohl(cheader.kvnoPtr); okeysaddr;
430 prevptr = nextprevptr, okeysaddr = nextaddr) {
431 /* foreacholdkeysblock */
432 /* Read the oldKeys block */
433 code = karead(tt, okeysaddr, (char *)&okeys, sizeof(okeys));
437 nextaddr = ntohl(okeys.next);
438 nextprevptr = DOFFSET(okeysaddr, &okeys, &okeys.next);
440 /* We only want oldkey blocks that belong to this entry */
441 if (ntohl(okeys.entry) != tentryaddr)
444 modified = 0; /* This oldkeys block has not been modified */
445 keyentries = 0; /* Number of valid key entries in the block */
446 for (i = 0; i < NOLDKEYS; i++) {
448 /* Keep count of number of entries found */
449 if (okeys.keys[i].superseded != 0) {
450 oldtotalkeyentries++;
453 /* If we find the entry that is not superseded, then supersede it */
454 if (ntohl(okeys.keys[i].superseded) == NEVERDATE) {
455 okeys.keys[i].superseded = htonl(now);
458 if (foundcurrentkey) {
460 ("Warning: Entry %s.%s contains more than one valid key: fixing\n",
461 tentry->userID.name, tentry->userID.instance));
467 /* If we find an oldkey of the same version or
468 * an old key that has expired, then delete it.
470 if ((ntohl(okeys.keys[i].version) == newkeyver)
471 || ((now - ntohl(okeys.keys[i].superseded) > maxKeyLifetime))) {
472 okeys.keys[i].superseded = 0;
473 okeys.keys[i].version = htonl(-1);
474 memset(&okeys.keys[i].key, 0,
475 sizeof(struct ktc_encryptionKey));
478 es_Report("Dropped oldkey %d seconds old with kvno %d\n",
479 now - ntohl(okeys.keys[i].superseded),
480 ntohl(okeys.keys[i].version));
483 /* Add our key here if its free */
484 if (!addednewkey && (okeys.keys[i].superseded == 0)) {
485 okeys.keys[i].version = htonl(newkeyver);
486 okeys.keys[i].superseded = htonl(NEVERDATE);
487 memcpy(&okeys.keys[i].key, key,
488 sizeof(struct ktc_encryptionKey));
490 addednewkey = okeysaddr;
493 /* Keep count of number of entries found */
494 if (okeys.keys[i].superseded != 0) {
496 newtotalkeyentries++;
500 /* If we modified the block, write it out */
501 if (modified && keyentries) {
502 code = kawrite(tt, okeysaddr, (char *)&okeys, sizeof(okeys));
507 /* If there are no more entries in this oldkeys block, delete it */
508 if (keyentries == 0) {
510 code = set_header_word(tt, kvnoPtr, okeys.next);
513 kawrite(tt, prevptr, (char *)&okeys.next,
518 code = FreeBlock(tt, okeysaddr);
522 nextprevptr = prevptr; /* won't bump prevptr */
524 } /* foreacholdkeysblock */
526 /* If we could not add the key, create a new oldkeys block */
528 /* Allocate and fill in an oldkeys block */
529 addednewkey = AllocBlock(tt, (struct kaentry *)&okeys);
532 okeys.flags = htonl(KAFOLDKEYS);
533 okeys.entry = htonl(tentryaddr);
534 okeys.keys[0].version = htonl(newkeyver);
535 okeys.keys[0].superseded = htonl(NEVERDATE);
536 memcpy(&okeys.keys[0].key, key, sizeof(struct ktc_encryptionKey));
537 newtotalkeyentries++;
539 /* Thread onto the header's chain of oldkeys */
540 okeys.next = cheader.kvnoPtr;
541 code = set_header_word(tt, kvnoPtr, htonl(addednewkey));
545 /* Write the oldkeys block out */
546 code = kawrite(tt, addednewkey, (char *)&okeys, sizeof(okeys));
550 es_Report("New oldkey block allocated at %d\n", addednewkey);
553 if (oldtotalkeyentries != ntohl(tentry->misc.asServer.nOldKeys)) {
555 ("Warning: Entry %s.%s reports %d oldkeys, found %d: fixing\n",
556 tentry->userID.name, tentry->userID.instance,
557 ntohl(tentry->misc.asServer.nOldKeys), oldtotalkeyentries));
561 /* Update the tentry. We rely on caller to write it out */
562 tentry->misc.asServer.oldKeys = htonl(addednewkey);
563 tentry->misc.asServer.nOldKeys = htonl(newtotalkeyentries);
564 tentry->key_version = htonl(newkeyver);
565 memcpy(&tentry->key, key, sizeof(tentry->key));
567 /* invalidate key caches everywhere */
568 code = inc_header_word(tt, specialKeysVersion);
572 es_Report("New kvno is %d, now are %d oldkeys\n", newkeyver,
578 ka_DelKey(struct ubik_trans *tt, afs_int32 tentryaddr,
579 struct kaentry *tentry)
582 struct kaOldKeys okeys; /* old keys block */
583 afs_int32 okeysaddr, nextaddr; /* offset of old keys block */
584 afs_int32 prevptr = 0;
586 es_Report("DelKey for %s.%s\n", tentry->userID.name,
587 tentry->userID.instance);
589 /* An entry may have more than one oldkeys blocks. The entry
590 * points to the most current, but all the oldkeys blocks for an
591 * entry are not linked together. All oldkeys blocks for all
592 * entries are linked together off of the header. So we follow
595 for (okeysaddr = ntohl(cheader.kvnoPtr); okeysaddr; okeysaddr = nextaddr) {
596 /* foreacholdkeysblock */
597 /* Read the oldKeys block */
598 code = karead(tt, okeysaddr, (char *)&okeys, sizeof(okeys));
601 nextaddr = ntohl(okeys.next);
603 /* We only want oldkey blocks that belong to this entry */
604 if (ntohl(okeys.entry) != tentryaddr) {
605 prevptr = DOFFSET(okeysaddr, &okeys, &okeys.next);
609 /* Delete the oldkeys block */
612 kawrite(tt, prevptr, (char *)&okeys.next, sizeof(afs_int32));
614 code = set_header_word(tt, kvnoPtr, okeys.next);
618 code = FreeBlock(tt, okeysaddr);
621 } /* foreacholdkeysblock */
623 /* Update the tentry. We rely on caller to write it out */
624 tentry->misc.asServer.oldKeys = 0;
625 tentry->misc.asServer.nOldKeys = 0;
627 /* invalidate key caches everywhere */
628 code = inc_header_word(tt, specialKeysVersion);
636 ka_debugKeyCache(struct ka_debugInfo *info)
640 /* cheader_lock no longer exists */
641 memset(&info->cheader_lock, 0, sizeof(info->cheader_lock));
642 memcpy(&info->keycache_lock, &keycache_lock, sizeof(info->keycache_lock));
644 info->kcVersion = keyCacheVersion;
645 info->kcSize = maxCachedKeys;
647 for (i = 0; i < maxCachedKeys; i++) {
648 if (keyCache[i].used) {
649 if (info->kcUsed < KADEBUGKCINFOSIZE) {
650 int j = info->kcUsed;
651 char principal[sizeof(keyCache[0].name) +
652 sizeof(keyCache[0].inst)];
654 info->kcInfo[j].used = keyCache[i].superseded;
655 info->kcInfo[j].kvno = keyCache[i].kvno;
656 info->kcInfo[j].primary =
657 (keyCache[i].superseded == NEVERDATE);
658 info->kcInfo[j].keycksum = 0;
662 for (k = 0; k < sizeof(struct ktc_encryptionKey); k++)
663 info->kcInfo[j].keycksum +=
664 ((char *)&keyCache[i].key)[k];
667 strcpy(principal, keyCache[i].name);
668 strcat(principal, ".");
669 strcat(principal, keyCache[i].inst);
670 strncpy(info->kcInfo[j].principal, principal,
671 sizeof(info->kcInfo[0].principal));
678 /* Add a key to the key cache, expanding it if necessary. */
681 ka_Encache(char *name, char *inst, afs_int32 kvno,
682 struct ktc_encryptionKey *key, Date superseded)
686 ObtainWriteLock(&keycache_lock);
687 if (keyCacheVersion != ntohl(cheader.specialKeysVersion)) {
688 for (i = 0; i < maxCachedKeys; i++)
689 keyCache[i].used = 0;
692 for (i = 0; i < maxCachedKeys; i++)
693 if (keyCache[i].used == 0) {
695 keyCache[i].kvno = kvno;
696 strncpy(keyCache[i].name, name, sizeof(keyCache[i].name));
697 strncpy(keyCache[i].inst, inst, sizeof(keyCache[i].inst));
698 keyCacheVersion = ntohl(cheader.specialKeysVersion);
699 memcpy(&keyCache[i].key, key, sizeof(*key));
700 keyCache[i].superseded = superseded;
701 keyCache[i].used = time(0);
703 ReleaseWriteLock(&keycache_lock);
706 /* i == maxCachedKeys */
708 (struct cachedKey *)realloc(keyCache,
710 2) * sizeof(struct cachedKey));
712 es_Report("Can't realloc keyCache! out of memory?");
717 int j = i; /* initialize new storage */
718 while (j < maxCachedKeys)
719 keyCache[j++].used = 0;
724 /* Look up the key given a principal and a kvno. This is called by GetTicket
725 to get the decryption key for the authenticating ticket. It is also called
726 by the rxkad security module to decrypt admin tickets. The rxkad call is
727 with tt==0, since Rx can't call Ubik. */
730 ka_LookupKvno(struct ubik_trans *tt, char *name, char *inst, afs_int32 kvno,
731 struct ktc_encryptionKey *key)
736 struct kaentry tentry;
738 struct kaOldKeys okeys;
740 ObtainReadLock(&keycache_lock);
741 if (keyCacheVersion != ntohl(cheader.specialKeysVersion))
742 code = KAKEYCACHEINVALID;
744 for (i = 0; i < maxCachedKeys; i++) {
745 if (keyCache[i].used) { /* zero used date means invalid */
746 if ((keyCache[i].kvno == kvno)
747 && (strcmp(keyCache[i].name, name) == 0)
748 && (strcmp(keyCache[i].inst, inst) == 0)) {
749 memcpy(key, &keyCache[i].key, sizeof(*key));
750 keyCache[i].used = time(0);
751 ReleaseReadLock(&keycache_lock);
758 ReleaseReadLock(&keycache_lock);
762 /* we missed in the cache so need to look in the Ubik database */
763 code = FindBlock(tt, name, inst, &to, &tentry);
769 /* first check the current key */
770 if (tentry.key_version == htonl(kvno)) {
771 memcpy(key, &tentry.key, sizeof(*key));
772 ka_Encache(name, inst, kvno, key, NEVERDATE);
775 for (ko = ntohl(cheader.kvnoPtr); ko; ko = ntohl(okeys.next)) {
776 code = karead(tt, ko, (char *)&okeys, sizeof(okeys));
779 if (ntohl(okeys.entry) == to)
780 for (i = 0; i < NOLDKEYS; i++)
781 if (okeys.keys[i].superseded
782 && (ntohl(okeys.keys[i].version) == kvno)) {
783 memcpy(key, &okeys.keys[i].key, sizeof(*key));
784 ka_Encache(name, inst, kvno, key,
785 ntohl(okeys.keys[i].superseded));
792 /* Look up the primary key and key version for a principal. */
795 ka_LookupKey(struct ubik_trans *tt,
798 afs_int32 *kvno, /* returned */
799 struct ktc_encryptionKey *key) /* copied out */
803 struct kaentry tentry;
806 ObtainReadLock(&keycache_lock);
807 if (keyCacheVersion != ntohl(cheader.specialKeysVersion))
808 code = KAKEYCACHEINVALID;
810 for (i = 0; i < maxCachedKeys; i++) {
811 if (keyCache[i].used) { /* zero used date means invalid */
812 if ((keyCache[i].superseded == NEVERDATE)
813 && (strcmp(keyCache[i].name, name) == 0)
814 && (strcmp(keyCache[i].inst, inst) == 0)) {
815 memcpy(key, &keyCache[i].key, sizeof(*key));
816 *kvno = keyCache[i].kvno;
817 keyCache[i].used = time(0);
818 ReleaseReadLock(&keycache_lock);
825 ReleaseReadLock(&keycache_lock);
829 /* we missed in the cache so need to look in the Ubik database */
830 code = FindBlock(tt, name, inst, &to, &tentry);
835 memcpy(key, &tentry.key, sizeof(*key));
836 *kvno = ntohl(tentry.key_version);
837 ka_Encache(name, inst, *kvno, key, NEVERDATE);
841 /* This is, hopefully a temporary mechanism to fill the cache will all keys
842 since filling cache misses during rxkad challenge responses will deadlock if
843 Ubik needs to use Rx. */
846 ka_FillKeyCache(struct ubik_trans *tt)
852 struct ktc_encryptionKey k;
853 struct kaOldKeys okeys;
854 struct kaentry tentry;
856 /* this is a little marginal, but... */
857 if (keyCacheVersion == ntohl(cheader.specialKeysVersion))
861 for (ko = ntohl(cheader.kvnoPtr); ko; ko = ntohl(okeys.next)) {
862 code = karead(tt, ko, (char *)&okeys, sizeof(okeys));
865 /* get name & instance */
867 karead(tt, ntohl(okeys.entry), (char *)&tentry, sizeof(tentry));
871 /* get all the old keys in this block */
872 for (i = 0; i < NOLDKEYS; i++)
873 if (okeys.keys[i].superseded) {
875 ka_LookupKvno(tt, tentry.userID.name,
876 tentry.userID.instance,
877 ntohl(okeys.keys[i].version), &k);
882 if (++nfound > maxCachedKeys)
883 return KADATABASEINCONSISTENT;
888 update_admin_count(struct ubik_trans *tt, int delta)
893 cheader.admin_accounts = htonl(ntohl(cheader.admin_accounts) + delta);
894 to = DOFFSET(0, &cheader, &cheader.admin_accounts);
896 kawrite(tt, to, (char *)&cheader.admin_accounts, sizeof(afs_int32));
903 index_OK(afs_int32 index)
905 if ((index < sizeof(cheader)) || (index >= ntohl(cheader.eofPtr))
906 || ((index - sizeof(cheader)) % sizeof(kaentry) != 0))
911 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
914 name_instance_legal(char *name, char *instance)
918 /* No string checks apply anymore. The international people want to use full 8
919 bit ascii without problems. */
921 code = (strlen(name) < MAXKTCNAMELEN)
922 && (strlen(instance) < MAXKTCNAMELEN);
924 map = LEGALCHARS; /* permitted chars, instance allows <period> */
925 code = (strlen(name) > 0) && string_legal(instance, map)
926 && string_legal(name, map + 1);
929 dynamic_statistics.string_checks++;
935 string_legal(char *str, char *map)
940 if (slen >= MAXKTCNAMELEN)
941 return 0; /* with trailing null must fit in data base */
942 return (slen == strspn(str, map)); /* strspn returns length(str) if all chars in map */