From de3a63c4b8e55ae2dbd3fbf12ca868c854ed8052 Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Aug 13 2018 15:00:00 +0000 Subject: sbus: convert proxy provider Reviewed-by: Jakub Hrozek --- diff --git a/Makefile.am b/Makefile.am index f51404a..671ec2f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -832,7 +832,6 @@ dist_noinst_HEADERS = \ src/providers/ad/ad_domain_info.h \ src/providers/ad/ad_subdomains.h \ src/providers/proxy/proxy.h \ - src/providers/proxy/proxy_iface_generated.h \ src/providers/files/files_private.h \ src/tools/tools_util.h \ src/tools/sss_sync_ops.h \ @@ -4263,7 +4262,6 @@ libsss_proxy_la_SOURCES = \ src/providers/proxy/proxy_netgroup.c \ src/providers/proxy/proxy_services.c \ src/providers/proxy/proxy_auth.c \ - src/providers/proxy/proxy_iface_generated.c \ $(NULL) libsss_proxy_la_CFLAGS = \ $(AM_CFLAGS) @@ -4276,6 +4274,7 @@ libsss_proxy_la_LIBADD = \ $(DHASH_LIBS) \ $(DBUS_LIBS) \ $(SSSD_INTERNAL_LTLIBS) \ + libsss_iface.la \ $(NULL) libsss_proxy_la_LDFLAGS = \ -avoid-version \ @@ -4589,7 +4588,6 @@ gpo_child_LDADD = \ proxy_child_SOURCES = \ src/providers/proxy/proxy_child.c \ - src/providers/proxy/proxy_iface_generated.c \ $(NULL) proxy_child_CFLAGS = \ $(AM_CFLAGS) \ @@ -4598,7 +4596,7 @@ proxy_child_LDADD = \ $(PAM_LIBS) \ $(SSSD_LIBS) \ $(SSSD_INTERNAL_LTLIBS) \ - libsss_sbus_old.la + libsss_iface.la p11_child_SOURCES = \ src/p11_child/p11_child_common.c \ diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h index 8bfdf0e..a0a21cc 100644 --- a/src/providers/data_provider.h +++ b/src/providers/data_provider.h @@ -41,8 +41,8 @@ #include "confdb/confdb.h" #include "sss_client/sss_cli.h" #include "util/authtok.h" +#include "util/sss_pam_data.h" #include "providers/data_provider_req.h" -#include "providers/data_provider/dp_pam_data.h" #define DATA_PROVIDER_VERSION 0x0001 #define DATA_PROVIDER_PIPE "private/sbus-dp" diff --git a/src/providers/data_provider/dp_target_auth.c b/src/providers/data_provider/dp_target_auth.c index 571ee66..02179dd 100644 --- a/src/providers/data_provider/dp_target_auth.c +++ b/src/providers/data_provider/dp_target_auth.c @@ -24,10 +24,10 @@ #include #include "sbus/sbus_request.h" -#include "providers/data_provider/dp_pam_data.h" #include "providers/data_provider/dp_private.h" #include "providers/data_provider/dp_iface.h" #include "providers/backend.h" +#include "util/sss_pam_data.h" #include "util/util.h" static void choose_target(struct data_provider *provider, diff --git a/src/providers/proxy/proxy.h b/src/providers/proxy/proxy.h index 67e1c55..56ad5d4 100644 --- a/src/providers/proxy/proxy.h +++ b/src/providers/proxy/proxy.h @@ -41,6 +41,7 @@ #include "db/sysdb.h" #include "sss_client/nss_compat.h" #include +#include "sss_iface/sss_iface_async.h" #define PROXY_CHILD_PATH "/org/freedesktop/sssd/proxychild" @@ -187,6 +188,8 @@ errno_t enum_services(struct proxy_id_ctx *ctx, struct sysdb_ctx *sysdb, struct sss_domain_info *dom); -int proxy_client_init(struct sbus_connection *conn, void *data); +errno_t +proxy_client_init(struct sbus_connection *conn, + struct proxy_auth_ctx *auth_ctx); #endif /* __PROXY_H__ */ diff --git a/src/providers/proxy/proxy_auth.c b/src/providers/proxy/proxy_auth.c index d3f87e9..3c5affe 100644 --- a/src/providers/proxy/proxy_auth.c +++ b/src/providers/proxy/proxy_auth.c @@ -25,7 +25,7 @@ #include #include "providers/proxy/proxy.h" -#include "sss_iface/sss_iface.h" +#include "sss_iface/sss_iface_async.h" struct pc_init_ctx; @@ -547,7 +547,7 @@ static struct tevent_req *proxy_pam_conv_send(TALLOC_CTX *mem_ctx, DEBUG_PAM_DATA(SSSDBG_CONF_SETTINGS, pd); subreq = sbus_call_proxy_auth_PAM_send(state, state->conn, sbus_cliname, - SSS_BACKEND_PATH, pd); + SSS_BUS_PATH, pd); if (subreq == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n"); ret = ENOMEM; diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c index 820a78a..134f96f 100644 --- a/src/providers/proxy/proxy_child.c +++ b/src/providers/proxy/proxy_child.c @@ -42,7 +42,7 @@ #include "util/util.h" #include "confdb/confdb.h" #include "providers/proxy/proxy.h" -#include "sss_iface/sss_iface.h" +#include "sss_iface/sss_iface_async.h" #include "providers/backend.h" @@ -349,16 +349,16 @@ proxy_cli_init(struct pc_ctx *ctx) } struct sbus_interface iface = SBUS_INTERFACE( - org_freedesktop_sssd_ProxyChild_Auth, + sssd_ProxyChild_Auth, SBUS_METHODS( - SBUS_SYNC(METHOD, org_freedesktop_sssd_ProxyChild_Auth, PAM, pc_pam_handler, ctx) + SBUS_SYNC(METHOD, sssd_ProxyChild_Auth, PAM, pc_pam_handler, ctx) ), SBUS_SIGNALS(SBUS_NO_SIGNALS), SBUS_PROPERTIES(SBUS_NO_PROPERTIES) ); struct sbus_path paths[] = { - {SSS_BACKEND_PATH, &iface}, + {SSS_BUS_PATH, &iface}, {NULL, NULL} }; @@ -398,7 +398,7 @@ proxy_cli_init(struct pc_ctx *ctx) ctx->id); subreq = sbus_call_proxy_client_Register_send(ctx, ctx->conn, sbus_busname, - SSS_BACKEND_PATH, ctx->id); + SSS_BUS_PATH, ctx->id); if (subreq == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n"); ret = ENOMEM; diff --git a/src/providers/proxy/proxy_client.c b/src/providers/proxy/proxy_client.c index 74957ca..1c325ee 100644 --- a/src/providers/proxy/proxy_client.c +++ b/src/providers/proxy/proxy_client.c @@ -23,60 +23,50 @@ */ #include "util/util.h" -#include "providers/proxy/proxy_iface_generated.h" #include "providers/proxy/proxy.h" +#include "sss_iface/sss_iface_async.h" struct proxy_client { struct proxy_auth_ctx *proxy_auth_ctx; struct sbus_connection *conn; struct tevent_timer *timeout; - bool initialized; }; -static int proxy_client_register(struct sbus_request *sbus_req, - void *data, - uint32_t cli_id) +errno_t +proxy_client_register(TALLOC_CTX *mem_ctx, + struct sbus_request *sbus_req, + struct proxy_auth_ctx *auth_ctx, + uint32_t cli_id) { - struct sbus_connection *conn; struct proxy_client *proxy_cli; - int hret; - hash_key_t key; - hash_value_t value; - struct tevent_req *req; struct proxy_child_ctx *child_ctx; struct pc_init_ctx *init_ctx; + struct tevent_req *req; + hash_value_t value; + hash_key_t key; + int hret; - conn = sbus_req->conn; - proxy_cli = talloc_get_type(data, struct proxy_client); + /* When connection is lost we also free the client. */ + proxy_cli = talloc_zero(sbus_req->conn, struct proxy_client); if (proxy_cli == NULL) { - DEBUG(SSSDBG_FATAL_FAILURE, "Connection holds no valid init data\n"); - return EINVAL; + return ENOMEM; } - /* First thing, cancel the timeout */ - DEBUG(SSSDBG_CONF_SETTINGS, - "Cancel proxy client ID timeout [%p]\n", proxy_cli->timeout); - talloc_zfree(proxy_cli->timeout); - - DEBUG(SSSDBG_FUNC_DATA, "Proxy client [%"PRIu32"] connected\n", cli_id); + proxy_cli->proxy_auth_ctx = auth_ctx; + proxy_cli->conn = sbus_req->conn; - /* Check the hash table */ key.type = HASH_KEY_ULONG; key.ul = cli_id; if (!hash_has_key(proxy_cli->proxy_auth_ctx->request_table, &key)) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Unknown child ID. Killing the connection\n"); - sbus_disconnect(proxy_cli->conn); + talloc_free(proxy_cli); return EIO; } - iface_proxy_client_Register_finish(sbus_req); - hret = hash_lookup(proxy_cli->proxy_auth_ctx->request_table, &key, &value); if (hret != HASH_SUCCESS) { DEBUG(SSSDBG_CRIT_FAILURE, "Hash error [%d]: %s\n", hret, hash_error_string(hret)); - sbus_disconnect(conn); + talloc_free(proxy_cli); return EIO; } @@ -92,86 +82,42 @@ static int proxy_client_register(struct sbus_request *sbus_req, */ DEBUG(SSSDBG_CRIT_FAILURE, "Client connection from a request " "that's not marked as running\n"); + talloc_free(proxy_cli); return EIO; } init_ctx = tevent_req_data(child_ctx->init_req, struct pc_init_ctx); - init_ctx->conn = conn; + init_ctx->conn = sbus_req->conn; tevent_req_done(child_ctx->init_req); child_ctx->init_req = NULL; return EOK; } -static void proxy_client_timeout(struct tevent_context *ev, - struct tevent_timer *te, - struct timeval t, - void *ptr) -{ - struct proxy_client *proxy_cli; - - DEBUG(SSSDBG_OP_FAILURE, - "Client timed out before Identification [%p]!\n", te); - - proxy_cli = talloc_get_type(ptr, struct proxy_client); - - sbus_disconnect(proxy_cli->conn); - talloc_zfree(proxy_cli); - - /* If we time out here, we will also time out to - * pc_init_timeout(), so we'll finish the request - * there. - */ -} - -int proxy_client_init(struct sbus_connection *conn, void *data) +errno_t +proxy_client_init(struct sbus_connection *conn, + struct proxy_auth_ctx *auth_ctx) { - struct proxy_auth_ctx *auth_ctx; - struct proxy_client *proxy_cli; - struct timeval tv; errno_t ret; - static struct iface_proxy_client iface_proxy_client = { - { &iface_proxy_client_meta, 0 }, - - .Register = proxy_client_register, + struct sbus_interface iface = SBUS_INTERFACE( + sssd_ProxyChild_Client, + SBUS_METHODS( + SBUS_SYNC(METHOD, sssd_ProxyChild_Client, Register, proxy_client_register, auth_ctx) + ), + SBUS_SIGNALS(SBUS_NO_SIGNALS), + SBUS_PROPERTIES(SBUS_NO_PROPERTIES) + ); + + struct sbus_path paths[] = { + {SSS_BUS_PATH, &iface}, + {NULL, NULL} }; - auth_ctx = talloc_get_type(data, struct proxy_auth_ctx); - - /* When connection is lost we also free the client. */ - proxy_cli = talloc_zero(conn, struct proxy_client); - if (proxy_cli == NULL) { - DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory, killing connection.\n"); - talloc_free(conn); - return ENOMEM; - } - - proxy_cli->proxy_auth_ctx = auth_ctx; - proxy_cli->conn = conn; - proxy_cli->initialized = false; - - /* Setup timeout in case client fails to register himself in time. */ - tv = tevent_timeval_current_ofs(5, 0); - proxy_cli->timeout = tevent_add_timer(auth_ctx->be->ev, proxy_cli, tv, - proxy_client_timeout, proxy_cli); - if (proxy_cli->timeout == NULL) { - /* Connection is closed in the caller. */ - DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory, killing connection\n"); - return ENOMEM; - } - - DEBUG(SSSDBG_CONF_SETTINGS, - "Set-up proxy client ID timeout [%p]\n", proxy_cli->timeout); - - /* Setup D-Bus interfaces and methods. */ - ret = sbus_conn_register_iface(conn, &iface_proxy_client.vtable, - PROXY_CHILD_PATH, proxy_cli); + ret = sbus_connection_add_path_map(conn, paths); if (ret != EOK) { - /* Connection is closed in the caller. */ - DEBUG(SSSDBG_FATAL_FAILURE, "Unable to register D-Bus interface, " - "killing connection [%d]: %s\n", ret, sss_strerror(ret)); - return ret; + DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add paths [%d]: %s\n", + ret, sss_strerror(ret)); } return ret; diff --git a/src/providers/proxy/proxy_iface.xml b/src/providers/proxy/proxy_iface.xml deleted file mode 100644 index 39b0b03..0000000 --- a/src/providers/proxy/proxy_iface.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/providers/proxy/proxy_iface_generated.c b/src/providers/proxy/proxy_iface_generated.c deleted file mode 100644 index 9fb5b2c..0000000 --- a/src/providers/proxy/proxy_iface_generated.c +++ /dev/null @@ -1,83 +0,0 @@ -/* The following definitions are auto-generated from proxy_iface.xml */ - -#include - -#include "dbus/dbus-protocol.h" -#include "util/util_errors.h" -#include "sbus/sssd_dbus.h" -#include "sbus/sssd_dbus_meta.h" -#include "sbus/sssd_dbus_invokers.h" -#include "proxy_iface_generated.h" - -/* invokes a handler with a 'u' DBus signature */ -static int invoke_u_method(struct sbus_request *dbus_req, void *function_ptr); - -/* arguments for org.freedesktop.sssd.ProxyChild.Client.Register */ -const struct sbus_arg_meta iface_proxy_client_Register__in[] = { - { "ID", "u" }, - { NULL, } -}; - -int iface_proxy_client_Register_finish(struct sbus_request *req) -{ - return sbus_request_return_and_finish(req, - DBUS_TYPE_INVALID); -} - -/* methods for org.freedesktop.sssd.ProxyChild.Client */ -const struct sbus_method_meta iface_proxy_client__methods[] = { - { - "Register", /* name */ - iface_proxy_client_Register__in, - NULL, /* no out_args */ - offsetof(struct iface_proxy_client, Register), - invoke_u_method, - }, - { NULL, } -}; - -/* interface info for org.freedesktop.sssd.ProxyChild.Client */ -const struct sbus_interface_meta iface_proxy_client_meta = { - "org.freedesktop.sssd.ProxyChild.Client", /* name */ - iface_proxy_client__methods, - NULL, /* no signals */ - NULL, /* no properties */ - sbus_invoke_get_all, /* GetAll invoker */ -}; - -/* methods for org.freedesktop.sssd.ProxyChild.Auth */ -const struct sbus_method_meta iface_proxy_auth__methods[] = { - { - "PAM", /* name */ - NULL, /* no in_args */ - NULL, /* no out_args */ - offsetof(struct iface_proxy_auth, PAM), - NULL, /* no invoker */ - }, - { NULL, } -}; - -/* interface info for org.freedesktop.sssd.ProxyChild.Auth */ -const struct sbus_interface_meta iface_proxy_auth_meta = { - "org.freedesktop.sssd.ProxyChild.Auth", /* name */ - iface_proxy_auth__methods, - NULL, /* no signals */ - NULL, /* no properties */ - sbus_invoke_get_all, /* GetAll invoker */ -}; - -/* invokes a handler with a 'u' DBus signature */ -static int invoke_u_method(struct sbus_request *dbus_req, void *function_ptr) -{ - uint32_t arg_0; - int (*handler)(struct sbus_request *, void *, uint32_t) = function_ptr; - - if (!sbus_request_parse_or_finish(dbus_req, - DBUS_TYPE_UINT32, &arg_0, - DBUS_TYPE_INVALID)) { - return EOK; /* request handled */ - } - - return (handler)(dbus_req, dbus_req->intf->handler_data, - arg_0); -} diff --git a/src/providers/proxy/proxy_iface_generated.h b/src/providers/proxy/proxy_iface_generated.h deleted file mode 100644 index 6471eaf..0000000 --- a/src/providers/proxy/proxy_iface_generated.h +++ /dev/null @@ -1,72 +0,0 @@ -/* The following declarations are auto-generated from proxy_iface.xml */ - -#ifndef __PROXY_IFACE_XML__ -#define __PROXY_IFACE_XML__ - -#include "sbus/sssd_dbus.h" -#include "sbus/sssd_dbus_meta.h" - -/* ------------------------------------------------------------------------ - * DBus Constants - * - * Various constants of interface and method names mostly for use by clients - */ - -/* constants for org.freedesktop.sssd.ProxyChild.Client */ -#define IFACE_PROXY_CLIENT "org.freedesktop.sssd.ProxyChild.Client" -#define IFACE_PROXY_CLIENT_REGISTER "Register" - -/* constants for org.freedesktop.sssd.ProxyChild.Auth */ -#define IFACE_PROXY_AUTH "org.freedesktop.sssd.ProxyChild.Auth" -#define IFACE_PROXY_AUTH_PAM "PAM" - -/* ------------------------------------------------------------------------ - * DBus handlers - * - * These structures are filled in by implementors of the different - * dbus interfaces to handle method calls. - * - * Handler functions of type sbus_msg_handler_fn accept raw messages, - * other handlers are typed appropriately. If a handler that is - * set to NULL is invoked it will result in a - * org.freedesktop.DBus.Error.NotSupported error for the caller. - * - * Handlers have a matching xxx_finish() function (unless the method has - * accepts raw messages). These finish functions the - * sbus_request_return_and_finish() with the appropriate arguments to - * construct a valid reply. Once a finish function has been called, the - * @dbus_req it was called with is freed and no longer valid. - */ - -/* vtable for org.freedesktop.sssd.ProxyChild.Client */ -struct iface_proxy_client { - struct sbus_vtable vtable; /* derive from sbus_vtable */ - int (*Register)(struct sbus_request *req, void *data, uint32_t arg_ID); -}; - -/* finish function for Register */ -int iface_proxy_client_Register_finish(struct sbus_request *req); - -/* vtable for org.freedesktop.sssd.ProxyChild.Auth */ -struct iface_proxy_auth { - struct sbus_vtable vtable; /* derive from sbus_vtable */ - sbus_msg_handler_fn PAM; -}; - -/* ------------------------------------------------------------------------ - * DBus Interface Metadata - * - * These structure definitions are filled in with the information about - * the interfaces, methods, properties and so on. - * - * The actual definitions are found in the accompanying C file next - * to this header. - */ - -/* interface info for org.freedesktop.sssd.ProxyChild.Client */ -extern const struct sbus_interface_meta iface_proxy_client_meta; - -/* interface info for org.freedesktop.sssd.ProxyChild.Auth */ -extern const struct sbus_interface_meta iface_proxy_auth_meta; - -#endif /* __PROXY_IFACE_XML__ */ diff --git a/src/providers/proxy/proxy_init.c b/src/providers/proxy/proxy_init.c index c72e364..cf4f82e 100644 --- a/src/providers/proxy/proxy_init.c +++ b/src/providers/proxy/proxy_init.c @@ -213,7 +213,7 @@ static errno_t proxy_init_auth_ctx(TALLOC_CTX *mem_ctx, goto done; } - ret = proxy_setup_sbus(auth_ctx, auth_ctx, be_ctx); + ret = proxy_client_init(dp_sbus_conn(be_ctx->provider), auth_ctx); if (ret != EOK) { goto done; }