summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sudo.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/sudo.c b/sudo.c
index 1e2ab922f..a62f1cd96 100644
--- a/sudo.c
+++ b/sudo.c
@@ -304,9 +304,6 @@ main(argc, argv, envp)
if (!update_defaults(SETDEF_RUNAS))
log_error(NO_STDERR|NO_EXIT, "problem with defaults entries");
- if (def_fqdn)
- set_fqdn(); /* deferred until after sudoers is parsed */
-
/* Set login class if applicable. */
set_loginclass(sudo_user.pw);
@@ -628,17 +625,22 @@ init_vars(sudo_mode, envp)
* "shost" is the unqualified form of the hostname.
*/
nohostname = gethostname(thost, sizeof(thost));
- if (nohostname) {
+ if (nohostname)
user_host = user_shost = "localhost";
- } else {
+ else {
thost[sizeof(thost) - 1] = '\0';
user_host = estrdup(thost);
- if ((p = strchr(user_host, '.'))) {
- *p = '\0';
- user_shost = estrdup(user_host);
- *p = '.';
- } else {
+ if (def_fqdn) {
+ /* 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;
+ }
}
}
@@ -717,6 +719,9 @@ init_vars(sudo_mode, envp)
user_ngroups = 0;
#endif
+ if (def_fqdn)
+ set_fqdn(); /* may call log_error() */
+
if (nohostname)
log_error(USE_ERRNO|MSG_ONLY, "can't get hostname");