* kprop.c: Call krb5_sname_to_principal rather than doing the OS calls.
authorRichard Basch <probe@mit.edu>
Tue, 5 Mar 1996 17:31:01 +0000 (17:31 +0000)
committerRichard Basch <probe@mit.edu>
Tue, 5 Mar 1996 17:31:01 +0000 (17:31 +0000)
  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

src/slave/ChangeLog
src/slave/kprop.c
src/slave/kpropd.c

index 4024559681e4473ddf6df4d5879d10e29fb757ac..fe6c8bacfffdcad39d6e4a8f3d90a8e9b83d65d6 100644 (file)
@@ -1,3 +1,18 @@
+Tue Mar  5 12:20:00 1996  Richard Basch  <basch@lehman.com>
+
+       * 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  <eichin@cygnus.com>
 
        * kprop.h (KPROP_SRVTAB, KPROP_DEFAULT_FILE, KPROPD_DEFAULT_FILE,
index 0243b8d33a18ad64d6fb7824fe96b922efe720a6..3166dfffe27b0e840bafc4768f7a6089abae9377 100644 (file)
@@ -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);
index 7258d7c89475b14264cf47f41bd3f78f74141b10..75e21fde24b0b23d04cedbf22221caa9bb288d29 100644 (file)
@@ -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);
        }
        /*