From: Todd C. Miller Date: Mon, 11 Mar 1996 19:05:55 +0000 (+0000) Subject: now uses shost even if not FQDN X-Git-Tag: SUDO_1_5_0~251 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=058a58a501e646b92af4d79634200a5b056c8cb4;p=sudo now uses shost even if not FQDN --- diff --git a/parse.yacc b/parse.yacc index f06a71d7f..23429a3fe 100644 --- a/parse.yacc +++ b/parse.yacc @@ -199,11 +199,7 @@ hostspec : ALL { (void) free($1); } | NAME { -#ifdef FQDN if (strcasecmp(shost, $1) == 0) -#else - if (strcasecmp(host, $1) == 0) -#endif /* FQDN */ host_matches = TRUE; (void) free($1); } diff --git a/sudo.c b/sudo.c index 2516f2c72..37e8386d8 100644 --- a/sudo.c +++ b/sudo.c @@ -140,9 +140,7 @@ char *cmnd = NULL; char *tty = NULL; char *prompt = PASSPROMPT; char host[MAXHOSTNAMELEN + 1]; -#ifdef FQDN -char shost[MAXHOSTNAMELEN + 1]; -#endif /*FQDN */ +char *shost; char cwd[MAXPATHLEN + 1]; struct stat cmnd_st; extern struct interface *interfaces; @@ -448,37 +446,37 @@ static void load_globals(sudo_mode) } /* - * load the host global variable from gethostname() - * and use gethostbyname() if we want it to be fully qualified. + * load the host global variable from gethostname() and use + * gethostbyname() if we want to be sure it is fully qualified. */ if ((gethostname(host, MAXHOSTNAMELEN))) { strcpy(host, "localhost"); log_error(GLOBAL_NO_HOSTNAME); inform_user(GLOBAL_NO_HOSTNAME); -#ifdef FQDN - } else { - if ((h_ent = gethostbyname(host)) == NULL) { - log_error(GLOBAL_HOST_UNREGISTERED); - } else { - strcpy(host, h_ent -> h_name); - if ((p = strchr(host, '.'))) { - *p = '\0'; - strcpy(shost, host); - *p = '.'; - } else { - strcpy(shost, host); - } - } - } -#else + exit(2); } +#ifdef FQDN + if ((h_ent = gethostbyname(host)) == NULL) + log_error(GLOBAL_HOST_UNREGISTERED); + else + strcpy(host, h_ent -> h_name); +#endif /* FQDN */ /* - * We don't want to return the fully quallified name unless FQDN is set + * "host" is the (possibly fully-qualified) hostname and + * "shost" is the unqualified form of the hostname. */ - if ((p = strchr(host, '.'))) + if ((p = strchr(host, '.'))) { *p = '\0'; -#endif /* FQDN */ + if ((shost = strdup(host)) == NULL) { + perror("malloc"); + (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); + exit(1); + } + *p = '.'; + } else { + shost = &host[0]; + } /* * load a list of ip addresses and netmasks into diff --git a/sudo.h b/sudo.h index d96446860..c6ef3e35f 100644 --- a/sudo.h +++ b/sudo.h @@ -186,9 +186,7 @@ void load_interfaces __P((void)); */ #ifndef MAIN extern char host[]; -#ifdef FQDN -extern char shost[]; -#endif /* FQDN */ +extern char *shost; extern char cwd[]; extern struct interface *interfaces; extern int num_interfaces; diff --git a/visudo.c b/visudo.c index 31f4fdf48..709effa7b 100644 --- a/visudo.c +++ b/visudo.c @@ -110,9 +110,7 @@ int parse_error = FALSE; * For the parsing routines */ char host[] = ""; -#ifdef FQDN -char shost[] = ""; -#endif /* FQDN */ +char *shost = ""; char *cmnd = ""; struct passwd *user_pw_ent;