diff options
Diffstat (limited to 'src/account/LMI_AccountProvider.c')
-rw-r--r-- | src/account/LMI_AccountProvider.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/account/LMI_AccountProvider.c b/src/account/LMI_AccountProvider.c index c7c16bb..5805f5e 100644 --- a/src/account/LMI_AccountProvider.c +++ b/src/account/LMI_AccountProvider.c @@ -43,6 +43,7 @@ #include "aux_lu.h" #include "macros.h" #include "globals.h" +#include "lock.h" // Return values of functions // Delete user @@ -55,6 +56,9 @@ static const CMPIBroker* _cb = NULL; static void LMI_AccountInitialize() { + if (init_lock_pool() == 0) { + CMReturn(CMPI_RC_ERR_FAILED); + } } static CMPIStatus LMI_AccountCleanup( @@ -62,6 +66,7 @@ static CMPIStatus LMI_AccountCleanup( const CMPIContext* cc, CMPIBoolean term) { + destroy_lock_pool(); CMReturn(CMPI_RC_OK); } @@ -270,9 +275,18 @@ static CMPIStatus LMI_AccountModifyInstance( LMI_Account_InitFromObjectPath(&la, _cb, cop); + /* boilerplate code */ + char userlock[USERNAME_LEN_MAX] = {0}; + /* -1 for NULL char */ + strncpy(userlock, la.Name.chars, sizeof(userlock) - 1); + if (get_lock(userlock) == 0) { + KReturn2(_cb, ERR_FAILED, "Unable to obtain lock."); + } + luc = lu_start(NULL, lu_user, NULL, NULL, lu_prompt_console_quiet, NULL, &error); if (!luc) { + release_lock (userlock); KReturn2(_cb, ERR_FAILED, "Unable to initialize libuser: %s\n", lu_strerror(error)); } @@ -362,6 +376,7 @@ static CMPIStatus LMI_AccountModifyInstance( last_change = aux_lu_get_long(lue, LU_SHADOWLASTCHANGE); #define FAIL(msg) \ + release_lock (userlock); \ lu_end(luc); \ lu_ent_free(lue); \ KReturn2(_cb, ERR_FAILED, msg); @@ -452,6 +467,7 @@ static CMPIStatus LMI_AccountModifyInstance( } fail: + release_lock (userlock); lu_ent_free(lue); lu_end(luc); @@ -488,8 +504,18 @@ static CMPIrc delete_user( struct lu_ent *lue = NULL; struct lu_ent *lueg = NULL; + /* boilerplate code */ + char userlock[USERNAME_LEN_MAX] = {0}; + /* -1 for NULL char */ + strncpy(userlock, username, sizeof(userlock) - 1); + if (get_lock(userlock) == 0) { + asprintf(&errormsg, "Unable to obtain lock."); + return CMPI_RC_ERR_FAILED; + } + luc = lu_start(NULL, 0, NULL, NULL, lu_prompt_console_quiet, NULL, &error); if (!luc) { + release_lock(userlock); asprintf(&errormsg, "Unable to initialize libuser: %s\n", lu_strerror(error)); return CMPI_RC_ERR_FAILED; } @@ -568,6 +594,7 @@ static CMPIrc delete_user( } clean: + release_lock(userlock); lu_ent_free(lue); lu_ent_free(lueg); lu_end(luc); |