summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2012-09-27 10:44:13 +0200
committerRoman Rakus <rrakus@redhat.com>2012-09-27 10:44:13 +0200
commit94b8157cb2fd30645662b9b798e7508f00dba01a (patch)
tree61b854392196daa377a4dbe20ae215e4d6180c69
parent9e112eb8e1c56be25d725ef5580d5e8c3e8eab94 (diff)
downloadopenlmi-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>
-rw-r--r--src/account/LMI_AccountManagementServiceProvider.c2
-rw-r--r--src/account/LMI_AccountProvider.c29
-rw-r--r--src/account/aux_lu.c31
-rw-r--r--src/account/aux_lu.h4
4 files changed, 62 insertions, 4 deletions
diff --git a/src/account/LMI_AccountManagementServiceProvider.c b/src/account/LMI_AccountManagementServiceProvider.c
index ae96b33..7f61754 100644
--- a/src/account/LMI_AccountManagementServiceProvider.c
+++ b/src/account/LMI_AccountManagementServiceProvider.c
@@ -319,6 +319,8 @@ KUint32 LMI_AccountManagementService_CreateAccount(
CMPIStatus* status)
{
/* TODO - Use embedded instance? */
+/* TODO - convert errmsg to array and don't use malloc/free */
+/* TODO - password creation */
/* XXX - split to functions and/or macros */
char *errmsg = NULL;
diff --git a/src/account/LMI_AccountProvider.c b/src/account/LMI_AccountProvider.c
index 067ef68..04f4857 100644
--- a/src/account/LMI_AccountProvider.c
+++ b/src/account/LMI_AccountProvider.c
@@ -4,6 +4,8 @@
#include <time.h>
#include <stdbool.h>
+#include <utmp.h>
+
#include <glib.h>
#include <libuser/entity.h>
@@ -59,7 +61,8 @@ static CMPIStatus LMI_AccountEnumInstances(
const char *nameSpace = KNameSpace(cop);
const char *hostname = get_system_name();
char *uid = NULL;
- long expire;
+ long expire, last_change, min_lifetime, max_lifetime;
+ time_t last_login;
CMPIUint64 binTime = 0;
CMPIStatus *rc = NULL;
char *password = NULL;
@@ -97,9 +100,28 @@ static CMPIStatus LMI_AccountEnumInstances(
LU_HOMEDIRECTORY));
LMI_Account_Set_LoginShell(&la, aux_lu_get_str(lue, LU_LOGINSHELL));
+ last_change = aux_lu_get_long(lue, LU_SHADOWLASTCHANGE);
LMI_Account_Set_PasswordLastChange(&la,
- CMNewDateTimeFromBinary(_cb,
- DAYSTOMS(aux_lu_get_long(lue, LU_SHADOWLASTCHANGE)),false, rc));
+ CMNewDateTimeFromBinary(_cb, DAYSTOMS(last_change),false, rc));
+
+ min_lifetime = aux_lu_get_long(lue, LU_SHADOWMIN) + last_change;
+ max_lifetime = aux_lu_get_long(lue, LU_SHADOWMAX) + last_change;
+
+ LMI_Account_Set_PasswordMinLifetime(&la,
+ CMNewDateTimeFromBinary(_cb, DAYSTOMS(min_lifetime), false, rc));
+
+ LMI_Account_Set_PasswordMaxLifetime(&la,
+ CMNewDateTimeFromBinary(_cb, DAYSTOMS(max_lifetime), false, rc));
+
+ last_login = aux_utmp_latest(aux_lu_get_str(lue, LU_USERNAME));
+
+ if (last_login != -1)
+ {
+ LMI_Account_Set_LastLogin(&la,
+ CMNewDateTimeFromBinary(_cb, last_login * 1000000, false, rc));
+ }
+
+ binTime = DAYSTOMS(aux_lu_get_long(lue, LU_SHADOWMIN));
password = aux_lu_get_str(lue, LU_SHADOWPASSWORD);
LMI_Account_Init_UserPassword(&la, 1);
@@ -171,7 +193,6 @@ static CMPIStatus LMI_AccountModifyInstance(
* Set up password expiration
*/
char* value = NULL;
- CMPIStatus* st = NULL;
CMPIString* vs = NULL;
CMPIArray* ar = NULL; int arsize;/* used for password */
CMPIData data;
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;
+}
+
diff --git a/src/account/aux_lu.h b/src/account/aux_lu.h
index c9fd771..8d9fd22 100644
--- a/src/account/aux_lu.h
+++ b/src/account/aux_lu.h
@@ -6,4 +6,8 @@
char* aux_lu_get_str(struct lu_ent*, char*);
long aux_lu_get_long(struct lu_ent*, char*);
+
+/* Get the latest login time for given user name */
+time_t aux_utmp_latest(const char*);
+
#endif