summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2015-10-23 13:33:20 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-10-30 11:49:59 +0100
commit6d0a69431a87a24dac04a9d77fbda5a6e24ac0dd (patch)
tree60b8e21934cc48296bcbafae85b0d66e60f2ad0e
parent1b45fed9f629d47fefc3feaba01810ca2200fed3 (diff)
downloadsssd-6d0a69431a87a24dac04a9d77fbda5a6e24ac0dd.tar.gz
sssd-6d0a69431a87a24dac04a9d77fbda5a6e24ac0dd.tar.xz
sssd-6d0a69431a87a24dac04a9d77fbda5a6e24ac0dd.zip
sss_override: add group-find
Resolves: https://fedorahosted.org/sssd/ticket/2736 Reviewed-by: Pavel Reichl <preichl@redhat.com>
-rw-r--r--src/man/sss_override.8.xml13
-rw-r--r--src/tools/sss_override.c150
2 files changed, 114 insertions, 49 deletions
diff --git a/src/man/sss_override.8.xml b/src/man/sss_override.8.xml
index d23bc1c17..36ce119c0 100644
--- a/src/man/sss_override.8.xml
+++ b/src/man/sss_override.8.xml
@@ -175,6 +175,19 @@
</varlistentry>
<varlistentry>
<term>
+ <option>group-find</option>
+ <optional><option>-d,--domain</option> DOMAIN</optional>
+ </term>
+ <listitem>
+ <para>
+ List all groups with set overrides.
+ If <emphasis>DOMAIN</emphasis> parameter is set,
+ only groups from the domain are listed.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
<option>group-import</option>
<emphasis>FILE</emphasis>
</term>
diff --git a/src/tools/sss_override.c b/src/tools/sss_override.c
index f438f92d6..0f45fbeae 100644
--- a/src/tools/sss_override.c
+++ b/src/tools/sss_override.c
@@ -1186,6 +1186,70 @@ done:
return ret;
}
+static errno_t group_export(const char *filename,
+ struct sss_domain_info *dom,
+ bool iterate)
+{
+ TALLOC_CTX *tmp_ctx;
+ struct sss_colondb *db;
+ struct override_group *objs;
+ errno_t ret;
+ int i;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
+ return ENOMEM;
+ }
+
+
+ db = sss_colondb_open(tmp_ctx, SSS_COLONDB_WRITE, filename);
+ if (db == NULL) {
+ fprintf(stderr, _("Unable to open %s.\n"),
+ filename == NULL ? "stdout" : filename);
+ ret = EIO;
+ goto done;
+ }
+
+ do {
+ objs = list_group_overrides(tmp_ctx, dom);
+ if (objs == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get override objects\n");
+ ret = ENOMEM;
+ goto done;
+ }
+
+ for (i = 0; objs[i].orig_name != NULL; i++) {
+ /**
+ * Format: orig_name:name:gid
+ */
+ struct sss_colondb_write_field table[] = {
+ {SSS_COLONDB_STRING, {.str = objs[i].orig_name}},
+ {SSS_COLONDB_STRING, {.str = objs[i].name}},
+ {SSS_COLONDB_UINT32, {.uint32 = objs[i].gid}},
+ {SSS_COLONDB_SENTINEL, {0}}
+ };
+
+ ret = sss_colondb_writeline(db, table);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to write line to db\n");
+ goto done;
+ }
+ }
+
+ /* All overrides are under the same subtree, so we don't want to
+ * descent into subdomains. */
+ dom = get_next_domain(dom, false);
+ } while (dom != NULL && iterate);
+
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+
+ return ret;
+}
+
static int override_user_add(struct sss_cmdline *cmdline,
struct sss_tool_ctx *tool_ctx,
void *pvt)
@@ -1431,6 +1495,36 @@ static int override_group_del(struct sss_cmdline *cmdline,
return EXIT_SUCCESS;
}
+static int override_group_find(struct sss_cmdline *cmdline,
+ struct sss_tool_ctx *tool_ctx,
+ void *pvt)
+{
+ struct sss_domain_info *dom;
+ bool iterate;
+ errno_t ret;
+
+ ret = parse_cmdline_find(cmdline, tool_ctx, &dom);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command line.\n");
+ return EXIT_FAILURE;
+ }
+
+ if (dom == NULL) {
+ dom = tool_ctx->domains;
+ iterate = true;
+ } else {
+ iterate = false;
+ }
+
+ ret = group_export(NULL, dom, iterate);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to export groups\n");
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
static int override_group_import(struct sss_cmdline *cmdline,
struct sss_tool_ctx *tool_ctx,
void *pvt)
@@ -1517,65 +1611,22 @@ static int override_group_export(struct sss_cmdline *cmdline,
struct sss_tool_ctx *tool_ctx,
void *pvt)
{
- struct sss_colondb *db;
const char *filename;
- struct override_group *objs;
- struct sss_domain_info *dom;
errno_t ret;
- int exit;
- int i;
ret = parse_cmdline_export(cmdline, &filename);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command line.\n");
- exit = EXIT_FAILURE;
- goto done;
+ return EXIT_FAILURE;
}
- db = sss_colondb_open(tool_ctx, SSS_COLONDB_WRITE, filename);
- if (db == NULL) {
- fprintf(stderr, _("Unable to open %s.\n"), filename);
- exit = EXIT_FAILURE;
- goto done;
+ ret = group_export(filename, tool_ctx->domains, true);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to export groups\n");
+ return EXIT_FAILURE;
}
- dom = tool_ctx->domains;
- do {
- objs = list_group_overrides(tool_ctx, dom);
- if (objs == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get override objects\n");
- exit = EXIT_FAILURE;
- goto done;
- }
-
- for (i = 0; objs[i].orig_name != NULL; i++) {
- /**
- * Format: orig_name:name:gid
- */
- struct sss_colondb_write_field table[] = {
- {SSS_COLONDB_STRING, {.str = objs[i].orig_name}},
- {SSS_COLONDB_STRING, {.str = objs[i].name}},
- {SSS_COLONDB_UINT32, {.uint32 = objs[i].gid}},
- {SSS_COLONDB_SENTINEL, {0}}
- };
-
- ret = sss_colondb_writeline(db, table);
- if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Unable to write line to db\n");
- exit = EXIT_FAILURE;
- goto done;
- }
- }
-
- /* All overrides are under the same subtree, so we don't want to
- * descent into subdomains. */
- dom = get_next_domain(dom, 0);
- } while (dom != NULL);
-
- exit = EXIT_SUCCESS;
-
-done:
- return exit;
+ return EXIT_SUCCESS;
}
int main(int argc, const char **argv)
@@ -1588,6 +1639,7 @@ int main(int argc, const char **argv)
{"user-export", override_user_export},
{"group-add", override_group_add},
{"group-del", override_group_del},
+ {"group-find", override_group_find},
{"group-import", override_group_import},
{"group-export", override_group_export},
{NULL, NULL}