static char sccsid
[] = "@(#)uucpname.c 5.1 (Berkeley) %G%";
/* Use USG uname() library routine */
/* Compile in 'sysname' as found in standard(!) include file */
* uucpname(name) get the uucp name
/* HUGE KLUDGE HERE! rti!trt
* 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 */
/* Use 4.1a library routine */
if (s
== NULL
|| *s
== '\0') {
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");
* 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.1a bsd system call by reading /usr/include/whoami.h
* and looking for the #define sysname
* CHANGE NOTICE (rti!trt): returns -1 on failure, 0 on success.
#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;
return(-1); /* added by rti!trt */
strncpy(name
, hname
, len
);
while (i
< len
&& (p
[0] != 0 || p
[1] != 0)) {