Imported Debian patch 1.6.8p12-2
[debian/sudo] / sudo.c
diff --git a/sudo.c b/sudo.c
index 3313b000cfbccef452062bd86df1d5dd51e19db6..52adaf14ca19aa4be63ccf5842b6747fdaad2067 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -510,22 +510,18 @@ init_vars(sudo_mode)
      * "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";
     else {
        user_host = estrdup(thost);
-       if (def_fqdn) {
-           /* Defer call to set_fqdn() until log_error() is safe. */
-           user_shost = user_host;
+       if ((p = strchr(user_host, '.'))) {
+           *p = '\0';
+           user_shost = estrdup(user_host);
+           *p = '.';
        } else {
-           if ((p = strchr(user_host, '.'))) {
-               *p = '\0';
-               user_shost = estrdup(user_host);
-               *p = '.';
-           } else {
-               user_shost = user_host;
-           }
+           user_shost = user_host;
        }
     }
 
@@ -566,12 +562,12 @@ init_vars(sudo_mode)
 
     /* It is now safe to use log_error() and set_perms() */
 
-    if (def_fqdn)
-       set_fqdn();                     /* may call log_error() */
-
     if (nohostname)
        log_error(USE_ERRNO|MSG_ONLY, "can't get hostname");
 
+    /* We don't query FQDN yet, it might get disabled later. Querying is done
+     * when host matching is executed and def_fqdn still true */
+
     set_runaspw(*user_runas);          /* may call log_error() */
     if (*user_runas[0] == '#' && runas_pw->pw_name && runas_pw->pw_name[0])
        *user_runas = estrdup(runas_pw->pw_name);
@@ -691,6 +687,8 @@ parse_args(argc, argv)
        return(rval);
     }
 
+    /* New default: reset the environment */
+    def_env_reset = TRUE;
     while (NewArgc > 0 && NewArgv[0][0] == '-') {
        if (NewArgv[0][1] != '\0' && NewArgv[0][2] != '\0')
            warnx("please use single character options");
@@ -1010,6 +1008,11 @@ set_fqdn()
     struct hostent *hp;
     char *p;
 
+    if (!def_fqdn || sudo_user.host_fqdn_queried) {
+       /* Only querying just once is good enough */
+       return;
+    }
+
     if (!(hp = gethostbyname(user_host))) {
        log_error(MSG_ONLY|NO_EXIT,
            "unable to lookup %s via gethostbyname()", user_host);
@@ -1026,6 +1029,7 @@ set_fqdn()
     } else {
        user_shost = user_host;
     }
+    sudo_user.host_fqdn_queried = TRUE;
 }
 
 /*