diff options
author | Roman Rakus <rrakus@redhat.com> | 2012-09-27 10:44:13 +0200 |
---|---|---|
committer | Roman Rakus <rrakus@redhat.com> | 2012-09-27 10:44:13 +0200 |
commit | 94b8157cb2fd30645662b9b798e7508f00dba01a (patch) | |
tree | 61b854392196daa377a4dbe20ae215e4d6180c69 /src/account/aux_lu.c | |
parent | 9e112eb8e1c56be25d725ef5580d5e8c3e8eab94 (diff) | |
download | openlmi-providers-94b8157cb2fd30645662b9b798e7508f00dba01a.tar.gz openlmi-providers-94b8157cb2fd30645662b9b798e7508f00dba01a.tar.xz openlmi-providers-94b8157cb2fd30645662b9b798e7508f00dba01a.zip |
account: last login, password min and max lifetime
Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src/account/aux_lu.c')
-rw-r--r-- | src/account/aux_lu.c | 31 |
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; +} + |