/* * Get the host base service name for the changepw principal. Returns * KADM5_OK on success. Caller must free the storage allocated for * host_service_name. */ kadm5_ret_t kadm5_get_cpw_host_srv_name(krb5_context context, const char *realm, char **host_service_name) { kadm5_ret_t ret; char *name; char *host; /* * First try to find the kpasswd server, after all we are about to * try to change our password. If this fails then try admin_server. */ if (ret = kadm5_get_kpasswd(context, realm, &host)) { if (ret = kadm5_get_master(context, realm, &host)) return (ret); } name = malloc(strlen(KADM5_CHANGEPW_HOST_SERVICE) + strlen(host) + 2); if (name == NULL) { free(host); return (ENOMEM); } sprintf(name, "%s@%s", KADM5_CHANGEPW_HOST_SERVICE, host); free(host); *host_service_name = name; return (KADM5_OK); }
/* * Solaris Kerberos: * Try to determine if this is the master KDC for a given realm */ kadm5_ret_t kadm5_is_master(krb5_context context, const char *realm, krb5_boolean *is_master) { kadm5_ret_t ret; char *admin_host = NULL; krb5_address **tmp_addr, **master_addr = NULL; krb5_address **local_addr = NULL; if (is_master) *is_master = FALSE; else return (KADM5_FAILURE); /* Locate the master KDC */ if (ret = kadm5_get_master(context, realm, &admin_host)) return (ret); if (ret = krb5_os_hostaddr(context, admin_host, &master_addr)) { free(admin_host); return (ret); } /* Get the local addresses */ if (ret = krb5_os_localaddr(context, &local_addr)) { krb5_free_addresses(context, master_addr); free(admin_host); return (ret); } /* Compare them */ for (tmp_addr = master_addr; *tmp_addr; tmp_addr++) { if (krb5_address_search(context, *tmp_addr, local_addr)) { *is_master = TRUE; break; } } krb5_free_addresses(context, local_addr); krb5_free_addresses(context, master_addr); free(admin_host); return (KADM5_OK); }
/* * Get the host base service name for the kiprop principal. Returns * KADM5_OK on success. Caller must free the storage allocated for * host_service_name. */ kadm5_ret_t kiprop_get_adm_host_srv_name(krb5_context context, const char *realm, char **host_service_name) { kadm5_ret_t ret; char *name; char *host; if (ret = kadm5_get_master(context, realm, &host)) return (ret); if (asprintf(&name, "%s@%s", KIPROP_SVC_NAME, host) < 0) { free(host); return (ENOMEM); } free(host); *host_service_name = name; return (KADM5_OK); }
/* * Get the host base service name for the kiprop principal. Returns * KADM5_OK on success. Caller must free the storage allocated * for host_service_name. */ kadm5_ret_t kadm5_get_kiprop_host_srv_name(krb5_context context, const char *realm, char **host_service_name) { kadm5_ret_t ret; char *name; char *host; if (ret = kadm5_get_master(context, realm, &host)) return (ret); name = malloc(strlen(KADM5_KIPROP_HOST_SERVICE) + strlen(host) + 2); if (name == NULL) { free(host); return (ENOMEM); } sprintf(name, "%s@%s", KADM5_KIPROP_HOST_SERVICE, host); free(host); *host_service_name = name; return (KADM5_OK); }