diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/account/LMI_AccountProvider.c | 156 | ||||
-rw-r--r-- | src/account/LMI_GroupProvider.c | 9 | ||||
-rw-r--r-- | src/account/LMI_IdentityProvider.c | 21 | ||||
-rw-r--r-- | src/account/LMI_MemberOfGroupProvider.c | 38 |
4 files changed, 94 insertions, 130 deletions
diff --git a/src/account/LMI_AccountProvider.c b/src/account/LMI_AccountProvider.c index 8eb538b..ef7cbf7 100644 --- a/src/account/LMI_AccountProvider.c +++ b/src/account/LMI_AccountProvider.c @@ -243,7 +243,6 @@ static CMPIStatus LMI_AccountModifyInstance( 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; @@ -268,11 +267,10 @@ static CMPIStatus LMI_AccountModifyInstance( 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); + KReturn2(_cb, ERR_NOT_FOUND, "User %s not found: %s", + la.Name.chars, lu_strerror(error)); } data = ci->ft->getProperty(ci, "UserPassword", NULL); @@ -286,11 +284,10 @@ static CMPIStatus LMI_AccountModifyInstance( { 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); + KReturn2(_cb, ERR_FAILED, "Error setting password: %s", + lu_strerror(error)); } } } @@ -298,11 +295,10 @@ static CMPIStatus LMI_AccountModifyInstance( { 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); + KReturn2(_cb, ERR_FAILED, "Error removing password: %s", + lu_strerror(error)); } } @@ -351,88 +347,75 @@ static CMPIStatus LMI_AccountModifyInstance( last_change = aux_lu_get_long(lue, LU_SHADOWLASTCHANGE); - errmsg[0] = '\0'; - do +#define FAIL(msg) \ + lu_end(luc); \ + lu_ent_free(lue); \ + KReturn2(_cb, ERR_FAILED, msg); + GETDATEVALUE("PasswordExpiration", expiration); + if (!expiration.null && !expiration.interval) { - GETDATEVALUE("PasswordExpiration", expiration); - if (!expiration.null && !expiration.interval) + if ((expiration.value -= last_change) < 0) { - if ((expiration.value -= last_change) < 0) - { - snprintf(errmsg, 256, "Wrong property setting, " - "PasswordExpiration must be later than " - "PasswordLastChange\n"); - break; - } + FAIL("Wrong property setting, " + "PasswordExpiration must be later than " + "PasswordLastChange\n"); } + } - GETDATEVALUE("PasswordExpirationWarning", warning); - if (!warning.null && !warning.interval) + GETDATEVALUE("PasswordExpirationWarning", warning); + if (!warning.null && !warning.interval) + { + if (expiration.null) { - if (expiration.null) - { - snprintf(errmsg, 256, "Wrong property setting, " - "PasswordExpiration must be set if you want to set " - "PasswordExpirationWarning as time of date\n"); - break; - } - warning.value = last_change + expiration.value - warning.value; - if (warning.value < 0) - { - snprintf(errmsg, 256, "Wrong property setting, " - "PasswordExpirationWarning must be earlier than " - "PasswordExpiration\n"); - break; - } + FAIL("Wrong property setting, " + "PasswordExpiration must be set if you want to set " + "PasswordExpirationWarning as time of date\n"); } - - GETDATEVALUE("PasswordInactivation", inactive_password); - if (!inactive_password.null && !inactive_password.interval) + warning.value = last_change + expiration.value - warning.value; + if (warning.value < 0) { - if (expiration.null) - { - snprintf(errmsg, 256, "Wrong property setting, " - "PasswordExpiration must be set if you want to set " - "PasswordInactivation as time of date\n"); - break; - } - inactive_password.value -= last_change + expiration.value; - if (inactive_password.value < 0) - { - snprintf(errmsg, 256, "Wrong property setting, " - "PasswordInactivation must be later than " - "PasswordExpiration\n"); - break; - } + FAIL("Wrong property setting, " + "PasswordExpirationWarning must be earlier than " + "PasswordExpiration\n"); } + } - GETDATEVALUE("PasswordPossibleChange", possible_change); - if (!possible_change.null && !possible_change.interval) + GETDATEVALUE("PasswordInactivation", inactive_password); + if (!inactive_password.null && !inactive_password.interval) + { + if (expiration.null) { - if ((possible_change.value -= last_change) < 0) - { - snprintf(errmsg, 256, "Wrong property setting, " - "PasswordPossibleChange must be later than " - "PasswordLastChange\n"); - break; - } + FAIL("Wrong property setting, " + "PasswordExpiration must be set if you want to set " + "PasswordInactivation as time of date\n"); } + inactive_password.value -= last_change + expiration.value; + if (inactive_password.value < 0) + { + FAIL("Wrong property setting, " + "PasswordInactivation must be later than " + "PasswordExpiration\n"); + } + } - GETDATEVALUE("AccountExpiration", inactive_account); - if (!inactive_account.null && inactive_account.interval) + GETDATEVALUE("PasswordPossibleChange", possible_change); + if (!possible_change.null && !possible_change.interval) + { + if ((possible_change.value -= last_change) < 0) { - snprintf(errmsg, 256, "Wrong property setting, " - "AccountExpiration must be set as interval\n"); - break; + FAIL("Wrong property setting, " + "PasswordPossibleChange must be later than " + "PasswordLastChange\n"); } - } while (0); + } - if (errmsg[0]) - { /* There was an error, print it and return */ - lu_end(luc); - lu_ent_free(lue); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + GETDATEVALUE("AccountExpiration", inactive_account); + if (!inactive_account.null && inactive_account.interval) + { + FAIL("Wrong property setting, " + "AccountExpiration must be set as interval\n"); } +#undef FAIL PARAMLONG(LU_SHADOWMIN, possible_change); PARAMLONG(LU_SHADOWMAX, expiration); @@ -448,11 +431,10 @@ static CMPIStatus LMI_AccountModifyInstance( 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); + KReturn2(_cb, ERR_FAILED, "User modification failed: %s", + lu_strerror(error)); } lu_ent_free(lue); @@ -468,7 +450,6 @@ static CMPIStatus LMI_AccountDeleteInstance( { LMI_Account acc; const char* username = NULL, *home = NULL; - char errmsg[256]; struct lu_context *luc = NULL; struct lu_error *error = NULL; struct lu_ent *lue = NULL; @@ -487,29 +468,28 @@ static CMPIStatus LMI_AccountDeleteInstance( if (!lu_user_lookup_name(luc, username, lue, &error)) { - snprintf(errmsg, 256, "Non existing user: %s\n", username); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); + KReturn2(_cb, ERR_NOT_FOUND, "Non existing user: %s\n", + username); } home = aux_lu_get_str(lue, LU_HOMEDIRECTORY); /* Be really safe here, it can delete ANY directory */ if (!lu_homedir_remove(home, &error)) { - snprintf(errmsg, 256, "User's homedir %s could not be deleted: %s\n", - home, lu_strerror(error)); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, + "User's homedir %s could not be deleted: %s\n", home, + lu_strerror(error)); } if (!lu_user_delete(luc, lue, &error)) { - snprintf(errmsg, 256, "User %s could not be deleted: %s\n", username, - lu_strerror(error)); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "User %s could not be deleted: %s\n", + username, lu_strerror(error)); } diff --git a/src/account/LMI_GroupProvider.c b/src/account/LMI_GroupProvider.c index a9c5477..c9d8ebb 100644 --- a/src/account/LMI_GroupProvider.c +++ b/src/account/LMI_GroupProvider.c @@ -147,7 +147,6 @@ static CMPIStatus LMI_GroupDeleteInstance( struct lu_context *luc = NULL; struct lu_error *error = NULL; struct lu_ent *lue = NULL; - char errmsg[256]; LMI_Group_InitFromObjectPath(&lg, _cb, cop); name = lg.Name.chars; @@ -162,19 +161,17 @@ static CMPIStatus LMI_GroupDeleteInstance( lue = lu_ent_new(); if (!lu_group_lookup_name(luc, name, lue, &error)) { /* Group not found */ - snprintf(errmsg, 256, "Non existing group: %s\n", name); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); + KReturn2(_cb, ERR_NOT_FOUND, "Non existing group: %s\n", name); } if (!lu_group_delete(luc, lue, &error)) { - snprintf(errmsg, 256, "Group %s could not be deleted: %s\n", name, - lu_strerror(error)); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "Group %s could not be deleted: %s\n", name, + lu_strerror(error)); } lu_ent_free(lue); diff --git a/src/account/LMI_IdentityProvider.c b/src/account/LMI_IdentityProvider.c index 92c2b01..b359a69 100644 --- a/src/account/LMI_IdentityProvider.c +++ b/src/account/LMI_IdentityProvider.c @@ -159,7 +159,6 @@ static CMPIStatus LMI_IdentityDeleteInstance( LMI_Identity identity; const char* instance_id = NULL; id_t id; - char errmsg[256]; struct lu_context *luc = NULL; struct lu_error *error = NULL; struct lu_ent *lue = NULL; @@ -180,21 +179,19 @@ static CMPIStatus LMI_IdentityDeleteInstance( { /* It's a group */ if (!lu_group_lookup_id(luc, id, lue, &error)) { /* User with that ID is not present */ - snprintf(errmsg, 256, "Non existing group id: %d\n", id); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); + KReturn2(_cb, ERR_NOT_FOUND, "Non existing group id: %d\n", id); } else { if (!lu_group_delete(luc, lue, &error)) { /* user delete error */ - snprintf(errmsg, 256, - "Group with id %d could not be deleted: %s\n", id, - lu_strerror(error)); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, + "Group with id %d could not be deleted: %s\n", id, + lu_strerror(error)); } } } @@ -202,21 +199,19 @@ static CMPIStatus LMI_IdentityDeleteInstance( { /* It's an user */ if (!lu_user_lookup_id(luc, id, lue, &error)) { /* User with that ID is not present */ - snprintf(errmsg, 256, "Non existing user id: %d\n", id); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); + KReturn2(_cb, ERR_NOT_FOUND, "Non existing user id: %d\n", id); } else { if (!lu_user_delete(luc, lue, &error)) { /* user delete error */ - snprintf(errmsg, 256, - "User with id %d could not be deleted: %s\n", id, - lu_strerror(error)); lu_ent_free(lue); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, + "User with id %d could not be deleted: %s\n", id, + lu_strerror(error)); } } } diff --git a/src/account/LMI_MemberOfGroupProvider.c b/src/account/LMI_MemberOfGroupProvider.c index dddd2e8..06f835c 100644 --- a/src/account/LMI_MemberOfGroupProvider.c +++ b/src/account/LMI_MemberOfGroupProvider.c @@ -154,7 +154,6 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance( { CMPIStatus status; CMPIEnumeration *instances = NULL; - char errmsg[256]; LMI_GroupRef lg_ref; LMI_IdentityRef li_ref; @@ -179,9 +178,8 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance( LMI_IdentityRef_ToObjectPath(&li_ref, NULL), LMI_AssignedAccountIdentity_ClassName, LMI_Account_ClassName, NULL, NULL, NULL, &status)) || !CMHasNext(instances, &status)) { - snprintf(errmsg, 256, "Unable to find user: %s\n", - status.msg ? CMGetCharsPtr(status.msg, NULL) : "" ); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "Unable to find user: %s\n", + status.msg ? CMGetCharsPtr(status.msg, NULL) : "" ); } LMI_Account_InitFromInstance(&la, _cb, CMGetNext(instances, &status).value.inst); @@ -195,9 +193,8 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance( } if (!lu_group_lookup_name(luc, group_name, lue, &error)) { - snprintf(errmsg, 256, "Group with name %s not found: %s\n", group_name, - lu_strerror(error)); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "Group with name %s not found: %s\n", + group_name, lu_strerror(error)); } memset(&val, 0, sizeof(val)); @@ -205,12 +202,11 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance( g_value_set_string(&val, user_name); lu_ent_add(lue, LU_MEMBERNAME, &val); if(!lu_group_modify(luc, lue, &error)) { - snprintf(errmsg, 256, "Modification of group %s failed: %s\n", - group_name, lu_strerror(error)); lu_ent_free(lue); lu_end(luc); g_value_unset(&val); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "Modification of group %s failed: %s\n", + group_name, lu_strerror(error)); } g_value_unset(&val); @@ -254,7 +250,6 @@ static CMPIStatus LMI_MemberOfGroupDeleteInstance( char *group_name = NULL; uid_t user_id = -1; GValueArray *groups = NULL; - char errmsg[256]; unsigned int i = 0; /* iterator */ int found = 0; /* indicator */ @@ -272,18 +267,16 @@ static CMPIStatus LMI_MemberOfGroupDeleteInstance( } if (!lu_user_lookup_id(luc, user_id, lue_u, &error)) { - snprintf(errmsg, 256, "User with id %d not found: %s\n", user_id, - lu_strerror(error)); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "User with id %d not found: %s\n", user_id, + lu_strerror(error)); } if (!lu_group_lookup_name(luc, group_name, lue_g, &error)) { - snprintf(errmsg, 256, "Group with name %s not found: %s\n", group_name, - lu_strerror(error)); lu_ent_free(lue_u); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "Group with name %s not found: %s\n", + group_name, lu_strerror(error)); } groups = lu_ent_get(lue_g, LU_MEMBERNAME); for (found = 0, i = 0; groups && i < groups->n_values; i++) { @@ -294,23 +287,22 @@ static CMPIStatus LMI_MemberOfGroupDeleteInstance( } } if (!found) { - snprintf(errmsg, 256, "User with id %d is not in group %s or is " - "users' primary group\n", user_id, group_name); lu_ent_free(lue_u); lu_ent_free(lue_g); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, + "User with id %d is not in group %s or is users' primary group\n", + user_id, group_name); } else { /* And now remove the user from the group */ g_value_array_remove(groups, i); lu_ent_set(lue_g, LU_MEMBERNAME, groups); if(!lu_group_modify(luc, lue_g, &error)) { - snprintf(errmsg, 256, "Modification of group %s failed: %s\n", - group_name, lu_strerror(error)); lu_ent_free(lue_u); lu_ent_free(lue_g); lu_end(luc); - CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + KReturn2(_cb, ERR_FAILED, "Modification of group %s failed: %s\n", + group_name, lu_strerror(error)); } } |