static krb5_error_code find_db (krb5_context context, char **dbname, char **mkey, krb5_const_principal principal) { krb5_const_realm realm = krb5_principal_get_realm(context, principal); krb5_error_code ret; struct hdb_dbinfo *head, *dbinfo = NULL; *dbname = *mkey = NULL; ret = hdb_get_dbinfo(context, &head); if (ret) return ret; while ((dbinfo = hdb_dbinfo_get_next(head, dbinfo)) != NULL) { const char *p = hdb_dbinfo_get_realm(context, dbinfo); if (p && strcmp (realm, p) == 0) { p = hdb_dbinfo_get_dbname(context, dbinfo); if (p) *dbname = strdup(p); p = hdb_dbinfo_get_mkey_file(context, dbinfo); if (p) *mkey = strdup(p); break; } } hdb_free_dbinfo(context, &head); if (*dbname == NULL) *dbname = strdup(HDB_DEFAULT_DB); return 0; }
static kadm5_ret_t find_db_spec(kadm5_server_context *ctx) { krb5_context context = ctx->context; struct hdb_dbinfo *info, *d; krb5_error_code ret; if (ctx->config.realm) { /* fetch the databases */ ret = hdb_get_dbinfo(context, &info); if (ret) return ret; d = NULL; while ((d = hdb_dbinfo_get_next(info, d)) != NULL) { const char *p = hdb_dbinfo_get_realm(context, d); /* match default (realm-less) */ if(p != NULL && strcmp(ctx->config.realm, p) != 0) continue; p = hdb_dbinfo_get_dbname(context, d); if (p) ctx->config.dbname = strdup(p); p = hdb_dbinfo_get_acl_file(context, d); if (p) ctx->config.acl_file = strdup(p); p = hdb_dbinfo_get_mkey_file(context, d); if (p) ctx->config.stash_file = strdup(p); p = hdb_dbinfo_get_log_file(context, d); if (p) ctx->log_context.log_file = strdup(p); break; } hdb_free_dbinfo(context, &info); } /* If any of the values was unset, pick up the default value */ if (ctx->config.dbname == NULL) ctx->config.dbname = strdup(hdb_default_db(context)); if (ctx->config.acl_file == NULL) asprintf(&ctx->config.acl_file, "%s/kadmind.acl", hdb_db_dir(context)); if (ctx->config.stash_file == NULL) asprintf(&ctx->config.stash_file, "%s/m-key", hdb_db_dir(context)); if (ctx->log_context.log_file == NULL) asprintf(&ctx->log_context.log_file, "%s/log", hdb_db_dir(context)); #ifndef NO_UNIX_SOCKETS set_socket_name(context, &ctx->log_context.socket_name); #else set_socket_info(context, &ctx->log_context.socket_info); #endif return 0; }
krb5_error_code krb5_kdc_set_dbinfo(krb5_context context, struct krb5_kdc_configuration *c) { struct hdb_dbinfo *info, *d; krb5_error_code ret; int i; /* fetch the databases */ ret = hdb_get_dbinfo(context, &info); if (ret) return ret; d = NULL; while ((d = hdb_dbinfo_get_next(info, d)) != NULL) { ret = add_db(context, c, hdb_dbinfo_get_dbname(context, d), hdb_dbinfo_get_mkey_file(context, d)); if (ret) goto out; kdc_log(context, c, 0, "label: %s", hdb_dbinfo_get_label(context, d)); kdc_log(context, c, 0, "\tdbname: %s", hdb_dbinfo_get_dbname(context, d)); kdc_log(context, c, 0, "\tmkey_file: %s", hdb_dbinfo_get_mkey_file(context, d)); kdc_log(context, c, 0, "\tacl_file: %s", hdb_dbinfo_get_acl_file(context, d)); } hdb_free_dbinfo(context, &info); return 0; out: for (i = 0; i < c->num_db; i++) if (c->db[i] && c->db[i]->hdb_destroy) (*c->db[i]->hdb_destroy)(context, c->db[i]); c->num_db = 0; free(c->db); c->db = NULL; hdb_free_dbinfo(context, &info); return ret; }
int main(int argc, char **argv) { struct hdb_dbinfo *info, *d; krb5_context context; int ret, o = 0; setprogname(argv[0]); if(getarg(args, num_args, argc, argv, &o)) krb5_std_usage(1, args, num_args); if(help_flag) krb5_std_usage(0, args, num_args); if(version_flag){ print_version(NULL); exit(0); } ret = krb5_init_context(&context); if (ret) errx (1, "krb5_init_context failed: %d", ret); ret = hdb_get_dbinfo(context, &info); if (ret) krb5_err(context, 1, ret, "hdb_get_dbinfo"); d = NULL; while ((d = hdb_dbinfo_get_next(info, d)) != NULL) { const char *s; s = hdb_dbinfo_get_label(context, d); printf("label: %s\n", s ? s : "no label"); s = hdb_dbinfo_get_realm(context, d); printf("\trealm: %s\n", s ? s : "no realm"); s = hdb_dbinfo_get_dbname(context, d); printf("\tdbname: %s\n", s ? s : "no dbname"); s = hdb_dbinfo_get_mkey_file(context, d); printf("\tmkey_file: %s\n", s ? s : "no mkey file"); s = hdb_dbinfo_get_acl_file(context, d); printf("\tacl_file: %s\n", s ? s : "no acl file"); } hdb_free_dbinfo(context, &info); krb5_free_context(context); return 0; }