summaryrefslogtreecommitdiffstats
path: root/src/account/aux_lu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/account/aux_lu.c')
-rw-r--r--src/account/aux_lu.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/account/aux_lu.c b/src/account/aux_lu.c
index 2907214..9da5256 100644
--- a/src/account/aux_lu.c
+++ b/src/account/aux_lu.c
@@ -1,6 +1,8 @@
#include "aux_lu.h"
#include <libuser/entity.h>
#include <libuser/user.h>
+#include <utmp.h>
+#include <string.h>
/*
* Get the value of type from the given entity
@@ -20,3 +22,32 @@ long aux_lu_get_long(struct lu_ent* ent, char* type)
return g_value_get_long(g_value_array_get_nth(lu_ent_get(ent, type), 0));
}
+/*
+ * Get the latest login time for given user name
+ * return value greater than 0 on success
+ * return 0 when not found
+ * return -1 on error and errno properly set
+ */
+time_t aux_utmp_latest(const char* name)
+{
+ time_t last = 0, check = 0;
+ unsigned int found = 0;
+ struct utmp *rec = NULL;
+ if (utmpname(WTMP_FILE))
+ {
+ return -1;
+ }
+ setutent();
+ while ((rec = getutent()) != NULL)
+ {
+ if (rec->ut_type == USER_PROCESS && strcmp(rec->ut_user, name) == 0)
+ {
+ found = 1;
+ check = rec->ut_tv.tv_sec;
+ last = last > check ? last : check;
+ }
+ }
+ endutent();
+ return found ? last : -1;
+}
+