diff options
author | Jan Synacek <jsynacek@redhat.com> | 2013-02-08 13:16:31 +0100 |
---|---|---|
committer | Jan Synacek <jsynacek@redhat.com> | 2013-02-11 13:10:40 +0100 |
commit | 7f40ebbf575d93a9d0bc540c484969ec614f308b (patch) | |
tree | 3a698f3560c626c5e9ca6aa060dc1c4b3e836b0a /src/logicalfile | |
parent | 80a4e2961a65f9922e000d27ce642a4789588648 (diff) | |
download | openlmi-providers-7f40ebbf575d93a9d0bc540c484969ec614f308b.tar.gz openlmi-providers-7f40ebbf575d93a9d0bc540c484969ec614f308b.tar.xz openlmi-providers-7f40ebbf575d93a9d0bc540c484969ec614f308b.zip |
New provider: LogicalFile
Diffstat (limited to 'src/logicalfile')
-rw-r--r-- | src/logicalfile/CMakeLists.txt | 29 | ||||
-rw-r--r-- | src/logicalfile/LMI_DataFileProvider.c | 147 | ||||
-rw-r--r-- | src/logicalfile/LMI_DirectoryContainsFileProvider.c | 411 | ||||
-rw-r--r-- | src/logicalfile/LMI_FIFOPipeFileProvider.c | 147 | ||||
-rw-r--r-- | src/logicalfile/LMI_FileIdentityProvider.c | 302 | ||||
-rw-r--r-- | src/logicalfile/LMI_SymbolicLinkProvider.c | 157 | ||||
-rw-r--r-- | src/logicalfile/LMI_UnixDeviceFileProvider.c | 162 | ||||
-rw-r--r-- | src/logicalfile/LMI_UnixDirectoryProvider.c | 160 | ||||
-rw-r--r-- | src/logicalfile/LMI_UnixFileProvider.c | 177 | ||||
-rw-r--r-- | src/logicalfile/file.c | 76 | ||||
-rw-r--r-- | src/logicalfile/file.h | 107 |
11 files changed, 1875 insertions, 0 deletions
diff --git a/src/logicalfile/CMakeLists.txt b/src/logicalfile/CMakeLists.txt new file mode 100644 index 0000000..8b0097a --- /dev/null +++ b/src/logicalfile/CMakeLists.txt @@ -0,0 +1,29 @@ + +set(PROVIDER_NAME LogicalFile) +set(LIBRARY_NAME cmpiLMI_${PROVIDER_NAME}) +set(MOF LMI_LogicalFile.mof) + +set(provider_SRCS + file.c +) + +konkretcmpi_generate(${MOF} + CIM_PROVIDERS + CIM_HEADERS +) + +add_library(${LIBRARY_NAME} SHARED + ${provider_SRCS} + ${CIM_PROVIDERS} + ${CIM_HEADERS} +) + +#pkg_check_modules(LIBPCI REQUIRED libpci) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMPI_INCLUDE_DIR} ${LIBPCI_INCLUDE_DIR}) +target_link_libraries(${LIBRARY_NAME} openlmicommon ${KONKRETCMPI_LIBRARIES} ${LIBPCI_LIBRARIES}) + +# Create registration file +cim_registration(${PROVIDER_NAME} ${LIBRARY_NAME} ${MOF} share/openlmi-providers) + +install(TARGETS ${LIBRARY_NAME} DESTINATION lib${LIB_SUFFIX}/cmpi) diff --git a/src/logicalfile/LMI_DataFileProvider.c b/src/logicalfile/LMI_DataFileProvider.c new file mode 100644 index 0000000..aa8e9e1 --- /dev/null +++ b/src/logicalfile/LMI_DataFileProvider.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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#include "LMI_DataFile.h" +#include "file.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_DataFileInitialize() +{ +} + +static CMPIStatus LMI_DataFileCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DataFileEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DataFileEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DataFileGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + get_instance(DataFile, S_IFREG, "Not a regular file: %s"); + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DataFileCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DataFileModifyInstance( + 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_DataFileDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DataFileExecQuery( + 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_DataFile, + LMI_DataFile, + _cb, + LMI_DataFileInitialize()) + +static CMPIStatus LMI_DataFileMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DataFileInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_DataFile_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_DataFile, + LMI_DataFile, + _cb, + LMI_DataFileInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_DataFile", + "LMI_DataFile", + "instance method") +/* vi: set et: */ diff --git a/src/logicalfile/LMI_DirectoryContainsFileProvider.c b/src/logicalfile/LMI_DirectoryContainsFileProvider.c new file mode 100644 index 0000000..29bde15 --- /dev/null +++ b/src/logicalfile/LMI_DirectoryContainsFileProvider.c @@ -0,0 +1,411 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#include "LMI_DirectoryContainsFile.h" +#include "LMI_UnixDirectory.h" +#include "CIM_LogicalFile.h" +#include "CIM_Directory.h" +#include "file.h" + +static const CMPIBroker* _cb; + +/* XXX if a directory contains more than MAX_REFS files, + * broker will abort with an error */ +/* const unsigned int MAX_REFS = 65536; */ +const unsigned int MAX_REFS = 4096; + +static CMPIStatus dir_file_objectpaths( + const CMPIContext* cc, + const CMPIResult* cr, + const char** properties, + const char *namespace, + const char *path, + CMPIObjectPath **ops, + unsigned int *count) +{ + CMPIObjectPath *o; + CMPIStatus st; + unsigned int i = 0; + + struct stat sb; + struct dirent *de; + DIR *dp; + dp = opendir(path); + while ((de = readdir(dp))) { + if (!strcmp(de->d_name, ".")) { + continue; + } + + char rpath[BUFLEN]; + char fileclass[BUFLEN]; + char *aux = strdup(path); + + if (!strcmp(de->d_name, "..")) { + strncpy(rpath, dirname(aux), BUFLEN); + free(aux); + } else { + snprintf(rpath, BUFLEN, "%s/%s", + (!strcmp(path, "/")) ? "" : path, + de->d_name); + } + + if (lstat(rpath, &sb) < 0) { + char err[BUFLEN]; + snprintf(err, BUFLEN, "Can't stat file: %s", rpath); + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, err); + } else { + (S_ISREG(sb.st_mode)) ? strcpy(fileclass, "LMI_DataFile") : + (S_ISDIR(sb.st_mode)) ? strcpy(fileclass, "LMI_UnixDirectory") : + (S_ISCHR(sb.st_mode)) ? strcpy(fileclass, "LMI_UnixDeviceFile") : + (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") : + strcpy(fileclass, "Unknown"); + } + + CIM_LogicalFileRef cim_lfr; + CIM_LogicalFileRef_Init(&cim_lfr, _cb, namespace); + fill_logicalfile(CIM_LogicalFileRef, &cim_lfr, rpath, fileclass); + o = CIM_LogicalFileRef_ToObjectPath(&cim_lfr, &st); + CMSetClassName(o, fileclass); + + ops[i++] = o; + } + *count = i; + CMReturn(CMPI_RC_OK); +} + +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) +{ + CMPIObjectPath *o; + CMPIInstance *ci; + CMPIStatus st; + CMPIData cd, pathd; + const char *ns = KNameSpace(cop); + + st = lmi_check_required(_cb, cop, LOGICALFILE); + if (st.rc != CMPI_RC_OK) { + return st; + } + + cd = CMGetKey(cop, "CreationClassName", &st); + const char *ccname = KChars(cd.value.string); + pathd = CMGetKey(cop, "Name", &st); + const char *path = KChars(pathd.value.string); + + CMPIObjectPath *refs[MAX_REFS]; + unsigned int count; + + if (CMClassPathIsA(_cb, cop, LMI_UnixDirectory_ClassName, &st)) { + /* UnixDirectory */ + st = dir_file_objectpaths(cc, cr, properties, ns, path, refs, &count); + if (st.rc != CMPI_RC_OK) { + return st; + } + if (count > MAX_REFS) { + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "Too many files in a single directory..."); + } + for (unsigned int i = 0; i < count; i++) { + if (names) { + CMReturnObjectPath(cr, refs[i]); + } else { + ci = _cb->bft->getInstance(_cb, cc, refs[i], properties, &st); + CMReturnInstance(cr, ci); + } + } + } else { + /* LogicalFile */ + CIM_LogicalFileRef cim_lfr; + CIM_LogicalFileRef_Init(&cim_lfr, _cb, ns); + fill_logicalfile(CIM_LogicalFileRef, &cim_lfr, path, ccname); + + o = CIM_LogicalFileRef_ToObjectPath(&cim_lfr, &st); + CMSetClassName(o, ccname); + 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, + int names) +{ + LMI_DirectoryContainsFile lmi_dcf; + CMPIStatus st; + CMPIData pathd; + CMPIData cd; + const char *ns = KNameSpace(cop); + + /* GroupComponent */ + CIM_DirectoryRef lmi_dr; + /* PartComponent */ + CIM_LogicalFileRef lmi_lfr; + CMPIObjectPath *o; + CMPIInstance *ci; + + CIM_DirectoryRef_Init(&lmi_dr, _cb, ns); + CIM_LogicalFileRef_Init(&lmi_lfr, _cb, ns); + LMI_DirectoryContainsFile_Init(&lmi_dcf, _cb, ns); + + st = lmi_check_required(_cb, cop, LOGICALFILE); + if (st.rc != CMPI_RC_OK) { + return st; + } + + cd = CMGetKey(cop, "CreationClassName", &st); + const char *ccname = KChars(cd.value.string); + pathd = CMGetKey(cop, "Name", &st); + const char *path = KChars(pathd.value.string); + + if (!strcmp(ccname, LMI_UnixDirectory_ClassName)) { + /* got GroupComponent - DirectoryRef */ + fill_logicalfile(CIM_DirectoryRef, &lmi_dr, path, LMI_UnixDirectory_ClassName); + o = CIM_DirectoryRef_ToObjectPath(&lmi_dr, &st); + CMSetClassName(o, LMI_UnixDirectory_ClassName); + LMI_DirectoryContainsFile_SetObjectPath_GroupComponent(&lmi_dcf, o); + + /* PartComponent */ + CMPIObjectPath *refs[MAX_REFS]; + unsigned int count; + st = dir_file_objectpaths(cc, cr, properties, ns, path, refs, &count); + if (st.rc != CMPI_RC_OK) { + return st; + } + if (count > MAX_REFS) { + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "Too many files in a single directory..."); + } + for (unsigned int i = 0; i < count; i++) { + if (names) { + LMI_DirectoryContainsFile_SetObjectPath_PartComponent(&lmi_dcf, refs[i]); + o = LMI_DirectoryContainsFile_ToObjectPath(&lmi_dcf, &st); + CMReturnObjectPath(cr, o); + } else { + ci = _cb->bft->getInstance(_cb, cc, refs[i], properties, &st); + CMReturnInstance(cr, ci); + } + } + } else { + /* got PartComponent - LogicalFileRef */ + fill_logicalfile(CIM_LogicalFileRef, &lmi_lfr, path, ccname); + o = CIM_LogicalFileRef_ToObjectPath(&lmi_lfr, &st); + CMSetClassName(o, ccname); + LMI_DirectoryContainsFile_SetObjectPath_PartComponent(&lmi_dcf, o); + + /* GroupComponent */ + char *aux = strdup(path); + fill_logicalfile(CIM_DirectoryRef, &lmi_dr, dirname(aux), LMI_UnixDirectory_ClassName); + o = CIM_DirectoryRef_ToObjectPath(&lmi_dr, &st); + CMSetClassName(o, LMI_UnixDirectory_ClassName); + if (names) { + LMI_DirectoryContainsFile_SetObjectPath_GroupComponent(&lmi_dcf, o); + o = LMI_DirectoryContainsFile_ToObjectPath(&lmi_dcf, &st); + CMReturnObjectPath(cr, o); + } else { + ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); + CMReturnInstance(cr, ci); + } + free(aux); + } + CMReturn(CMPI_RC_OK); +} + +static void LMI_DirectoryContainsFileInitialize() +{ +} + +static CMPIStatus LMI_DirectoryContainsFileCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DirectoryContainsFileEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DirectoryContainsFileEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DirectoryContainsFileGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + /* TODO TBI */ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DirectoryContainsFileCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DirectoryContainsFileModifyInstance( + 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_DirectoryContainsFileDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DirectoryContainsFileExecQuery( + 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_DirectoryContainsFileAssociationCleanup( + CMPIAssociationMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + + +static CMPIStatus LMI_DirectoryContainsFileAssociators( + 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_DirectoryContainsFileAssociatorNames( + 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_DirectoryContainsFileReferences( + 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_DirectoryContainsFileReferenceNames( + 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_DirectoryContainsFile, + LMI_DirectoryContainsFile, + _cb, + LMI_DirectoryContainsFileInitialize()) + +CMAssociationMIStub( + LMI_DirectoryContainsFile, + LMI_DirectoryContainsFile, + _cb, + LMI_DirectoryContainsFileInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_DirectoryContainsFile", + "LMI_DirectoryContainsFile", + "instance association") +/* vi: set et: */ diff --git a/src/logicalfile/LMI_FIFOPipeFileProvider.c b/src/logicalfile/LMI_FIFOPipeFileProvider.c new file mode 100644 index 0000000..3a4c1ff --- /dev/null +++ b/src/logicalfile/LMI_FIFOPipeFileProvider.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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#include "LMI_FIFOPipeFile.h" +#include "file.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_FIFOPipeFileInitialize() +{ +} + +static CMPIStatus LMI_FIFOPipeFileCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_FIFOPipeFileEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_FIFOPipeFileEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_FIFOPipeFileGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + get_instance(FIFOPipeFile, S_IFIFO, "No such FIFO: %s"); + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_FIFOPipeFileCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_FIFOPipeFileModifyInstance( + 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_FIFOPipeFileDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_FIFOPipeFileExecQuery( + 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_FIFOPipeFile, + LMI_FIFOPipeFile, + _cb, + LMI_FIFOPipeFileInitialize()) + +static CMPIStatus LMI_FIFOPipeFileMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_FIFOPipeFileInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_FIFOPipeFile_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_FIFOPipeFile, + LMI_FIFOPipeFile, + _cb, + LMI_FIFOPipeFileInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_FIFOPipeFile", + "LMI_FIFOPipeFile", + "instance method") +/* vi: set et: */ diff --git a/src/logicalfile/LMI_FileIdentityProvider.c b/src/logicalfile/LMI_FileIdentityProvider.c new file mode 100644 index 0000000..453764e --- /dev/null +++ b/src/logicalfile/LMI_FileIdentityProvider.c @@ -0,0 +1,302 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#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 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; + + /* TODO filtering */ + if (names) { + res = CMReturnObjectPath(cr, cop); + } else { + ci = _cb->bft->getInstance(_cb, cc, cop, properties, &st); + res = CMReturnInstance(cr, ci); + } + + 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; + /* SameElement */ + LMI_UnixFile lmi_uf; + /* SystemElement */ + CIM_LogicalFileRef lmi_lfr; + CMPIStatus st; + CMPIData pathd; + CMPIData cnd; + const char *ns = KNameSpace(cop); + CMPIInstance *ci; + + LMI_FileIdentity_Init(&lmi_fi, _cb, ns); + + if (CMClassPathIsA(_cb, cop, LMI_UnixFile_ClassName, &st)) { + /* got SameElement - UnixFile */ + LMI_FileIdentity_SetObjectPath_SameElement(&lmi_fi, cop); + + st = lmi_check_required(_cb, cop, UNIXFILE); + if (st.rc != CMPI_RC_OK) { + return st; + } + + pathd = CMGetKey(cop, "LFName", &st); + cnd = CMGetKey(cop, "LFCreationClassName", &st); + const char *path = KChars(pathd.value.string); + const char *ccname = KChars(cnd.value.string); + + /* SystemElement */ + CIM_LogicalFileRef_Init(&lmi_lfr, _cb, ns); + fill_logicalfile(CIM_LogicalFileRef, &lmi_lfr, path, ccname); + CMPIObjectPath *o = CIM_LogicalFileRef_ToObjectPath(&lmi_lfr, &st); + CMSetClassName(o, ccname); + + if (names) { + LMI_FileIdentity_SetObjectPath_SystemElement(&lmi_fi, o); + } else { + ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); + CMReturnInstance(cr, ci); + } + } else { + /* got SystemElement - LogicalFile */ + LMI_FileIdentity_SetObjectPath_SystemElement(&lmi_fi, cop); + + st = lmi_check_required(_cb, cop, LOGICALFILE); + if (st.rc != CMPI_RC_OK) { + return st; + } + + pathd = CMGetKey(cop, "Name", &st); + cnd = CMGetKey(cop, "CreationClassName", &st); + const char *path = KChars(pathd.value.string); + const char *ccname = KChars(cnd.value.string); + + /* SameElement */ + 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); + CMPIObjectPath *o = LMI_UnixFile_ToObjectPath(&lmi_uf, &st); + if (names) { + LMI_FileIdentity_SetObjectPath_SameElement(&lmi_fi, o); + } else { + ci = _cb->bft->getInstance(_cb, cc, o, properties, &st); + CMReturnInstance(cr, ci); + } + } + + if (names) { + return CMReturnObjectPath(cr, LMI_FileIdentity_ToObjectPath(&lmi_fi, &st)); + } + CMReturn(CMPI_RC_OK); +} + +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: */ diff --git a/src/logicalfile/LMI_SymbolicLinkProvider.c b/src/logicalfile/LMI_SymbolicLinkProvider.c new file mode 100644 index 0000000..0645689 --- /dev/null +++ b/src/logicalfile/LMI_SymbolicLinkProvider.c @@ -0,0 +1,157 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#include "LMI_SymbolicLink.h" +#include "file.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_SymbolicLinkInitialize() +{ +} + +static CMPIStatus LMI_SymbolicLinkCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_SymbolicLinkEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_SymbolicLinkEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_SymbolicLinkGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_SymbolicLink lmi_file; + const char *path; + char rpath[PATH_MAX]; + + LMI_SymbolicLink_InitFromObjectPath(&lmi_file, _cb, cop); + path = KChars(lmi_file.Name.value); + fill_basic(SymbolicLink, path, S_IFLNK, "No such symlink: %s"); + realpath(path, rpath); + LMI_SymbolicLink_Set_TargetFile(&lmi_file, rpath); + + KReturnInstance(cr, lmi_file); + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_SymbolicLinkCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_SymbolicLinkModifyInstance( + 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_SymbolicLinkDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_SymbolicLinkExecQuery( + 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_SymbolicLink, + LMI_SymbolicLink, + _cb, + LMI_SymbolicLinkInitialize()) + +static CMPIStatus LMI_SymbolicLinkMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_SymbolicLinkInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_SymbolicLink_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_SymbolicLink, + LMI_SymbolicLink, + _cb, + LMI_SymbolicLinkInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_SymbolicLink", + "LMI_SymbolicLink", + "instance method") +/* vi: set et: */ diff --git a/src/logicalfile/LMI_UnixDeviceFileProvider.c b/src/logicalfile/LMI_UnixDeviceFileProvider.c new file mode 100644 index 0000000..22d4486 --- /dev/null +++ b/src/logicalfile/LMI_UnixDeviceFileProvider.c @@ -0,0 +1,162 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#include "LMI_UnixDeviceFile.h" +#include "file.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_UnixDeviceFileInitialize() +{ +} + +static CMPIStatus LMI_UnixDeviceFileCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixDeviceFileEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDeviceFileEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDeviceFileGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_UnixDeviceFile lmi_file; + const char *path; + char tmp[16]; + + LMI_UnixDeviceFile_InitFromObjectPath(&lmi_file, _cb, cop); + path = KChars(lmi_file.Name.value); + fill_basic(UnixDeviceFile, path, S_IFCHR | S_IFBLK, "No such device: %s"); + + sprintf(tmp, "%u", sb.st_rdev); + LMI_UnixDeviceFile_Set_DeviceId(&lmi_file, tmp); + sprintf(tmp, "%u", major(sb.st_rdev)); + LMI_UnixDeviceFile_Set_DeviceMajor(&lmi_file, tmp); + sprintf(tmp, "%u", minor(sb.st_rdev)); + LMI_UnixDeviceFile_Set_DeviceMinor(&lmi_file, tmp); + + KReturnInstance(cr, lmi_file); + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixDeviceFileCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDeviceFileModifyInstance( + 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_UnixDeviceFileDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDeviceFileExecQuery( + 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_UnixDeviceFile, + LMI_UnixDeviceFile, + _cb, + LMI_UnixDeviceFileInitialize()) + +static CMPIStatus LMI_UnixDeviceFileMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixDeviceFileInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_UnixDeviceFile_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_UnixDeviceFile, + LMI_UnixDeviceFile, + _cb, + LMI_UnixDeviceFileInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_UnixDeviceFile", + "LMI_UnixDeviceFile", + "instance method") +/* vi: set et: */ diff --git a/src/logicalfile/LMI_UnixDirectoryProvider.c b/src/logicalfile/LMI_UnixDirectoryProvider.c new file mode 100644 index 0000000..d70aae7 --- /dev/null +++ b/src/logicalfile/LMI_UnixDirectoryProvider.c @@ -0,0 +1,160 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#include "LMI_UnixDirectory.h" +#include "file.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_UnixDirectoryInitialize() +{ +} + +static CMPIStatus LMI_UnixDirectoryCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDirectoryEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDirectoryEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDirectoryGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + get_instance(UnixDirectory, S_IFDIR, "No such directory: %s"); + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixDirectoryCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + LMI_UnixDirectory lmi_ud; + LMI_UnixDirectory_InitFromInstance(&lmi_ud, _cb, ci); + CMPIStatus st; + CMPIObjectPath *iop = CMGetObjectPath(ci, &st); + CMPIData pathd = CMGetKey(iop, "Name", &st); + const char *path = KChars(pathd.value.string); + + if (mkdir(path, 0777) < 0) { + char errmsg[BUFLEN]; + snprintf(errmsg, BUFLEN, "Can't mkdir: %s", path); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixDirectoryModifyInstance( + 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_UnixDirectoryDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixDirectoryExecQuery( + 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_UnixDirectory, + LMI_UnixDirectory, + _cb, + LMI_UnixDirectoryInitialize()) + +static CMPIStatus LMI_UnixDirectoryMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixDirectoryInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_UnixDirectory_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_UnixDirectory, + LMI_UnixDirectory, + _cb, + LMI_UnixDirectoryInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_UnixDirectory", + "LMI_UnixDirectory", + "instance method") +/* vi: set et: */ diff --git a/src/logicalfile/LMI_UnixFileProvider.c b/src/logicalfile/LMI_UnixFileProvider.c new file mode 100644 index 0000000..8f47d33 --- /dev/null +++ b/src/logicalfile/LMI_UnixFileProvider.c @@ -0,0 +1,177 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#include <konkret/konkret.h> +#include "LMI_UnixFile.h" +#include "file.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_UnixFileInitialize() +{ +} + +static CMPIStatus LMI_UnixFileCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixFileEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixFileEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixFileGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_UnixFile lmi_file; + CMPIStatus st; + struct stat sb; + char aux[BUFLEN]; + const char *path; + + st = lmi_check_required(_cb, cop, UNIXFILE); + if (st.rc != CMPI_RC_OK) { + return st; + } + + LMI_UnixFile_InitFromObjectPath(&lmi_file, _cb, cop); + path = KChars(lmi_file.LFName.value); + + if (stat(path, &sb) < 0) { + snprintf(aux, BUFLEN, "Can't stat file: %s", path); + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, aux); + } + sprintf(aux, "%u", sb.st_uid); + LMI_UnixFile_Set_UserID(&lmi_file, aux); + sprintf(aux, "%u", sb.st_gid); + LMI_UnixFile_Set_GroupID(&lmi_file, aux); + LMI_UnixFile_Set_SetUid(&lmi_file, sb.st_mode & S_IFMT & S_ISUID); + LMI_UnixFile_Set_SetGid(&lmi_file, sb.st_mode & S_IFMT & S_ISGID); + sprintf(aux, "%u", (unsigned int)sb.st_ino); + LMI_UnixFile_Set_FileInodeNumber(&lmi_file, aux); + LMI_UnixFile_Set_LinkCount(&lmi_file, sb.st_nlink); + /* sticky bit */ + LMI_UnixFile_Set_SaveText(&lmi_file, sb.st_mode & S_IFMT & S_ISVTX); + + KReturnInstance(cr, lmi_file); + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixFileCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixFileModifyInstance( + 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_UnixFileDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_UnixFileExecQuery( + 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_UnixFile, + LMI_UnixFile, + _cb, + LMI_UnixFileInitialize()) + +static CMPIStatus LMI_UnixFileMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_UnixFileInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_UnixFile_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_UnixFile, + LMI_UnixFile, + _cb, + LMI_UnixFileInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_UnixFile", + "LMI_UnixFile", + "instance method") +/* vi: set et: */ diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c new file mode 100644 index 0000000..a9a13a6 --- /dev/null +++ b/src/logicalfile/file.c @@ -0,0 +1,76 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#include "file.h" + +static const char *LOGICALFILE_REQUIRED_NAMES[] = { + "CSCreationClassName", + "CSName", + "CreationClassName", + "FSCreationClassName", + "FSName", + "Name", + NULL +}; + +static const char *UNIXFILE_REQUIRED_NAMES[] = { + "CSCreationClassName", + "CSName", + "LFCreationClassName", + "FSCreationClassName", + "FSName", + "LFName", + NULL +}; + +CMPIStatus lmi_check_required( + const CMPIBroker *b, + const CMPIObjectPath *o, + const enum RequiredNames rn) +{ + const char **names; + + switch (rn) { + case LOGICALFILE: + names = LOGICALFILE_REQUIRED_NAMES; + break; + case UNIXFILE: + names = UNIXFILE_REQUIRED_NAMES; + break; + default: + /* not possible! */ + assert(0); + break; + } + + for (int i = 0; names[i]; i++) { + if (CMIsNullValue(CMGetKey(o, names[i], NULL))) { + char errmsg[BUFLEN]; + snprintf(errmsg, BUFLEN, "No '%s' specified", names[i]); + CMReturnWithChars(b, CMPI_RC_ERR_FAILED, errmsg); + } + } + CMReturn(CMPI_RC_OK); +} + +void _dump_objectpath(const CMPIObjectPath *o) +{ + printf("OP: %s\n", CMGetCharsPtr(o->ft->toString(o, NULL), NULL)); +} +/* vi: set et: */ diff --git a/src/logicalfile/file.h b/src/logicalfile/file.h new file mode 100644 index 0000000..e59c2ef --- /dev/null +++ b/src/logicalfile/file.h @@ -0,0 +1,107 @@ +/* + * 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 <jsynacek@redhat.com> + */ +#ifndef _FILE_H +#define _FILE_H + +#include <linux/limits.h> +#include <sys/stat.h> +#include <dirent.h> +#include <stdlib.h> +#include <string.h> +#include <limits.h> +#include <libgen.h> +#include <konkret/konkret.h> +#include <assert.h> +#include "globals.h" + +#ifndef BUFLEN + #define BUFLEN 512 +#endif +#ifndef PATH_MAX + #define PATH_MAX 4096 +#endif + +#define FSCREATIONCLASSNAME "FSCCNToBeAgreedOn" +#define FSNAME "FSNToBeAgreedOn" + +#define sb_permmask(sb) ((sb).st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) +#define sb_isreadable(sb) ( \ + (sb_permmask(sb) & S_IRUSR) || \ + (sb_permmask(sb) & S_IRGRP) || \ + (sb_permmask(sb) & S_IROTH) \ +) +#define sb_iswriteable(sb) ( \ + (sb_permmask(sb) & S_IWUSR) || \ + (sb_permmask(sb) & S_IWGRP) || \ + (sb_permmask(sb) & S_IWOTH) \ +) +#define sb_isexecutable(sb) ( \ + (sb_permmask(sb) & S_IXUSR) || \ + (sb_permmask(sb) & S_IXGRP) || \ + (sb_permmask(sb) & S_IXOTH) \ +) +#define stoms(t) ((t)*1000000) + +#define fill_logicalfile(type, obj, name, creation_class) \ + type##_Set_Name((obj), (name)); \ + type##_Set_CSCreationClassName((obj), get_system_creation_class_name()); \ + type##_Set_CSName((obj), get_system_name()); \ + type##_Set_FSCreationClassName((obj), FSCREATIONCLASSNAME); \ + type##_Set_FSName((obj), FSNAME); \ + type##_Set_CreationClassName((obj), (creation_class)); + +#define fill_basic(cmpitype, path, stattype, error) \ + struct stat sb; \ + char errmsg[BUFLEN]; \ + \ + if (lstat((path), &sb) < 0 || !(sb.st_mode & S_IFMT & (stattype))) { \ + snprintf(errmsg, BUFLEN, error, (path)); \ + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); \ + } \ + \ + LMI_##cmpitype##_Set_Readable(&lmi_file, sb_isreadable(sb)); \ + LMI_##cmpitype##_Set_Writeable(&lmi_file, sb_iswriteable(sb)); \ + LMI_##cmpitype##_Set_Executable(&lmi_file, sb_isexecutable(sb)); \ + LMI_##cmpitype##_Set_FileSize(&lmi_file, sb.st_size); \ + LMI_##cmpitype##_Set_LastAccessed(&lmi_file, CMNewDateTimeFromBinary(_cb, stoms(sb.st_atime), 0, NULL)); \ + LMI_##cmpitype##_Set_LastModified(&lmi_file, CMNewDateTimeFromBinary(_cb, stoms(sb.st_mtime), 0, NULL)); + +#define get_instance(cmpitype, stattype, error) \ + LMI_##cmpitype lmi_file; \ + CMPIStatus st; \ + \ + LMI_##cmpitype##_InitFromObjectPath(&lmi_file, _cb, cop); \ + st = lmi_check_required(_cb, cop, LOGICALFILE); \ + if (st.rc != CMPI_RC_OK) { \ + return st; \ + } \ + fill_basic(cmpitype, KChars(lmi_file.Name.value), stattype, error) \ + KReturnInstance(cr, lmi_file); + +enum RequiredNames { + LOGICALFILE, + UNIXFILE, +}; + +CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIObjectPath *, const enum RequiredNames); +void _dump_objectpath(const CMPIObjectPath *); + +#endif /* _FILE_H */ +/* vi: set et: */ |