summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2013-08-26 07:54:15 +0200
committerJan Synacek <jsynacek@redhat.com>2013-08-26 16:00:33 +0200
commitb6026601142253efcdc8d29241c706789d6d6a3a (patch)
tree03e7b06454e6168331170006a7466f4709ba77e2 /src
parent8c6265eb50dfce55684659a5087c7739717f371a (diff)
downloadopenlmi-providers-b6026601142253efcdc8d29241c706789d6d6a3a.tar.gz
openlmi-providers-b6026601142253efcdc8d29241c706789d6d6a3a.tar.xz
openlmi-providers-b6026601142253efcdc8d29241c706789d6d6a3a.zip
logicalfile: correctly apply filters in LMI_DirectoryContainsFile
Diffstat (limited to 'src')
-rw-r--r--src/logicalfile/LMI_DirectoryContainsFileProvider.c88
1 files changed, 78 insertions, 10 deletions
diff --git a/src/logicalfile/LMI_DirectoryContainsFileProvider.c b/src/logicalfile/LMI_DirectoryContainsFileProvider.c
index 46db891..25b9529 100644
--- a/src/logicalfile/LMI_DirectoryContainsFileProvider.c
+++ b/src/logicalfile/LMI_DirectoryContainsFileProvider.c
@@ -34,6 +34,9 @@ const unsigned int MAX_REFS = 4096;
static CMPIStatus dir_file_objectpaths(
const CMPIContext* cc,
const CMPIResult* cr,
+ const char* resultClass,
+ int group,
+ int rgroup,
const char** properties,
const char *namespace,
const char *path,
@@ -48,6 +51,7 @@ static CMPIStatus dir_file_objectpaths(
struct dirent *de;
DIR *dp;
dp = opendir(path);
+
while ((de = readdir(dp))) {
if (!strcmp(de->d_name, ".")) {
continue;
@@ -59,9 +63,21 @@ static CMPIStatus dir_file_objectpaths(
char *fsname;
if (!strcmp(de->d_name, "..")) {
+ /* to get the parent directory, if either role or result role is
+ * set, role must be GroupComponent, or result role must be
+ * PartComponent */
+ if (group == 1 || rgroup == 0) {
+ continue;
+ }
strncpy(rpath, dirname(aux), BUFLEN);
free(aux);
} else {
+ /* to get the content of a directory, if either role or result role
+ * is set, role must be PartComponent, or result role must be
+ * GroupComponent */
+ if (group == 0 || rgroup == 1) {
+ continue;
+ }
snprintf(rpath, BUFLEN, "%s/%s",
(!strcmp(path, "/")) ? "" : path,
de->d_name);
@@ -73,6 +89,7 @@ static CMPIStatus dir_file_objectpaths(
CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, err);
} else {
get_class_from_stat(&sb, fileclass);
+ check_assoc_class(_cb, namespace, resultClass, fileclass);
if (get_fsname_from_stat(&sb, &fsname) < 0) {
CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
}
@@ -128,30 +145,58 @@ static CMPIStatus associators(
CMPIInstance *ci;
CMPIStatus st;
const char *ns = KNameSpace(cop);
+ int group = -1;
+ int rgroup = -1;
st = lmi_check_required(_cb, cop, LOGICALFILE);
if (st.rc != CMPI_RC_OK) {
return st;
}
+ check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName);
/* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */
if (!check_valid_classes(cop)) {
CMReturn(CMPI_RC_OK);
}
+ /* role && resultRole checks */
+ if (role) {
+ if (strcmp(role, GROUP_COMPONENT) && strcmp(role, PART_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ } else if (!strcmp(role, GROUP_COMPONENT)) {
+ group = 1;
+ } else if (!strcmp(role, PART_COMPONENT)) {
+ group = 0;
+ }
+ }
+ if (resultRole) {
+ if (strcmp(resultRole, GROUP_COMPONENT) && strcmp(resultRole, PART_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ } else if (!strcmp(resultRole, GROUP_COMPONENT)) {
+ rgroup = 1;
+ } else if (!strcmp(resultRole, PART_COMPONENT)) {
+ rgroup = 0;
+ }
+ }
+ /* if role and resultRole are the same, there is nothing left to return */
+ if ((group == 1 && rgroup == 1) ||
+ (group == 0 && rgroup == 0)) {
+ CMReturn(CMPI_RC_OK);
+ }
const char *path = get_string_property_from_op(cop, "Name");
CMPIObjectPath *refs[MAX_REFS];
- unsigned int count;
+ unsigned int count = 0;
if (CMClassPathIsA(_cb, cop, LMI_UnixDirectory_ClassName, &st)) {
- /* got UnixDirectory */
- st = dir_file_objectpaths(cc, cr, properties, ns, path, refs, &count);
+ /* got UnixDirectory - GroupComponent */
+ st = dir_file_objectpaths(cc, cr, resultClass, group, rgroup, 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]);
@@ -161,12 +206,18 @@ static CMPIStatus associators(
}
}
} else {
- /* got LogicalFile */
+ /* got LogicalFile - PartComponent */
CIM_DirectoryRef lmi_dr;
CIM_DirectoryRef_Init(&lmi_dr, _cb, ns);
char *aux = strdup(path);
char *dir = dirname(aux);
char *fsname;
+
+ if (group == 1 || rgroup == 0) {
+ CMReturn(CMPI_RC_OK);
+ }
+ check_assoc_class(_cb, ns, resultClass, LMI_UnixDirectory_ClassName);
+
if (get_fsname_from_path(dir, &fsname) < 0) {
CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
}
@@ -206,21 +257,31 @@ static CMPIStatus references(
CIM_LogicalFileRef lmi_lfr;
CMPIObjectPath *o;
CMPIInstance *ci;
+ int group = -1;
+ check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName);
/* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */
if (!check_valid_classes(cop)) {
CMReturn(CMPI_RC_OK);
}
-
- CIM_DirectoryRef_Init(&lmi_dr, _cb, ns);
- CIM_LogicalFileRef_Init(&lmi_lfr, _cb, ns);
- LMI_DirectoryContainsFile_Init(&lmi_dcf, _cb, ns);
-
+ if (role) {
+ if (strcmp(role, GROUP_COMPONENT) && strcmp(role, PART_COMPONENT)) {
+ CMReturn(CMPI_RC_OK);
+ } else if (!strcmp(role, GROUP_COMPONENT)) {
+ group = 1;
+ } else if (!strcmp(role, PART_COMPONENT)) {
+ group = 0;
+ }
+ }
st = lmi_check_required(_cb, cop, LOGICALFILE);
if (st.rc != CMPI_RC_OK) {
return st;
}
+ CIM_DirectoryRef_Init(&lmi_dr, _cb, ns);
+ CIM_LogicalFileRef_Init(&lmi_lfr, _cb, ns);
+ LMI_DirectoryContainsFile_Init(&lmi_dcf, _cb, ns);
+
const char *ccname = get_string_property_from_op(cop, "CreationClassName");
const char *path = get_string_property_from_op(cop, "Name");
char *fsname;
@@ -238,7 +299,7 @@ static CMPIStatus references(
/* PartComponent */
CMPIObjectPath *refs[MAX_REFS];
unsigned int count;
- st = dir_file_objectpaths(cc, cr, properties, ns, path, refs, &count);
+ st = dir_file_objectpaths(cc, cr, NULL, group, -1, properties, ns, path, refs, &count);
if (st.rc != CMPI_RC_OK) {
return st;
}
@@ -257,6 +318,10 @@ static CMPIStatus references(
}
} else {
/* got PartComponent - LogicalFileRef */
+ if (group == 1) {
+ CMReturn(CMPI_RC_OK);
+ }
+
fill_logicalfile(CIM_LogicalFileRef, &lmi_lfr, path, fsname, ccname);
o = CIM_LogicalFileRef_ToObjectPath(&lmi_lfr, &st);
CMSetClassName(o, ccname);
@@ -450,3 +515,6 @@ KONKRET_REGISTRATION(
"LMI_DirectoryContainsFile",
"instance association")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */