summaryrefslogtreecommitdiff
path: root/libmisc/utmp.c
diff options
context:
space:
mode:
authorBalint Reczey <balint.reczey@canonical.com>2019-06-23 22:06:37 +0200
committerBalint Reczey <balint.reczey@canonical.com>2019-06-23 22:06:37 +0200
commitb28d45d2bd2462414b9dbbe38e6c7f3d5f7b462b (patch)
tree4b068e3513ef5c60228cddfcda72be0a31d09b14 /libmisc/utmp.c
parentb0729855e8fb744192a0395ea24673557818172c (diff)
downloadshadow-b28d45d2bd2462414b9dbbe38e6c7f3d5f7b462b.tar.gz
New upstream version 4.7upstream/4.7
Diffstat (limited to 'libmisc/utmp.c')
-rw-r--r--libmisc/utmp.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/libmisc/utmp.c b/libmisc/utmp.c
index f5614a22..ba69cf61 100644
--- a/libmisc/utmp.c
+++ b/libmisc/utmp.c
@@ -35,10 +35,10 @@
#include "defines.h"
#include "prototypes.h"
-#include <utmp.h>
-
#ifdef USE_UTMPX
#include <utmpx.h>
+#else
+#include <utmp.h>
#endif
#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.
*/
+#ifndef USE_UTMPX
/*@null@*/ /*@only@*/struct utmp *get_current_utmp (void)
{
struct utmp *ut;
@@ -130,6 +131,36 @@ static bool is_my_tty (const char *tty)
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
/*
@@ -166,6 +197,7 @@ static void updwtmpx (const char *filename, const struct utmpx *utx)
#endif /* ! USE_PAM */
+#ifndef USE_UTMPX
/*
* prepare_utmp - prepare an utmp entry so that it can be logged in a
* utmp/wtmp file.
@@ -325,14 +357,14 @@ int setutmp (struct utmp *ut)
return err;
}
-#ifdef USE_UTMPX
+#else
/*
* prepare_utmpx - the UTMPX version for prepare_utmp
*/
/*@only@*/struct utmpx *prepare_utmpx (const char *name,
const char *line,
const char *host,
- /*@null@*/const struct utmp *ut)
+ /*@null@*/const struct utmpx *ut)
{
struct timeval tv;
char *hostname = NULL;
@@ -398,7 +430,7 @@ int setutmp (struct utmp *ut)
struct sockaddr_in *sa =
(struct sockaddr_in *) info->ai_addr;
#ifdef HAVE_STRUCT_UTMPX_UT_ADDR
- memcpy (utxent->ut_addr,
+ memcpy (&utxent->ut_addr,
&(sa->sin_addr),
MIN (sizeof (utxent->ut_addr),
sizeof (sa->sin_addr)));