sudosrv_get_sudorules.c revision 20e310e32a47e861ce0c11bcd1dcf89dc78d8aba
/*
Authors:
Pavel Březina <pbrezina@redhat.com>
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) 2011 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 <stdint.h>
#include <string.h>
#include <talloc.h>
#include "db/sysdb_sudo.h"
#include "responder/sudo/sudosrv_private.h"
{
dctx->check_provider = true;
("Looking up the user info from Data Provider\n"));
return EAGAIN;
return ret;
}
/* OK, got the user from cache. Try to get the rules. */
("Looking up the sudo rules from Data Provider\n"));
return EAGAIN;
return ret;
}
return EOK;
}
{
time_t cache_expire = 0;
struct tevent_req *dpreq;
struct dp_callback_ctx *cb_ctx;
while (dom) {
/* if it is a domainless search, skip domains that require fully
* qualified names instead */
}
if (!dom) break;
/* make sure to update the dctx if we changed domain */
("sysdb context not found for this domain!\n"));
return EIO;
}
("Failed to make request to our cache!\n"));
return EIO;
}
("getpwnam call returned more than one result !?!\n"));
return EIO;
}
/* if a multidomain search, try with next */
if (cmd_ctx->check_next) {
dctx->check_provider = true;
if (dom) continue;
}
return ENOENT;
}
/* One result found, check cache expiry */
SYSDB_CACHE_EXPIRE, 0);
}
/* If cache miss and we haven't checked DP yet OR the entry is
* outdated, go to DP */
dom, false, SSS_DP_INITGROUPS,
if (!dpreq) {
("Out of memory sending data provider request\n"));
return ENOMEM;
}
if(!cb_ctx) {
return ENOMEM;
}
/* tell caller we are in an async call */
return EAGAIN;
}
return EOK;
}
return ENOENT;
}
{
struct dp_callback_ctx *cb_ctx =
char *err_msg;
&err_msg);
("Fatal error, killing connection!\n"));
return;
}
}
{
if (err_maj) {
("Unable to get information from Data Provider\n"
"Error: %u, %u, %s\n",
}
dctx->check_provider = false;
/* FIXME - set entry into cache so that we don't perform initgroups too often */
goto done;
("Could not look up the user [%d]: %s\n",
return;
}
goto done;
("Error getting sudo rules [%d]: %s\n",
return;
}
done:
}
{
struct tevent_req *dpreq;
/* FIXME - cache logic will be here. For now, just refresh
* the cache unconditionally */
("Fatal: Sysdb CTX not found for this domain!\n"));
return EIO;
}
return EAGAIN;
}
{
struct sudo_dom_ctx *dctx;
("Data provider returned an error [%d]: %s "
"DBus error min: %d maj %d\n",
return;
}
("Failed to make a request to our cache [%d]: %s\n",
return;
}
}
const char *username,
char **groupnames,
struct sysdb_attrs ***_rules,
{
char **groupnames;
("sysdb context not found for this domain!\n"));
goto done;
}
goto done;
}
goto done;
}
done:
return ret;
}
static errno_t
const char *username,
char **groupnames,
struct sysdb_attrs ***_rules,
{
char *filter;
struct sysdb_attrs **rules;
struct ldb_message **msgs;
const char *attrs[] = { SYSDB_OBJECTCLASS
NULL };
("Could not construct the search filter [%d]: %s\n",
goto done;
}
goto done;
*_count = 0;
goto done;
}
("Could not convert ldb message to sysdb_attrs\n"));
goto done;
}
("Could not sort rules by sudoOrder\n"));
goto done;
}
done:
return ret;
}
static int
sudo_order_cmp_fn(const void *a, const void *b)
{
int ret;
r1 = * (struct sysdb_attrs * const *) a;
r2 = * (struct sysdb_attrs * const *) b;
return 0;
}
/* man sudoers-ldap: If the sudoOrder attribute is not present,
* a value of 0 is assumed */
o1 = 0;
return 0;
}
/* man sudoers-ldap: If the sudoOrder attribute is not present,
* a value of 0 is assumed */
o2 = 0;
return 0;
}
return 1;
return -1;
}
return 0;
}
static errno_t
{
return EOK;
}
const char *query_body,
int query_len)
{
return NULL;
}
}
/*
* Response format:
* <error_code(uint32_t)><num_entries(uint32_t)><rule1><rule2>...
* <ruleN> = <num_attrs(uint32_t)><attr1><attr2>...
* <attrN> = <name(char*)>\0<num_values(uint32_t)><value1(char*)>\0<value2(char*)>\0...
*
* if <error_code> is not SSS_SUDO_ERROR_OK, the rest of the data is skipped.
*/
int rules_num,
struct sysdb_attrs **rules,
{
size_t response_len = 0;
int i = 0;
return ENOMEM;
}
/* error code */
goto fail;
}
if (error != SSS_SUDO_ERROR_OK) {
goto done;
}
/* rules count */
goto fail;
}
/* rules */
for (i = 0; i < rules_num; i++) {
goto fail;
}
}
done:
fail:
return ret;
}