From ef753ffe67c059020f56610f66960662e98d78d4 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Wed, 27 Jul 2016 14:46:26 -0400 Subject: [PATCH] Remove non-reserved attributes when setting "target". --- doc/pwmd-dump.1.in | 11 ++++++----- src/pwmd-dump.c | 32 ++++++++++++++++++++++++++++++++ src/xml.c | 20 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/doc/pwmd-dump.1.in b/doc/pwmd-dump.1.in index 3f5649f0..3ba9d01e 100644 --- a/doc/pwmd-dump.1.in +++ b/doc/pwmd-dump.1.in @@ -19,7 +19,7 @@ \\$2 \(laURL: \\$1 \(ra\\$3 .. .if \n[.g] .mso www.tmac -.TH PWMD-DUMP 1 "2 Jul 2016" "@VERSION@" "Password Manager Daemon" +.TH PWMD-DUMP 1 "27 Jul 2016" "@VERSION@" "Password Manager Daemon" .SH NAME pwmd-dump \- dump raw XML from a pwmd 3.0.x data file @@ -32,8 +32,8 @@ pwmd-dump \- dump raw XML from a pwmd 3.0.x data file reads a .BR pwmd (1) version 3.0.x data file and dumps the raw unencrypted XML to the specified -output file while stripping the literal element character and child nodes of -an element with a +output file while stripping the literal element character and non-reserved +attributes and child nodes of an element with a .B target attribute. See option .B --no-convert. @@ -61,8 +61,9 @@ and others. Before dumping the XML, .B pwmd-dump will strip any leading literal element character '!' from -each element in the element path of a "target" attribute and remove all child -nodes of the element containing the "target" attribute. Since version 3.1 of +each element in the element path of a "target" attribute and remove all +non-reserved attributes and all child nodes of the element containing +the "target" attribute. Since version 3.1 of .B pwmd there are no such literal elements. All targets are followed just as a symbolic link on a filesystem. This option prevents converting and will dump diff --git a/src/pwmd-dump.c b/src/pwmd-dump.c index 87c01312..8991d30d 100644 --- a/src/pwmd-dump.c +++ b/src/pwmd-dump.c @@ -134,6 +134,10 @@ struct crypto_s #define DEFAULT_KDFS2K_ITERATIONS 5000000 #define COMPAT_KDFS2K_ITERATIONS 1000 +const char *reserved_attributes[] = { + "_name", "_mtime", "_ctime", "_acl", "target", + NULL +}; static unsigned char crypto_magic[5] = "\177PWMD"; static int use_agent; @@ -303,6 +307,33 @@ xml_attribute_value (xmlNodePtr n, xmlChar * attr) return xmlGetProp (n, attr); } +static int +xml_reserved_attribute (const char *name) +{ + int i; + + for (i = 0; reserved_attributes[i]; i++) + { + if (!strcmp (name, reserved_attributes[i])) + return 1; + } + + return 0; +} +static void +remove_non_reserved_attributes (xmlNodePtr n) +{ + xmlAttrPtr a; + + for (a = n->properties; a; a = a->next) + { + if (xml_reserved_attribute ((char *)a->name)) + continue; + + xmlRemoveProp (a); + } +} + static gpg_error_t strip_literals (const char *filename, xmlNodePtr n, int force) { @@ -320,6 +351,7 @@ strip_literals (const char *filename, xmlNodePtr n, int force) { xmlChar lastc = 0, *p; + remove_non_reserved_attributes (n); again: for (lastc = 0, p = target; *p;) { diff --git a/src/xml.c b/src/xml.c index bf37b91a..059a3cd3 100644 --- a/src/xml.c +++ b/src/xml.c @@ -568,18 +568,35 @@ xml_attribute_value (xmlNodePtr n, xmlChar * attr) return xmlGetProp (n, attr); } +static void +remove_non_reserved_attributes (xmlNodePtr n) +{ + xmlAttrPtr a; + + for (a = n->properties; a; a = a->next) + { + if (xml_reserved_attribute ((char *)a->name)) + continue; + + (void)xml_delete_attribute (NULL, n, a->name); + } +} + gpg_error_t xml_add_attribute (struct client_s *client, xmlNodePtr node, const char *name, const char *value) { char *buf; gpg_error_t rc = 0; + int is_target = 0; if (client && name && !strcmp (name, "target")) { rc = xml_is_element_owner (client, node); if (rc) return rc; + + is_target = 1; } else if (name && !strcmp (name, "expire")) { @@ -621,6 +638,9 @@ xml_add_attribute (struct client_s *client, xmlNodePtr node, const char *name, if (name && xmlStrEqual ((xmlChar *) name, (xmlChar *) "_mtime")) return 0; + if (is_target) + remove_non_reserved_attributes (node); + buf = str_asprintf ("%lu", time (NULL)); rc = xml_add_attribute (client, node, "_mtime", buf); xfree (buf); -- 2.11.4.GIT