#include "kuser_locl.h"
#include <config.h>
#include "kcc-commands.h"
static const struct {
char *name;
int type;
} types[] = {
{ "kdc", KRB5_KRBHST_KDC },
{ "kadmin", KRB5_KRBHST_ADMIN },
{ "changepw", KRB5_KRBHST_CHANGEPW },
{ "krb524", KRB5_KRBHST_KRB524 },
{ "kkdcp", KRB5_KRBHST_KKDCP }
};
int
kdc(struct kdc_options *opt, int argc, char **argv)
{
krb5_krbhst_handle handle;
int type = KRB5_KRBHST_KDC;
char host[MAXHOSTNAMELEN];
krb5_error_code ret;
int first_realm = 1;
size_t n;
int i;
if (argc == 0) {
printf("give at least on realm\n");
return 1;
}
if (opt->type_string) {
for (n = 0; n < sizeof(types)/sizeof(types[0]); n++) {
if (strcasecmp(types[n].name, opt->type_string) == 0)
type = types[n].type;
}
if (n == sizeof(types)/sizeof(types[0])) {
printf("unknown type: %s\nAvailaile types are: \n", opt->type_string);
for (n = 0; n < sizeof(types)/sizeof(types[0]); n++)
printf("%s ", types[n].name);
printf("\n");
return 1;
}
}
if (opt->json_flag)
printf("{");
for (i = 0; i < argc; i++) {
const char *realm = argv[i];
ret = krb5_krbhst_init(kcc_context, realm, type, &handle);
if (ret) {
krb5_warn(kcc_context, ret, "krb5_krbhst_init");
return 1;
}
if (opt->json_flag) {
int first = 1;
printf("%s\n\t\"%s\" = [ ", first_realm ? "" : ",", realm);
first_realm = 0;
while(krb5_krbhst_next_as_string(kcc_context, handle, host, sizeof(host)) == 0) {
printf("%s\n\t\t\"%s\"", first ? "" : ",", host);
first = 0;
}
printf("\n\t]");
} else {
printf("[realms]\n");
printf("\t%s = {\n", realm);
while(krb5_krbhst_next_as_string(kcc_context, handle, host, sizeof(host)) == 0)
printf("\t\tkdc = %s\n", host);
printf("\t}\n");
}
krb5_krbhst_free(kcc_context, handle);
}
if (opt->json_flag)
printf("\n}\n");
return 0;
}