[SCM] Samba Shared Repository - branch master updated

Martin Schwenke martins at samba.org
Wed Apr 17 00:55:02 UTC 2024


The branch, master has been updated
       via  7e621b1b530 ctdb: Modernize a few DEBUGs
       via  73e806c559d ctdb: Remove common/line.[ch]
       via  ba8f8ef33cd ctdb: Use stdio's getline() in ctdb_connection_list_read()
       via  4de14e27231 lib: Use fdopen_keepfd()
       via  b6f4acb9b46 rpc_server3: Use fdopen_keepfd()
       via  28335cdb5d7 lib: Add fdopen_keepfd()
       via  0baae61e423 lib: Give lib/util/util_file.c its own header file
       via  f42c5802faf ctdb-scripts: Add options to generate smb.conf interfaces include file
       via  56eeb058d2d ctdb-scripts: Rename and relocate function get_all_interfaces()
       via  ff3b92ffaed smbd-server: Process ip add/drop events for options:dynamic only
       via  c60fe03ef7d lib-interface: Change API for interface 'options'
       via  3edeb2bdce4 lib-interface: Add parsing for interface 'options'
       via  cfa846fa292 lib-interface: Add extra parameter 'options' to interface definition
       via  9fcb62cf22d param: Add additional key 'options' for interfaces
       via  916fabe7e83 smbd-server: Use MSG_SMB_IP_DROPPED
       via  644b50b05b2 messaging: Add new SMBD message
       via  4ef1eb92edc smbd-server: Handle ip drop event and close listening socket
       via  bca01b501cb smbd-server: Open socket for additional ip address
       via  961104262c6 lib-interface: Add new API to validate interface info for given interface index
       via  6f18422aadc lib-addrchange: Change API to fill up if_index value from netlink msg
       via  02a99126abf smbd-server: Set event callback for interface change notification
      from  7532c798d13 docs: Document new tdbdump -x option

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7e621b1b530f740bce8d2de084c0f710f1ddb437
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Feb 29 16:11:16 2024 +0100

    ctdb: Modernize a few DEBUGs
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    
    Autobuild-User(master): Martin Schwenke <martins at samba.org>
    Autobuild-Date(master): Wed Apr 17 00:54:55 UTC 2024 on atb-devel-224

commit 73e806c559d8889026b2b14a8d22145bd1a2b430
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 1 21:19:51 2024 +0100

    ctdb: Remove common/line.[ch]
    
    This was an implementation of getline(3), use that instead.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>

commit ba8f8ef33cd99ea60fc2682727a5497995b5f569
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Mar 1 21:16:57 2024 +0100

    ctdb: Use stdio's getline() in ctdb_connection_list_read()
    
    This is the only user of common/line.[ch], which can go next.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>

commit 4de14e2723139b488e69251e500f022f50f983e1
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 13:11:11 2024 +0200

    lib: Use fdopen_keepfd()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>

commit b6f4acb9b46773d61aaea242b67af90d40bc4c9c
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 13:08:06 2024 +0200

    rpc_server3: Use fdopen_keepfd()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>

commit 28335cdb5d72c63d52c83fe00a67b8aa28558677
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 13:07:56 2024 +0200

    lib: Add fdopen_keepfd()
    
    Capture the dup/fdopen pattern
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>

commit 0baae61e4233bc812c65c3646b1acf15ef7bc22f
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 10 13:02:39 2024 +0200

    lib: Give lib/util/util_file.c its own header file
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>

commit f42c5802fafa61fe29a0b78c0247eb5a5c386c15
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Jan 30 01:50:20 2024 -0800

    ctdb-scripts: Add options to generate smb.conf interfaces include file
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 56eeb058d2d5fde17c461afe7fac2f0832993a8c
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Jan 30 01:25:37 2024 -0800

    ctdb-scripts: Rename and relocate function get_all_interfaces()
    
    get_all_interfaces() functions gets all names for all public interfaces.
    However name is misleading. Thus renamed it to get_public_ifaces() and
    moved it under functions.
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit ff3b92ffaed64e8ecb250f0ad160210f511a39e2
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Mar 5 03:03:25 2024 -0800

    smbd-server: Process ip add/drop events for options:dynamic only
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit c60fe03ef7d09f98b2c91669e0ecbd880c72fa0e
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Mar 5 02:32:23 2024 -0800

    lib-interface: Change API for interface 'options'
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 3edeb2bdce41acb4ae09954adaf9dcfe9aa627cc
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Mar 5 02:15:11 2024 -0800

    lib-interface: Add parsing for interface 'options'
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit cfa846fa292fa665ee1c72671a4c41116cfb4e15
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Mar 5 02:27:04 2024 -0800

    lib-interface: Add extra parameter 'options' to interface definition
    
    Signed-off-by: Vinit Agnihotri<vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 9fcb62cf22d237fb61d1297e9e53418ce73105a3
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Mar 5 03:16:49 2024 -0800

    param: Add additional key 'options' for interfaces
    
    The key 'options' specifies if server should spawn/kill listning sockets
    in event of add/dropped ip addresses on specified interface.
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 916fabe7e838c02e1d221e7edc16ba723e7bed97
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Thu Feb 29 00:52:08 2024 -0800

    smbd-server: Use MSG_SMB_IP_DROPPED
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 644b50b05b288298b359310dd56963e0e11b9290
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Wed Feb 28 22:22:38 2024 -0800

    messaging: Add new SMBD message
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 4ef1eb92edcd6f93a743e5bb801834250ce1a8ca
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Wed Feb 28 03:56:23 2024 -0800

    smbd-server: Handle ip drop event and close listening socket
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit bca01b501cb0b521e60784e6ce4e4f9af0773ff8
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Feb 20 21:49:34 2024 -0800

    smbd-server: Open socket for additional ip address
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 961104262c6209be13cd29a67b3e323999cc5b4e
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Feb 20 02:40:13 2024 -0800

    lib-interface: Add new API to validate interface info for given interface index
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 6f18422aadce109ca30b7703ddd8574f49d8aff0
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Thu Feb 15 05:23:37 2024 -0800

    lib-addrchange: Change API to fill up if_index value from netlink msg
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 02a99126abf7cc4399c3784f3edf6a10d7c34c4e
Author: Vinit Agnihotri <vagnihotri at ddn.com>
Date:   Tue Feb 13 03:30:50 2024 -0800

    smbd-server: Set event callback for interface change notification
    
    Signed-off-by: Vinit Agnihotri <vagnihotri at ddn.com>
    Reviewed-by: Martin Schwenke <mschwenke at ddn.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 auth/credentials/credentials.c                |   1 +
 ctdb/common/ctdb_util.c                       |   1 +
 ctdb/common/line.c                            | 145 -----------------
 ctdb/common/line.h                            |  62 -------
 ctdb/config/events/legacy/10.interface.script |  30 +---
 ctdb/config/events/legacy/50.samba.script     |  24 +++
 ctdb/config/functions                         |  24 +++
 ctdb/doc/ctdb-script.options.5.xml            |  45 ++++++
 ctdb/protocol/protocol_util.c                 |  36 +++--
 ctdb/server/ctdb_recoverd.c                   |  36 +++--
 ctdb/server/ctdb_takeover.c                   |   1 +
 ctdb/tests/UNIT/cunit/line_test_001.sh        |  90 -----------
 ctdb/tests/src/fake_ctdbd.c                   |   1 +
 ctdb/tests/src/line_test.c                    | 102 ------------
 ctdb/tools/ctdb.c                             |   1 +
 ctdb/wscript                                  |   2 -
 docs-xml/smbdotconf/base/interfaces.xml       |  23 ++-
 lib/fuzzing/afl-fuzz-main.c                   |   2 +-
 lib/socket/interfaces.h                       |   1 +
 lib/util/samba_util.h                         |  55 -------
 lib/util/tests/file.c                         |   1 +
 lib/util/util_file.c                          |  37 ++++-
 lib/util/util_file.h                          |  82 ++++++++++
 libcli/nbt/lmhosts.c                          |   1 +
 libcli/netlogon/netlogon.c                    |   1 +
 libgpo/gpo_ini.c                              |   1 +
 librpc/idl/messaging.idl                      |   3 +
 librpc/rpc/dcerpc_pkt_auth.c                  |   1 +
 librpc/rpc/dcerpc_util.c                      |   1 +
 librpc/tools/ndrdump.c                        |   1 +
 librpc/wsp/wsp_util.c                         |   1 +
 source3/auth/user_util.c                      |   1 +
 source3/client/clitar.c                       |   1 +
 source3/include/smb.h                         |   1 +
 source3/lib/addrchange.c                      |  13 +-
 source3/lib/addrchange.h                      |   6 +-
 source3/lib/dumpcore.c                        |   1 +
 source3/lib/interface.c                       |  51 +++++-
 source3/lib/interface.h                       |   4 +
 source3/lib/tallocmsg.c                       |  13 +-
 source3/lib/util_file.c                       |   3 +-
 source3/libgpo/gpext/registry.c               |   1 +
 source3/modules/vfs_fruit.c                   |   1 +
 source3/modules/vfs_glusterfs.c               |   1 +
 source3/modules/vfs_shell_snap.c              |   1 +
 source3/nmbd/nmbd_synclists.c                 |   1 +
 source3/nmbd/nmbd_winsserver.c                |   1 +
 source3/param/loadparm.c                      |   1 +
 source3/passdb/machine_sid.c                  |   1 +
 source3/printing/nt_printing_os2.c            |   1 +
 source3/printing/print_generic.c              |   1 +
 source3/printing/print_standard.c             |   1 +
 source3/rpc_server/rpc_host.c                 |  13 +-
 source3/rpc_server/rpc_worker.c               |  15 +-
 source3/rpc_server/spoolss/srv_spoolss_nt.c   |   1 +
 source3/smbd/server.c                         | 222 ++++++++++++++++++++++++++
 source3/smbd/smb1_lanman.c                    |   1 +
 source3/smbd/smb2_process.c                   |  38 +++++
 source3/torture/test_addrchange.c             |   2 +-
 source3/torture/torture.c                     |   1 +
 source3/utils/net_ads.c                       |   1 +
 source3/utils/net_eventlog.c                  |   1 +
 source3/utils/net_offlinejoin.c               |   1 +
 source3/utils/net_usershare.c                 |   1 +
 source3/utils/smbcacls.c                      |   1 +
 source3/winbindd/winbindd.c                   |   2 +-
 source4/lib/registry/patchfile_dotreg.c       |   1 +
 source4/lib/registry/regf.c                   |   4 +-
 source4/lib/tls/tls_tstream.c                 |   1 +
 source4/lib/tls/tlscert.c                     |   1 +
 source4/libcli/dgram/browse.c                 |   1 +
 source4/libcli/dgram/netlogon.c               |   1 +
 source4/librpc/rpc/dcerpc.c                   |   1 +
 source4/torture/auth/pac.c                    |   1 +
 source4/torture/basic/misc.c                  |   1 +
 source4/torture/drs/rpc/dssync.c              |   1 +
 source4/torture/gentest.c                     |   1 +
 source4/torture/locktest.c                    |   1 +
 source4/torture/smbtorture.c                  |   1 +
 source4/torture/util_smb.c                    |   1 +
 80 files changed, 673 insertions(+), 561 deletions(-)
 delete mode 100644 ctdb/common/line.c
 delete mode 100644 ctdb/common/line.h
 delete mode 100755 ctdb/tests/UNIT/cunit/line_test_001.sh
 delete mode 100644 ctdb/tests/src/line_test.c
 create mode 100644 lib/util/util_file.h


Changeset truncated at 500 lines:

diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
index 20ab858e67b..6a590483e99 100644
--- a/auth/credentials/credentials.c
+++ b/auth/credentials/credentials.c
@@ -22,6 +22,7 @@
 */
 
 #include "includes.h"
+#include "lib/util/util_file.h"
 #include "librpc/gen_ndr/samr.h" /* for struct samrPassword */
 #include "auth/credentials/credentials.h"
 #include "auth/credentials/credentials_internal.h"
diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c
index 3ca1f772eba..ebf0203871f 100644
--- a/ctdb/common/ctdb_util.c
+++ b/ctdb/common/ctdb_util.c
@@ -21,6 +21,7 @@
 #include "system/network.h"
 #include "system/filesys.h"
 #include "system/wait.h"
+#include "lib/util/util_file.h"
 
 #include <tdb.h>
 
diff --git a/ctdb/common/line.c b/ctdb/common/line.c
deleted file mode 100644
index c4c6726875b..00000000000
--- a/ctdb/common/line.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
-   Line based I/O over fds
-
-   Copyright (C) Amitay Isaacs  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 "replace.h"
-
-#include <talloc.h>
-
-#include "lib/util/sys_rw.h"
-
-#include "common/line.h"
-
-struct line_read_state {
-	line_process_fn_t callback;
-	void *private_data;
-	char *buf;
-	size_t hint, len, offset;
-	int num_lines;
-};
-
-static bool line_read_one(char *buf, size_t start, size_t len, size_t *pos)
-{
-	size_t i;
-
-	for (i=start; i<len; i++) {
-		if (buf[i] == '\n' || buf[i] == '\0') {
-			*pos = i;
-			return true;
-		}
-	}
-
-	return false;
-}
-
-static int line_read_process(struct line_read_state *state)
-{
-	size_t start = 0;
-	size_t pos = 0;
-
-	while (1) {
-		int ret;
-		bool ok;
-
-		ok = line_read_one(state->buf, start, state->offset, &pos);
-		if (! ok) {
-			break;
-		}
-
-		state->buf[pos] = '\0';
-		state->num_lines += 1;
-
-		ret = state->callback(state->buf + start, state->private_data);
-		if (ret != 0) {
-			return ret;
-		}
-
-		start = pos+1;
-	}
-
-	if (pos > 0) {
-		if (pos+1 < state->offset) {
-			memmove(state->buf,
-				state->buf + pos+1,
-				state->offset - (pos+1));
-		}
-		state->offset -= (pos+1);
-	}
-
-	return 0;
-}
-
-int line_read(int fd,
-	      size_t length,
-	      TALLOC_CTX *mem_ctx,
-	      line_process_fn_t callback,
-	      void *private_data,
-	      int *num_lines)
-{
-	struct line_read_state state;
-
-	if (length < 32) {
-		length = 32;
-	}
-
-	state = (struct line_read_state) {
-		.callback = callback,
-		.private_data = private_data,
-		.hint = length,
-	};
-
-	while (1) {
-		ssize_t n;
-		int ret;
-
-		if (state.offset == state.len) {
-			state.len += state.hint;
-			state.buf = talloc_realloc_size(mem_ctx,
-							state.buf,
-							state.len);
-			if (state.buf == NULL) {
-				return ENOMEM;
-			}
-		}
-
-		n = sys_read(fd,
-			     state.buf + state.offset,
-			     state.len - state.offset);
-		if (n < 0) {
-			return errno;
-		}
-		if (n == 0) {
-			break;
-		}
-
-		state.offset += n;
-
-		ret = line_read_process(&state);
-		if (ret != 0) {
-			if (num_lines != NULL) {
-				*num_lines = state.num_lines;
-			}
-			return ret;
-		}
-	}
-
-	if (num_lines != NULL) {
-		*num_lines = state.num_lines;
-	}
-	return 0;
-}
diff --git a/ctdb/common/line.h b/ctdb/common/line.h
deleted file mode 100644
index 6b67f1e92e1..00000000000
--- a/ctdb/common/line.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-   Line based I/O over fds
-
-   Copyright (C) Amitay Isaacs  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 __CTDB_LINE_H__
-#define __CTDB_LINE_H__
-
-#include <talloc.h>
-
-/**
- * @file line.h
- *
- * @brief Line based I/O over pipes and sockets
- */
-
-/**
- * @brief The callback routine called to process a line
- *
- * @param[in]  line The line read
- * @param[in]  private_data Private data for callback
- * @return 0 to continue processing lines, non-zero to stop reading
- */
-typedef int (*line_process_fn_t)(char *line, void *private_data);
-
-/**
- * @brief Read a line (terminated by \n or \0)
- *
- * If there is any read error on fd, then errno will be returned.
- * If callback function returns a non-zero value, then that value will be
- * returned.
- *
- * @param[in]  fd The file descriptor
- * @param[in]  length The expected length of a line (this is only a hint)
- * @param[in]  mem_ctx Talloc memory context
- * @param[in]  callback Callback function called when a line is read
- * @param[in]  private_data Private data for callback
- * @param[out] num_lines Number of lines read so far
- * @return 0 on on success, errno on failure
- */
-int line_read(int fd,
-	      size_t length,
-	      TALLOC_CTX *mem_ctx,
-	      line_process_fn_t callback,
-	      void *private_data,
-	      int *num_lines);
-
-#endif /* __CTDB_LINE_H__ */
diff --git a/ctdb/config/events/legacy/10.interface.script b/ctdb/config/events/legacy/10.interface.script
index fead88c014f..110b1213966 100755
--- a/ctdb/config/events/legacy/10.interface.script
+++ b/ctdb/config/events/legacy/10.interface.script
@@ -12,37 +12,16 @@
 
 load_script_options
 
-ctdb_public_addresses="${CTDB_BASE}/public_addresses"
-
-if [ ! -f "$ctdb_public_addresses" ]; then
+if ! have_public_addresses; then
 	if [ "$1" = "init" ] ; then
 		echo "No public addresses file found"
 	fi
 	exit 0
 fi
 
-# This sets $all_interfaces as a side-effect.
-get_all_interfaces ()
-{
-    # Get all the interfaces listed in the public_addresses file
-    all_interfaces=$(sed -e '/^#.*/d' \
-			 -e 's/^[^\t ]*[\t ]*//' \
-			 -e 's/,/ /g' \
-			 -e 's/[\t ]*$//' "$ctdb_public_addresses")
-
-    # Get the interfaces for which CTDB has public IPs configured.
-    # That is, for all but the 1st line, get the 1st field.
-    ctdb_ifaces=$($CTDB -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@')
-
-    # Add $ctdb_ifaces and make $all_interfaces unique
-    # Use word splitting to squash whitespace
-    # shellcheck disable=SC2086
-    all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
-}
-
 monitor_interfaces()
 {
-	get_all_interfaces
+	get_public_ifaces
 
 	down_interfaces_found=false
 	up_interfaces_found=false
@@ -50,7 +29,10 @@ monitor_interfaces()
 	# Note that this loop must not exit early.  It must process
 	# all interfaces so that the correct state for each interface
 	# is set in CTDB using setifacelink.
-	for _iface in $all_interfaces ; do
+	#
+	# public_ifaces set by get_public_ifaces() above
+	# shellcheck disable=SC2154
+	for _iface in $public_ifaces ; do
 		if interface_monitor "$_iface" ; then
 			up_interfaces_found=true
 			$CTDB setifacelink "$_iface" up >/dev/null 2>&1
diff --git a/ctdb/config/events/legacy/50.samba.script b/ctdb/config/events/legacy/50.samba.script
index 84600e25024..90de6a3f31b 100755
--- a/ctdb/config/events/legacy/50.samba.script
+++ b/ctdb/config/events/legacy/50.samba.script
@@ -27,6 +27,27 @@ load_script_options
 
 ctdb_setup_state_dir "service" "$service_name"
 
+generate_smb_interfaces_config()
+{
+	get_public_ifaces
+	pub_iface_list=$public_ifaces
+	public_ifaces=""
+	for iface in $pub_iface_list;
+	do
+		public_ifaces="$public_ifaces \"$iface;options=dynamic\""
+	done
+
+	if [ -n "$CTDB_SAMBA_INTERFACES_EXTRA" ]; then
+		public_ifaces="$public_ifaces $CTDB_SAMBA_INTERFACES_EXTRA"
+	fi
+	public_ifaces=$(echo "$public_ifaces" | xargs -n 1 | sort -u)
+
+cat <<EOT > "$CTDB_SAMBA_INTERFACES_FILE"
+    bind interfaces only = yes
+    interfaces = lo $public_ifaces
+EOT
+}
+
 service_start()
 {
 	# make sure samba is not already started
@@ -36,6 +57,9 @@ service_start()
 		# make absolutely sure samba is dead
 		killall -q -9 smbd
 	}
+	if [ -n "$CTDB_SAMBA_INTERFACES_FILE" ]; then
+		generate_smb_interfaces_config
+	fi
 	# start Samba service. Start it reniced, as under very heavy load
 	# the number of smbd processes will mean that it leaves few cycles
 	# for anything else
diff --git a/ctdb/config/functions b/ctdb/config/functions
index a40b276e2b8..e76082b7cb3 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -651,6 +651,30 @@ drop_ip()
 	fi
 }
 
+have_public_addresses()
+{
+	[ -f "${CTDB_BASE}/public_addresses" ]
+}
+
+# This sets $public_ifaces as a side-effect.
+get_public_ifaces()
+{
+	# Get all the interfaces listed in the public_addresses file
+	public_ifaces=$(sed -e '/^#.*/d' \
+		-e 's/^[^\t ]*[\t ]*//' \
+		-e 's/,/ /g' \
+		-e 's/[\t ]*$//' "${CTDB_BASE}/public_addresses")
+
+	# Get the interfaces for which CTDB has public IPs configured.
+	# That is, for all but the 1st line, get the 1st field.
+	ctdb_ifaces=$($CTDB -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@')
+
+	# Add $ctdb_ifaces and make $public_ifaces unique
+	# Use word splitting to squash whitespace
+	# shellcheck disable=SC2086
+	public_ifaces=$(echo $public_ifaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
+}
+
 drop_all_public_ips()
 {
 	# _x is intentionally ignored
diff --git a/ctdb/doc/ctdb-script.options.5.xml b/ctdb/doc/ctdb-script.options.5.xml
index ef3ad416d0d..ffe4c3abd62 100644
--- a/ctdb/doc/ctdb-script.options.5.xml
+++ b/ctdb/doc/ctdb-script.options.5.xml
@@ -691,6 +691,51 @@ CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=9000
 	  </listitem>
 	</varlistentry>
 
+	<varlistentry>
+	  <term>
+	    CTDB_SAMBA_INTERFACES_FILE=<parameter>FILENAME</parameter>
+	  </term>
+	  <listitem>
+	    <para>
+	      Generates FILENAME, containing an smb.conf snippet with
+	      an interfaces setting that includes interfaces for
+	      configured CTDB public IP addresses.  This file then
+	      needs to be explicitly included in smb.conf.
+	    </para>
+	    <para>
+	      For example, if public IP addresses are defined on
+	      interfaces eth0 and eth1, and this is set to
+	      <filename>/etc/samba/interfaces.conf</filename>, then
+	      that file will contain the following before smbd is
+	      started:
+	    </para>
+	    <screen>
+     bind interfaces only = yes
+     interfaces = lo eth0 eth1
+	    </screen>
+	    <para>
+	      This can be useful for limiting the interfaces used by
+	      SMB multichannel.
+	    </para>
+	    <para>
+	      Default is to not generate a file.
+	    </para>
+	  </listitem>
+	</varlistentry>
+
+	<varlistentry>
+	  <term>
+	    CTDB_SAMBA_INTERFACES_EXTRA=<parameter>INTERFACE-LIST</parameter>
+	  </term>
+	  <listitem>
+	    <para>
+	      A space separated list to provide additional interfaces to bind.
+	    </para>
+	    <para>
+	      Default is empty - no extra interfaces are added.
+	    </para>
+	  </listitem>
+	</varlistentry>
       </variablelist>
 
     </refsect2>
diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
index 01756cfa759..25e668b73ee 100644
--- a/ctdb/protocol/protocol_util.c
+++ b/ctdb/protocol/protocol_util.c
@@ -22,12 +22,11 @@
 
 #include <talloc.h>
 
-#include "common/line.h"
-
 #include "protocol.h"
 #include "protocol_util.h"
 #include "lib/util/util.h"
 #include "lib/util/smb_strtox.h"
+#include "lib/util/util_file.h"
 
 static struct {
 	enum ctdb_runstate runstate;
@@ -712,10 +711,10 @@ struct ctdb_connection_list_read_state {
 	bool client_first;
 };
 
-static int ctdb_connection_list_read_line(char *line, void *private_data)
+static int ctdb_connection_list_read_line(
+	char *line,
+	struct ctdb_connection_list_read_state *state)
 {
-	struct ctdb_connection_list_read_state *state =
-		(struct ctdb_connection_list_read_state *)private_data;
 	struct ctdb_connection conn;
 	int ret;
 
@@ -748,7 +747,11 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx,
 			      struct ctdb_connection_list **conn_list)
 {
 	struct ctdb_connection_list_read_state state;
+	char *line = NULL;
+	FILE *f = NULL;
 	int ret;
+	size_t len = 0;
+	ssize_t nread;
 
 	if (conn_list == NULL) {
 		return EINVAL;
@@ -761,12 +764,23 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx,
 
 	state.client_first = client_first;
 
-	ret = line_read(fd,
-			128,
-			mem_ctx,
-			ctdb_connection_list_read_line,
-			&state,
-			NULL);
+	f = fdopen_keepfd(fd, "r");
+	if (f == NULL) {
+		return errno;
+	}
+
+	while ((nread = getline(&line, &len, f)) != -1) {
+		if ((nread > 0) && (line[nread-1] == '\n')) {
+			line[nread-1] = '\0';
+		}
+		ret = ctdb_connection_list_read_line(line, &state);
+		if (ret != 0) {
+			break;
+		}
+	}


-- 
Samba Shared Repository



More information about the samba-cvs mailing list