Merge branch 'upstream'
[debian/sudo] / sudo.c
diff --git a/sudo.c b/sudo.c
index aec3acf6bc6f2d74b48fe96d8f29077fae528bc3..f051d5ae9455ad766c4a7093f82ae67855074765 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -526,6 +526,7 @@ init_vars(sudo_mode, envp)
      * "host" is the (possibly fully-qualified) hostname and
      * "shost" is the unqualified form of the hostname.
      */
+    sudo_user.host_fqdn_queried = FALSE;
     nohostname = gethostname(thost, sizeof(thost));
     if (nohostname)
        user_host = user_shost = "localhost";
@@ -535,13 +536,7 @@ init_vars(sudo_mode, envp)
            /* Defer call to set_fqdn() until log_error() is safe. */
            user_shost = user_host;
        } else {
-           if ((p = strchr(user_host, '.'))) {
-               *p = '\0';
-               user_shost = estrdup(user_host);
-               *p = '.';
-           } else {
-               user_shost = user_host;
-           }
+           user_shost = user_host;
        }
     }
 
@@ -1217,6 +1212,35 @@ set_fqdn()
     } else {
        user_shost = user_host;
     }
+    sudo_user.host_fqdn_queried = TRUE;
+}
+
+/*
+ * Get passwd entry for the user we are going to run commands as.
+ * By default, this is "root".  Updates runas_pw as a side effect.
+ */
+int
+set_runaspw(user)
+    char *user;
+{
+    if (runas_pw != NULL) {
+       if (user_runas != &def_runas_default)
+           return(TRUE);               /* don't override -u option */
+       efree(runas_pw);
+    }
+    if (*user == '#') {
+       runas_pw = sudo_getpwuid(atoi(user + 1));
+       if (runas_pw == NULL) {
+           runas_pw = emalloc(sizeof(struct passwd));
+           (void) memset((VOID *)runas_pw, 0, sizeof(struct passwd));
+           runas_pw->pw_uid = atoi(user + 1);
+       }
+    } else {
+       runas_pw = sudo_getpwnam(user);
+       if (runas_pw == NULL)
+           log_error(NO_MAIL|MSG_ONLY, "no passwd entry for %s!", user);
+    }
+    return(TRUE);
 }
 
 /*