|
|
1.1 ! root 1: /* ! 2: * $Source: /mit/kerberos/src/lib/kdb/RCS/krb_cache.c,v $ ! 3: * $Author: jon $ ! 4: * ! 5: * Copyright 1988 by the Massachusetts Institute of Technology. ! 6: * ! 7: * For copying and distribution information, please see the file ! 8: * <mit-copyright.h>. ! 9: * ! 10: * This is where a cache would be implemented, if it were necessary. ! 11: */ ! 12: ! 13: #ifndef lint ! 14: static char rcsid_krb_cache_c[] = ! 15: "$Header: krb_cache.c,v 4.5 89/01/24 18:12:34 jon Exp $"; ! 16: #endif lint ! 17: ! 18: #include <mit-copyright.h> ! 19: #include <stdio.h> ! 20: #include <sys/types.h> ! 21: #include <netinet/in.h> ! 22: #include <sys/uio.h> ! 23: #include <sys/time.h> ! 24: #include <sys/resource.h> ! 25: #include <strings.h> ! 26: #include <des.h> ! 27: #include <krb.h> ! 28: #include <krb_db.h> ! 29: ! 30: extern char *strncpy(); ! 31: ! 32: #ifdef DEBUG ! 33: extern int debug; ! 34: extern long kerb_debug; ! 35: #endif ! 36: static init = 0; ! 37: ! 38: /* ! 39: * initialization routine for cache ! 40: */ ! 41: ! 42: int ! 43: kerb_cache_init() ! 44: { ! 45: init = 1; ! 46: return (0); ! 47: } ! 48: ! 49: /* ! 50: * look up a principal in the cache returns number of principals found ! 51: */ ! 52: ! 53: int ! 54: kerb_cache_get_principal(serv, inst, principal, max) ! 55: char *serv; /* could have wild card */ ! 56: char *inst; /* could have wild card */ ! 57: Principal *principal; ! 58: unsigned int max; /* max number of name structs to return */ ! 59: ! 60: { ! 61: int found = 0; ! 62: u_long i; ! 63: ! 64: if (!init) ! 65: kerb_cache_init(); ! 66: #ifdef DEBUG ! 67: if (kerb_debug & 2) ! 68: fprintf(stderr, "cache_get_principal for %s %s max = %d\n", ! 69: serv, inst, max); ! 70: #endif DEBUG ! 71: ! 72: #ifdef DEBUG ! 73: if (kerb_debug & 2) { ! 74: if (found) { ! 75: fprintf(stderr, "cache get %s %s found %s %s sid = %d\n", ! 76: serv, inst, principal->name, principal->instance); ! 77: } else { ! 78: fprintf(stderr, "cache %s %s not found\n", serv, ! 79: inst); ! 80: } ! 81: } ! 82: #endif ! 83: return (found); ! 84: } ! 85: ! 86: /* ! 87: * insert/replace a principal in the cache returns number of principals ! 88: * inserted ! 89: */ ! 90: ! 91: int ! 92: kerb_cache_put_principal(principal, max) ! 93: Principal *principal; ! 94: unsigned int max; /* max number of principal structs to ! 95: * insert */ ! 96: ! 97: { ! 98: int found = 0; ! 99: u_long i; ! 100: int count = 0; ! 101: ! 102: if (!init) ! 103: kerb_cache_init(); ! 104: ! 105: #ifdef DEBUG ! 106: if (kerb_debug & 2) { ! 107: fprintf(stderr, "kerb_cache_put_principal max = %d", ! 108: max); ! 109: } ! 110: #endif ! 111: ! 112: for (i = 0; i < max; i++) { ! 113: #ifdef DEBUG ! 114: if (kerb_debug & 2) ! 115: fprintf(stderr, "\n %s %s", ! 116: principal->name, principal->instance); ! 117: #endif ! 118: /* DO IT */ ! 119: count++; ! 120: principal++; ! 121: } ! 122: return count; ! 123: } ! 124: ! 125: /* ! 126: * look up a dba in the cache returns number of dbas found ! 127: */ ! 128: ! 129: int ! 130: kerb_cache_get_dba(serv, inst, dba, max) ! 131: char *serv; /* could have wild card */ ! 132: char *inst; /* could have wild card */ ! 133: Dba *dba; ! 134: unsigned int max; /* max number of name structs to return */ ! 135: ! 136: { ! 137: int found = 0; ! 138: u_long i; ! 139: ! 140: if (!init) ! 141: kerb_cache_init(); ! 142: ! 143: #ifdef DEBUG ! 144: if (kerb_debug & 2) ! 145: fprintf(stderr, "cache_get_dba for %s %s max = %d\n", ! 146: serv, inst, max); ! 147: #endif ! 148: ! 149: #ifdef DEBUG ! 150: if (kerb_debug & 2) { ! 151: if (found) { ! 152: fprintf(stderr, "cache get %s %s found %s %s sid = %d\n", ! 153: serv, inst, dba->name, dba->instance); ! 154: } else { ! 155: fprintf(stderr, "cache %s %s not found\n", serv, inst); ! 156: } ! 157: } ! 158: #endif ! 159: return (found); ! 160: } ! 161: ! 162: /* ! 163: * insert/replace a dba in the cache returns number of dbas inserted ! 164: */ ! 165: ! 166: int ! 167: kerb_cache_put_dba(dba, max) ! 168: Dba *dba; ! 169: unsigned int max; /* max number of dba structs to insert */ ! 170: ! 171: { ! 172: int found = 0; ! 173: u_long i; ! 174: int count = 0; ! 175: ! 176: if (!init) ! 177: kerb_cache_init(); ! 178: #ifdef DEBUG ! 179: if (kerb_debug & 2) { ! 180: fprintf(stderr, "kerb_cache_put_dba max = %d", max); ! 181: } ! 182: #endif ! 183: for (i = 0; i < max; i++) { ! 184: #ifdef DEBUG ! 185: if (kerb_debug & 2) ! 186: fprintf(stderr, "\n %s %s", ! 187: dba->name, dba->instance); ! 188: #endif ! 189: /* DO IT */ ! 190: count++; ! 191: dba++; ! 192: } ! 193: return count; ! 194: } ! 195:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.