[Rpm-maint] [PATCH 4/6] Create a new publicly accessible function, rpmteHeaderOpen

Steve Lawrence slawrence at tresys.com
Wed Jul 14 20:40:46 UTC 2010


When the SELinux policy collection plugin is executed, the transaction
element has already been closed, and the header cannot be accessed.
However, access to the header is needed to extract policy data. The new
rpmteHeaderOpen function allows accessing the header of a closed
transaction element by opening it if necessary.
---
 lib/rpmte.c |   17 +++++++++++++++++
 lib/rpmte.h |    8 ++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/lib/rpmte.c b/lib/rpmte.c
index ee86957..442b2cd 100644
--- a/lib/rpmte.c
+++ b/lib/rpmte.c
@@ -73,6 +73,7 @@ struct rpmte_s {
 
 /* forward declarations */
 static void rpmteColorDS(rpmte te, rpmTag tag);
+static int rpmteOpen(rpmte te, int reload_fi);
 static int rpmteClose(rpmte te, int reset_fi);
 
 void rpmteCleanDS(rpmte te)
@@ -328,6 +329,22 @@ Header rpmteHeader(rpmte te)
     return (te != NULL && te->h != NULL ? headerLink(te->h) : NULL);
 }
 
+Header rpmteHeaderOpen(rpmte te)
+{
+    Header h = NULL;
+
+    if (te) {
+	h = rpmteHeader(te);
+	if (!h) {
+	    rpmteOpen(te, 0);
+	    h = rpmteHeader(te);
+	    rpmteClose(te, 0);
+	}
+    }
+
+    return h;
+}
+
 Header rpmteSetHeader(rpmte te, Header h)
 {
     if (te != NULL)  {
diff --git a/lib/rpmte.h b/lib/rpmte.h
index 17854d7..54fec6d 100644
--- a/lib/rpmte.h
+++ b/lib/rpmte.h
@@ -29,6 +29,14 @@ typedef enum rpmElementType_e {
 Header rpmteHeader(rpmte te);
 
 /** \ingroup rpmte
+ * Retrieve header from transaction element. Open and close the transaction
+ * element to get the header if necessary.
+ * @param te		transaction element
+ * @return		header (new reference)
+ */
+Header rpmteHeaderOpen(rpmte te);
+
+/** \ingroup rpmte
  * Save header into transaction element.
  * @param te		transaction element
  * @param h		header
-- 
1.6.2.5



More information about the Rpm-maint mailing list