diff options
Diffstat (limited to 'src/logicalfile/file.c')
-rw-r--r-- | src/logicalfile/file.c | 141 |
1 files changed, 104 insertions, 37 deletions
diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c index 64b7d52..e3be07f 100644 --- a/src/logicalfile/file.c +++ b/src/logicalfile/file.c @@ -19,52 +19,112 @@ */ #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: + const char *prop; + const char *errmsg = NULL; + char *path = NULL; + + /* check computer system creation class name */ + if (CMIsNullValue(CMGetKey(o, "CSCreationClassName", NULL))) { + errmsg = "CSCreationClassName is empty"; + goto done; + } + prop = get_string_property_from_op(o, "CSCreationClassName"); + if (strcmp(prop, lmi_get_system_creation_class_name())) { + errmsg = "Wrong CSCreationClassName"; + goto done; + } + + /* check fqdn */ + if (CMIsNullValue(CMGetKey(o, "CSName", NULL))) { + errmsg = "CSName is empty"; + goto done; + } + prop = get_string_property_from_op(o, "CSName"); + if (strcmp(prop, lmi_get_system_name())) { + errmsg = "Wrong CSName"; + goto done; + } + + if (rn == UNIXFILE) { + /* check creation class name */ + char fileclass[BUFLEN]; + if (CMIsNullValue(CMGetKey(o, "LFCreationClassName", NULL))) { + errmsg = "LFCreationClassName is empty"; + goto done; + } + prop = get_string_property_from_op(o, "LFCreationClassName"); + if (get_class_from_path(get_string_property_from_op(o, "LFName"), fileclass) != 0) { + errmsg = "Can't get class from path"; + goto done; + } + if (strcmp(prop, fileclass)) { + errmsg = "LFCreationClassName doesn't match the file's type"; + goto done; + } + if (CMIsNullValue(CMGetKey(o, "LFName", NULL))) { + errmsg = "LFName is empty"; + goto done; + } + if (get_fsname_from_path(get_string_property_from_op(o, "LFName"), &path) < 0) { + errmsg = "Can't get FSName from path"; + goto done; + } + } else if (rn == LOGICALFILE) { + /* check creation class name */ + if (CMIsNullValue(CMGetKey(o, "CreationClassName", NULL))) { + errmsg = "CreationClassName is empty"; + goto done; + } + prop = get_string_property_from_op(o, "CreationClassName"); + if (!CMClassPathIsA(b, o, prop, NULL)) { + errmsg = "CreationClassName and the class name don't match"; + goto done; + } + if (CMIsNullValue(CMGetKey(o, "Name", NULL))) { + errmsg = "Name is empty"; + goto done; + } + if (get_fsname_from_path(get_string_property_from_op(o, "Name"), &path) < 0) { + errmsg = "Can't get FSName from path"; + goto done; + } + } else { /* 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); - } + /* check fs creation class name and fsname */ + if (CMIsNullValue(CMGetKey(o, "FSCreationClassName", NULL))) { + errmsg = "FSCreationClassName is empty"; + goto done; + } + prop = get_string_property_from_op(o, "FSCreationClassName"); + if (strcmp(prop, FSCREATIONCLASSNAME)) { + errmsg = "Wrong FSCreationClassName"; + goto done; + } + + if (CMIsNullValue(CMGetKey(o, "FSName", NULL))) { + errmsg = "FSName is empty"; + goto done; + } + prop = get_string_property_from_op(o, "FSName"); + if (strcmp(prop, path)) { + errmsg = "Wrong FSName"; + goto done; + } + +done: + if (path) { + free(path); + } + if (errmsg) { + CMReturnWithChars(b, CMPI_RC_ERR_FAILED, errmsg); } CMReturn(CMPI_RC_OK); } @@ -137,6 +197,13 @@ int get_fsname_from_path(const char *path, char **fsname) return rc; } +const char *get_string_property_from_op(const CMPIObjectPath *o, const char *prop) +{ + CMPIData d; + d = CMGetKey(o, prop, NULL); + return KChars(d.value.string); +} + void _dump_objectpath(const CMPIObjectPath *o) { printf("OP: %s\n", CMGetCharsPtr(o->ft->toString(o, NULL), NULL)); |