From 806c9b45edf41d54c6673fc04a6e0c06e92af101 Mon Sep 17 00:00:00 2001 From: Jan Synacek Date: Wed, 13 Feb 2013 15:26:15 +0100 Subject: LogicalFile: add socket file type and root directory association Add LMI_UnixSocket and LMI_RootDirectory association. LMI_RootDirectory associates the root directory with the computer system on which it resides. --- .../LMI_DirectoryContainsFileProvider.c | 1 + src/logicalfile/LMI_RootDirectoryProvider.c | 311 +++++++++++++++++++++ src/logicalfile/LMI_UnixSocketProvider.c | 147 ++++++++++ 3 files changed, 459 insertions(+) create mode 100644 src/logicalfile/LMI_RootDirectoryProvider.c create mode 100644 src/logicalfile/LMI_UnixSocketProvider.c (limited to 'src') diff --git a/src/logicalfile/LMI_DirectoryContainsFileProvider.c b/src/logicalfile/LMI_DirectoryContainsFileProvider.c index 29bde15..8eb6018 100644 --- a/src/logicalfile/LMI_DirectoryContainsFileProvider.c +++ b/src/logicalfile/LMI_DirectoryContainsFileProvider.c @@ -77,6 +77,7 @@ static CMPIStatus dir_file_objectpaths( (S_ISBLK(sb.st_mode)) ? strcpy(fileclass, "LMI_UnixDeviceFile") : (S_ISLNK(sb.st_mode)) ? strcpy(fileclass, "LMI_SymbolicLink") : (S_ISFIFO(sb.st_mode)) ? strcpy(fileclass, "LMI_FIFOPipeFile") : + (S_ISSOCK(sb.st_mode)) ? strcpy(fileclass, "LMI_UnixSocket") : strcpy(fileclass, "Unknown"); } diff --git a/src/logicalfile/LMI_RootDirectoryProvider.c b/src/logicalfile/LMI_RootDirectoryProvider.c new file mode 100644 index 0000000..4bcedf0 --- /dev/null +++ b/src/logicalfile/LMI_RootDirectoryProvider.c @@ -0,0 +1,311 @@ +/* + * 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: Jan Synacek + */ +#include +#include "LMI_RootDirectory.h" +#include "LMI_UnixDirectory.h" +#include "file.h" + +static const CMPIBroker* _cb; + +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(); + + + if (CMClassPathIsA(_cb, cop, LMI_UnixDirectory_ClassName, &st)) { + /* got LMI_UnixDirectory */ + 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, "/", 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); + } + } + + 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); + + CMPIData pathd; + CMPIData cd; + pathd = CMGetKey(cop, "Name", &st); + cd = CMGetKey(cop, "CreationClassName", &st); + const char *path = KChars(pathd.value.string); + const char *ccname = KChars(cd.value.string); + + LMI_RootDirectory_Init(&lmi_rd, _cb, ns); + + if (!strcmp(ccname, LMI_UnixDirectory_ClassName)) { + /* 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); + if (names) { + LMI_RootDirectory_SetObjectPath_GroupComponent(&lmi_rd, o); + o = LMI_RootDirectory_ToObjectPath(&lmi_rd, &st); + CMReturnObjectPath(cr, o); + } else { + ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); + CMReturnInstance(cr, ci); + } + } else { + /* 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, "/", LMI_UnixDirectory_ClassName); + o = LMI_UnixDirectory_ToObjectPath(&lmi_ud, &st); + if (names) { + LMI_RootDirectory_SetObjectPath_PartComponent(&lmi_rd, o); + o = LMI_RootDirectory_ToObjectPath(&lmi_rd, &st); + CMReturnObjectPath(cr, o); + } else { + ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); + CMReturnInstance(cr, ci); + } + } + + 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: */ diff --git a/src/logicalfile/LMI_UnixSocketProvider.c b/src/logicalfile/LMI_UnixSocketProvider.c new file mode 100644 index 0000000..c122502 --- /dev/null +++ b/src/logicalfile/LMI_UnixSocketProvider.c @@ -0,0 +1,147 @@ +/* + * 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: Jan Synacek + */ +#include +#include "LMI_UnixSocket.h" +#include "file.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_UnixSocketInitialize() +{ +} + +static CMPIStatus LMI_UnixSocketCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixSocketEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixSocketEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixSocketGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + get_instance(UnixSocket, S_IFSOCK, "No such socket: %s"); + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixSocketCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixSocketModifyInstance( + 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_UnixSocketDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixSocketExecQuery( + 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_UnixSocket, + LMI_UnixSocket, + _cb, + LMI_UnixSocketInitialize()) + +static CMPIStatus LMI_UnixSocketMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixSocketInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_UnixSocket_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_UnixSocket, + LMI_UnixSocket, + _cb, + LMI_UnixSocketInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_UnixSocket", + "LMI_UnixSocket", + "instance method") +/* vi: set et: */ -- cgit