BSD 4_4 release
[unix-history] / usr / src / usr.bin / uucp / libuu / uucpname.c
index 62f5f32..f92a442 100644 (file)
@@ -1,11 +1,21 @@
+/*-
+ * Copyright (c) 1985, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This module is believed to contain source code proprietary to AT&T.
+ * Use and redistribution is subject to the Berkeley Software License
+ * Agreement and your Software Agreement with AT&T (Western Electric).
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)uucpname.c 5.2 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)uucpname.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 #include "uucp.h"
 
 #include "uucp.h"
-#include <sys/types.h>
 #include <sys/stat.h>
 
 #include <sys/stat.h>
 
+/*LINTLIBRARY*/
+
 #ifdef GETMYHNAME
 #include <UNET/unetio.h>
 #endif
 #ifdef GETMYHNAME
 #include <UNET/unetio.h>
 #endif
@@ -19,6 +29,7 @@ static char sccsid[] = "@(#)uucpname.c        5.2 (Berkeley) %G%";
 /* Compile in 'sysname' as found in standard(!) include file */
 #include <whoami.h>
 #endif
 /* Compile in 'sysname' as found in standard(!) include file */
 #include <whoami.h>
 #endif
+char Myfullname[64];
 
 /*
  *     uucpname(name)          get the uucp name
 
 /*
  *     uucpname(name)          get the uucp name
@@ -28,7 +39,7 @@ static char sccsid[] = "@(#)uucpname.c        5.2 (Berkeley) %G%";
 uucpname(name)
 register char *name;
 {
 uucpname(name)
 register char *name;
 {
-       register char *s, *d;
+       register char *s;
 
        /*
         * Since some UNIX systems do not honor the set-user-id bit
 
        /*
         * Since some UNIX systems do not honor the set-user-id bit
@@ -48,16 +59,15 @@ register char *name;
 
 #ifdef GETHOSTNAME
        if (s == NULL || *s == '\0') {
 
 #ifdef GETHOSTNAME
        if (s == NULL || *s == '\0') {
-               char hostname[32];
 #ifdef VMS
 #ifdef VMS
-               int i = sizeof(hostname);
+               int i = sizeof(Myfullname);
 #endif VMS
 
 #endif VMS
 
-               s = hostname;
+               s = Myfullname;
 #ifdef VMS
 #ifdef VMS
-               if(gethostname(hostname, &i) == -1) {
+               if(gethostname(Myfullname, &i) == -1) {
 #else !VMS
 #else !VMS
-               if(gethostname(hostname, sizeof(hostname)) == -1) {
+               if(gethostname(Myfullname, sizeof(Myfullname)) == -1) {
 #endif !VMS
                        DEBUG(1, "gethostname", _FAILED);
                        s = NULL;
 #endif !VMS
                        DEBUG(1, "gethostname", _FAILED);
                        s = NULL;
@@ -70,10 +80,12 @@ register char *name;
        if (s == NULL || *s == '\0') {
                struct utsname utsn;
 
        if (s == NULL || *s == '\0') {
                struct utsname utsn;
 
-               s = utsn.nodename;
                if (uname(&utsn) == -1) {
                        DEBUG(1, "uname", _FAILED);
                        s = NULL;
                if (uname(&utsn) == -1) {
                        DEBUG(1, "uname", _FAILED);
                        s = NULL;
+               } else {
+                       strncpy(Myfullname, utsn.nodename, sizeof Myfullname);
+                       s = Myfullname;
                }
        }
 #endif
                }
        }
 #endif
@@ -81,10 +93,9 @@ register char *name;
 #ifdef WHOAMI
        /* Use fake gethostname() routine */
        if (s == NULL || *s == '\0') {
 #ifdef WHOAMI
        /* Use fake gethostname() routine */
        if (s == NULL || *s == '\0') {
-               char fakehost[32];
 
 
-               s = fakehost;
-               if (fakegethostname(fakehost, sizeof(fakehost)) == -1) {
+               s = Myfullname;
+               if (fakegethostname(Myfullname, sizeof(Myfullname)) == -1) {
                        DEBUG(1, "whoami search", _FAILED);
                        s = NULL;
                }
                        DEBUG(1, "whoami search", _FAILED);
                        s = NULL;
                }
@@ -95,6 +106,7 @@ register char *name;
        /* compile sysname right into uucp */
        if (s == NULL || *s == '\0') {
                s = sysname;
        /* compile sysname right into uucp */
        if (s == NULL || *s == '\0') {
                s = sysname;
+               strncpy(Myfullname, s, sizeof Myfullname);
        }
 #endif
 
        }
 #endif
 
@@ -102,19 +114,20 @@ register char *name;
        /* uucp name is stored in /etc/uucpname or /local/uucpname */
        if (s == NULL || *s == '\0') {
                FILE *uucpf;
        /* uucp name is stored in /etc/uucpname or /local/uucpname */
        if (s == NULL || *s == '\0') {
                FILE *uucpf;
-               char stmp[10];
 
 
-               s = stmp;
+               s = Myfullname;
                if (((uucpf = fopen("/etc/uucpname", "r")) == NULL &&
                     (uucpf = fopen("/local/uucpname", "r")) == NULL) ||
                if (((uucpf = fopen("/etc/uucpname", "r")) == NULL &&
                     (uucpf = fopen("/local/uucpname", "r")) == NULL) ||
-                       fgets(s, 8, uucpf) == NULL) {
+                       fgets(Myfullname, sizeof Myfullname, uucpf) == NULL) {
                                DEBUG(1, "uuname search", _FAILED);
                                s = NULL;
                                DEBUG(1, "uuname search", _FAILED);
                                s = NULL;
-               } else {
-                       for (d = stmp; *d && *d != '\n' && d < stmp + 8; d++)
-                               ;
-                       *d = '\0';
                }
                }
+               if (s == Myfullname) {
+                       register char *p;
+                       p = index(s, '\n');
+                       if (p)
+                               *p = '\0';
+               }
                if (uucpf != NULL)
                        fclose(uucpf);
        }
                if (uucpf != NULL)
                        fclose(uucpf);
        }
@@ -123,14 +136,17 @@ register char *name;
 #ifdef GETMYHNAME
        /* Use 3Com's getmyhname() routine */
        if (s == NULL || *s == '\0') {
 #ifdef GETMYHNAME
        /* Use 3Com's getmyhname() routine */
        if (s == NULL || *s == '\0') {
-               if ((s == getmyhname()) == NULL)
+               if ((s = getmyhname()) == NULL)
                        DEBUG(1, "getmyhname", _FAILED);
                        DEBUG(1, "getmyhname", _FAILED);
+               else
+                       strncpy(Myfullname, s, sizeof Myfullname);
        }
 #endif
 
 #ifdef MYNAME
        if (s == NULL || *s == '\0') {
                s = MYNAME;
        }
 #endif
 
 #ifdef MYNAME
        if (s == NULL || *s == '\0') {
                s = MYNAME;
+               strncpy(Myfullname, s, sizeof Myfullname);
        }
 #endif
 
        }
 #endif
 
@@ -141,28 +157,26 @@ register char *name;
                 * but that is too much trouble, isn't it?
                 */
                logent("SYSTEM NAME", "CANNOT DETERMINE");
                 * but that is too much trouble, isn't it?
                 */
                logent("SYSTEM NAME", "CANNOT DETERMINE");
-               s = "unknown";
+               strcpy(Myfullname, "unknown");
        }
 
        }
 
-       /*
-        * save entire name for TCP/IP verification
-        */
-
-       strcpy(Myfullname, s);
-
        /*
         * copy uucpname back to caller-supplied buffer,
        /*
         * copy uucpname back to caller-supplied buffer,
-        * truncating to 7 characters.
-        * Also set up subdirectory names, if subdirs are being used.
+        * truncating to MAXBASENAME characters.
+        * Also set up subdirectory names
+        * Truncate names at '.' if found to handle cases like
+        * seismo.css.gov being returned by gethostname().
+        * uucp sites should not have '.' in their name anyway
         */
         */
-       d = name;
-       while ((*d = *s++) && d < name + 7)
-               d++;
-       *(name + 7) = '\0';
+       s = index(Myfullname, '.');
+       if (s != NULL)
+               *s = '\0';
+       strncpy(name, Myfullname, MAXBASENAME);
+       name[MAXBASENAME] = '\0';
        DEBUG(1, "My uucpname = %s\n", name);
 
        DEBUG(1, "My uucpname = %s\n", name);
 
-       sprintf(DLocal, "D.%s", name);
-       sprintf(DLocalX, "D.%sX", name);
+       sprintf(DLocal, "D.%.*s", SYSNSIZE, name);
+       sprintf(DLocalX, "D.%.*sX", SYSNSIZE, name);
 }
 
 #ifdef WHOAMI
 }
 
 #ifdef WHOAMI
@@ -189,7 +203,7 @@ int len;
        if (fd == NULL)
                return(-1);
        
        if (fd == NULL)
                return(-1);
        
-       hname[0] = 0;   /* rti!trt: was "hostunknown" */
+       hname[0] = 0;
        nname[0] = 0;
        nptr = nname;
 
        nname[0] = 0;
        nptr = nname;