}
}
-/* Runs krb5_sname_to_principal with a substitute realm
- * Duplicated in kpropd.c, sharing TBD */
-static krb5_error_code
-sn2princ_with_realm(krb5_context context, const char *hostname,
- const char *sname, krb5_int32 type, const char *rrealm,
- krb5_principal *princ_out)
-{
- krb5_error_code ret;
- krb5_principal princ = NULL;
-
- *princ_out = NULL;
-
- if (rrealm == NULL)
- return EINVAL;
-
- ret = krb5_sname_to_principal(context, hostname, sname, type, &princ);
- if (ret)
- return ret;
-
- ret = krb5_set_principal_realm(context, princ, rrealm);
- if (ret) {
- krb5_free_principal(context, princ);
- return ret;
- }
-
- *princ_out = princ;
- return 0;
-}
-
static void
get_tickets(krb5_context context)
{
krb5_principal server_princ = NULL;
/* Figure out what tickets we'll be using to send. */
- retval = sn2princ_with_realm(context, NULL, NULL, KRB5_NT_SRV_HST, realm,
- &my_principal);
+ retval = sn2princ_realm(context, NULL, KPROP_SERVICE_NAME, realm,
+ &my_principal);
if (retval) {
com_err(progname, errno, _("while setting client principal name"));
exit(1);
/* Construct the principal name for the slave host. */
memset(&creds, 0, sizeof(creds));
- retval = sn2princ_with_realm(context, slave_host, KPROP_SERVICE_NAME,
- KRB5_NT_SRV_HST, realm, &server_princ);
+ retval = sn2princ_realm(context, slave_host, KPROP_SERVICE_NAME, realm,
+ &server_princ);
if (retval) {
com_err(progname, errno, _("while setting server principal name"));
exit(1);
int sockaddr2krbaddr(krb5_context context, int family, struct sockaddr *sa,
krb5_address **dest);
+
+krb5_error_code
+sn2princ_realm(krb5_context context, const char *hostname, const char *sname,
+ const char *realm, krb5_principal *princ_out);
return krb5_copy_addr(context, &addr, dest);
}
+
+/* Construct a host-based principal, similar to krb5_sname_to_principal() but
+ * with a specified realm. */
+krb5_error_code
+sn2princ_realm(krb5_context context, const char *hostname, const char *sname,
+ const char *realm, krb5_principal *princ_out)
+{
+ krb5_error_code ret;
+ char *canonhost, localname[MAXHOSTNAMELEN];
+
+ *princ_out = NULL;
+ assert(sname != NULL && realm != NULL);
+
+ /* If hostname is NULL, use the local hostname. */
+ if (hostname == NULL) {
+ if (gethostname(localname, MAXHOSTNAMELEN) != 0)
+ return SOCKET_ERRNO;
+ hostname = localname;
+ }
+
+ ret = krb5_expand_hostname(context, hostname, &canonhost);
+ if (ret)
+ return ret;
+
+ ret = krb5_build_principal(context, princ_out, strlen(realm), realm, sname,
+ canonhost, (char *)NULL);
+ krb5_free_string(context, canonhost);
+ if (!ret)
+ (*princ_out)->type = KRB5_NT_SRV_HST;
+ return ret;
+}
return (status == RPC_SUCCESS) ? &clnt_res : NULL;
}
-/* Runs krb5_sname_to_principal with a substitute realm.
- * Duplicated in kprop.c, sharing TBD */
-static krb5_error_code
-sn2princ_with_realm(krb5_context context, const char *hostname,
- const char *sname, krb5_int32 type, const char *rrealm,
- krb5_principal *princ_out)
-{
- krb5_error_code ret;
- krb5_principal princ = NULL;
-
- *princ_out = NULL;
-
- if (rrealm == NULL)
- return EINVAL;
-
- ret = krb5_sname_to_principal(context, hostname, sname, type, &princ);
- if (ret)
- return ret;
-
- ret = krb5_set_principal_realm(context, princ, rrealm);
- if (ret) {
- krb5_free_principal(context, princ);
- return ret;
- }
-
- *princ_out = princ;
- return 0;
-}
/*
* Beg for incrementals from the KDC.
*
}
}
- retval = sn2princ_with_realm(kpropd_context, NULL, KIPROP_SVC_NAME,
- KRB5_NT_SRV_HST, realm, &iprop_svc_principal);
+ retval = sn2princ_realm(kpropd_context, NULL, KIPROP_SVC_NAME, realm,
+ &iprop_svc_principal);
if (retval) {
com_err(progname, retval,
_("while trying to construct host service principal"));
}
/* Construct service name from local hostname. */
- retval = sn2princ_with_realm(kpropd_context, NULL, KPROP_SERVICE_NAME,
- KRB5_NT_SRV_HST, realm, &server);
+ retval = sn2princ_realm(kpropd_context, NULL, KPROP_SERVICE_NAME, realm,
+ &server);
if (retval) {
com_err(progname, retval,
_("while trying to construct my service name"));