static char sccsid
[] = "@(#)uucpname.c 5.2 (Berkeley) %G%";
/* 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(hostname
);
if(gethostname(hostname
, &i
) == -1) {
if(gethostname(hostname
, sizeof(hostname
)) == -1) {
DEBUG(1, "gethostname", _FAILED
);
/* Use USG library routine */
if (s
== NULL
|| *s
== '\0') {
if (uname(&utsn
) == -1) {
DEBUG(1, "uname", _FAILED
);
/* Use fake gethostname() routine */
if (s
== NULL
|| *s
== '\0') {
if (fakegethostname(fakehost
, sizeof(fakehost
)) == -1) {
DEBUG(1, "whoami search", _FAILED
);
/* compile sysname right into uucp */
if (s
== NULL
|| *s
== '\0') {
/* 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(s
, 8, uucpf
) == NULL
) {
DEBUG(1, "uuname search", _FAILED
);
for (d
= stmp
; *d
&& *d
!= '\n' && d
< stmp
+ 8; d
++)
/* Use 3Com's getmyhname() routine */
if (s
== NULL
|| *s
== '\0') {
if ((s
== getmyhname()) == NULL
)
DEBUG(1, "getmyhname", _FAILED
);
if (s
== NULL
|| *s
== '\0') {
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");
* save entire name for TCP/IP verification
* copy uucpname back to caller-supplied buffer,
* truncating to 7 characters.
* Also set up subdirectory names, if subdirs are being used.
while ((*d
= *s
++) && d
< name
+ 7)
DEBUG(1, "My uucpname = %s\n", name
);
sprintf(DLocal
, "D.%s", name
);
sprintf(DLocalX
, "D.%sX", 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");
hname
[0] = 0; /* rti!trt: was "hostunknown" */
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)) {