summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-06-19 19:17:41 +0000
committerMiles Bader <miles@gnu.org>1996-06-19 19:17:41 +0000
commitd0c311230e3bc0f82a2f39c331e71103ee0a86ae (patch)
tree8e3dcbe90259ddf7a07ee30535c5fcb1a8547c48 /utils
parent105003e04b971e9f01ea3e8fb31f53f4756123ad (diff)
(hurd_file_name_path_lookup): Declaration removed.
(main: child_lookup): Pass 0 for new LOOKUP arg to hurd_file_name_path_lookup. (get_utmp_host): Function removed. (add_utmp_entry): Get rid of TTY_FD parameter. Don't search for the tty unless we need it to get the old host, since login does it for us. Also use the `existing host' in the case that a new one isn't specified. (main): Update call to add_utmp_entry.
Diffstat (limited to 'utils')
-rw-r--r--utils/login.c91
1 files changed, 33 insertions, 58 deletions
diff --git a/utils/login.c b/utils/login.c
index c291575c..82ca9ea0 100644
--- a/utils/login.c
+++ b/utils/login.c
@@ -48,15 +48,6 @@ extern error_t
exec_reauth (auth_t auth, int secure, int must_reauth,
mach_port_t *ports, unsigned num_ports,
mach_port_t *fds, unsigned num_fds);
-
-extern error_t
-hurd_file_name_path_lookup (error_t (*use_init_port)
- (int which,
- error_t (*operate) (mach_port_t)),
- file_t (*get_dtable_port) (int fd),
- const char *file_name, const char *path,
- int flags, mode_t mode,
- file_t *result, char **prefixed_name);
/* Defaults for various login parameters. */
char *default_args[] = {
@@ -146,68 +137,52 @@ cat (mach_port_t node, char *str)
error (0, errno, "%s", str);
}
-/* Returns the host from the umtp entry for the current tty, or 0. The
- return value is in a static buffer. */
-static char *
-get_utmp_host ()
-{
- static struct utmp utmp;
- int tty = ttyslot ();
- char *host = 0;
-
- if (tty > 0)
- {
- int fd = open (_PATH_UTMP, O_RDONLY);
- if (fd >= 0)
- {
- lseek (fd, (off_t)(tty * sizeof (struct utmp)), L_SET);
- if (read (fd, &utmp, sizeof utmp) == sizeof utmp
- && *utmp.ut_name && *utmp.ut_line && *utmp.ut_host)
- host = utmp.ut_host;
- close (fd);
- }
- }
-
- return host;
-}
-
-/* Add a utmp entry based on the parameters in ARGS & ARGS_LEN, from tty
- TTY_FD. If INHERIT_HOST is true, the host parameters in ARGS aren't to be
- trusted, so try to get the host from the existing utmp entry (this only
- works if re-logging in during an existing session). */
+/* Add a utmp entry based on the parameters in ARGS & ARGS_LEN. If
+ INHERIT_HOST is true, the host parameters in ARGS aren't to be trusted, so
+ try to get the host from the existing utmp entry (this only works if
+ re-logging in during an existing session). */
static void
-add_utmp_entry (char *args, unsigned args_len, int tty_fd, int inherit_host)
+add_utmp_entry (char *args, unsigned args_len, int inherit_host)
{
struct utmp utmp;
- char bogus_tty[sizeof (_PATH_TTY) + 2];
- char *tty = ttyname (0);
- char const *host;
-
- if (! tty)
- {
- sprintf (bogus_tty, "%s??", _PATH_TTY);
- tty = bogus_tty;
- }
-
- if (strncmp (tty, _PATH_DEV, sizeof (_PATH_DEV) - 1) == 0)
- /* Remove a prefix of `/dev/'. */
- tty += sizeof (_PATH_DEV) - 1;
+ char const *host = 0;
bzero (&utmp, sizeof (utmp));
gettimeofday (&utmp.ut_tv, 0);
strncpy (utmp.ut_name, envz_get (args, args_len, "USER") ?: "",
sizeof (utmp.ut_name));
- strncpy (utmp.ut_line, tty, sizeof (utmp.ut_line));
- if (inherit_host)
- host = get_utmp_host ();
- else
+ if (! inherit_host)
{
host = envz_get (args, args_len, "VIA");
if (host && strlen (host) > sizeof (utmp.ut_host))
host = envz_get (args, args_len, "VIA_ADDR") ?: host;
}
+
+ if (! host)
+ /* Get the host from the `existing utmp entry'. This is a crock. */
+ {
+ int tty_fd = 0;
+ char *tty = 0;
+
+ /* Search for a file descriptor naming a tty. */
+ while (!tty && tty_fd < 3)
+ tty = ttyname (tty_fd);
+
+ if (tty)
+ /* Look for an existing utmp entry that has our tty. */
+ {
+ struct utmp *old_utmp;
+
+ strncpy (utmp.ut_line, tty, sizeof (utmp.ut_line));
+ old_utmp = getutline (&utmp);
+
+ if (old_utmp)
+ host = old_utmp->ut_host;
+ }
+ }
+
strncpy (utmp.ut_host, host ?: "", sizeof (utmp.ut_host));
login (&utmp);
@@ -438,7 +413,7 @@ main(int argc, char *argv[])
{
mach_port_t port = MACH_PORT_NULL;
errno =
- hurd_file_name_path_lookup (use_child_init_port, get_child_fd_port,
+ hurd_file_name_path_lookup (use_child_init_port, get_child_fd_port, 0,
name, path, flags, 0, &port, 0);
return port;
}
@@ -999,7 +974,7 @@ main(int argc, char *argv[])
err = proc_getsid (proc_server, pid, &sid);
if (!err && pid == sid)
/* Only add utmp entries for the session leader. */
- add_utmp_entry (args, args_len, 0, !parent_has_uid (0));
+ add_utmp_entry (args, args_len, !parent_has_uid (0));
if ((eff_uids->num | eff_gids->num) && !no_login)
{