summaryrefslogtreecommitdiffstats
path: root/src/logicalfile
diff options
context:
space:
mode:
Diffstat (limited to 'src/logicalfile')
-rw-r--r--src/logicalfile/LMI_DataFileProvider.c17
-rw-r--r--src/logicalfile/LMI_DirectoryContainsFileProvider.c57
-rw-r--r--src/logicalfile/LMI_FIFOPipeFileProvider.c17
-rw-r--r--src/logicalfile/LMI_FileIdentityProvider.c32
-rw-r--r--src/logicalfile/LMI_RootDirectoryProvider.c26
-rw-r--r--src/logicalfile/LMI_SymbolicLinkProvider.c23
-rw-r--r--src/logicalfile/LMI_UnixDeviceFileProvider.c32
-rw-r--r--src/logicalfile/LMI_UnixDirectoryProvider.c17
-rw-r--r--src/logicalfile/LMI_UnixFileProvider.c7
-rw-r--r--src/logicalfile/LMI_UnixSocketProvider.c17
-rw-r--r--src/logicalfile/file.c131
-rw-r--r--src/logicalfile/file.h95
12 files changed, 310 insertions, 161 deletions
diff --git a/src/logicalfile/LMI_DataFileProvider.c b/src/logicalfile/LMI_DataFileProvider.c
index ea410c3..4053fcd 100644
--- a/src/logicalfile/LMI_DataFileProvider.c
+++ b/src/logicalfile/LMI_DataFileProvider.c
@@ -61,8 +61,18 @@ static CMPIStatus LMI_DataFileGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- get_instance(DataFile, S_IFREG, "Not a regular file: %s");
- CMReturn(CMPI_RC_OK);
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+ logicalfile_t logicalfile;
+
+ st = lmi_check_required(_cb, cop);
+ check_status(st);
+
+ LMI_DataFile_InitFromObjectPath(&logicalfile.lf.datafile, _cb, cop);
+ st = stat_logicalfile_and_fill(_cb, &logicalfile, S_IFREG, "Not a regular file: %s");
+ check_status(st);
+
+ KReturnInstance(cr, logicalfile.lf.datafile);
+ return st;
}
static CMPIStatus LMI_DataFileCreateInstance(
@@ -145,3 +155,6 @@ KONKRET_REGISTRATION(
"LMI_DataFile",
"instance method")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/LMI_DirectoryContainsFileProvider.c b/src/logicalfile/LMI_DirectoryContainsFileProvider.c
index 427c2a6..06bc7b9 100644
--- a/src/logicalfile/LMI_DirectoryContainsFileProvider.c
+++ b/src/logicalfile/LMI_DirectoryContainsFileProvider.c
@@ -90,10 +90,16 @@ 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) {
+ st = check_assoc_class(_cb, namespace, resultClass, fileclass);
+ check_class_check_status(st);
+ if (st.rc != CMPI_RC_OK) {
closedir(dp);
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
+ return st;
+ }
+ st = get_fsname_from_stat(_cb, &sb, &fsname);
+ if (st.rc != CMPI_RC_OK) {
+ closedir(dp);
+ return st;
}
}
@@ -155,7 +161,8 @@ static CMPIStatus associators(
if (st.rc != CMPI_RC_OK) {
return st;
}
- check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName);
+ st = check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName);
+ check_class_check_status(st);
/* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */
if (!check_valid_classes(cop)) {
CMReturn(CMPI_RC_OK);
@@ -200,6 +207,8 @@ static CMPIStatus associators(
CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "Too many files in a single directory...");
}
+ /* TODO: directories are walked in two passes
+ * rewrite using only one pass */
for (unsigned int i = 0; i < count; i++) {
if (names) {
CMReturnObjectPath(cr, refs[i]);
@@ -210,21 +219,24 @@ static CMPIStatus associators(
}
} else {
/* got LogicalFile - PartComponent */
+ if (group == 1 || rgroup == 0) {
+ CMReturn(CMPI_RC_OK);
+ }
+ st = check_assoc_class(_cb, ns, resultClass, LMI_UnixDirectory_ClassName);
+ check_class_check_status(st);
+
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) {
+ st = get_fsname_from_path(_cb, path, &fsname);
+ if (st.rc != CMPI_RC_OK) {
free(aux);
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
+ return st;
}
+
fill_logicalfile(CIM_DirectoryRef, &lmi_dr, dir, fsname, LMI_UnixDirectory_ClassName);
o = CIM_DirectoryRef_ToObjectPath(&lmi_dr, &st);
CMSetClassName(o, LMI_UnixDirectory_ClassName);
@@ -263,7 +275,8 @@ static CMPIStatus references(
CMPIInstance *ci;
int group = -1;
- check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName);
+ st = check_assoc_class(_cb, ns, assocClass, LMI_DirectoryContainsFile_ClassName);
+ check_class_check_status(st);
/* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */
if (!check_valid_classes(cop)) {
CMReturn(CMPI_RC_OK);
@@ -278,9 +291,7 @@ static CMPIStatus references(
}
}
st = lmi_check_required(_cb, cop);
- if (st.rc != CMPI_RC_OK) {
- return st;
- }
+ check_status(st);
CIM_DirectoryRef_Init(&lmi_dr, _cb, ns);
CIM_LogicalFileRef_Init(&lmi_lfr, _cb, ns);
@@ -289,9 +300,8 @@ static CMPIStatus references(
const char *ccname = get_string_property_from_op(cop, "CreationClassName");
const char *path = get_string_property_from_op(cop, "Name");
char *fsname;
- if (get_fsname_from_path(path, &fsname) < 0) {
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
- }
+ st = get_fsname_from_path(_cb, path, &fsname);
+ check_status(st);
if (strcmp(ccname, LMI_UnixDirectory_ClassName) == 0) {
/* got GroupComponent - DirectoryRef */
@@ -304,12 +314,12 @@ static CMPIStatus references(
CMPIObjectPath *refs[MAX_REFS];
unsigned int count;
st = dir_file_objectpaths(cc, cr, NULL, group, -1, properties, ns, path, refs, &count);
- if (st.rc != CMPI_RC_OK) {
- return st;
- }
+ check_status(st);
if (count > MAX_REFS) {
CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, "Too many files in a single directory...");
}
+ /* TODO: directories are walked in two passes
+ * rewrite using only one pass */
for (unsigned int i = 0; i < count; i++) {
LMI_DirectoryContainsFile_SetObjectPath_PartComponent(&lmi_dcf, refs[i]);
o = LMI_DirectoryContainsFile_ToObjectPath(&lmi_dcf, &st);
@@ -335,9 +345,10 @@ static CMPIStatus references(
char *aux = strdup(path);
char *dir = dirname(aux);
char *fsname;
- if (get_fsname_from_path(dir, &fsname) < 0) {
+ st = get_fsname_from_path(_cb, dir, &fsname);
+ if (st.rc != CMPI_RC_OK) {
free(aux);
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
+ return st;
}
fill_logicalfile(CIM_DirectoryRef, &lmi_dr, dir, fsname, LMI_UnixDirectory_ClassName);
diff --git a/src/logicalfile/LMI_FIFOPipeFileProvider.c b/src/logicalfile/LMI_FIFOPipeFileProvider.c
index 8730299..6179f16 100644
--- a/src/logicalfile/LMI_FIFOPipeFileProvider.c
+++ b/src/logicalfile/LMI_FIFOPipeFileProvider.c
@@ -61,7 +61,19 @@ static CMPIStatus LMI_FIFOPipeFileGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- get_instance(FIFOPipeFile, S_IFIFO, "No such FIFO: %s");
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+ logicalfile_t logicalfile;
+
+ st = lmi_check_required(_cb, cop);
+ check_status(st);
+
+ LMI_FIFOPipeFile_InitFromObjectPath(&logicalfile.lf.fifopipefile, _cb, cop);
+ st = stat_logicalfile_and_fill(_cb, &logicalfile, S_IFIFO, "No such FIFO: %s");
+ check_status(st);
+
+ KReturnInstance(cr, logicalfile.lf.fifopipefile);
+ return st;
+
CMReturn(CMPI_RC_OK);
}
@@ -145,3 +157,6 @@ KONKRET_REGISTRATION(
"LMI_FIFOPipeFile",
"instance method")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/LMI_FileIdentityProvider.c b/src/logicalfile/LMI_FileIdentityProvider.c
index 7720a75..adb841b 100644
--- a/src/logicalfile/LMI_FileIdentityProvider.c
+++ b/src/logicalfile/LMI_FileIdentityProvider.c
@@ -68,7 +68,8 @@ static CMPIStatus associators(
char fileclass[BUFLEN];
char *fsname;
- check_assoc_class(_cb, ns, assocClass, LMI_FileIdentity_ClassName);
+ st = check_assoc_class(_cb, ns, assocClass, LMI_FileIdentity_ClassName);
+ check_class_check_status(st);
/* allow only LMI_UnixFile and classes derived from CIM_LogicalFile */
if (!check_valid_classes(cop)) {
CMReturn(CMPI_RC_OK);
@@ -84,7 +85,8 @@ static CMPIStatus associators(
const char *path = get_string_property_from_op(cop, "LFName");
const char *ccname = get_string_property_from_op(cop, "LFCreationClassName");
- check_assoc_class(_cb, ns, resultClass, ccname);
+ st = check_assoc_class(_cb, ns, resultClass, ccname);
+ check_class_check_status(st);
if (role && strcmp(role, SAME_ELEMENT) != 0) {
CMReturn(CMPI_RC_OK);
}
@@ -93,9 +95,8 @@ static CMPIStatus associators(
}
get_class_from_path(path, fileclass);
- if (get_fsname_from_path(path, &fsname) < 0) {
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
- }
+ st = get_fsname_from_path(_cb, path, &fsname);
+ check_status(st);
CIM_LogicalFileRef cim_lfr;
CIM_LogicalFileRef_Init(&cim_lfr, _cb, ns);
@@ -111,7 +112,8 @@ static CMPIStatus associators(
const char *path = get_string_property_from_op(cop, "Name");
- check_assoc_class(_cb, ns, resultClass, LMI_UnixFile_ClassName);
+ st = check_assoc_class(_cb, ns, resultClass, LMI_UnixFile_ClassName);
+ check_class_check_status(st);
if (role && strcmp(role, SYSTEM_ELEMENT) != 0) {
CMReturn(CMPI_RC_OK);
}
@@ -120,9 +122,8 @@ static CMPIStatus associators(
}
get_class_from_path(path, fileclass);
- if (get_fsname_from_path(path, &fsname) < 0) {
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
- }
+ st = get_fsname_from_path(_cb, path, &fsname);
+ check_status(st);
LMI_UnixFile lmi_uf;
LMI_UnixFile_Init(&lmi_uf, _cb, ns);
@@ -163,7 +164,8 @@ static CMPIStatus references(
char fileclass[BUFLEN];
char *fsname;
- check_assoc_class(_cb, ns, assocClass, LMI_FileIdentity_ClassName);
+ st = check_assoc_class(_cb, ns, assocClass, LMI_FileIdentity_ClassName);
+ check_class_check_status(st);
/*
* allow only LMI_UnixFile and classes derived from CIM_LogicalFile
*
@@ -193,9 +195,8 @@ static CMPIStatus references(
}
get_class_from_path(path, fileclass);
- if (get_fsname_from_path(path, &fsname) < 0) {
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
- }
+ st = get_fsname_from_path(_cb, path, &fsname);
+ check_status(st);
/* TODO is this error necessary? */
if (strcmp(fileclass, ccname) != 0) {
@@ -225,9 +226,8 @@ static CMPIStatus references(
if (role && strcmp(role, SYSTEM_ELEMENT) != 0) {
CMReturn(CMPI_RC_OK);
}
- if (get_fsname_from_path(path, &fsname) < 0) {
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
- }
+ st = get_fsname_from_path(_cb, path, &fsname);
+ check_status(st);
/* SameElement */
LMI_UnixFile lmi_uf;
diff --git a/src/logicalfile/LMI_RootDirectoryProvider.c b/src/logicalfile/LMI_RootDirectoryProvider.c
index 0c3b23e..4bb1a31 100644
--- a/src/logicalfile/LMI_RootDirectoryProvider.c
+++ b/src/logicalfile/LMI_RootDirectoryProvider.c
@@ -61,7 +61,8 @@ static CMPIStatus associators(
const char *path = get_string_property_from_op(cop, "Name");
char *fsname;
- check_assoc_class(_cb, ns, assocClass, LMI_RootDirectory_ClassName);
+ st = check_assoc_class(_cb, ns, assocClass, LMI_RootDirectory_ClassName);
+ check_class_check_status(st);
/*
* allow only LMI_UnixDirectory and Linux_ComputerSystem
* XXX
@@ -70,13 +71,13 @@ 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");
- }
+ st = get_fsname_from_path(_cb, "/", &fsname);
+ check_status(st);
if (CMClassPathIsA(_cb, cop, LMI_UnixDirectory_ClassName, &st)) {
/* got LMI_UnixDirectory - PartComponent */
- check_assoc_class(_cb, ns, resultClass, comp_ccname);
+ st = check_assoc_class(_cb, ns, resultClass, comp_ccname);
+ check_class_check_status(st);
if (role && strcmp(role, PART_COMPONENT) != 0) {
CMReturn(CMPI_RC_OK);
}
@@ -102,7 +103,8 @@ static CMPIStatus associators(
}
} else {
/* got Linux_ComputerSystem - GroupComponent */
- check_assoc_class(_cb, ns, resultClass, LMI_UnixDirectory_ClassName);
+ st = check_assoc_class(_cb, ns, resultClass, LMI_UnixDirectory_ClassName);
+ check_class_check_status(st);
if (role && strcmp(role, GROUP_COMPONENT) != 0) {
CMReturn(CMPI_RC_OK);
}
@@ -144,7 +146,8 @@ static CMPIStatus references(
const char *path = get_string_property_from_op(cop, "Name");
const char *ccname = get_string_property_from_op(cop, "CreationClassName");
- check_assoc_class(_cb, ns, assocClass, LMI_RootDirectory_ClassName);
+ st = check_assoc_class(_cb, ns, assocClass, LMI_RootDirectory_ClassName);
+ check_class_check_status(st);
/*
* allow only LMI_UnixDirectory and Linux_ComputerSystem
* XXX
@@ -154,9 +157,8 @@ static CMPIStatus references(
}
char *fsname;
- if (get_fsname_from_path("/", &fsname) < 0) {
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name");
- }
+ st = get_fsname_from_path(_cb, "/", &fsname);
+ check_status(st);
LMI_RootDirectory_Init(&lmi_rd, _cb, ns);
@@ -170,9 +172,7 @@ static CMPIStatus references(
CMReturn(CMPI_RC_OK);
}
st = lmi_check_required(_cb, cop);
- if (st.rc != CMPI_RC_OK) {
- return st;
- }
+ check_status(st);
LMI_RootDirectory_SetObjectPath_PartComponent(&lmi_rd, cop);
CIM_ComputerSystemRef cim_csr;
diff --git a/src/logicalfile/LMI_SymbolicLinkProvider.c b/src/logicalfile/LMI_SymbolicLinkProvider.c
index c93c087..cff8851 100644
--- a/src/logicalfile/LMI_SymbolicLinkProvider.c
+++ b/src/logicalfile/LMI_SymbolicLinkProvider.c
@@ -61,18 +61,18 @@ static CMPIStatus LMI_SymbolicLinkGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- LMI_SymbolicLink lmi_file;
- const char *path;
- char rpath[PATH_MAX];
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+ logicalfile_t logicalfile;
- 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);
+ st = lmi_check_required(_cb, cop);
+ check_status(st);
- KReturnInstance(cr, lmi_file);
- CMReturn(CMPI_RC_OK);
+ LMI_SymbolicLink_InitFromObjectPath(&logicalfile.lf.symboliclink, _cb, cop);
+ st = stat_logicalfile_and_fill(_cb, &logicalfile, S_IFLNK, "No such symlink: %s");
+ check_status(st);
+
+ KReturnInstance(cr, logicalfile.lf.symboliclink);
+ return st;
}
static CMPIStatus LMI_SymbolicLinkCreateInstance(
@@ -155,3 +155,6 @@ KONKRET_REGISTRATION(
"LMI_SymbolicLink",
"instance method")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/LMI_UnixDeviceFileProvider.c b/src/logicalfile/LMI_UnixDeviceFileProvider.c
index 4d09efa..6a707f8 100644
--- a/src/logicalfile/LMI_UnixDeviceFileProvider.c
+++ b/src/logicalfile/LMI_UnixDeviceFileProvider.c
@@ -61,23 +61,18 @@ static CMPIStatus LMI_UnixDeviceFileGetInstance(
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, "%lu", 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);
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+ logicalfile_t logicalfile;
+
+ st = lmi_check_required(_cb, cop);
+ check_status(st);
+
+ LMI_UnixDeviceFile_InitFromObjectPath(&logicalfile.lf.unixdevicefile, _cb, cop);
+ st = stat_logicalfile_and_fill(_cb, &logicalfile, S_IFCHR | S_IFBLK, "No such device: %s");
+ check_status(st);
+
+ KReturnInstance(cr, logicalfile.lf.unixdevicefile);
+ return st;
}
static CMPIStatus LMI_UnixDeviceFileCreateInstance(
@@ -160,3 +155,6 @@ KONKRET_REGISTRATION(
"LMI_UnixDeviceFile",
"instance method")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/LMI_UnixDirectoryProvider.c b/src/logicalfile/LMI_UnixDirectoryProvider.c
index bdd1245..df51fb5 100644
--- a/src/logicalfile/LMI_UnixDirectoryProvider.c
+++ b/src/logicalfile/LMI_UnixDirectoryProvider.c
@@ -63,8 +63,18 @@ static CMPIStatus LMI_UnixDirectoryGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- get_instance(UnixDirectory, S_IFDIR, "No such directory: %s");
- CMReturn(CMPI_RC_OK);
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+ logicalfile_t logicalfile;
+
+ st = lmi_check_required(_cb, cop);
+ check_status(st);
+
+ LMI_UnixDirectory_InitFromObjectPath(&logicalfile.lf.unixdirectory, _cb, cop);
+ st = stat_logicalfile_and_fill(_cb, &logicalfile, S_IFDIR, "Not a directory: %s");
+ check_status(st);
+
+ KReturnInstance(cr, logicalfile.lf.unixdirectory);
+ return st;
}
static CMPIStatus LMI_UnixDirectoryCreateInstance(
@@ -167,3 +177,6 @@ KONKRET_REGISTRATION(
"LMI_UnixDirectory",
"instance method")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/LMI_UnixFileProvider.c b/src/logicalfile/LMI_UnixFileProvider.c
index 6b3a45e..9c9be79 100644
--- a/src/logicalfile/LMI_UnixFileProvider.c
+++ b/src/logicalfile/LMI_UnixFileProvider.c
@@ -32,6 +32,8 @@ static const CMPIBroker* _cb = NULL;
static pthread_mutex_t selinux_mutex;
static struct selabel_handle *_selabel_hnd = NULL;
+/* XXX: selabel_close() and freecon() do no work as expected
+ * see bug #1008924 */
static struct selabel_handle *get_selabel_handle()
{
static struct timeval timestamp = {.tv_sec = 0, .tv_usec = 0};
@@ -117,6 +119,7 @@ static CMPIStatus LMI_UnixFileGetInstance(
struct stat sb;
char aux[BUFLEN];
const char *path;
+ char *fsname;
st = lmi_check_required(_cb, cop);
if (st.rc != CMPI_RC_OK) {
@@ -132,8 +135,8 @@ static CMPIStatus LMI_UnixFileGetInstance(
}
/* set ignored stuff */
LMI_UnixFile_Set_FSCreationClassName(&lmi_file, FSCREATIONCLASSNAME);
- char *fsname;
- get_fsname_from_stat(&sb, &fsname);
+ st = get_fsname_from_stat(_cb, &sb, &fsname);
+ check_status(st);
LMI_UnixFile_Set_FSName(&lmi_file, fsname);
free(fsname);
get_class_from_stat(&sb, aux);
diff --git a/src/logicalfile/LMI_UnixSocketProvider.c b/src/logicalfile/LMI_UnixSocketProvider.c
index 56fb6bd..ca12d53 100644
--- a/src/logicalfile/LMI_UnixSocketProvider.c
+++ b/src/logicalfile/LMI_UnixSocketProvider.c
@@ -61,8 +61,18 @@ static CMPIStatus LMI_UnixSocketGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- get_instance(UnixSocket, S_IFSOCK, "No such socket: %s");
- CMReturn(CMPI_RC_OK);
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+ logicalfile_t logicalfile;
+
+ st = lmi_check_required(_cb, cop);
+ check_status(st);
+
+ LMI_UnixSocket_InitFromObjectPath(&logicalfile.lf.unixsocket, _cb, cop);
+ st = stat_logicalfile_and_fill(_cb, &logicalfile, S_IFSOCK, "No such socket: %s");
+ check_status(st);
+
+ KReturnInstance(cr, logicalfile.lf.unixsocket);
+ return st;
}
static CMPIStatus LMI_UnixSocketCreateInstance(
@@ -145,3 +155,6 @@ KONKRET_REGISTRATION(
"LMI_UnixSocket",
"instance method")
/* vi: set et: */
+/* Local Variables: */
+/* indent-tabs-mode: nil */
+/* End: */
diff --git a/src/logicalfile/file.c b/src/logicalfile/file.c
index e768ea0..7a3cfac 100644
--- a/src/logicalfile/file.c
+++ b/src/logicalfile/file.c
@@ -24,7 +24,6 @@ CMPIStatus lmi_check_required(
const CMPIObjectPath *o)
{
const char *prop;
- const char *errmsg = NULL;
/* check computer system creation class name */
if (CMIsNullValue(CMGetKey(o, "CSCreationClassName", NULL))) {
@@ -73,20 +72,16 @@ int get_class_from_path(const char *path, char *fileclass)
return rc;
}
-int get_fsname_from_stat(const struct stat *sb, char **fname)
+CMPIStatus get_fsname_from_stat(const CMPIBroker *b, const struct stat *sb, char **fname)
{
- static struct udev *udev_ctx = NULL;
+ struct udev *udev_ctx;
struct udev_device *udev_dev;
const char *dev_name;
- int rc = 0;
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+ udev_ctx = udev_new();
if (!udev_ctx) {
- udev_ctx = udev_new();
- if (!udev_ctx) {
- lmi_warn("Could not create udev context");
- rc = -1;
- goto err;
- }
+ return_with_status(b, &st, ERR_FAILED, "Could not create udev context");
}
char dev_id[16];
@@ -94,26 +89,34 @@ int get_fsname_from_stat(const struct stat *sb, char **fname)
udev_dev = udev_device_new_from_device_id(udev_ctx, dev_id);
if ((dev_name = udev_device_get_property_value(udev_dev, "ID_FS_UUID_ENC"))) {
- rc = asprintf(fname, "UUID=%s", dev_name);
+ if (asprintf(fname, "UUID=%s", dev_name) < 0) {
+ return_with_status(b, &st, ERR_FAILED, "asprintf failed");
+ }
} else if ((dev_name = udev_device_get_property_value(udev_dev, "DEVNAME"))) {
- rc = asprintf(fname, "DEVICE=%s", dev_name);
+ if (asprintf(fname, "DEVICE=%s", dev_name) < 0) {
+ return_with_status(b, &st, ERR_FAILED, "asprintf failed");
+ }
} else {
- rc = asprintf(fname, "Unknown");
+ if (asprintf(fname, "Unknown") < 0) {
+ return_with_status(b, &st, ERR_FAILED, "asprintf failed");
+ }
}
-err:
- return rc;
+ udev_device_unref(udev_dev);
+ udev_unref(udev_ctx);
+
+ return st;
}
-int get_fsname_from_path(const char *path, char **fsname)
+CMPIStatus get_fsname_from_path(const CMPIBroker *b, const char *path, char **fsname)
{
+ CMPIStatus st = {.rc = CMPI_RC_OK};
struct stat sb;
- int rc;
- rc = lstat(path, &sb);
- if (rc == 0) {
- rc = get_fsname_from_stat(&sb, fsname);
+ if (lstat(path, &sb) < 0) {
+ return_with_status(b, &st, ERR_FAILED, "lstat(2) failed");
}
- return rc;
+
+ return get_fsname_from_stat(b, &sb, fsname);
}
const char *get_string_property_from_op(const CMPIObjectPath *o, const char *prop)
@@ -123,6 +126,92 @@ const char *get_string_property_from_op(const CMPIObjectPath *o, const char *pro
return KChars(d.value.string);
}
+CMPIStatus check_assoc_class(
+ const CMPIBroker *cb,
+ const char *namespace,
+ const char *assocClass,
+ const char *class)
+{
+ CMPIObjectPath *o;
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+
+ o = CMNewObjectPath(cb, namespace, class, &st);
+ if (!o || st.rc) {
+ CMRelease(o);
+ return st;
+ }
+ if (assocClass && !CMClassPathIsA(cb, o, assocClass, &st)) {
+ CMRelease(o);
+ st.rc = RC_ERR_CLASS_CHECK_FAILED;
+ return st;
+ }
+ CMRelease(o);
+ return st;
+}
+
+CMPIStatus stat_logicalfile_and_fill(
+ const CMPIBroker *b,
+ logicalfile_t *lf,
+ mode_t mode,
+ const char *errmsg)
+{
+ struct stat sb;
+ char buf[BUFLEN];
+ char *fsname = NULL;
+ const char *path = KChars(lf->lf.datafile.Name.value);
+ CMPIStatus st = {.rc = CMPI_RC_OK};
+
+ if (lstat(path, &sb) < 0 || !(sb.st_mode & S_IFMT & mode)) {
+ snprintf(buf, BUFLEN, errmsg, path);
+ CMReturnWithChars(b, CMPI_RC_ERR_NOT_FOUND, buf);
+ }
+
+ get_class_from_stat(&sb, buf);
+
+ st = get_fsname_from_stat(b, &sb, &fsname);
+ check_status(st);
+
+ switch(mode) {
+ case S_IFREG:
+ fill_basic(b, DataFile, &lf->lf.datafile, buf, fsname, sb);
+ break;
+ case S_IFCHR:
+ /* FALLTHROUGH */
+ case S_IFBLK:
+ fill_basic(b, UnixDeviceFile, &lf->lf.unixdevicefile, buf, fsname, sb);
+ /* device-specific stuff */
+ char tmp[16];
+ sprintf(tmp, "%lu", sb.st_rdev);
+ LMI_UnixDeviceFile_Set_DeviceId(&lf->lf.unixdevicefile, tmp);
+ sprintf(tmp, "%u", major(sb.st_rdev));
+ LMI_UnixDeviceFile_Set_DeviceMajor(&lf->lf.unixdevicefile, tmp);
+ sprintf(tmp, "%u", minor(sb.st_rdev));
+ LMI_UnixDeviceFile_Set_DeviceMinor(&lf->lf.unixdevicefile, tmp);
+ break;
+ case S_IFDIR:
+ fill_basic(b, UnixDirectory, &lf->lf.unixdirectory, buf, fsname, sb);
+ break;
+ case S_IFIFO:
+ fill_basic(b, FIFOPipeFile, &lf->lf.fifopipefile, buf, fsname, sb);
+ break;
+ case S_IFLNK:
+ fill_basic(b, SymbolicLink, &lf->lf.symboliclink, buf, fsname, sb);
+ /* symlink-specific stuff */
+ char rpath[PATH_MAX];
+ const char *path;
+ path = KChars(lf->lf.symboliclink.Name.value);
+ realpath(path, rpath);
+ LMI_SymbolicLink_Set_TargetFile(&lf->lf.symboliclink, rpath);
+ break;
+ default:
+ /* impossible */
+ assert(0);
+ }
+
+ free(fsname);
+ return st;
+}
+
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 938673c..b84dc34 100644
--- a/src/logicalfile/file.h
+++ b/src/logicalfile/file.h
@@ -30,6 +30,12 @@
#include <konkret/konkret.h>
#include <assert.h>
#include <libudev.h>
+#include "LMI_DataFile.h"
+#include "LMI_UnixDeviceFile.h"
+#include "LMI_SymbolicLink.h"
+#include "LMI_UnixDirectory.h"
+#include "LMI_UnixSocket.h"
+#include "LMI_FIFOPipeFile.h"
#include "globals.h"
#ifndef BUFLEN
@@ -45,6 +51,9 @@
#define SAME_ELEMENT "SameElement"
#define SYSTEM_ELEMENT "SystemElement"
+/* CMPI_RC_ERR_<error> values end at 200. 0xFF should be safe. */
+#define RC_ERR_CLASS_CHECK_FAILED 0xFF
+
#define sb_permmask(sb) ((sb).st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))
#define sb_isreadable(sb) ( \
(sb_permmask(sb) & S_IRUSR) || \
@@ -71,69 +80,51 @@
type##_Set_FSName((obj), (fsname)); \
type##_Set_CreationClassName((obj), (creation_class));
-#define fill_basic(cmpitype, path, stattype, error) \
- struct stat sb; \
- char errmsg[BUFLEN]; \
- char aux[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); \
- } \
- \
- get_class_from_stat(&sb, aux); \
- LMI_##cmpitype##_Set_CreationClassName(&lmi_file, aux); \
- LMI_##cmpitype##_Set_FSCreationClassName(&lmi_file, FSCREATIONCLASSNAME); \
- char *fsname; \
- if (get_fsname_from_stat(&sb, &fsname) < 0) { \
- CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, "Can't get filesystem name"); \
- } else { \
- LMI_##cmpitype##_Set_FSName(&lmi_file, fsname); \
- free(fsname); \
- } \
- 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 fill_basic(b, cmpitype, lmi_file, creation_class_name, fsname, sb) \
+ LMI_##cmpitype##_Set_CreationClassName(lmi_file, creation_class_name); \
+ LMI_##cmpitype##_Set_FSCreationClassName(lmi_file, FSCREATIONCLASSNAME); \
+ LMI_##cmpitype##_Set_FSName(lmi_file, fsname); \
+ 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(b, stoms(sb.st_atime), 0, NULL)); \
+ LMI_##cmpitype##_Set_LastModified(lmi_file, CMNewDateTimeFromBinary(b, 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); \
+#define check_status(st) \
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); \
+#define check_class_check_status(st) \
+ if (st.rc == RC_ERR_CLASS_CHECK_FAILED) { \
CMReturn(CMPI_RC_OK); \
} \
- CMRelease(o); \
-}
+ check_status(st);
+
+#define return_with_status(b, st, code, msg) \
+ KSetStatus2(b, st, code, msg); \
+ return *(st);
+
+typedef struct {
+ union {
+ LMI_DataFile datafile;
+ LMI_UnixDeviceFile unixdevicefile;
+ LMI_UnixDirectory unixdirectory;
+ LMI_FIFOPipeFile fifopipefile;
+ LMI_UnixSocket unixsocket;
+ LMI_SymbolicLink symboliclink;
+ } lf;
+} logicalfile_t;
CMPIStatus lmi_check_required(const CMPIBroker *, const CMPIObjectPath *);
void get_class_from_stat(const struct stat *, char *);
int get_class_from_path(const char *, char *);
-int get_fsname_from_stat(const struct stat *, char **);
-int get_fsname_from_path(const char *, char **);
+CMPIStatus get_fsname_from_stat(const CMPIBroker *, const struct stat *, char **);
+CMPIStatus get_fsname_from_path(const CMPIBroker *, const char *, char **);
const char *get_string_property_from_op(const CMPIObjectPath *, const char *);
-
+CMPIStatus check_assoc_class(const CMPIBroker *, const char *, const char *, const char *);
+CMPIStatus stat_logicalfile_and_fill(const CMPIBroker *, logicalfile_t *, mode_t, const char *);
void _dump_objectpath(const CMPIObjectPath *);
#endif /* _FILE_H */