[SCM] Samba Shared Repository - branch v4-2-test updated

Karolin Seeger kseeger at samba.org
Tue Dec 9 16:01:14 MST 2014


The branch, v4-2-test has been updated
       via  2151f1d WHATSNEW: Announce SMB2 leases support.
       via  434edeb s3:locking: Change the data model for leases_db to cope with dynamic path renames.
       via  0547beb s3:locking: pass down servicepath to leases_db_add()
       via  8ad49ec s3:locking: Add new utility function leases_db_copy_file_ids()
       via  8f2b0eb s3:locking: prepare the data model for leases_db to cope with dynamic path renames.
       via  4cf99a2 s3:locking: pass servicename_new to leases_db_rename()
       via  636d109 socket_wrapper: Add missing prototype check for eventfd.
       via  bb2177e swrap: Bump version to 1.1.2.
       via  6c220fc swrap: Add support for eventfd with unsigned count variable.
       via  c70e36a swrap: Add a trace message for swrap_socket().
       via  48a42c5 swrap: Implement fcntl() to catch F_DUPFD.
       via  ec00684 swrap: Include the function name in the debug output.
       via  b1d8ee8 swrap: Silence alignment warnings.
       via  fee8d88 swrap: Fix type punning warnings when loading functions.
       via  39aebaf swrap: Fix access to struct members in log messages.
       via  e046e44 swrap: Fix whitespace errors.
       via  2eaca17 swrap: Update copyright notice.
       via  d09501a swrap: Wrap fopen to detect stale file descriptors.
       via  cbe2d33 swrap: Use swrap_address in swrap_accept().
       via  55046c7 swrap: Remove unused sockaddr_dup() function.
       via  848ca71 swrap: Use swrap_address in the socket_info struct.
       via  728ed20 swrap: Use a sockaddr_un for the unix path in socket_info.
       via  e4d79ef swrap: Rename swrap_pcap_dump_packet().
       via  92b0c5f swrap: Rename swrap_pcap_get_fd().
       via  17b0e33 swrap: Rename swrap_marshall_packet().
       via  7a23bdf swrap: Rename swrap_packet_init().
       via  4041dfa swrap: Rename socket_wrapper_pcap_file().
       via  183fb06 swrap: Fix type punning warnings.
       via  049a0e7 Provide a compatible declaration of CMSG_ALIGN
       via  596cfe8 swrap: fix another discard const warning in swrap_bind()
       via  0f61a73 swrap: fix discard const warning in swrap_bind()
       via  40a5196 swrap: fix discard const warning in swrap_remove_stale()
       via  82bcad3 swrap: fix build when neither HAVE_STRUCT_IN_PKTINFO nor IP_RECVDSTADDR is defined
       via  ee6209b WHATSNEW: Apple's SMB2 extension AAPL
      from  3e8a168 s3: modules: Fix *allocate* calls to follow POSIX error return convention.

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


- Log -----------------------------------------------------------------
commit 2151f1dd4a85420da1e67383146555d8ae454754
Author: Jeremy Allison <jra at samba.org>
Date:   Sun Nov 9 21:30:27 2014 +0100

    WHATSNEW: Announce SMB2 leases support.
    
    Signed-off-by: Karolin Seeger <kseeger at samba.org>
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=10911
    
    Autobuild-User(v4-2-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-2-test): Wed Dec 10 00:00:08 CET 2014 on sn-devel-104

commit 434edebd769b061ba85355a961bb2999efa0f084
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 5 12:47:52 2014 -0800

    s3:locking: Change the data model for leases_db to cope with dynamic path renames.
    
    interface leases_db
    {
            typedef [public] struct {
                    GUID client_guid;
                    smb2_lease_key lease_key;
            } leases_db_key;
    
            typedef [public] struct {
                    file_id id;
                    [string,charset(UTF8)] char *servicepath;
                    [string,charset(UTF8)] char *base_name;
                    [string,charset(UTF8)] char *stream_name;
            } leases_db_file;
    
            typedef [public] struct {
                    uint32 num_files;
                    [size_is(num_files)] leases_db_file files[];
            } leases_db_value;
    }
    
    As designed by metze.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Tue Dec  9 03:44:04 CET 2014 on sn-devel-104
    
    (cherry picked from commit 5ebb1903858b4d1aadfa4e04644ec1b2b218b914)
    
    The last 5 patches address
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=10911
    SMB2 leases are not yet supported.

commit 0547beb9dec40a6a39db482d2a2255ee5e67f008
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 5 12:58:39 2014 -0800

    s3:locking: pass down servicepath to leases_db_add()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 708f87b79dcdfc58e2219e90473160eb5a22ecb6)

commit 8ad49ec3e7c934836930db07ed11a9328c24157b
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 5 12:57:24 2014 -0800

    s3:locking: Add new utility function leases_db_copy_file_ids()
    
    Will be used by lease db parsers.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit b3b878eea4ecdd13828fc8f912ad95904e8a6c5e)

commit 8f2b0eb73c58a47fe277e095b830b7b4f29f294c
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 5 12:47:52 2014 -0800

    s3:locking: prepare the data model for leases_db to cope with dynamic path renames.
    
    interface leases_db
    {
            typedef [public] struct {
                    GUID client_guid;
                    smb2_lease_key lease_key;
            } leases_db_key;
    
            typedef [public] struct {
                    file_id id;
                    [string,charset(UTF8)] char *servicepath;
                    [string,charset(UTF8)] char *base_name;
                    [string,charset(UTF8)] char *stream_name;
            } leases_db_file;
    
            typedef [public] struct {
                    uint32 num_files;
                    [size_is(num_files)] leases_db_file files[];
            } leases_db_value;
    }
    
    As designed by metze.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 5661198d718496201ea2a6bb75d043a8b255b578)

commit 4cf99a2eba473a71ac7e73ad3e7675e4a7e015c6
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 5 12:56:03 2014 -0800

    s3:locking: pass servicename_new to leases_db_rename()
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 2cd9a5c3209e947a6e63ad019da869790d01d0aa)

commit 636d10994156b8a799136207c7c65354a9a71dff
Author: Andreas Schneider <asn at samba.org>
Date:   Wed Nov 26 10:18:34 2014 +0100

    socket_wrapper: Add missing prototype check for eventfd.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=10965
    
    Newer glibc versions use and unsinged integer for the count instead of
    an integer.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 78e8bafb322ec69c5ff4b32a5e1c5679c9dea6bf)

commit bb2177e2cfd461bbf3c76f208b943130b2e73cf4
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:26:35 2014 +0200

    swrap: Bump version to 1.1.2.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Matthieu Patou <mat at matws.net>
    
    Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
    Autobuild-Date(master): Thu Oct  2 12:00:14 CEST 2014 on sn-devel-104
    
    (cherry picked from commit 47f307d112a4eaec0d375ee1604c13ed7449b3c4)

commit 6c220fceaa18adcce3b1b31946edc7c4b9071a29
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:25:32 2014 +0200

    swrap: Add support for eventfd with unsigned count variable.
    
    The prototype in glibc 2.20.90 changed.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit afe2f47c0fd17c215857e800296de795d48c004d)

commit c70e36a54da9d3731ac69a9d0e54d0c4009e57fb
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:24:55 2014 +0200

    swrap: Add a trace message for swrap_socket().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 539fa2c04f6220e72a63ab492fae298c86b00954)

commit 48a42c5f6830dce3c68e8718683b8f27d861537f
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:24:27 2014 +0200

    swrap: Implement fcntl() to catch F_DUPFD.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 8efc0952adda9273e90ffbbc0c691c9ff4b9b947)

commit ec006841ad415849d42e86b893ea95955d90b58c
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:23:53 2014 +0200

    swrap: Include the function name in the debug output.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 2efd5b242928c2e048b5421d52e35dd2e13dca15)

commit b1d8ee8c62383bde8569b74573ed3efb9bd311c3
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:23:25 2014 +0200

    swrap: Silence alignment warnings.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 872e1ae0ef22f659f52241c753f7f9b1b6f5b279)

commit fee8d883647897027a841780b5a309dfc9491663
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:22:59 2014 +0200

    swrap: Fix type punning warnings when loading functions.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 088db7f7b561c1b87a890359c67b551bc1a48593)

commit 39aebafac353e1bf12ee5a72d194139270d960a1
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:22:13 2014 +0200

    swrap: Fix access to struct members in log messages.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit b3c72e151f5dc479e600118dbdca2fdc006dbd83)

commit e046e447d588b683cadf16e334dcd39287158a4c
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:20:53 2014 +0200

    swrap: Fix whitespace errors.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 9ba259e68aa755037a1a720da3662fe07a0a7ee4)

commit 2eaca17eb9950fc6f4dd08fd69d865cd9501227b
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:20:15 2014 +0200

    swrap: Update copyright notice.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit a5046865661f814bab8af7f84f8ebd81a62067b7)

commit d09501ae51ddd9f63e3ec8dda27d8b2fe7918eb4
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:18:48 2014 +0200

    swrap: Wrap fopen to detect stale file descriptors.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 9731516e7f87cc16412eb830840d0393e8a4f823)

commit cbe2d3394682ad30c65a4d2a739d2f146223d248
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:18:14 2014 +0200

    swrap: Use swrap_address in swrap_accept().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit f8584abfef0974a19547927258369b04e03d6336)

commit 55046c75b3760fd6be79a6fb328376de8379cc89
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:17:42 2014 +0200

    swrap: Remove unused sockaddr_dup() function.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 891e837c3c0ca3db2ae2d59d04296aa67eb25d3a)

commit 848ca71ea4261f19882590ad82b5fc98aa257c81
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:17:10 2014 +0200

    swrap: Use swrap_address in the socket_info struct.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 889747486560e71d27c5a5255c825c4ebd62f8f9)

commit 728ed20384e1c2890e25d14225a6272b64483ea2
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:16:25 2014 +0200

    swrap: Use a sockaddr_un for the unix path in socket_info.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 4402ba10b5afc57e72b45ce640c14764d5f0f2c7)

commit e4d79ef933b6fb0fd8f79bfcf3c12d85dc96255f
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:15:38 2014 +0200

    swrap: Rename swrap_pcap_dump_packet().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 9da1ff9ad1d7983bd11693263f3dfcd1ed9685d4)

commit 92b0c5fe269cc61cee40e81bd55f433d0735ac96
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:14:44 2014 +0200

    swrap: Rename swrap_pcap_get_fd().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 79e545b304db8b3fa6fcb21a6f1e023e0ae0f3b4)

commit 17b0e3374dd735fa658963c24c93d7359517e9af
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:14:04 2014 +0200

    swrap: Rename swrap_marshall_packet().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 7d4c6cf25d5f424156fa0a6f90673744c5eba18e)

commit 7a23bdf06921b6db53c1cfe0d8be2f4ae629485b
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:13:10 2014 +0200

    swrap: Rename swrap_packet_init().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit e64ea9cb79b804c299d0213b2cca207fb000a3b8)

commit 4041dfa4cab56e9dfbb3a02752ab3ee6dd74febe
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:11:49 2014 +0200

    swrap: Rename socket_wrapper_pcap_file().
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit c626aad36a9757d584b9f10f0ba55dda72499c50)

commit 183fb069762bae05ab94c81b6123238a3541e962
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Oct 2 07:09:33 2014 +0200

    swrap: Fix type punning warnings.
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    (cherry picked from commit 2be25abcb13353c26712ec8bc50f65ad53d390d4)

commit 049a0e7692834131c84c76fc71b9fdb3e7aa8649
Author: Jakub Hrozek <jakub.hrozek at gmail.com>
Date:   Thu Oct 2 07:05:35 2014 +0200

    Provide a compatible declaration of CMSG_ALIGN
    
    Some platforms (like OSX) do support some of the CMGS macros, but don't
    have a CMSG_ALIGN macro of their own.
    
    Signed-off-by: Jakub Hrozek <jakub.hrozek at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>
    (cherry picked from commit 95c9917c8638f1eb5480e851c8dfbb808f1687bd)

commit 596cfe8bc2d7bbb719845eb8240125ed3ae145cd
Author: Michael Adam <obnox at samba.org>
Date:   Thu Oct 2 07:03:22 2014 +0200

    swrap: fix another discard const warning in swrap_bind()
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit 616364378da073f841d46fb299c81adb05d5222d)

commit 0f61a736daec84968671f4d0848fff71e9c3db60
Author: Michael Adam <obnox at samba.org>
Date:   Thu Oct 2 07:02:36 2014 +0200

    swrap: fix discard const warning in swrap_bind()
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit f6fe9a997d2f5a1c504ea53886e00cfb33ec76d0)

commit 40a5196ab8f91aa641e27babee488a7cefc88d73
Author: Michael Adam <obnox at samba.org>
Date:   Thu Oct 2 07:01:34 2014 +0200

    swrap: fix discard const warning in swrap_remove_stale()
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit bebbd289859cff50d63cdbe76d214b67fd33e3f8)

commit 82bcad3aeeba61bcc118f8074cafdcbe2fccb308
Author: Michael Adam <obnox at samba.org>
Date:   Thu Oct 2 07:00:44 2014 +0200

    swrap: fix build when neither HAVE_STRUCT_IN_PKTINFO nor IP_RECVDSTADDR is defined
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit a7a47796fd7ca1fa830a8c2644042c311b9796da)

commit ee6209b0dd54ac984d03622b006d80d25ed199ce
Author: Ralph Boehme <slow at samba.org>
Date:   Mon Dec 8 13:27:22 2014 +0100

    WHATSNEW: Apple's SMB2 extension AAPL
    
    Signed-off-by: Ralph Boehme <slow at samba.org>

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

Summary of changes:
 WHATSNEW.txt                        |  16 +-
 lib/socket_wrapper/socket_wrapper.c | 821 ++++++++++++++++++++++--------------
 lib/socket_wrapper/wscript          |   7 +-
 source3/librpc/idl/leases_db.idl    |  11 +-
 source3/locking/leases_db.c         |  85 ++--
 source3/locking/leases_db.h         |  13 +-
 source3/locking/locking.c           |   1 +
 source3/smbd/open.c                 | 151 +++++--
 source3/smbd/smb2_break.c           |  16 +-
 9 files changed, 726 insertions(+), 395 deletions(-)


Changeset truncated at 500 lines:

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 1673911..a96e7f7 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -145,6 +145,19 @@ The default values for "smb2 max read", "smb2 max write" and "smb2 max trans"
 have been changed to 8388608 (8MiB) in order to match the default of
 Windows 2012R2.
 
+SMB2 leases
+===========
+
+The SMB2 protocol allows clients to aggressively cache files
+locally above and beyond the caching allowed by SMB1 and SMB2 oplocks.
+
+Called SMB2 leases, this can greatly reduce traffic on an SMB2
+connection. Samba 4.2 now implements SMB2 leases.
+
+It can be turned on by setting the parameter "smb2 leases = yes"
+in the [global] section of your smb.conf. This parameter is set
+to off by default until the SMB2 leasing code is declared fully stable.
+
 Improved DCERPC man in the middle detection
 ===========================================
 
@@ -287,7 +300,8 @@ clients and interoperability with a Netatalk 3 AFP fileserver.
 The module features enhanced performance with reliable named streams
 support, interoperability with special characters commonly used by OS
 X client (eg '*', '/'), integrated file locking and Mac metadata
-access with Netatalk 3.
+access with Netatalk 3 and enhanced performance by implementing
+Apple's SMB2 extension codenamed "AAPL".
 
 The modules behaviour is fully configurable, please refer to the
 manpage vfs_fruit for further details.
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index 67303eb..d5c343d 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -1,7 +1,7 @@
 /*
- * Copyright (C) Jelmer Vernooij 2005,2008 <jelmer at samba.org>
- * Copyright (C) Stefan Metzmacher 2006-2009 <metze at samba.org>
- * Copyright (C) Andreas Schneider 2013 <asn at samba.org>
+ * Copyright (c) 2005-2008 Jelmer Vernooij <jelmer at samba.org>
+ * Copyright (C) 2006-2014 Stefan Metzmacher <metze at samba.org>
+ * Copyright (C) 2013-2014 Andreas Schneider <asn at samba.org>
  *
  * All rights reserved.
  *
@@ -210,6 +210,19 @@ enum swrap_dbglvl_e {
  * without changing the format above */
 #define MAX_WRAPPED_INTERFACES 40
 
+struct swrap_address {
+	socklen_t sa_socklen;
+	union {
+		struct sockaddr s;
+		struct sockaddr_in in;
+#ifdef HAVE_IPV6
+		struct sockaddr_in6 in6;
+#endif
+		struct sockaddr_un un;
+		struct sockaddr_storage ss;
+	} sa;
+};
+
 struct socket_info_fd {
 	struct socket_info_fd *prev, *next;
 	int fd;
@@ -229,16 +242,12 @@ struct socket_info
 	int defer_connect;
 	int pktinfo;
 
-	char *tmp_path;
-
-	struct sockaddr *bindname;
-	socklen_t bindname_len;
-
-	struct sockaddr *myname;
-	socklen_t myname_len;
+	/* The unix path so we can unlink it on close() */
+	struct sockaddr_un un_addr;
 
-	struct sockaddr *peername;
-	socklen_t peername_len;
+	struct swrap_address bindname;
+	struct swrap_address myname;
+	struct swrap_address peername;
 
 	struct {
 		unsigned long pck_snd;
@@ -263,10 +272,12 @@ void swrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
 # define SWRAP_LOG(...)
 #else
 
-static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
-# define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __VA_ARGS__)
+static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *func, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
+# define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __func__, __VA_ARGS__)
 
-static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *format, ...)
+static void swrap_log(enum swrap_dbglvl_e dbglvl,
+		      const char *func,
+		      const char *format, ...)
 {
 	char buffer[1024];
 	va_list va;
@@ -286,23 +297,23 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *format, ...)
 		switch (dbglvl) {
 			case SWRAP_LOG_ERROR:
 				fprintf(stderr,
-					"SWRAP_ERROR(%d): %s\n",
-					(int)getpid(), buffer);
+					"SWRAP_ERROR(%d) - %s: %s\n",
+					(int)getpid(), func, buffer);
 				break;
 			case SWRAP_LOG_WARN:
 				fprintf(stderr,
-					"SWRAP_WARN(%d): %s\n",
-					(int)getpid(), buffer);
+					"SWRAP_WARN(%d) - %s: %s\n",
+					(int)getpid(), func, buffer);
 				break;
 			case SWRAP_LOG_DEBUG:
 				fprintf(stderr,
-					"SWRAP_DEBUG(%d): %s\n",
-					(int)getpid(), buffer);
+					"SWRAP_DEBUG(%d) - %s: %s\n",
+					(int)getpid(), func, buffer);
 				break;
 			case SWRAP_LOG_TRACE:
 				fprintf(stderr,
-					"SWRAP_TRACE(%d): %s\n",
-					(int)getpid(), buffer);
+					"SWRAP_TRACE(%d) - %s: %s\n",
+					(int)getpid(), func, buffer);
 				break;
 		}
 	}
@@ -328,6 +339,8 @@ struct swrap_libc_fns {
 			    socklen_t addrlen);
 	int (*libc_dup)(int fd);
 	int (*libc_dup2)(int oldfd, int newfd);
+	int (*libc_fcntl)(int fd, int cmd, ...);
+	FILE *(*libc_fopen)(const char *name, const char *mode);
 #ifdef HAVE_EVENTFD
 	int (*libc_eventfd)(int count, int flags);
 #endif
@@ -510,8 +523,9 @@ static void *_swrap_load_lib_function(enum swrap_lib lib, const char *fn_name)
 
 #define swrap_load_lib_function(lib, fn_name) \
 	if (swrap.fns.libc_##fn_name == NULL) { \
+		void *swrap_cast_ptr = _swrap_load_lib_function(lib, #fn_name); \
 		*(void **) (&swrap.fns.libc_##fn_name) = \
-			_swrap_load_lib_function(lib, #fn_name); \
+			swrap_cast_ptr; \
 	}
 
 
@@ -578,6 +592,28 @@ static int libc_eventfd(int count, int flags)
 }
 #endif
 
+static int libc_vfcntl(int fd, int cmd, va_list ap)
+{
+	long int args[4];
+	int rc;
+	int i;
+
+	swrap_load_lib_function(SWRAP_LIBC, fcntl);
+
+	for (i = 0; i < 4; i++) {
+		args[i] = va_arg(ap, long int);
+	}
+
+	rc = swrap.fns.libc_fcntl(fd,
+				  cmd,
+				  args[0],
+				  args[1],
+				  args[2],
+				  args[3]);
+
+	return rc;
+}
+
 static int libc_getpeername(int sockfd,
 			    struct sockaddr *addr,
 			    socklen_t *addrlen)
@@ -636,6 +672,13 @@ static int libc_listen(int sockfd, int backlog)
 	return swrap.fns.libc_listen(sockfd, backlog);
 }
 
+static FILE *libc_fopen(const char *name, const char *mode)
+{
+	swrap_load_lib_function(SWRAP_LIBC, fopen);
+
+	return swrap.fns.libc_fopen(name, mode);
+}
+
 static int libc_vopen(const char *pathname, int flags, va_list ap)
 {
 	long int mode = 0;
@@ -813,22 +856,15 @@ static const struct in6_addr *swrap_ipv6(void)
 }
 #endif
 
-static struct sockaddr *sockaddr_dup(const void *data, socklen_t len)
-{
-	struct sockaddr *ret = (struct sockaddr *)malloc(len);
-	memcpy(ret, data, len);
-	return ret;
-}
-
-static void set_port(int family, int prt, struct sockaddr *addr)
+static void set_port(int family, int prt, struct swrap_address *addr)
 {
 	switch (family) {
 	case AF_INET:
-		((struct sockaddr_in *)addr)->sin_port = htons(prt);
+		addr->sa.in.sin_port = htons(prt);
 		break;
 #ifdef HAVE_IPV6
 	case AF_INET6:
-		((struct sockaddr_in6 *)addr)->sin6_port = htons(prt);
+		addr->sa.in6.sin6_port = htons(prt);
 		break;
 #endif
 	}
@@ -970,7 +1006,7 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i
 
 	switch (inaddr->sa_family) {
 	case AF_INET: {
-		const struct sockaddr_in *in = 
+		const struct sockaddr_in *in =
 		    (const struct sockaddr_in *)(const void *)inaddr;
 		unsigned int addr = ntohl(in->sin_addr.s_addr);
 		char u_type = '\0';
@@ -1017,7 +1053,7 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i
 	}
 #ifdef HAVE_IPV6
 	case AF_INET6: {
-		const struct sockaddr_in6 *in = 
+		const struct sockaddr_in6 *in =
 		    (const struct sockaddr_in6 *)(const void *)inaddr;
 		struct in6_addr cmp1, cmp2;
 
@@ -1064,14 +1100,14 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i
 	}
 
 	if (is_bcast) {
-		snprintf(un->sun_path, sizeof(un->sun_path), "%s/EINVAL", 
+		snprintf(un->sun_path, sizeof(un->sun_path), "%s/EINVAL",
 			 socket_wrapper_dir());
 		SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path);
 		/* the caller need to do more processing */
 		return 0;
 	}
 
-	snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, 
+	snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT,
 		 socket_wrapper_dir(), type, iface, prt);
 	SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path);
 
@@ -1091,7 +1127,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
 
 	switch (si->family) {
 	case AF_INET: {
-		const struct sockaddr_in *in = 
+		const struct sockaddr_in *in =
 		    (const struct sockaddr_in *)(const void *)inaddr;
 		unsigned int addr = ntohl(in->sin_addr.s_addr);
 		char u_type = '\0';
@@ -1144,7 +1180,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
 		}
 
 		/* Store the bind address for connect() */
-		if (si->bindname == NULL) {
+		if (si->bindname.sa_socklen == 0) {
 			struct sockaddr_in bind_in;
 			socklen_t blen = sizeof(struct sockaddr_in);
 
@@ -1153,15 +1189,15 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
 			bind_in.sin_port = in->sin_port;
 			bind_in.sin_addr.s_addr = htonl(0x7F000000 | iface);
 
-			si->bindname = sockaddr_dup(&bind_in, blen);
-			si->bindname_len = blen;
+			si->bindname.sa_socklen = blen;
+			memcpy(&si->bindname.sa.in, &bind_in, blen);
 		}
 
 		break;
 	}
 #ifdef HAVE_IPV6
 	case AF_INET6: {
-		const struct sockaddr_in6 *in = 
+		const struct sockaddr_in6 *in =
 		    (const struct sockaddr_in6 *)(const void *)inaddr;
 		struct in6_addr cmp1, cmp2;
 
@@ -1195,7 +1231,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
 		}
 
 		/* Store the bind address for connect() */
-		if (si->bindname == NULL) {
+		if (si->bindname.sa_socklen == 0) {
 			struct sockaddr_in6 bind_in;
 			socklen_t blen = sizeof(struct sockaddr_in6);
 
@@ -1206,8 +1242,8 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
 			bind_in.sin6_addr = *swrap_ipv6();
 			bind_in.sin6_addr.s6_addr[15] = iface;
 
-			si->bindname = sockaddr_dup(&bind_in, blen);
-			si->bindname_len = blen;
+			memcpy(&si->bindname.sa.in6, &bind_in, blen);
+			si->bindname.sa_socklen = blen;
 		}
 
 		break;
@@ -1230,12 +1266,12 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
 	if (prt == 0) {
 		/* handle auto-allocation of ephemeral ports */
 		for (prt = 5001; prt < 10000; prt++) {
-			snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, 
+			snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT,
 				 socket_wrapper_dir(), type, iface, prt);
 			if (stat(un->sun_path, &st) == 0) continue;
 
-			set_port(si->family, prt, si->myname);
-			set_port(si->family, prt, si->bindname);
+			set_port(si->family, prt, &si->myname);
+			set_port(si->family, prt, &si->bindname);
 
 			break;
 		}
@@ -1245,7 +1281,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
 		}
 	}
 
-	snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, 
+	snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT,
 		 socket_wrapper_dir(), type, iface, prt);
 	SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path);
 	return 0;
@@ -1394,14 +1430,14 @@ static int sockaddr_convert_to_un(struct socket_info *si,
 
 	switch (in_addr->sa_family) {
 	case AF_UNSPEC: {
-		struct sockaddr_in *sin;
+		const struct sockaddr_in *sin;
 		if (si->family != AF_INET) {
 			break;
 		}
 		if (in_len < sizeof(struct sockaddr_in)) {
 			break;
 		}
-		sin = (struct sockaddr_in *)in_addr;
+		sin = (const struct sockaddr_in *)(const void *)in_addr;
 		if(sin->sin_addr.s_addr != htonl(INADDR_ANY)) {
 			break;
 		}
@@ -1440,8 +1476,8 @@ static int sockaddr_convert_to_un(struct socket_info *si,
 	return -1;
 }
 
-static int sockaddr_convert_from_un(const struct socket_info *si, 
-				    const struct sockaddr_un *in_addr, 
+static int sockaddr_convert_from_un(const struct socket_info *si,
+				    const struct sockaddr_un *in_addr,
 				    socklen_t un_addrlen,
 				    int family,
 				    struct sockaddr *out_addr,
@@ -1449,7 +1485,7 @@ static int sockaddr_convert_from_un(const struct socket_info *si,
 {
 	int ret;
 
-	if (out_addr == NULL || out_addrlen == NULL) 
+	if (out_addr == NULL || out_addrlen == NULL)
 		return 0;
 
 	if (un_addrlen == 0) {
@@ -1597,7 +1633,7 @@ union swrap_packet_payload {
 	 SWRAP_PACKET_IP_SIZE + \
 	 SWRAP_PACKET_PAYLOAD_SIZE)
 
-static const char *socket_wrapper_pcap_file(void)
+static const char *swrap_pcap_init_file(void)
 {
 	static int initialized = 0;
 	static const char *s = NULL;
@@ -1614,7 +1650,7 @@ static const char *socket_wrapper_pcap_file(void)
 	/*
 	 * TODO: don't use the structs use plain buffer offsets
 	 *       and PUSH_U8(), PUSH_U16() and PUSH_U32()
-	 * 
+	 *
 	 * for now make sure we disable PCAP support
 	 * if the struct has alignment!
 	 */
@@ -1659,17 +1695,17 @@ static const char *socket_wrapper_pcap_file(void)
 	return s;
 }
 
-static uint8_t *swrap_packet_init(struct timeval *tval,
-				  const struct sockaddr *src,
-				  const struct sockaddr *dest,
-				  int socket_type,
-				  const uint8_t *payload,
-				  size_t payload_len,
-				  unsigned long tcp_seqno,
-				  unsigned long tcp_ack,
-				  unsigned char tcp_ctl,
-				  int unreachable,
-				  size_t *_packet_len)
+static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
+				       const struct sockaddr *src,
+				       const struct sockaddr *dest,
+				       int socket_type,
+				       const uint8_t *payload,
+				       size_t payload_len,
+				       unsigned long tcp_seqno,
+				       unsigned long tcp_ack,
+				       unsigned char tcp_ctl,
+				       int unreachable,
+				       size_t *_packet_len)
 {
 	uint8_t *base;
 	uint8_t *buf;
@@ -1696,16 +1732,16 @@ static uint8_t *swrap_packet_init(struct timeval *tval,
 
 	switch (src->sa_family) {
 	case AF_INET:
-		src_in = (const struct sockaddr_in *)src;
-		dest_in = (const struct sockaddr_in *)dest;
+		src_in = (const struct sockaddr_in *)(const void *)src;
+		dest_in = (const struct sockaddr_in *)(const void *)dest;
 		src_port = src_in->sin_port;
 		dest_port = dest_in->sin_port;
 		ip_hdr_len = sizeof(ip->v4);
 		break;
 #ifdef HAVE_IPV6
 	case AF_INET6:
-		src_in6 = (const struct sockaddr_in6 *)src;
-		dest_in6 = (const struct sockaddr_in6 *)dest;
+		src_in6 = (const struct sockaddr_in6 *)(const void *)src;
+		dest_in6 = (const struct sockaddr_in6 *)(const void *)dest;
 		src_port = src_in6->sin6_port;
 		dest_port = dest_in6->sin6_port;
 		ip_hdr_len = sizeof(ip->v6);
@@ -1767,14 +1803,14 @@ static uint8_t *swrap_packet_init(struct timeval *tval,
 
 	buf = base;
 
-	frame = (struct swrap_packet_frame *)buf;
+	frame = (struct swrap_packet_frame *)(void *)buf;
 	frame->seconds		= tval->tv_sec;
 	frame->micro_seconds	= tval->tv_usec;
 	frame->recorded_length	= wire_len - icmp_truncate_len;
 	frame->full_length	= wire_len - icmp_truncate_len;
 	buf += SWRAP_PACKET_FRAME_SIZE;
 
-	ip = (union swrap_packet_ip *)buf;
+	ip = (union swrap_packet_ip *)(void *)buf;
 	switch (src->sa_family) {
 	case AF_INET:
 		ip->v4.ver_hdrlen	= 0x45; /* version 4 and 5 * 32 bit words */
@@ -1805,7 +1841,7 @@ static uint8_t *swrap_packet_init(struct timeval *tval,
 	}
 
 	if (unreachable) {
-		pay = (union swrap_packet_payload *)buf;
+		pay = (union swrap_packet_payload *)(void *)buf;
 		switch (src->sa_family) {
 		case AF_INET:
 			pay->icmp4.type		= 0x03; /* destination unreachable */
@@ -1815,7 +1851,7 @@ static uint8_t *swrap_packet_init(struct timeval *tval,
 			buf += SWRAP_PACKET_PAYLOAD_ICMP4_SIZE;
 
 			/* set the ip header in the ICMP payload */
-			ip = (union swrap_packet_ip *)buf;
+			ip = (union swrap_packet_ip *)(void *)buf;
 			ip->v4.ver_hdrlen	= 0x45; /* version 4 and 5 * 32 bit words */
 			ip->v4.tos		= 0x00;
 			ip->v4.packet_length	= htons(wire_len - icmp_hdr_len);
@@ -1841,7 +1877,7 @@ static uint8_t *swrap_packet_init(struct timeval *tval,
 			buf += SWRAP_PACKET_PAYLOAD_ICMP6_SIZE;
 
 			/* set the ip header in the ICMP payload */
-			ip = (union swrap_packet_ip *)buf;
+			ip = (union swrap_packet_ip *)(void *)buf;
 			ip->v6.ver_prio		= 0x60; /* version 4 and 5 * 32 bit words */
 			ip->v6.flow_label_high	= 0x00;
 			ip->v6.flow_label_low	= 0x0000;
@@ -1858,7 +1894,7 @@ static uint8_t *swrap_packet_init(struct timeval *tval,
 		}
 	}
 
-	pay = (union swrap_packet_payload *)buf;
+	pay = (union swrap_packet_payload *)(void *)buf;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list