summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2014-04-22 17:00:52 +0200
committerPeter Schiffer <pschiffe@redhat.com>2014-04-23 14:40:12 +0200
commita9b3e7f90b4d2e3f1e2de158bdd861c859e0c825 (patch)
treea2e2fd1540bf25b6bbba77cd4f74f455d562cb94
parente46160ae6f3ea48d4de4e09dfe6fb3ed2ae943b5 (diff)
downloadopenlmi-providers-a9b3e7f90b4d2e3f1e2de158bdd861c859e0c825.tar.gz
openlmi-providers-a9b3e7f90b4d2e3f1e2de158bdd861c859e0c825.tar.xz
openlmi-providers-a9b3e7f90b4d2e3f1e2de158bdd861c859e0c825.zip
Software-dbus: safer extracting of element name from SwIdentity InstanceID
-rw-r--r--src/software-dbus/LMI_HostedSoftwareCollectionProvider.c2
-rw-r--r--src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c22
-rw-r--r--src/software-dbus/LMI_MemberOfSoftwareCollectionProvider.c6
-rw-r--r--src/software-dbus/LMI_Software.h36
-rw-r--r--src/software-dbus/LMI_SoftwareIdentityProvider.c6
-rw-r--r--src/software-dbus/LMI_SoftwareIdentityResourceProvider.c2
-rw-r--r--src/software-dbus/LMI_SystemSoftwareCollectionProvider.c2
-rw-r--r--src/software-dbus/sw-utils.c26
-rw-r--r--src/software-dbus/sw-utils.h36
9 files changed, 70 insertions, 68 deletions
diff --git a/src/software-dbus/LMI_HostedSoftwareCollectionProvider.c b/src/software-dbus/LMI_HostedSoftwareCollectionProvider.c
index 1284eee..8277baa 100644
--- a/src/software-dbus/LMI_HostedSoftwareCollectionProvider.c
+++ b/src/software-dbus/LMI_HostedSoftwareCollectionProvider.c
@@ -20,7 +20,7 @@
#include <konkret/konkret.h>
#include "LMI_HostedSoftwareCollection.h"
-#include "LMI_Software.h"
+#include "sw-utils.h"
static const CMPIBroker* _cb;
diff --git a/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c b/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c
index 849e8f6..144c805 100644
--- a/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c
+++ b/src/software-dbus/LMI_InstalledSoftwareIdentityProvider.c
@@ -20,7 +20,7 @@
#include <konkret/konkret.h>
#include "LMI_InstalledSoftwareIdentity.h"
-#include "LMI_Software.h"
+#include "sw-utils.h"
static const CMPIBroker* _cb;
@@ -130,9 +130,7 @@ static CMPIStatus LMI_InstalledSoftwareIdentityGetInstance(
LMI_InstalledSoftwareIdentity w;
LMI_InstalledSoftwareIdentity_InitFromObjectPath(&w, _cb, cop);
- if (create_sw_package_from_elem_name(get_str_property_from_op(w.InstalledSoftware.value,
- "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"),
- &sw_pkg) != 0) {
+ if (get_sw_pkg_from_sw_identity_op(w.InstalledSoftware.value, &sw_pkg) != 0) {
CMReturn(CMPI_RC_ERR_NOT_FOUND);
}
@@ -261,13 +259,11 @@ static CMPIStatus associators(
}
/* Is this SwIdentity installed? */
- if (create_sw_package_from_elem_name(get_str_property_from_op(cop,
- "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"),
- &sw_pkg) != 0) {
+ if (get_sw_pkg_from_sw_identity_op(cop, &sw_pkg) != 0) {
goto done;
}
- get_pk_pkg_from_sw_pkg(&sw_pkg, pk_bitfield_value(PK_FILTER_ENUM_INSTALLED),
- &pk_pkg);
+ 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) {
goto done;
@@ -357,13 +353,11 @@ static CMPIStatus references(
}
/* Is this SwIdentity installed? */
- if (create_sw_package_from_elem_name(get_str_property_from_op(cop,
- "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"),
- &sw_pkg) != 0) {
+ if (get_sw_pkg_from_sw_identity_op(cop, &sw_pkg) != 0) {
goto done;
}
- get_pk_pkg_from_sw_pkg(&sw_pkg, pk_bitfield_value(PK_FILTER_ENUM_INSTALLED),
- &pk_pkg);
+ 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) {
goto done;
diff --git a/src/software-dbus/LMI_MemberOfSoftwareCollectionProvider.c b/src/software-dbus/LMI_MemberOfSoftwareCollectionProvider.c
index ae36daa..1d4bb45 100644
--- a/src/software-dbus/LMI_MemberOfSoftwareCollectionProvider.c
+++ b/src/software-dbus/LMI_MemberOfSoftwareCollectionProvider.c
@@ -20,7 +20,7 @@
#include <konkret/konkret.h>
#include "LMI_MemberOfSoftwareCollection.h"
-#include "LMI_Software.h"
+#include "sw-utils.h"
static const CMPIBroker* _cb;
@@ -144,9 +144,7 @@ static CMPIStatus LMI_MemberOfSoftwareCollectionGetInstance(
CMReturn(CMPI_RC_ERR_NOT_FOUND);
}
- if (create_sw_package_from_elem_name(get_str_property_from_op(w.Member.value,
- "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"),
- &sw_pkg) != 0) {
+ if (get_sw_pkg_from_sw_identity_op(w.Member.value, &sw_pkg) != 0) {
CMReturn(CMPI_RC_ERR_NOT_FOUND);
}
diff --git a/src/software-dbus/LMI_Software.h b/src/software-dbus/LMI_Software.h
deleted file mode 100644
index d059f45..0000000
--- a/src/software-dbus/LMI_Software.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 LMI_SOFTWARE_H_
-#define LMI_SOFTWARE_H_
-
-#include "sw-utils.h"
-
-#define SYSTEM_SW_COLLECTION_CLASS_NAME "SystemSoftwareCollection"
-#define SW_IDENTITY_RESOURCE_CLASS_NAME "SoftwareIdentityResource"
-#define MEM_SW_COLL_CLASS_NAME "MemberOfSoftwareCollection"
-#define INST_SW_IDENTITY_CLASS_NAME "InstalledSoftwareIdentity"
-
-#define COLLECTION_ATTR "Collection"
-#define MEMBER_ATTR "Member"
-#define SYSTEM_ATTR "System"
-#define INST_SW_ATTR "InstalledSoftware"
-
-#endif /* LMI_SOFTWARE_H_ */
diff --git a/src/software-dbus/LMI_SoftwareIdentityProvider.c b/src/software-dbus/LMI_SoftwareIdentityProvider.c
index be22497..7e03bad 100644
--- a/src/software-dbus/LMI_SoftwareIdentityProvider.c
+++ b/src/software-dbus/LMI_SoftwareIdentityProvider.c
@@ -20,7 +20,7 @@
#include <konkret/konkret.h>
#include "LMI_SoftwareIdentity.h"
-#include "LMI_Software.h"
+#include "sw-utils.h"
static const CMPIBroker* _cb = NULL;
@@ -80,9 +80,7 @@ static CMPIStatus LMI_SoftwareIdentityGetInstance(
init_sw_package(&sw_pkg);
- if (create_sw_package_from_elem_name(get_str_property_from_op(cop,
- "InstanceID") + strlen(ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"),
- &sw_pkg) != 0) {
+ if (get_sw_pkg_from_sw_identity_op(cop, &sw_pkg) != 0) {
goto done;
}
diff --git a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
index c09b71d..fec2794 100644
--- a/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
+++ b/src/software-dbus/LMI_SoftwareIdentityResourceProvider.c
@@ -20,7 +20,7 @@
#include <konkret/konkret.h>
#include "LMI_SoftwareIdentityResource.h"
-#include "LMI_Software.h"
+#include "sw-utils.h"
#define DSC_LEN 256
diff --git a/src/software-dbus/LMI_SystemSoftwareCollectionProvider.c b/src/software-dbus/LMI_SystemSoftwareCollectionProvider.c
index 56a4d36..b4bc12f 100644
--- a/src/software-dbus/LMI_SystemSoftwareCollectionProvider.c
+++ b/src/software-dbus/LMI_SystemSoftwareCollectionProvider.c
@@ -20,7 +20,7 @@
#include <konkret/konkret.h>
#include "LMI_SystemSoftwareCollection.h"
-#include "LMI_Software.h"
+#include "sw-utils.h"
static const CMPIBroker* _cb = NULL;
diff --git a/src/software-dbus/sw-utils.c b/src/software-dbus/sw-utils.c
index d06bf03..76ca58b 100644
--- a/src/software-dbus/sw-utils.c
+++ b/src/software-dbus/sw-utils.c
@@ -117,6 +117,11 @@ short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg)
init_sw_package(sw_pkg);
+ if (!elem_name || !*elem_name) {
+ warn("Empty element name.");
+ goto done;
+ }
+
if (!(en = strdup(elem_name))) {
warn("Memory allocation failed.");
goto done;
@@ -606,6 +611,27 @@ gint pk_det_cmp(gpointer a, gpointer b)
* Functions related to CMPI
******************************************************************************/
+const char *get_elem_name_from_instance_id(const char *instance_id)
+{
+ if (!instance_id || !*instance_id) {
+ warn("Empty InstanceID.");
+ return "";
+ }
+
+ if (strlen(instance_id) <= SW_IDENTITY_INSTANCE_ID_PREFIX_LEN) {
+ warn("Invalid InstanceID: %s", instance_id);
+ return "";
+ }
+
+ if (strncasecmp(instance_id, SW_IDENTITY_INSTANCE_ID_PREFIX,
+ SW_IDENTITY_INSTANCE_ID_PREFIX_LEN) != 0) {
+ warn("Invalid InstanceID: %s", instance_id);
+ return "";
+ }
+
+ return instance_id + SW_IDENTITY_INSTANCE_ID_PREFIX_LEN;
+}
+
void create_instance_id(const char *class_name, const char *id,
char *instance_id, const unsigned instance_id_len)
{
diff --git a/src/software-dbus/sw-utils.h b/src/software-dbus/sw-utils.h
index 1cb7593..16e6ca1 100644
--- a/src/software-dbus/sw-utils.h
+++ b/src/software-dbus/sw-utils.h
@@ -23,6 +23,15 @@
#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <konkret/konkret.h>
+#include <packagekit-glib2/packagekit.h>
+
+#include "globals.h"
+#include "LMI_SoftwareIdentity.h"
+
#define VER_STR_LEN 256
#define ELEM_NAME_LEN 256
#define INSTANCE_ID_LEN 282
@@ -31,16 +40,22 @@
#define PK_DETAILS_LIMIT 4999
#define SW_IDENTITY_CLASS_NAME "SoftwareIdentity"
+#define SYSTEM_SW_COLLECTION_CLASS_NAME "SystemSoftwareCollection"
+#define SW_IDENTITY_RESOURCE_CLASS_NAME "SoftwareIdentityResource"
+#define MEM_SW_COLL_CLASS_NAME "MemberOfSoftwareCollection"
+#define INST_SW_IDENTITY_CLASS_NAME "InstalledSoftwareIdentity"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <packagekit-glib2/packagekit.h>
-#include <konkret/konkret.h>
+#define COLLECTION_ATTR "Collection"
+#define MEMBER_ATTR "Member"
+#define SYSTEM_ATTR "System"
+#define INST_SW_ATTR "InstalledSoftware"
-#include "globals.h"
+#define SW_IDENTITY_INSTANCE_ID_PREFIX ORGID ":" ORGID "_" SW_IDENTITY_CLASS_NAME ":"
+#define SW_IDENTITY_INSTANCE_ID_PREFIX_LEN 25
-#include "LMI_SoftwareIdentity.h"
+#define get_sw_pkg_from_sw_identity_op(cop, sw_pkg) \
+ create_sw_package_from_elem_name(get_elem_name_from_instance_id(\
+ get_str_property_from_op(cop, "InstanceID")), sw_pkg)
const char *provider_name;
const ConfigEntry *provider_config_defaults;
@@ -219,6 +234,13 @@ gint pk_det_cmp(gpointer a, gpointer b);
* Functions related to CMPI
******************************************************************************/
/*
+ * Get SwPackage element name from InstanceID of LMI_SoftwareIdentity object.
+ * @param instance_id of LMI_SoftwareIdentity object
+ * @return element name or empty string in case of some problem
+ */
+const char *get_elem_name_from_instance_id(const char *instance_id);
+
+/*
* Create standard instance ID based on class name and ID.
* @param class_name
* @param id, may by null