/* * Copyright (C) 2012-2014 Red Hat, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: Roman Rakus */ #include #include "LMI_OwningGroup.h" #include "CIM_ComputerSystem.h" #include "LMI_Group.h" #include "macros.h" #include "aux_lu.h" #include "account_globals.h" #include #include static const CMPIBroker* _cb; static void LMI_OwningGroupInitialize(const CMPIContext *ctx) { lmi_init(provider_name, _cb, ctx, provider_config_defaults); } static CMPIStatus LMI_OwningGroupCleanup( CMPIInstanceMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_OwningGroupEnumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { return KDefaultEnumerateInstanceNames( _cb, mi, cc, cr, cop); } static CMPIStatus LMI_OwningGroupEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { LMI_GroupRef lgref; LMI_OwningGroup log; struct lu_context *luc = NULL; struct lu_error *error = NULL; GPtrArray *groups = NULL; struct lu_ent *lue = NULL; size_t i; const char *nameSpace = KNameSpace(cop); luc = lu_start(NULL, lu_group, NULL, NULL, lu_prompt_console_quiet, NULL, &error); if (!luc) { KReturn2(_cb, ERR_FAILED, "Unable to initialize libuser: %s\n", lu_strerror(error)); } groups = lu_groups_enumerate_full(luc, "*", &error); for (i = 0; (groups != NULL) && (i < groups->len); i++) { lue = g_ptr_array_index(groups, i); LMI_GroupRef_Init(&lgref, _cb, nameSpace); LMI_GroupRef_Set_Name(&lgref, aux_lu_get_str(lue, LU_GROUPNAME)); LMI_GroupRef_Set_CreationClassName(&lgref, LMI_Group_ClassName); LMI_OwningGroup_Init(&log, _cb, nameSpace); LMI_OwningGroup_SetObjectPath_OwningElement(&log, lmi_get_computer_system()); LMI_OwningGroup_Set_OwnedElement(&log, &lgref); KReturnInstance(cr, log); lu_ent_free(lue); } /* for */ if (groups) { g_ptr_array_free(groups, TRUE); } lu_end(luc); CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_OwningGroupGetInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { return KDefaultGetInstance( _cb, mi, cc, cr, cop, properties); } static CMPIStatus LMI_OwningGroupCreateInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_OwningGroupModifyInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci, const char**properties) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_OwningGroupDeleteInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_OwningGroupExecQuery( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* lang, const char* query) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_OwningGroupAssociationCleanup( CMPIAssociationMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_OwningGroupAssociators( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* resultClass, const char* role, const char* resultRole, const char** properties) { return KDefaultAssociators( _cb, mi, cc, cr, cop, LMI_OwningGroup_ClassName, assocClass, resultClass, role, resultRole, properties); } static CMPIStatus LMI_OwningGroupAssociatorNames( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* resultClass, const char* role, const char* resultRole) { return KDefaultAssociatorNames( _cb, mi, cc, cr, cop, LMI_OwningGroup_ClassName, assocClass, resultClass, role, resultRole); } static CMPIStatus LMI_OwningGroupReferences( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role, const char** properties) { return KDefaultReferences( _cb, mi, cc, cr, cop, LMI_OwningGroup_ClassName, assocClass, role, properties); } static CMPIStatus LMI_OwningGroupReferenceNames( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role) { return KDefaultReferenceNames( _cb, mi, cc, cr, cop, LMI_OwningGroup_ClassName, assocClass, role); } CMInstanceMIStub( LMI_OwningGroup, LMI_OwningGroup, _cb, LMI_OwningGroupInitialize(ctx)) CMAssociationMIStub( LMI_OwningGroup, LMI_OwningGroup, _cb, LMI_OwningGroupInitialize(ctx)) KONKRET_REGISTRATION( "root/cimv2", "LMI_OwningGroup", "LMI_OwningGroup", "instance association")