SCCS-vsn: usr.bin/uucp/libuu/uucpname.c 5.4
-static char sccsid[] = "@(#)uucpname.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)uucpname.c 5.4 (Berkeley) %G%";
#endif
#include "uucp.h"
#include <sys/stat.h>
#endif
#include "uucp.h"
#include <sys/stat.h>
#ifdef GETMYHNAME
#include <UNET/unetio.h>
#endif
#ifdef GETMYHNAME
#include <UNET/unetio.h>
#endif
/* 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
/*
* uucpname(name) get the uucp name
/*
* uucpname(name) get the uucp name
uucpname(name)
register char *name;
{
uucpname(name)
register char *name;
{
/*
* Since some UNIX systems do not honor the set-user-id bit
/*
* Since some UNIX systems do not honor the set-user-id bit
#ifdef GETHOSTNAME
if (s == NULL || *s == '\0') {
#ifdef GETHOSTNAME
if (s == NULL || *s == '\0') {
- int i = sizeof(hostname);
+ int i = sizeof(Myfullname);
- if(gethostname(hostname, &i) == -1) {
+ if(gethostname(Myfullname, &i) == -1) {
- 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;
if (s == NULL || *s == '\0') {
struct utsname utsn;
if (s == NULL || *s == '\0') {
struct utsname utsn;
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;
#ifdef WHOAMI
/* Use fake gethostname() routine */
if (s == NULL || *s == '\0') {
#ifdef WHOAMI
/* Use fake gethostname() routine */
if (s == NULL || *s == '\0') {
- 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;
}
/* 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;
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);
}
#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);
- /*
- * 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.arpa 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';
+ strncpy(name, s, MAXBASENAME);
+ name[MAXBASENAME] = '\0';
+ s = index(name, '.');
+ if (s != NULL)
+ *s = '\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);