sss_groupshow.c revision 7d83d46ff9eb06b294c186a41ad9e7dbe648f5c3
/*
SSSD
sss_groupshow
Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2010
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/tools_util.h"
#include "tools/sss_sync_ops.h"
#define PADDING_SPACES 4
NULL }
SYSDB_NAME, NULL }
struct group_info {
const char *name;
bool mpg;
const char **user_members;
const char **memberofs;
struct group_info **group_members;
};
/*==================Helper routines to process results================= */
{
return NULL;
}
}
struct ldb_message_element *el,
struct group_info *gi)
{
int i;
return ENOMEM;
}
for (i = 0; i< el->num_values; ++i) {
return ENOMEM;
}
}
return EOK;
}
struct ldb_context *ldb,
struct sss_domain_info *domain,
struct ldb_message_element *el,
const char *parent_name,
const char ***user_members,
const char ***group_members,
int *num_group_members)
{
int ret;
int i;
if (!tmp_ctx) {
goto fail;
}
if (!user_basedn || !group_basedn) {
goto fail;
}
goto fail;
}
for (i = 0; i< el->num_values; ++i) {
/* user member or group member? */
goto fail;
}
um_index++;
goto fail;
}
continue;
}
gm_index++;
} else {
goto fail;
}
}
if (um_index > 0) {
if (!um) {
goto fail;
}
} else {
}
if (gm_index > 0) {
if (!gm) {
goto fail;
}
} else {
}
*user_members = um;
*group_members = gm;
return EOK;
fail:
return ret;
}
struct ldb_context *ldb,
struct ldb_message *msg,
struct sss_domain_info *domain,
const char *parent_name,
struct group_info **info,
const char ***group_members,
int *num_group_members)
{
struct ldb_message_element *el;
int ret;
if (!gi) {
goto done;
}
/* mandatory data - name and gid */
NULL));
SYSDB_GIDNUM, 0);
goto done;
}
/* list members */
if (el) {
&gi->user_members,
goto done;
}
}
/* list memberofs */
if (el) {
goto done;
}
}
return EOK;
done:
return ret;
}
/*========Find info about a group and recursively about subgroups====== */
struct group_show_state {
struct tevent_context *ev;
struct sysdb_handle *handle;
struct sss_domain_info *domain;
struct group_info *root;
bool recursive;
};
struct group_show_state *,
struct group_info *,
const char **,
const int );
struct group_info ***);
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
const char *name,
const char **memberofs);
struct tevent_req *req,
const char ***direct);
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
bool recursive,
const char *name)
{
static const char *attrs[] = GROUP_SHOW_ATTRS;
return NULL;
}
/* First, search for the root group */
if (!subreq) {
return NULL;
}
return req;
}
{
struct tevent_req);
struct group_show_state);
int ret;
int i;
const char **group_members = NULL;
int nmembers = 0;
if (ret) {
return;
}
&group_members, &nmembers);
return;
}
if (group_members) {
struct group_info *,
nmembers+1);
for (i=0; group_members[i]; i++) {
struct group_info);
return;
}
group_members[i]);
return;
}
}
}
return;
}
/* if not recursive, only show the direct parent */
if (!subreq) {
return;
}
return;
}
if (group_members == NULL) {
return;
}
nmembers);
if (!subreq) {
return;
}
}
{
struct tevent_req);
struct group_show_state);
int ret;
if (ret) {
return;
}
return;
}
{
struct tevent_req);
struct group_show_state);
int ret;
if (ret) {
return;
}
}
struct tevent_req *req,
struct group_info **res)
{
struct group_show_state);
return EOK;
}
/*=========Nonrecursive search should only show direct parent========== */
struct group_show_trim_state {
const char *name;
const char **all;
int current;
const char **direct;
int ndirect;
struct tevent_context *ev;
struct sysdb_handle *handle;
struct sss_domain_info *domain;
};
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
const char *name,
const char **memberofs)
{
struct group_show_trim_state *state;
int ret;
return NULL;
}
return NULL;
}
if (ret) {
return NULL;
}
return req;
}
{
const char *filter;
struct group_show_trim_state);
if (!filter) {
return ENOMEM;
}
if (!subreq) {
return ENOMEM;
}
return EOK;
}
{
struct tevent_req);
struct group_show_trim_state);
int ret;
struct ldb_message **msgs;
const char *name;
/* ENOENT is OK, the group is just not a direct parent */
return;
}
if (count > 0) {
SYSDB_NAME, NULL);
if (!name) {
return;
}
}
}
}
}
return;
}
}
struct tevent_req *req,
const char ***direct)
{
struct group_show_trim_state);
return EOK;
}
/*==================Recursive search for nested groups================= */
struct group_show_recurse {
const char **names;
int current;
struct group_info *parent;
struct group_show_state *state;
struct group_info **groups;
};
static int group_show_recurse_search(struct tevent_req *,
struct group_show_recurse *);
static void group_show_recurse_next(struct tevent_req *);
static void group_show_recurse_level_done(struct tevent_req *);
static void group_show_recurse_cont(struct tevent_req *);
struct group_show_state *state,
struct group_info *parent,
const char **group_members,
const int nmembers)
{
return NULL;
}
recurse_state->current = 0;
struct group_info *,
if (!recurse_state->names ||
return NULL;
}
return NULL;
}
return req;
}
struct group_show_recurse *recurse_state)
{
static const char *attrs[] = GROUP_SHOW_ATTRS;
/* Skip circular groups */
return EOK;
}
attrs);
if (!subreq) {
return ENOMEM;
}
return EOK;
}
{
struct tevent_req);
struct group_show_recurse);
const char **group_members = NULL;
int nmembers = 0;
int ret;
if (ret) {
return;
}
msg,
&nmembers);
return;
}
/* descend to another level */
if (nmembers > 0) {
if (!recurse_req) {
return;
}
/* to free group_members in the callback */
return;
}
/* Move to next group in the same level */
}
{
int ret;
struct tevent_req);
struct group_show_recurse);
if (ret) {
return;
}
/* Move to next group on the upper level */
}
{
struct group_show_recurse);
int ret;
recurse_state->current++;
return;
}
/* examine next group on the same level */
return;
}
}
struct tevent_req *req,
struct group_info ***out)
{
struct group_show_recurse);
return EOK;
}
/*==================Get info about MPG================================= */
struct group_show_mpg_state {
struct ldb_context *ldb;
struct group_info *info;
};
static void group_show_mpg_done(struct tevent_req *);
struct tevent_context *ev,
struct sysdb_handle *handle,
struct sss_domain_info *domain,
const char *name)
{
struct group_show_mpg_state *state;
static const char *mpg_attrs[] = GROUP_SHOW_MPG_ATTRS;
return NULL;
}
if (!subreq) {
return NULL;
}
return req;
}
{
int ret;
struct tevent_req);
struct group_show_mpg_state);
if (ret) {
return;
}
return;
}
NULL));
return;
}
}
struct tevent_req *req,
struct group_info **res)
{
struct group_show_mpg_state);
return EOK;
}
/*==================The main program=================================== */
struct sss_groupshow_state {
struct group_info *root;
int ret;
bool done;
};
{
int ret;
struct sss_groupshow_state);
}
{
int ret;
struct sss_groupshow_state);
}
{
int i;
char padding[512];
char fmt[8];
g->name);
if (g->user_members) {
for (i=0; g->user_members[i]; ++i) {
g->user_members[i]);
}
}
if (g->memberofs) {
for (i=0; g->memberofs[i]; ++i) {
g->memberofs[i]);
}
}
}
{
int i;
if (group_members == NULL) {
return;
}
level++;
for (i=0; group_members[i]; ++i) {
printf("\n");
printf("\n");
}
}
{
int ret = EXIT_SUCCESS;
int pc_debug = 0;
bool pc_recursive = false;
const char *pc_groupname = NULL;
int i;
struct poptOption long_options[] = {
0, _("The debug level to run with"), NULL },
_("Print indirect group members recursively"), NULL },
};
debug_prg_name = argv[0];
ret = set_locale();
ERROR("Error setting the locale\n");
ret = EXIT_FAILURE;
goto fini;
}
/* parse ops_ctx */
switch (ret) {
case 'r':
pc_recursive = true;
break;
}
}
if (ret != -1) {
ret = EXIT_FAILURE;
goto fini;
}
if (pc_groupname == NULL) {
ret = EXIT_FAILURE;
goto fini;
}
ERROR("Error initializing the tools - no local domain\n");
} else {
ERROR("Error initializing the tools\n");
}
ret = EXIT_FAILURE;
goto fini;
}
/* if the domain was not given as part of FQDN, default to local domain */
ERROR("Invalid domain specified in FQDN\n");
ret = EXIT_FAILURE;
goto fini;
}
/* The search itself */
if (!state) {
goto fini;
}
if (!req) {
ERROR("Cannot initiate search\n");
ret = EXIT_FAILURE;
goto fini;
}
}
/* Also show MPGs */
if (!req) {
ERROR("Cannot initiate search\n");
ret = EXIT_FAILURE;
goto fini;
}
}
}
/* Process result */
if (ret) {
switch (ret) {
case ENOENT:
ERROR("No such group in local domain. "
"Printing groups only allowed in local domain.\n");
break;
default:
ERROR("Internal error. Could not print group.\n");
break;
}
ret = EXIT_FAILURE;
goto fini;
}
/* print the results */
if (pc_recursive) {
printf("\n");
} else {
}
}
printf("\n");
}
fini:
}