sysdb_ops.c revision dd285415d7a8d8376207960cfa3e977524c3b98c
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor System Database
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor This program is free software; you can redistribute it and/or modify
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor it under the terms of the GNU General Public License as published by
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor the Free Software Foundation; either version 3 of the License, or
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen (at your option) any later version.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen This program is distributed in the hope that it will be useful,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen but WITHOUT ANY WARRANTY; without even the implied warranty of
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor GNU General Public License for more details.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen You should have received a copy of the GNU General Public License
3f08db06526d6901aa08c110b5bc7dde6bc39905nd along with this program. If not, see <http://www.gnu.org/licenses/>.
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzorstatic uint32_t get_attr_as_uint32(struct ldb_message *msg, const char *attr)
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr);
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor long long int l;
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor if (!v || !v->data) {
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * The wrapper around ldb_modify that uses LDB_CONTROL_PERMISSIVE_MODIFY_OID
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * so that on adds entries that already exist are skipped and similarly
e40d2af13fd7ff120eda49cd327c68fbc16443e8sf * entries that are missing are ignored on deletes
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * Please note this function returns LDB error codes, not sysdb error
df135dbebadfdf65d0c45e181d6c19b84d17b7c6sf * codes on purpose, see usage in callers!
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzorint sss_ldb_modify_permissive(struct ldb_context *ldb,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor ret = ldb_request_add_control(req, LDB_CONTROL_PERMISSIVE_MODIFY_OID,
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor /* Please note this function returns LDB error codes, not sysdb error
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor * codes on purpose, see usage in callers!
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor#define ERROR_OUT(v, r, l) do { v = r; goto l; } while(0)
1462ff536f1b939bb337766b2056109c29664c4erbowen/* =Remove-Entry-From-Sysdb=============================================== */
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor /* fall through */
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor DEBUG(SSSDBG_CRIT_FAILURE, "LDB Error: %s(%d)\nError Message: [%s]\n",
cc8190433d13f5e9de618c5d7f10c824c0c1919cgryzor/* =Remove-Subentries-From-Sysdb=========================================== */
1462ff536f1b939bb337766b2056109c29664c4erbowen DEBUG(SSSDBG_TRACE_ALL, "Found [%zu] items to delete.\n", msgs_count);
1462ff536f1b939bb337766b2056109c29664c4erbowen sizeof(struct ldb_message *), compare_ldb_dn_comp_num);
1462ff536f1b939bb337766b2056109c29664c4erbowen for (i = 0; i < msgs_count; i++) {
1462ff536f1b939bb337766b2056109c29664c4erbowen/* =Search-Entry========================================================== */
1462ff536f1b939bb337766b2056109c29664c4erbowenstatic int sysdb_cache_search_entry(TALLOC_CTX *mem_ctx,
1462ff536f1b939bb337766b2056109c29664c4erbowen const char *filter,
1462ff536f1b939bb337766b2056109c29664c4erbowen const char **attrs,
0d0ba3a410038e179b695446bb149cce6264e0abnd const char *filter,
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd const char **attrs,
return ret;
attrs);
const char *filter,
const char **attrs,
*_msgs_count = 0;
return EOK;
const char *search_base,
const char *filter_str,
const char *sid_str,
const char **attrs,
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
if (!filter) {
goto done;
&msgs);
if (ret) {
goto done;
done:
else if (ret) {
return ret;
enum sysdb_obj_type {
SYSDB_UNKNOWN = 0,
const char *name,
const char **attrs,
char *sanitized_name;
char *lc_sanitized_name;
char *filter;
int ret;
switch (type) {
case SYSDB_USER:
case SYSDB_GROUP:
return EINVAL;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
goto done;
if (!filter) {
goto done;
if (ret) {
goto done;
done:
else if (ret) {
return ret;
const char *name,
const char **attrs,
const char **attrs,
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
if (!filter) {
goto done;
if (ret) {
goto done;
done:
else if (ret) {
return ret;
const char *sid_str,
const char **attrs,
const char *upn,
const char **attrs,
int ret;
NULL };
goto done;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
const char *upn,
const char **attrs,
goto done;
goto done;
goto done;
done:
return ret;
const char *name,
const char **attrs,
const char **attrs,
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
if (!filter) {
goto done;
if (ret) {
goto done;
done:
else if (ret) {
return ret;
const char *sid_str,
const char **attrs,
const char *name,
const char **attrs,
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
&msgs);
if (ret) {
goto done;
done:
else if (ret) {
return ret;
int mod_op)
int i, ret;
int lret;
if (!tmp_ctx) {
return ENOMEM;
goto done;
if (!msg) {
goto done;
goto done;
done:
else if (ret) {
return ret;
const char *name,
int mod_op)
if (!tmp_ctx) {
return ENOMEM;
if (!dn) {
goto done;
goto done;
done:
return ret;
const char *name,
int mod_op)
if (!tmp_ctx) {
goto done;
if (!dn) {
goto done;
if (ret) {
goto done;
done:
return ret;
const char *name,
int mod_op)
if (!tmp_ctx) {
return ENOMEM;
if (!dn) {
goto done;
done:
return ret;
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!base_dn) {
return ENOMEM;
if (ret) {
return ret;
switch (ret) {
case EOK:
goto done;
goto done;
case ENOENT:
goto done;
count = 0;
if (!filter) {
goto done;
switch (ret) {
case EOK:
for (i = 0; i < count; i++) {
new_id++;
goto done;
case ENOENT:
goto done;
count = 0;
if (!msg) {
goto done;
if (ret) {
goto done;
done:
if (ret) {
return ret;
const char *name,
const char *gecos,
const char *homedir,
const char *shell)
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!msg) {
goto done;
done:
if (ret) {
return ret;
static errno_t
const char *name,
const char *orig_dn,
const char *userdn)
bool add_member = false;
if (!tmp_ctx) {
return ENOENT;
if (!msg) {
add_member = true;
add_member = false;
if (orig_members) {
orig_dn) == 0) {
add_member = true;
add_member = true;
if (add_member) {
goto done;
done:
return ret;
static errno_t
const char *orig_dn,
const char *name)
const char *userdn;
char *sanitized_name;
char *filter;
if (!tmp_ctx) {
return ENOENT;
goto done;
if (!filter) {
goto done;
goto done;
goto done;
goto done;
if (!tmpdn) {
if (!userdn) {
if (!tmpdn) {
goto done;
goto done;
for (i = 0; i < group_count; i++) {
done:
return ret;
const char *name,
const char *gecos,
const char *homedir,
const char *shell,
const char *orig_dn,
int cache_timeout,
int ret;
if (gid != 0) {
return EINVAL;
return ERANGE;
return ERANGE;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
goto done;
if (uid != 0) {
goto done;
if (uid == 0) {
if (!id_attrs) {
goto done;
if (!attrs) {
if (!attrs) {
goto done;
if (!now) {
((cache_timeout) ?
name);
done:
return ret;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!msg) {
goto done;
done:
if (ret) {
return ret;
int cache_timeout,
int ret;
bool posix;
return ERANGE;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
goto done;
if (gid != 0) {
goto done;
if (ret) {
goto done;
if (!attrs) {
if (!attrs) {
goto done;
posix = true;
if (ret) {
goto done;
goto done;
if (ret) {
goto done;
if (ret) {
goto done;
if (!now) {
if (ret) {
goto done;
((cache_timeout) ?
if (ret) {
goto done;
if (ret) {
goto done;
done:
return ret;
const char *name,
const char *original_dn,
const char *sid_str,
const char *uuid,
bool posix,
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!attrs) {
goto done;
if (!now) {
if (original_dn) {
if (sid_str) {
if (uuid) {
done:
return ret;
int mod_op)
const char *dn;
int ret;
if (!msg) {
if (!dn) {
fail:
if (ret) {
return ret;
int ret;
if (!msg) {
return ENOMEM;
done:
if (ret) {
return ret;
const char *name,
const char *description,
char **missing,
int cache_timeout,
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
if (!attrs) {
if (!attrs) {
goto done;
if (!now) {
((cache_timeout) ?
if (missing) {
missing);
done:
return ret;
const char *name,
const char *pwd,
const char *gecos,
const char *homedir,
const char *shell,
const char *orig_dn,
char **remove_attrs,
int ret;
bool in_transaction = false;
if (!tmp_ctx) {
return ENOMEM;
if (!attrs) {
if (!attrs) {
goto fail;
goto fail;
in_transaction = true;
goto fail;
if (!now) {
goto fail;
goto fail;
goto done;
goto fail;
if (uid) {
if (gid) {
if (gecos) {
if (homedir) {
if (shell) {
((cache_timeout) ?
if (remove_attrs) {
done:
goto fail;
in_transaction = false;
fail:
if (in_transaction) {
if (ret) {
return ret;
const char *name,
const char *name,
const char *name,
bool new_group = false;
int ret;
bool in_transaction = false;
if (!tmp_ctx) {
return ENOMEM;
goto done;
in_transaction = true;
goto done;
new_group = true;
if (!attrs) {
if (!attrs) {
goto done;
if (!now) {
if (new_group) {
goto done;
in_transaction = false;
done:
if (in_transaction) {
if (ret) {
return ret;
const char *name,
return EEXIST;
return ret;
if (ret) {
return ret;
return EOK;
const char *name,
if (gid) {
if (ret) {
return ret;
if (ret) {
return ret;
((cache_timeout) ?
if (ret) {
return ret;
if (ret) {
return ret;
return EOK;
const char *group,
const char *member,
int modify_op,
bool is_dn)
int ret;
if (!tmp_ctx) {
return ENOMEM;
goto done;
if (!member_dn) {
goto done;
if (!is_dn) {
if (!group_dn) {
goto done;
done:
return ret;
const char *group,
const char *member,
bool is_dn)
const char *group,
const char *member,
bool is_dn)
const char *username,
const char *password,
char *salt;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
goto fail;
if (ret) {
goto fail;
if (!attrs) {
if (ret) {
goto fail;
return EOK;
fail:
if (ret) {
return ret;
const char *username,
const char *password)
const char *filter,
const char *subtree_name,
const char **attrs,
int ret;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
const char *object_name,
const char *subtree_name,
const char **attrs,
int ret;
return EINVAL;
if (!tmp_ctx) {
return ENOMEM;
goto done;
goto done;
if (ret) {
goto done;
goto done;
done:
return ret;
const char *object_name,
const char *subtree_name,
bool add_object = false;
int ret;
return EINVAL;
if (ret) {
if (!tmp_ctx) {
goto done;
goto done;
add_object = true;
goto done;
goto done;
goto done;
if (add_object) {
if (add_object) {
done:
if (ret) {
return ret;
const char *object_name,
const char *subtree_name)
int ret;
return EINVAL;
if (!tmp_ctx) {
return ENOMEM;
goto done;
switch (ret) {
case LDB_SUCCESS:
case LDB_ERR_NO_SUCH_OBJECT:
done:
return ret;
const char *expression,
const char *asq_attribute,
const char **attrs,
int ret;
if (!tmp_ctx) {
return ENOMEM;
goto fail;
goto fail;
goto fail;
goto fail;
if (!res) {
goto fail;
goto fail;
if (ret) {
goto fail;
return EOK;
fail:
else if (ret) {
return ret;
const char *sub_filter,
const char **attrs,
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto fail;
if (!filter) {
goto fail;
if (ret) {
goto fail;
return EOK;
fail:
else if (ret) {
return ret;
const char *sub_filter,
const char **attrs,
return ret;
attrs);
const char *sub_filter,
const char **attrs,
return ENOENT;
char *filter;
int ret;
char *sanitized_name;
if (!tmp_ctx) {
return ENOMEM;
if (name) {
const char *c_name;
goto fail;
goto fail;
if (ret) {
goto fail;
goto fail;
goto fail;
goto fail;
for (i = 0; i < msg_count; i++) {
if (!msg) {
goto fail;
goto fail;
return EOK;
fail:
return ret;
const char *sub_filter,
const char **attrs,
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto fail;
if (!filter) {
goto fail;
if (ret) {
goto fail;
return EOK;
fail:
else if (ret) {
return ret;
const char *sub_filter,
const char **attrs,
return ret;
attrs);
const char *sub_filter,
const char **attrs,
return ENOENT;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (name) {
if (ret) {
goto fail;
const char *c_name;
goto fail;
goto fail;
if (ret) {
goto fail;
return EOK;
fail:
return ret;
const char *sub_filter,
const char **attrs,
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto fail;
if (!filter) {
goto fail;
if (ret) {
goto fail;
return EOK;
fail:
return ret;
const char *name)
int ret;
if (!tmp_ctx) {
return ENOMEM;
goto done;
goto done;
goto done;
done:
return ret;
const char *sid_str)
int ret;
if (!tmp_ctx) {
return ENOMEM;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
int ret;
int failed_login_delay;
if (!tmp_ctx) {
return ENOMEM;
goto done;
goto done;
if (failed_login_delay) {
*failed_login_attempts = 0;
goto done;
goto done;
done:
return ret;
const char *password,
const char *userhash)
unsigned int cached_authtok_type;
unsigned int cached_fa2_len;
char *short_pw;
char *comphash;
int ret;
return EINVAL;
if (cached_fa2_len == 0) {
return EINVAL;
return EINVAL;
return ENOMEM;
goto done;
goto done;
goto done;
done:
return ret;
const char *name,
const char *password,
bool just_check,
const char *userhash;
char *comphash;
int cred_expiration;
bool authentication_successful = false;
int ret;
return EINVAL;
return EINVAL;
return EINVAL;
return EINVAL;
if (!tmp_ctx) {
return ENOMEM;
if (ret) {
return ret;
goto done;
goto done;
if (cred_expiration) {
expire_date = 0;
goto done;
expire_date = 0;
goto done;
goto done;
if (ret) {
goto done;
goto done;
authentication_successful = true;
if (just_check) {
goto done;
goto done;
goto done;
authentication_successful = false;
goto done;
goto done;
if (ret) {
done:
if (ret) {
if (ret) {
if (authentication_successful) {
return ret;
const char *member,
const char *const *add_groups,
const char *const *del_groups,
bool is_dn)
bool in_transaction = false;
if(!tmp_ctx) {
return ENOMEM;
goto done;
in_transaction = true;
if (add_groups) {
for (i = 0; add_groups[i]; i++) {
if (del_groups) {
for (i = 0; del_groups[i]; i++) {
goto done;
in_transaction = false;
done:
if (in_transaction) {
return ret;
const char *member,
const char *const *add_groups,
const char *const *del_groups)
const char *member,
const char *const *add_groups,
const char *const *del_groups)
const char *name,
char **remove_attrs)
bool in_transaction = false;
int lret;
size_t i;
switch(type) {
case SYSDB_MEMBER_USER:
case SYSDB_MEMBER_GROUP:
case SYSDB_MEMBER_NETGROUP:
case SYSDB_MEMBER_SERVICE:
goto done;
goto done;
in_transaction = true;
for (i = 0; remove_attrs[i]; i++) {
goto done;
goto done;
goto done;
in_transaction = false;
done:
if (in_transaction) {
return ret;
const char *filter_tmpl,
const char *str,
const char **attrs,
NULL };
int ret;
if (!tmp_ctx) {
return ENOMEM;
goto done;
goto done;
goto done;
goto done;
done:
} else if (ret) {
return ret;
const char *sid_str,
const char **attrs,
const char *uuid_str,
const char **attrs,
const char *cert,
const char **attrs,
int ret;
char *user_filter;
&user_filter);
return ret;
return ret;
const char *cert,
const char *cert)
goto done;
goto done;
goto done;
done:
return ret;
const char *group_name,
const char ***_sids,
const char ***_dns,
size_t n = 0;
return ENOMEM;
goto done;
goto done;
goto done;
goto done;
for (i=0; i < m_count; i++) {
const char *sidstr;
goto done;
goto done;
*_n = n;
done:
} else if (ret) {
return ret;
const char *src_name,
const char *dest_name)
int ret;
return ENOENT;
return EINVAL;
return ret;
return ret;
return ret;;
return EOK;
return ENOMEM;
goto done;
goto done;
goto done;
goto done;
done:
return ret;
return ENOMEM;
goto done;
done:
return ret;