sss_groupshow.c revision 95cc95749a5e783f2b5d2124d783f85820baf937
/*
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 sss_domain_info *domain,
struct group_info *root,
struct group_info *parent,
const char **group_members,
const int nmembers,
struct group_info ***up_members);
struct sss_domain_info *domain,
const char *name,
const char **memberofs,
const char ***_direct);
struct sss_domain_info *domain,
bool recursive,
const char *name,
struct group_info **res)
{
struct group_info *root;
static const char *attrs[] = GROUP_SHOW_ATTRS;
const char **group_members = NULL;
int nmembers = 0;
int ret;
int i;
/* First, search for the root group */
if (ret) {
goto done;
}
&group_members, &nmembers);
goto done;
}
if (!recursive) {
if (group_members) {
struct group_info *,
nmembers+1);
if (!root->group_members) {
goto done;
}
for (i = 0; i < nmembers; i++) {
if (!root->group_members[i]) {
goto done;
}
group_members[i]);
goto done;
}
}
}
goto done;
}
/* if not recursive, only show the direct parent */
goto done;
}
if (group_members == NULL) {
goto done;
}
&root->group_members);
if (ret) {
goto done;
}
done:
}
return ret;
}
/*=========Nonrecursive search should only show direct parent========== */
struct sss_domain_info *domain,
const char *name,
const char **memberofs,
const char ***_direct)
{
char *filter;
struct ldb_message **msgs;
int ndirect = 0;
int ret;
int i;
if (!dn) {
return ENOMEM;
}
for (i = 0; memberofs[i]; i++) {
SYSDB_NAME, memberofs[i],
if (!filter) {
return ENOMEM;
}
/* ENOENT is OK, the group is just not a direct parent */
return ret;
}
if (count > 0) {
SYSDB_NAME, NULL);
if (!name) {
return EFAULT;
}
const char *, ndirect + 2);
if (!direct) {
return ENOMEM;
}
return ENOMEM;
}
ndirect++;
}
}
return EOK;
}
/*==================Recursive search for nested groups================= */
struct sss_domain_info *domain,
struct group_info *root,
struct group_info *parent,
const char **group_members,
const int nmembers,
struct group_info ***up_members)
{
struct group_info **groups;
static const char *attrs[] = GROUP_SHOW_ATTRS;
struct ldb_message *msg;
const char **new_group_members = NULL;
int new_nmembers = 0;
int ret;
int i;
struct group_info *,
if (!group_members || !group_members[0]) {
return ENOENT;
}
for (i = 0; i < nmembers; i++) {
/* Skip circular groups */
continue;
}
if (ret) {
return EIO;
}
return ret;
}
/* descend to another level */
if (new_nmembers > 0) {
&parent->group_members);
return ret;
}
}
}
*up_members = groups;
return EOK;
}
/*==================Get info about MPG================================= */
struct sss_domain_info *domain,
const char *name,
struct group_info **res)
{
const char *attrs[] = GROUP_SHOW_MPG_ATTRS;
struct ldb_message *msg;
struct group_info *info;
int ret;
if (!info) {
goto fail;
}
if (ret) {
goto fail;
}
SYSDB_NAME, NULL));
goto fail;
}
return EOK;
fail:
return ret;
}
/*==================The main program=================================== */
{
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 = SSSDBG_DEFAULT;
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) {
}
if (pc_groupname == NULL) {
}
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 */
/* Also show MPGs */
}
/* 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 */
print_group_info(root, 0);
if (pc_recursive) {
printf("\n");
} else {
if (root->group_members) {
for (i=0; root->group_members[i]; ++i) {
}
}
printf("\n");
}
fini:
}