sudosrv_get_sudorules.c revision 278284224aa10805d58c978977e43b1d1126f9b1
/*
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 "config.h"
#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;
const char *original_name = NULL;
return ENOMEM;
}
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 */
goto done;
}
("sysdb context not found for this domain!\n"));
goto done;
}
("Failed to make request to our cache!\n"));
goto done;
}
("getpwnam call returned more than one result !?!\n"));
goto done;
}
/* if a multidomain search, try with next */
if (cmd_ctx->check_next) {
dctx->check_provider = true;
if (dom) continue;
}
goto done;
}
/* 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 */
&& dctx->check_provider) {
dom, false, SSS_DP_INITGROUPS,
if (!dpreq) {
("Out of memory sending data provider request\n"));
goto done;
}
if(!cb_ctx) {
goto done;
}
/* tell caller we are in an async call */
goto done;
}
/* user is stored in cache, remember cased and original name */
SYSDB_NAME, NULL);
goto done;
}
goto done;
}
goto done;
}
done:
return ret;
}
{
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",
}
("Data Provider returned, check the cache again\n"));
dctx->check_provider = false;
goto done;
("Could not look up the user [%d]: %s\n",
return;
}
goto done;
("Error getting sudo rules [%d]: %s\n",
return;
}
done:
}
static void
static void
{
struct tevent_req *dpreq;
("Cannot issue DP request.\n"));
return EIO;
}
if (!cb_ctx) {
return ENOMEM;
}
return EAGAIN;
}
static void
{
struct dp_callback_ctx *cb_ctx =
struct sudo_dom_ctx *dctx =
char *err_msg;
&err_msg);
return;
}
}
static void
{
struct sudo_dom_ctx *dctx =
if (err_maj) {
("Unable to get information from Data Provider\n"
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
/* Loop to the next domain if possible */
}
}
("Failed to make a request to our cache [%d]: %s\n",
return;
}
}
enum sss_dp_sudo_type type,
const char *username,
char **groupnames,
struct sysdb_attrs ***_rules,
{
char **groupnames;
("sysdb context not found for this domain!\n"));
goto done;
}
goto done;
}
} else {
uid = 0;
groupnames = NULL;
}
goto done;
}
/* Store result in in-memory cache */
} else {
}
done:
return ret;
}
static errno_t
enum sss_dp_sudo_type type,
const char *username,
char **groupnames,
struct sysdb_attrs ***_rules,
{
char *filter;
struct sysdb_attrs **rules;
struct ldb_message **msgs;
unsigned int flags = SYSDB_SUDO_FILTER_NONE;
const char *attrs[] = { SYSDB_OBJECTCLASS
NULL };
switch (type) {
case SSS_DP_SUDO_DEFAULTS:
break;
case SSS_DP_SUDO_USER:
break;
}
("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)
{
/* empty string or not NULL terminated */
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;
}