/* * Copyright (C) 2012 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_Group.h" #include #include #include "aux_lu.h" #include "macros.h" #include "globals.h" static const CMPIBroker* _cb = NULL; static void LMI_GroupInitialize() { } static CMPIStatus LMI_GroupCleanup( CMPIInstanceMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_GroupEnumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { return KDefaultEnumerateInstanceNames( _cb, mi, cc, cr, cop); } static CMPIStatus LMI_GroupEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { LMI_Group lg; 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); char *instanceid = NULL; luc = lu_start(NULL, lu_group, NULL, NULL, lu_prompt_console_quiet, NULL, &error); if (!luc) { fprintf(stderr, "Error initializing: %s\n", lu_strerror(error)); exit(1); } instanceid = malloc(256 * sizeof(char)); groups = lu_groups_enumerate_full(luc, "*", &error); for (i = 0; (groups != NULL) && (i < groups->len); i++) { lue = g_ptr_array_index(groups, i); LMI_Group_Init(&lg, _cb, nameSpace); LMI_Group_Set_CreationClassName(&lg, LMI_Group_ClassName); LMI_Group_Set_Name(&lg, aux_lu_get_str(lue, LU_GROUPNAME)); LMI_Group_Set_ElementName(&lg, aux_lu_get_str(lue, LU_GROUPNAME)); LMI_Group_Set_CommonName(&lg, aux_lu_get_str(lue, LU_GROUPNAME)); snprintf(instanceid, 255, ORGID":GID:%ld", aux_lu_get_long(lue, LU_GIDNUMBER)); LMI_Group_Set_InstanceID(&lg, instanceid); KReturnInstance(cr, lg); lu_ent_free(lue); } /* for */ free(instanceid); if (groups) { g_ptr_array_free(groups, TRUE); } lu_end(luc); CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_GroupGetInstance( 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_GroupCreateInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_GroupModifyInstance( 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_GroupDeleteInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { LMI_Group lg; const char *name = NULL; 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; luc = lu_start(NULL, 0, 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_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); } 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); } lu_ent_free(lue); lu_end(luc); CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_GroupExecQuery( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* lang, const char* query) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } CMInstanceMIStub( LMI_Group, LMI_Group, _cb, LMI_GroupInitialize()) static CMPIStatus LMI_GroupMethodCleanup( CMPIMethodMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_GroupInvokeMethod( CMPIMethodMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* meth, const CMPIArgs* in, CMPIArgs* out) { return LMI_Group_DispatchMethod( _cb, mi, cc, cr, cop, meth, in, out); } CMMethodMIStub( LMI_Group, LMI_Group, _cb, LMI_GroupInitialize()) KONKRET_REGISTRATION( "root/cimv2", "LMI_Group", "LMI_Group", "instance method")