summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2013-02-14 15:23:51 +0100
committerJan Synacek <jsynacek@redhat.com>2013-02-14 16:00:03 +0100
commit01a81cf733f25bbe8d988e557672b539e9fc3c1b (patch)
tree2f09d5b4b5178f5137eacdea306acaf6aa0ffb04 /src
parentf9800113caf680157b86a7d7e072fb163985e52f (diff)
downloadopenlmi-providers-01a81cf733f25bbe8d988e557672b539e9fc3c1b.tar.gz
openlmi-providers-01a81cf733f25bbe8d988e557672b539e9fc3c1b.tar.xz
openlmi-providers-01a81cf733f25bbe8d988e557672b539e9fc3c1b.zip
LogicalFile: fix FileIdentity
LMI_FileIdentity.Associators() was not behaving correctly -- it was returning the object itself instead of the other one. Also, LMI_FileIdentity.References() has been updated.
Diffstat (limited to 'src')
-rw-r--r--src/logicalfile/LMI_FileIdentityProvider.c130
-rw-r--r--src/logicalfile/file.c26
-rw-r--r--src/logicalfile/file.h3
3 files changed, 123 insertions, 36 deletions
diff --git a/src/logicalfile/LMI_FileIdentityProvider.c b/src/logicalfile/LMI_FileIdentityProvider.c
index 9e3427c..81371dd 100644
--- a/src/logicalfile/LMI_FileIdentityProvider.c
+++ b/src/logicalfile/LMI_FileIdentityProvider.c
@@ -63,20 +63,73 @@ static CMPIStatus associators(
{
CMPIStatus st, res;
CMPIInstance *ci;
+ CMPIObjectPath *o;
+ const char *ns = KNameSpace(cop);
+ CMPIData pathd;
+ CMPIData cd;
/* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */
if (!check_valid_classes(cop)) {
CMReturn(CMPI_RC_OK);
}
- /* TODO filtering */
+ 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;
+ }
+
+ pathd = CMGetKey(cop, "LFName", &st);
+ cd = CMGetKey(cop, "LFCreationClassName", &st);
+ const char *path = KChars(pathd.value.string);
+ const char *ccname = KChars(cd.value.string);
+ char fileclass[BUFLEN];
+ get_class_from_path(path, fileclass);
+
+ /* 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, 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;
+ }
+
+ pathd = CMGetKey(cop, "Name", &st);
+ cd = CMGetKey(cop, "CreationClassName", &st);
+ const char *path = KChars(pathd.value.string);
+ char fileclass[BUFLEN];
+ get_class_from_path(path, fileclass);
+
+ 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, cop);
+ res = CMReturnObjectPath(cr, o);
} else {
- ci = _cb->bft->getInstance(_cb, cc, cop, properties, &st);
+ ci = _cb->bft->getInstance(_cb, cc, o, properties, &st);
res = CMReturnInstance(cr, ci);
}
-
return res;
}
@@ -91,17 +144,19 @@ static CMPIStatus references(
int names)
{
LMI_FileIdentity lmi_fi;
- /* SameElement */
- LMI_UnixFile lmi_uf;
- /* SystemElement */
- CIM_LogicalFileRef lmi_lfr;
- CMPIStatus st;
+ CMPIStatus st, res;
CMPIData pathd;
- CMPIData cnd;
+ CMPIData cd;
const char *ns = KNameSpace(cop);
CMPIInstance *ci;
-
- /* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */
+ CMPIObjectPath *o;
+
+ /*
+ * 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);
}
@@ -109,7 +164,7 @@ static CMPIStatus references(
LMI_FileIdentity_Init(&lmi_fi, _cb, ns);
if (CMClassPathIsA(_cb, cop, LMI_UnixFile_ClassName, &st)) {
- /* got SameElement - UnixFile */
+ /* got UnixFile */
LMI_FileIdentity_SetObjectPath_SameElement(&lmi_fi, cop);
st = lmi_check_required(_cb, cop, UNIXFILE);
@@ -118,24 +173,27 @@ static CMPIStatus references(
}
pathd = CMGetKey(cop, "LFName", &st);
- cnd = CMGetKey(cop, "LFCreationClassName", &st);
+ cd = CMGetKey(cop, "LFCreationClassName", &st);
const char *path = KChars(pathd.value.string);
- const char *ccname = KChars(cnd.value.string);
+ const char *ccname = KChars(cd.value.string);
+ char fileclass[BUFLEN];
+ get_class_from_path(path, fileclass);
+
+ /* TODO is this error necessary? */
+ if (strcmp(fileclass, ccname)) {
+ CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND,
+ "LMCreationClassName is not correct");
+ }
/* SystemElement */
+ CIM_LogicalFileRef lmi_lfr;
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);
- }
+ o = CIM_LogicalFileRef_ToObjectPath(&lmi_lfr, &st);
+ CMSetClassName(o, fileclass);
+ LMI_FileIdentity_SetObjectPath_SystemElement(&lmi_fi, o);
} else {
- /* got SystemElement - LogicalFile */
+ /* got LogicalFile */
LMI_FileIdentity_SetObjectPath_SystemElement(&lmi_fi, cop);
st = lmi_check_required(_cb, cop, LOGICALFILE);
@@ -144,11 +202,12 @@ static CMPIStatus references(
}
pathd = CMGetKey(cop, "Name", &st);
- cnd = CMGetKey(cop, "CreationClassName", &st);
+ cd = CMGetKey(cop, "CreationClassName", &st);
const char *path = KChars(pathd.value.string);
- const char *ccname = KChars(cnd.value.string);
+ const char *ccname = KChars(cd.value.string);
/* 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());
@@ -156,19 +215,18 @@ static CMPIStatus references(
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);
- }
+ o = LMI_UnixFile_ToObjectPath(&lmi_uf, &st);
+ LMI_FileIdentity_SetObjectPath_SameElement(&lmi_fi, o);
}
if (names) {
- return CMReturnObjectPath(cr, LMI_FileIdentity_ToObjectPath(&lmi_fi, &st));
+ o = LMI_FileIdentity_ToObjectPath(&lmi_fi, &st);
+ res = CMReturnObjectPath(cr, o);
+ } else {
+ ci = LMI_FileIdentity_ToInstance(&lmi_fi, &st);
+ res = CMReturnInstance(cr, ci);
}
- CMReturn(CMPI_RC_OK);
+ return res;
}
static void LMI_FileIdentityInitialize()
diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c
index a9a13a6..6c482f0 100644
--- a/src/logicalfile/file.c
+++ b/src/logicalfile/file.c
@@ -69,6 +69,32 @@ CMPIStatus lmi_check_required(
CMReturn(CMPI_RC_OK);
}
+void get_class_from_stat(const struct stat *sb, char *fileclass) {
+ (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") :
+ (S_ISSOCK(sb->st_mode)) ? strcpy(fileclass, "LMI_UnixSocket") :
+ strcpy(fileclass, "Unknown");
+ assert(strcmp(fileclass, "Unknown") != 0);
+}
+
+int get_class_from_path(const char *path, char *fileclass)
+{
+ int rc = 0;
+ struct stat sb;
+
+ if (lstat(path, &sb) < 0) {
+ rc = 1;
+ } else {
+ get_class_from_stat(&sb, fileclass);
+ }
+
+ return rc;
+}
+
void _dump_objectpath(const CMPIObjectPath *o)
{
printf("OP: %s\n", CMGetCharsPtr(o->ft->toString(o, NULL), NULL));
diff --git a/src/logicalfile/file.h b/src/logicalfile/file.h
index e59c2ef..64a25f3 100644
--- a/src/logicalfile/file.h
+++ b/src/logicalfile/file.h
@@ -101,6 +101,9 @@ enum RequiredNames {
};
CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIObjectPath *, const enum RequiredNames);
+void get_class_from_stat(const struct stat *, char *);
+int get_class_from_path(const char *, char *);
+
void _dump_objectpath(const CMPIObjectPath *);
#endif /* _FILE_H */