diff options
author | Roman Rakus <rrakus@redhat.com> | 2012-09-26 13:16:01 +0200 |
---|---|---|
committer | Roman Rakus <rrakus@redhat.com> | 2012-09-26 13:16:01 +0200 |
commit | 9e112eb8e1c56be25d725ef5580d5e8c3e8eab94 (patch) | |
tree | 5ea6c8161b030fae8fdce6561ee38c950e302839 /src/account | |
parent | 029fdf1051c2992e4a08202589ddf3067bb512b9 (diff) | |
download | openlmi-providers-9e112eb8e1c56be25d725ef5580d5e8c3e8eab94.tar.gz openlmi-providers-9e112eb8e1c56be25d725ef5580d5e8c3e8eab94.tar.xz openlmi-providers-9e112eb8e1c56be25d725ef5580d5e8c3e8eab94.zip |
account: ModifyInstance of Account
So far only possible to change GECOS record (ElementName), home directory,
login shell and password.
Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src/account')
-rw-r--r-- | src/account/LMI_AccountProvider.c | 106 |
1 files changed, 105 insertions, 1 deletions
diff --git a/src/account/LMI_AccountProvider.c b/src/account/LMI_AccountProvider.c index 79f138b..067ef68 100644 --- a/src/account/LMI_AccountProvider.c +++ b/src/account/LMI_AccountProvider.c @@ -164,7 +164,111 @@ static CMPIStatus LMI_AccountModifyInstance( const CMPIInstance* ci, const char** properties) { - CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); + /* TODO: + * + * Allow to modify the following: + * Set up account expiration + * Set up password expiration + */ + char* value = NULL; + CMPIStatus* st = NULL; + CMPIString* vs = NULL; + CMPIArray* ar = NULL; int arsize;/* used for password */ + CMPIData data; + char errmsg[256]; + + struct lu_context *luc = NULL; + struct lu_ent *lue = NULL; + struct lu_error *error = NULL; + GValue val; + + LMI_Account la; + + LMI_Account_InitFromObjectPath(&la, _cb, cop); + + luc = lu_start(NULL, lu_user, NULL, NULL, lu_prompt_console_quiet, NULL, &error); + if (!luc) + { + fprintf(stderr, "Error initializing: %s\n", lu_strerror(error)); + exit(1); + } + + lue = lu_ent_new(); + if (!lu_user_lookup_name(luc, la.Name.chars, lue, &error)) + { + snprintf(errmsg, 256, "User %s not found: %s", la.Name.chars, + lu_strerror(error)); + lu_end(luc); + lu_ent_free(lue); + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); + } + + data = ci->ft->getProperty(ci, "UserPassword", NULL); + ar = data.value.array; + if (ar && (arsize = ar->ft->getSize(ar, NULL) > 0)) + { + vs = ar->ft->getElementAt(ar, 0, NULL).value.string; + value = vs->ft->getCharPtr(vs, NULL); + if (!lu_user_setpass(luc, lue, value, TRUE, &error)) + { + snprintf(errmsg, 256, "Error setting password: %s", + lu_strerror(error)); + lu_end(luc); + lu_ent_free(lue); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + } + else + { + if (!lu_user_removepass(luc, lue, &error)) + { + snprintf(errmsg, 256, "Error removing password: %s", + lu_strerror(error)); + lu_end(luc); + lu_ent_free(lue); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + } + +#define PARAM(ATTR, VAR)\ + g_value_set_string(&val, (VAR));\ + lu_ent_clear(lue, (ATTR));\ + lu_ent_add(lue, (ATTR), &val);\ + +/* This macro will get property named NAME and save it into `value' variable */ +#define GETSTRVALUE(NAME)\ + data = ci->ft->getProperty(ci, (NAME), NULL);\ + vs = data.value.string;\ + value = vs->ft->getCharPtr(vs, NULL);\ + + memset(&val, 0, sizeof(val)); + g_value_init(&val, G_TYPE_STRING); + + GETSTRVALUE("ElementName"); + PARAM(LU_GECOS, value); + + GETSTRVALUE("HomeDirectory"); + PARAM(LU_HOMEDIRECTORY, value); + + GETSTRVALUE("LoginShell"); + PARAM(LU_LOGINSHELL, value); +#undef PARAM +#undef GETSTRVALUE + g_value_unset(&val); + + + if (!lu_user_modify(luc, lue, &error)) + { + snprintf(errmsg, 256, "User modification failed: %s", + lu_strerror(error)); + lu_end(luc); + lu_ent_free(lue); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + + lu_ent_free(lue); + lu_end(luc); + CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_AccountDeleteInstance( |