/* * 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 "CIM_LogicalFile.h" #include "CIM_UnixFile.h" #include "LMI_FileIdentity.h" #include "LMI_UnixFile.h" #include "LMI_DataFile.h" #include "file.h" static const CMPIBroker* _cb; static int check_valid_classes(const CMPIObjectPath *o) { const char *VALID_CLASSES[] = { "LMI_UnixFile", "LMI_DataFile", "LMI_UnixDeviceFile", "LMI_UnixDirectory", "LMI_FIFOPipeFile", "LMI_SymbolicLink", "LMI_UnixSocket", 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, int names) { CMPIStatus st, res; CMPIInstance *ci; CMPIObjectPath *o; const char *ns = KNameSpace(cop); char fileclass[BUFLEN]; char *fsname; /* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */ if (!check_valid_classes(cop)) { CMReturn(CMPI_RC_OK); } if (CMClassPathIsA(_cb, cop, LMI_UnixFile_ClassName, &st)) { /* got UnixFile */ st = lmi_check_required(_cb, cop, UNIXFILE); if (st.rc != CMPI_RC_OK) { return st; } const char *path = get_string_property_from_op(cop, "LFName"); const char *ccname = get_string_property_from_op(cop, "LFCreationClassName"); get_class_from_path(path, fileclass); if (get_fsname_from_path(path, &fsname) < 0) { CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); } /* TODO is this error necessary? */ if (strcmp(fileclass, ccname)) { CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "LMCreationClassName is not correct"); } CIM_LogicalFileRef cim_lfr; CIM_LogicalFileRef_Init(&cim_lfr, _cb, ns); fill_logicalfile(CIM_LogicalFileRef, &cim_lfr, path, fsname, ccname); o = CIM_LogicalFileRef_ToObjectPath(&cim_lfr, &st); CMSetClassName(o, fileclass); } else { /* got LogicalFile */ st = lmi_check_required(_cb, cop, LOGICALFILE); if (st.rc != CMPI_RC_OK) { return st; } const char *path = get_string_property_from_op(cop, "Name"); get_class_from_path(path, fileclass); if (get_fsname_from_path(path, &fsname) < 0) { CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); } LMI_UnixFile lmi_uf; LMI_UnixFile_Init(&lmi_uf, _cb, ns); LMI_UnixFile_Set_LFName(&lmi_uf, path); LMI_UnixFile_Set_CSCreationClassName(&lmi_uf, get_system_creation_class_name()); LMI_UnixFile_Set_CSName(&lmi_uf, get_system_name()); LMI_UnixFile_Set_FSCreationClassName(&lmi_uf, FSCREATIONCLASSNAME); LMI_UnixFile_Set_FSName(&lmi_uf, fsname); LMI_UnixFile_Set_LFCreationClassName(&lmi_uf, fileclass); o = LMI_UnixFile_ToObjectPath(&lmi_uf, &st); } if (names) { res = CMReturnObjectPath(cr, o); } else { ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); res = CMReturnInstance(cr, ci); } free(fsname); return res; } static CMPIStatus references( CMPIAssociationMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char* assocClass, const char* role, const char** properties, int names) { LMI_FileIdentity lmi_fi; CMPIStatus st, res; const char *ns = KNameSpace(cop); CMPIInstance *ci; CMPIObjectPath *o; char fileclass[BUFLEN]; char *fsname; /* * allow only LMI_UnixFile and classes derived from CIM_LogicalFile * * XXX this should not be necessary, but FileIdentity.Refereneces() is * called when Linux_ComputerSystem.References() is... server bug? */ if (!check_valid_classes(cop)) { CMReturn(CMPI_RC_OK); } LMI_FileIdentity_Init(&lmi_fi, _cb, ns); if (CMClassPathIsA(_cb, cop, LMI_UnixFile_ClassName, &st)) { /* got UnixFile */ LMI_FileIdentity_SetObjectPath_SameElement(&lmi_fi, cop); st = lmi_check_required(_cb, cop, UNIXFILE); if (st.rc != CMPI_RC_OK) { return st; } const char *path = get_string_property_from_op(cop, "LFName"); const char *ccname = get_string_property_from_op(cop, "LFCreationClassName"); get_class_from_path(path, fileclass); if (get_fsname_from_path(path, &fsname) < 0) { CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); } /* TODO is this error necessary? */ if (strcmp(fileclass, ccname)) { CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "LFCreationClassName is not correct"); } /* SystemElement */ CIM_LogicalFileRef lmi_lfr; CIM_LogicalFileRef_Init(&lmi_lfr, _cb, ns); fill_logicalfile(CIM_LogicalFileRef, &lmi_lfr, path, fsname, ccname); o = CIM_LogicalFileRef_ToObjectPath(&lmi_lfr, &st); CMSetClassName(o, fileclass); LMI_FileIdentity_SetObjectPath_SystemElement(&lmi_fi, o); } else { /* got LogicalFile */ LMI_FileIdentity_SetObjectPath_SystemElement(&lmi_fi, cop); st = lmi_check_required(_cb, cop, LOGICALFILE); if (st.rc != CMPI_RC_OK) { return st; } const char *path = get_string_property_from_op(cop, "Name"); const char *ccname = get_string_property_from_op(cop, "CreationClassName"); if (get_fsname_from_path(path, &fsname) < 0) { CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); } /* SameElement */ LMI_UnixFile lmi_uf; LMI_UnixFile_Init(&lmi_uf, _cb, ns); LMI_UnixFile_Set_LFName(&lmi_uf, path); LMI_UnixFile_Set_CSCreationClassName(&lmi_uf, get_system_creation_class_name()); LMI_UnixFile_Set_CSName(&lmi_uf, get_system_name()); LMI_UnixFile_Set_FSCreationClassName(&lmi_uf, FSCREATIONCLASSNAME); LMI_UnixFile_Set_FSName(&lmi_uf, fsname); LMI_UnixFile_Set_LFCreationClassName(&lmi_uf, ccname); o = LMI_UnixFile_ToObjectPath(&lmi_uf, &st); LMI_FileIdentity_SetObjectPath_SameElement(&lmi_fi, o); } if (names) { o = LMI_FileIdentity_ToObjectPath(&lmi_fi, &st); res = CMReturnObjectPath(cr, o); } else { ci = LMI_FileIdentity_ToInstance(&lmi_fi, &st); res = CMReturnInstance(cr, ci); } free(fsname); return res; } static void LMI_FileIdentityInitialize() { } static CMPIStatus LMI_FileIdentityCleanup( CMPIInstanceMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_FileIdentityEnumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_FileIdentityEnumInstances( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_FileIdentityGetInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { /* TODO TBI */ CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_FileIdentityCreateInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const CMPIInstance* ci) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_FileIdentityModifyInstance( 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_FileIdentityDeleteInstance( CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop) { CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } static CMPIStatus LMI_FileIdentityExecQuery( 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_FileIdentityAssociationCleanup( CMPIAssociationMI* mi, const CMPIContext* cc, CMPIBoolean term) { CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_FileIdentityAssociators( 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_FileIdentityAssociatorNames( 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_FileIdentityReferences( 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_FileIdentityReferenceNames( 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_FileIdentity, LMI_FileIdentity, _cb, LMI_FileIdentityInitialize()) CMAssociationMIStub( LMI_FileIdentity, LMI_FileIdentity, _cb, LMI_FileIdentityInitialize()) KONKRET_REGISTRATION( "root/cimv2", "LMI_FileIdentity", "LMI_FileIdentity", "instance association") /* vi: set et: */