From: Richard Basch Date: Tue, 5 Mar 1996 17:31:01 +0000 (+0000) Subject: * kprop.c: Call krb5_sname_to_principal rather than doing the OS calls. X-Git-Tag: krb5-1.0-beta6~405 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=66b60913edde7f4585f23955c804abf2117f881f;p=krb5.git * kprop.c: Call krb5_sname_to_principal rather than doing the OS calls. Removed a trailing ; that caused a spurious message to be printed even upon success. * kpropd.c: Call krb5_sname_to_principal rather than doing the OS calls. Open the lock file read-write, as required by POSIX. Downgrade the lock to a shared lock prior to the execution of kdb5_edit (it also tries to place a shared lock on the dump file). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7595 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/slave/ChangeLog b/src/slave/ChangeLog index 402455968..fe6c8bacf 100644 --- a/src/slave/ChangeLog +++ b/src/slave/ChangeLog @@ -1,3 +1,18 @@ +Tue Mar 5 12:20:00 1996 Richard Basch + + * kprop.c: Call krb5_sname_to_principal rather than doing the OS + specific calls; this also deals with site-specific hostname + munging that might have occurred. + Removed a trailing ; that caused a spurious message to be printed + even upon success. + + * kpropd.c: Call krb5_sname_to_principal rather than doing the OS + specific calls. + Open the lock file read-write, as required by + POSIX. + Downgrade the lock to a shared lock prior to the execution + of kdb5_edit (it also tries to place a shared lock on the dump file). + Wed Sep 13 23:53:19 1995 Mark Eichin * kprop.h (KPROP_SRVTAB, KPROP_DEFAULT_FILE, KPROPD_DEFAULT_FILE, diff --git a/src/slave/kprop.c b/src/slave/kprop.c index 0243b8d33..3166dfffe 100644 --- a/src/slave/kprop.c +++ b/src/slave/kprop.c @@ -213,26 +213,20 @@ void get_tickets(context) /* * 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"); - exit(1); + retval = krb5_sname_to_principal(context, NULL, NULL, + KRB5_NT_SRV_HST, &my_principal); + if (retval) { + com_err(progname, errno, "while setting client principal name"); + exit(1); } - /* get canonicalized service instance name */ - if (!(hp = gethostbyname(my_host_name))) { - fprintf(stderr, "Couldn't get my canonicalized 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(context, buf, &my_principal)) { - com_err (progname, retval, "when parsing name %s",buf); - exit(1); + if (realm) { + (void) krb5_xfree(krb5_princ_realm(context, my_principal)->data); + krb5_princ_set_realm_length(context, my_principal, strlen(realm)); + krb5_princ_set_realm_data(context, my_principal, strdup(realm)); } +#if 0 + krb5_princ_type(context, my_principal) = KRB5_NT_PRINCIPAL; +#endif /* * Initialize cache file which we're going to be using @@ -256,30 +250,19 @@ void get_tickets(context) * Construct the principal name for the slave host. */ memset((char *)&creds, 0, sizeof(creds)); - if (!(hp = gethostbyname(slave_host))) { - fprintf(stderr, - "Couldn't get canonicalized 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); + retval = krb5_sname_to_principal(context, + slave_host, KPROP_SERVICE_NAME, + KRB5_NT_SRV_HST, &creds.server); + if (retval) { + com_err(progname, errno, "while setting server principal name"); + 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(context, buf, &creds.server)) { - com_err(progname, retval, - "while parsing slave principal name"); - exit(1); + if (realm) { + (void) krb5_xfree(krb5_princ_realm(context, creds.server)->data); + krb5_princ_set_realm_length(context, creds.server, strlen(realm)); + krb5_princ_set_realm_data(context, creds.server, strdup(realm)); } + /* * Now fill in the client.... */ @@ -508,7 +491,7 @@ close_database(context, fd) int fd; { int err; - if (err = krb5_lock_file(context, fd, KRB5_LOCKMODE_UNLOCK)); + if (err = krb5_lock_file(context, fd, KRB5_LOCKMODE_UNLOCK)) com_err(progname, err, "while unlocking database '%s'", dbpathname); free(dbpathname); (void)close(fd); diff --git a/src/slave/kpropd.c b/src/slave/kpropd.c index 7258d7c89..75e21fde2 100644 --- a/src/slave/kpropd.c +++ b/src/slave/kpropd.c @@ -279,7 +279,7 @@ void doit(fd) exit(1); } omask = umask(077); - lock_fd = open(temp_file_name, O_RDONLY, 0600); + lock_fd = open(temp_file_name, O_RDWR|O_CREAT, 0600); (void) umask(omask); retval = krb5_lock_file(kpropd_context, lock_fd, KRB5_LOCKMODE_EXCLUSIVE|KRB5_LOCKMODE_DONTBLOCK); @@ -306,6 +306,12 @@ void doit(fd) temp_file_name, file); exit(1); } + retval = krb5_lock_file(kpropd_context, lock_fd, KRB5_LOCKMODE_SHARED); + if (retval) { + com_err(progname, retval, "while downgrading lock on '%s'", + temp_file_name); + exit(1); + } load_database(kpropd_context, kdb5_edit, file); retval = krb5_lock_file(kpropd_context, lock_fd, KRB5_LOCKMODE_UNLOCK); if (retval) { @@ -430,25 +436,12 @@ void PRS(argv) /* * Get my hostname, so we can construct my service name */ - if (gethostname (my_host_name, sizeof(my_host_name)) != 0) { - com_err(progname, errno, "while getting my hostname"); - exit(1); - } - 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, "%s/%s@%s", KPROP_SERVICE_NAME, hp->h_name, - realm); - else - sprintf(buf, "%s/%s", KPROP_SERVICE_NAME, hp->h_name); - if (retval = krb5_parse_name(kpropd_context, buf, &server)) { + retval = krb5_sname_to_principal(kpropd_context, + NULL, KPROP_SERVICE_NAME, + KRB5_NT_SRV_HST, &server); + if (retval) { com_err(progname, retval, - "While trying to parse %s for service name"); + "While trying to construct my service name"); exit(1); } /*