sysdb_search.c revision 2d66c2eee2e4364a52d5436b61759ef990108230
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch System Database
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
aacf2a69acc59e9382578d6f4e030788abc79706Timo Sirainen This program is free software; you can redistribute it and/or modify
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch it under the terms of the GNU General Public License as published by
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch the Free Software Foundation; either version 3 of the License, or
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch (at your option) any later version.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch This program is distributed in the hope that it will be useful,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch but WITHOUT ANY WARRANTY; without even the implied warranty of
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch GNU General Public License for more details.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch You should have received a copy of the GNU General Public License
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch along with this program. If not, see <http://www.gnu.org/licenses/>.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* If this is a subomain we need to use fully qualified names for the
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch * search as well by default */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch src_name = talloc_asprintf(tmp_ctx, domain->names->fq_fmt,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = sss_filter_sanitize(tmp_ctx, src_name, &sanitized_name);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch LDB_SCOPE_SUBTREE, attrs, SYSDB_PWUID_FILTER, ul_uid);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch LDB_SCOPE_SUBTREE, attrs, SYSDB_PWENT_FILTER);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int mpg_convert(struct ldb_message *msg)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch el = ldb_msg_find_element(msg, "objectClass");
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* see if this is a user to convert to a group */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* no, leave as is */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* yes, convert */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch val->data = (uint8_t *)talloc_strdup(msg, SYSDB_GROUP_CLASS);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic int mpg_res_convert(struct ldb_result *res)
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch static const char *attrs[] = SYSDB_GRSRC_ATTRS;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* If this is a subomain we need to use fully qualified names for the
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch * search as well by default */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch src_name = talloc_asprintf(tmp_ctx, domain->names->fq_fmt,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = sss_filter_sanitize(tmp_ctx, src_name, &sanitized_name);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch static const char *attrs[] = SYSDB_GRSRC_ATTRS;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch LDB_SCOPE_SUBTREE, attrs, fmt_filter, ul_gid);
92e011227877493a1b6a5a38863aabde7e07bd76Timo Sirainen static const char *attrs[] = SYSDB_GRSRC_ATTRS;
92e011227877493a1b6a5a38863aabde7e07bd76Timo Sirainen ret = ldb_search(sysdb->ldb, tmp_ctx, &res, base_dn,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch static const char *attrs[] = SYSDB_INITGR_ATTRS;
6bc9fb43cc1ac24693d030a6cbfa43bc7cbc82cbTimo Sirainen ret = sysdb_getpwnam(tmp_ctx, sysdb, sysdb->domain, name, &res);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch DEBUG(1, ("sysdb_getpwnam failed: [%d][%s]\n",
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch /* User is not cached yet */
6bc9fb43cc1ac24693d030a6cbfa43bc7cbc82cbTimo Sirainen DEBUG(1, ("sysdb_getpwnam returned count: [%d]\n", res->count));
if (!ctrl) {
goto done;
if (!ctrl[0]) {
goto done;
if (!control) {
goto done;
goto done;
NULL);
goto done;
goto done;
done:
return ret;
const char *name,
const char **attributes,
char *sanitized_name;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!base_dn) {
goto done;
goto done;
if (ret) {
goto done;
done:
return ret;
const char *triple,
char **hostname,
char **username,
char **domainname)
const char *p = triple;
const char *p_host;
const char *p_user;
const char *p_domain;
if (!tmp_ctx) {
return ENOMEM;
while (*p && isspace(*p)) p++;
goto done;
p_host = p;
goto done;
if (len > 0) {
if (!host) {
goto done;
p_user = p;
goto done;
if (len > 0) {
if (!user) {
goto done;
p_domain = p;
goto done;
if (len > 0) {
if (!domain) {
goto done;
while (*p && isspace(*p)) p++;
goto done;
if (host) {
if (user) {
if (domain) {
done:
return ret;
size_t c = 0;
char *triple_str;
return ENOENT;
if (!tmp_ctx) {
return ENOMEM;
goto done;
if (size != 0) {
if (!triple_str) {
goto done;
struct sysdb_netgroup_ctx);
if (!tmp_entry[c]) {
goto done;
goto done;
struct sysdb_netgroup_ctx);
if (!tmp_entry[c]) {
goto done;
goto done;
done:
return ret;
const char *netgroup,
char *sanitized_netgroup;
char *netgroup_dn;
int lret;
if (!tmp_ctx) {
return ENOMEM;
if (!base_dn) {
goto done;
goto done;
if (!netgroup_dn) {
goto done;
goto done;
done:
return ret;
const char *netgrname,
const char **attributes,
char *sanitized_netgroup;
int ret;
if (!tmp_ctx) {
return ENOMEM;
if (!base_dn) {
goto done;
goto done;
if (ret) {
goto done;
done:
return ret;
const char *name,
char ***_direct_parents)
const char *dn;
char *sanitized_dn;
const char *member_filter;
int i, pi;
const char *tmp_str;
goto done;
if (!dn) {
goto done;
goto done;
if (!member_filter) {
goto done;
if (!basedn) {
goto done;
direct_sysdb_count = 0;
goto done;
if (!direct_parents) {
goto done;
pi = 0;
for(i = 0; i < direct_sysdb_count; i++) {
if (!tmp_str) {
goto done;
pi++;
done:
return ret;