ldap_id.c revision e81deec535d11912b87954c81a1edd768c1386c9
/*
SSSD
LDAP Identity Backend Module
Authors:
Simo Sorce <ssorce@redhat.com>
Copyright (C) 2008 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <time.h>
#include "util/strtonum.h"
#include "providers/ldap/ldap_common.h"
#include "providers/ldap/sdap_async.h"
#include "providers/ldap/sdap_idmap.h"
#include "providers/ldap/sdap_users.h"
/* =Users-Related-Functions-(by-name,by-uid)============================== */
struct users_get_state {
struct tevent_context *ev;
struct sdap_id_ctx *ctx;
struct sdap_domain *sdom;
struct sdap_id_conn_ctx *conn;
struct sdap_id_op *op;
struct sss_domain_info *domain;
const char *name;
int filter_type;
char *filter;
const char **attrs;
bool use_id_mapping;
int dp_error;
int sdap_ret;
bool noexist_delete;
};
struct tevent_context *ev,
struct sdap_id_ctx *ctx,
struct sdap_domain *sdom,
struct sdap_id_conn_ctx *conn,
const char *name,
int filter_type,
int attrs_type,
bool noexist_delete)
{
struct tevent_req *req;
struct users_get_state *state;
char *clean_name;
char *endptr;
int ret;
enum idmap_error_code err;
char *sid;
goto fail;
}
switch (filter_type) {
case BE_FILTER_NAME:
goto fail;
}
break;
case BE_FILTER_IDNUM:
if (state->use_id_mapping) {
/* If we're ID-mapping, we need to use the objectSID
* in the search filter.
*/
goto fail;
}
/* Convert the UID to its objectSID */
if (err == IDMAP_NO_DOMAIN) {
("[%s] did not match any configured ID mapping domain\n",
name));
/* Ignore errors to remove users that were not cached previously */
}
goto fail;
} else if (err != IDMAP_SUCCESS) {
("Mapping ID [%s] to SID failed: [%s]\n",
goto fail;
}
goto fail;
}
} else {
goto fail;
}
}
break;
case BE_FILTER_SECID:
goto fail;
}
break;
default:
goto fail;
}
goto fail;
}
/* When mapping IDs or looking for SIDs, we don't want to limit
* ourselves to users with a UID value. But there must be a SID to map
* from.
*/
"(&(%s=%s)(objectclass=%s)(%s=*)(%s=*))",
} else {
/* When not ID-mapping, make sure there is a non-NULL UID */
"(&(%s=%s)(objectclass=%s)(%s=*)(&(%s=*)(!(%s=0))))",
}
goto fail;
}
/* TODO: handle attrs_type */
goto fail;
}
return req;
fail:
} else {
}
return req;
}
{
struct users_get_state);
struct tevent_req *subreq;
if (!subreq) {
return ret;
}
return EOK;
}
{
struct tevent_req);
struct users_get_state);
int dp_error = DP_ERR_FATAL;
int ret;
return;
}
/* If POSIX attributes have been requested with an AD server and we
* have no idea about POSIX attributes support, run a one-time check
*/
if (state->use_id_mapping == false &&
return;
}
return;
}
}
{
bool has_posix;
int dp_error;
struct tevent_req);
struct users_get_state);
/* We can only finish the id_op on error as the connection
* is re-used by the user search
*/
/* retry */
}
return;
}
}
/* If the check ran to completion, we know for certain about the attributes
*/
if (has_posix == false) {
return;
}
}
{
struct users_get_state);
struct tevent_req *subreq;
false);
if (!subreq) {
return;
}
}
{
struct tevent_req);
struct users_get_state);
char *endptr;
int dp_error = DP_ERR_FATAL;
int ret;
/* retry */
return;
}
return;
}
SDAP_RFC2307_FALLBACK_TO_LOCAL_USERS) == true)) {
struct sysdb_attrs **usr_attrs;
bool fallback;
switch (state->filter_type) {
case BE_FILTER_NAME:
uid = -1;
fallback = true;
break;
case BE_FILTER_IDNUM:
return;
}
fallback = true;
break;
default:
fallback = false;
break;
}
if (fallback) {
}
}
}
return;
}
switch (state->filter_type) {
case BE_FILTER_ENUM:
return;
case BE_FILTER_NAME:
return;
}
break;
case BE_FILTER_IDNUM:
return;
}
return;
}
break;
case BE_FILTER_SECID:
/* Since it is not clear if the SID belongs to a user or a group
* we have nothing to do here. */
break;
default:
return;
}
}
/* FIXME - return sdap error so that we know the user was not found */
}
{
struct users_get_state);
if (dp_error_out) {
}
if (sdap_ret) {
}
return EOK;
}
/* =Groups-Related-Functions-(by-name,by-uid)============================= */
struct groups_get_state {
struct tevent_context *ev;
struct sdap_id_ctx *ctx;
struct sdap_domain *sdom;
struct sdap_id_conn_ctx *conn;
struct sdap_id_op *op;
struct sss_domain_info *domain;
const char *name;
int filter_type;
char *filter;
const char **attrs;
bool use_id_mapping;
int dp_error;
int sdap_ret;
bool noexist_delete;
};
struct tevent_context *ev,
struct sdap_id_ctx *ctx,
struct sdap_domain *sdom,
struct sdap_id_conn_ctx *conn,
const char *name,
int filter_type,
int attrs_type,
bool noexist_delete)
{
struct tevent_req *req;
struct groups_get_state *state;
char *clean_name;
char *endptr;
int ret;
enum idmap_error_code err;
char *sid;
const char *member_filter[2];
goto fail;
}
switch(filter_type) {
case BE_FILTER_NAME:
goto fail;
}
break;
case BE_FILTER_IDNUM:
if (state->use_id_mapping) {
/* If we're ID-mapping, we need to use the objectSID
* in the search filter.
*/
goto fail;
}
/* Convert the GID to its objectSID */
if (err == IDMAP_NO_DOMAIN) {
("[%s] did not match any configured ID mapping domain\n",
name));
/* Ignore errors to remove users that were not cached previously */
}
goto fail;
} else if (err != IDMAP_SUCCESS) {
("Mapping ID [%s] to SID failed: [%s]\n",
goto fail;
}
goto fail;
}
} else {
goto fail;
}
}
break;
case BE_FILTER_SECID:
goto fail;
}
break;
default:
goto fail;
}
goto fail;
}
/* When mapping IDs or looking for SIDs, we don't want to limit
* ourselves to groups with a GID value
*/
"(&(%s=%s)(objectclass=%s)(%s=*))",
} else {
"(&(%s=%s)(objectclass=%s)(%s=*)(&(%s=*)(!(%s=0))))",
}
goto fail;
}
/* TODO: handle attrs_type */
(const char **)member_filter : NULL,
goto fail;
}
return req;
fail:
} else {
}
return req;
}
{
struct groups_get_state);
struct tevent_req *subreq;
if (!subreq) {
return ret;
}
return EOK;
}
{
struct tevent_req);
struct groups_get_state);
int dp_error = DP_ERR_FATAL;
int ret;
return;
}
/* If POSIX attributes have been requested with an AD server and we
* have no idea about POSIX attributes support, run a one-time check
*/
if (state->use_id_mapping == false &&
return;
}
return;
}
}
{
bool has_posix;
int dp_error;
struct tevent_req);
struct groups_get_state);
/* We can only finish the id_op on error as the connection
* is re-used by the group search
*/
/* retry */
}
return;
}
}
/* If the check ran to completion, we know for certain about the attributes
*/
if (has_posix == false) {
return;
}
}
{
struct groups_get_state);
struct tevent_req *subreq;
false);
if (!subreq) {
return;
}
}
{
struct tevent_req);
struct groups_get_state);
char *endptr;
int dp_error = DP_ERR_FATAL;
int ret;
/* retry */
return;
}
return;
}
return;
}
switch (state->filter_type) {
case BE_FILTER_ENUM:
return;
case BE_FILTER_NAME:
return;
}
break;
case BE_FILTER_IDNUM:
return;
}
return;
}
break;
case BE_FILTER_SECID:
/* Since it is not clear if the SID belongs to a user or a group
* we have nothing to do here. */
break;
default:
return;
}
}
}
{
struct groups_get_state);
if (dp_error_out) {
}
if (sdap_ret) {
}
return EOK;
}
/* =Get-Groups-for-User================================================== */
struct groups_by_user_state {
struct tevent_context *ev;
struct sdap_id_ctx *ctx;
struct sdap_domain *sdom;
struct sdap_id_conn_ctx *conn;
struct sdap_id_op *op;
struct sss_domain_info *domain;
const char *name;
const char **attrs;
int dp_error;
int sdap_ret;
bool noexist_delete;
};
struct tevent_context *ev,
struct sdap_id_ctx *ctx,
struct sdap_domain *sdom,
struct sdap_id_conn_ctx *conn,
const char *name,
bool noexist_delete)
{
struct tevent_req *req;
struct groups_by_user_state *state;
int ret;
goto fail;
}
goto fail;
}
return req;
fail:
return req;
}
{
struct groups_by_user_state);
struct tevent_req *subreq;
if (!subreq) {
return ret;
}
return EOK;
}
{
struct tevent_req);
struct groups_by_user_state);
int dp_error = DP_ERR_FATAL;
int ret;
return;
}
if (!subreq) {
return;
}
}
{
struct tevent_req);
struct groups_by_user_state);
int dp_error = DP_ERR_FATAL;
int ret;
/* retry */
return;
}
return;
}
return;
}
return;
}
}
}
{
struct groups_by_user_state);
if (dp_error_out) {
}
if (sdap_ret) {
}
return EOK;
}
{
struct sdap_id_ctx *ctx;
struct sdap_id_ctx);
}
struct sdap_online_check_ctx {
struct sdap_id_ctx *id_ctx;
};
{
struct tevent_req *req;
struct sdap_online_check_ctx *check_ctx;
if (!check_ctx) {
goto fail;
}
CON_TLS_DFL, false);
goto fail;
}
return;
fail:
}
{
struct sdap_online_check_ctx);
int ret;
int dp_err = DP_ERR_FATAL;
bool can_retry;
struct sdap_server_opts *srv_opts;
struct sdap_id_ctx *id_ctx;
bool reinit = false;
if (!can_retry) {
}
} else {
srv_opts->max_user_value = 0;
srv_opts->max_group_value = 0;
srv_opts->max_service_value = 0;
srv_opts->max_sudo_value = 0;
&& srv_opts->supports_usn
reinit = true;
}
}
if (reinit) {
"Cleaning cache.\n"));
if (reinit_req == NULL) {
"clean up.\n"));
/* not fatal */
goto done;
}
be_req);
return;
}
done:
}
{
/* not fatal */
} else {
}
}
/* =Get-Account-Info-Call================================================= */
/* FIXME: embed this function in sssd_be and only call out
* specific functions from modules ? */
struct sdap_id_conn_ctx *conn);
struct tevent_context *ev,
struct sdap_id_ctx *ctx,
struct sdap_domain *sdom,
struct sdap_id_conn_ctx *conn,
const char *name,
int filter_type,
int attrs_type,
bool noexist_delete);
int *dp_error_out, int *sdap_ret);
{
struct sdap_id_ctx *ctx;
if (!ctx) {
EINVAL, "Invalid request data\n");
}
}
/* A generic LDAP account info handler */
struct sdap_handle_acct_req_state {
struct be_acct_req *ar;
const char *err;
int dp_error;
int sdap_ret;
};
struct tevent_req *
struct be_acct_req *ar,
struct sdap_id_ctx *id_ctx,
struct sdap_domain *sdom,
struct sdap_id_conn_ctx *conn,
bool noexist_delete)
{
struct tevent_req *req;
struct tevent_req *subreq;
struct sdap_handle_acct_req_state *state;
struct sdap_handle_acct_req_state);
if (!req) {
goto done;
}
goto done;
}
case BE_REQ_USER: /* user */
/* skip enumerations on demand */
("Skipping user enumeration on demand\n"));
goto done;
}
break;
case BE_REQ_GROUP: /* group */
/* skip enumerations on demand */
("Skipping group enumeration on demand\n"));
goto done;
}
break;
case BE_REQ_INITGROUPS: /* init groups for user */
goto done;
}
goto done;
}
break;
case BE_REQ_NETGROUP:
goto done;
}
break;
case BE_REQ_SERVICES:
/* skip enumerations on demand */
("Skipping service enumeration on demand\n"));
goto done;
}
goto done;
}
break;
case BE_REQ_BY_SECID:
goto done;
}
break;
case BE_REQ_USER_AND_GROUP:
goto done;
}
break;
default: /*fail*/
goto done;
}
if (!subreq) {
goto done;
}
return req;
done:
} else {
}
return req;
}
static void
{
struct sdap_handle_acct_req_state *state;
const char *err = "Invalid request type";
case BE_REQ_USER: /* user */
err = "User lookup failed";
break;
case BE_REQ_GROUP: /* group */
err = "Group lookup failed";
break;
case BE_REQ_INITGROUPS: /* init groups for user */
err = "Init group lookup failed";
break;
case BE_REQ_NETGROUP:
err = "Netgroup lookup failed";
break;
case BE_REQ_SERVICES:
err = "Service lookup failed";
break;
case BE_REQ_BY_SECID:
/* Fallthrough */
case BE_REQ_USER_AND_GROUP:
err = "Lookup by SID failed";
break;
default: /*fail*/
break;
}
return;
}
}
int *sdap_ret)
{
struct sdap_handle_acct_req_state *state;
if (_dp_error) {
}
if (_err) {
}
if (sdap_ret) {
}
return EOK;
}
struct sdap_id_conn_ctx *conn)
{
struct be_acct_req *ar;
struct tevent_req *req;
}
EINVAL, "Invalid private data");
}
}
}
{
const char *error_text;
const char *req_error_text;
error_text = NULL;
} else {
("Bug: dp_error is OK on failed request"));
}
} else if (dp_error == DP_ERR_OFFLINE) {
error_text = "Offline";
error_text = "Out of memory";
} else {
}
}
struct get_user_and_group_state {
struct tevent_context *ev;
struct sdap_id_ctx *id_ctx;
struct sdap_domain *sdom;
struct sdap_id_conn_ctx *conn;
struct sdap_id_op *op;
struct sss_domain_info *domain;
const char *filter_val;
int filter_type;
int attrs_type;
char *filter;
const char **attrs;
int dp_error;
int sdap_ret;
bool noexist_delete;
};
struct tevent_context *ev,
struct sdap_id_ctx *id_ctx,
struct sdap_domain *sdom,
struct sdap_id_conn_ctx *conn,
const char *filter_val,
int filter_type,
int attrs_type,
bool noexist_delete)
{
struct tevent_req *req;
struct tevent_req *subreq;
struct get_user_and_group_state *state;
int ret;
return NULL;
}
goto fail;
}
goto fail;
}
return req;
fail:
return req;
}
{
struct tevent_req);
struct get_user_and_group_state);
int ret;
return;
}
return;
return;
}
/* Now the search finished fine but did not find an entry.
* Retry with users. */
return;
}
}
{
struct tevent_req);
struct get_user_and_group_state);
int ret;
return;
}
/* The search ran to completion, but nothing was found.
* Delete the existing entry, if any. */
state->filter_val);
return;
}
return;
}
/* Both ret and sdap->ret are EOK. Matching user found */
return;
}
int *dp_error_out, int *sdap_ret)
{
struct get_user_and_group_state);
if (dp_error_out) {
}
if (sdap_ret) {
}
return EOK;
}