krb5_error_code krb5_ktsrvint_open(krb5_context context, krb5_keytab id) { KTFILEP(id) = fopen(KTFILENAME(id), READ_MODE); if (!KTFILEP(id)) return errno; return 0; }
krb5_error_code krb5_ktsrvint_close(krb5_context context, krb5_keytab id) { if (!KTFILEP(id)) return 0; (void) fclose(KTFILEP(id)); KTFILEP(id) = 0; return 0; }
krb5_error_code KRB5_CALLCONV krb5_ktsrvtab_get_next(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry, krb5_kt_cursor *cursor) { long *fileoff = (long *)*cursor; krb5_keytab_entry cur_entry; krb5_error_code kerror; if (fseek(KTFILEP(id), *fileoff, 0) == -1) return KRB5_KT_END; if ((kerror = krb5_ktsrvint_read_entry(context, id, &cur_entry))) return kerror; *fileoff = ftell(KTFILEP(id)); *entry = cur_entry; return 0; }
krb5_error_code krb5_ktsrvint_read_entry(krb5_context context, krb5_keytab id, krb5_keytab_entry *ret_entry) { FILE *fp; char name[SNAME_SZ], instance[INST_SZ], realm[REALM_SZ]; unsigned char key[8]; int vno; krb5_error_code kerror; /* Read in an entry from the srvtab file. */ fp = KTFILEP(id); kerror = read_field(fp, name, sizeof(name)); if (kerror != 0) return kerror; kerror = read_field(fp, instance, sizeof(instance)); if (kerror != 0) return kerror; kerror = read_field(fp, realm, sizeof(realm)); if (kerror != 0) return kerror; vno = getc(fp); if (vno == EOF) return KRB5_KT_END; if (fread(key, 1, sizeof(key), fp) != sizeof(key)) return KRB5_KT_END; /* Fill in ret_entry with the data we read. Everything maps well * except for the timestamp, which we don't have a value for. For * now we just set it to 0. */ memset(ret_entry, 0, sizeof(*ret_entry)); ret_entry->magic = KV5M_KEYTAB_ENTRY; kerror = krb5_425_conv_principal(context, name, instance, realm, &ret_entry->principal); if (kerror != 0) return kerror; ret_entry->vno = vno; ret_entry->timestamp = 0; ret_entry->key.enctype = ENCTYPE_DES_CBC_CRC; ret_entry->key.magic = KV5M_KEYBLOCK; ret_entry->key.length = sizeof(key); ret_entry->key.contents = malloc(sizeof(key)); if (!ret_entry->key.contents) { krb5_free_principal(context, ret_entry->principal); return ENOMEM; } memcpy(ret_entry->key.contents, key, sizeof(key)); return 0; }
krb5_error_code KRB5_CALLCONV krb5_ktsrvtab_start_seq_get(krb5_context context, krb5_keytab id, krb5_kt_cursor *cursorp) { krb5_error_code retval; long *fileoff; if ((retval = krb5_ktsrvint_open(context, id))) return retval; if (!(fileoff = (long *)malloc(sizeof(*fileoff)))) { krb5_ktsrvint_close(context, id); return ENOMEM; } *fileoff = ftell(KTFILEP(id)); *cursorp = (krb5_kt_cursor)fileoff; return 0; }