summaryrefslogtreecommitdiffstats
path: root/src/sbus
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2015-01-29 15:29:26 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-05-22 15:57:03 +0200
commit10a28f461c25d788ff4dcffefa881e7aa724a25d (patch)
tree5df10c69ac2c35e93c9934a6a43fc4474efde3c8 /src/sbus
parent364b3572bab5a9649e8f2d4da835d05d3c8ca7a9 (diff)
downloadsssd-10a28f461c25d788ff4dcffefa881e7aa724a25d.tar.gz
sssd-10a28f461c25d788ff4dcffefa881e7aa724a25d.tar.xz
sssd-10a28f461c25d788ff4dcffefa881e7aa724a25d.zip
sbus: add sbus_opath_decompose[_exact]
This function decomposes object path into array of strings. The "_exact" version expects a certain number of parts otherwise an error is thrown. Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/sbus')
-rw-r--r--src/sbus/sssd_dbus.h14
-rw-r--r--src/sbus/sssd_dbus_interface.c93
2 files changed, 107 insertions, 0 deletions
diff --git a/src/sbus/sssd_dbus.h b/src/sbus/sssd_dbus.h
index 6d2d5897a..61c18ae28 100644
--- a/src/sbus/sssd_dbus.h
+++ b/src/sbus/sssd_dbus.h
@@ -196,6 +196,20 @@ _sbus_opath_compose(TALLOC_CTX *mem_ctx,
#define sbus_opath_compose(mem_ctx, base, ...) \
_sbus_opath_compose(mem_ctx, base, ##__VA_ARGS__, NULL)
+errno_t
+sbus_opath_decompose(TALLOC_CTX *mem_ctx,
+ const char *object_path,
+ const char *prefix,
+ char ***_components,
+ size_t *_len);
+
+errno_t
+sbus_opath_decompose_exact(TALLOC_CTX *mem_ctx,
+ const char *object_path,
+ const char *prefix,
+ size_t expected,
+ char ***_components);
+
const char *
sbus_opath_strip_prefix(const char *object_path,
const char *prefix);
diff --git a/src/sbus/sssd_dbus_interface.c b/src/sbus/sssd_dbus_interface.c
index 1fd55904d..1651478a8 100644
--- a/src/sbus/sssd_dbus_interface.c
+++ b/src/sbus/sssd_dbus_interface.c
@@ -354,6 +354,99 @@ fail:
return NULL;
}
+errno_t
+sbus_opath_decompose(TALLOC_CTX *mem_ctx,
+ const char *object_path,
+ const char *prefix,
+ char ***_components,
+ size_t *_len)
+{
+ TALLOC_CTX *tmp_ctx;
+ const char *path;
+ char **decomposed;
+ char **unescaped;
+ errno_t ret;
+ int len;
+ int i;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ /* Strip prefix from the path. */
+ if (prefix != NULL) {
+ path = sbus_opath_strip_prefix(object_path, prefix);
+ if (path == NULL) {
+ ret = ERR_SBUS_INVALID_PATH;
+ goto done;
+ }
+ } else {
+ path = object_path;
+ }
+
+ /* Split the string using / as delimiter. */
+ split_on_separator(tmp_ctx, path, '/', true, true, &decomposed, &len);
+
+ /* Unescape parts. */
+ unescaped = talloc_zero_array(tmp_ctx, char *, len + 1);
+ if (unescaped == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ for (i = 0; i < len; i++) {
+ unescaped[i] = sbus_opath_unescape_part(unescaped, decomposed[i]);
+ if (unescaped[i] == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+ }
+
+ if (_components != NULL) {
+ *_components = talloc_steal(mem_ctx, unescaped);
+ }
+
+ if (_len != NULL) {
+ *_len = len;
+ }
+
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+errno_t
+sbus_opath_decompose_exact(TALLOC_CTX *mem_ctx,
+ const char *object_path,
+ const char *prefix,
+ size_t expected,
+ char ***_components)
+{
+ char **components;
+ size_t len;
+ errno_t ret;
+
+ ret = sbus_opath_decompose(mem_ctx, object_path, prefix,
+ &components, &len);
+ if (ret != EOK) {
+ return ret;
+ }
+
+ if (len != expected) {
+ talloc_free(components);
+ return ERR_SBUS_INVALID_PATH;
+ }
+
+ if (_components != NULL) {
+ *_components = components;
+ }
+
+ return EOK;
+}
+
const char *
sbus_opath_strip_prefix(const char *object_path,
const char *prefix)