summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2013-08-22 13:59:35 +0200
committerJan Synacek <jsynacek@redhat.com>2013-08-26 16:00:33 +0200
commit48b32898c5a8a46cef619cec52d3d15ee7105c97 (patch)
tree6de462edcc1e800de2d056a5a1ccb0c5b1453c25
parent715ab2548dd9daed4bca971eaec1b00b0306ebdb (diff)
downloadopenlmi-providers-48b32898c5a8a46cef619cec52d3d15ee7105c97.tar.gz
openlmi-providers-48b32898c5a8a46cef619cec52d3d15ee7105c97.tar.xz
openlmi-providers-48b32898c5a8a46cef619cec52d3d15ee7105c97.zip
logicalfile: correctly apply filters in LMI_RootDirectory
-rw-r--r--src/logicalfile/LMI_RootDirectoryProvider.c52
-rw-r--r--src/logicalfile/file.c3
-rw-r--r--src/logicalfile/file.h108
3 files changed, 107 insertions, 56 deletions
diff --git a/src/logicalfile/LMI_RootDirectoryProvider.c b/src/logicalfile/LMI_RootDirectoryProvider.c
index 600f7a5..7f0c4d6 100644
--- a/src/logicalfile/LMI_RootDirectoryProvider.c
+++ b/src/logicalfile/LMI_RootDirectoryProvider.c
@@ -58,13 +58,10 @@ static CMPIStatus associators(
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");
- }
+ check_assoc_class(_cb, ns, assocClass, LMI_RootDirectory_ClassName);
/*
* allow only LMI_UnixDirectory and Linux_ComputerSystem
* XXX
@@ -73,8 +70,19 @@ static CMPIStatus associators(
CMReturn(CMPI_RC_OK);
}
+ if (get_fsname_from_path("/", &fsname) < 0) {
+ CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
+ }
+
if (CMClassPathIsA(_cb, cop, LMI_UnixDirectory_ClassName, &st)) {
- /* got LMI_UnixDirectory */
+ /* got LMI_UnixDirectory - PartComponent */
+ check_assoc_class(_cb, ns, resultClass, comp_ccname);
+ if (role && strcmp(role, PART_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ }
+ if (resultRole && strcmp(resultRole, GROUP_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ }
/* ignore this association if the directory is not root */
if (strcmp(path, "/")) {
CMReturn(CMPI_RC_OK);
@@ -93,7 +101,15 @@ static CMPIStatus associators(
CMReturnInstance(cr, ci);
}
} else {
- /* got Linux_ComputerSystem */
+ /* got Linux_ComputerSystem - GroupComponent */
+ check_assoc_class(_cb, ns, resultClass, LMI_UnixDirectory_ClassName);
+ if (role && strcmp(role, GROUP_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ }
+ if (resultRole && strcmp(resultRole, PART_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ }
+
LMI_UnixDirectory lmi_ud;
LMI_UnixDirectory_Init(&lmi_ud, _cb, ns);
fill_logicalfile(LMI_UnixDirectory, &lmi_ud, "/", fsname, LMI_UnixDirectory_ClassName);
@@ -125,14 +141,10 @@ static CMPIStatus references(
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");
- }
+ check_assoc_class(_cb, ns, assocClass, LMI_RootDirectory_ClassName);
/*
* allow only LMI_UnixDirectory and Linux_ComputerSystem
* XXX
@@ -141,10 +153,18 @@ static CMPIStatus references(
CMReturn(CMPI_RC_OK);
}
+ char *fsname;
+ if (get_fsname_from_path("/", &fsname) < 0) {
+ CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
+ }
+
LMI_RootDirectory_Init(&lmi_rd, _cb, ns);
if (!strcmp(ccname, LMI_UnixDirectory_ClassName)) {
- /* got UnixDirectory */
+ /* got UnixDirectory - PartComponent */
+ if (role && strcmp(role, PART_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ }
/* ignore this association if the directory is not root */
if (strcmp(path, "/")) {
CMReturn(CMPI_RC_OK);
@@ -163,7 +183,10 @@ static CMPIStatus references(
CMSetClassName(o, comp_ccname);
LMI_RootDirectory_SetObjectPath_GroupComponent(&lmi_rd, o);
} else {
- /* got Linux_ComputerSystem */
+ /* got Linux_ComputerSystem - GroupComponent */
+ if (role && strcmp(role, GROUP_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ }
LMI_RootDirectory_SetObjectPath_GroupComponent(&lmi_rd, cop);
LMI_UnixDirectory lmi_ud;
@@ -345,3 +368,6 @@ KONKRET_REGISTRATION(
"LMI_RootDirectory",
"instance association")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c
index e3be07f..74be931 100644
--- a/src/logicalfile/file.c
+++ b/src/logicalfile/file.c
@@ -209,3 +209,6 @@ void _dump_objectpath(const CMPIObjectPath *o)
printf("OP: %s\n", CMGetCharsPtr(o->ft->toString(o, NULL), NULL));
}
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/file.h b/src/logicalfile/file.h
index b7f8c50..3db8386 100644
--- a/src/logicalfile/file.h
+++ b/src/logicalfile/file.h
@@ -40,61 +40,80 @@
#endif
#define FSCREATIONCLASSNAME "LMI_LocalFileSystem"
+#define GROUP_COMPONENT "GroupComponent"
+#define PART_COMPONENT "PartComponent"
#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_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_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 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, fsname, 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_logicalfile(type, obj, name, fsname, 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)); \
+#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) \
+#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);
+#define check_assoc_class(b, ns, assoc_class, cls) \
+{ \
+ CMPIObjectPath *o; \
+ CMPIStatus st; \
+ \
+ o = CMNewObjectPath(b, ns, cls, &st); \
+ if (!o || st.rc) { \
+ CMRelease(o); \
+ return st; \
+ } \
+ if (assoc_class && !CMClassPathIsA(b, o, assoc_class, &st)) { \
+ CMRelease(o); \
+ CMReturn(CMPI_RC_OK); \
+ } \
+ CMRelease(o); \
+}
+
enum RequiredNames {
LOGICALFILE,
UNIXFILE,
@@ -111,3 +130,6 @@ void _dump_objectpath(const CMPIObjectPath *);
#endif /* _FILE_H */
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */