[1203] in Kerberos-V5-bugs
krb5b4pl3: slave/kprop.c: use krb5_sname_to_principal
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Sun Mar 19 20:49:28 1995
From: "Jonathan I. Kamens" <jik@cam.ov.com>
Date: Sun, 19 Mar 1995 20:52:44 -0500
To: krb5-bugs@MIT.EDU
kprop should use krb5_sname_to_principal to figur eout what principals
to use, rather than duplicating its efforts.
Here's a patch:
--- slave/kprop.c 1995/03/13 20:48:57 1.2
+++ slave/kprop.c 1995/03/13 20:53:16 1.3
@@ -63,7 +63,7 @@
char *realm = 0;
char *file = KPROP_DEFAULT_FILE;
-krb5_principal my_principal; /* The Kerberos principal we'll be */
+krb5_principal my_principal; /* The Kerberos principal we'll be */
/* running under, initialized in */
/* get_tickets() */
krb5_ccache ccache; /* Credentials cache which we'll be using */
@@ -175,10 +175,7 @@
void get_tickets()
{
- char my_host_name[MAXHOSTNAMELEN];
char buf[BUFSIZ];
- char *cp;
- struct hostent *hp;
krb5_address **my_addresses;
krb5_error_code retval;
static char tkstring[] = "/tmp/kproptktXXXXXX";
@@ -186,27 +183,21 @@
/*
* Figure out what tickets we'll be using to send stuff
*/
- if (gethostname (my_host_name, sizeof(my_host_name)) != 0) {
- com_err(progname, errno, "while getting my hostname");
+ if (retval = krb5_sname_to_principal(0, 0, KRB5_NT_SRV_HST,
+ &my_principal)) {
+ com_err (progname, retval, "when getting default service name for local host",buf);
exit(1);
}
- /* get canonicalized service instance name */
- if (!(hp = gethostbyname(my_host_name))) {
- fprintf(stderr, "Couldn't get my cannonicalized host name!\n");
- exit(1);
- }
- for (cp=hp->h_name; *cp; cp++)
- if (isupper(*cp))
- *cp = tolower(*cp);
- if (realm)
- sprintf(buf, "host/%s@%s", hp->h_name, realm);
- else
- sprintf(buf, "host/%s", hp->h_name);
- if (retval = krb5_parse_name(buf, &my_principal)) {
- com_err (progname, retval, "when parsing name %s",buf);
- exit(1);
+ if (realm) {
+ krb5_xfree(krb5_princ_realm(my_principal)->data);
+ krb5_princ_set_realm_length(my_principal, strlen(realm));
+ krb5_princ_set_realm_data(my_principal, strdup(realm));
+ if (! krb5_princ_realm(my_principal)->data) {
+ com_err(progname, ENOMEM,
+ "while setting client realm");
+ exit(1);
+ }
}
-
/*
* Initialize cache file which we're going to be using
*/
@@ -225,34 +216,32 @@
/*
* Get the tickets we'll need.
- *
- * Construct the principal name for the slave host.
*/
+
memset((char *)&my_creds, 0, sizeof(my_creds));
- if (!(hp = gethostbyname(slave_host))) {
- fprintf(stderr,
- "Couldn't get cannonicalized name for slave\n");
- exit(1);
- }
- for (cp=hp->h_name; *cp; cp++)
- if (isupper(*cp))
- *cp = tolower(*cp);
- if (!(slave_host = malloc(strlen(hp->h_name) + 1))) {
- com_err(progname, ENOMEM,
- "while allocate space for canonicalized slave host");
- exit(1);
- }
- strcpy(slave_host, hp->h_name);
- if (realm)
- sprintf(buf, "%s/%s@%s", KPROP_SERVICE_NAME, slave_host,
- realm);
- else
- sprintf(buf, "%s/%s", KPROP_SERVICE_NAME, hp->h_name);
- if (retval = krb5_parse_name(buf, &my_creds.server)) {
+
+ /*
+ * Construct the principal name for the slave host.
+ */
+ if (retval = krb5_sname_to_principal(slave_host, KPROP_SERVICE_NAME,
+ KRB5_NT_SRV_HST,
+ &my_creds.server)) {
com_err(progname, retval,
- "while parsing slave principal name");
+ "while getting service principal %s/%s",
+ KPROP_SERVICE_NAME, slave_host);
exit(1);
}
+ if (realm) {
+ krb5_xfree(krb5_princ_realm(my_creds.server)->data);
+ krb5_princ_set_realm_length(my_creds.server, strlen(realm));
+ krb5_princ_set_realm_data(my_creds.server, strdup(realm));
+ if (! krb5_princ_realm(my_creds.server)->data) {
+ com_err(progname, ENOMEM,
+ "while setting server realm");
+ exit(1);
+ }
+ }
+
/*
* Now fill in the client....
*/