mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
login: Assume that _HAVE_UT_* constants are true
Make the GNU version of bits/utmp.h the generic version because all remaining ports use it (with a sysdeps override for Linux s390/s390x).
This commit is contained in:
26
ChangeLog
26
ChangeLog
@ -1,3 +1,29 @@
|
|||||||
|
2019-08-13 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* login/getutid_r.c (__getutid_r): _HAVE_UT_ID and _HAVE_UT_TYPE
|
||||||
|
are always true.
|
||||||
|
* login/getutmp.c (getutmp): _HAVE_UT_TYPE, _HAVE_UT_PID,
|
||||||
|
_HAVE_UT_ID, _HAVE_UT_HOST, _HAVE_UT_TV are always true.
|
||||||
|
* login/getutmpx.c (getutmpx): Likewise.
|
||||||
|
* login/login.c (login): _HAVE_UT_TYPE, _HAVE_UT_PID are always
|
||||||
|
true.
|
||||||
|
* login/logout.c (logout): _HAVE_UT_TYPE, _HAVE_UT_HOST,
|
||||||
|
_HAVE_UT_TV are always true.
|
||||||
|
* login/logwtmp.c (logwtmp): _HAVE_UT_PID, _HAVE_UT_TYPE,
|
||||||
|
_HAVE_UT_HOST, _HAVE_UT_TV are always true.
|
||||||
|
* login/tst-utmp.c: _HAVE_UT_TYPE, _HAVE_UT_TV are always true.
|
||||||
|
* login/utmp_file.c (__libc_setutent): _HAVE_UT_TYPE, _HAVE_UT_ID
|
||||||
|
are always true.
|
||||||
|
(internal_getut_r): _HAVE_UT_TYPE is always true.
|
||||||
|
(__libc_pututline): Likewise.
|
||||||
|
* login/programs/utmpdump.c (print_entry): Assume that
|
||||||
|
_HAVE_UT_TYPE, _HAVE_UT_PID, _HAVE_UT_ID, _HAVE_UT_HOST,
|
||||||
|
_HAVE_UT_TV are always true.
|
||||||
|
* sysdeps/generic/utmp-equal.h (__utmp_equal): _HAVE_UT_TYPE,
|
||||||
|
_HAVE_UT_ID are always true.
|
||||||
|
* sysdeps/gnu/bits/utmp.h: Move to ...
|
||||||
|
* bits/utmp.h: ... here, replacing the old file.
|
||||||
|
|
||||||
2019-08-12 Florian Weimer <fweimer@redhat.com>
|
2019-08-12 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
* elf/Makefile (tests): Unconditionally add tst-dlopen-aout.
|
* elf/Makefile (tests): Unconditionally add tst-dlopen-aout.
|
||||||
|
103
bits/utmp.h
103
bits/utmp.h
@ -1,4 +1,4 @@
|
|||||||
/* The `struct utmp' type, describing entries in the utmp file. Generic/BSDish
|
/* The `struct utmp' type, describing entries in the utmp file.
|
||||||
Copyright (C) 1993-2019 Free Software Foundation, Inc.
|
Copyright (C) 1993-2019 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
@ -21,29 +21,106 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <time.h>
|
#include <sys/time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <bits/wordsize.h>
|
||||||
|
|
||||||
|
|
||||||
#define UT_NAMESIZE 8
|
#define UT_LINESIZE 32
|
||||||
#define UT_LINESIZE 8
|
#define UT_NAMESIZE 32
|
||||||
#define UT_HOSTSIZE 16
|
#define UT_HOSTSIZE 256
|
||||||
|
|
||||||
|
|
||||||
|
/* The structure describing an entry in the database of
|
||||||
|
previous logins. */
|
||||||
struct lastlog
|
struct lastlog
|
||||||
{
|
{
|
||||||
time_t ll_time;
|
#if __WORDSIZE_TIME64_COMPAT32
|
||||||
|
int32_t ll_time;
|
||||||
|
#else
|
||||||
|
__time_t ll_time;
|
||||||
|
#endif
|
||||||
char ll_line[UT_LINESIZE];
|
char ll_line[UT_LINESIZE];
|
||||||
char ll_host[UT_HOSTSIZE];
|
char ll_host[UT_HOSTSIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct utmp
|
|
||||||
|
/* The structure describing the status of a terminated process. This
|
||||||
|
type is used in `struct utmp' below. */
|
||||||
|
struct exit_status
|
||||||
{
|
{
|
||||||
char ut_line[UT_LINESIZE];
|
short int e_termination; /* Process termination status. */
|
||||||
char ut_user[UT_NAMESIZE];
|
short int e_exit; /* Process exit status. */
|
||||||
#define ut_name ut_user
|
|
||||||
char ut_host[UT_HOSTSIZE];
|
|
||||||
long int ut_time;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define _HAVE_UT_HOST 1 /* We have the ut_host field. */
|
/* The structure describing an entry in the user accounting database. */
|
||||||
|
struct utmp
|
||||||
|
{
|
||||||
|
short int ut_type; /* Type of login. */
|
||||||
|
pid_t ut_pid; /* Process ID of login process. */
|
||||||
|
char ut_line[UT_LINESIZE]
|
||||||
|
__attribute_nonstring__; /* Devicename. */
|
||||||
|
char ut_id[4]; /* Inittab ID. */
|
||||||
|
char ut_user[UT_NAMESIZE]
|
||||||
|
__attribute_nonstring__; /* Username. */
|
||||||
|
char ut_host[UT_HOSTSIZE]
|
||||||
|
__attribute_nonstring__; /* Hostname for remote login. */
|
||||||
|
struct exit_status ut_exit; /* Exit status of a process marked
|
||||||
|
as DEAD_PROCESS. */
|
||||||
|
/* The ut_session and ut_tv fields must be the same size when compiled
|
||||||
|
32- and 64-bit. This allows data files and shared memory to be
|
||||||
|
shared between 32- and 64-bit applications. */
|
||||||
|
#if __WORDSIZE_TIME64_COMPAT32
|
||||||
|
int32_t ut_session; /* Session ID, used for windowing. */
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int32_t tv_sec; /* Seconds. */
|
||||||
|
int32_t tv_usec; /* Microseconds. */
|
||||||
|
} ut_tv; /* Time entry was made. */
|
||||||
|
#else
|
||||||
|
long int ut_session; /* Session ID, used for windowing. */
|
||||||
|
struct timeval ut_tv; /* Time entry was made. */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t ut_addr_v6[4]; /* Internet address of remote host. */
|
||||||
|
char __glibc_reserved[20]; /* Reserved for future use. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Backwards compatibility hacks. */
|
||||||
|
#define ut_name ut_user
|
||||||
|
#ifndef _NO_UT_TIME
|
||||||
|
/* We have a problem here: `ut_time' is also used otherwise. Define
|
||||||
|
_NO_UT_TIME if the compiler complains. */
|
||||||
|
# define ut_time ut_tv.tv_sec
|
||||||
|
#endif
|
||||||
|
#define ut_xtime ut_tv.tv_sec
|
||||||
|
#define ut_addr ut_addr_v6[0]
|
||||||
|
|
||||||
|
|
||||||
|
/* Values for the `ut_type' field of a `struct utmp'. */
|
||||||
|
#define EMPTY 0 /* No valid user accounting information. */
|
||||||
|
|
||||||
|
#define RUN_LVL 1 /* The system's runlevel. */
|
||||||
|
#define BOOT_TIME 2 /* Time of system boot. */
|
||||||
|
#define NEW_TIME 3 /* Time after system clock changed. */
|
||||||
|
#define OLD_TIME 4 /* Time when system clock changed. */
|
||||||
|
|
||||||
|
#define INIT_PROCESS 5 /* Process spawned by the init process. */
|
||||||
|
#define LOGIN_PROCESS 6 /* Session leader of a logged in user. */
|
||||||
|
#define USER_PROCESS 7 /* Normal process. */
|
||||||
|
#define DEAD_PROCESS 8 /* Terminated process. */
|
||||||
|
|
||||||
|
#define ACCOUNTING 9
|
||||||
|
|
||||||
|
/* Old Linux name for the EMPTY type. */
|
||||||
|
#define UT_UNKNOWN EMPTY
|
||||||
|
|
||||||
|
|
||||||
|
/* Tell the user that we have a modern system with UT_HOST, UT_PID,
|
||||||
|
UT_TYPE, UT_ID and UT_TV fields. */
|
||||||
|
#define _HAVE_UT_TYPE 1
|
||||||
|
#define _HAVE_UT_PID 1
|
||||||
|
#define _HAVE_UT_ID 1
|
||||||
|
#define _HAVE_UT_TV 1
|
||||||
|
#define _HAVE_UT_HOST 1
|
||||||
|
@ -32,7 +32,6 @@ __libc_lock_define (extern, __libc_utmp_lock attribute_hidden)
|
|||||||
int
|
int
|
||||||
__getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result)
|
__getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result)
|
||||||
{
|
{
|
||||||
#if (_HAVE_UT_ID - 0) && (_HAVE_UT_TYPE - 0)
|
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
/* Test whether ID has any of the legal types. */
|
/* Test whether ID has any of the legal types. */
|
||||||
@ -54,10 +53,6 @@ __getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result)
|
|||||||
__libc_lock_unlock (__libc_utmp_lock);
|
__libc_lock_unlock (__libc_utmp_lock);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
#else /* !_HAVE_UT_ID && !_HAVE_UT_TYPE */
|
|
||||||
__set_errno (ENOSYS);
|
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
libc_hidden_def (__getutid_r)
|
libc_hidden_def (__getutid_r)
|
||||||
weak_alias (__getutid_r, getutid_r)
|
weak_alias (__getutid_r, getutid_r)
|
||||||
|
@ -23,23 +23,11 @@
|
|||||||
void
|
void
|
||||||
getutmp (const struct utmpx *utmpx, struct utmp *utmp)
|
getutmp (const struct utmpx *utmpx, struct utmp *utmp)
|
||||||
{
|
{
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
utmp->ut_type = utmpx->ut_type;
|
utmp->ut_type = utmpx->ut_type;
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_PID - 0
|
|
||||||
utmp->ut_pid = utmpx->ut_pid;
|
utmp->ut_pid = utmpx->ut_pid;
|
||||||
#endif
|
|
||||||
memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line));
|
memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line));
|
||||||
memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user));
|
memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user));
|
||||||
#if _HAVE_UT_ID - 0
|
|
||||||
memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id));
|
memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id));
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_HOST - 0
|
|
||||||
memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host));
|
memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host));
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_TV - 0
|
|
||||||
utmp->ut_tv = utmpx->ut_tv;
|
utmp->ut_tv = utmpx->ut_tv;
|
||||||
#else
|
|
||||||
utmp->ut_time = utmpx->ut_time;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -24,24 +24,11 @@ void
|
|||||||
getutmpx (const struct utmp *utmp, struct utmpx *utmpx)
|
getutmpx (const struct utmp *utmp, struct utmpx *utmpx)
|
||||||
{
|
{
|
||||||
memset (utmpx, 0, sizeof (struct utmpx));
|
memset (utmpx, 0, sizeof (struct utmpx));
|
||||||
|
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
utmpx->ut_type = utmp->ut_type;
|
utmpx->ut_type = utmp->ut_type;
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_PID - 0
|
|
||||||
utmpx->ut_pid = utmp->ut_pid;
|
utmpx->ut_pid = utmp->ut_pid;
|
||||||
#endif
|
|
||||||
memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line));
|
memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line));
|
||||||
memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user));
|
memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user));
|
||||||
#if _HAVE_UT_ID - 0
|
|
||||||
memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id));
|
memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id));
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_HOST - 0
|
|
||||||
memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host));
|
memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host));
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_TV - 0
|
|
||||||
utmpx->ut_tv = utmp->ut_tv;
|
utmpx->ut_tv = utmp->ut_tv;
|
||||||
#else
|
|
||||||
utmpx->ut_time = utmp->ut_time;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -91,12 +91,8 @@ login (const struct utmp *ut)
|
|||||||
struct utmp copy = *ut;
|
struct utmp copy = *ut;
|
||||||
|
|
||||||
/* Fill in those fields we supply. */
|
/* Fill in those fields we supply. */
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
copy.ut_type = USER_PROCESS;
|
copy.ut_type = USER_PROCESS;
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_PID - 0
|
|
||||||
copy.ut_pid = getpid ();
|
copy.ut_pid = getpid ();
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Seek tty. */
|
/* Seek tty. */
|
||||||
found_tty = tty_name (STDIN_FILENO, &tty, sizeof (_tty));
|
found_tty = tty_name (STDIN_FILENO, &tty, sizeof (_tty));
|
||||||
|
@ -36,9 +36,7 @@ logout (const char *line)
|
|||||||
setutent ();
|
setutent ();
|
||||||
|
|
||||||
/* Fill in search information. */
|
/* Fill in search information. */
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
tmp.ut_type = USER_PROCESS;
|
tmp.ut_type = USER_PROCESS;
|
||||||
#endif
|
|
||||||
strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
|
strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
|
||||||
|
|
||||||
/* Read the record. */
|
/* Read the record. */
|
||||||
@ -46,20 +44,12 @@ logout (const char *line)
|
|||||||
{
|
{
|
||||||
/* Clear information about who & from where. */
|
/* Clear information about who & from where. */
|
||||||
memset (ut->ut_name, '\0', sizeof ut->ut_name);
|
memset (ut->ut_name, '\0', sizeof ut->ut_name);
|
||||||
#if _HAVE_UT_HOST - 0
|
|
||||||
memset (ut->ut_host, '\0', sizeof ut->ut_host);
|
memset (ut->ut_host, '\0', sizeof ut->ut_host);
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_TV - 0
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
__gettimeofday (&tv, NULL);
|
__gettimeofday (&tv, NULL);
|
||||||
ut->ut_tv.tv_sec = tv.tv_sec;
|
ut->ut_tv.tv_sec = tv.tv_sec;
|
||||||
ut->ut_tv.tv_usec = tv.tv_usec;
|
ut->ut_tv.tv_usec = tv.tv_usec;
|
||||||
#else
|
|
||||||
ut->ut_time = time (NULL);
|
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
ut->ut_type = DEAD_PROCESS;
|
ut->ut_type = DEAD_PROCESS;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (pututline (ut) != NULL)
|
if (pututline (ut) != NULL)
|
||||||
result = 1;
|
result = 1;
|
||||||
|
@ -30,26 +30,16 @@ logwtmp (const char *line, const char *name, const char *host)
|
|||||||
|
|
||||||
/* Set information in new entry. */
|
/* Set information in new entry. */
|
||||||
memset (&ut, 0, sizeof (ut));
|
memset (&ut, 0, sizeof (ut));
|
||||||
#if _HAVE_UT_PID - 0
|
|
||||||
ut.ut_pid = getpid ();
|
ut.ut_pid = getpid ();
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS;
|
ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS;
|
||||||
#endif
|
|
||||||
strncpy (ut.ut_line, line, sizeof ut.ut_line);
|
strncpy (ut.ut_line, line, sizeof ut.ut_line);
|
||||||
strncpy (ut.ut_name, name, sizeof ut.ut_name);
|
strncpy (ut.ut_name, name, sizeof ut.ut_name);
|
||||||
#if _HAVE_UT_HOST - 0
|
|
||||||
strncpy (ut.ut_host, host, sizeof ut.ut_host);
|
strncpy (ut.ut_host, host, sizeof ut.ut_host);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if _HAVE_UT_TV - 0
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
__gettimeofday (&tv, NULL);
|
__gettimeofday (&tv, NULL);
|
||||||
ut.ut_tv.tv_sec = tv.tv_sec;
|
ut.ut_tv.tv_sec = tv.tv_sec;
|
||||||
ut.ut_tv.tv_usec = tv.tv_usec;
|
ut.ut_tv.tv_usec = tv.tv_usec;
|
||||||
#else
|
|
||||||
ut.ut_time = time (NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
updwtmp (_PATH_WTMP, &ut);
|
updwtmp (_PATH_WTMP, &ut);
|
||||||
}
|
}
|
||||||
|
@ -37,47 +37,11 @@ print_entry (struct utmp *up)
|
|||||||
temp_tv.tv_sec = up->ut_tv.tv_sec;
|
temp_tv.tv_sec = up->ut_tv.tv_sec;
|
||||||
temp_tv.tv_usec = up->ut_tv.tv_usec;
|
temp_tv.tv_usec = up->ut_tv.tv_usec;
|
||||||
|
|
||||||
(printf) (
|
printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-16.16s] [%-15.15s]"
|
||||||
/* The format string. */
|
" [%ld]\n",
|
||||||
#if _HAVE_UT_TYPE
|
up->ut_type, up->ut_pid, up->ut_id, up->ut_user, up->ut_line,
|
||||||
"[%d] "
|
up->ut_host, 4 + ctime (&temp_tv.tv_sec),
|
||||||
#endif
|
(long int) temp_tv.tv_usec);
|
||||||
#if _HAVE_UT_PID
|
|
||||||
"[%05d] "
|
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_ID
|
|
||||||
"[%-4.4s] "
|
|
||||||
#endif
|
|
||||||
"[%-8.8s] [%-12.12s]"
|
|
||||||
#if _HAVE_UT_HOST
|
|
||||||
" [%-16.16s]"
|
|
||||||
#endif
|
|
||||||
" [%-15.15s]"
|
|
||||||
#if _HAVE_UT_TV
|
|
||||||
" [%ld]"
|
|
||||||
#endif
|
|
||||||
"\n"
|
|
||||||
/* The arguments. */
|
|
||||||
#if _HAVE_UT_TYPE
|
|
||||||
, up->ut_type
|
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_PID
|
|
||||||
, up->ut_pid
|
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_ID
|
|
||||||
, up->ut_id
|
|
||||||
#endif
|
|
||||||
, up->ut_user, up->ut_line
|
|
||||||
#if _HAVE_UT_HOST
|
|
||||||
, up->ut_host
|
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_TV
|
|
||||||
, 4 + ctime (&temp_tv.tv_sec)
|
|
||||||
, (long int) temp_tv.tv_usec
|
|
||||||
#else
|
|
||||||
, 4 + ctime (&up->ut_time)
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -39,8 +39,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined UTMPX || _HAVE_UT_TYPE
|
|
||||||
|
|
||||||
/* Prototype for our test function. */
|
/* Prototype for our test function. */
|
||||||
static int do_test (int argc, char *argv[]);
|
static int do_test (int argc, char *argv[]);
|
||||||
|
|
||||||
@ -75,11 +73,7 @@ do_prepare (int argc, char *argv[])
|
|||||||
|
|
||||||
struct utmp entry[] =
|
struct utmp entry[] =
|
||||||
{
|
{
|
||||||
#if defined UTMPX || _HAVE_UT_TV
|
|
||||||
#define UT(a) .ut_tv = { .tv_sec = (a)}
|
#define UT(a) .ut_tv = { .tv_sec = (a)}
|
||||||
#else
|
|
||||||
#define UT(a) .ut_time = (a)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{ .ut_type = BOOT_TIME, .ut_pid = 1, UT(1000) },
|
{ .ut_type = BOOT_TIME, .ut_pid = 1, UT(1000) },
|
||||||
{ .ut_type = RUN_LVL, .ut_pid = 1, UT(2000) },
|
{ .ut_type = RUN_LVL, .ut_pid = 1, UT(2000) },
|
||||||
@ -167,11 +161,7 @@ simulate_login (const char *line, const char *user)
|
|||||||
entry[n].ut_pid = (entry_pid += 27);
|
entry[n].ut_pid = (entry_pid += 27);
|
||||||
entry[n].ut_type = USER_PROCESS;
|
entry[n].ut_type = USER_PROCESS;
|
||||||
strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user));
|
strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user));
|
||||||
#if defined UTMPX || _HAVE_UT_TV - 0
|
|
||||||
entry[n].ut_tv.tv_sec = (entry_time += 1000);
|
entry[n].ut_tv.tv_sec = (entry_time += 1000);
|
||||||
#else
|
|
||||||
entry[n].ut_time = (entry_time += 1000);
|
|
||||||
#endif
|
|
||||||
setutent ();
|
setutent ();
|
||||||
|
|
||||||
if (pututline (&entry[n]) == NULL)
|
if (pututline (&entry[n]) == NULL)
|
||||||
@ -201,11 +191,7 @@ simulate_logout (const char *line)
|
|||||||
{
|
{
|
||||||
entry[n].ut_type = DEAD_PROCESS;
|
entry[n].ut_type = DEAD_PROCESS;
|
||||||
strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
|
strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
|
||||||
#if defined UTMPX || _HAVE_UT_TV - 0
|
|
||||||
entry[n].ut_tv.tv_sec = (entry_time += 1000);
|
entry[n].ut_tv.tv_sec = (entry_time += 1000);
|
||||||
#else
|
|
||||||
entry[n].ut_time = (entry_time += 1000);
|
|
||||||
#endif
|
|
||||||
setutent ();
|
setutent ();
|
||||||
|
|
||||||
if (pututline (&entry[n]) == NULL)
|
if (pututline (&entry[n]) == NULL)
|
||||||
@ -390,14 +376,3 @@ do_test (int argc, char *argv[])
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* No field 'ut_type' in struct utmp. */
|
|
||||||
int
|
|
||||||
main (void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -129,14 +129,7 @@ __libc_setutent (void)
|
|||||||
file_offset = 0;
|
file_offset = 0;
|
||||||
|
|
||||||
/* Make sure the entry won't match. */
|
/* Make sure the entry won't match. */
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
last_entry.ut_type = -1;
|
last_entry.ut_type = -1;
|
||||||
#else
|
|
||||||
last_entry.ut_line[0] = '\177';
|
|
||||||
# if _HAVE_UT_ID - 0
|
|
||||||
last_entry.ut_id[0] = '\0';
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -201,7 +194,6 @@ internal_getut_r (const struct utmp *id, struct utmp *buffer,
|
|||||||
LOCKING_FAILED ();
|
LOCKING_FAILED ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
|
if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
|
||||||
|| id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
|
|| id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
|
||||||
{
|
{
|
||||||
@ -225,7 +217,6 @@ internal_getut_r (const struct utmp *id, struct utmp *buffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* _HAVE_UT_TYPE */
|
|
||||||
{
|
{
|
||||||
/* Search for the next entry with the specified ID and with type
|
/* Search for the next entry with the specified ID and with type
|
||||||
INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS. */
|
INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS. */
|
||||||
@ -316,13 +307,10 @@ __libc_getutline_r (const struct utmp *line, struct utmp *buffer,
|
|||||||
file_offset += sizeof (struct utmp);
|
file_offset += sizeof (struct utmp);
|
||||||
|
|
||||||
/* Stop if we found a user or login entry. */
|
/* Stop if we found a user or login entry. */
|
||||||
if (
|
if ((last_entry.ut_type == USER_PROCESS
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
(last_entry.ut_type == USER_PROCESS
|
|
||||||
|| last_entry.ut_type == LOGIN_PROCESS)
|
|| last_entry.ut_type == LOGIN_PROCESS)
|
||||||
&&
|
&& (strncmp (line->ut_line, last_entry.ut_line, sizeof line->ut_line)
|
||||||
#endif
|
== 0))
|
||||||
!strncmp (line->ut_line, last_entry.ut_line, sizeof line->ut_line))
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,16 +356,12 @@ __libc_pututline (const struct utmp *data)
|
|||||||
|
|
||||||
/* Find the correct place to insert the data. */
|
/* Find the correct place to insert the data. */
|
||||||
if (file_offset > 0
|
if (file_offset > 0
|
||||||
&& (
|
&& ((last_entry.ut_type == data->ut_type
|
||||||
#if _HAVE_UT_TYPE - 0
|
|
||||||
(last_entry.ut_type == data->ut_type
|
|
||||||
&& (last_entry.ut_type == RUN_LVL
|
&& (last_entry.ut_type == RUN_LVL
|
||||||
|| last_entry.ut_type == BOOT_TIME
|
|| last_entry.ut_type == BOOT_TIME
|
||||||
|| last_entry.ut_type == OLD_TIME
|
|| last_entry.ut_type == OLD_TIME
|
||||||
|| last_entry.ut_type == NEW_TIME))
|
|| last_entry.ut_type == NEW_TIME))
|
||||||
||
|
|| __utmp_equal (&last_entry, data)))
|
||||||
#endif
|
|
||||||
__utmp_equal (&last_entry, data)))
|
|
||||||
found = 1;
|
found = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -27,26 +27,16 @@
|
|||||||
static int
|
static int
|
||||||
__utmp_equal (const struct utmp *entry, const struct utmp *match)
|
__utmp_equal (const struct utmp *entry, const struct utmp *match)
|
||||||
{
|
{
|
||||||
return
|
return (entry->ut_type == INIT_PROCESS
|
||||||
(
|
|| entry->ut_type == LOGIN_PROCESS
|
||||||
#if _HAVE_UT_TYPE - 0
|
|| entry->ut_type == USER_PROCESS
|
||||||
(entry->ut_type == INIT_PROCESS
|
|| entry->ut_type == DEAD_PROCESS)
|
||||||
|| entry->ut_type == LOGIN_PROCESS
|
&& (match->ut_type == INIT_PROCESS
|
||||||
|| entry->ut_type == USER_PROCESS
|
|| match->ut_type == LOGIN_PROCESS
|
||||||
|| entry->ut_type == DEAD_PROCESS)
|
|| match->ut_type == USER_PROCESS
|
||||||
&&
|
|| match->ut_type == DEAD_PROCESS)
|
||||||
(match->ut_type == INIT_PROCESS
|
&& (entry->ut_id[0] && match->ut_id[0]
|
||||||
|| match->ut_type == LOGIN_PROCESS
|
? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
|
||||||
|| match->ut_type == USER_PROCESS
|
: (strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line)
|
||||||
|| match->ut_type == DEAD_PROCESS)
|
== 0));
|
||||||
&&
|
|
||||||
#endif
|
|
||||||
#if _HAVE_UT_ID - 0
|
|
||||||
(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)
|
|
||||||
#else
|
|
||||||
strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -1,126 +0,0 @@
|
|||||||
/* The `struct utmp' type, describing entries in the utmp file. GNU version.
|
|
||||||
Copyright (C) 1993-2019 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
|
|
||||||
<http://www.gnu.org/licenses/>. */
|
|
||||||
|
|
||||||
#ifndef _UTMP_H
|
|
||||||
# error "Never include <bits/utmp.h> directly; use <utmp.h> instead."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <paths.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <bits/wordsize.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define UT_LINESIZE 32
|
|
||||||
#define UT_NAMESIZE 32
|
|
||||||
#define UT_HOSTSIZE 256
|
|
||||||
|
|
||||||
|
|
||||||
/* The structure describing an entry in the database of
|
|
||||||
previous logins. */
|
|
||||||
struct lastlog
|
|
||||||
{
|
|
||||||
#if __WORDSIZE_TIME64_COMPAT32
|
|
||||||
int32_t ll_time;
|
|
||||||
#else
|
|
||||||
__time_t ll_time;
|
|
||||||
#endif
|
|
||||||
char ll_line[UT_LINESIZE];
|
|
||||||
char ll_host[UT_HOSTSIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* The structure describing the status of a terminated process. This
|
|
||||||
type is used in `struct utmp' below. */
|
|
||||||
struct exit_status
|
|
||||||
{
|
|
||||||
short int e_termination; /* Process termination status. */
|
|
||||||
short int e_exit; /* Process exit status. */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* The structure describing an entry in the user accounting database. */
|
|
||||||
struct utmp
|
|
||||||
{
|
|
||||||
short int ut_type; /* Type of login. */
|
|
||||||
pid_t ut_pid; /* Process ID of login process. */
|
|
||||||
char ut_line[UT_LINESIZE]
|
|
||||||
__attribute_nonstring__; /* Devicename. */
|
|
||||||
char ut_id[4]; /* Inittab ID. */
|
|
||||||
char ut_user[UT_NAMESIZE]
|
|
||||||
__attribute_nonstring__; /* Username. */
|
|
||||||
char ut_host[UT_HOSTSIZE]
|
|
||||||
__attribute_nonstring__; /* Hostname for remote login. */
|
|
||||||
struct exit_status ut_exit; /* Exit status of a process marked
|
|
||||||
as DEAD_PROCESS. */
|
|
||||||
/* The ut_session and ut_tv fields must be the same size when compiled
|
|
||||||
32- and 64-bit. This allows data files and shared memory to be
|
|
||||||
shared between 32- and 64-bit applications. */
|
|
||||||
#if __WORDSIZE_TIME64_COMPAT32
|
|
||||||
int32_t ut_session; /* Session ID, used for windowing. */
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
int32_t tv_sec; /* Seconds. */
|
|
||||||
int32_t tv_usec; /* Microseconds. */
|
|
||||||
} ut_tv; /* Time entry was made. */
|
|
||||||
#else
|
|
||||||
long int ut_session; /* Session ID, used for windowing. */
|
|
||||||
struct timeval ut_tv; /* Time entry was made. */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int32_t ut_addr_v6[4]; /* Internet address of remote host. */
|
|
||||||
char __glibc_reserved[20]; /* Reserved for future use. */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Backwards compatibility hacks. */
|
|
||||||
#define ut_name ut_user
|
|
||||||
#ifndef _NO_UT_TIME
|
|
||||||
/* We have a problem here: `ut_time' is also used otherwise. Define
|
|
||||||
_NO_UT_TIME if the compiler complains. */
|
|
||||||
# define ut_time ut_tv.tv_sec
|
|
||||||
#endif
|
|
||||||
#define ut_xtime ut_tv.tv_sec
|
|
||||||
#define ut_addr ut_addr_v6[0]
|
|
||||||
|
|
||||||
|
|
||||||
/* Values for the `ut_type' field of a `struct utmp'. */
|
|
||||||
#define EMPTY 0 /* No valid user accounting information. */
|
|
||||||
|
|
||||||
#define RUN_LVL 1 /* The system's runlevel. */
|
|
||||||
#define BOOT_TIME 2 /* Time of system boot. */
|
|
||||||
#define NEW_TIME 3 /* Time after system clock changed. */
|
|
||||||
#define OLD_TIME 4 /* Time when system clock changed. */
|
|
||||||
|
|
||||||
#define INIT_PROCESS 5 /* Process spawned by the init process. */
|
|
||||||
#define LOGIN_PROCESS 6 /* Session leader of a logged in user. */
|
|
||||||
#define USER_PROCESS 7 /* Normal process. */
|
|
||||||
#define DEAD_PROCESS 8 /* Terminated process. */
|
|
||||||
|
|
||||||
#define ACCOUNTING 9
|
|
||||||
|
|
||||||
/* Old Linux name for the EMPTY type. */
|
|
||||||
#define UT_UNKNOWN EMPTY
|
|
||||||
|
|
||||||
|
|
||||||
/* Tell the user that we have a modern system with UT_HOST, UT_PID,
|
|
||||||
UT_TYPE, UT_ID and UT_TV fields. */
|
|
||||||
#define _HAVE_UT_TYPE 1
|
|
||||||
#define _HAVE_UT_PID 1
|
|
||||||
#define _HAVE_UT_ID 1
|
|
||||||
#define _HAVE_UT_TV 1
|
|
||||||
#define _HAVE_UT_HOST 1
|
|
Reference in New Issue
Block a user