]> granicus.if.org Git - sudo/commitdiff
now uses shost even if not FQDN
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 11 Mar 1996 19:05:55 +0000 (19:05 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 11 Mar 1996 19:05:55 +0000 (19:05 +0000)
parse.yacc
sudo.c
sudo.h
visudo.c

index f06a71d7f9759c304b24a51c23df6174feeec2f1..23429a3fe5cf07e98123459a63c0cdea7f72382f 100644 (file)
@@ -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 2516f2c726d37b3c377f48bb8ee5c2e3ee08d114..37e8386d81f36a52dfa141fdfed735e22e9ca3c3 100644 (file)
--- 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 d96446860715555e853fa6d95aefeaf0df1de22d..c6ef3e35f07e539bea3aff089db9ef884096e827 100644 (file)
--- 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;
index 31f4fdf485dc856a003b75c0f684d4290a14e7a6..709effa7b552cf824bd9366791c81d52097aaed1 100644 (file)
--- 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;