/* * Copyright (C) 2012-2013 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: Jan Synacek */ #include #include "LMI_RootDirectory.h" #include "LMI_UnixDirectory.h" #include "file.h" static const CMPIBroker* _cb; static int check_valid_classes(const CMPIObjectPath *o) { const char *VALID_CLASSES[] = { "LMI_UnixDirectory", "Linux_ComputerSystem", NULL }; int found = 0; for (int i = 0; VALID_CLASSES[i]; i++) { if (CMClassPathIsA(_cb, o, VALID_CLASSES[i], NULL)) { found++; break; } } return found; } static CMPIStatus associators( 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, const int names) { CMPIObjectPath *o; CMPIInstance *ci; CMPIStatus st; const char *ns = KNameSpace(cop); const char *comp_ccname = get_system_creation_class_name(); const char *path = get_string_property_from_op(cop, "Name"); char *fsname; if (get_fsname_from_path("/", &fsname) < 0) { CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); } /* * allow only LMI_UnixDirectory and Linux_ComputerSystem * XXX */ if (!check_valid_classes(cop)) { CMReturn(CMPI_RC_OK); } if (CMClassPathIsA(_cb, cop, LMI_UnixDirectory_ClassName, &st)) { /* got LMI_UnixDirectory */ /* ignore this association if the directory is not root */ if (strcmp(path, "/")) { CMReturn(CMPI_RC_OK); } CIM_ComputerSystemRef cim_csr; CIM_ComputerSystemRef_Init(&cim_csr, _cb, ns); CIM_ComputerSystemRef_Set_Name(&cim_csr, get_system_name()); CIM_ComputerSystemRef_Set_CreationClassName(&cim_csr, comp_ccname); o = CIM_ComputerSystemRef_ToObjectPath(&cim_csr, &st); CMSetClassName(o, comp_ccname); if (names) { CMReturnObjectPath(cr, o); } else { ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); CMReturnInstance(cr, ci); } } else { /* got Linux_ComputerSystem */ LMI_UnixDirectory lmi_ud; LMI_UnixDirectory_Init(&lmi_ud, _cb, ns); fill_logicalfile(LMI_UnixDirectory, &lmi_ud, "/", fsname, LMI_UnixDirectory_ClassName); o = LMI_UnixDirectory_ToObjectPath(&lmi_ud, &st); if (names) { CMReturnObjectPath(cr, o); } else { ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); CMReturnInstance(cr, ci); } } free(fsname); CMReturn(CMPI_RC_OK); } static CMPIStatus references( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role, const char** properties, const int names) { LMI_RootDirectory lmi_rd; CMPIObjectPath *o; CMPIInstance *ci; CMPIStatus st; const char *comp_ccname = get_system_creation_class_name(); const char *ns = KNameSpace(cop); const char *path = get_string_property_from_op(cop, "Name"); const char *ccname = get_string_property_from_op(cop, "CreationClassName"); char *fsname; if (get_fsname_from_path("/", &fsname) < 0) { CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); } /* * allow only LMI_UnixDirectory and Linux_ComputerSystem * XXX */ if (!check_valid_classes(cop)) { CMReturn(CMPI_RC_OK); } LMI_RootDirectory_Init(&lmi_rd, _cb, ns); if (!strcmp(ccname, LMI_UnixDirectory_ClassName)) { /* got UnixDirectory */ /* ignore this association if the directory is not root */ if (strcmp(path, "/")) { CMReturn(CMPI_RC_OK); } st = lmi_check_required(_cb, cop, LOGICALFILE); if (st.rc != CMPI_RC_OK) { return st; } LMI_RootDirectory_SetObjectPath_PartComponent(&lmi_rd, cop); CIM_ComputerSystemRef cim_csr; CIM_ComputerSystemRef_Init(&cim_csr, _cb, ns); CIM_ComputerSystemRef_Set_Name(&cim_csr, get_system_name()); CIM_ComputerSystemRef_Set_CreationClassName(&cim_csr, comp_ccname); o = CIM_ComputerSystemRef_ToObjectPath(&cim_csr, &st); CMSetClassName(o, comp_ccname); LMI_RootDirectory_SetObjectPath_GroupComponent(&lmi_rd, o); } else { /* got Linux_ComputerSystem */ LMI_RootDirectory_SetObjectPath_GroupComponent(&lmi_rd, cop); LMI_UnixDirectory lmi_ud; LMI_UnixDirectory_Init(&lmi_ud, _cb, ns); fill_logicalfile(LMI_UnixDirectory, &lmi_ud, "/", fsname, LMI_UnixDirectory_ClassName); o = LMI_UnixDirectory_ToObjectPath(&lmi_ud, &st); LMI_RootDirectory_SetObjectPath_PartComponent(&lmi_rd, o); } if (names) { o = LMI_RootDirectory_ToObjectPath(&lmi_rd, &st); CMReturnObjectPath(cr, o); } else { ci = LMI_RootDirectory_ToInstance(&lmi_rd, &st); CMReturnInstance(cr, ci); } free(fsname); CMReturn(CMPI_RC_OK); } static void LMI_RootDirectoryInitialize() { } static CMPIStatus LMI_RootDirectoryCleanup( CMPIInstanceMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_RootDirectoryEnumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_RootDirectoryEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_RootDirectoryGetInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { /* TODO TBI */ CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_RootDirectoryCreateInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_RootDirectoryModifyInstance( 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_RootDirectoryDeleteInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_RootDirectoryExecQuery( 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_RootDirectoryAssociationCleanup( CMPIAssociationMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_RootDirectoryAssociators( 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 associators(mi, cc, cr, cop, assocClass, resultClass, role, resultRole, properties, 0); } static CMPIStatus LMI_RootDirectoryAssociatorNames( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* resultClass, const char* role, const char* resultRole) { return associators(mi, cc, cr, cop, assocClass, resultClass, role, resultRole, NULL, 1); } static CMPIStatus LMI_RootDirectoryReferences( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role, const char** properties) { return references(mi, cc, cr, cop, assocClass, role, properties, 0); } static CMPIStatus LMI_RootDirectoryReferenceNames( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role) { return references(mi, cc, cr, cop, assocClass, role, NULL, 1); } CMInstanceMIStub( LMI_RootDirectory, LMI_RootDirectory, _cb, LMI_RootDirectoryInitialize()) CMAssociationMIStub( LMI_RootDirectory, LMI_RootDirectory, _cb, LMI_RootDirectoryInitialize()) KONKRET_REGISTRATION( "root/cimv2", "LMI_RootDirectory", "LMI_RootDirectory", "instance association") /* vi: set et: */