summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorChristof Schmitt <cs@samba.org>2018-08-20 14:44:28 -0700
committerKarolin Seeger <kseeger@samba.org>2018-10-09 11:29:22 +0200
commit4aace8194964e08aa19a6c45571dc2b3afb7986e (patch)
tree3443da564277c9d02a1316cedfdaad3619227a11 /source3
parent050208f3b6bf59fcf58b3f134db4eeb6ba3cf47c (diff)
downloadsamba-4aace8194964e08aa19a6c45571dc2b3afb7986e.tar.gz
s3:lib: Introduce cmdline context wrapper
Command line tools need acccess to the same messaging context provided by server_messaging_context, as common code for db_open uses that context. We want to have additional checking for command line tools without having that code part of the servers. Introduce a wrapper library to use for command line tools with the additional checks, that then acquires the server_messaging_context. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13465 Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> (cherry picked from commit 8c3b62e6231e62feafacf2a7ee4c9d41cd27a4a1)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/cmdline_contexts.c70
-rw-r--r--source3/lib/cmdline_contexts.h27
-rw-r--r--source3/wscript_build5
3 files changed, 102 insertions, 0 deletions
diff --git a/source3/lib/cmdline_contexts.c b/source3/lib/cmdline_contexts.c
new file mode 100644
index 00000000000..5713f7f7956
--- /dev/null
+++ b/source3/lib/cmdline_contexts.c
@@ -0,0 +1,70 @@
+/*
+ Unix SMB/CIFS implementation.
+ cmdline context wrapper.
+
+ Copyright (C) Christof Schmitt <cs@samba.org> 2018
+
+ This program is free software; you can redistribute it and/or modify
+ 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 "cmdline_contexts.h"
+#include "includes.h"
+#include "messages.h"
+
+struct messaging_context *cmdline_messaging_context(const char *config_file)
+{
+ struct messaging_context *msg_ctx = NULL;
+
+ /*
+ * Ensure that a config is loaded, in case the underlying
+ * messaging_init needs to create directories or sockets.
+ */
+ if (!lp_loaded()) {
+ if (!lp_load_initial_only(config_file)) {
+ return NULL;
+ }
+ }
+
+ /*
+ * Clustered Samba can only work as root due to required
+ * access to the registry and ctdb, which in turn requires
+ * messaging access as root.
+ */
+ if (lp_clustering() && geteuid() != 0) {
+ fprintf(stderr, "Cluster mode requires running as root.\n");
+ exit(1);
+ }
+
+ msg_ctx = server_messaging_context();
+ if (msg_ctx == NULL) {
+ if (geteuid() == 0) {
+ fprintf(stderr,
+ "Unable to initialize messaging context!\n");
+ exit(1);
+ } else {
+ /*
+ * Non-cluster, non-root: Log error, but leave
+ * it up to the caller how to proceed.
+ */
+ DBG_NOTICE("Unable to initialize messaging context.\n");
+ }
+ }
+
+ return msg_ctx;
+}
+
+void cmdline_messaging_context_free(void)
+{
+ server_messaging_context_free();
+}
diff --git a/source3/lib/cmdline_contexts.h b/source3/lib/cmdline_contexts.h
new file mode 100644
index 00000000000..21f81f0f1cd
--- /dev/null
+++ b/source3/lib/cmdline_contexts.h
@@ -0,0 +1,27 @@
+/*
+ Unix SMB/CIFS implementation.
+ cmdline context wrapper.
+
+ Copyright (C) Christof Schmitt <cs@samba.org> 2018
+
+ This program is free software; you can redistribute it and/or modify
+ 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/>.
+*/
+
+#ifndef _LIB_CMDLINE_CONTEXTS_H
+#define _LIB_CMDLINE_CONTEXTS_H
+
+struct messaging_context *cmdline_messaging_context(const char *config_file);
+void cmdline_messaging_context_free(void);
+
+#endif
diff --git a/source3/wscript_build b/source3/wscript_build
index 83ef56d8ba8..1808b5e0cb3 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -270,6 +270,11 @@ bld.SAMBA3_LIBRARY('util_cmdline',
deps='secrets3',
private_library=True)
+bld.SAMBA3_LIBRARY('cmdline_contexts',
+ source='lib/cmdline_contexts.c',
+ deps='samba3core',
+ private_library=True)
+
bld.SAMBA3_SUBSYSTEM('KRBCLIENT',
source='libads/kerberos.c libads/ads_status.c',
public_deps='krb5samba asn1util k5crypto gssapi LIBTSOCKET CLDAP LIBNMB')