|
|
6cf099 |
From a3b608a72f2cba3cece3a28dbc1c5d532d91ce14 Mon Sep 17 00:00:00 2001
|
|
|
6cf099 |
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
|
|
|
6cf099 |
Date: Fri, 24 Jul 2015 09:58:11 +0200
|
|
|
6cf099 |
Subject: [PATCH 23/23] TOOLS: add sss_override for local overrides
|
|
|
6cf099 |
|
|
|
6cf099 |
Resolves:
|
|
|
6cf099 |
https://fedorahosted.org/sssd/ticket/2584
|
|
|
6cf099 |
|
|
|
6cf099 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
6cf099 |
---
|
|
|
6cf099 |
Makefile.am | 16 +-
|
|
|
6cf099 |
contrib/sssd.spec.in | 2 +
|
|
|
6cf099 |
src/man/Makefile.am | 1 +
|
|
|
6cf099 |
src/man/po/po4a.cfg | 1 +
|
|
|
6cf099 |
src/man/sss_override.8.xml | 108 +++++++
|
|
|
6cf099 |
src/tools/sss_override.c | 718 +++++++++++++++++++++++++++++++++++++++++++++
|
|
|
6cf099 |
6 files changed, 845 insertions(+), 1 deletion(-)
|
|
|
6cf099 |
create mode 100644 src/man/sss_override.8.xml
|
|
|
6cf099 |
create mode 100644 src/tools/sss_override.c
|
|
|
6cf099 |
|
|
|
6cf099 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
6cf099 |
index 1edecc483c61d04562b7bfd9086146e93963b74e..912bfc6641465ef5cd2ff2cce9975b4027c3218d 100644
|
|
|
6cf099 |
--- a/Makefile.am
|
|
|
6cf099 |
+++ b/Makefile.am
|
|
|
6cf099 |
@@ -117,7 +117,9 @@ sbin_PROGRAMS = \
|
|
|
6cf099 |
sss_groupshow \
|
|
|
6cf099 |
sss_cache \
|
|
|
6cf099 |
sss_debuglevel \
|
|
|
6cf099 |
- sss_seed
|
|
|
6cf099 |
+ sss_override \
|
|
|
6cf099 |
+ sss_seed \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
|
|
|
6cf099 |
sssdlibexec_PROGRAMS = \
|
|
|
6cf099 |
sssd_nss \
|
|
|
6cf099 |
@@ -1297,6 +1299,18 @@ sss_signal_LDADD = \
|
|
|
6cf099 |
$(SSSD_INTERNAL_LTLIBS) \
|
|
|
6cf099 |
$(NULL)
|
|
|
6cf099 |
|
|
|
6cf099 |
+sss_override_SOURCES = \
|
|
|
6cf099 |
+ src/tools/sss_override.c \
|
|
|
6cf099 |
+ $(SSSD_TOOLS_OBJ) \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
+sss_override_LDADD = \
|
|
|
6cf099 |
+ $(TOOLS_LIBS) \
|
|
|
6cf099 |
+ $(SSSD_INTERNAL_LTLIBS) \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
+sss_override_CFLAGS = \
|
|
|
6cf099 |
+ $(AM_CFLAGS) \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
+
|
|
|
6cf099 |
if BUILD_SUDO
|
|
|
6cf099 |
sss_sudo_cli_SOURCES = \
|
|
|
6cf099 |
src/sss_client/common.c \
|
|
|
6cf099 |
diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
|
|
|
6cf099 |
index 15f7c582cba1b9052e180596625be7dd5749599f..f050501ff9d0711a0da7f094ee968cae87a3f49b 100644
|
|
|
6cf099 |
--- a/contrib/sssd.spec.in
|
|
|
6cf099 |
+++ b/contrib/sssd.spec.in
|
|
|
6cf099 |
@@ -837,6 +837,7 @@ rm -rf $RPM_BUILD_ROOT
|
|
|
6cf099 |
%{_sbindir}/sss_groupmod
|
|
|
6cf099 |
%{_sbindir}/sss_groupshow
|
|
|
6cf099 |
%{_sbindir}/sss_obfuscate
|
|
|
6cf099 |
+%{_sbindir}/sss_override
|
|
|
6cf099 |
%{_sbindir}/sss_debuglevel
|
|
|
6cf099 |
%{_sbindir}/sss_seed
|
|
|
6cf099 |
%{_mandir}/man8/sss_groupadd.8*
|
|
|
6cf099 |
@@ -847,6 +848,7 @@ rm -rf $RPM_BUILD_ROOT
|
|
|
6cf099 |
%{_mandir}/man8/sss_userdel.8*
|
|
|
6cf099 |
%{_mandir}/man8/sss_usermod.8*
|
|
|
6cf099 |
%{_mandir}/man8/sss_obfuscate.8*
|
|
|
6cf099 |
+%{_mandir}/man8/sss_override.8*
|
|
|
6cf099 |
%{_mandir}/man8/sss_debuglevel.8*
|
|
|
6cf099 |
%{_mandir}/man8/sss_seed.8*
|
|
|
6cf099 |
|
|
|
6cf099 |
diff --git a/src/man/Makefile.am b/src/man/Makefile.am
|
|
|
6cf099 |
index 1ef1da48cce74f7d1ad77e3751ee6ac3450f0259..70cadf5951f56b78ff0bfbcb303e255478af5fec 100644
|
|
|
6cf099 |
--- a/src/man/Makefile.am
|
|
|
6cf099 |
+++ b/src/man/Makefile.am
|
|
|
6cf099 |
@@ -51,6 +51,7 @@ man_MANS = \
|
|
|
6cf099 |
sssd-krb5.5 sssd-simple.5 \
|
|
|
6cf099 |
sssd_krb5_locator_plugin.8 sss_groupshow.8 \
|
|
|
6cf099 |
pam_sss.8 sss_obfuscate.8 sss_cache.8 sss_debuglevel.8 sss_seed.8 \
|
|
|
6cf099 |
+ sss_override.8
|
|
|
6cf099 |
$(NULL)
|
|
|
6cf099 |
|
|
|
6cf099 |
if BUILD_SAMBA
|
|
|
6cf099 |
diff --git a/src/man/po/po4a.cfg b/src/man/po/po4a.cfg
|
|
|
6cf099 |
index 25d20c6f0c23a0900469573d47ab96ebc8898e50..67e87ba7006f0bb1346e5b845428f2bed1a324db 100644
|
|
|
6cf099 |
--- a/src/man/po/po4a.cfg
|
|
|
6cf099 |
+++ b/src/man/po/po4a.cfg
|
|
|
6cf099 |
@@ -11,6 +11,7 @@
|
|
|
6cf099 |
[type:docbook] sssd-sudo.5.xml $lang:$(builddir)/$lang/sssd-sudo.5.xml
|
|
|
6cf099 |
[type:docbook] sssd.8.xml $lang:$(builddir)/$lang/sssd.8.xml
|
|
|
6cf099 |
[type:docbook] sss_obfuscate.8.xml $lang:$(builddir)/$lang/sss_obfuscate.8.xml
|
|
|
6cf099 |
+[type:docbook] sss_override.8.xml $lang:$(builddir)/$lang/sss_override.8.xml
|
|
|
6cf099 |
[type:docbook] sss_useradd.8.xml $lang:$(builddir)/$lang/sss_useradd.8.xml
|
|
|
6cf099 |
[type:docbook] sssd-krb5.5.xml $lang:$(builddir)/$lang/sssd-krb5.5.xml
|
|
|
6cf099 |
[type:docbook] sss_groupadd.8.xml $lang:$(builddir)/$lang/sss_groupadd.8.xml
|
|
|
6cf099 |
diff --git a/src/man/sss_override.8.xml b/src/man/sss_override.8.xml
|
|
|
6cf099 |
new file mode 100644
|
|
|
6cf099 |
index 0000000000000000000000000000000000000000..ec9a7bb75c13f4f18ece7f5f84baede14a8a1e2e
|
|
|
6cf099 |
--- /dev/null
|
|
|
6cf099 |
+++ b/src/man/sss_override.8.xml
|
|
|
6cf099 |
@@ -0,0 +1,108 @@
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
|
|
6cf099 |
+<reference>
|
|
|
6cf099 |
+<title>SSSD Manual pages</title>
|
|
|
6cf099 |
+<refentry>
|
|
|
6cf099 |
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="include/upstream.xml" />
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ <refmeta>
|
|
|
6cf099 |
+ <refentrytitle>sss_override</refentrytitle>
|
|
|
6cf099 |
+ <manvolnum>8</manvolnum>
|
|
|
6cf099 |
+ </refmeta>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ <refnamediv id='name'>
|
|
|
6cf099 |
+ <refname>sss_override</refname>
|
|
|
6cf099 |
+ <refpurpose>create local overrides of user and group attributes</refpurpose>
|
|
|
6cf099 |
+ </refnamediv>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ <refsynopsisdiv id='synopsis'>
|
|
|
6cf099 |
+ <cmdsynopsis>
|
|
|
6cf099 |
+ <command>sss_override</command>
|
|
|
6cf099 |
+ <arg choice='plain'><replaceable>COMMAND</replaceable></arg>
|
|
|
6cf099 |
+ <arg choice='opt'>
|
|
|
6cf099 |
+ <replaceable>options</replaceable>
|
|
|
6cf099 |
+ </arg>
|
|
|
6cf099 |
+ </cmdsynopsis>
|
|
|
6cf099 |
+ </refsynopsisdiv>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ <refsect1 id='description'>
|
|
|
6cf099 |
+ <title>DESCRIPTION</title>
|
|
|
6cf099 |
+ <para>
|
|
|
6cf099 |
+ <command>sss_override</command> enables to create a client-side
|
|
|
6cf099 |
+ view and allows to change selected values of specific user
|
|
|
6cf099 |
+ and groups. This change takes effect only on local machine.
|
|
|
6cf099 |
+ </para>
|
|
|
6cf099 |
+ <para>
|
|
|
6cf099 |
+ Overrides data are stored in SSSD cache. If the cache is deleted
|
|
|
6cf099 |
+ all local overrides are lost.
|
|
|
6cf099 |
+ </para>
|
|
|
6cf099 |
+ </refsect1>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ <refsect1 id='commands'>
|
|
|
6cf099 |
+ <title>AVAILABLE COMMANDS</title>
|
|
|
6cf099 |
+ <para>
|
|
|
6cf099 |
+ Argument <emphasis>NAME</emphasis> is the name of original object
|
|
|
6cf099 |
+ in all commands. It is not possible to override
|
|
|
6cf099 |
+ <emphasis>uid</emphasis> or <emphasis>gid</emphasis> to 0.
|
|
|
6cf099 |
+ </para>
|
|
|
6cf099 |
+ <variablelist remap='IP'>
|
|
|
6cf099 |
+ <varlistentry>
|
|
|
6cf099 |
+ <term>
|
|
|
6cf099 |
+ <option>user-add</option>
|
|
|
6cf099 |
+ <emphasis>NAME</emphasis>
|
|
|
6cf099 |
+ <optional><option>-n,--name</option> NAME</optional>
|
|
|
6cf099 |
+ <optional><option>-u,--uid</option> UID</optional>
|
|
|
6cf099 |
+ <optional><option>-g,--gid</option> GID</optional>
|
|
|
6cf099 |
+ <optional><option>-h,--home</option> HOME</optional>
|
|
|
6cf099 |
+ <optional><option>-s,--shell</option> SHELL</optional>
|
|
|
6cf099 |
+ <optional><option>-c,--gecos</option> GECOS</optional>
|
|
|
6cf099 |
+ </term>
|
|
|
6cf099 |
+ <listitem>
|
|
|
6cf099 |
+ <para>
|
|
|
6cf099 |
+ Override attributes of an user.
|
|
|
6cf099 |
+ </para>
|
|
|
6cf099 |
+ </listitem>
|
|
|
6cf099 |
+ </varlistentry>
|
|
|
6cf099 |
+ <varlistentry>
|
|
|
6cf099 |
+ <term>
|
|
|
6cf099 |
+ <option>user-del</option>
|
|
|
6cf099 |
+ <emphasis>NAME</emphasis>
|
|
|
6cf099 |
+ </term>
|
|
|
6cf099 |
+ <listitem>
|
|
|
6cf099 |
+ <para>
|
|
|
6cf099 |
+ Remove user overrides.
|
|
|
6cf099 |
+ </para>
|
|
|
6cf099 |
+ </listitem>
|
|
|
6cf099 |
+ </varlistentry>
|
|
|
6cf099 |
+ <varlistentry>
|
|
|
6cf099 |
+ <term>
|
|
|
6cf099 |
+ <option>group-add</option>
|
|
|
6cf099 |
+ <emphasis>NAME</emphasis>
|
|
|
6cf099 |
+ <optional><option>-n,--name</option> NAME</optional>
|
|
|
6cf099 |
+ <optional><option>-g,--gid</option> GID</optional>
|
|
|
6cf099 |
+ </term>
|
|
|
6cf099 |
+ <listitem>
|
|
|
6cf099 |
+ <para>
|
|
|
6cf099 |
+ Override attributes of a group.
|
|
|
6cf099 |
+ </para>
|
|
|
6cf099 |
+ </listitem>
|
|
|
6cf099 |
+ </varlistentry>
|
|
|
6cf099 |
+ <varlistentry>
|
|
|
6cf099 |
+ <term>
|
|
|
6cf099 |
+ <option>group-del</option>
|
|
|
6cf099 |
+ <emphasis>NAME</emphasis>
|
|
|
6cf099 |
+ </term>
|
|
|
6cf099 |
+ <listitem>
|
|
|
6cf099 |
+ <para>
|
|
|
6cf099 |
+ Remove group overrides.
|
|
|
6cf099 |
+ </para>
|
|
|
6cf099 |
+ </listitem>
|
|
|
6cf099 |
+ </varlistentry>
|
|
|
6cf099 |
+ </variablelist>
|
|
|
6cf099 |
+ </refsect1>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="include/seealso.xml" />
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+</refentry>
|
|
|
6cf099 |
+</reference>
|
|
|
6cf099 |
diff --git a/src/tools/sss_override.c b/src/tools/sss_override.c
|
|
|
6cf099 |
new file mode 100644
|
|
|
6cf099 |
index 0000000000000000000000000000000000000000..5e901e2e31de64dacb171337defc03d428f8ed57
|
|
|
6cf099 |
--- /dev/null
|
|
|
6cf099 |
+++ b/src/tools/sss_override.c
|
|
|
6cf099 |
@@ -0,0 +1,718 @@
|
|
|
6cf099 |
+/*
|
|
|
6cf099 |
+ Authors:
|
|
|
6cf099 |
+ Pavel Březina <pbrezina@redhat.com>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ Copyright (C) 2015 Red Hat
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
6cf099 |
+ it under the terms of the GNU General Public License as published by
|
|
|
6cf099 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
6cf099 |
+ (at your option) any later version.
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ This program is distributed in the hope that it will be useful,
|
|
|
6cf099 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6cf099 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6cf099 |
+ GNU General Public License for more details.
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ You should have received a copy of the GNU General Public License
|
|
|
6cf099 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
6cf099 |
+*/
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#include <stdlib.h>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#include "util/util.h"
|
|
|
6cf099 |
+#include "db/sysdb.h"
|
|
|
6cf099 |
+#include "tools/common/sss_tools.h"
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#define LOCALVIEW SYSDB_LOCAL_VIEW_NAME
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+struct override_user {
|
|
|
6cf099 |
+ const char *input_name;
|
|
|
6cf099 |
+ const char *orig_name;
|
|
|
6cf099 |
+ struct sss_domain_info *domain;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ const char *name;
|
|
|
6cf099 |
+ uid_t uid;
|
|
|
6cf099 |
+ gid_t gid;
|
|
|
6cf099 |
+ const char *home;
|
|
|
6cf099 |
+ const char *shell;
|
|
|
6cf099 |
+ const char *gecos;
|
|
|
6cf099 |
+};
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+struct override_group {
|
|
|
6cf099 |
+ const char *input_name;
|
|
|
6cf099 |
+ const char *orig_name;
|
|
|
6cf099 |
+ struct sss_domain_info *domain;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ const char *name;
|
|
|
6cf099 |
+ gid_t gid;
|
|
|
6cf099 |
+};
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int parse_cmdline(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ struct poptOption *options,
|
|
|
6cf099 |
+ const char **_input_name,
|
|
|
6cf099 |
+ const char **_orig_name,
|
|
|
6cf099 |
+ struct sss_domain_info **_domain)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ enum sss_tool_opt require;
|
|
|
6cf099 |
+ const char *input_name;
|
|
|
6cf099 |
+ const char *orig_name;
|
|
|
6cf099 |
+ struct sss_domain_info *domain;
|
|
|
6cf099 |
+ int ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ require = options == NULL ? SSS_TOOL_OPT_OPTIONAL : SSS_TOOL_OPT_REQUIRED;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sss_tool_popt_ex(cmdline, options, require,
|
|
|
6cf099 |
+ NULL, NULL, "NAME", _("Specify name of modified "
|
|
|
6cf099 |
+ "object."), &input_name);
|
|
|
6cf099 |
+ if (ret != EXIT_SUCCESS) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
|
|
|
6cf099 |
+ return ret;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sss_tool_parse_name(tool_ctx, tool_ctx, input_name,
|
|
|
6cf099 |
+ &orig_name, &domain);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Unable to parse name.\n"));
|
|
|
6cf099 |
+ return ret;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ *_input_name = input_name;
|
|
|
6cf099 |
+ *_orig_name = orig_name;
|
|
|
6cf099 |
+ *_domain = domain;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return EXIT_SUCCESS;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int parse_cmdline_user_add(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ struct override_user *user)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct poptOption options[] = {
|
|
|
6cf099 |
+ POPT_AUTOHELP
|
|
|
6cf099 |
+ {"name", 'n', POPT_ARG_STRING, &user->name, 0, _("Override name"), NULL },
|
|
|
6cf099 |
+ {"uid", 'u', POPT_ARG_INT, &user->uid, 0, _("Override uid (non-zero value)"), NULL },
|
|
|
6cf099 |
+ {"gid", 'g', POPT_ARG_INT, &user->gid, 0, _("Override gid (non-zero value)"), NULL },
|
|
|
6cf099 |
+ {"home", 'h', POPT_ARG_STRING, &user->home, 0, _("Override home directory"), NULL },
|
|
|
6cf099 |
+ {"shell", 's', POPT_ARG_STRING, &user->shell, 0, _("Override shell"), NULL },
|
|
|
6cf099 |
+ {"gecos", 'c', POPT_ARG_STRING, &user->gecos, 0, _("Override gecos"), NULL },
|
|
|
6cf099 |
+ POPT_TABLEEND
|
|
|
6cf099 |
+ };
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return parse_cmdline(cmdline, tool_ctx, options, &user->input_name,
|
|
|
6cf099 |
+ &user->orig_name, &user->domain);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int parse_cmdline_user_del(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ struct override_user *user)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ return parse_cmdline(cmdline, tool_ctx, NULL, &user->input_name,
|
|
|
6cf099 |
+ &user->orig_name, &user->domain);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int parse_cmdline_group_add(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ struct override_group *group)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct poptOption options[] = {
|
|
|
6cf099 |
+ POPT_AUTOHELP
|
|
|
6cf099 |
+ {"name", 'n', POPT_ARG_STRING, &group->name, 0, _("Override name"), NULL },
|
|
|
6cf099 |
+ {"gid", 'g', POPT_ARG_INT, &group->gid, 0, _("Override gid"), NULL },
|
|
|
6cf099 |
+ POPT_TABLEEND
|
|
|
6cf099 |
+ };
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return parse_cmdline(cmdline, tool_ctx, options, &group->input_name,
|
|
|
6cf099 |
+ &group->orig_name, &group->domain);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int parse_cmdline_group_del(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ struct override_group *group)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ return parse_cmdline(cmdline, tool_ctx, NULL, &group->input_name,
|
|
|
6cf099 |
+ &group->orig_name, &group->domain);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static errno_t prepare_view(struct sss_domain_info *domain)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ char *viewname = NULL;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_get_view_name(NULL, domain->sysdb, &viewname);
|
|
|
6cf099 |
+ if (ret != EOK && ret != ENOENT) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_get_view_name() failed.\n");
|
|
|
6cf099 |
+ return ret;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (ret == EOK) {
|
|
|
6cf099 |
+ if (is_local_view(viewname)) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "%s view is already present.\n", viewname);
|
|
|
6cf099 |
+ ret = EOK;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ } else if (viewname != NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_MINOR_FAILURE, "There already exists view %s. "
|
|
|
6cf099 |
+ "Only one view is supported. Nothing to do.\n", viewname);
|
|
|
6cf099 |
+ ret = EEXIST;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Creating %s view.\n", LOCALVIEW);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_update_view_name(domain->sysdb, LOCALVIEW);
|
|
|
6cf099 |
+ if (ret == EOK) {
|
|
|
6cf099 |
+ printf("SSSD needs to be restarted for the changes to take effect.\n");
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ talloc_free(viewname);
|
|
|
6cf099 |
+ return ret;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static char *build_anchor(TALLOC_CTX *mem_ctx, const char *obj_dn)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ char *anchor;
|
|
|
6cf099 |
+ char *safe_dn;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_dn_sanitize(mem_ctx, obj_dn, &safe_dn);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_dn_sanitize() failed\n");
|
|
|
6cf099 |
+ return NULL;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ anchor = talloc_asprintf(mem_ctx, ":%s:%s", LOCALVIEW, safe_dn);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ talloc_free(safe_dn);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return anchor;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static struct sysdb_attrs *build_attrs(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ const char *name,
|
|
|
6cf099 |
+ uid_t uid,
|
|
|
6cf099 |
+ gid_t gid,
|
|
|
6cf099 |
+ const char *home,
|
|
|
6cf099 |
+ const char *shell,
|
|
|
6cf099 |
+ const char *gecos)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct sysdb_attrs *attrs;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ attrs = sysdb_new_attrs(mem_ctx);
|
|
|
6cf099 |
+ if (attrs == NULL) {
|
|
|
6cf099 |
+ return NULL;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (name != NULL) {
|
|
|
6cf099 |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (uid != 0) {
|
|
|
6cf099 |
+ ret = sysdb_attrs_add_uint32(attrs, SYSDB_UIDNUM, uid);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (gid != 0) {
|
|
|
6cf099 |
+ ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, gid);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (home != NULL) {
|
|
|
6cf099 |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_HOMEDIR, home);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (shell != NULL) {
|
|
|
6cf099 |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_SHELL, shell);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (gecos != NULL) {
|
|
|
6cf099 |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_GECOS, gecos);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = EOK;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ talloc_free(attrs);
|
|
|
6cf099 |
+ return NULL;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return attrs;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static struct sysdb_attrs *build_user_attrs(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ struct override_user *user)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ return build_attrs(mem_ctx, user->name, user->uid, user->gid, user->home,
|
|
|
6cf099 |
+ user->shell, user->gecos);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static struct sysdb_attrs *build_group_attrs(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ struct override_group *group)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ return build_attrs(mem_ctx, group->name, 0, group->gid, 0, NULL, NULL);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static const char *get_object_dn_and_domain(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ enum sysdb_member_type type,
|
|
|
6cf099 |
+ const char *name,
|
|
|
6cf099 |
+ struct sss_domain_info *domain,
|
|
|
6cf099 |
+ struct sss_domain_info *domains,
|
|
|
6cf099 |
+ struct sss_domain_info **_new_domain)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
6cf099 |
+ struct sss_domain_info *dom;
|
|
|
6cf099 |
+ struct ldb_result *res;
|
|
|
6cf099 |
+ const char *dn;
|
|
|
6cf099 |
+ const char *strtype;
|
|
|
6cf099 |
+ bool check_next;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
6cf099 |
+ if (tmp_ctx == NULL) {
|
|
|
6cf099 |
+ return NULL;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* Ensure that the object is in cache. */
|
|
|
6cf099 |
+ switch (type) {
|
|
|
6cf099 |
+ case SYSDB_MEMBER_USER:
|
|
|
6cf099 |
+ if (getpwnam(name) == NULL) {
|
|
|
6cf099 |
+ ret = ENOENT;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ case SYSDB_MEMBER_GROUP:
|
|
|
6cf099 |
+ if (getgrnam(name) == NULL) {
|
|
|
6cf099 |
+ ret = ENOENT;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ default:
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported member type %d\n", type);
|
|
|
6cf099 |
+ ret = ERR_INTERNAL;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* Find domain if it is unknown. */
|
|
|
6cf099 |
+ if (domain == NULL) {
|
|
|
6cf099 |
+ check_next = true;
|
|
|
6cf099 |
+ dom = domains;
|
|
|
6cf099 |
+ } else {
|
|
|
6cf099 |
+ check_next = false;
|
|
|
6cf099 |
+ dom = domain;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ do {
|
|
|
6cf099 |
+ switch (type) {
|
|
|
6cf099 |
+ case SYSDB_MEMBER_USER:
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Trying to find user %s@%s\n",
|
|
|
6cf099 |
+ name, dom->name);
|
|
|
6cf099 |
+ ret = sysdb_getpwnam(tmp_ctx, dom, name, &res;;
|
|
|
6cf099 |
+ strtype = "user";
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ case SYSDB_MEMBER_GROUP:
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Trying to find group %s@%s\n",
|
|
|
6cf099 |
+ name, dom->name);
|
|
|
6cf099 |
+ ret = sysdb_getgrnam(tmp_ctx, dom, name, &res;;
|
|
|
6cf099 |
+ strtype = "group";
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ default:
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported member type %d\n", type);
|
|
|
6cf099 |
+ ret = ERR_INTERNAL;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (ret == EOK && res->count == 0) {
|
|
|
6cf099 |
+ ret = ENOENT;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (check_next) {
|
|
|
6cf099 |
+ dom = dom->next;
|
|
|
6cf099 |
+ continue;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to find %s %s@%s [%d]: %s\n",
|
|
|
6cf099 |
+ strtype, name, dom->name, ret, sss_strerror(ret));
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ } else if (res->count != 1) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "More than one %s found?\n", strtype);
|
|
|
6cf099 |
+ ret = ERR_INTERNAL;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ check_next = false;
|
|
|
6cf099 |
+ } while (check_next && dom != NULL);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (dom == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "No domain match for %s\n", name);
|
|
|
6cf099 |
+ ret = ENOENT;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Domain of %s %s is %s\n",
|
|
|
6cf099 |
+ strtype, name, dom->name);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dn = ldb_dn_get_linearized(res->msgs[0]->dn);
|
|
|
6cf099 |
+ if (dn == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "ldb_dn_get_linearized() failed.\n");
|
|
|
6cf099 |
+ ret = ENOMEM;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ talloc_steal(mem_ctx, dn);
|
|
|
6cf099 |
+ *_new_domain = dom;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = EOK;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ talloc_free(tmp_ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ return NULL;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return dn;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static const char * get_user_dn_and_domain(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ struct sss_domain_info *domains,
|
|
|
6cf099 |
+ struct override_user *user)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ return get_object_dn_and_domain(mem_ctx, SYSDB_MEMBER_USER,
|
|
|
6cf099 |
+ user->orig_name, user->domain, domains,
|
|
|
6cf099 |
+ &user->domain);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static const char * get_group_dn_and_domain(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ struct sss_domain_info *domains,
|
|
|
6cf099 |
+ struct override_group *group)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ return get_object_dn_and_domain(mem_ctx, SYSDB_MEMBER_GROUP,
|
|
|
6cf099 |
+ group->orig_name, group->domain, domains,
|
|
|
6cf099 |
+ &group->domain);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static errno_t override_object_add(struct sss_domain_info *domain,
|
|
|
6cf099 |
+ enum sysdb_member_type type,
|
|
|
6cf099 |
+ struct sysdb_attrs *attrs,
|
|
|
6cf099 |
+ const char *obj_dn)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
6cf099 |
+ const char *anchor;
|
|
|
6cf099 |
+ struct ldb_dn *ldb_dn;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
6cf099 |
+ if (tmp_ctx == NULL) {
|
|
|
6cf099 |
+ return ENOMEM;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ldb_dn = ldb_dn_new(tmp_ctx, sysdb_ctx_get_ldb(domain->sysdb), obj_dn);
|
|
|
6cf099 |
+ if (ldb_dn == NULL) {
|
|
|
6cf099 |
+ ret = ENOMEM;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ anchor = build_anchor(tmp_ctx, obj_dn);
|
|
|
6cf099 |
+ if (anchor == NULL) {
|
|
|
6cf099 |
+ ret = ENOMEM;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID, anchor);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Creating override for %s\n", obj_dn);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_store_override(domain, LOCALVIEW, type, attrs, ldb_dn);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ talloc_free(tmp_ctx);
|
|
|
6cf099 |
+ return ret;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static errno_t override_object_del(struct sss_domain_info *domain,
|
|
|
6cf099 |
+ const char *obj_dn)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
6cf099 |
+ const char *anchor;
|
|
|
6cf099 |
+ struct ldb_dn *override_dn;
|
|
|
6cf099 |
+ struct ldb_message *msg;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+ int sret;
|
|
|
6cf099 |
+ bool in_transaction = false;
|
|
|
6cf099 |
+ struct ldb_context *ldb = sysdb_ctx_get_ldb(domain->sysdb);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
6cf099 |
+ if (tmp_ctx == NULL) {
|
|
|
6cf099 |
+ return ENOMEM;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ anchor = build_anchor(tmp_ctx, obj_dn);
|
|
|
6cf099 |
+ if (anchor == NULL) {
|
|
|
6cf099 |
+ ret = ENOMEM;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ override_dn = ldb_dn_new_fmt(tmp_ctx, ldb,
|
|
|
6cf099 |
+ SYSDB_TMPL_OVERRIDE, anchor, LOCALVIEW);
|
|
|
6cf099 |
+ if (override_dn == NULL) {
|
|
|
6cf099 |
+ ret = ENOMEM;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_FUNC, "Removing override for %s\n", obj_dn);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_transaction_start(domain->sysdb);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_transaction_start() failed.\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ in_transaction = true;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_delete_entry(domain->sysdb, override_dn, true);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_delete_entry() failed.\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ msg = ldb_msg_new(tmp_ctx);
|
|
|
6cf099 |
+ if (msg == NULL) {
|
|
|
6cf099 |
+ ret = ENOMEM;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ msg->dn = ldb_dn_new(msg, ldb, obj_dn);
|
|
|
6cf099 |
+ if (msg->dn == NULL) {
|
|
|
6cf099 |
+ ret = ENOMEM;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = ldb_msg_add_empty(msg, SYSDB_OVERRIDE_DN, LDB_FLAG_MOD_DELETE, NULL);
|
|
|
6cf099 |
+ if (ret != LDB_SUCCESS) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "ldb_msg_add_empty() failed\n");
|
|
|
6cf099 |
+ ret = sysdb_error_to_errno(ret);
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = ldb_modify(ldb, msg);
|
|
|
6cf099 |
+ if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_ATTRIBUTE) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
6cf099 |
+ "ldb_modify() failed: [%s](%d)[%s]\n",
|
|
|
6cf099 |
+ ldb_strerror(ret), ret, ldb_errstring(ldb));
|
|
|
6cf099 |
+ ret = sysdb_error_to_errno(ret);
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = sysdb_transaction_commit(domain->sysdb);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ in_transaction = false;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = EOK;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ if (in_transaction) {
|
|
|
6cf099 |
+ sret = sysdb_transaction_cancel(domain->sysdb);
|
|
|
6cf099 |
+ if (sret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Could not cancel transaction\n");
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ talloc_free(tmp_ctx);
|
|
|
6cf099 |
+ return ret;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int override_user_add(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ void *pvt)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct override_user user = {NULL};
|
|
|
6cf099 |
+ struct sysdb_attrs *attrs;
|
|
|
6cf099 |
+ const char *dn;
|
|
|
6cf099 |
+ int ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = parse_cmdline_user_add(cmdline, tool_ctx, &user);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command line.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dn = get_user_dn_and_domain(tool_ctx, tool_ctx->domains, &user);
|
|
|
6cf099 |
+ if (dn == NULL) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Unable to find user %s@%s.\n"),
|
|
|
6cf099 |
+ user.orig_name,
|
|
|
6cf099 |
+ user.domain == NULL ? "[unknown]" : user.domain->name);
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = prepare_view(user.domain);
|
|
|
6cf099 |
+ if (ret == EEXIST) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Other than LOCAL view already exist in "
|
|
|
6cf099 |
+ "domain %s.\n"), user.domain->name);
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ } else if (ret != EOK) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Unable to prepare view [%d]: %s.\n"),
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ attrs = build_user_attrs(tool_ctx, &user);
|
|
|
6cf099 |
+ if (attrs == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to build sysdb attrs.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = override_object_add(user.domain, SYSDB_MEMBER_USER, attrs, dn);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add override object.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return EXIT_SUCCESS;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int override_user_del(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ void *pvt)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct override_user user = {NULL};
|
|
|
6cf099 |
+ const char *dn;
|
|
|
6cf099 |
+ int ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = parse_cmdline_user_del(cmdline, tool_ctx, &user);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command line.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dn = get_user_dn_and_domain(tool_ctx, tool_ctx->domains, &user);
|
|
|
6cf099 |
+ if (dn == NULL) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Unable to find user %s@%s.\n"),
|
|
|
6cf099 |
+ user.orig_name, user.domain->name);
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = override_object_del(user.domain, dn);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add override object.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return EXIT_SUCCESS;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int override_group_add(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ void *pvt)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct override_group group = {NULL};
|
|
|
6cf099 |
+ struct sysdb_attrs *attrs;
|
|
|
6cf099 |
+ const char *dn;
|
|
|
6cf099 |
+ int ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = parse_cmdline_group_add(cmdline, tool_ctx, &group);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command line.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dn = get_group_dn_and_domain(tool_ctx, tool_ctx->domains, &group);
|
|
|
6cf099 |
+ if (dn == NULL) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Unable to find group %s@%s.\n"),
|
|
|
6cf099 |
+ group.orig_name, group.domain->name);
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = prepare_view(group.domain);
|
|
|
6cf099 |
+ if (ret == EEXIST) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Other than LOCAL view already exist in "
|
|
|
6cf099 |
+ "domain %s.\n"), group.domain->name);
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ } else if (ret != EOK) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Unable to prepare view [%d]: %s.\n"),
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ attrs = build_group_attrs(tool_ctx, &group);
|
|
|
6cf099 |
+ if (attrs == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to build sysdb attrs.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = override_object_add(group.domain, SYSDB_MEMBER_GROUP, attrs, dn);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add override object.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return EXIT_SUCCESS;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int override_group_del(struct sss_cmdline *cmdline,
|
|
|
6cf099 |
+ struct sss_tool_ctx *tool_ctx,
|
|
|
6cf099 |
+ void *pvt)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct override_group group = {NULL};
|
|
|
6cf099 |
+ const char *dn;
|
|
|
6cf099 |
+ int ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = parse_cmdline_group_del(cmdline, tool_ctx, &group);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command line.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dn = get_group_dn_and_domain(tool_ctx, tool_ctx->domains, &group);
|
|
|
6cf099 |
+ if (dn == NULL) {
|
|
|
6cf099 |
+ fprintf(stderr, _("Unable to find group %s@%s.\n"),
|
|
|
6cf099 |
+ group.orig_name, group.domain->name);
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = override_object_del(group.domain, dn);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add override object.\n");
|
|
|
6cf099 |
+ return EXIT_FAILURE;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return EXIT_SUCCESS;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+int main(int argc, const char **argv)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct sss_route_cmd commands[] = {
|
|
|
6cf099 |
+ {"user-add", override_user_add},
|
|
|
6cf099 |
+ {"user-del", override_user_del},
|
|
|
6cf099 |
+ {"group-add", override_group_add},
|
|
|
6cf099 |
+ {"group-del", override_group_del},
|
|
|
6cf099 |
+ {NULL, NULL}
|
|
|
6cf099 |
+ };
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return sss_tool_main(argc, argv, commands, NULL);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
--
|
|
|
6cf099 |
2.4.3
|
|
|
6cf099 |
|