sysdb_ops.c revision 2e7a2bece1b00022f826d511a3eb87453e285862
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen System Database
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen This program is free software; you can redistribute it and/or modify
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen it under the terms of the GNU General Public License as published by
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen the Free Software Foundation; either version 3 of the License, or
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen (at your option) any later version.
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen This program is distributed in the hope that it will be useful,
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen GNU General Public License for more details.
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen You should have received a copy of the GNU General Public License
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenint add_string(struct ldb_message *msg, int flags,
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen ret = ldb_msg_add_empty(msg, attr, flags, NULL);
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenint add_ulong(struct ldb_message *msg, int flags,
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen ret = ldb_msg_add_empty(msg, attr, flags, NULL);
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen ret = ldb_msg_add_fmt(msg, attr, "%lu", value);
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenstatic uint32_t get_attr_as_uint32(struct ldb_message *msg, const char *attr)
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr);
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen long long int l;
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen if (!v || !v->data) {
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen#define ERROR_OUT(v, r, l) do { v = r; goto l; } while(0)
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen/* =Remove-Entry-From-Sysdb=============================================== */
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenint sysdb_delete_entry(struct sysdb_ctx *sysdb,
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen /* fall through */
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen DEBUG(1, ("LDB Error: %s(%d)\nError Message: [%s]\n",
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen ldb_strerror(ret), ret, ldb_errstring(sysdb->ldb)));
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen/* =Remove-Subentries-From-Sysdb=========================================== */
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenint sysdb_delete_recursive(struct sysdb_ctx *sysdb,
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen DEBUG(6, ("Search error: %d (%s)\n", ret, strerror(ret)));
for (i = 0; i < msgs_count; i++) {
if (ret) {
goto done;
done:
return ret;
int scope,
const char *filter,
const char **attrs,
int ret;
if (ret) {
return ENOENT;
return EOK;
const char *name,
const char **attrs,
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
if (ret) {
goto done;
done:
else if (ret) {
return ret;
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 *name,
const char **attrs,
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
if (ret) {
goto done;
done:
else if (ret) {
return ret;
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 *name,
const char **attrs,
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!basedn) {
goto done;
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;
const char *name,
const char *gecos,
const char *homedir,
const char *shell,
const char *orig_dn,
int cache_timeout,
const char *userdn;
char *filter;
int ret, i, j;
bool add_member = false;
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;
goto done;
if (!attrs) {
if (!attrs) {
goto done;
if (!now) {
((cache_timeout) ?
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++) {
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;
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 (!attrs) {
if (!attrs) {
goto done;
posix = true;
goto done;
if (!now) {
((cache_timeout) ?
done:
return ret;
const char *name,
const char *original_dn,
bool posix,
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!attrs) {
goto done;
if (!now) {
if (original_dn) {
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,
bool new_group = false;
int ret;
if (!tmp_ctx) {
return ENOMEM;
goto done;
new_group = true;
if (!attrs) {
if (!attrs) {
goto done;
if (!now) {
if (new_group) {
return EEXIST;
goto done;
goto done;
if (gid) {
((cache_timeout) ?
done:
if (ret) {
return ret;
const char *group,
const char *member,
int modify_op)
int ret;
if (!tmp_ctx) {
return ENOMEM;
goto done;
if (!member_dn) {
goto done;
if (!group_dn) {
goto done;
done:
return ret;
const char *group,
const char *member,
const char *group,
const char *member,
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 *filter,
const char *subtree_name,
const char **attrs,
int ret;
return EINVAL;
return ENOMEM;
return EINVAL;
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;
char *filter;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (name) {
const char *c_name;
goto fail;
goto fail;
if (ret) {
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;
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;
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 *name,
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;
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 in_transaction = false;
if(!tmp_ctx) {
return ENOMEM;
goto done;
in_transaction = true;
if (add_groups) {
for (i = 0; add_groups[i]; i++) {
type);
if (del_groups) {
for (i = 0; del_groups[i]; i++) {
type);
goto done;
in_transaction = false;
done:
if (in_transaction) {
return ret;
const char *netgroup,
const char *hostname,
const char *username,
const char *domainname)
const char *netgroup,
const char *hostname,
const char *username,
const char *domainname)
const char *netgroup,
const char *hostname,
const char *username,
const char *domainname,
int mod_op)
int lret;
char *triple;
if (!msg) {
if (!triple) {
goto done;
done:
if (ret) {
return ret;
const char *netgroup,
const char *member_netgroup)
const char *netgroup,
const char *member_netgroup)
const char *netgroup,
const char *member_netgroup,
int mod_op)
int lret;
char *member;
if (!msg) {
if (!member) {
goto done;
goto done;
done:
if (ret) {
return ret;
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;