summaryrefslogtreecommitdiff
path: root/login
diff options
context:
space:
mode:
Diffstat (limited to 'login')
-rw-r--r--login/getutent_r.c54
-rw-r--r--login/getutid_r.c4
-rw-r--r--login/getutline_r.c4
-rw-r--r--login/programs/database.c5
-rw-r--r--login/programs/utmpd.c5
-rw-r--r--login/utmp-private.h5
-rw-r--r--login/utmp_daemon.c35
-rw-r--r--login/utmp_file.c51
8 files changed, 76 insertions, 87 deletions
diff --git a/login/getutent_r.c b/login/getutent_r.c
index a50e2786fd..ed4c330f73 100644
--- a/login/getutent_r.c
+++ b/login/getutent_r.c
@@ -29,9 +29,9 @@
/* The various backends we have. */
-static int setutent_unknown (int reset);
static int getutent_r_unknown (struct utmp *buffer, struct utmp **result);
static struct utmp *pututline_unknown (const struct utmp *data);
+static void setutent_unknown (void);
static void endutent_unknown (void);
/* Initial Jump table. */
@@ -58,7 +58,7 @@ __setutent (void)
{
__libc_lock_lock (__libc_utmp_lock);
- (void) (*__libc_utmp_jump_table->setutent) (1);
+ (*__libc_utmp_jump_table->setutent) ();
__libc_lock_unlock (__libc_utmp_lock);
}
@@ -66,36 +66,6 @@ weak_alias (__setutent, setutent)
weak_alias (__setutent, setutxent)
-static int
-setutent_unknown (int reset)
-{
- /* We have to test whether it is still not decided which backend to use. */
- assert (__libc_utmp_jump_table == &__libc_utmp_unknown_functions);
-
- /* See whether utmpd is running. */
- if ((*__libc_utmp_daemon_functions.setutent) (reset))
- __libc_utmp_jump_table = &__libc_utmp_daemon_functions;
- else
- {
- /* Use the normal file, but if the current file is _PATH_UTMP or
- _PATH_WTMP and the corresponding extended file (with an extra
- 'x' added to the pathname) exists, we use the extended file,
- because the original file is in a different format. */
- if (strcmp (__libc_utmp_file_name, _PATH_UTMP) == 0
- && __access (_PATH_UTMP "x", F_OK) == 0)
- __utmpname (_PATH_UTMP "x");
- else if (strcmp (__libc_utmp_file_name, _PATH_WTMP) == 0
- && __access (_PATH_WTMP "x", F_OK) == 0)
- __utmpname (_PATH_WTMP "x");
-
- (*__libc_utmp_file_functions.setutent) (reset);
- __libc_utmp_jump_table = &__libc_utmp_file_functions;
- }
-
- return 0;
-}
-
-
void
__endutent (void)
{
@@ -110,6 +80,20 @@ weak_alias (__endutent, endutxent)
static void
+setutent_unknown (void)
+{
+ /* See whether utmpd is running. */
+ if ((*__libc_utmp_daemon_functions.setutent) ())
+ __libc_utmp_jump_table = &__libc_utmp_daemon_functions;
+ else
+ {
+ (*__libc_utmp_file_functions.setutent) ();
+ __libc_utmp_jump_table = &__libc_utmp_file_functions;
+ }
+}
+
+
+static void
endutent_unknown (void)
{
/* Huh, how do we came here? Nothing to do. */
@@ -136,7 +120,7 @@ static int
getutent_r_unknown (struct utmp *buffer, struct utmp **result)
{
/* It is not yet initialized. */
- setutent_unknown (0);
+ __setutent ();
return (*__libc_utmp_jump_table->getutent_r) (buffer, result);
}
@@ -158,12 +142,12 @@ __pututline (const struct utmp *data)
weak_alias (__pututline, pututline)
weak_alias (__pututline, pututxline)
-
+
static struct utmp *
pututline_unknown (const struct utmp *data)
{
/* It is not yet initialized. */
- setutent_unknown (0);
+ __setutent ();
return (*__libc_utmp_jump_table->pututline) (data);
}
diff --git a/login/getutid_r.c b/login/getutid_r.c
index ee3a39a3bd..90b75b8c01 100644
--- a/login/getutid_r.c
+++ b/login/getutid_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>
and Paul Janzen <pcj@primenet.com>, 1996.
@@ -55,7 +55,7 @@ __getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result)
__libc_lock_lock (__libc_utmp_lock);
/* Not yet initialized. */
- if ((*__libc_utmp_jump_table->setutent) (0))
+ if ((*__libc_utmp_jump_table->setutent) ())
retval = (*__libc_utmp_jump_table->getutid_r) (id, buffer, result);
else
*result = NULL;
diff --git a/login/getutline_r.c b/login/getutline_r.c
index 9b4180fe4a..a1bdc0bc4e 100644
--- a/login/getutline_r.c
+++ b/login/getutline_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>
and Paul Janzen <pcj@primenet.com>, 1996.
@@ -43,7 +43,7 @@ __getutline_r (const struct utmp *line, struct utmp *buffer,
__libc_lock_lock (__libc_utmp_lock);
/* Not yet initialized. */
- if ((*__libc_utmp_jump_table->setutent) (0))
+ if ((*__libc_utmp_jump_table->setutent) ())
retval = (*__libc_utmp_jump_table->getutline_r) (line, buffer, result);
else
*result = NULL;
diff --git a/login/programs/database.c b/login/programs/database.c
index 087ec54d26..00d573f336 100644
--- a/login/programs/database.c
+++ b/login/programs/database.c
@@ -52,6 +52,7 @@ static int get_mtime (int filedes, time_t *timer);
utmp_database *
open_database (const char *file, const char *old_file)
{
+ mode_t mode = S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH;
utmp_database *database;
/* Allocate memory. */
@@ -65,7 +66,7 @@ open_database (const char *file, const char *old_file)
memset (database, 0, sizeof (utmp_database));
/* Open database, create it if it doesn't exist already. */
- database->fd = open (file, O_RDWR | O_CREAT);
+ database->fd = open (file, O_RDWR | O_CREAT, mode);
if (database->fd < 0)
{
error (0, errno, "%s", file);
@@ -81,7 +82,7 @@ open_database (const char *file, const char *old_file)
if (old_file)
{
- database->old_fd = open (old_file, O_RDWR);
+ database->old_fd = open (old_file, O_RDWR|O_CREAT, mode);
if (database->old_fd < 0)
{
error (0, errno, "%s", old_file);
diff --git a/login/programs/utmpd.c b/login/programs/utmpd.c
index 1469d94ca7..e0648ebb42 100644
--- a/login/programs/utmpd.c
+++ b/login/programs/utmpd.c
@@ -141,6 +141,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
if (check_pid (_PATH_UTMPDPID))
error (EXIT_FAILURE, 0, _("already running"));
+ /* Cleanup files created by a previous `bind'. */
+ unlink (_PATH_UTMPD_RO);
+ unlink (_PATH_UTMPD_RW);
+
/* Open UTMP database. */
utmp_db = open_database (_PATH_UTMP "x", _PATH_UTMP);
if (utmp_db == NULL)
@@ -248,6 +252,7 @@ make_socket (const char *name)
size = (offsetof (struct sockaddr_un, sun_path)
+ strlen (addr.sun_path));
+
if (bind (sock, (struct sockaddr *) &addr, size) < 0)
error (EXIT_FAILURE, errno, "%s", name);
diff --git a/login/utmp-private.h b/login/utmp-private.h
index 87860d5d33..531d058469 100644
--- a/login/utmp-private.h
+++ b/login/utmp-private.h
@@ -24,11 +24,10 @@
#include <utmp.h>
-/* The extra `int' argument for each function shows whether locking is
- wanted or not. */
+/* The structure describing the functions in a backend. */
struct utfuncs
{
- int (*setutent) (int);
+ int (*setutent) (void);
int (*getutent_r) (struct utmp *, struct utmp **);
int (*getutid_r) (const struct utmp *, struct utmp *, struct utmp **);
int (*getutline_r) (const struct utmp *, struct utmp *, struct utmp **);
diff --git a/login/utmp_daemon.c b/login/utmp_daemon.c
index e0a20e9a9f..5907e06e2d 100644
--- a/login/utmp_daemon.c
+++ b/login/utmp_daemon.c
@@ -35,7 +35,7 @@ static int daemon_sock = INT_MIN;
/* Functions defined here. */
-static int setutent_daemon (int reset);
+static int setutent_daemon (void);
static int getutent_r_daemon (struct utmp *buffer, struct utmp **result);
static int getutid_r_daemon (const struct utmp *line, struct utmp *buffer,
struct utmp **result);
@@ -74,9 +74,13 @@ static int send_request (int sock, const request_header *request,
static int
-setutent_daemon (int reset)
+setutent_daemon (void)
{
- if (daemon_sock == INT_MIN)
+ if (access (_PATH_UTMPD_RW, F_OK) == -1
+ && access (_PATH_UTMPD_RO, F_OK) == -1)
+ return 0;
+
+ if (daemon_sock < 0)
{
daemon_sock = open_socket (_PATH_UTMPD_RW);
if (daemon_sock < 0)
@@ -86,18 +90,12 @@ setutent_daemon (int reset)
if (daemon_sock < 0)
return 0;
}
-
- /* Send request to the daemon. */
- if (do_setutent (daemon_sock) < 0)
- return 0;
- }
- else if (reset)
- {
- /* Send request to the daemon. */
- if (do_setutent (daemon_sock) < 0)
- return 0;
}
+ /* Send request to the daemon. */
+ if (do_setutent (daemon_sock) < 0)
+ return 0;
+
return 1;
}
@@ -121,7 +119,7 @@ getutent_r_daemon (struct utmp *buffer, struct utmp **result)
{
/* Open connection if not already done. */
if (daemon_sock == INT_MIN)
- setutent_daemon (1);
+ setutent_daemon ();
if (daemon_sock < 0)
{
@@ -189,9 +187,9 @@ getutid_r_daemon (const struct utmp *id, struct utmp *buffer,
static struct utmp *
pututline_daemon (const struct utmp *utmp)
{
+ /* Open connection if not already done. */
if (daemon_sock == INT_MIN)
- /* The connection is closed. Open it again. */
- setutent_daemon (0);
+ setutent_daemon ();
if (daemon_sock < 0)
/* Something went wrong. */
@@ -217,7 +215,10 @@ updwtmp_daemon (const char *file, const struct utmp *utmp)
/* Send request to the daemon. */
if (do_updwtmp (sock, file, utmp) < 0)
- return -1;
+ {
+ close (sock);
+ return -1;
+ }
close (sock);
return 0;
diff --git a/login/utmp_file.c b/login/utmp_file.c
index 4e218d8baa..6d6e05b292 100644
--- a/login/utmp_file.c
+++ b/login/utmp_file.c
@@ -39,7 +39,7 @@ static struct utmp last_entry;
/* Functions defined here. */
-static int setutent_file (int reset);
+static int setutent_file (void);
static int getutent_r_file (struct utmp *buffer, struct utmp **result);
static int getutid_r_file (const struct utmp *key, struct utmp *buffer,
struct utmp **result);
@@ -63,41 +63,40 @@ struct utfuncs __libc_utmp_file_functions =
static int
-setutent_file (int reset)
+setutent_file (void)
{
- if (file_fd == INT_MIN)
+ if (file_fd < 0)
{
- file_fd = open (__libc_utmp_file_name, O_RDWR);
+ const char *file_name = __libc_utmp_file_name;
+
+ if (strcmp (__libc_utmp_file_name, _PATH_UTMP) == 0
+ && __access (_PATH_UTMP "x", F_OK) == 0)
+ file_name = _PATH_UTMP "x";
+ else if (strcmp (__libc_utmp_file_name, _PATH_WTMP) == 0
+ && __access (_PATH_WTMP "x", F_OK) == 0)
+ file_name = _PATH_WTMP "x";
+
+ file_fd = open (file_name, O_RDWR);
if (file_fd == -1)
{
/* Hhm, read-write access did not work. Try read-only. */
- file_fd = open (__libc_utmp_file_name, O_RDONLY);
+ file_fd = open (file_name, O_RDONLY);
if (file_fd == -1)
{
perror (_("while opening UTMP file"));
return 0;
}
}
- file_offset = 0;
-
-#if _HAVE_UT_TYPE - 0
- /* Make sure the entry won't match. */
- last_entry.ut_type = -1;
-#endif
}
- else if (reset)
- {
- lseek (file_fd, 0, SEEK_SET);
- /* Remember we are at beginning of file. */
- file_offset = 0;
+ lseek (file_fd, 0, SEEK_SET);
+ file_offset = 0;
#if _HAVE_UT_TYPE - 0
- /* Make sure the entry won't match. */
- last_entry.ut_type = -1;
+ /* Make sure the entry won't match. */
+ last_entry.ut_type = -1;
#endif
- }
-
+
return 1;
}
@@ -120,7 +119,7 @@ getutent_r_file (struct utmp *buffer, struct utmp **result)
/* Open utmp file if not already done. */
if (file_fd == INT_MIN)
- setutent_file (1);
+ setutent_file ();
if (file_fd == -1 || file_offset == -1l)
{
@@ -348,14 +347,14 @@ pututline_file (const struct utmp *data)
struct utmp *pbuf;
int found;
- if (file_fd < 0)
+ /* Open utmp file if not already done. */
+ if (file_fd == INT_MIN)
+ setutent_file ();
+
+ if (file_fd == -1)
/* Something went wrong. */
return NULL;
- if (file_fd == INT_MIN)
- /* The file is closed. Open it again. */
- setutent_file (0);
-
/* Find the correct place to insert the data. */
if (file_offset > 0
&& (