Initialize the system dependent routines.
Copyright (C) 1991, 1992 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
#if ! HAVE_GETHOSTNAME && HAVE_UNAME
/* Use getcwd in preference to getwd; if we have neither, we will be
using a getcwd replacement. */
#else /* ! HAVE_GETCWD */
#endif /* ! HAVE_GETWD */
#endif /* ! HAVE_GETCWD */
/* Get a value for MAXPATHLEN. */
#define MAXPATHLEN PATH_MAX
#else /* ! defined (PATH_MAX) */
#endif /* ! defined (PATH_MAX) */
#endif /* ! defined (MAXPATHLEN) */
/* External functions. */
extern char *getlogin ();
#if GETPWNAM_DECLARATION_OK
extern struct passwd
*getpwnam ();
#if GETPWUID_DECLARATION_OK
extern struct passwd
*getpwuid ();
/* Initialize the system dependent routines. We will probably be running
suid to uucp, so we make sure that nothing is obviously wrong. We
save the login name since we will be losing the real uid. */
/* The UUCP spool directory. */
/* The UUCP lock directory. */
/* The local UUCP name. */
/* We save the current directory since we will do a chdir to the
/* The maximum length of a system name is controlled by the type of spool
#if SPOOLDIR_V2 || SPOOLDIR_BSD42 || SPOOLDIR_BSD43 || SPOOLDIR_ULTRIX
size_t cSysdep_max_name_len
= 7;
#if SPOOLDIR_HDB || SPOOLDIR_SVR4
size_t cSysdep_max_name_len
= 14;
size_t cSysdep_max_name_len
= 255;
#else /* ! HAVE_LONG_FILE_NAMES */
size_t cSysdep_max_name_len
= 14;
#endif /* ! HAVE_LONG_FILE_NAMES */
#endif /* SPOOLDIR_TAYLOR */
/* Initialize the system dependent routines. */
usysdep_initialize (puuconf
,iflags
)
/* Close everything but stdin, stdout and stderr. */
cdescs
= getdtablesize ();
cdescs
= sysconf (_SC_OPEN_MAX
);
#endif /* ! defined (NOFILE) */
#endif /* ! defined (OPEN_MAX) */
#endif /* ! HAVE_SYSCONF */
#endif /* ! HAVE_GETDTABLESIZE */
for (o
= 3; o
< cdescs
; o
++)
/* Make sure stdin, stdout and stderr are open. */
if (fcntl (0, F_GETFD
, 0) < 0
&& open ((char *) "/dev/null", O_RDONLY
, 0) != 0)
if (fcntl (1, F_GETFD
, 0) < 0
&& open ((char *) "/dev/null", O_WRONLY
, 0) != 1)
if (fcntl (2, F_GETFD
, 0) < 0
&& open ((char *) "/dev/null", O_WRONLY
, 0) != 2)
iuuconf
= uuconf_spooldir (puuconf
, &zSspooldir
);
if (iuuconf
!= UUCONF_SUCCESS
)
ulog_uuconf (LOG_FATAL
, puuconf
, iuuconf
);
iuuconf
= uuconf_lockdir (puuconf
, &zSlockdir
);
if (iuuconf
!= UUCONF_SUCCESS
)
ulog_uuconf (LOG_FATAL
, puuconf
, iuuconf
);
iuuconf
= uuconf_localname (puuconf
, &zSlocalname
);
if (iuuconf
== UUCONF_NOT_FOUND
)
if (gethostname (ab
, sizeof ab
- 1) < 0)
ulog (LOG_FATAL
, "gethostname: %s", strerror (errno
));
ab
[sizeof ab
- 1] = '\0';
ab
[strcspn (ab
, ".")] = '\0';
zSlocalname
= zbufcpy (ab
);
#else /* ! HAVE_GETHOSTNAME */
ulog (LOG_FATAL
, "uname: %s", strerror (errno
));
zSlocalname
= zbufcpy (s
.nodename
);
ulog (LOG_FATAL
, "Don't know how to get local node name");
#endif /* ! HAVE_UNAME */
#endif /* ! HAVE_GETHOSTNAME */
else if (iuuconf
!= UUCONF_SUCCESS
)
ulog_uuconf (LOG_FATAL
, puuconf
, iuuconf
);
/* We always set our file modes to exactly what we want. */
/* Get the login name, making sure that it matches the uid. Many
systems truncate the getlogin return value to 8 characters, but
keep the full name in the password file, so we prefer the name in
if (q
== NULL
|| q
->pw_uid
!= getuid ())
q
= getpwuid (getuid ());
/* On some old systems, an suid program run by root is started with
an euid of 0. If this happens, we look up the uid we should have
and set ourselves to it manually. This means that on such a
system root will not be able to uucp or uux files that are not
if ((iflags
& INIT_SUID
) != 0
if ((iflags
& INIT_GETCWD
) != 0)
/* Get the current working directory. We have to get it now,
since we're about to do a chdir. We use PWD if it's defined
and if it really names the working directory, since if it's
not the same as whatever getcwd returns it's probably more
&& stat ((char *) zenv
, &senv
) == 0
&& stat ((char *) ".", &sdot
) == 0
&& senv
.st_ino
== sdot
.st_ino
&& senv
.st_dev
== sdot
.st_dev
)
zScwd
= (char *) xmalloc (c
);
if (getcwd (zScwd
, c
) != NULL
)
zScwd
= (char *) xmalloc (MAXPATHLEN
);
if (getwd (zScwd
) == NULL
)
zScwd
= (char *) xrealloc ((pointer
) zScwd
,
if ((iflags
& INIT_NOCHDIR
) == 0)
/* Connect to the spool directory, and create it if it doesn't
if (chdir (zSspooldir
) < 0)
&& mkdir ((char *) zSspooldir
, IDIRECTORY_MODE
) < 0)
ulog (LOG_FATAL
, "mkdir (%s): %s", zSspooldir
,
if (chdir (zSspooldir
) < 0)
ulog (LOG_FATAL
, "chdir (%s): %s", zSspooldir
,
exit (fsuccess
? EXIT_SUCCESS
: EXIT_FAILURE
);
/* This is called when a non-standard configuration file is used, to
make sure the program doesn't hand out privileged file access.
This means that to test non-standard configuration files, you
should be logged in as uucp. This is called before
usysdep_initialize. It ensures that someone can't simply use an
alternate configuration file to steal UUCP transfers from other
systems. This will still permit people to set up their own
configuration file and pretend to be whatever system they choose.
The only real security is to use a high level of protection on the
boolean
fsysdep_other_config (z
)
(void) setuid (getuid ());
(void) setgid (getgid ());
/* Get the node name to use if it was not specified in the configuration
/* Get the login name. We actually get the login name in
usysdep_initialize, because after that we may switch away from the
ulog (LOG_FATAL
, "Can't get login name");