diff options
author | Simo Sorce <idra@samba.org> | 2009-01-08 10:43:26 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2009-01-08 10:43:26 -0500 |
commit | 7122f66c144b1837e22adef519103cfd9808db62 (patch) | |
tree | da639d1000b84e3fc0bfe700a1d9126df38e1126 /server/providers | |
parent | 4aa8e6e7085f1498c80881db7f9a5cd2b70228f9 (diff) | |
download | sssd-7122f66c144b1837e22adef519103cfd9808db62.tar.gz sssd-7122f66c144b1837e22adef519103cfd9808db62.tar.bz2 sssd-7122f66c144b1837e22adef519103cfd9808db62.zip |
The code now successfully sends a getpwnam request to a remote LDAP server,
and caches the result in LDAP.
Still chasing a bug that does not let NSS known that the BE was successful.
This makes NSS timeout the client and not return any results yet.
Diffstat (limited to 'server/providers')
-rw-r--r-- | server/providers/data_provider.c | 55 | ||||
-rw-r--r-- | server/providers/data_provider_be.c | 71 | ||||
-rw-r--r-- | server/providers/dp_backend_store.c | 2 | ||||
-rw-r--r-- | server/providers/ldap_provider.c | 15 |
4 files changed, 93 insertions, 50 deletions
diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c index 645c1425..7d282e05 100644 --- a/server/providers/data_provider.c +++ b/server/providers/data_provider.c @@ -115,6 +115,8 @@ static int service_identity(DBusMessage *message, void *data, DBusMessage **r) DBusMessage *reply; dbus_bool_t ret; + DEBUG(4, ("Sending identity data [%s,%d]\n", name, version)); + reply = dbus_message_new_method_return(message); ret = dbus_message_append_args(reply, DBUS_TYPE_STRING, &name, @@ -252,7 +254,7 @@ static int dbus_dp_init(struct sbus_conn_ctx *conn_ctx, void *data) return ENOMEM; } dbret = dbus_connection_send_with_reply(conn, msg, &pending_reply, - -1 /* TODO: set timeout */); + 600000 /* TODO: set timeout */); if (!dbret) { /* * Critical Failure @@ -405,9 +407,9 @@ static void be_got_account_info(DBusPendingCall *pending, void *data) DBusMessage *reply; DBusConnection *conn; DBusError dbus_error; - dbus_uint16_t cli_err_maj; - dbus_uint32_t cli_err_min; - char *cli_err_msg; + dbus_uint16_t err_maj = 0; + dbus_uint32_t err_min = 0; + const char *err_msg; dbus_bool_t ret; int type; @@ -431,21 +433,20 @@ static void be_got_account_info(DBusPendingCall *pending, void *data) switch (type) { case DBUS_MESSAGE_TYPE_METHOD_RETURN: ret = dbus_message_get_args(reply, &dbus_error, - DBUS_TYPE_UINT16, &cli_err_maj, - DBUS_TYPE_UINT32, &cli_err_min, - DBUS_TYPE_STRING, &cli_err_msg, + DBUS_TYPE_UINT16, &err_maj, + DBUS_TYPE_UINT32, &err_min, + DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); if (!ret) { - DEBUG(1,("be_identity_check failed, to parse message, killing connection\n")); + DEBUG(1,("Failed to parse message, killing connection\n")); sbus_disconnect(bereq->be_cli->conn_ctx); goto done; } - /* Set up the destructor for this service */ break; case DBUS_MESSAGE_TYPE_ERROR: - DEBUG(0,("getAccountInfo returned an error [%s], closing connection.\n", + DEBUG(0,("The Data Provider returned an error [%s], closing connection.\n", dbus_message_get_error_name(reply))); /* Falling through to default intentionally*/ default: @@ -459,16 +460,24 @@ static void be_got_account_info(DBusPendingCall *pending, void *data) sbus_disconnect(bereq->be_cli->conn_ctx); } - /* TODO: handle errors !! */ + if (err_maj) { + DEBUG(1, ("Backend returned an error: %d,%d(%s),%s\n", + err_maj, err_min, strerror(err_min), err_msg)); + /* TODO: handle errors !! */ + } + if (bereq->req->pending_replies > 1) { bereq->req->pending_replies--; talloc_free(bereq); } else { conn = sbus_get_connection(bereq->be_cli->conn_ctx); + err_maj = 0; + err_min = 0; + err_msg = "Success"; ret = dbus_message_append_args(bereq->req->reply, - DBUS_TYPE_UINT16, 0, - DBUS_TYPE_UINT32, 0, - DBUS_TYPE_STRING, "Success", + DBUS_TYPE_UINT16, &err_maj, + DBUS_TYPE_UINT32, &err_min, + DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); if (!ret) { DEBUG(1, ("Failed to build reply ... frontend will wait for timeout ...\n")); @@ -509,6 +518,8 @@ static int dp_send_acct_req(struct dp_be_request *bereq, return ENOMEM; } + DEBUG(4, ("Sending request for [%u][%s][%s]\n", type, attrs, filter)); + ret = dbus_message_append_args(msg, DBUS_TYPE_UINT32, &type, DBUS_TYPE_STRING, &attrs, @@ -520,7 +531,7 @@ static int dp_send_acct_req(struct dp_be_request *bereq, } ret = dbus_connection_send_with_reply(conn, msg, &pending_reply, - -1 /* TODO: set timeout */); + 600000 /* TODO: set timeout */); if (!ret) { /* * Critical Failure @@ -577,6 +588,9 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r return EIO; } + DEBUG(4, ("Got request for [%s][%u][%s][%s]\n", + domain, type, attrs, filter)); + reply = dbus_message_new_method_return(message); /* search for domain */ @@ -620,9 +634,10 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r } bereq->req = dpreq; bereq->be_cli = dpbe->dpcli; + DEBUG(4, ("Sending wildcard request to [%s]\n", dpbe->domain)); ret = dp_send_acct_req(bereq, type, attrs, filter); if (ret != EOK) { - DEBUG(2,("Failed to dispatch request to %s", dpbe->domain)); + DEBUG(2,("Failed to dispatch request to %s\n", dpbe->domain)); dpbe = dpbe->next; continue; } @@ -678,7 +693,7 @@ static int dp_get_account_info(DBusMessage *message, void *data, DBusMessage **r ret = dp_send_acct_req(bereq, type, attrs, filter); if (ret != EOK) { - DEBUG(2,("Failed to dispatch request to %s", dpbe->domain)); + DEBUG(2,("Failed to dispatch request to %s\n", dpbe->domain)); dpret = DP_ERR_FATAL; errmsg = "Dispatch Failed"; talloc_free(dpreq); @@ -710,8 +725,7 @@ respond: static int dp_backend_destructor(void *ctx) { struct dp_backend *dpbe = talloc_get_type(ctx, struct dp_backend); - if (dpbe->dpcli && dpbe->dpcli && - dpbe->dpcli->dpctx && dpbe->dpcli->dpctx->be_list) { + if (dpbe->dpcli && dpbe->dpcli->dpctx && dpbe->dpcli->dpctx->be_list) { DLIST_REMOVE(dpbe->dpcli->dpctx->be_list, dpbe); } return 0; @@ -720,8 +734,7 @@ static int dp_backend_destructor(void *ctx) static int dp_frontend_destructor(void *ctx) { struct dp_frontend *dpfe = talloc_get_type(ctx, struct dp_frontend); - if (dpfe->dpcli && dpfe->dpcli && - dpfe->dpcli->dpctx && dpfe->dpcli->dpctx->fe_list) { + if (dpfe->dpcli && dpfe->dpcli->dpctx && dpfe->dpcli->dpctx->fe_list) { DLIST_REMOVE(dpfe->dpcli->dpctx->fe_list, dpfe); } return 0; diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c index 6f3f841f..568fb2ec 100644 --- a/server/providers/data_provider_be.c +++ b/server/providers/data_provider_be.c @@ -187,10 +187,15 @@ static int be_get_account_info(DBusMessage *message, void *data, DBusMessage **r dbus_bool_t dbret; void *user_data; uint32_t type; - char *attrs, *search_exp; + char *attrs, *filter; int attr_type, filter_type; char *filter_val; int ret; + dbus_uint16_t err_maj = 0; + dbus_uint32_t err_min = 0; + const char *err_msg = "Success"; + + *r = NULL; if (!data) return EINVAL; smh_ctx = talloc_get_type(data, struct sbus_message_handler_ctx); @@ -205,45 +210,75 @@ static int be_get_account_info(DBusMessage *message, void *data, DBusMessage **r ret = dbus_message_get_args(message, &dbus_error, DBUS_TYPE_UINT32, &type, DBUS_TYPE_STRING, &attrs, - DBUS_TYPE_STRING, &search_exp, + DBUS_TYPE_STRING, &filter, DBUS_TYPE_INVALID); if (!ret) { DEBUG(1,("Failed, to parse message!\n")); return EIO; } - if (!attrs) { + DEBUG(4, ("Got request for [%u][%s][%s]\n", type, attrs, filter)); + + reply = dbus_message_new_method_return(message); + + if (attrs) { if (strcmp(attrs, "core") == 0) attr_type = BE_ATTR_CORE; else if (strcmp(attrs, "membership") == 0) attr_type = BE_ATTR_MEM; else if (strcmp(attrs, "all") == 0) attr_type = BE_ATTR_ALL; - else return EINVAL; + else { + err_maj = DP_ERR_FATAL; + err_min = EINVAL; + err_msg = "Invalid Attrs Parameter"; + goto done; + } + } else { + err_maj = DP_ERR_FATAL; + err_min = EINVAL; + err_msg = "Missing Attrs Parameter"; + goto done; } - else return EINVAL; - if (!search_exp) { - if (strncmp(search_exp, "name=", 5) == 0) { + if (filter) { + if (strncmp(filter, "name=", 5) == 0) { filter_type = BE_FILTER_NAME; - filter_val = &search_exp[5]; - } else if (strncmp(search_exp, "idnumber=", 9) == 0) { + filter_val = &filter[5]; + } else if (strncmp(filter, "idnumber=", 9) == 0) { filter_type = BE_FILTER_IDNUM; - filter_val = &search_exp[9]; - } else return EINVAL; + filter_val = &filter[9]; + } else { + err_maj = DP_ERR_FATAL; + err_min = EINVAL; + err_msg = "Invalid Filter"; + goto done; + } + } else { + err_maj = DP_ERR_FATAL; + err_min = EINVAL; + err_msg = "Missing Filter Parameter"; + goto done; } - else return EINVAL; /* process request */ ret = ctx->ops->get_account_info(ctx, type, attr_type, filter_type, filter_val); - if (ret != EOK) return ret; + if (ret != EOK) { + err_maj = DP_ERR_FATAL; + err_min = ret; + err_msg = "Backend error"; + goto done; + } - reply = dbus_message_new_method_return(message); +done: dbret = dbus_message_append_args(reply, - DBUS_TYPE_UINT16, 0, - DBUS_TYPE_UINT32, 0, - DBUS_TYPE_STRING, "Success", + DBUS_TYPE_UINT16, &err_maj, + DBUS_TYPE_UINT32, &err_min, + DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); if (!dbret) return EIO; + DEBUG(4, ("Request processed. Returned %d,%d,%s\n", + err_maj, err_min, err_msg)); + *r = reply; return EOK; } @@ -445,7 +480,7 @@ int main(int argc, const char *argv[]) main_ctx->confdb_ctx); if (ret != EOK) return 3; - DEBUG(1, ("Backend provider %s(%s) started!", be_name, be_domain)); + DEBUG(1, ("Backend provider %s(%s) started!\n", be_name, be_domain)); /* loop on main */ server_loop(main_ctx); diff --git a/server/providers/dp_backend_store.c b/server/providers/dp_backend_store.c index e518f438..9bccb218 100644 --- a/server/providers/dp_backend_store.c +++ b/server/providers/dp_backend_store.c @@ -71,7 +71,7 @@ int dp_be_store_account_posix(struct be_ctx *ctx, account_dn, LDB_SCOPE_BASE, "(objectClass=User)", attrs, NULL, res, ldb_search_default_callback, NULL); - if (!lret) { + if (lret != LDB_SUCCESS) { DEBUG(1, ("Failed to build search request (%d) !?\n", lret)); ret = EIO; goto done; diff --git a/server/providers/ldap_provider.c b/server/providers/ldap_provider.c index 884f843e..dd8ac18d 100644 --- a/server/providers/ldap_provider.c +++ b/server/providers/ldap_provider.c @@ -93,16 +93,6 @@ static int get_pw_name(struct be_ctx *be_ctx, struct ldap_ctx *ldap_ctx, char *n return ret; } -static int ldap_check_online(struct be_ctx *be_ctx, int *reply); -static int ldap_get_account_info(struct be_ctx *be_ctx, - int entry_type, int attr_type, - int filter_type, char *filter_value); - -struct be_mod_ops ldap_mod_ops = { - .check_online = ldap_check_online, - .get_account_info = ldap_get_account_info -}; - static int ldap_check_online(struct be_ctx *be_ctx, int *reply) { *reply = MOD_ONLINE; @@ -151,6 +141,11 @@ static int ldap_get_account_info(struct be_ctx *be_ctx, return EOK; } +struct be_mod_ops ldap_mod_ops = { + .check_online = ldap_check_online, + .get_account_info = ldap_get_account_info +}; + int sssm_ldap_init(struct be_ctx *bectx, struct be_mod_ops **ops, void **pvt_data) { struct ldap_ctx *ctx; |