Merge pull request #118 from AdelieLinux/utmpx-only-support
[WIP] Support systems that only have utmpx
This commit is contained in:
commit
ff8b1ebafa
@ -74,12 +74,6 @@ AC_CHECK_MEMBERS([struct utmp.ut_type,
|
|||||||
struct utmp.ut_time,
|
struct utmp.ut_time,
|
||||||
struct utmp.ut_xtime,
|
struct utmp.ut_xtime,
|
||||||
struct utmp.ut_tv],,,[[#include <utmp.h>]])
|
struct utmp.ut_tv],,,[[#include <utmp.h>]])
|
||||||
dnl There are dependencies:
|
|
||||||
dnl If UTMPX has to be used, the utmp structure shall have a ut_id field.
|
|
||||||
if test "$ac_cv_header_utmpx_h" = "yes" &&
|
|
||||||
test "$ac_cv_member_struct_utmp_ut_id" != "yes"; then
|
|
||||||
AC_MSG_ERROR(Systems with UTMPX and no ut_id field in the utmp structure are not supported)
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_CHECK_MEMBERS([struct utmpx.ut_name,
|
AC_CHECK_MEMBERS([struct utmpx.ut_name,
|
||||||
struct utmpx.ut_host,
|
struct utmpx.ut_host,
|
||||||
|
@ -416,17 +416,19 @@ extern int set_filesize_limit (int blocks);
|
|||||||
extern int user_busy (const char *name, uid_t uid);
|
extern int user_busy (const char *name, uid_t uid);
|
||||||
|
|
||||||
/* utmp.c */
|
/* utmp.c */
|
||||||
|
#ifndef USE_UTMPX
|
||||||
extern /*@null@*/struct utmp *get_current_utmp (void);
|
extern /*@null@*/struct utmp *get_current_utmp (void);
|
||||||
extern struct utmp *prepare_utmp (const char *name,
|
extern struct utmp *prepare_utmp (const char *name,
|
||||||
const char *line,
|
const char *line,
|
||||||
const char *host,
|
const char *host,
|
||||||
/*@null@*/const struct utmp *ut);
|
/*@null@*/const struct utmp *ut);
|
||||||
extern int setutmp (struct utmp *ut);
|
extern int setutmp (struct utmp *ut);
|
||||||
#ifdef USE_UTMPX
|
#else
|
||||||
|
extern /*@null@*/struct utmpx *get_current_utmp (void);
|
||||||
extern struct utmpx *prepare_utmpx (const char *name,
|
extern struct utmpx *prepare_utmpx (const char *name,
|
||||||
const char *line,
|
const char *line,
|
||||||
const char *host,
|
const char *host,
|
||||||
/*@null@*/const struct utmp *ut);
|
/*@null@*/const struct utmpx *ut);
|
||||||
extern int setutmpx (struct utmpx *utx);
|
extern int setutmpx (struct utmpx *utx);
|
||||||
#endif /* USE_UTMPX */
|
#endif /* USE_UTMPX */
|
||||||
|
|
||||||
|
@ -35,10 +35,10 @@
|
|||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
#include <utmp.h>
|
|
||||||
|
|
||||||
#ifdef USE_UTMPX
|
#ifdef USE_UTMPX
|
||||||
#include <utmpx.h>
|
#include <utmpx.h>
|
||||||
|
#else
|
||||||
|
#include <utmp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -97,6 +97,7 @@ static bool is_my_tty (const char *tty)
|
|||||||
*
|
*
|
||||||
* Return NULL if no entries exist in utmp for the current process.
|
* Return NULL if no entries exist in utmp for the current process.
|
||||||
*/
|
*/
|
||||||
|
#ifndef USE_UTMPX
|
||||||
/*@null@*/ /*@only@*/struct utmp *get_current_utmp (void)
|
/*@null@*/ /*@only@*/struct utmp *get_current_utmp (void)
|
||||||
{
|
{
|
||||||
struct utmp *ut;
|
struct utmp *ut;
|
||||||
@ -130,6 +131,36 @@ static bool is_my_tty (const char *tty)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
/*@null@*/ /*@only*/struct utmpx *get_current_utmp(void)
|
||||||
|
{
|
||||||
|
struct utmpx *ut;
|
||||||
|
struct utmpx *ret = NULL;
|
||||||
|
|
||||||
|
setutxent ();
|
||||||
|
|
||||||
|
/* Find the utmpx entry for this PID. */
|
||||||
|
while ((ut = getutxent ()) != NULL) {
|
||||||
|
if ( (ut->ut_pid == getpid ())
|
||||||
|
&& ('\0' != ut->ut_id[0])
|
||||||
|
&& ( (LOGIN_PROCESS == ut->ut_type)
|
||||||
|
|| (USER_PROCESS == ut->ut_type))
|
||||||
|
&& is_my_tty (ut->ut_line)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != ut) {
|
||||||
|
ret = (struct utmpx *) xmalloc (sizeof (*ret));
|
||||||
|
memcpy (ret, ut, sizeof (*ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
endutxent ();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef USE_PAM
|
#ifndef USE_PAM
|
||||||
/*
|
/*
|
||||||
@ -166,6 +197,7 @@ static void updwtmpx (const char *filename, const struct utmpx *utx)
|
|||||||
#endif /* ! USE_PAM */
|
#endif /* ! USE_PAM */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef USE_UTMPX
|
||||||
/*
|
/*
|
||||||
* prepare_utmp - prepare an utmp entry so that it can be logged in a
|
* prepare_utmp - prepare an utmp entry so that it can be logged in a
|
||||||
* utmp/wtmp file.
|
* utmp/wtmp file.
|
||||||
@ -325,14 +357,14 @@ int setutmp (struct utmp *ut)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_UTMPX
|
#else
|
||||||
/*
|
/*
|
||||||
* prepare_utmpx - the UTMPX version for prepare_utmp
|
* prepare_utmpx - the UTMPX version for prepare_utmp
|
||||||
*/
|
*/
|
||||||
/*@only@*/struct utmpx *prepare_utmpx (const char *name,
|
/*@only@*/struct utmpx *prepare_utmpx (const char *name,
|
||||||
const char *line,
|
const char *line,
|
||||||
const char *host,
|
const char *host,
|
||||||
/*@null@*/const struct utmp *ut)
|
/*@null@*/const struct utmpx *ut)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char *hostname = NULL;
|
char *hostname = NULL;
|
||||||
@ -398,7 +430,7 @@ int setutmp (struct utmp *ut)
|
|||||||
struct sockaddr_in *sa =
|
struct sockaddr_in *sa =
|
||||||
(struct sockaddr_in *) info->ai_addr;
|
(struct sockaddr_in *) info->ai_addr;
|
||||||
#ifdef HAVE_STRUCT_UTMPX_UT_ADDR
|
#ifdef HAVE_STRUCT_UTMPX_UT_ADDR
|
||||||
memcpy (utxent->ut_addr,
|
memcpy (&utxent->ut_addr,
|
||||||
&(sa->sin_addr),
|
&(sa->sin_addr),
|
||||||
MIN (sizeof (utxent->ut_addr),
|
MIN (sizeof (utxent->ut_addr),
|
||||||
sizeof (sa->sin_addr)));
|
sizeof (sa->sin_addr)));
|
||||||
|
27
src/login.c
27
src/login.c
@ -129,7 +129,12 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
|
|||||||
static void update_utmp (const char *user,
|
static void update_utmp (const char *user,
|
||||||
const char *tty,
|
const char *tty,
|
||||||
const char *host,
|
const char *host,
|
||||||
/*@null@*/const struct utmp *utent);
|
#ifdef USE_UTMPX
|
||||||
|
/*@null@*/const struct utmpx *utent
|
||||||
|
#else
|
||||||
|
/*@null@*/const struct utmp *utent
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
#ifndef USE_PAM
|
#ifndef USE_PAM
|
||||||
static struct faillog faillog;
|
static struct faillog faillog;
|
||||||
@ -481,17 +486,23 @@ static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
|
|||||||
static void update_utmp (const char *user,
|
static void update_utmp (const char *user,
|
||||||
const char *tty,
|
const char *tty,
|
||||||
const char *host,
|
const char *host,
|
||||||
/*@null@*/const struct utmp *utent)
|
#ifdef USE_UTMPX
|
||||||
|
/*@null@*/const struct utmpx *utent
|
||||||
|
#else
|
||||||
|
/*@null@*/const struct utmp *utent
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{
|
{
|
||||||
struct utmp *ut = prepare_utmp (user, tty, host, utent);
|
|
||||||
#ifdef USE_UTMPX
|
#ifdef USE_UTMPX
|
||||||
struct utmpx *utx = prepare_utmpx (user, tty, host, utent);
|
struct utmpx *utx = prepare_utmpx (user, tty, host, utent);
|
||||||
|
#else
|
||||||
|
struct utmp *ut = prepare_utmp (user, tty, host, utent);
|
||||||
#endif /* USE_UTMPX */
|
#endif /* USE_UTMPX */
|
||||||
|
|
||||||
|
#ifndef USE_UTMPX
|
||||||
(void) setutmp (ut); /* make entry in the utmp & wtmp files */
|
(void) setutmp (ut); /* make entry in the utmp & wtmp files */
|
||||||
free (ut);
|
free (ut);
|
||||||
|
#else
|
||||||
#ifdef USE_UTMPX
|
|
||||||
(void) setutmpx (utx); /* make entry in the utmpx & wtmpx files */
|
(void) setutmpx (utx); /* make entry in the utmpx & wtmpx files */
|
||||||
free (utx);
|
free (utx);
|
||||||
#endif /* USE_UTMPX */
|
#endif /* USE_UTMPX */
|
||||||
@ -539,7 +550,11 @@ int main (int argc, char **argv)
|
|||||||
struct passwd *pwd = NULL;
|
struct passwd *pwd = NULL;
|
||||||
char **envp = environ;
|
char **envp = environ;
|
||||||
const char *failent_user;
|
const char *failent_user;
|
||||||
|
#ifdef USE_UTMPX
|
||||||
|
/*@null@*/struct utmpx *utent;
|
||||||
|
#else
|
||||||
/*@null@*/struct utmp *utent;
|
/*@null@*/struct utmp *utent;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
int retcode;
|
int retcode;
|
||||||
@ -681,7 +696,7 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
if (rflg || hflg) {
|
if (rflg || hflg) {
|
||||||
cp = hostname;
|
cp = hostname;
|
||||||
#ifdef HAVE_STRUCT_UTMP_UT_HOST
|
#if defined(HAVE_STRUCT_UTMP_UT_HOST) || defined(USE_UTMPX)
|
||||||
} else if ((NULL != utent) && ('\0' != utent->ut_host[0])) {
|
} else if ((NULL != utent) && ('\0' != utent->ut_host[0])) {
|
||||||
cp = utent->ut_host;
|
cp = utent->ut_host;
|
||||||
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
|
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
|
||||||
|
Loading…
Reference in New Issue
Block a user