@@ -21,22 +21,12 @@
#include <unistd.h>
#include "utmp-private.h"
-
-#ifndef TRANSFORM_UTMP_FILE_NAME
-# define TRANSFORM_UTMP_FILE_NAME(file_name) \
- ((strcmp (file_name, _PATH_UTMP "x") == 0 \
- && __access (_PATH_UTMP "x", F_OK) != 0) \
- ? _PATH_UTMP \
- : ((strcmp (file_name, _PATH_WTMP "x") == 0 \
- && __access (_PATH_WTMP "x", F_OK) != 0) \
- ? _PATH_WTMP \
- : file_name))
-#endif
+#include <utmp-path.h>
void
__updwtmp (const char *wtmp_file, const struct utmp *utmp)
{
- const char *file_name = TRANSFORM_UTMP_FILE_NAME (wtmp_file);
+ const char *file_name = utmp_file_name_time32 (wtmp_file);
__libc_updwtmp (file_name, utmp);
}
similarity index 50%
rename from sysdeps/gnu/utmp_file.c
rename to login/utmp-path.h
@@ -1,6 +1,6 @@
-/* Copyright (C) 1998-2021 Free Software Foundation, Inc.
+/* Handle {u,w}tmp and {u,w}tmpx file name usage.
+ Copyright (C) 1998-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -16,16 +16,26 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#ifndef _UTMP_PATH_H
+#define _UTMP_PATH_H 1
+
#include <string.h>
#include <unistd.h>
-#define TRANSFORM_UTMP_FILE_NAME(file_name) \
- ((strcmp (file_name, _PATH_UTMP "x") == 0 \
- && __access (_PATH_UTMP "x", F_OK) != 0) \
- ? _PATH_UTMP \
- : ((strcmp (file_name, _PATH_WTMP "x") == 0 \
- && __access (_PATH_WTMP "x", F_OK) != 0) \
- ? _PATH_WTMP \
- : file_name))
+/* The function returns the utmp database for 32-bit utmp{x} entries based
+ on FILE_NAME. If the argument ends with 'x' and the file does not
+ exits the default old utmp{x} name is returned instead. */
+static inline const char *
+utmp_file_name_time32 (const char *file_name)
+{
+ if (strcmp (file_name, _PATH_UTMP_BASE "x") == 0
+ && __access (_PATH_UTMP_BASE "x", F_OK) != 0)
+ return _PATH_UTMP_BASE;
+ else if (strcmp (file_name, _PATH_WTMP_BASE "x") == 0
+ && __access (_PATH_WTMP_BASE "x", F_OK) != 0)
+ return _PATH_UTMP_BASE;
+
+ return file_name;
+}
-#include <login/utmp_file.c>
+#endif /* _UTMP_PATH_H */
@@ -32,7 +32,7 @@
#include <not-cancel.h>
#include "utmp-private.h"
-#include "utmp-equal.h"
+#include <utmp-path.h>
/* Descriptor for the file and position. */
@@ -60,7 +60,21 @@ matches_last_entry (const struct utmp *data)
return data->ut_type == last_entry.ut_type;
else
/* For the process-related entries, a full match is needed. */
- return __utmp_equal (&last_entry, data);
+ return (data->ut_type == INIT_PROCESS
+ || data->ut_type == LOGIN_PROCESS
+ || data->ut_type == USER_PROCESS
+ || data->ut_type == DEAD_PROCESS)
+ && (last_entry.ut_type == INIT_PROCESS
+ || last_entry.ut_type == LOGIN_PROCESS
+ || last_entry.ut_type == USER_PROCESS
+ || last_entry.ut_type == DEAD_PROCESS)
+ && (data->ut_id[0] && last_entry.ut_id[0]
+ ? strncmp (data->ut_id, last_entry.ut_id,
+ sizeof last_entry.ut_id)
+ == 0
+ : (strncmp (data->ut_line, last_entry.ut_line,
+ sizeof last_entry.ut_line)
+ == 0));
}
/* Locking timeout. */
@@ -129,10 +143,6 @@ file_unlock (int fd)
__fcntl64_nocancel (fd, F_SETLKW, &fl);
}
-#ifndef TRANSFORM_UTMP_FILE_NAME
-# define TRANSFORM_UTMP_FILE_NAME(file_name) (file_name)
-#endif
-
int
__libc_setutent (void)
{
@@ -140,7 +150,7 @@ __libc_setutent (void)
{
const char *file_name;
- file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
+ file_name = utmp_file_name_time32 (__libc_utmp_file_name);
file_writable = false;
file_fd = __open_nocancel
@@ -353,7 +363,7 @@ __libc_pututline (const struct utmp *data)
if (! file_writable)
{
/* We must make the file descriptor writable before going on. */
- const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
+ const char *file_name = utmp_file_name_time32 (__libc_utmp_file_name);
int new_fd = __open_nocancel
(file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC);
@@ -1234,7 +1234,7 @@ over again.
@c pututline_unknown @mtasurace:utent @acsfd
@c setutent_unknown dup @mtasurace:utent @acsfd
@c pututline_file @mtascusig:ALRM @mtascutimer @acsfd
-@c TRANSFORM_UTMP_FILE_NAME ok
+@c utmp_file_name_time32 ok
@c strcmp dup ok
@c acesss dup ok
@c open_not_cancel_2 dup @acsfd
@@ -1427,7 +1427,7 @@ the following function:
@standards{SVID, utmp.h}
@safety{@prelim{}@mtunsafe{@mtascusig{:ALRM} @mtascutimer{}}@asunsafe{}@acunsafe{@acsfd{}}}
@c updwtmp @mtascusig:ALRM @mtascutimer @acsfd
-@c TRANSFORM_UTMP_FILE_NAME dup ok
+@c utmp_file_name_time32 dup ok
@c *libc_utmp_file_functions->updwtmp = updwtmp_file @mtascusig:ALRM @mtascutimer @acsfd
@c open_not_cancel_2 dup @acsfd
@c LOCK_FILE dup @mtascusig:ALRM @mtascutimer
@@ -60,10 +60,12 @@
#define _PATH_SHELLS "/etc/shells"
#define _PATH_TTY "/dev/tty"
#define _PATH_UNIX "/vmunix"
-#define _PATH_UTMP "/var/run/utmp"
-#define _PATH_UTMP_DB "/var/run/utmp.db"
+#define _PATH_UTMP_BASE "/var/run/utmp"
+#define _PATH_UTMP _PATH_UTMP_BASE
+#define _PATH_UTMP_DB _PATH_UTMP_BASE ".db"
#define _PATH_VI "/usr/bin/vi"
-#define _PATH_WTMP "/var/log/wtmp"
+#define _PATH_WTMP_BASE "/var/log/wtmp"
+#define _PATH_WTMP _PATH_WTMP_BASE
/* Provide trailing slash, since mostly used for building pathnames. */
#define _PATH_DEV "/dev/"
deleted file mode 100644
@@ -1,42 +0,0 @@
-/* Helper function for utmp functions to see if two entries are equal.
- Copyright (C) 1996-2021 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.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <string.h>
-#include <utmp.h>
-
-#include "utmp-private.h"
-
-/* Test whether two entries match. */
-static int
-__utmp_equal (const struct utmp *entry, const struct utmp *match)
-{
- return (entry->ut_type == INIT_PROCESS
- || entry->ut_type == LOGIN_PROCESS
- || entry->ut_type == USER_PROCESS
- || entry->ut_type == DEAD_PROCESS)
- && (match->ut_type == INIT_PROCESS
- || match->ut_type == LOGIN_PROCESS
- || match->ut_type == USER_PROCESS
- || match->ut_type == DEAD_PROCESS)
- && (entry->ut_id[0] && match->ut_id[0]
- ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
- : (strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line)
- == 0));
-}
@@ -61,9 +61,11 @@
#define _PATH_SHELLS "/etc/shells"
#define _PATH_TTY "/dev/tty"
#define _PATH_UNIX "/boot/vmlinux"
-#define _PATH_UTMP "/var/run/utmp"
+#define _PATH_UTMP_BASE "/var/run/utmp"
+#define _PATH_UTMP _PATH_UTMP_BASE
#define _PATH_VI "/usr/bin/vi"
-#define _PATH_WTMP "/var/log/wtmp"
+#define _PATH_WTMP_BASE "/var/log/wtmp"
+#define _PATH_WTMP _PATH_WTMP_BASE
/* Provide trailing slash, since mostly used for building pathnames. */
#define _PATH_DEV "/dev/"
deleted file mode 100644
@@ -1,37 +0,0 @@
-/* Copyright (C) 1998-2021 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <string.h>
-#include <unistd.h>
-
-#define TRANSFORM_UTMP_FILE_NAME(file_name) \
- ((strcmp (file_name, _PATH_UTMP) == 0 \
- && __access (_PATH_UTMP "x", F_OK) == 0) \
- ? (_PATH_UTMP "x") \
- : ((strcmp (file_name, _PATH_WTMP) == 0 \
- && __access ( _PATH_WTMP "x", F_OK) == 0) \
- ? (_PATH_WTMP "x") \
- : ((strcmp (file_name, _PATH_UTMP "x") == 0 \
- && __access (_PATH_UTMP "x", F_OK) != 0) \
- ? _PATH_UTMP \
- : ((strcmp (file_name, _PATH_WTMP "x") == 0 \
- && __access (_PATH_WTMP "x", F_OK) != 0) \
- ? _PATH_WTMP \
- : file_name))))
-
-#include <login/updwtmp.c>
new file mode 100644
@@ -0,0 +1,55 @@
+/* Handle {u,w}tmp and {u,w}tmpx file name usage.
+ Copyright (C) 1998-2021 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _UTMP_PATH_H
+#define _UTMP_PATH_H 1
+
+#include <string.h>
+#include <unistd.h>
+
+
+/* The function returns the utmp database for 32-bit utmp{x} entries based
+ on FILE_NAME:
+
+ - if the default {x,w}utmp name is used but a file name ending with 'x'
+ exists it is returned instead
+
+ - if the argument ends with 'x' and the file is not accessible the default
+ {x,w}utmp is returned instead.
+
+ - if neither 1. nor 2. applies, the FILE_NAME is returned instead. */
+static inline const char *
+utmp_file_name_time32 (const char *file_name)
+{
+ if (strcmp (file_name, _PATH_UTMP_BASE) == 0
+ && __access (_PATH_UTMP_BASE "x", F_OK) == 0)
+ return _PATH_UTMP_BASE "x";
+ else if (strcmp (file_name, _PATH_WTMP_BASE) == 0
+ && __access (_PATH_WTMP_BASE "x", F_OK) == 0)
+ return _PATH_WTMP_BASE "x";
+ else if (strcmp (file_name, _PATH_UTMP_BASE "x") == 0
+ && __access (_PATH_UTMP_BASE "x", F_OK) != 0)
+ return _PATH_UTMP_BASE;
+ else if (strcmp (file_name, _PATH_WTMP_BASE "x") == 0
+ && __access (_PATH_WTMP_BASE "x", F_OK) != 0)
+ return _PATH_WTMP_BASE;
+
+ return file_name;
+}
+
+#endif /* _UTMP_PATH_H */
deleted file mode 100644
@@ -1,37 +0,0 @@
-/* Copyright (C) 1998-2021 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <string.h>
-#include <unistd.h>
-
-#define TRANSFORM_UTMP_FILE_NAME(file_name) \
- ((strcmp (file_name, _PATH_UTMP) == 0 \
- && __access (_PATH_UTMP "x", F_OK) == 0) \
- ? (_PATH_UTMP "x") \
- : ((strcmp (file_name, _PATH_WTMP) == 0 \
- && __access ( _PATH_WTMP "x", F_OK) == 0) \
- ? (_PATH_WTMP "x") \
- : ((strcmp (file_name, _PATH_UTMP "x") == 0 \
- && __access (_PATH_UTMP "x", F_OK) != 0) \
- ? _PATH_UTMP \
- : ((strcmp (file_name, _PATH_WTMP "x") == 0 \
- && __access (_PATH_WTMP "x", F_OK) != 0) \
- ? _PATH_WTMP \
- : file_name))))
-
-#include <login/utmp_file.c>