[SCM] Samba Shared Repository - branch v4-8-stable updated

Karolin Seeger kseeger at samba.org
Thu Apr 4 10:16:11 UTC 2019


The branch, v4-8-stable has been updated
       via  4575c88005d VERSION: Disable GIT_SNAPSHOT for the 4.8.10 release.
       via  3bfb6ee3915 WHATSNEW: Add release notes for Samba 4.8.10.
       via  501e28cc8d6 selftest: Make setexpiry test much more reliable
       via  d1484add1fc s3:lib: Fix the debug message for adding cache entries.
       via  77b4430bd5e s3:waf: Fix the detection of makdev() macro on Linux
       via  cf7d657a4d0 dbcheck: use the str() value of the "name" attribute
       via  a41fa4dd1e9 dbcheck: don't check expired tombstone objects by default anymore
       via  e0f6e6cff3e blackbox/dbcheck-links.sh: prepare regression test for skipping expired tombstones
       via  57f7ec5c1ca blackbox/dbcheck*.sh: pass --selftest-check-expired-tombstones to dbcheck
       via  b388052af91 dbcheck: add --selftest-check-expired-tombstones cmdline option
       via  f6f2efd080b python/samba/netcmd: provide SUPPRESS_HELP via Option class
       via  42c9e569e81 dbcheck: detect the change after deletion bug
       via  08f7f33acb9 blackbox/dbcheck-links.sh: add regression test for lost deleted object repair
       via  2272dea483e dbcheck: add find_repl_attid() helper function
       via  0473eab6862 dbcheck: don't remove dangling one-way links on already deleted objects
       via  0fd3f38c1cf dbcheck: don't move already deleted objects to LostAndFound
       via  ac900c23b5b dbcheck: do isDeleted, systemFlags and replPropertyMetaData detection first
       via  3136a2cc546 dbcheck: use DSDB_CONTROL_DBCHECK_FIX_LINK_DN_NAME when renaming deleted objects
       via  9daeafbfec8 dsdb:repl_meta_data: allow CONTROL_DBCHECK_FIX_LINK_DN_NAME to by pass rename
       via  f91050ee547 blackbox/dbcheck-links.sh: reproduce lost deleted object problem
       via  833d543717c selftest: force running with TZ=UTC
       via  6da5ef15ec1 python/samba: extra ndr_unpack needs bytes function
       via  19a77a10b76 python/samba: PY3 port for ridalloc_exop test to work
       via  300d52de7e5 s4:librpc: Fix installation of Samba
       via  96a229b0281 ctdb-tests: Add some testing for IPv4-mapped IPv6 address parsing
       via  02da215c104 ctdb: Initialize addr struct to zero before reparsing as IPV4
       via  aeba27d3a48 ctdb-common: Add fd argument to ctdb_connection_list_read()
       via  cd5f1904032 ctdb-protocol: Avoid fgets in ctdb_connection_list_read
       via  2c89c388518 ctdb-common: Add line based I/O
       via  4a5868be3a9 s3:client: Fix smbspool device uri handling
       via  e28dd0f95b3 s3:client: Make sure we work on a copy of the title
       via  f284a5c10f7 s3:client: Evaluate the AUTH_INFO_REQUIRED variable set by cups
       via  f0f56e7e84f s3:client: Pass DEVICE_URI and AUTH_INFO_REQUIRED env to smbspool
       via  cc43f3cd3aa s3:script: Fix jobid check in test_smbspool.sh
       via  c7e7ea8d953 ndr_spoolss_buf: fix out of scope use of stack variable in NDR_SPOOLSS_PUSH_ENUM_OUT()
       via  7b52da5ecdc Send status to systemd on daemon start
       via  d3e306433f7 lib:util: Move debug message for mkdir failing to log level 1
       via  e655fa0a437 WHATSNEW: mention new vfs_glusterfs_fuse module
       via  57158ba47e7 lib/winbind_util: Add winbind_xid_to_sid for --without-winbind
       via  38d723896da lib/winbind_util: Move include out of ifdef
       via  e2588af9cc4 passdb: Update ABI to 0.27.2
       via  d7ba89435d4 s3:passdb: add create_builtin_guests()
       via  79191a7193a passdb: Make [ug]id_to_sid use xid_to_sid
       via  4fd495159d1 passdb: Introduce xid_to_sid
       via  e8bb1f65cd1 lib: Add dom_sid_str_buf
       via  b9ac92992ce lib: Introduce winbind_xid_to_sid
       via  8d0a8864b17 winbind: Use idmap_cache_find_xid2sid
       via  0a2db567327 torture: Add tests for idmap cache
       via  894567e19ec idmap_cache: Introduce idmap_cache_find_xid2sid
       via  dd9ca43d6a7 winbind: Now we explicitly track if we got ids from cache
       via  c031b9e23ac winbind: Initialize "expired" parameter to idmap_cache_xid2sid
       via  b0a1d90050c idmap_cache: Only touch "sid" on success in find_xid_to_sid
       via  14234542aa5 lib: Make idmap_cache return negative mappings
       via  29984beafc9 libcli/security: fix handling of deny type ACEs in access_check_max_allowed()
       via  05a54f9c0ef s4:torture: Add test_deny1().
       via  8f77ba1b7c7 s4:torture: Add test_owner_rights_deny1().
       via  ebee56db540 libcli/security: correct access check and maximum access calculation for Owner Rights ACEs
       via  b079f59768d s4:torture: Add test_owner_rights_deny().
       via  72bab8d08b0 s4:torture: Fix the test_owner_rights() test to show permissions are additive.
       via  2fd618413db libcli/security: add "Owner Rights" calculation to access_check_max_allowed()
       via  7ab6b04558c s4:torture: add a Maximum Access check with an Owner Rights ACE
       via  021321f5a89 s4:libcli: remember return code from maximum access
       via  66a0bb5575d sambaundoguididx: use the right escaped oder unescaped sam ldb files
       via  7c476487867 vfs_ceph: remove ceph_fallocate/ceph_ftruncate fallback
       via  c539cf176a6 vfs_ceph: fix strict_allocate_ftruncate()
       via  cf279fbdd53 vfs_ceph: add missing fallocate hook
       via  03e4555f344 s3: smbd: filenames - ensure we replace the missing '/' if we error in an intermediate POSIX path.
       via  c249c88cdb7 s3: torture: Add additional POSIX mkdir tests.
       via  1ca055cb13b smbd: unix_convert: Ensure we don't call get_real_filename on POSIX paths.
       via  8d407971129 smbd: SMB1-POSIX: Add missing info-level SMB_POSIX_PATH_OPEN for UCF_UNIX_NAME_LOOKUP flag.
       via  3060221960b s3: smbtorture3: Add POSIX-MKDIR test for posix_mkdir case sensitive bug.
       via  89c3db2e9bb winbindd: set idmap cache entries as the last step in async wb_xids2sids
       via  29e16f4737c winbindd: track whether a result from xid2sid was coming from the cache
       via  447b0ad3a95 winbindd: switch send-next/done order
       via  19d06f27688 winbindd: update xid in wb_xids2sids_state->xids with what we got
       via  3197810fe1f winbindd: convert id to a pointer in wb_xids2sids_dom_done()
       via  8234ef264a7 winbindd: make xids a const argument to wb_xids2sids_send()
       via  a76277af385 winbindd: make a copy of xid's in wb_xids2sids_send()
       via  0f1525d430e messages_dgm: Properly handle receiver re-initialization
       via  e2b7d3ff627 torture3: Extend read3 for the "messaging target re-inits" failure
       via  069dd7189c1 messages_dgm: Use saved errno value
       via  1cb278ddaea notifyd: Fix SIGBUS on sparc
       via  8be2836cd82 PVE-2019-3824 ldb: Release ldb 1.3.8
       via  a6b067e00b6 CVE-2019-3824 ldb: Add tests for ldb_wildcard_match
       via  2f6b4d11136 CVE-2019-3824 ldb: wildcard_match end of data check
       via  9b5a7c8abec CVE-2019-3824 ldb: wildcard_match check tree operation
       via  da12e534efe CVE-2019-3824 ldb: ldb_parse_tree use talloc_zero
       via  699e2aa1994 CVE-2019-3824 ldb: Improve code style and layout in wildcard processing
       via  28193ca851c CVE-2019-3824 ldb: Extra comments to clarify no pointer wrap in wildcard processing
       via  bd62896ddc2 CVE-2019-3824 ldb: Out of bound read in ldb_wildcard_compare
       via  080dae06412 waf: Check for libnscd
       via  e60d5ca3a7b tldap: avoid more use after free errors
       via  24c71628c34 tldap: avoid a use after free crash
       via  2f8bd74b67c s3:vfs: Correctly check if OFD locks should be enabled or not
       via  b9120174c66 s3:vfs: Initialize pid to 0 in test_netatalk_lock()
       via  0b15de2db78 s4: torture: vfs_fruit. Change test_fruit_locking_conflict() to match the vfs_fruit working server code.
       via  aec654431dd s3: VFS: vfs_fruit. Fix the NetAtalk deny mode compatibility code.
       via  3a50ce1cc9d netcmd/user: python[3]-gpgme unsupported and replaced by python[3]-gpg
       via  83d82e735bb smbd: uid: Don't crash if 'force group' is added to an existing share connection.
       via  b3638852508 s3: tests: Add regression test for smbd crash on share force group change with existing connection.
       via  8c8457150c5 printing: check lp_load_printers() prior to pcap cache update
       via  32d6bf67801 printing: drop pcap_cache_loaded() guard around load_printers()
       via  6e0514d273e s3-smbd: use fruit:model string for mDNS registration
       via  22d5649e895 ldb: Bump ldb version to 1.3.7
       via  d3a9f298f49 ldb: Avoid inefficient one-level searches
       via  9917a7e70ea VERSION: Bump version up to 4.8.10...
      from  42a6fee788d VERSION: Disable GIT_SNAPSHOT for the 4.8.9 release.

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-8-stable


- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 VERSION                                            |   2 +-
 WHATSNEW.txt                                       | 132 ++++-
 ctdb/common/line.c                                 | 145 ++++++
 ctdb/common/line.h                                 |  62 +++
 ctdb/protocol/protocol_util.c                      |  91 ++--
 ctdb/protocol/protocol_util.h                      |   4 +-
 ctdb/tests/cunit/line_test_001.sh                  |  90 ++++
 ctdb/tests/src/line_test.c                         | 102 ++++
 ctdb/tests/src/protocol_util_test.c                |  37 +-
 ctdb/tools/ctdb.c                                  |   6 +-
 ctdb/tools/ctdb_killtcp.c                          |   2 +-
 ctdb/wscript                                       |   9 +-
 lib/ldb/ABI/{ldb-1.3.0.sigs => ldb-1.3.7.sigs}     |   0
 lib/ldb/ABI/{ldb-1.3.0.sigs => ldb-1.3.8.sigs}     |   0
 ...yldb-util-1.1.10.sigs => pyldb-util-1.3.7.sigs} |   0
 ...yldb-util-1.1.10.sigs => pyldb-util-1.3.8.sigs} |   0
 ...-util-1.1.10.sigs => pyldb-util.py3-1.3.7.sigs} |   0
 ...-util-1.1.10.sigs => pyldb-util.py3-1.3.8.sigs} |   0
 lib/ldb/common/ldb_match.c                         |  41 +-
 lib/ldb/common/ldb_parse.c                         |   2 +-
 lib/ldb/ldb_tdb/ldb_index.c                        |  18 +-
 lib/ldb/tests/ldb_match_test.c                     | 191 +++++++
 lib/ldb/tests/ldb_match_test.valgrind              |  16 +
 lib/ldb/wscript                                    |  10 +-
 lib/util/become_daemon.c                           |  18 +-
 lib/util/util.c                                    |   6 +-
 libcli/security/access_check.c                     | 127 +++--
 libcli/security/dom_sid.c                          |  10 +
 libcli/security/dom_sid.h                          |   2 +
 librpc/ndr/ndr_spoolss_buf.c                       |   4 +-
 python/samba/dbchecker.py                          | 234 +++++++--
 python/samba/netcmd/__init__.py                    |   1 +
 python/samba/netcmd/dbcheck.py                     |  15 +-
 python/samba/netcmd/user.py                        |  85 +++-
 python/samba/remove_dc.py                          |   4 +-
 python/samba/tests/samba_tool/user.py              |   5 +-
 selftest/selftest.pl                               |   3 +
 selftest/selftesthelpers.py                        |   1 +
 selftest/skip                                      |   1 +
 selftest/target/Samba3.pm                          |   6 +
 source3/client/smbspool.c                          | 170 +++++--
 source3/client/smbspool_krb5_wrapper.c             |  24 +-
 source3/include/passdb.h                           |   1 +
 source3/include/proto.h                            |   2 +-
 source3/lib/gencache.c                             |   8 +-
 source3/lib/idmap_cache.c                          |  48 +-
 source3/lib/idmap_cache.h                          |   2 +
 source3/lib/messages_dgm.c                         |  18 +-
 source3/lib/tldap.c                                |   1 -
 source3/lib/tldap_util.c                           |   2 -
 source3/lib/util.c                                 |   7 +-
 source3/lib/winbind_util.c                         |  41 +-
 source3/lib/winbind_util.h                         |   2 +
 source3/modules/vfs_ceph.c                         | 117 +----
 source3/modules/vfs_default.c                      |  14 +-
 source3/modules/vfs_fruit.c                        | 204 ++++----
 ...passdb-0.27.0.sigs => samba-passdb-0.27.1.sigs} |   1 +
 ...passdb-0.27.0.sigs => samba-passdb-0.27.2.sigs} |   3 +
 source3/passdb/lookup_sid.c                        | 233 +++------
 source3/passdb/lookup_sid.h                        |   1 +
 source3/passdb/pdb_util.c                          |  52 ++
 source3/printing/load.c                            |   4 +-
 source3/printing/pcap.c                            |   5 +
 source3/printing/queue_process.c                   |   6 +-
 source3/printing/spoolssd.c                        |   8 +-
 source3/script/tests/test_force_group_change.sh    |  73 +++
 source3/script/tests/test_smbspool.sh              |   4 +-
 source3/selftest/tests.py                          |   6 +-
 source3/smbd/avahi_register.c                      |  27 +
 source3/smbd/filename.c                            |  43 ++
 source3/smbd/files.c                               |   9 +
 source3/smbd/notifyd/notifyd.c                     |  11 +-
 source3/smbd/trans2.c                              |   1 +
 source3/smbd/uid.c                                 |  35 +-
 source3/torture/proto.h                            |   1 +
 source3/torture/test_idmap_cache.c                 | 122 +++++
 source3/torture/test_messaging_read.c              |  44 +-
 source3/torture/torture.c                          | 203 ++++++++
 source3/winbindd/wb_xids2sids.c                    | 107 ++--
 source3/winbindd/winbindd_proto.h                  |   2 +-
 source3/wscript                                    |   6 +
 source3/wscript_build                              |   4 +-
 source4/dsdb/samdb/ldb_modules/repl_meta_data.c    |   7 +
 source4/libcli/raw/interfaces.h                    |   1 +
 source4/libcli/smb2/create.c                       |   4 +-
 source4/librpc/wscript_build                       |   8 -
 source4/scripting/bin/sambaundoguididx             |   3 +-
 ...cted-dbcheck-link-output-lost-deleted-user1.txt |   9 +
 ...cted-dbcheck-link-output-lost-deleted-user2.txt |   8 +
 ...cted-dbcheck-link-output-lost-deleted-user3.txt |  19 +
 source4/torture/smb2/acls.c                        | 558 +++++++++++++++++++++
 source4/torture/vfs/fruit.c                        |  26 +-
 testprogs/blackbox/dbcheck-links.sh                | 342 ++++++++++++-
 testprogs/blackbox/dbcheck-oldrelease.sh           |  14 +-
 94 files changed, 3399 insertions(+), 754 deletions(-)
 create mode 100644 ctdb/common/line.c
 create mode 100644 ctdb/common/line.h
 create mode 100755 ctdb/tests/cunit/line_test_001.sh
 create mode 100644 ctdb/tests/src/line_test.c
 copy lib/ldb/ABI/{ldb-1.3.0.sigs => ldb-1.3.7.sigs} (100%)
 copy lib/ldb/ABI/{ldb-1.3.0.sigs => ldb-1.3.8.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util-1.3.7.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util-1.3.8.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util.py3-1.3.7.sigs} (100%)
 copy lib/ldb/ABI/{pyldb-util-1.1.10.sigs => pyldb-util.py3-1.3.8.sigs} (100%)
 create mode 100644 lib/ldb/tests/ldb_match_test.c
 create mode 100644 lib/ldb/tests/ldb_match_test.valgrind
 copy source3/passdb/ABI/{samba-passdb-0.27.0.sigs => samba-passdb-0.27.1.sigs} (99%)
 copy source3/passdb/ABI/{samba-passdb-0.27.0.sigs => samba-passdb-0.27.2.sigs} (99%)
 create mode 100755 source3/script/tests/test_force_group_change.sh
 create mode 100644 source3/torture/test_idmap_cache.c
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-dbcheck-link-output-lost-deleted-user1.txt
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-dbcheck-link-output-lost-deleted-user2.txt
 create mode 100644 source4/selftest/provisions/release-4-5-0-pre1/expected-dbcheck-link-output-lost-deleted-user3.txt


Changeset truncated at 500 lines:

diff --git a/VERSION b/VERSION
index 0c99c4084cb..5f6857a28b9 100644
--- a/VERSION
+++ b/VERSION
@@ -25,7 +25,7 @@
 ########################################################
 SAMBA_VERSION_MAJOR=4
 SAMBA_VERSION_MINOR=8
-SAMBA_VERSION_RELEASE=9
+SAMBA_VERSION_RELEASE=10
 
 ########################################################
 # If a official release has a serious bug              #
diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index ecb3db1c713..cc9123ee246 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -1,3 +1,117 @@
+                   ==============================
+                   Release Notes for Samba 4.8.10
+                           April 4, 2019
+                   ==============================
+
+
+This is the latest stable release of the Samba 4.8 release series.
+Please note that this will very likely be the last bugfix release of the
+Samba 4.8 release series. There will be security releases beyond this point
+only.
+
+
+Changes since 4.8.9:
+--------------------
+
+o  Jeremy Allison <jra at samba.org>
+   * BUG 13690: smbd: uid: Don't crash if 'force group' is added to an existing
+     share connection.
+   * BUG 13770: s3: VFS: vfs_fruit. Fix the NetAtalk deny mode compatibility
+     code.
+   * BUG 13803: SMB1 POSIX mkdir does case insensitive name lookup.
+
+o  Tim Beale <timbeale at catalyst.net.nz>
+   * ldb: Bump ldb version to 1.3.7.
+   * BUG 13686: 'samba-tool user syscpasswords' fails on a domain with many DCs.
+   * BUG 13762: Performance regression in LDB one-level searches.
+ 
+o  Ralph Boehme <slow at samba.org>
+   * BUG 13776: tldap: Avoid use after free errors.
+   * BUG 13802: Fix idmap xid2sid cache churn.
+   * BUG 13812: access_check_max_allowed() doesn't process "Owner Rights" ACEs.
+
+o  Günther Deschner <gd at samba.org>
+   * BUG 13746: s3-smbd: use fruit:model string for mDNS registration.
+
+o  David Disseldorp <ddiss at samba.org>
+   * BUG 13766: Printcap still processed with "load printers" disabled.
+   * BUG 13807: vfs_ceph strict_allocate_ftruncate calls (local FS) ftruncate
+     and fallocate.
+
+o  Joe Guo <joeg at catalyst.net.nz>
+   * BUG 13728: netcmd/user: python[3]-gpgme unsupported and replaced by
+     python[3]-gpg.
+
+o  Amitay Isaacs <amitay at gmail.com>
+   * BUG 13520: Fix portability issues on freebsd.
+
+o  Björn Jacke <bj at sernet.de>
+   * BUG 13759: sambaundoguididx: Use the right escaped oder unescaped sam ldb
+     files.
+
+o  Volker Lendecke <vl at samba.org>
+   * BUG 13786: messages_dgm: Properly handle receiver re-initialization.
+   * BUG 13813: Fix idmap cache pollution with S-1-22- IDs on winbind hickup.
+
+o  Gary Lockyer <gary at catalyst.net.nz>
+   * BUG 13773: CVE-2019-3824 ldb: Release ldb 1.3.8, ldb: Out of bound read in
+     ldb_wildcard_compare.
+
+o  Marcos Mello <marcosfrm at gmail.com>
+   * BUG 11568: Send status to systemd on daemon start.
+
+o  Stefan Metzmacher <metze at samba.org>
+   * BUG 13816: dbcheck in the middle of the tombstone garbage collection causes
+     replication failures.
+   * BUG 13818: An out of scope usage of a stack variable may cause corruption
+     in EnumPrinter*.
+
+o  Noel Power <noel.power at suse.com>
+   * python/samba: Extra ndr_unpack needs bytes function.
+
+o  Jiří Šašek <jiri.sasek at oracle.com>
+   * BUG 13704: notifyd: Fix SIGBUS on sparc.
+
+o  Christof Schmitt <cs at samba.org>
+   * BUG 13787: waf: Check for libnscd.
+   * BUG 13813: lib/winbind_util: Add winbind_xid_to_sid for --without-winbind.
+   * passdb: Update ABI to 0.27.2.
+
+o  Andreas Schneider <asn at samba.org>
+   * BUG 13770: s3:vfs: Correctly check if OFD locks should be enabled or not.
+   * BUG 13823: lib:util: Move debug message for mkdir failing to log level 1.
+   * BUG 13832: Fix printing via smbspool backend with kerberos auth.
+   * BUG 13847: s4:librpc: Fix installation of Samba.
+   * BUG 13848: s3:lib: Fix the debug message for adding cache entries.
+   * BUG 13853: s3:waf: Fix the detection of makdev() macro on Linux.
+
+o  Zhu Shangzhong <zhu.shangzhong at zte.com.cn>
+   * BUG 13839: ctdb: Initialize addr struct to zero before reparsing as IPV4.
+
+
+#######################################
+Reporting bugs & Development Discussion
+#######################################
+
+Please discuss this release on the samba-technical mailing list or by
+joining the #samba-technical IRC channel on irc.freenode.net.
+
+If you do report problems then please try to send high quality
+feedback. If you don't provide vital information to help us track down
+the problem then you will probably be ignored.  All bug reports should
+be filed under the "Samba 4.1 and newer" product in the project's Bugzilla
+database (https://bugzilla.samba.org/).
+
+
+======================================================================
+== Our Code, Our Bugs, Our Responsibility.
+== The Samba Team
+======================================================================
+
+
+Release notes for older releases follow:
+----------------------------------------
+
                    =============================
                    Release Notes for Samba 4.8.9
                          February 7, 2019
@@ -80,8 +194,8 @@ database (https://bugzilla.samba.org/).
 ======================================================================
 
 
-Release notes for older releases follow:
-----------------------------------------
+----------------------------------------------------------------------
+
 
                    =============================
                    Release Notes for Samba 4.8.8
@@ -1110,6 +1224,20 @@ Kerberos would return ALICE as the username. Kerberos would not be able to map
 names can be correctly mapped. This only applies to GSSAPI authentication,
 not for the geting the initial ticket granting ticket.
 
+New glusterfs_fuse VFS module
+-----------------------------
+
+The new vfs_glusterfs_fuse module improves performance when Samba
+accesses a glusterfs volume mounted via FUSE (Filesystem in Userspace
+as part of the Linux kernel). It achieves that by leveraging a
+mechanism to retrieve the appropriate case of filenames by querying a
+specific extended attribute in the filesystem. No extra configuration
+is required to use this module, only glusterfs_fuse needs to be set in
+the "vfs objects" parameter. Further details can be found in the
+vfs_glusterfs_fuse(8) manpage. This new vfs_glusterfs_fuse module does
+not replace the existing vfs_glusterfs module, it just provides an
+additional, alternative mechanism to access a Gluster volume.
+
 REMOVED FEATURES
 ================
 
diff --git a/ctdb/common/line.c b/ctdb/common/line.c
new file mode 100644
index 00000000000..c4c6726875b
--- /dev/null
+++ b/ctdb/common/line.c
@@ -0,0 +1,145 @@
+/*
+   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
new file mode 100644
index 00000000000..6b67f1e92e1
--- /dev/null
+++ b/ctdb/common/line.h
@@ -0,0 +1,62 @@
+/*
+   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/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
index c75555fa734..a46cde9f46f 100644
--- a/ctdb/protocol/protocol_util.c
+++ b/ctdb/protocol/protocol_util.c
@@ -22,6 +22,8 @@
 
 #include <talloc.h>
 
+#include "common/line.h"
+
 #include "protocol.h"
 #include "protocol_util.h"
 
@@ -249,6 +251,9 @@ static int ip_from_string(const char *str, ctdb_sock_addr *addr)
 		if (memcmp(&addr->ip6.sin6_addr.s6_addr[0],
 			   ipv4_mapped_prefix,
 			   sizeof(ipv4_mapped_prefix)) == 0) {
+                        /* Initialize addr struct to zero before reparsing as IPV4 */
+                        ZERO_STRUCTP(addr);
+
 			/* Reparse as IPv4 */
 			ret = ipv4_from_string(p+1, &addr->ip);
 		}
@@ -603,56 +608,68 @@ const char *ctdb_connection_list_to_string(
 	return out;
 }
 
-int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first,
-			      struct ctdb_connection_list **conn_list)
-{
+struct ctdb_connection_list_read_state {
 	struct ctdb_connection_list *list;
-	char line[128]; /* long enough for IPv6 */
+	bool client_first;
+};
+
+static int ctdb_connection_list_read_line(char *line, void *private_data)
+{
+	struct ctdb_connection_list_read_state *state =
+		(struct ctdb_connection_list_read_state *)private_data;
+	struct ctdb_connection conn;
 	int ret;
 
-	if (conn_list == NULL) {
-		return EINVAL;
+	/* Skip empty lines */
+	if (line[0] == '\0') {
+		return 0;
 	}
 
-	list = talloc_zero(mem_ctx, struct ctdb_connection_list);
-	if (list == NULL) {
-		return ENOMEM;
+	/* Comment */
+	if (line[0] == '#') {
+		return 0;
 	}
 
-	while (fgets(line, sizeof(line), stdin) != NULL) {
-		char *t;
-		struct ctdb_connection conn;
+	ret = ctdb_connection_from_string(line, state->client_first, &conn);
+	if (ret != 0) {
+		return ret;
+	}
 
-		/* Skip empty lines */
-		if (line[0] == '\n') {
-			continue;
-		}
+	ret = ctdb_connection_list_add(state->list, &conn);
+	if (ret != 0) {
+		return ret;
+	}
 
-		/* Comment */
-		if (line[0] == '#') {
-			continue;
-		}
+	return 0;
+}
 
-		t = strtok(line, "\n");
-		if (t == NULL) {
-			goto fail;
-		}
+int ctdb_connection_list_read(TALLOC_CTX *mem_ctx,
+			      int fd,
+			      bool client_first,
+			      struct ctdb_connection_list **conn_list)
+{
+	struct ctdb_connection_list_read_state state;
+	int ret;
 
-		ret = ctdb_connection_from_string(t, client_first, &conn);
-		if (ret != 0) {
-			goto fail;
-		}
+	if (conn_list == NULL) {
+		return EINVAL;
+	}
 
-		ret = ctdb_connection_list_add(list, &conn);
-		if (ret != 0) {
-			goto fail;
-		}
+	state.list = talloc_zero(mem_ctx, struct ctdb_connection_list);
+	if (state.list == NULL) {
+		return ENOMEM;
 	}
 
-	*conn_list = list;
-	return 0;
+	state.client_first = client_first;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list