* 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).
static char sccsid
[] = "@(#)uucpname.c 8.1 (Berkeley) 6/6/93";
/* Use USG uname() library routine */
/* Compile in 'sysname' as found in standard(!) include file */
* uucpname(name) get the uucp name
* Since some UNIX systems do not honor the set-user-id bit
* when the invoking user is root, we must change the uid here.
* So uucp files are created with the correct owner.
if (geteuid() == 0 && getuid() == 0) {
stbuf
.st_uid
= 0; /* In case the stat fails */
stat(UUCICO
, &stbuf
); /* Assume uucico is correctly owned */
s
= NULL
; /* system name unknown, so far */
if (s
== NULL
|| *s
== '\0') {
int i
= sizeof(Myfullname
);
if(gethostname(Myfullname
, &i
) == -1) {
if(gethostname(Myfullname
, sizeof(Myfullname
)) == -1) {
DEBUG(1, "gethostname", _FAILED
);
/* Use USG library routine */
if (s
== NULL
|| *s
== '\0') {
if (uname(&utsn
) == -1) {
DEBUG(1, "uname", _FAILED
);
strncpy(Myfullname
, utsn
.nodename
, sizeof Myfullname
);
/* Use fake gethostname() routine */
if (s
== NULL
|| *s
== '\0') {
if (fakegethostname(Myfullname
, sizeof(Myfullname
)) == -1) {
DEBUG(1, "whoami search", _FAILED
);
/* compile sysname right into uucp */
if (s
== NULL
|| *s
== '\0') {
strncpy(Myfullname
, s
, sizeof Myfullname
);
/* uucp name is stored in /etc/uucpname or /local/uucpname */
if (s
== NULL
|| *s
== '\0') {
if (((uucpf
= fopen("/etc/uucpname", "r")) == NULL
&&
(uucpf
= fopen("/local/uucpname", "r")) == NULL
) ||
fgets(Myfullname
, sizeof Myfullname
, uucpf
) == NULL
) {
DEBUG(1, "uuname search", _FAILED
);
/* Use 3Com's getmyhname() routine */
if (s
== NULL
|| *s
== '\0') {
if ((s
= getmyhname()) == NULL
)
DEBUG(1, "getmyhname", _FAILED
);
strncpy(Myfullname
, s
, sizeof Myfullname
);
if (s
== NULL
|| *s
== '\0') {
strncpy(Myfullname
, s
, sizeof Myfullname
);
if (s
== NULL
|| *s
== '\0') {
* As a last ditch thing, we *could* search Spool
* for D.<uucpname> and use that,
* but that is too much trouble, isn't it?
logent("SYSTEM NAME", "CANNOT DETERMINE");
strcpy(Myfullname
, "unknown");
* copy uucpname back to caller-supplied buffer,
* 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
s
= index(Myfullname
, '.');
strncpy(name
, Myfullname
, MAXBASENAME
);
name
[MAXBASENAME
] = '\0';
DEBUG(1, "My uucpname = %s\n", name
);
sprintf(DLocal
, "D.%.*s", SYSNSIZE
, name
);
sprintf(DLocalX
, "D.%.*sX", SYSNSIZE
, name
);
* simulate the 4.2 bsd system call by reading /usr/include/whoami.h
* and looking for the #define sysname
#define HDRFILE "/usr/include/whoami.h"
fakegethostname(name
, len
)
register char *p
, *q
, *nptr
;
fd
= fopen(HDRFILE
, "r");
while (fgets(buf
, sizeof buf
, fd
) != NULL
) { /* each line in the file */
if (sscanf(buf
, "#define sysname \"%[^\"]\"", bname
) == 1) {
} else if (sscanf(buf
, "#define nickname \"%[^\"]\"", bname
) == 1) {
nptr
+= strlen(bname
) + 1;
} else if (sscanf(buf
, "#define nickname%d \"%[^\"]\"", &i
, bname
) == 2) {
nptr
+= strlen(bname
) + 1;
strncpy(name
, hname
, len
);
while (i
< len
&& (p
[0] != 0 || p
[1] != 0)) {