summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2014-06-13 15:23:29 +0200
committerPeter Schiffer <pschiffe@redhat.com>2014-06-17 13:48:52 +0200
commit3f16fa68006b8734a626a2b6e300926079150c07 (patch)
tree784cb1e2c9e7525715b001d8b8b463356114ea1c
parentd53ca0303a56a1811f73806f5f2ea38ae676049f (diff)
downloadopenlmi-providers-3f16fa68006b8734a626a2b6e300926079150c07.tar.gz
openlmi-providers-3f16fa68006b8734a626a2b6e300926079150c07.tar.xz
openlmi-providers-3f16fa68006b8734a626a2b6e300926079150c07.zip
software-dbus: implemented LMI_SoftwareIdentityFileCheckProvider
-rw-r--r--mof/60_LMI_Software.mof9
-rw-r--r--src/software-dbus/CMakeLists.txt7
-rw-r--r--src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c17
-rw-r--r--src/software-dbus/LMI_SoftwareIdentityFileCheckProvider.c437
-rw-r--r--src/software-dbus/config.h.in26
-rw-r--r--src/software-dbus/sw-utils.c48
-rw-r--r--src/software-dbus/sw-utils.h18
7 files changed, 532 insertions, 30 deletions
diff --git a/mof/60_LMI_Software.mof b/mof/60_LMI_Software.mof
index e3d6325..e0e7a29 100644
--- a/mof/60_LMI_Software.mof
+++ b/mof/60_LMI_Software.mof
@@ -922,11 +922,12 @@ class LMI_SoftwareIdentityFileCheck : CIM_FileSpecification {
"File name of verified file without any directory prefix.")]
string FileName;
- [Implemented(true), Override("FileSize"), Description(
+ [Implemented(true), Units("Bytes"), PUnit("Byte"), Override("FileSize"),
+ Description(
"Size of installed file in Bytes. It's NULL if file does not exist"
" or it's not a regular file or symbolic link.")]
uint64 FileSize;
- [Implemented(true), Units("KiloBytes"),
+ [Implemented(true), Units("Bytes"), PUnit("Byte"),
Description("File size in Bytes from RPM database.")]
uint64 FileSizeOriginal;
@@ -968,12 +969,12 @@ class LMI_SoftwareIdentityFileCheck : CIM_FileSpecification {
[Implemented(true), Description(
"Target destination of symbolic link as returned by"
- " readline. If file is not a symbolic link or it's missing,"
+ " readlink. If file is not a symbolic link or it's missing,"
" NULL is returned.")]
string LinkTarget;
[Implemented(true), Description(
"Target destination of symbolic link from RPM database"
- " as returned by readline. If file is not a symbolic link,"
+ " as returned by readlink. If file is not a symbolic link,"
" NULL is returned.")]
string LinkTargetOriginal;
diff --git a/src/software-dbus/CMakeLists.txt b/src/software-dbus/CMakeLists.txt
index 04d8508..a1ab215 100644
--- a/src/software-dbus/CMakeLists.txt
+++ b/src/software-dbus/CMakeLists.txt
@@ -22,6 +22,7 @@ add_library(${LIBRARY_NAME} SHARED
)
pkg_check_modules(PACKAGEKIT REQUIRED packagekit-glib2)
+pkg_check_modules(RPM rpm)
include_directories(${CMAKE_CURRENT_BINARY_DIR}
${CMPI_INCLUDE_DIR}
@@ -29,7 +30,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}
target_link_libraries(${LIBRARY_NAME}
openlmicommon
${KONKRETCMPI_LIBRARIES}
- ${PACKAGEKIT_LIBRARIES})
+ ${PACKAGEKIT_LIBRARIES}
+ ${RPM_LIBRARIES})
+
+configure_file(config.h.in
+ config.h)
# Create registration file
set(TARGET_MOF "${CMAKE_BINARY_DIR}/mof/90_LMI_${PROVIDER_NAME}_Profile.mof")
diff --git a/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c b/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c
index a190327..823ac1c 100644
--- a/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c
+++ b/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c
@@ -122,25 +122,14 @@ static CMPIStatus LMI_InstalledSoftwareIdentityGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- PkPackage *pk_pkg = NULL;
- SwPackage sw_pkg;
-
- init_sw_package(&sw_pkg);
-
LMI_InstalledSoftwareIdentity w;
LMI_InstalledSoftwareIdentity_InitFromObjectPath(&w, _cb, cop);
- if (get_sw_pkg_from_sw_identity_op(w.InstalledSoftware.value, &sw_pkg) != 0) {
- CMReturn(CMPI_RC_ERR_NOT_FOUND);
- }
-
- get_pk_pkg_from_sw_pkg(&sw_pkg, pk_bitfield_value(PK_FILTER_ENUM_INSTALLED),
- &pk_pkg);
- free_sw_package(&sw_pkg);
- if (!pk_pkg) {
+ if (!is_elem_name_installed(get_elem_name_from_instance_id(
+ lmi_get_string_property_from_objectpath(w.InstalledSoftware.value,
+ "InstanceID")))) {
CMReturn(CMPI_RC_ERR_NOT_FOUND);
}
- g_object_unref(pk_pkg);
KReturnInstance(cr, w);
CMReturn(CMPI_RC_OK);
diff --git a/src/software-dbus/LMI_SoftwareIdentityFileCheckProvider.c b/src/software-dbus/LMI_SoftwareIdentityFileCheckProvider.c
index 57e34bf..0f865a3 100644
--- a/src/software-dbus/LMI_SoftwareIdentityFileCheckProvider.c
+++ b/src/software-dbus/LMI_SoftwareIdentityFileCheckProvider.c
@@ -1,10 +1,78 @@
+/*
+ * Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Peter Schiffer <pschiffe@redhat.com>
+ */
+
#include <konkret/konkret.h>
#include "LMI_SoftwareIdentityFileCheck.h"
+#include "sw-utils.h"
+#include "config.h"
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+#include <errno.h>
+#include <pthread.h>
+
+#ifdef RPM_FOUND
+#include <rpm/rpmlib.h>
+#include <rpm/rpmdb.h>
+#include <rpm/rpmts.h>
+#include <rpm/rpmfi.h>
+#include <rpm/rpmvf.h>
+#include <rpm/rpmfileutil.h>
+#endif
static const CMPIBroker* _cb = NULL;
-static void LMI_SoftwareIdentityFileCheckInitialize()
+/* Mutex for transaction set */
+static pthread_mutex_t ts_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+#ifdef RPM_FOUND
+ rpmts ts = NULL;
+#endif
+
+static void LMI_SoftwareIdentityFileCheckInitialize(const CMPIContext *ctx)
{
+ lmi_init(provider_name, _cb, ctx, provider_config_defaults);
+
+#ifdef RPM_FOUND
+ pthread_mutex_lock(&ts_mutex);
+
+ if (rpmReadConfigFiles(NULL, NULL) != 0) {
+ pthread_mutex_unlock(&ts_mutex);
+ lmi_error("Failed to read RPM configuration files.");
+ abort();
+ }
+
+ if (!ts) {
+ if (!(ts = rpmtsCreate())) {
+ pthread_mutex_unlock(&ts_mutex);
+ lmi_error("Failed to create RPM transaction set.");
+ abort();
+ }
+ }
+
+ pthread_mutex_unlock(&ts_mutex);
+#endif
}
static CMPIStatus LMI_SoftwareIdentityFileCheckCleanup(
@@ -12,6 +80,15 @@ static CMPIStatus LMI_SoftwareIdentityFileCheckCleanup(
const CMPIContext* cc,
CMPIBoolean term)
{
+#ifdef RPM_FOUND
+ if (ts) {
+ pthread_mutex_lock(&ts_mutex);
+ rpmtsFree(ts);
+ ts = NULL;
+ pthread_mutex_unlock(&ts_mutex);
+ }
+#endif
+
CMReturn(CMPI_RC_OK);
}
@@ -21,8 +98,7 @@ static CMPIStatus LMI_SoftwareIdentityFileCheckEnumInstanceNames(
const CMPIResult* cr,
const CMPIObjectPath* cop)
{
- return KDefaultEnumerateInstanceNames(
- _cb, mi, cc, cr, cop);
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
}
static CMPIStatus LMI_SoftwareIdentityFileCheckEnumInstances(
@@ -32,7 +108,92 @@ static CMPIStatus LMI_SoftwareIdentityFileCheckEnumInstances(
const CMPIObjectPath* cop,
const char** properties)
{
- CMReturn(CMPI_RC_OK);
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+}
+
+static short count_mode_flags(mode_t st_mode)
+{
+ short all_flags = S_IXOTH | S_IWOTH | S_IROTH | S_IXGRP | S_IWGRP | S_IRGRP
+ | S_IXUSR | S_IWUSR | S_IRUSR | S_ISVTX | S_ISGID | S_ISUID;
+
+ return(popcount(st_mode & all_flags));
+}
+
+static void set_file_mode_flags(
+ CMPIBoolean (*lmi_set_file_type)(LMI_SoftwareIdentityFileCheck *, CMPICount, CMPIUint8),
+ LMI_SoftwareIdentityFileCheck *w, mode_t st_mode)
+{
+ short curr_flag = 0;
+
+ if (st_mode & S_IXOTH) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Execute_Other);
+ }
+ if (st_mode & S_IWOTH) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Write_Other);
+ }
+ if (st_mode & S_IROTH) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Read_Other);
+ }
+ if (st_mode & S_IXGRP) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Execute_Group);
+ }
+ if (st_mode & S_IWGRP) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Write_Group);
+ }
+ if (st_mode & S_IRGRP) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Read_Group);
+ }
+ if (st_mode & S_IXUSR) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Execute_User);
+ }
+ if (st_mode & S_IWUSR) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Write_User);
+ }
+ if (st_mode & S_IRUSR) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Read_User);
+ }
+ if (st_mode & S_ISVTX) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_Sticky);
+ }
+ if (st_mode & S_ISGID) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_SGID);
+ }
+ if (st_mode & S_ISUID) {
+ lmi_set_file_type(w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FileModeFlags_SUID);
+ }
+}
+
+static void set_file_type(
+ void (*lmi_set_file_type)(LMI_SoftwareIdentityFileCheck *, CMPIUint16),
+ LMI_SoftwareIdentityFileCheck *w, mode_t st_mode)
+{
+ if (S_ISREG(st_mode)) {
+ lmi_set_file_type(w, LMI_SoftwareIdentityFileCheck_FileType_File);
+ } else if (S_ISDIR(st_mode)) {
+ lmi_set_file_type(w, LMI_SoftwareIdentityFileCheck_FileType_Directory);
+ } else if (S_ISCHR(st_mode)) {
+ lmi_set_file_type(w, LMI_SoftwareIdentityFileCheck_FileType_Character_Device);
+ } else if (S_ISBLK(st_mode)) {
+ lmi_set_file_type(w, LMI_SoftwareIdentityFileCheck_FileType_Block_Device);
+ } else if (S_ISFIFO(st_mode)) {
+ lmi_set_file_type(w, LMI_SoftwareIdentityFileCheck_FileType_FIFO);
+ } else if (S_ISLNK(st_mode)) {
+ lmi_set_file_type(w, LMI_SoftwareIdentityFileCheck_FileType_Symlink);
+ } else {
+ lmi_set_file_type(w, LMI_SoftwareIdentityFileCheck_FileType_Unknown);
+ }
}
static CMPIStatus LMI_SoftwareIdentityFileCheckGetInstance(
@@ -42,8 +203,231 @@ static CMPIStatus LMI_SoftwareIdentityFileCheckGetInstance(
const CMPIObjectPath* cop,
const char** properties)
{
- return KDefaultGetInstance(
- _cb, mi, cc, cr, cop, properties);
+#ifndef RPM_FOUND
+ CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+#else
+ rpmfi fi = NULL;
+ Header rpm_header;
+ rpm_mode_t rpm_mode;
+ rpmdbMatchIterator iter = NULL;
+ struct stat sb;
+ const char *elem_name, *file_name;
+ char error_msg[BUFLEN] = "";
+ short file_exists = 1;
+
+ elem_name = lmi_get_string_property_from_objectpath(cop, "SoftwareElementID");
+ file_name = lmi_get_string_property_from_objectpath(cop, "Name");
+
+ if (!is_elem_name_installed(elem_name)) {
+ CMReturn(CMPI_RC_ERR_NOT_FOUND);
+ }
+
+ pthread_mutex_lock(&ts_mutex);
+
+ iter = rpmtsInitIterator(ts, RPMDBI_LABEL, elem_name, 0);
+ if (!iter || rpmdbGetIteratorCount(iter) != 1) {
+ pthread_mutex_unlock(&ts_mutex);
+ snprintf(error_msg, BUFLEN, "Failed to find package: %s", elem_name);
+ goto done;
+ }
+
+ rpm_header = rpmdbNextIterator(iter);
+
+ if (!(fi = rpmfiNew(ts, rpm_header, 0, RPMFI_KEEPHEADER))) {
+ pthread_mutex_unlock(&ts_mutex);
+ snprintf(error_msg, BUFLEN, "Failed to create RPM file info.");
+ goto done;
+ }
+
+ pthread_mutex_unlock(&ts_mutex);
+
+ int fi_it;
+ rpmfiInit(fi, 0);
+ while ((fi_it = rpmfiNext(fi)) >= 0) {
+ if (strcmp(rpmfiFN(fi), file_name) == 0) {
+ break;
+ }
+ }
+ if (fi_it < 0) {
+ snprintf(error_msg, BUFLEN, "Package %s doesn't contain file: %s",
+ elem_name, file_name);
+ goto done;
+ }
+
+ if (lstat(file_name, &sb) != 0) {
+ if (errno == ENOENT) {
+ file_exists = 0;
+ } else {
+ snprintf(error_msg, BUFLEN, "Failed to lstat file %s: %s",
+ file_name, strerror(errno));
+ goto done;
+ }
+ }
+
+ rpm_mode = rpmfiFMode(fi);
+
+ LMI_SoftwareIdentityFileCheck w;
+ LMI_SoftwareIdentityFileCheck_InitFromObjectPath(&w, _cb, cop);
+ LMI_SoftwareIdentityFileCheck_Set_CheckMode(&w, 1);
+ LMI_SoftwareIdentityFileCheck_Set_FileExists(&w, file_exists);
+
+ if (basename(file_name)) {
+ LMI_SoftwareIdentityFileCheck_Set_FileName(&w, basename(file_name));
+ }
+
+ rpmVerifyAttrs res = 0;
+ pthread_mutex_lock(&ts_mutex);
+ if (rpmVerifyFile(ts, fi, &res, 0) != 0) {
+ pthread_mutex_unlock(&ts_mutex);
+ LMI_SoftwareIdentityFileCheck_Init_FailedFlags(&w, 1);
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, 0,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_Existence);
+ } else if (res) {
+ pthread_mutex_unlock(&ts_mutex);
+
+ short curr_flag = 0;
+
+ LMI_SoftwareIdentityFileCheck_Init_FailedFlags(&w, popcount(res));
+
+ if (res & RPMVERIFY_FILESIZE) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_FileSize);
+ }
+ if (res & RPMVERIFY_MODE) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_FileMode);
+ }
+ if (res & RPMVERIFY_FILEDIGEST) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_Checksum);
+ }
+ if (res & RPMVERIFY_RDEV) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_Device_Number);
+ }
+ if (res & RPMVERIFY_LINKTO) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_LinkTarget);
+ }
+ if (res & RPMVERIFY_USER) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_UserID);
+ }
+ if (res & RPMVERIFY_GROUP) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_GroupID);
+ }
+ if (res & RPMVERIFY_MTIME) {
+ LMI_SoftwareIdentityFileCheck_Set_FailedFlags(&w, curr_flag++,
+ LMI_SoftwareIdentityFileCheck_FailedFlags_Last_Modification_Time);
+ }
+ } else {
+ pthread_mutex_unlock(&ts_mutex);
+ }
+
+ int algo = PGPHASHALGO_MD5;
+ char *header_digest = NULL;
+ if ((header_digest = rpmfiFDigestHex(fi, &algo))) {
+ LMI_SoftwareIdentityFileCheck_Set_ChecksumType(&w, algo);
+ if (rpm_mode && S_ISREG(rpm_mode)) {
+ LMI_SoftwareIdentityFileCheck_Set_FileChecksumOriginal(&w,
+ header_digest);
+ }
+
+ free(header_digest);
+ header_digest = NULL;
+
+ unsigned char fdigest[BUFLEN];
+ if (rpmDoDigest(algo, file_name, 1, fdigest, NULL) == 0) {
+ if (*fdigest) {
+ LMI_SoftwareIdentityFileCheck_Set_FileChecksum(&w,
+ (char *)fdigest);
+ }
+ }
+ if (rpmDoDigest(PGPHASHALGO_MD5, file_name, 1, fdigest, NULL) == 0) {
+ if (*fdigest) {
+ LMI_SoftwareIdentityFileCheck_Set_MD5Checksum(&w, (char *)fdigest);
+ }
+ }
+ }
+
+ if (rpmfiFSize(fi)) {
+ LMI_SoftwareIdentityFileCheck_Set_FileSizeOriginal(&w, rpmfiFSize(fi));
+ }
+
+ if (file_exists) {
+ LMI_SoftwareIdentityFileCheck_Set_FileSize(&w, sb.st_size);
+
+ LMI_SoftwareIdentityFileCheck_Set_FileMode(&w, sb.st_mode);
+ LMI_SoftwareIdentityFileCheck_Init_FileModeFlags(&w,
+ count_mode_flags(sb.st_mode));
+ set_file_mode_flags(LMI_SoftwareIdentityFileCheck_Set_FileModeFlags, &w,
+ sb.st_mode);
+ set_file_type(LMI_SoftwareIdentityFileCheck_Set_FileType, &w, sb.st_mode);
+
+ LMI_SoftwareIdentityFileCheck_Set_UserID(&w, sb.st_uid);
+ LMI_SoftwareIdentityFileCheck_Set_GroupID(&w, sb.st_gid);
+ LMI_SoftwareIdentityFileCheck_Set_LastModificationTime(&w, sb.st_mtime);
+
+ if (S_ISLNK(sb.st_mode)) {
+ ssize_t r;
+ char link_name[PATH_MAX];
+ if ((r = readlink(file_name, link_name, PATH_MAX)) > 0) {
+ link_name[r] = '\0';
+ LMI_SoftwareIdentityFileCheck_Set_LinkTarget(&w, link_name);
+ }
+ }
+ }
+
+ if (rpm_mode) {
+ LMI_SoftwareIdentityFileCheck_Set_FileModeOriginal(&w, rpm_mode);
+ LMI_SoftwareIdentityFileCheck_Init_FileModeFlagsOriginal(&w,
+ count_mode_flags(rpm_mode));
+ set_file_mode_flags(LMI_SoftwareIdentityFileCheck_Set_FileModeFlagsOriginal,
+ &w, rpm_mode);
+ set_file_type(LMI_SoftwareIdentityFileCheck_Set_FileTypeOriginal, &w,
+ rpm_mode);
+ }
+
+ if (rpmfiFUser(fi)) {
+ struct passwd *pwd = getpwnam(rpmfiFUser(fi));
+ if (pwd) {
+ LMI_SoftwareIdentityFileCheck_Set_UserIDOriginal(&w, pwd->pw_uid);
+ }
+ }
+
+ if (rpmfiFGroup(fi)) {
+ struct group *grp = getgrnam(rpmfiFGroup(fi));
+ if (grp) {
+ LMI_SoftwareIdentityFileCheck_Set_GroupIDOriginal(&w, grp->gr_gid);
+ }
+ }
+
+ if (rpmfiFMtime(fi)) {
+ LMI_SoftwareIdentityFileCheck_Set_LastModificationTimeOriginal(&w,
+ rpmfiFMtime(fi));
+ }
+
+ if (rpmfiFLink(fi)) {
+ LMI_SoftwareIdentityFileCheck_Set_LinkTargetOriginal(&w, rpmfiFLink(fi));
+ }
+
+ KReturnInstance(cr, w);
+
+done:
+ if (fi) {
+ rpmfiFree(fi);
+ }
+ if (iter) {
+ rpmdbFreeIterator(iter);
+ }
+
+ if (*error_msg) {
+ KReturn2(_cb, ERR_FAILED, "%s", error_msg);
+ }
+
+ CMReturn(CMPI_RC_OK);
+#endif
}
static CMPIStatus LMI_SoftwareIdentityFileCheckCreateInstance(
@@ -91,7 +475,7 @@ CMInstanceMIStub(
LMI_SoftwareIdentityFileCheck,
LMI_SoftwareIdentityFileCheck,
_cb,
- LMI_SoftwareIdentityFileCheckInitialize())
+ LMI_SoftwareIdentityFileCheckInitialize(ctx))
static CMPIStatus LMI_SoftwareIdentityFileCheckMethodCleanup(
CMPIMethodMI* mi,
@@ -118,7 +502,7 @@ CMMethodMIStub(
LMI_SoftwareIdentityFileCheck,
LMI_SoftwareIdentityFileCheck,
_cb,
- LMI_SoftwareIdentityFileCheckInitialize())
+ LMI_SoftwareIdentityFileCheckInitialize(ctx))
KUint32 LMI_SoftwareIdentityFileCheck_Invoke(
const CMPIBroker* cb,
@@ -129,7 +513,30 @@ KUint32 LMI_SoftwareIdentityFileCheck_Invoke(
{
KUint32 result = KUINT32_INIT;
+#ifdef RPM_FOUND
+ CMPIObjectPath *o = LMI_SoftwareIdentityFileCheckRef_ToObjectPath(self, NULL);
+ CMPIInstance *ci = _cb->bft->getInstance(_cb, context, o, NULL, NULL);
+ CMPIData d = CMGetProperty(ci, "FailedFlags", NULL);
+
+ /*
+ * Result values:
+ * 0 - condition is satisfied
+ * 1 - method is not supported
+ * 2 - condition is not satisfied
+ */
+ if (CMIsNullValue(d)) {
+ KUint32_Set(&result, 0);
+ } else {
+ KUint32_Set(&result, 2);
+ }
+
+ KSetStatus(status, OK);
+
+#else
+ KUint32_Set(&result, 1);
KSetStatus(status, ERR_NOT_SUPPORTED);
+#endif
+
return result;
}
@@ -141,10 +548,18 @@ KUint32 LMI_SoftwareIdentityFileCheck_InvokeOnSystem(
const KRef* TargetSystem,
CMPIStatus* status)
{
- KUint32 result = KUINT32_INIT;
+ if (TargetSystem && TargetSystem->exists) {
+ CMPIStatus st = lmi_check_required_properties(cb, context,
+ TargetSystem->value, "CreationClassName", "Name");
- KSetStatus(status, ERR_NOT_SUPPORTED);
- return result;
+ if (st.rc != CMPI_RC_OK) {
+ KUint32 result = KUINT32_INIT;
+ KSetStatus(status, ERR_NOT_FOUND);
+ return result;
+ }
+ }
+
+ return LMI_SoftwareIdentityFileCheck_Invoke(cb, mi, context, self, status);
}
KONKRET_REGISTRATION(
diff --git a/src/software-dbus/config.h.in b/src/software-dbus/config.h.in
new file mode 100644
index 0000000..7088bf2
--- /dev/null
+++ b/src/software-dbus/config.h.in
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Peter Schiffer <pschiffe@redhat.com>
+ */
+
+#ifndef CONFIG_H_
+#define CONFIG_H_
+
+#cmakedefine RPM_FOUND
+
+#endif /* CONFIG_H_ */
diff --git a/src/software-dbus/sw-utils.c b/src/software-dbus/sw-utils.c
index d6aa06e..01784d5 100644
--- a/src/software-dbus/sw-utils.c
+++ b/src/software-dbus/sw-utils.c
@@ -229,6 +229,35 @@ void sw_pkg_get_element_name(const SwPackage *pkg, char *elem_name,
* Functions related to single PkPackage
******************************************************************************/
+short is_elem_name_installed(const char *elem_name)
+{
+ SwPackage sw_pkg;
+ PkPackage *pk_pkg = NULL;
+ short ret = 0;
+
+ init_sw_package(&sw_pkg);
+
+ if (create_sw_package_from_elem_name(elem_name, &sw_pkg) != 0) {
+ goto done;
+ }
+
+ get_pk_pkg_from_sw_pkg(&sw_pkg,
+ pk_bitfield_value(PK_FILTER_ENUM_INSTALLED), &pk_pkg);
+
+ if (pk_pkg) {
+ ret = 1;
+ }
+
+done:
+ free_sw_package(&sw_pkg);
+
+ if (pk_pkg) {
+ g_object_unref(pk_pkg);
+ }
+
+ return ret;
+}
+
void get_pk_pkg_from_sw_pkg(const SwPackage *sw_pkg, PkBitfield filters,
PkPackage **pk_pkg)
{
@@ -925,3 +954,22 @@ void create_instance_id(const char *class_name, const char *id,
snprintf(instance_id, instance_id_len, LMI_ORGID ":%s", class_name);
}
}
+
+/*******************************************************************************
+ * General functions
+ ******************************************************************************/
+
+short popcount(unsigned x)
+{
+ short count;
+
+ if (!x) {
+ return 0;
+ }
+
+ for (count = 0; x; count++) {
+ x &= x - 1;
+ }
+
+ return count;
+}
diff --git a/src/software-dbus/sw-utils.h b/src/software-dbus/sw-utils.h
index d3475a8..567ca72 100644
--- a/src/software-dbus/sw-utils.h
+++ b/src/software-dbus/sw-utils.h
@@ -118,6 +118,13 @@ void sw_pkg_get_element_name(const SwPackage *pkg, char *elem_name,
* Functions related to single PkPackage
******************************************************************************/
/*
+ * Checks with PackageKit whether package with this element name is installed.
+ * @param elem_name element name of the package
+ * @return 1 if package is installed, 0 otherwise
+ */
+short is_elem_name_installed(const char *elem_name);
+
+/*
* Get PkPackage according to the SwPackage.
* @param sw_pkg SwPackage
* @param filters
@@ -319,4 +326,15 @@ const char *get_elem_name_from_instance_id(const char *instance_id);
void create_instance_id(const char *class_name, const char *id,
char *instance_id, const unsigned instance_id_len);
+/*******************************************************************************
+ * General functions
+ ******************************************************************************/
+/*
+ * Function counting Hamming weight, i.e. number of 1's in a binary
+ * representation of the number x.
+ * @param x number where we want to count the 1's
+ * @return number of 1's
+ */
+short popcount(unsigned x);
+
#endif /* SW_UTILS_H_ */