sss_cache.c revision fd3cbf6bfe86a245d7e90d2a355794eb9c70d525
/*
SSSD
sss_cache
Copyright (C) Jan Zeleny <jzeleny@redhat.com> 2011
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 <stdio.h>
#include <stdlib.h>
#include <talloc.h>
#include <popt.h>
#include "tools/sss_sync_ops.h"
#include "db/sysdb_services.h"
#include "db/sysdb_autofs.h"
#include "db/sysdb_ssh.h"
#include "db/sysdb_sudo.h"
#define INVALIDATE_NONE 0
#define INVALIDATE_USERS 1
#define INVALIDATE_GROUPS 2
#define INVALIDATE_NETGROUPS 4
#define INVALIDATE_SERVICES 8
#define INVALIDATE_AUTOFSMAPS 16
#define INVALIDATE_SSH_HOSTS 32
#define INVALIDATE_SUDO_RULES 64
#ifdef BUILD_AUTOFS
#ifdef BUILD_SSH
#else /* BUILD_SSH */
#endif /* BUILD_SSH */
#else /* BUILD_AUTOFS */
#ifdef BUILD_SSH
#else /* BUILD_SSH */
#endif /* BUILD_SSH */
#endif /* BUILD_AUTOFS */
enum sss_cache_entry {
TYPE_USER=0,
};
struct sss_domain_info *domain,
const char *sub_filter, const char **attrs,
struct input_values {
char *domain;
char *group;
char *map;
char *netgroup;
char *service;
char *ssh_host;
char *sudo_rule;
char *user;
};
struct cache_tool_ctx {
struct confdb_ctx *confdb;
struct sss_domain_info *domains;
char *user_filter;
char *group_filter;
char *netgroup_filter;
char *service_filter;
char *autofs_filter;
char *ssh_host_filter;
char *sudo_rule_filter;
char *user_name;
char *group_name;
char *netgroup_name;
char *service_name;
char *autofs_name;
char *ssh_host_name;
char *sudo_rule_name;
bool update_user_filter;
bool update_group_filter;
bool update_netgroup_filter;
bool update_service_filter;
bool update_autofs_filter;
bool update_ssh_host_filter;
bool update_sudo_rule_filter;
};
struct sss_domain_info *domain,
const char *name, int entry_type);
struct sss_domain_info *dinfo,
enum sss_cache_entry entry_type,
struct sss_domain_info *dinfo);
{
bool skipped = true;
struct sss_domain_info *dinfo;
"Error initializing context for the application\n");
goto done;
}
if (!IS_SUBDOMAIN(dinfo)) {
/* Update list of subdomains for this domain */
}
}
/* Update filters for each domain */
goto done;
}
"Could not start the transaction!\n");
goto done;
}
tctx->group_name);
tctx->service_name);
tctx->autofs_name);
"Could not commit the transaction!\n");
"Failed to cancel transaction\n");
}
}
}
if (skipped == true) {
ERROR("No cache object matched the specified search\n");
goto done;
} else {
goto done;
}
}
done:
return ret;
}
{
}
struct sss_domain_info *dinfo,
bool force_case_sensitivity,
char **_filter)
{
char *parsed_domain = NULL;
char *parsed_name = NULL;
char *filter;
char *sanitized;
char *lc_sanitized;
/* Nothing to do */
return EOK;
}
return ENOMEM;
}
&parsed_domain, &parsed_name);
goto done;
}
/* We were able to parse the domain from given fqdn, but it
* does not match with currently processed domain. */
goto done;
}
if (!use_name) {
goto done;
}
} else {
}
if (parsed_domain) {
if (!use_name) {
goto done;
}
}
&sanitized, &lc_sanitized);
goto done;
}
if (fmt) {
} else {
}
} else {
}
goto done;
}
done:
}
return ret;
}
/* This function updates all filters for specified domain using this
* domains regex to parse string into domain and name (if exists). */
struct sss_domain_info *dinfo)
{
/* Update user filter */
&tctx->user_filter);
return ret;
}
/* Update group filter */
&tctx->group_filter);
return ret;
}
/* Update netgroup filter */
&tctx->netgroup_filter);
return ret;
}
/* Update service filter */
&tctx->service_filter);
return ret;
}
/* Update autofs filter */
&tctx->autofs_filter);
return ret;
}
/* Update ssh host filter */
&tctx->ssh_host_filter);
return ret;
}
/* Update sudo rule filter */
&tctx->sudo_rule_filter);
return ret;
}
return EOK;
}
struct sss_domain_info *dinfo,
enum sss_cache_entry entry_type,
{
struct ldb_message **msgs;
const char *type_string = "unknown";
int i;
const char *c_name;
bool iret;
if (!filter) return false;
switch (entry_type) {
case TYPE_USER:
type_string = "user";
break;
case TYPE_GROUP:
type_string = "group";
break;
case TYPE_NETGROUP:
type_string = "netgroup";
break;
case TYPE_SERVICE:
type_string = "service";
break;
case TYPE_AUTOFSMAP:
type_string = "autofs map";
break;
case TYPE_SSH_HOST:
type_string = "ssh_host";
#ifdef BUILD_SSH
#else /* BUILD_SSH */
#endif /* BUILD_SSH */
break;
case TYPE_SUDO_RULE:
type_string = "sudo_rule";
#ifdef BUILD_SUDO
#else /* BUILD_SUDO */
#endif /* BUILD_SUDO */
break;
}
} else {
"Searching for %s in domain %s with filter %s failed\n",
}
return false;
}
iret = true;
for (i = 0; i < msg_count; i++) {
"Something bad happened, can't find attribute %s\n",
iret = false;
} else {
iret = false;
}
}
}
return iret;
}
struct sss_domain_info *domain,
const char *name, int entry_type)
{
if (sys_attrs) {
SYSDB_CACHE_EXPIRE, 1);
switch (entry_type) {
case TYPE_USER:
/* For users, we also need to reset the initgroups
* cache expiry */
SYSDB_INITGR_EXPIRE, 1);
break;
case TYPE_GROUP:
break;
case TYPE_NETGROUP:
break;
case TYPE_SERVICE:
break;
case TYPE_AUTOFSMAP:
break;
case TYPE_SSH_HOST:
#ifdef BUILD_SSH
#else /* BUILD_SSH */
#endif /* BUILD_SSH */
break;
case TYPE_SUDO_RULE:
#ifdef BUILD_SUDO
#else /* BUILD_SUDO */
#endif /* BUILD_SUDO */
break;
default:
return EINVAL;
}
}
} else {
"Could not add expiration time to attributes\n");
}
} else {
}
return ret;
}
{
char *confdb_path;
int ret;
struct sss_domain_info *dinfo;
if (confdb_path == NULL) {
return ENOMEM;
}
/* Connect to the conf db */
"Could not initialize connection to the confdb\n");
return ret;
}
if (domain) {
"Could not initialize connection to the sysdb\n");
return ret;
}
} else {
return ret;
}
"Could not initialize connection to the sysdb\n");
return ret;
}
}
return ret;
}
}
return EOK;
}
{
int idb = INVALIDATE_NONE;
struct input_values values = { 0 };
int debug = SSSDBG_DEFAULT;
struct poptOption long_options[] = {
0, _("The debug level to run with"), NULL },
_("Invalidate all cached entries"), NULL },
_("Invalidate particular user"), NULL },
_("Invalidate all users"), NULL },
_("Invalidate particular group"), NULL },
_("Invalidate all groups"), NULL },
_("Invalidate particular netgroup"), NULL },
_("Invalidate all netgroups"), NULL },
_("Invalidate particular service"), NULL },
_("Invalidate all services"), NULL },
#ifdef BUILD_AUTOFS
_("Invalidate particular autofs map"), NULL },
_("Invalidate all autofs maps"), NULL },
#endif /* BUILD_AUTOFS */
#ifdef BUILD_SSH
_("Invalidate particular SSH host"), NULL },
_("Invalidate all SSH hosts"), NULL },
#endif /* BUILD_SSH */
#ifdef BUILD_SUDO
_("Invalidate particular sudo rule"), NULL },
_("Invalidate all cached sudo rules"), NULL },
#endif /* BUILD_SUDO */
_("Only invalidate entries from a particular domain"), NULL },
};
ret = set_locale();
ERROR("Error setting the locale\n");
goto fini;
}
switch (ret) {
case 'u':
idb |= INVALIDATE_USERS;
break;
case 'g':
idb |= INVALIDATE_GROUPS;
break;
case 'n':
break;
case 's':
break;
case 'a':
break;
case 'h':
break;
case 'r':
break;
case 'e':
#ifdef BUILD_SUDO
#endif /* BUILD_SUDO */
break;
}
}
debug_prg_name = argv[0];
if (ret != -1) {
}
_("Please select at least one object to invalidate\n"),
}
"Could not allocate memory for tools context\n");
goto fini;
}
if (idb & INVALIDATE_USERS) {
ctx->update_user_filter = false;
ctx->update_user_filter = true;
}
if (idb & INVALIDATE_GROUPS) {
ctx->update_group_filter = false;
ctx->update_group_filter = true;
}
if (idb & INVALIDATE_NETGROUPS) {
ctx->update_netgroup_filter = false;
ctx->update_netgroup_filter = true;
}
if (idb & INVALIDATE_SERVICES) {
ctx->update_service_filter = false;
ctx->update_service_filter = true;
}
if (idb & INVALIDATE_AUTOFSMAPS) {
ctx->update_autofs_filter = false;
ctx->update_autofs_filter = true;
}
if (idb & INVALIDATE_SSH_HOSTS) {
ctx->update_ssh_host_filter = false;
ctx->update_ssh_host_filter = true;
}
if (idb & INVALIDATE_SUDO_RULES) {
ctx->update_sudo_rule_filter = false;
ctx->update_sudo_rule_filter = true;
}
goto fini;
}
ERROR("Could not open domain %1$s. If the domain is a subdomain "
"(trusted domain), use fully qualified name instead of "
} else {
ERROR("Could not open available domains\n");
}
"Initialization of sysdb connections failed\n");
goto fini;
}
fini:
}
}
return ret;
}
{
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return true;
}
static errno_t
struct sss_domain_info *domain,
const char *sub_filter, const char **attrs,
{
#ifdef BUILD_AUTOFS
msgs_count, msgs);
#else
return ENOSYS;
#endif /* BUILD_AUTOFS */
}