Compare commits
13 Commits
4.15.0-rc2
...
4.15.0-rc3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
959343fe79 | ||
|
|
1af6b68cbe | ||
|
|
2806b827d8 | ||
|
|
7e94a2f484 | ||
|
|
e5815acf37 | ||
|
|
f4ea04b728 | ||
|
|
5ff6edf9f2 | ||
|
|
544709fad3 | ||
|
|
8d1f0bcf99 | ||
|
|
64bcb54fa9 | ||
|
|
4d139ca466 | ||
|
|
e15aa5a8a6 | ||
|
|
dfb4d8fdf9 |
22
configure.ac
22
configure.ac
@@ -4,7 +4,7 @@ m4_define([libsubid_abi_major], 4)
|
||||
m4_define([libsubid_abi_minor], 0)
|
||||
m4_define([libsubid_abi_micro], 0)
|
||||
m4_define([libsubid_abi], [libsubid_abi_major.libsubid_abi_minor.libsubid_abi_micro])
|
||||
AC_INIT([shadow], [4.15.0-rc2], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||
AC_INIT([shadow], [4.15.0-rc3], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||
[https://github.com/shadow-maint/shadow])
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
|
||||
AC_CONFIG_MACRO_DIRS([m4])
|
||||
@@ -49,7 +49,7 @@ AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])])
|
||||
AC_CHECK_FUNCS(arc4random_buf futimes \
|
||||
getentropy getrandom getspnam getusershell \
|
||||
initgroups lckpwdf lutimes \
|
||||
setgroups updwtmp updwtmpx innetgr \
|
||||
setgroups updwtmpx innetgr \
|
||||
getspnam_r \
|
||||
rpmatch \
|
||||
memset_explicit explicit_bzero stpecpy stpeprintf)
|
||||
@@ -57,17 +57,13 @@ AC_SYS_LARGEFILE
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
|
||||
AC_CHECK_MEMBERS([struct utmp.ut_type,
|
||||
struct utmp.ut_id,
|
||||
struct utmp.ut_name,
|
||||
struct utmp.ut_user,
|
||||
struct utmp.ut_host,
|
||||
struct utmp.ut_syslen,
|
||||
struct utmp.ut_addr,
|
||||
struct utmp.ut_addr_v6,
|
||||
struct utmp.ut_time,
|
||||
struct utmp.ut_xtime,
|
||||
struct utmp.ut_tv],,,[[#include <utmp.h>]])
|
||||
AC_CHECK_MEMBERS([struct utmpx.ut_name,
|
||||
struct utmpx.ut_host,
|
||||
struct utmpx.ut_syslen,
|
||||
struct utmpx.ut_addr,
|
||||
struct utmpx.ut_addr_v6,
|
||||
struct utmpx.ut_time,
|
||||
struct utmpx.ut_xtime],,,[[#include <utmpx.h>]])
|
||||
|
||||
dnl Checks for library functions.
|
||||
AC_TYPE_GETGROUPS
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <readpassphrase.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -24,11 +23,6 @@
|
||||
#endif /* WITH_LIBBSD */
|
||||
|
||||
|
||||
#if !defined(PASS_MAX)
|
||||
#define PASS_MAX BUFSIZ - 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* SYNOPSIS
|
||||
* [[gnu::malloc(erase_pass)]]
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -202,4 +203,14 @@
|
||||
# define shadow_getenv(name) getenv(name)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Maximum password length
|
||||
*
|
||||
* Consider that there is also limit in PAM (PAM_MAX_RESP_SIZE)
|
||||
* currently set to 512.
|
||||
*/
|
||||
#if !defined(PASS_MAX)
|
||||
#define PASS_MAX BUFSIZ - 1
|
||||
#endif
|
||||
|
||||
#endif /* _DEFINES_H_ */
|
||||
|
||||
@@ -319,7 +319,7 @@ relunit : tUNUMBER tYEAR_UNIT {
|
||||
yyRelYear += $1 * $2;
|
||||
}
|
||||
| tYEAR_UNIT {
|
||||
yyRelYear++;
|
||||
yyRelYear += $1;
|
||||
}
|
||||
| tUNUMBER tMONTH_UNIT {
|
||||
yyRelMonth += $1 * $2;
|
||||
@@ -328,7 +328,7 @@ relunit : tUNUMBER tYEAR_UNIT {
|
||||
yyRelMonth += $1 * $2;
|
||||
}
|
||||
| tMONTH_UNIT {
|
||||
yyRelMonth++;
|
||||
yyRelMonth += $1;
|
||||
}
|
||||
| tUNUMBER tDAY_UNIT {
|
||||
yyRelDay += $1 * $2;
|
||||
@@ -337,7 +337,7 @@ relunit : tUNUMBER tYEAR_UNIT {
|
||||
yyRelDay += $1 * $2;
|
||||
}
|
||||
| tDAY_UNIT {
|
||||
yyRelDay++;
|
||||
yyRelDay += $1;
|
||||
}
|
||||
| tUNUMBER tHOUR_UNIT {
|
||||
yyRelHour += $1 * $2;
|
||||
@@ -346,7 +346,7 @@ relunit : tUNUMBER tYEAR_UNIT {
|
||||
yyRelHour += $1 * $2;
|
||||
}
|
||||
| tHOUR_UNIT {
|
||||
yyRelHour++;
|
||||
yyRelHour += $1;
|
||||
}
|
||||
| tUNUMBER tMINUTE_UNIT {
|
||||
yyRelMinutes += $1 * $2;
|
||||
@@ -355,7 +355,7 @@ relunit : tUNUMBER tYEAR_UNIT {
|
||||
yyRelMinutes += $1 * $2;
|
||||
}
|
||||
| tMINUTE_UNIT {
|
||||
yyRelMinutes++;
|
||||
yyRelMinutes += $1;
|
||||
}
|
||||
| tUNUMBER tSEC_UNIT {
|
||||
yyRelSeconds += $1 * $2;
|
||||
@@ -364,7 +364,7 @@ relunit : tUNUMBER tYEAR_UNIT {
|
||||
yyRelSeconds += $1 * $2;
|
||||
}
|
||||
| tSEC_UNIT {
|
||||
yyRelSeconds++;
|
||||
yyRelSeconds += $1;
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
*
|
||||
* A "last login" entry is created for the user being logged in. The
|
||||
* UID is extracted from the global (struct passwd) entry and the
|
||||
* TTY information is gotten from the (struct utmp).
|
||||
* TTY information is gotten from the (struct utmpx).
|
||||
*/
|
||||
void dolastlog (
|
||||
struct lastlog *ll,
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
#include "must_be.h"
|
||||
|
||||
|
||||
#define WIDTHOF(x) (sizeof(x) * CHAR_BIT)
|
||||
#define SIZEOF_ARRAY(a) (sizeof(a) + must_be_array(a))
|
||||
#define NITEMS(a) (SIZEOF_ARRAY((a)) / sizeof((a)[0]))
|
||||
#define STRLEN(s) (NITEMS(s) - 1)
|
||||
#define memberof(T, member) ((T){}.member)
|
||||
#define WIDTHOF(x) (sizeof(x) * CHAR_BIT)
|
||||
#define SIZEOF_ARRAY(a) (sizeof(a) + must_be_array(a))
|
||||
#define NITEMS(a) (SIZEOF_ARRAY((a)) / sizeof((a)[0]))
|
||||
#define STRLEN(s) (NITEMS(s) - 1)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -51,13 +51,15 @@ int user_busy (const char *name, uid_t uid)
|
||||
#endif /* !__linux__ */
|
||||
}
|
||||
|
||||
#ifndef __linux__
|
||||
static int user_busy_utmp (const char *name)
|
||||
{
|
||||
struct utmp *utent;
|
||||
|
||||
setutent ();
|
||||
while ((utent = getutent ()) != NULL)
|
||||
#ifndef __linux__
|
||||
static int
|
||||
user_busy_utmp(const char *name)
|
||||
{
|
||||
struct utmpx *utent;
|
||||
|
||||
setutxent();
|
||||
while ((utent = getutxent()) != NULL)
|
||||
{
|
||||
if (utent->ut_type != USER_PROCESS) {
|
||||
continue;
|
||||
@@ -79,6 +81,7 @@ static int user_busy_utmp (const char *name)
|
||||
}
|
||||
#endif /* !__linux__ */
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef ENABLE_SUBIDS
|
||||
#define in_parentuid_range(uid) ((uid) >= parentuid && (uid) < parentuid + range)
|
||||
|
||||
180
lib/utmp.c
180
lib/utmp.c
@@ -13,7 +13,7 @@
|
||||
#include "prototypes.h"
|
||||
#include "getdef.h"
|
||||
|
||||
#include <utmp.h>
|
||||
#include <utmpx.h>
|
||||
#include <assert.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
@@ -31,19 +31,23 @@
|
||||
#ident "$Id$"
|
||||
|
||||
|
||||
#define UTX_LINESIZE NITEMS(memberof(struct utmpx, ut_line))
|
||||
|
||||
|
||||
/*
|
||||
* is_my_tty -- determine if "tty" is the same TTY stdin is using
|
||||
*/
|
||||
static bool is_my_tty (const char tty[UT_LINESIZE])
|
||||
static bool
|
||||
is_my_tty(const char tty[UTX_LINESIZE])
|
||||
{
|
||||
char full_tty[STRLEN("/dev/") + UT_LINESIZE + 1];
|
||||
char full_tty[STRLEN("/dev/") + UTX_LINESIZE + 1];
|
||||
/* tmptty shall be bigger than full_tty */
|
||||
static char tmptty[sizeof(full_tty) + 1];
|
||||
|
||||
full_tty[0] = '\0';
|
||||
if (tty[0] != '/')
|
||||
strcpy (full_tty, "/dev/");
|
||||
strncat (full_tty, tty, UT_LINESIZE);
|
||||
strncat(full_tty, tty, UTX_LINESIZE);
|
||||
|
||||
if ('\0' == tmptty[0]) {
|
||||
const char *tname = ttyname (STDIN_FILENO);
|
||||
@@ -59,13 +63,15 @@ static bool is_my_tty (const char tty[UT_LINESIZE])
|
||||
return strcmp (full_tty, tmptty) == 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* failtmp - update the cumulative failure log
|
||||
*
|
||||
* failtmp updates the (struct utmp) formatted failure log which
|
||||
* failtmp updates the (struct utmpx) formatted failure log which
|
||||
* maintains a record of all login failures.
|
||||
*/
|
||||
static void failtmp (const char *username, const struct utmp *failent)
|
||||
static void
|
||||
failtmp(const char *username, const struct utmpx *failent)
|
||||
{
|
||||
const char *ftmp;
|
||||
int fd;
|
||||
@@ -121,6 +127,7 @@ err_close:
|
||||
username, ftmp));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_current_utmp - return the most probable utmp entry for the current
|
||||
* session
|
||||
@@ -129,57 +136,57 @@ err_close:
|
||||
* The line entered by the *getty / telnetd, etc. should also match
|
||||
* the current terminal.
|
||||
*
|
||||
* When an entry is returned by get_current_utmp, and if the utmp
|
||||
* When an entry is returned by get_current_utmp, and if the utmpx
|
||||
* structure has a ut_id field, this field should be used to update
|
||||
* the entry information.
|
||||
*
|
||||
* Return NULL if no entries exist in utmp for the current process.
|
||||
*/
|
||||
static
|
||||
/*@null@*/ /*@only@*/struct utmp *get_current_utmp (void)
|
||||
static /*@null@*/ /*@only@*/struct utmpx *
|
||||
get_current_utmp(void)
|
||||
{
|
||||
struct utmp *ut;
|
||||
struct utmp *ret = NULL;
|
||||
struct utmpx *ut;
|
||||
struct utmpx *ret = NULL;
|
||||
|
||||
setutent ();
|
||||
setutxent();
|
||||
|
||||
/* First, try to find a valid utmp entry for this process. */
|
||||
while ((ut = getutent ()) != NULL) {
|
||||
while ((ut = getutxent()) != NULL) {
|
||||
if ( (ut->ut_pid == getpid ())
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_ID
|
||||
&& ('\0' != ut->ut_id[0])
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
|
||||
&& ( (LOGIN_PROCESS == ut->ut_type)
|
||||
|| (USER_PROCESS == ut->ut_type))
|
||||
#endif
|
||||
/* A process may have failed to close an entry
|
||||
* Check if this entry refers to the current tty */
|
||||
&& is_my_tty (ut->ut_line)) {
|
||||
&& is_my_tty(ut->ut_line))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != ut) {
|
||||
ret = XMALLOC(1, struct utmp);
|
||||
ret = XMALLOC(1, struct utmpx);
|
||||
memcpy (ret, ut, sizeof (*ret));
|
||||
}
|
||||
|
||||
endutent ();
|
||||
endutxent();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_session_host (char **out)
|
||||
|
||||
int
|
||||
get_session_host(char **out)
|
||||
{
|
||||
char *hostname = NULL;
|
||||
struct utmp *ut = NULL;
|
||||
int ret = 0;
|
||||
int ret = 0;
|
||||
struct utmpx *ut;
|
||||
|
||||
ut = get_current_utmp();
|
||||
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_HOST
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
|
||||
if ((ut != NULL) && (ut->ut_host[0] != '\0')) {
|
||||
char *hostname;
|
||||
|
||||
hostname = XMALLOC(sizeof(ut->ut_host) + 1, char);
|
||||
ZUSTR2STP(hostname, ut->ut_host);
|
||||
*out = hostname;
|
||||
@@ -191,18 +198,19 @@ int get_session_host (char **out)
|
||||
#else
|
||||
*out = NULL;
|
||||
ret = -2;
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef USE_PAM
|
||||
|
||||
#if !defined(USE_PAM) && !defined(HAVE_UPDWTMPX)
|
||||
/*
|
||||
* Some systems already have updwtmp() and possibly updwtmpx(). Others
|
||||
* Some systems already have updwtmpx(). Others
|
||||
* don't, so we re-implement these functions if necessary.
|
||||
*/
|
||||
#ifndef HAVE_UPDWTMP
|
||||
static void updwtmp (const char *filename, const struct utmp *ut)
|
||||
static void
|
||||
updwtmpx(const char *filename, const struct utmpx *ut)
|
||||
{
|
||||
int fd;
|
||||
|
||||
@@ -212,9 +220,7 @@ static void updwtmp (const char *filename, const struct utmp *ut)
|
||||
close (fd);
|
||||
}
|
||||
}
|
||||
#endif /* ! HAVE_UPDWTMP */
|
||||
|
||||
#endif /* ! USE_PAM */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@@ -235,15 +241,13 @@ static void updwtmp (const char *filename, const struct utmp *ut)
|
||||
*
|
||||
* The returned structure shall be freed by the caller.
|
||||
*/
|
||||
static
|
||||
/*@only@*/struct utmp *prepare_utmp (const char *name,
|
||||
const char *line,
|
||||
const char *host,
|
||||
/*@null@*/const struct utmp *ut)
|
||||
static /*@only@*/struct utmpx *
|
||||
prepare_utmp(const char *name, const char *line, const char *host,
|
||||
/*@null@*/const struct utmpx *ut)
|
||||
{
|
||||
struct timeval tv;
|
||||
char *hostname = NULL;
|
||||
struct utmp *utent;
|
||||
char *hostname = NULL;
|
||||
struct utmpx *utent;
|
||||
struct timeval tv;
|
||||
|
||||
assert (NULL != name);
|
||||
assert (NULL != line);
|
||||
@@ -254,12 +258,12 @@ static
|
||||
&& ('\0' != host[0])) {
|
||||
hostname = XMALLOC(strlen(host) + 1, char);
|
||||
strcpy (hostname, host);
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_HOST
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
|
||||
} else if ( (NULL != ut)
|
||||
&& ('\0' != ut->ut_host[0])) {
|
||||
hostname = XMALLOC(NITEMS(ut->ut_host) + 1, char);
|
||||
ZUSTR2STP(hostname, ut->ut_host);
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
|
||||
#endif
|
||||
}
|
||||
|
||||
if (strncmp(line, "/dev/", 5) == 0) {
|
||||
@@ -267,38 +271,32 @@ static
|
||||
}
|
||||
|
||||
|
||||
utent = XCALLOC (1, struct utmp);
|
||||
utent = XCALLOC(1, struct utmpx);
|
||||
|
||||
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
|
||||
utent->ut_type = USER_PROCESS;
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_TYPE */
|
||||
utent->ut_pid = getpid ();
|
||||
STRNCPY(utent->ut_line, line);
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_ID
|
||||
if (NULL != ut) {
|
||||
STRNCPY(utent->ut_id, ut->ut_id);
|
||||
} else {
|
||||
/* XXX - assumes /dev/tty?? */
|
||||
STRNCPY(utent->ut_id, line + 3);
|
||||
}
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_ID */
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_NAME
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_NAME)
|
||||
STRNCPY(utent->ut_name, name);
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_NAME */
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_USER
|
||||
#endif
|
||||
STRNCPY(utent->ut_user, name);
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_USER */
|
||||
if (NULL != hostname) {
|
||||
struct addrinfo *info = NULL;
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_HOST
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
|
||||
STRNCPY(utent->ut_host, hostname);
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_SYSLEN
|
||||
#endif
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_SYSLEN)
|
||||
utent->ut_syslen = MIN (strlen (hostname),
|
||||
sizeof (utent->ut_host));
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_SYSLEN */
|
||||
#if defined(HAVE_STRUCT_UTMP_UT_ADDR) || defined(HAVE_STRUCT_UTMP_UT_ADDR_V6)
|
||||
#endif
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_ADDR) || defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6)
|
||||
if (getaddrinfo (hostname, NULL, NULL, &info) == 0) {
|
||||
/* getaddrinfo might not be reliable.
|
||||
* Just try to log what may be useful.
|
||||
@@ -306,13 +304,13 @@ static
|
||||
if (info->ai_family == AF_INET) {
|
||||
struct sockaddr_in *sa =
|
||||
(struct sockaddr_in *) info->ai_addr;
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
|
||||
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR)
|
||||
memcpy (&(utent->ut_addr),
|
||||
&(sa->sin_addr),
|
||||
MIN (sizeof (utent->ut_addr),
|
||||
sizeof (sa->sin_addr)));
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_ADDR */
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_ADDR_V6
|
||||
# endif
|
||||
# if defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6)
|
||||
memcpy (utent->ut_addr_v6,
|
||||
&(sa->sin_addr),
|
||||
MIN (sizeof (utent->ut_addr_v6),
|
||||
@@ -324,61 +322,61 @@ static
|
||||
&(sa->sin6_addr),
|
||||
MIN (sizeof (utent->ut_addr_v6),
|
||||
sizeof (sa->sin6_addr)));
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_ADDR_V6 */
|
||||
# endif
|
||||
}
|
||||
freeaddrinfo (info);
|
||||
}
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_ADDR || HAVE_STRUCT_UTMP_UT_ADDR_V6 */
|
||||
#endif
|
||||
free (hostname);
|
||||
}
|
||||
/* ut_exit is only for DEAD_PROCESS */
|
||||
utent->ut_session = getsid (0);
|
||||
if (gettimeofday (&tv, NULL) == 0) {
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_TIME
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_TIME)
|
||||
utent->ut_time = tv.tv_sec;
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_TIME */
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_XTIME
|
||||
#endif
|
||||
#if defined(HAVE_STRUCT_UTMPX_UT_XTIME)
|
||||
utent->ut_xtime = tv.tv_usec;
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_XTIME */
|
||||
#ifdef HAVE_STRUCT_UTMP_UT_TV
|
||||
#endif
|
||||
utent->ut_tv.tv_sec = tv.tv_sec;
|
||||
utent->ut_tv.tv_usec = tv.tv_usec;
|
||||
#endif /* HAVE_STRUCT_UTMP_UT_TV */
|
||||
}
|
||||
|
||||
return utent;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* setutmp - Update an entry in utmp and log an entry in wtmp
|
||||
*
|
||||
* Return 1 on failure and 0 on success.
|
||||
*/
|
||||
static int setutmp (struct utmp *ut)
|
||||
static int
|
||||
setutmp(struct utmpx *ut)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
assert (NULL != ut);
|
||||
|
||||
setutent ();
|
||||
if (pututline (ut) == NULL) {
|
||||
setutxent();
|
||||
if (pututxline(ut) == NULL) {
|
||||
err = 1;
|
||||
}
|
||||
endutent ();
|
||||
endutxent();
|
||||
|
||||
#ifndef USE_PAM
|
||||
#if !defined(USE_PAM)
|
||||
/* This is done by pam_lastlog */
|
||||
updwtmp (_WTMP_FILE, ut);
|
||||
#endif /* ! USE_PAM */
|
||||
updwtmpx(_WTMP_FILE, ut);
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int update_utmp (const char *user,
|
||||
const char *tty,
|
||||
const char *host)
|
||||
|
||||
int
|
||||
update_utmp(const char *user, const char *tty, const char *host)
|
||||
{
|
||||
struct utmp *utent, *ut;
|
||||
struct utmpx *utent, *ut;
|
||||
|
||||
utent = get_current_utmp ();
|
||||
ut = prepare_utmp (user, tty, host, utent);
|
||||
@@ -391,11 +389,11 @@ int update_utmp (const char *user,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void record_failure(const char *failent_user,
|
||||
const char *tty,
|
||||
const char *hostname)
|
||||
|
||||
void
|
||||
record_failure(const char *failent_user, const char *tty, const char *hostname)
|
||||
{
|
||||
struct utmp *utent, *failent;
|
||||
struct utmpx *utent, *failent;
|
||||
|
||||
if (getdef_str ("FTMP_FILE") != NULL) {
|
||||
utent = get_current_utmp ();
|
||||
@@ -406,13 +404,15 @@ void record_failure(const char *failent_user,
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long active_sessions_count(const char *name, unsigned long limit)
|
||||
{
|
||||
struct utmp *ut;
|
||||
unsigned long count = 0;
|
||||
|
||||
setutent ();
|
||||
while ((ut = getutent ()))
|
||||
unsigned long
|
||||
active_sessions_count(const char *name, unsigned long limit)
|
||||
{
|
||||
struct utmpx *ut;
|
||||
unsigned long count = 0;
|
||||
|
||||
setutxent();
|
||||
while ((ut = getutxent()))
|
||||
{
|
||||
if (USER_PROCESS != ut->ut_type) {
|
||||
continue;
|
||||
@@ -428,7 +428,7 @@ unsigned long active_sessions_count(const char *name, unsigned long limit)
|
||||
break;
|
||||
}
|
||||
}
|
||||
endutent ();
|
||||
endutxent();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <utmp.h>
|
||||
#include <utmpx.h>
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog.h"
|
||||
@@ -34,14 +34,17 @@ const char *Prog;
|
||||
#define HUP_MESG_FILE "/etc/logoutd.mesg"
|
||||
#endif
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
static int check_login (const struct utmp *ut);
|
||||
static int check_login (const struct utmpx *ut);
|
||||
static void send_mesg_to_tty (int tty_fd);
|
||||
|
||||
|
||||
/*
|
||||
* check_login - check if user (struct utmp) allowed to stay logged in
|
||||
* check_login - check if user (struct utmpx) allowed to stay logged in
|
||||
*/
|
||||
static int check_login (const struct utmp *ut)
|
||||
static int
|
||||
check_login(const struct utmpx *ut)
|
||||
{
|
||||
char user[sizeof(ut->ut_user) + 1];
|
||||
char line[sizeof(ut->ut_line) + 1];
|
||||
@@ -112,16 +115,17 @@ static void send_mesg_to_tty (int tty_fd)
|
||||
* utmp file is periodically scanned and offending users are logged
|
||||
* off from the system.
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int status;
|
||||
pid_t pid;
|
||||
int i;
|
||||
int status;
|
||||
pid_t pid;
|
||||
|
||||
struct utmp *ut;
|
||||
char user[sizeof (ut->ut_user) + 1]; /* terminating NUL */
|
||||
char tty_name[sizeof (ut->ut_line) + 6]; /* /dev/ + NUL */
|
||||
int tty_fd;
|
||||
struct utmpx *ut;
|
||||
char user[sizeof (ut->ut_user) + 1]; /* terminating NUL */
|
||||
char tty_name[sizeof (ut->ut_line) + 6]; /* /dev/ + NUL */
|
||||
int tty_fd;
|
||||
|
||||
if (1 != argc) {
|
||||
(void) fputs (_("Usage: logoutd\n"), stderr);
|
||||
@@ -169,14 +173,14 @@ int main (int argc, char **argv)
|
||||
* Attempt to re-open the utmp file. The file is only
|
||||
* open while it is being used.
|
||||
*/
|
||||
setutent ();
|
||||
setutxent();
|
||||
|
||||
/*
|
||||
* Read all of the entries in the utmp file. The entries
|
||||
* for login sessions will be checked to see if the user
|
||||
* is permitted to be signed on at this time.
|
||||
*/
|
||||
while ((ut = getutent ()) != NULL) {
|
||||
while ((ut = getutxent()) != NULL) {
|
||||
if (ut->ut_type != USER_PROCESS) {
|
||||
continue;
|
||||
}
|
||||
@@ -208,7 +212,7 @@ int main (int argc, char **argv)
|
||||
tty_name[0] = '\0';
|
||||
}
|
||||
|
||||
strncat (tty_name, ut->ut_line, UT_LINESIZE);
|
||||
strncat(tty_name, ut->ut_line, NITEMS(ut->ut_line));
|
||||
#ifndef O_NOCTTY
|
||||
#define O_NOCTTY 0
|
||||
#endif
|
||||
@@ -238,7 +242,7 @@ int main (int argc, char **argv)
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
endutent ();
|
||||
endutxent();
|
||||
|
||||
#ifndef DEBUG
|
||||
sleep (60);
|
||||
|
||||
20
src/passwd.c
20
src/passwd.c
@@ -175,9 +175,10 @@ static int new_password (const struct passwd *pw)
|
||||
char *cipher; /* Pointer to cipher text */
|
||||
const char *salt; /* Pointer to new salt */
|
||||
char *cp; /* Pointer to agetpass() response */
|
||||
char orig[200]; /* Original password */
|
||||
char pass[200]; /* New password */
|
||||
char orig[PASS_MAX + 1]; /* Original password */
|
||||
char pass[PASS_MAX + 1]; /* New password */
|
||||
int i; /* Counter for retries */
|
||||
int ret;
|
||||
bool warned;
|
||||
int pass_max_len = -1;
|
||||
const char *method;
|
||||
@@ -276,8 +277,13 @@ static int new_password (const struct passwd *pw)
|
||||
if (NULL == cp) {
|
||||
return -1;
|
||||
}
|
||||
STRTCPY (pass, cp);
|
||||
ret = STRTCPY (pass, cp);
|
||||
erase_pass (cp);
|
||||
if (ret == -1) {
|
||||
(void) fputs (_("Password is too long.\n"), stderr);
|
||||
MEMZERO(pass);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
warned = false;
|
||||
for (i = getdef_num ("PASS_CHANGE_TRIES", 5); i > 0; i--) {
|
||||
@@ -290,8 +296,14 @@ static int new_password (const struct passwd *pw)
|
||||
if (warned && (strcmp (pass, cp) != 0)) {
|
||||
warned = false;
|
||||
}
|
||||
STRTCPY(pass, cp);
|
||||
ret = STRTCPY (pass, cp);
|
||||
erase_pass (cp);
|
||||
if (ret == -1) {
|
||||
(void) fputs (_("Password is too long.\n"), stderr);
|
||||
MEMZERO(orig);
|
||||
MEMZERO(pass);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!amroot && !obscure(orig, pass, pw)) {
|
||||
(void) puts (_("Try again."));
|
||||
|
||||
Reference in New Issue
Block a user