diff options
author | Pavel Březina <pbrezina@redhat.com> | 2014-12-16 15:19:05 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-01-23 21:45:38 +0100 |
commit | 3a8f6b575f4019f21c9425a26f1b346c08a197ae (patch) | |
tree | e640b5e6302b48b38ef3a3172f1e58a3500a74ff /src/responder/ifp | |
parent | 51d65c4ad15c2cc23f38fa09dd6efeb15e4f3e86 (diff) | |
download | sssd-3a8f6b575f4019f21c9425a26f1b346c08a197ae.tar.gz sssd-3a8f6b575f4019f21c9425a26f1b346c08a197ae.tar.xz sssd-3a8f6b575f4019f21c9425a26f1b346c08a197ae.zip |
sbus: move common opath functions from ifp to sbus code
These functions are quite general thus they may be part
of sbus interface.
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/responder/ifp')
-rw-r--r-- | src/responder/ifp/ifp_components.c | 14 | ||||
-rw-r--r-- | src/responder/ifp/ifp_domains.c | 14 | ||||
-rw-r--r-- | src/responder/ifp/ifp_private.h | 11 | ||||
-rw-r--r-- | src/responder/ifp/ifpsrv_util.c | 181 |
4 files changed, 14 insertions, 206 deletions
diff --git a/src/responder/ifp/ifp_components.c b/src/responder/ifp/ifp_components.c index 2b76a480d..5847a767d 100644 --- a/src/responder/ifp/ifp_components.c +++ b/src/responder/ifp/ifp_components.c @@ -97,11 +97,11 @@ static errno_t check_and_get_component_from_path(TALLOC_CTX *mem_ctx, type = COMPONENT_MONITOR; name = "monitor"; } else { - name = ifp_path_strip_prefix(path, PATH_RESPONDERS "/"); + name = sbus_opath_strip_prefix(path, PATH_RESPONDERS "/"); if (name != NULL) { type = COMPONENT_RESPONDER; } else { - name = ifp_path_strip_prefix(path, PATH_BACKENDS "/"); + name = sbus_opath_strip_prefix(path, PATH_BACKENDS "/"); if (name != NULL) { type = COMPONENT_BACKEND; } else { @@ -116,7 +116,7 @@ static errno_t check_and_get_component_from_path(TALLOC_CTX *mem_ctx, goto done; } - safe_name = ifp_bus_path_unescape(mem_ctx, name); + safe_name = sbus_opath_unescape_part(mem_ctx, name); if (safe_name == NULL) { ret = ENOMEM; goto done; @@ -236,7 +236,7 @@ static errno_t list_responders(TALLOC_CTX *mem_ctx, } for (i = 0; i < num; i++) { - list[i] = ifp_reply_objpath(list, PATH_RESPONDERS, svc[i]); + list[i] = sbus_opath_compose(list, PATH_RESPONDERS, svc[i]); if (list[i] == NULL) { ret = ENOMEM; goto done; @@ -286,7 +286,7 @@ static errno_t list_backends(TALLOC_CTX *mem_ctx, } for (i = 0; i < num; i++) { - list[i] = ifp_reply_objpath(list, PATH_BACKENDS, names[i]); + list[i] = sbus_opath_compose(list, PATH_BACKENDS, names[i]); if (list[i] == NULL) { ret = ENOMEM; goto done; @@ -418,7 +418,7 @@ int ifp_find_responder_by_name(struct sbus_request *dbus_req, const char *result = NULL; if (responder_exists(arg_name)) { - result = ifp_reply_objpath(dbus_req, PATH_RESPONDERS, arg_name); + result = sbus_opath_compose(dbus_req, PATH_RESPONDERS, arg_name); if (result == NULL) { return sbus_request_fail_and_finish(dbus_req, NULL); } @@ -448,7 +448,7 @@ int ifp_find_backend_by_name(struct sbus_request *dbus_req, } if (backend_exists(ctx->rctx->cdb, arg_name)) { - result = ifp_reply_objpath(dbus_req, PATH_BACKENDS, arg_name); + result = sbus_opath_compose(dbus_req, PATH_BACKENDS, arg_name); if (result == NULL) { return sbus_request_fail_and_finish(dbus_req, NULL); } diff --git a/src/responder/ifp/ifp_domains.c b/src/responder/ifp/ifp_domains.c index 1841cbe58..0af81af81 100644 --- a/src/responder/ifp/ifp_domains.c +++ b/src/responder/ifp/ifp_domains.c @@ -125,7 +125,7 @@ static void ifp_list_domains_process(struct tevent_req *req) for (dom = ireq->ifp_ctx->rctx->domains; dom != NULL; dom = get_next_domain(dom, true)) { - p = ifp_reply_objpath(ireq, INFOPIPE_DOMAIN_PATH_PFX, dom->name); + p = sbus_opath_compose(ireq, INFOPIPE_DOMAIN_PATH_PFX, dom->name); if (p == NULL) { DEBUG(SSSDBG_MINOR_FAILURE, "Could not create path for dom %s, skipping\n", dom->name); @@ -234,7 +234,7 @@ static void ifp_find_domain_by_name_process(struct tevent_req *req) return; } - path = ifp_reply_objpath(ireq, INFOPIPE_DOMAIN_PATH_PFX, iter->name); + path = sbus_opath_compose(ireq, INFOPIPE_DOMAIN_PATH_PFX, iter->name); if (path == NULL) { DEBUG(SSSDBG_MINOR_FAILURE, "Could not create path for domain %s, skipping\n", iter->name); @@ -263,13 +263,13 @@ get_domain_info_from_req(struct sbus_request *dbus_req, void *data) return NULL; } - raw_name = ifp_path_strip_prefix(dbus_req->path, - INFOPIPE_DOMAIN_PATH_PFX "/"); + raw_name = sbus_opath_strip_prefix(dbus_req->path, + INFOPIPE_DOMAIN_PATH_PFX "/"); if (raw_name == NULL) { return NULL; } - name = ifp_bus_path_unescape(dbus_req, raw_name); + name = sbus_opath_unescape_part(dbus_req, raw_name); if (name == NULL) { return NULL; } @@ -536,6 +536,6 @@ void ifp_dom_get_parent_domain(struct sbus_request *dbus_req, return; } - *_out = ifp_reply_objpath(dbus_req, INFOPIPE_DOMAIN_PATH_PFX, - dom->parent->name); + *_out = sbus_opath_compose(dbus_req, INFOPIPE_DOMAIN_PATH_PFX, + dom->parent->name); } diff --git a/src/responder/ifp/ifp_private.h b/src/responder/ifp/ifp_private.h index fb1639c8d..676544fad 100644 --- a/src/responder/ifp/ifp_private.h +++ b/src/responder/ifp/ifp_private.h @@ -68,17 +68,6 @@ errno_t ifp_req_create(struct sbus_request *dbus_req, /* Returns an appropriate DBus error for specific ifp_req_create failures */ int ifp_req_create_handle_failure(struct sbus_request *dbus_req, errno_t err); -const char *ifp_path_strip_prefix(const char *path, const char *prefix); - -char *ifp_bus_path_unescape(TALLOC_CTX *mem_ctx, const char *path); -char *ifp_bus_path_escape(TALLOC_CTX *mem_ctx, const char *path); - -char *_ifp_reply_objpath(TALLOC_CTX *mem_ctx, const char *base, - const char *part, ...); - -#define ifp_reply_objpath(mem_ctx, base, ...) \ - _ifp_reply_objpath(mem_ctx, base, ##__VA_ARGS__, NULL) - errno_t ifp_add_ldb_el_to_dict(DBusMessageIter *iter_dict, struct ldb_message_element *el); const char **ifp_parse_attr_list(TALLOC_CTX *mem_ctx, const char *conf_str); diff --git a/src/responder/ifp/ifpsrv_util.c b/src/responder/ifp/ifpsrv_util.c index 909bc5487..b6a0b168b 100644 --- a/src/responder/ifp/ifpsrv_util.c +++ b/src/responder/ifp/ifpsrv_util.c @@ -97,187 +97,6 @@ int ifp_req_create_handle_failure(struct sbus_request *dbus_req, errno_t err) "Cannot create IFP request\n")); } -const char *ifp_path_strip_prefix(const char *path, const char *prefix) -{ - if (strncmp(path, prefix, strlen(prefix)) == 0) { - return path + strlen(prefix); - } - - return NULL; -} - -/* The following path related functions are based on similar code in - * storaged, just tailored to use talloc instead of glib - */ -char *ifp_bus_path_escape(TALLOC_CTX *mem_ctx, const char *path) -{ - size_t n; - char *safe_path = NULL; - TALLOC_CTX *tmp_ctx = NULL; - - /* The path must be valid */ - if (path == NULL) { - return NULL; - } - - tmp_ctx = talloc_new(NULL); - if (tmp_ctx == NULL) { - return NULL; - } - - safe_path = talloc_strdup(tmp_ctx, ""); - if (safe_path == NULL) { - goto done; - } - - /* Special case for an empty string */ - if (strcmp(path, "") == 0) { - /* the for loop would just fall through */ - safe_path = talloc_asprintf_append_buffer(safe_path, "_"); - } - - for (n = 0; path[n]; n++) { - int c = path[n]; - /* D-Bus spec says: - * * - * * Each element must only contain the ASCII characters - * "[A-Z][a-z][0-9]_" - * */ - if ((c >= 'A' && c <= 'Z') - || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9')) { - safe_path = talloc_asprintf_append_buffer(safe_path, "%c", c); - if (safe_path == NULL) { - goto done; - } - } else { - safe_path = talloc_asprintf_append_buffer(safe_path, "_%02x", c); - if (safe_path == NULL) { - goto done; - } - } - } - - safe_path = talloc_steal(mem_ctx, safe_path); -done: - talloc_free(tmp_ctx); - return safe_path; -} - -static inline int unhexchar(char c) -{ - if (c >= '0' && c <= '9') { - return c - '0'; - } - - if (c >= 'a' && c <= 'f') { - return c - 'a' + 10; - } - - if (c >= 'A' && c <= 'F') { - return c - 'A' + 10; - } - - return -1; -} - -char *ifp_bus_path_unescape(TALLOC_CTX *mem_ctx, const char *path) -{ - char *safe_path; - const char *p; - int a, b, c; - TALLOC_CTX *tmp_ctx = NULL; - - tmp_ctx = talloc_new(NULL); - if (tmp_ctx == NULL) { - return NULL; - } - - safe_path = talloc_strdup(tmp_ctx, ""); - if (safe_path == NULL) { - goto done; - } - - /* Special case for the empty string */ - if (strcmp(path, "_") == 0) { - safe_path = talloc_steal(mem_ctx, safe_path); - goto done; - } - - for (p = path; *p; p++) { - if (*p == '_') { - /* There must be at least two more chars after underscore */ - if (p[1] == '\0' || p[2] == '\0') { - safe_path = NULL; - goto done; - } - - if ((a = unhexchar(p[1])) < 0 - || (b = unhexchar(p[2])) < 0) { - /* Invalid escape code, let's take it literal then */ - c = '_'; - } else { - c = ((a << 4) | b); - p += 2; - } - } else { - c = *p; - } - - safe_path = talloc_asprintf_append_buffer(safe_path, "%c", c); - if (safe_path == NULL) { - goto done; - } - } - - safe_path = talloc_steal(mem_ctx, safe_path); -done: - talloc_free(tmp_ctx); - return safe_path; -} - -char * -_ifp_reply_objpath(TALLOC_CTX *mem_ctx, const char *base, - const char *part, ...) -{ - char *safe_part; - char *path = NULL; - va_list va; - - if (base == NULL) { - DEBUG(SSSDBG_OP_FAILURE, "Wrong object path base!\n"); - return NULL; - } - - path = talloc_strdup(mem_ctx, base); - if (path == NULL) return NULL; - - va_start(va, part); - while (part != NULL) { - safe_part = ifp_bus_path_escape(mem_ctx, part); - if (safe_part == NULL) { - DEBUG(SSSDBG_OP_FAILURE, "Could not add [%s] to objpath\n", part); - goto fail; - } - - path = talloc_asprintf_append(path, "/%s", safe_part); - talloc_free(safe_part); - if (path == NULL) { - goto fail; - } - - part = va_arg(va, const char *); - } - va_end(va); - - return path; - -fail: - va_end(va); - talloc_free(path); - return NULL; -} - errno_t ifp_add_ldb_el_to_dict(DBusMessageIter *iter_dict, struct ldb_message_element *el) { |