>From 8de3596be268fdcb3c753d616b65a77226fa9760 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 23 May 2013 01:15:02 +0200 Subject: [PATCH 04/15] LDAP: Pass in a connection to ID functions Instead of using the default connection from the sdap_id_ctx, allow the caller to specify which connection shall be used for this particular request. Again, no functional change is present in this patch, just another parameter is added. --- src/providers/ad/ad_id.c | 2 +- src/providers/ipa/ipa_id.c | 2 +- src/providers/ldap/ldap_common.h | 10 +++-- src/providers/ldap/ldap_id.c | 59 ++++++++++++++++++++---------- src/providers/ldap/ldap_id_netgroup.c | 11 ++++-- src/providers/ldap/ldap_id_services.c | 5 ++- src/providers/ldap/sdap_async.h | 1 + src/providers/ldap/sdap_async_initgroups.c | 5 ++- 8 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/providers/ad/ad_id.c b/src/providers/ad/ad_id.c index f6e975e113c87461952bc435d0823b48a881c945..5d8c78371a2e91fbec554a2a90d424d758ffd1a2 100644 --- a/src/providers/ad/ad_id.c +++ b/src/providers/ad/ad_id.c @@ -34,7 +34,7 @@ ad_account_info_handler(struct be_req *be_req) struct ad_id_ctx); sdap_id_ctx = ad_ctx->sdap_id_ctx; - return sdap_handle_account_info(be_req, sdap_id_ctx); + return sdap_handle_account_info(be_req, sdap_id_ctx, sdap_id_ctx->conn); } void diff --git a/src/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c index b7ae81f6629b922b252b6f2cfb4d566a6c207947..b11abaa7dbdfdae119d9ec18e1d53538b5382259 100644 --- a/src/providers/ipa/ipa_id.c +++ b/src/providers/ipa/ipa_id.c @@ -97,7 +97,7 @@ void ipa_account_info_handler(struct be_req *breq) } else { /* any account request is handled by sdap, * any invalid request is caught there. */ - return sdap_handle_account_info(breq, ctx); + return sdap_handle_account_info(breq, ctx, ctx->conn); } if (!req) { diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h index c1b62f727af98dda23833954d9fd05a13214b363..dbf6c7d59cc0a2006920717e3f733fc123fd3cb7 100644 --- a/src/providers/ldap/ldap_common.h +++ b/src/providers/ldap/ldap_common.h @@ -94,14 +94,16 @@ errno_t sdap_reinit_cleanup_recv(struct tevent_req *req); /* id */ void sdap_account_info_handler(struct be_req *breq); -void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx); +void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn); int sdap_id_setup_tasks(struct sdap_id_ctx *ctx); struct tevent_req * sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, struct be_req *breq, struct be_acct_req *ar, - struct sdap_id_ctx *id_ctx); + struct sdap_id_ctx *id_ctx, + struct sdap_id_conn_ctx *conn); errno_t sdap_handle_acct_req_recv(struct tevent_req *req, int *_dp_error, const char **_err); @@ -173,15 +175,16 @@ void sdap_mark_offline(struct sdap_id_ctx *ctx); struct tevent_req *groups_get_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn, const char *name, int filter_type, int attrs_type); int groups_get_recv(struct tevent_req *req, int *dp_error_out); - struct tevent_req *ldap_netgroup_get_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn, const char *name); int ldap_netgroup_get_recv(struct tevent_req *req, int *dp_error_out); @@ -189,6 +192,7 @@ struct tevent_req * services_get_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct sdap_id_ctx *id_ctx, + struct sdap_id_conn_ctx *conn, const char *name, const char *protocol, int filter_type); diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c index 38f5529b68b574f9621a26bd30f5c3a58469daba..3aeffa83954ae0d058fbe47f9859507c60597f1e 100644 --- a/src/providers/ldap/ldap_id.c +++ b/src/providers/ldap/ldap_id.c @@ -39,6 +39,7 @@ struct users_get_state { struct tevent_context *ev; struct sdap_id_ctx *ctx; + struct sdap_id_conn_ctx *conn; struct sdap_id_op *op; struct sysdb_ctx *sysdb; struct sss_domain_info *domain; @@ -59,6 +60,7 @@ static void users_get_done(struct tevent_req *subreq); struct tevent_req *users_get_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn, const char *name, int filter_type, int attrs_type) @@ -78,9 +80,10 @@ struct tevent_req *users_get_send(TALLOC_CTX *memctx, state->ev = ev; state->ctx = ctx; + state->conn = conn; state->dp_error = DP_ERR_FATAL; - state->op = sdap_id_op_create(state, state->ctx->conn->conn_cache); + state->op = sdap_id_op_create(state, state->conn->conn_cache); if (!state->op) { DEBUG(2, ("sdap_id_op_create failed\n")); ret = ENOMEM; @@ -360,6 +363,7 @@ int users_get_recv(struct tevent_req *req, int *dp_error_out) struct groups_get_state { struct tevent_context *ev; struct sdap_id_ctx *ctx; + struct sdap_id_conn_ctx *conn; struct sdap_id_op *op; struct sysdb_ctx *sysdb; struct sss_domain_info *domain; @@ -380,6 +384,7 @@ static void groups_get_done(struct tevent_req *subreq); struct tevent_req *groups_get_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn, const char *name, int filter_type, int attrs_type) @@ -401,9 +406,10 @@ struct tevent_req *groups_get_send(TALLOC_CTX *memctx, state->ev = ev; state->ctx = ctx; + state->conn = conn; state->dp_error = DP_ERR_FATAL; - state->op = sdap_id_op_create(state, state->ctx->conn->conn_cache); + state->op = sdap_id_op_create(state, state->conn->conn_cache); if (!state->op) { DEBUG(2, ("sdap_id_op_create failed\n")); ret = ENOMEM; @@ -671,6 +677,7 @@ int groups_get_recv(struct tevent_req *req, int *dp_error_out) struct groups_by_user_state { struct tevent_context *ev; struct sdap_id_ctx *ctx; + struct sdap_id_conn_ctx *conn; struct sdap_id_op *op; const char *name; const char **attrs; @@ -685,6 +692,7 @@ static void groups_by_user_done(struct tevent_req *subreq); static struct tevent_req *groups_by_user_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn, const char *name) { struct tevent_req *req; @@ -697,8 +705,9 @@ static struct tevent_req *groups_by_user_send(TALLOC_CTX *memctx, state->ev = ev; state->ctx = ctx; state->dp_error = DP_ERR_FATAL; + state->conn = conn; - state->op = sdap_id_op_create(state, state->ctx->conn->conn_cache); + state->op = sdap_id_op_create(state, state->conn->conn_cache); if (!state->op) { DEBUG(2, ("sdap_id_op_create failed\n")); ret = ENOMEM; @@ -762,6 +771,7 @@ static void groups_by_user_connect_done(struct tevent_req *subreq) state->ev, sdap_id_op_handle(state->op), state->ctx, + state->conn, state->name, state->attrs); if (!subreq) { @@ -971,11 +981,13 @@ static void sdap_check_online_reinit_done(struct tevent_req *req) /* FIXME: embed this function in sssd_be and only call out * specific functions from modules ? */ -void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx); +void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn); static struct tevent_req *get_user_and_group_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn, const char *name, int filter_type, int attrs_type); @@ -991,7 +1003,7 @@ void sdap_account_info_handler(struct be_req *breq) return sdap_handler_done(breq, DP_ERR_FATAL, EINVAL, "Invalid request data\n"); } - return sdap_handle_account_info(breq, ctx); + return sdap_handle_account_info(breq, ctx, ctx->conn); } /* A generic LDAP account info handler */ @@ -1008,7 +1020,8 @@ struct tevent_req * sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, struct be_req *breq, struct be_acct_req *ar, - struct sdap_id_ctx *id_ctx) + struct sdap_id_ctx *id_ctx, + struct sdap_id_conn_ctx *conn) { struct tevent_req *req; struct tevent_req *subreq; @@ -1044,7 +1057,7 @@ sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, goto done; } - subreq = users_get_send(breq, be_ctx->ev, id_ctx, + subreq = users_get_send(breq, be_ctx->ev, id_ctx, conn, ar->filter_value, ar->filter_type, ar->attr_type); @@ -1061,7 +1074,7 @@ sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, goto done; } - subreq = groups_get_send(breq, be_ctx->ev, id_ctx, + subreq = groups_get_send(breq, be_ctx->ev, id_ctx, conn, ar->filter_value, ar->filter_type, ar->attr_type); @@ -1079,7 +1092,7 @@ sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, goto done; } - subreq = groups_by_user_send(breq, be_ctx->ev, id_ctx, + subreq = groups_by_user_send(breq, be_ctx->ev, id_ctx, conn, ar->filter_value); break; @@ -1090,7 +1103,7 @@ sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, goto done; } - subreq = ldap_netgroup_get_send(breq, be_ctx->ev, id_ctx, + subreq = ldap_netgroup_get_send(breq, be_ctx->ev, id_ctx, conn, ar->filter_value); break; @@ -1110,7 +1123,7 @@ sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, goto done; } - subreq = services_get_send(breq, be_ctx->ev, id_ctx, + subreq = services_get_send(breq, be_ctx->ev, id_ctx, conn, ar->filter_value, ar->extra_value, ar->filter_type); @@ -1123,7 +1136,7 @@ sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, goto done; } - subreq = get_user_and_group_send(breq, be_ctx->ev, id_ctx, + subreq = get_user_and_group_send(breq, be_ctx->ev, id_ctx, conn, ar->filter_value, ar->filter_type, ar->attr_type); @@ -1137,7 +1150,7 @@ sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, goto done; } - subreq = get_user_and_group_send(breq, be_ctx->ev, id_ctx, + subreq = get_user_and_group_send(breq, be_ctx->ev, id_ctx, conn, ar->filter_value, ar->filter_type, ar->attr_type); @@ -1243,7 +1256,8 @@ sdap_handle_acct_req_recv(struct tevent_req *req, static void sdap_account_info_complete(struct tevent_req *req); -void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx) +void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn) { struct be_acct_req *ar; struct tevent_req *req; @@ -1258,7 +1272,7 @@ void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx) EINVAL, "Invalid private data"); } - req = sdap_handle_acct_req_send(breq, breq, ar, ctx); + req = sdap_handle_acct_req_send(breq, breq, ar, ctx, conn); if (req == NULL) { return sdap_handler_done(breq, DP_ERR_FATAL, ENOMEM, "Out of memory"); } @@ -1297,6 +1311,7 @@ static void sdap_account_info_complete(struct tevent_req *req) struct get_user_and_group_state { struct tevent_context *ev; struct sdap_id_ctx *id_ctx; + struct sdap_id_conn_ctx *conn; struct sdap_id_op *op; struct sysdb_ctx *sysdb; struct sss_domain_info *domain; @@ -1317,6 +1332,7 @@ static void get_user_and_group_groups_done(struct tevent_req *subreq); static struct tevent_req *get_user_and_group_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_id_ctx *id_ctx, + struct sdap_id_conn_ctx *conn, const char *filter_val, int filter_type, int attrs_type) @@ -1334,9 +1350,10 @@ static struct tevent_req *get_user_and_group_send(TALLOC_CTX *memctx, state->ev = ev; state->id_ctx = id_ctx; + state->conn = conn; state->dp_error = DP_ERR_FATAL; - state->op = sdap_id_op_create(state, state->id_ctx->conn->conn_cache); + state->op = sdap_id_op_create(state, state->conn->conn_cache); if (!state->op) { DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed\n")); ret = ENOMEM; @@ -1349,8 +1366,9 @@ static struct tevent_req *get_user_and_group_send(TALLOC_CTX *memctx, state->filter_type = filter_type; state->attrs_type = attrs_type; - subreq = users_get_send(req, state->ev, state->id_ctx, state->filter_val, - state->filter_type, state->attrs_type); + subreq = users_get_send(req, state->ev, state->id_ctx, state->conn, + state->filter_val, state->filter_type, + state->attrs_type); if (subreq == NULL) { DEBUG(SSSDBG_OP_FAILURE, ("users_get_send failed.\n")); ret = ENOMEM; @@ -1386,8 +1404,9 @@ static void get_user_and_group_users_done(struct tevent_req *subreq) return; } - subreq = groups_get_send(req, state->ev, state->id_ctx, state->filter_val, - state->filter_type, state->attrs_type); + subreq = groups_get_send(req, state->ev, state->id_ctx, state->conn, + state->filter_val, state->filter_type, + state->attrs_type); if (subreq == NULL) { DEBUG(SSSDBG_OP_FAILURE, ("groups_get_send failed.\n")); tevent_req_error(req, ENOMEM); diff --git a/src/providers/ldap/ldap_id_netgroup.c b/src/providers/ldap/ldap_id_netgroup.c index 6788a52e52fdc11663f8a264717cceb3145d6f34..5f44c0a9b195500c566c7c20e2ae16c661102f85 100644 --- a/src/providers/ldap/ldap_id_netgroup.c +++ b/src/providers/ldap/ldap_id_netgroup.c @@ -34,6 +34,7 @@ struct ldap_netgroup_get_state { struct tevent_context *ev; struct sdap_id_ctx *ctx; struct sdap_id_op *op; + struct sdap_id_conn_ctx *conn; struct sysdb_ctx *sysdb; struct sss_domain_info *domain; @@ -54,9 +55,10 @@ static void ldap_netgroup_get_connect_done(struct tevent_req *subreq); static void ldap_netgroup_get_done(struct tevent_req *subreq); struct tevent_req *ldap_netgroup_get_send(TALLOC_CTX *memctx, - struct tevent_context *ev, - struct sdap_id_ctx *ctx, - const char *name) + struct tevent_context *ev, + struct sdap_id_ctx *ctx, + struct sdap_id_conn_ctx *conn, + const char *name) { struct tevent_req *req; struct ldap_netgroup_get_state *state; @@ -68,9 +70,10 @@ struct tevent_req *ldap_netgroup_get_send(TALLOC_CTX *memctx, state->ev = ev; state->ctx = ctx; + state->conn = conn; state->dp_error = DP_ERR_FATAL; - state->op = sdap_id_op_create(state, state->ctx->conn->conn_cache); + state->op = sdap_id_op_create(state, state->conn->conn_cache); if (!state->op) { DEBUG(2, ("sdap_id_op_create failed\n")); ret = ENOMEM; diff --git a/src/providers/ldap/ldap_id_services.c b/src/providers/ldap/ldap_id_services.c index 5c3c53f2a6bea73eb26e43e00cb4dca723660c9d..2a3f104c7383144383f2411f2d5dc664f45d3779 100644 --- a/src/providers/ldap/ldap_id_services.c +++ b/src/providers/ldap/ldap_id_services.c @@ -36,6 +36,7 @@ struct sdap_services_get_state { struct sdap_id_op *op; struct sysdb_ctx *sysdb; struct sss_domain_info *domain; + struct sdap_id_conn_ctx *conn; const char *name; const char *protocol; @@ -59,6 +60,7 @@ struct tevent_req * services_get_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct sdap_id_ctx *id_ctx, + struct sdap_id_conn_ctx *conn, const char *name, const char *protocol, int filter_type) @@ -75,6 +77,7 @@ services_get_send(TALLOC_CTX *mem_ctx, state->ev = ev; state->id_ctx = id_ctx; + state->conn = conn; state->dp_error = DP_ERR_FATAL; state->sysdb = id_ctx->be->domain->sysdb; state->domain = state->id_ctx->be->domain; @@ -82,7 +85,7 @@ services_get_send(TALLOC_CTX *mem_ctx, state->protocol = protocol; state->filter_type = filter_type; - state->op = sdap_id_op_create(state, state->id_ctx->conn->conn_cache); + state->op = sdap_id_op_create(state, state->conn->conn_cache); if (!state->op) { DEBUG(SSSDBG_MINOR_FAILURE, ("sdap_id_op_create failed\n")); ret = ENOMEM; diff --git a/src/providers/ldap/sdap_async.h b/src/providers/ldap/sdap_async.h index eedf8a706edadac437fadc80df7af4c4066bab2a..38c8302dc2afe81539e6b3dda0e840ad523f0178 100644 --- a/src/providers/ldap/sdap_async.h +++ b/src/providers/ldap/sdap_async.h @@ -117,6 +117,7 @@ struct tevent_req *sdap_get_initgr_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_handle *sh, struct sdap_id_ctx *id_ctx, + struct sdap_id_conn_ctx *conn, const char *name, const char **grp_attrs); int sdap_get_initgr_recv(struct tevent_req *req); diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c index 5a6ba02851be1534cebe7e604573f61a80a62b38..57193f71d28e5d908b258782af4062c59499fb77 100644 --- a/src/providers/ldap/sdap_async_initgroups.c +++ b/src/providers/ldap/sdap_async_initgroups.c @@ -2510,6 +2510,7 @@ struct sdap_get_initgr_state { struct sss_domain_info *dom; struct sdap_handle *sh; struct sdap_id_ctx *id_ctx; + struct sdap_id_conn_ctx *conn; const char *name; const char **grp_attrs; const char **user_attrs; @@ -2531,6 +2532,7 @@ struct tevent_req *sdap_get_initgr_send(TALLOC_CTX *memctx, struct tevent_context *ev, struct sdap_handle *sh, struct sdap_id_ctx *id_ctx, + struct sdap_id_conn_ctx *conn, const char *name, const char **grp_attrs) { @@ -2550,6 +2552,7 @@ struct tevent_req *sdap_get_initgr_send(TALLOC_CTX *memctx, state->dom = id_ctx->be->domain; state->sh = sh; state->id_ctx = id_ctx; + state->conn = conn; state->name = name; state->grp_attrs = grp_attrs; state->orig_user = NULL; @@ -2947,7 +2950,7 @@ static void sdap_get_initgr_done(struct tevent_req *subreq) goto fail; } - subreq = groups_get_send(req, state->ev, state->id_ctx, gid, + subreq = groups_get_send(req, state->ev, state->id_ctx, state->conn, gid, BE_FILTER_IDNUM, BE_ATTR_ALL); if (!subreq) { ret = ENOMEM; -- 1.8.2.1