From 09c52ea4b5d3f94bd20dec9baafcdbc05b87f9e8 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Wed, 14 May 2014 12:31:24 +0200 Subject: account: Make LMI_MemberOfGroup.CreateInstance() more robust Return proper error when required properties are not set. https://fedorahosted.org/openlmi/ticket/270 --- src/account/LMI_MemberOfGroupProvider.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/account/LMI_MemberOfGroupProvider.c b/src/account/LMI_MemberOfGroupProvider.c index 4928f4d..d62d016 100644 --- a/src/account/LMI_MemberOfGroupProvider.c +++ b/src/account/LMI_MemberOfGroupProvider.c @@ -168,15 +168,30 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance( struct lu_context *luc = NULL; struct lu_error *error = NULL; + CMPIObjectPath *collection_ref; + CMPIObjectPath *member_ref; CMPIrc rc = CMPI_RC_OK; char *errmsg = NULL; int pwdlockres; +#define GET_REF(PROP_NAME, REF) \ + { \ + CMPIStatus rcs = { CMPI_RC_OK, NULL }; \ + CMPIData d = CMGetProperty(ci, PROP_NAME, &rcs); \ + if (rcs.rc != CMPI_RC_OK || (d.state & CMPI_nullValue) == CMPI_nullValue || \ + (d.state & CMPI_notFound) == CMPI_notFound || d.value.ref == NULL) \ + KReturn2(_cb, ERR_INVALID_PARAMETER, "Required argument '%s' not set.", PROP_NAME);\ + REF = d.value.ref; \ + } + + GET_REF("Collection", collection_ref); + GET_REF("Member", member_ref); + +#undef GET_REF + LMI_MemberOfGroup_InitFromObjectPath(&lmog, _cb, cop); - LMI_GroupRef_InitFromObjectPath(&lg_ref, _cb, - CMGetProperty(ci, "Collection", NULL).value.ref); - LMI_IdentityRef_InitFromObjectPath(&li_ref, _cb, - CMGetProperty(ci, "Member", NULL).value.ref); + LMI_GroupRef_InitFromObjectPath(&lg_ref, _cb, collection_ref); + LMI_IdentityRef_InitFromObjectPath(&li_ref, _cb, member_ref); if (!(instances = CBAssociators(_cb, cc, LMI_IdentityRef_ToObjectPath(&li_ref, NULL), -- cgit