summaryrefslogtreecommitdiffstats
path: root/src/account/LMI_AccountProvider.c
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2013-06-12 15:28:38 +0200
committerRoman Rakus <rrakus@redhat.com>2013-06-12 15:50:35 +0200
commitec58653e83ba32cba3a3f51d9fcedca4873c7ab7 (patch)
treea2bc5f2922dec675835602d0ea12fcdf66847597 /src/account/LMI_AccountProvider.c
parentccb095d49a35b001439c254beebf5ba4e57e89e0 (diff)
downloadopenlmi-providers-ec58653e83ba32cba3a3f51d9fcedca4873c7ab7.tar.gz
openlmi-providers-ec58653e83ba32cba3a3f51d9fcedca4873c7ab7.tar.xz
openlmi-providers-ec58653e83ba32cba3a3f51d9fcedca4873c7ab7.zip
Account: Use KReturn2 instead of CMReturnWithChars
KReturn2 now supports valist so we don't need to use temp variables Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src/account/LMI_AccountProvider.c')
-rw-r--r--src/account/LMI_AccountProvider.c156
1 files changed, 68 insertions, 88 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));
}