[PATCHES v2] Fix FreeBSD developer build

Uri Simchoni uri at samba.org
Tue Nov 21 19:25:17 UTC 2017


Hi,

Attached version 3 - same as v2, but with added 3 patches at the end,
which allow FreeBSD developer build to run without the ADDITIONAL_CFLAGS
workaround, and without breaking Linux...

Some responses below.

Thanks,
Uri.

On 11/21/2017 12:58 AM, Timur I. Bakeyev via samba-technical wrote:
> Hi, Uri!
> 
> That's quite a jumbo patch, possibly splitting it into smaller chunks could
> be easier to review :)
> 

That's a jumbo patch-*set*. Each patch is pretty small, concerns one
issue, and most patches modify a single file. I believe that's more or
less the Samba practice. Granted, it's easier for people to review a
small patch set, but that would mean I'd get into a cycle of several
weeks, waiting for the previous subset to land before submitting the
next one - I don't have the patience for that so let's keep our fingers
crossed.

> I've noticed mentioning of missing HAVE_INTPTR_T on FreeBSD, need to check
> that, but meanwhile:
> 
> https://bugzilla.samba.org/show_bug.cgi?id=4635
> 
> Also, is that patchset against the HEAD? As traditionally we usually first
> work with releases, so at least two patches fail to me...
> 
> What are the problems with the patches I sent on Linux? I believe similar
> approach is used in couple of other places in wscripts.
> 

I didn't want to use the patches as-is, as I don't support the notion
of CHECK_CFLAGS(<flag-we-want-to-check> + <error flags>). CHECK_CFLAGS
should be able to detect <flag-we-want-to-check> without having to add.
So what I did was make a similar change to CHECK_CFLAGS itself. That
worked on FreeBSD, but changed the set of supported flags on Fedora 25
(GCC 6.4.1), all of the sudden claiming that -Wformat-security is not
supported. With further examination, it turned out that
-Wformat-security is ignored when -Wformat is not specified, hence the
addition of "prereq_flags" to CHECK_FLAGS.

> With regards,
> Timur Bakeyev.
> 
> 
> 
> 
> 
> On Mon, Nov 20, 2017 at 11:00 PM, Uri Simchoni <uri at samba.org> wrote:
> 
>> Attached v2, with 16/35 modified so as not to change the params.
>>
>> As for the cflag detection tricks - What I tried changed things on the
>> Linux/gcc side, so I propose to leave it at that (with the
>> ADDITIONAL_CFLAGS workaround) and attack this later.
>>
>> Thanks,
>> Uri.
>>
>> On 11/20/2017 03:26 PM, Timur I. Bakeyev via samba-technical wrote:
>>> Thanks, Uri, a great work have been done to chaise all this annoying
>>> warnings. Hope those will end up in the master tree.
>>>
>>> In you "[PATCH 16/35] winbind_nss_freebsd: fix a const discard warning"
>>> though you change the signature of the function:
>>>
>>> int
>>> __getgroupmembership(const char *uname, gid_t agroup, gid_t *groups,
>>>         int maxgrp, int *grpcnt)
>>>
>>> which should be avoided. Need to fix this warning somewhere else.
>>>
>>> As for the Clang being liberal regarding unknown options we use the
>>> following trick:
>>>
>>> --- buildtools/wafsamba/samba_autoconf.py.orig  2017-07-04 10:05:25 UTC
>>> +++ buildtools/wafsamba/samba_autoconf.py
>>> @@ -873,7 +873,7 @@ def SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS(c
>>>          conf.env.undefined_ldflags = conf.ADD_LDFLAGS('-Wl,-no-
>> undefined',
>>> testflags=True)
>>>
>>>      if not sys.platform.startswith("openbsd") and
>>> conf.env.undefined_ignore_ldflags == []:
>>> -        if conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup']):
>>> +        if conf.CHECK_LDFLAGS(['-undefined', 'dynamic_lookup'] +
>>> conf.env.WERROR_CFLAGS):
>>>              conf.env.undefined_ignore_ldflags = ['-undefined',
>>> 'dynamic_lookup']
>>>
>>>  @conf
>>> --- lib/replace/wscript.orig    2017-11-02 11:38:36 UTC
>>> +++ lib/replace/wscript
>>> @@ -81,7 +81,7 @@ def configure(conf):
>>>      conf.CHECK_HEADERS('sys/atomic.h')
>>>      conf.CHECK_HEADERS('libgen.h')
>>>
>>> -    if conf.CHECK_CFLAGS('-Wno-format-truncation'):
>>> +    if conf.CHECK_CFLAGS(['-Wno-format-truncation'] +
>>> conf.env.WERROR_CFLAGS):
>>>          conf.define('HAVE_WNO_FORMAT_TRUNCATION', '1')
>>>
>>>      # Check for process set name support
>>>
>>>
>>> There are a lot of small fixes like this in the FreeBSD Samba port, hope
>>> they'll find their way into master as well.
>>>
>>> With regards,
>>> Timur Bakeyev.
>>>
>>> On Mon, Nov 20, 2017 at 10:10 AM, Uri Simchoni <uri at samba.org> wrote:
>>>
>>>> On 11/18/2017 01:35 AM, Jeremy Allison via samba-technical wrote:
>>>>>
>>>>> Right now, can you type:
>>>>>
>>>>> make test
>>>>>
>>>>> on a FreeBSD Samba build and have all the tests pass ? I
>>>>> would currently doubt it, as many of the tests (like the
>>>>> Linux kernel oplock and change notify ones) require Linux
>>>>> specific features. Also, some of the tevent tests require
>>>>> epoll etc. etc.
>>>>>
>>>>
>>>> As step 0.1, here's a patch set that make Samba build successfully in
>>>> developer mode on FreeBSD 11.1-RELEASE (clang 4.0.0). Most of this is
>>>> clang-related, so I suppose it has value beyond FreeBSD.
>>>>
>>>> The configuration command I used was:
>>>>
>>>> ADDITIONAL_CFLAGS="-Wno-unknown-warning-option" ./configure.developer
>>>> --with-selftest-prefix=./bin/ab  --picky-developer --abi-check-disable
>>>> --prefix=<my prefix> --with-profiling-data
>>>>
>>>> This is *almost* the Samba autobuild configuration, except:
>>>> 1. No ABI checking - It looks like ABI checking depends on some tool
>>>> that emits differently-formatted output on FreeBSD
>>>>
>>>> 2. The no-unknonwn-warning-option - I couldn't figure out how to make
>>>> clang, during configuration time, identify whether it supports a warning
>>>> option or not, *without* supplying other command line options which
>>>> could bread another compiler. Upstream waf simply identifies clang, so
>>>> one might use that to insert clang-specific behavior.
>>>>
>>>> I'm not sure when (and if...) I'll be able to continue this and see what
>>>> are the make test hurdles. If we can hook this to some CI, we can detect
>>>> post-push build breakage and fix it before release.
>>>>
>>>> Thanks,
>>>> Uri.
>>>>
>>>>> This is doable, but not an easy change to make.
>>>>>
>>>>
>>>>
>>
>>


-------------- next part --------------
From 95f938e1ba63de5165c0950973d0607da01902a4 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 05:07:54 +0000
Subject: [PATCH v3 01/38] sysacls: make SMB_ACL_PERMSET_T opaque

sys_acl_get_permset() returns a pointer to a uint32_t. Prior
to this change, SMB_ACL_PERMSET_T has been defined as a mode_t
pointer, where mode_t may or may not be uint32_t (on FreeBSD
it's uint16_t, which could screw up big-endian FreeBSD systems).

Since SMB_ACL_PERMSET_T is being used as an opaque
data type to the ouside world, this patch changes it
to a void*, and in the implementation casts the pointer
to a uint32_t pointer.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/include/smb_acls.h |  2 +-
 source3/lib/sysacls.c      | 20 +++++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/source3/include/smb_acls.h b/source3/include/smb_acls.h
index 73b67af..629c243 100644
--- a/source3/include/smb_acls.h
+++ b/source3/include/smb_acls.h
@@ -27,7 +27,7 @@ struct files_struct;
 struct smb_filename;
 
 typedef int			SMB_ACL_TYPE_T;
-typedef mode_t			*SMB_ACL_PERMSET_T;
+typedef void			*SMB_ACL_PERMSET_T;
 typedef mode_t			SMB_ACL_PERM_T;
 
 typedef enum smb_acl_tag_t SMB_ACL_TAG_T;
diff --git a/source3/lib/sysacls.c b/source3/lib/sysacls.c
index 0bf3c37..7d5c7e1 100644
--- a/source3/lib/sysacls.c
+++ b/source3/lib/sysacls.c
@@ -95,7 +95,7 @@ int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
 
 int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
 {
-	*permset_p = &entry_d->a_perm;
+	*permset_p = (SMB_ACL_PERMSET_T)&entry_d->a_perm;
 
 	return 0;
 }
@@ -116,32 +116,37 @@ void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
 
 int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
 {
-	*permset_d = 0;
+	uint32_t *perm_p = permset_d;
+	*perm_p = 0;
 
 	return 0;
 }
 
 int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
 {
+	uint32_t *perm_p = permset_d;
+
 	if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
 	    && perm != SMB_ACL_EXECUTE) {
 		errno = EINVAL;
 		return -1;
 	}
 
-	if (permset_d == NULL) {
+	if (perm_p == NULL) {
 		errno = EINVAL;
 		return -1;
 	}
 
-	*permset_d |= perm;
+	*perm_p |= perm;
 
 	return 0;
 }
 
 int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
 {
-	return *permset_d & perm;
+	uint32_t *perm_p = permset_d;
+
+	return *perm_p & perm;
 }
 
 char *sys_acl_to_text(const struct smb_acl_t *acl_d, ssize_t *len_p)
@@ -331,12 +336,13 @@ int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
 
 int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
 {
-	if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
+	uint32_t *perm_p = permset_d;
+	if (*perm_p & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
 		errno = EINVAL;
 		return -1;
 	}
 
-	entry_d->a_perm = *permset_d;
+	entry_d->a_perm = *perm_p;
 
 	return 0;
 }
-- 
2.9.5


From 7f3279ba8b45af3a1b65a2e1ceb2aa330437a279 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 05:18:03 +0000
Subject: [PATCH v3 02/38] nfs4acl: fix picky build in case rpc/xdr.h is not
 available

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/nfs4acl_xattr_xdr.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/source3/modules/nfs4acl_xattr_xdr.c b/source3/modules/nfs4acl_xattr_xdr.c
index 67684dce..524e69c 100644
--- a/source3/modules/nfs4acl_xattr_xdr.c
+++ b/source3/modules/nfs4acl_xattr_xdr.c
@@ -403,6 +403,7 @@ NTSTATUS nfs4acl_xdr_blob_to_smb4(struct vfs_handle_struct *handle,
 }
 
 #else /* !HAVE_RPC_XDR_H */
+#include "nfs4acl_xattr_xdr.h"
 NTSTATUS nfs4acl_xdr_blob_to_smb4(struct vfs_handle_struct *handle,
 				  TALLOC_CTX *mem_ctx,
 				  DATA_BLOB *blob,
-- 
2.9.5


From a1135c14d44d162936a5110a3089f50fa6e810c7 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 05:20:57 +0000
Subject: [PATCH v3 03/38] torture: remove spurious semicolon

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/torture/rpc/spoolss_notify.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source4/torture/rpc/spoolss_notify.c b/source4/torture/rpc/spoolss_notify.c
index dd9cd31..718ae70 100644
--- a/source4/torture/rpc/spoolss_notify.c
+++ b/source4/torture/rpc/spoolss_notify.c
@@ -500,7 +500,8 @@ static bool test_start_dcerpc_server(struct torture_context *tctx,
 static struct received_packet *last_packet(struct received_packet *p)
 {
 	struct received_packet *tmp;
-	for (tmp = p; tmp->next; tmp = tmp->next) ;;
+	for (tmp = p; tmp->next; tmp = tmp->next) {
+	}
 	return tmp;
 }
 
-- 
2.9.5


From 50e031164dda7ef7f790d9601a69c46db30d1c17 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 07:02:12 +0000
Subject: [PATCH v3 04/38] lib/crypto: remove unused code

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/crypto/sha512.c | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/lib/crypto/sha512.c b/lib/crypto/sha512.c
index 9c7367b..41be1ec 100644
--- a/lib/crypto/sha512.c
+++ b/lib/crypto/sha512.c
@@ -38,26 +38,6 @@
 #define min(a,b) (((a)>(b))?(b):(a))
 #endif
 
-/* Vector Crays doesn't have a good 32-bit type, or more precisely,
-   int32_t as defined by <bind/bitypes.h> isn't 32 bits, and we don't
-   want to depend in being able to redefine this type.  To cope with
-   this we have to clamp the result in some places to [0,2^32); no
-   need to do this on other machines.  Did I say this was a mess?
-   */
-
-#ifdef _CRAY
-#define CRAYFIX(X) ((X) & 0xffffffff)
-#else
-#define CRAYFIX(X) (X)
-#endif
-
-static inline uint32_t
-cshift (uint32_t x, unsigned int n)
-{
-    x = CRAYFIX(x);
-    return CRAYFIX((x << n) | (x >> (32 - n)));
-}
-
 static inline uint64_t
 cshift64 (uint64_t x, unsigned int n)
 {
-- 
2.9.5


From d1e794ddfd9111578452b40c54a3e6a016ce214e Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 07:02:51 +0000
Subject: [PATCH v3 05/38] s4-cli: increment once in the for loop

Done to silence a clang warning.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/libcli/resolve/lmhosts.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/source4/libcli/resolve/lmhosts.c b/source4/libcli/resolve/lmhosts.c
index 21cc3e4..6416da8 100644
--- a/source4/libcli/resolve/lmhosts.c
+++ b/source4/libcli/resolve/lmhosts.c
@@ -71,7 +71,7 @@ struct composite_context *resolve_name_lmhosts_send(TALLOC_CTX *mem_ctx,
 						     state, &resolved_iplist, &resolved_count);
 	if (!composite_is_ok(c)) return c;
 
-	for (i=0; i < resolved_count; i++) {
+	for (i=0; i < resolved_count; i+=2) {
 		state->addrs = talloc_realloc(state, state->addrs, struct socket_address *, i+2);
 		if (composite_nomem(state->addrs, c)) return c;
 
@@ -90,8 +90,6 @@ struct composite_context *resolve_name_lmhosts_send(TALLOC_CTX *mem_ctx,
 		if (composite_nomem(state->names[i], c)) return c;
 
 		state->names[i+1] = NULL;
-
-		i++;
 	}
 
 	composite_done(c);
-- 
2.9.5


From e8219f8a1ff1b2ef7a39b0bd34fa67a1b3b28a23 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 07:04:16 +0000
Subject: [PATCH v3 06/38] replace: avoid shifting a negative value

This is undefined according to clang, and generates a
warning when doing a picky-developer build.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/replace/replace.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 128978c..7f53b1e 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -649,8 +649,11 @@ int rep_strerror_r(int errnum, char *buf, size_t buflen);
 #define _TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
    It is necessary at least when t == time_t.  */
-#define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) \
-  			      ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
+#define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) ? \
+			       (t)( \
+				   (unsigned long long)(~ (t) 0) << \
+				   (sizeof (t) * CHAR_BIT - 1) \
+				  ) : (t) 0))
 #define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t)))
 
 #ifndef UINT16_MAX
-- 
2.9.5


From d1f372c10b469d56c1643486ab12ab0746ee6d80 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 07:19:03 +0000
Subject: [PATCH v3 07/38] ldb: silence some clang warnings in picky developer
 mode

Avoid const in casting since it doesn't increase code
safety in this case and causes clang to generate const-qual
warning. Also initialize a pointer to NULL to silence clang
uninitialized variable warning.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/ldb/pyldb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index 515a69e..e61b5b6 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -510,10 +510,10 @@ static PyObject *py_ldb_dn_set_extended_component(PyLdbDnObject *self, PyObject
 {
 	char *name;
 	int err;
-	uint8_t *value;
+	uint8_t *value = NULL;
 	Py_ssize_t size = 0;
 
-	if (!PyArg_ParseTuple(args, "sz#", &name, (const char**)&value, &size))
+	if (!PyArg_ParseTuple(args, "sz#", &name, (char **)&value, &size))
 		return NULL;
 
 	if (value == NULL) {
-- 
2.9.5


From 634aa2cf5949682896ab0e233365fdb7edbff92a Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 11:30:56 +0000
Subject: [PATCH v3 08/38] build: allow passing custom cflags to end of library
 build

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/wafsamba.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py
index 23fd3c4..4bb19d0 100644
--- a/buildtools/wafsamba/wafsamba.py
+++ b/buildtools/wafsamba/wafsamba.py
@@ -112,6 +112,7 @@ def SAMBA_LIBRARY(bld, libname, source,
                   vnum=None,
                   soname=None,
                   cflags='',
+                  cflags_end=None,
                   ldflags='',
                   external_library=False,
                   realname=None,
@@ -195,6 +196,7 @@ def SAMBA_LIBRARY(bld, libname, source,
                         private_headers= private_headers,
                         header_path    = header_path,
                         cflags         = cflags,
+                        cflags_end     = cflags_end,
                         group          = subsystem_group,
                         autoproto      = autoproto,
                         autoproto_extra_source=autoproto_extra_source,
-- 
2.9.5


From 7ca48e9adf59816f9d7779278a160e8b3a25c908 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 11:32:16 +0000
Subject: [PATCH v3 09/38] build: allow adding cflags to end of python module
 build command

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/samba_python.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py
index f97439c..cb99fe9 100644
--- a/buildtools/wafsamba/samba_python.py
+++ b/buildtools/wafsamba/samba_python.py
@@ -109,6 +109,7 @@ def SAMBA_PYTHON(bld, name,
                  public_deps='',
                  realname=None,
                  cflags='',
+                 cflags_end=None,
                  includes='',
                  init_function_sentinel=None,
                  local_include=True,
@@ -154,6 +155,7 @@ def SAMBA_PYTHON(bld, name,
                       public_deps=public_deps,
                       includes=includes,
                       cflags=cflags,
+                      cflags_end=cflags_end,
                       local_include=local_include,
                       vars=vars,
                       realname=realname,
-- 
2.9.5


From 1855163506bfa76324cf3eb057a641f0aa0fe2f7 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 11:33:03 +0000
Subject: [PATCH v3 10/38] build: detect availability of -Wno-unused-function

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/replace/wscript | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/replace/wscript b/lib/replace/wscript
index 7436a90..2f94d49 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -84,6 +84,9 @@ def configure(conf):
     if conf.CHECK_CFLAGS('-Wno-format-truncation'):
         conf.define('HAVE_WNO_FORMAT_TRUNCATION', '1')
 
+    if conf.CHECK_CFLAGS('-Wno-unused-function'):
+        conf.define('HAVE_WNO_UNUSED_FUNCTION', '1')
+
     # Check for process set name support
     conf.CHECK_CODE('''
                     #include <sys/prctl.h>
-- 
2.9.5


From 754424a6ae6f5b75aaf18eb8cf2ce5d15fe18528 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 11:34:01 +0000
Subject: [PATCH v3 11/38] librpc-build: ignore unused functions in generated
 code

Some pidl-generated code includes static functions that are
to be optimized-away by the compiler if not used. When
running picky developer with clang that breaks the build. This
change ignores this warning for the pidl-generated python binding
files.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/librpc/wscript_build | 109 +++++++++++++++++++++++++++++--------------
 1 file changed, 74 insertions(+), 35 deletions(-)

diff --git a/source4/librpc/wscript_build b/source4/librpc/wscript_build
index eed0551..ce893a2 100644
--- a/source4/librpc/wscript_build
+++ b/source4/librpc/wscript_build
@@ -172,6 +172,10 @@ bld.SAMBA_LIBRARY('dcerpc',
 	vnum='0.0.1'
 	)
 
+gen_cflags = ''
+if bld.CONFIG_SET('HAVE_WNO_UNUSED_FUNCTION'):
+    gen_cflags = '-Wno-unused-function'
+
 for env in bld.gen_python_environments():
 	pyrpc_util = bld.pyembed_libname('pyrpc_util')
 	pytalloc_util = bld.pyembed_libname('pytalloc-util')
@@ -187,221 +191,256 @@ for env in bld.gen_python_environments():
 	bld.SAMBA_PYTHON('python_dcerpc',
 		source='rpc/pyrpc.c',
 		public_deps='LIBCLI_SMB samba-util samba-hostconfig dcerpc-samr RPC_NDR_LSA DYNCONFIG %s gensec' % pyrpc_util,
-		realname='samba/dcerpc/base.so'
+		realname='samba/dcerpc/base.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_misc',
 		source='../../librpc/gen_ndr/py_misc.c',
 		deps='%s %s ndr-krb5pac' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/misc.so'
+		realname='samba/dcerpc/misc.so',
+		cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_auth',
 		source='../../librpc/gen_ndr/py_auth.c',
 		deps='NDR_AUTH %s %s' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/auth.so'
+		realname='samba/dcerpc/auth.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_security',
 		source='../../librpc/gen_ndr/py_security.c',
 		deps='%s %s NDR_SECURITY' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/security.so'
+		realname='samba/dcerpc/security.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_lsa',
 		source='../../librpc/gen_ndr/py_lsa.c',
 		deps='RPC_NDR_LSA %s %s' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/lsa.so'
+		realname='samba/dcerpc/lsa.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_krb5pac',
 		source='../../librpc/gen_ndr/py_krb5pac.c',
 		deps='ndr-krb5pac %s %s' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/krb5pac.so'
+		realname='samba/dcerpc/krb5pac.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_netlogon',
 		source='../../librpc/gen_ndr/py_netlogon.c',
 		deps='RPC_NDR_NETLOGON %s %s' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/netlogon.so'
+		realname='samba/dcerpc/netlogon.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_samr',
 		source='../../librpc/gen_ndr/py_samr.c',
 		deps='dcerpc-samr %s %s' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/samr.so'
+		realname='samba/dcerpc/samr.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_nbt',
 		source='../../librpc/gen_ndr/py_nbt.c',
 		deps='ndr_nbt RPC_NDR_NBT %s %s' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/nbt.so'
+		realname='samba/dcerpc/nbt.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_drsblobs',
 		source='../../librpc/gen_ndr/py_drsblobs.c',
 		deps='%s %s NDR_SECURITY RPC_NDR_DRSBLOBS' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/drsblobs.so'
+		realname='samba/dcerpc/drsblobs.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_ntlmssp',
 		source='../../librpc/gen_ndr/py_ntlmssp.c',
 		deps='%s %s RPC_NDR_NTLMSSP' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/ntlmssp.so'
+		realname='samba/dcerpc/ntlmssp.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_srvsvc',
 	    source='../../librpc/gen_ndr/py_srvsvc.c',
 	    deps='RPC_NDR_SRVSVC pytalloc-util pyrpc_util',
-	    realname='samba/dcerpc/srvsvc.so'
+	    realname='samba/dcerpc/srvsvc.so',
+            cflags_end=gen_cflags
 	    )
 
 	bld.SAMBA_PYTHON('python_echo',
 		source='../../librpc/gen_ndr/py_echo.c',
 		deps='RPC_NDR_ECHO pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/echo.so'
+		realname='samba/dcerpc/echo.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dns',
 		source='../../librpc/gen_ndr/py_dns.c',
 		deps='NDR_DNS pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/dns.so'
+		realname='samba/dcerpc/dns.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_winreg',
 		source='../../librpc/gen_ndr/py_winreg.c',
 		deps='RPC_NDR_WINREG pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/winreg.so'
+		realname='samba/dcerpc/winreg.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_initshutdown',
 		source='../../librpc/gen_ndr/py_initshutdown.c',
 		deps='RPC_NDR_INITSHUTDOWN pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/initshutdown.so'
+		realname='samba/dcerpc/initshutdown.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_epmapper',
 		source='../../librpc/gen_ndr/py_epmapper.c',
 		deps='dcerpc pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/epmapper.so'
+		realname='samba/dcerpc/epmapper.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_mgmt',
 		source='../../librpc/gen_ndr/py_mgmt.c',
 		deps='pytalloc-util dcerpc pyrpc_util',
-		realname='samba/dcerpc/mgmt.so'
+		realname='samba/dcerpc/mgmt.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_atsvc',
 		source='../../librpc/gen_ndr/py_atsvc.c',
 		deps='RPC_NDR_ATSVC pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/atsvc.so'
+		realname='samba/dcerpc/atsvc.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_svcctl',
 		source='../../librpc/gen_ndr/py_svcctl.c',
 		deps='RPC_NDR_SVCCTL pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/svcctl.so'
+		realname='samba/dcerpc/svcctl.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_wkssvc',
 		source='../../librpc/gen_ndr/py_wkssvc.c',
 		deps='RPC_NDR_WKSSVC pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/wkssvc.so'
+		realname='samba/dcerpc/wkssvc.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_dfs',
 		source='../../librpc/gen_ndr/py_dfs.c',
 		deps='RPC_NDR_DFS pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/dfs.so'
+		realname='samba/dcerpc/dfs.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_dcerpc',
 		source='../../librpc/gen_ndr/py_dcerpc.c',
 		deps='NDR_DCERPC pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/dcerpc.so'
+		realname='samba/dcerpc/dcerpc.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_unixinfo',
 		source='../../librpc/gen_ndr/py_unixinfo.c',
 		deps='RPC_NDR_UNIXINFO pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/unixinfo.so'
+		realname='samba/dcerpc/unixinfo.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_irpc',
 		source='gen_ndr/py_irpc.c',
 		deps='RPC_NDR_IRPC %s %s' % (pytalloc_util, pyrpc_util),
-		realname='samba/dcerpc/irpc.so'
+		realname='samba/dcerpc/irpc.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_server_id',
 		source='../../librpc/gen_ndr/py_server_id.c',
 		deps='RPC_NDR_SERVER_ID pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/server_id.so'
+		realname='samba/dcerpc/server_id.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_winbind',
 		source='../../librpc/gen_ndr/py_winbind.c',
 		deps='RPC_NDR_WINBIND pytalloc-util pyrpc_util python_netlogon',
-		realname='samba/dcerpc/winbind.so'
+		realname='samba/dcerpc/winbind.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_idmap',
 		source='../../librpc/gen_ndr/py_idmap.c',
 		deps='NDR_IDMAP pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/idmap.so'
+		realname='samba/dcerpc/idmap.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_drsuapi',
 		source='../../librpc/gen_ndr/py_drsuapi.c',
 		deps='RPC_NDR_DRSUAPI pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/drsuapi.so'
+		realname='samba/dcerpc/drsuapi.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_dnsp',
 		source='../../librpc/gen_ndr/py_dnsp.c',
 		deps='pytalloc-util pyrpc_util NDR_SECURITY NDR_DNSP',
-		realname='samba/dcerpc/dnsp.so'
+		realname='samba/dcerpc/dnsp.so',
+                cflags_end=gen_cflags
 		)
 
 
 	bld.SAMBA_PYTHON('python_dcerpc_xattr',
 		source='../../librpc/gen_ndr/py_xattr.c',
 		deps='pytalloc-util pyrpc_util RPC_NDR_XATTR',
-		realname='samba/dcerpc/xattr.so'
+		realname='samba/dcerpc/xattr.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_idmap',
 		source='../../librpc/gen_ndr/py_idmap.c',
 		deps='pytalloc-util pyrpc_util RPC_NDR_XATTR',
-		realname='samba/dcerpc/idmap.so'
+		realname='samba/dcerpc/idmap.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dnsserver',
 		source='../../librpc/gen_ndr/py_dnsserver.c',
 		deps='RPC_NDR_DNSSERVER pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/dnsserver.so'
+		realname='samba/dcerpc/dnsserver.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('python_dcerpc_smb_acl',
 		source='../../librpc/gen_ndr/py_smb_acl.c',
 		deps='pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/smb_acl.so'
+		realname='samba/dcerpc/smb_acl.so',
+                cflags_end=gen_cflags
 		)
 
 	bld.SAMBA_PYTHON('dcerpc_python_messaging',
 		source='../../librpc/gen_ndr/py_messaging.c',
 		deps='pytalloc-util pyrpc_util',
-		realname='samba/dcerpc/messaging.so'
+		realname='samba/dcerpc/messaging.so',
+                cflags_end=gen_cflags
 		)
 
 if bld.PYTHON_BUILD_IS_ENABLED():
-- 
2.9.5


From 227246ab0a909147a87bb32f07f8d9cd9b7a1265 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 13:02:56 +0000
Subject: [PATCH v3 12/38] ldb-samba: use ldap enum instead of ldb enum

This silences a picky compiler warning.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/ldb-samba/ldb_ildap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ldb-samba/ldb_ildap.c b/lib/ldb-samba/ldb_ildap.c
index a4e96e4..0cdf738 100644
--- a/lib/ldb-samba/ldb_ildap.c
+++ b/lib/ldb-samba/ldb_ildap.c
@@ -476,7 +476,7 @@ static int ildb_search(struct ildb_context *ac)
 	}
 
 	if (req->op.search.scope == LDB_SCOPE_DEFAULT) {
-		msg->r.SearchRequest.scope = LDB_SCOPE_SUBTREE;
+		msg->r.SearchRequest.scope = LDAP_SEARCH_SCOPE_SUB;
 	} else {
 		msg->r.SearchRequest.scope = req->op.search.scope;
 	}
-- 
2.9.5


From 8b65365c046fb6aa8d79eb171b0489e2d832ebf1 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 20 Nov 2017 10:15:26 +0200
Subject: [PATCH v3 13/38] build: accept unknown pragmas

The whole point of #pragmas is that a compiler may
ignore #pragmas it does not understand. GCC, with -Wall,
warns against unknown pragmas, hence the need to explicitly
disable this warning.

In a following commit we're adding clang-specific pragmas,
hence the need to allow ignoring them by non-clang compilers.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index 795d130..5b54af0 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -685,6 +685,7 @@ def SAMBA_CONFIG_H(conf, path=None):
 
         conf.ADD_CFLAGS('-g', testflags=True)
         conf.ADD_CFLAGS('-Wall', testflags=True)
+        conf.ADD_CFLAGS('-Wno-unknown-pragmas', testflags=True)
         conf.ADD_CFLAGS('-Wshadow', testflags=True)
         conf.ADD_CFLAGS('-Wmissing-prototypes', testflags=True)
         conf.ADD_CFLAGS('-Wcast-align -Wcast-qual', testflags=True)
-- 
2.9.5


From ea93c19ff1b6053b1e6c72ee4b67ab52871826a0 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 13:14:14 +0000
Subject: [PATCH v3 14/38] pam_winbind: avoid non-literal-format warning

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 nsswitch/pam_winbind.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/nsswitch/pam_winbind.c b/nsswitch/pam_winbind.c
index 4ae6464..cead147 100644
--- a/nsswitch/pam_winbind.c
+++ b/nsswitch/pam_winbind.c
@@ -189,6 +189,9 @@ static void _pam_log_int(const pam_handle_t *pamh,
 			 const char *format,
 			 va_list args)
 {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+
 	char *format2 = NULL;
 	const char *service;
 	int ret;
@@ -204,6 +207,8 @@ static void _pam_log_int(const pam_handle_t *pamh,
 
 	vsyslog(err, format2, args);
 	SAFE_FREE(format2);
+
+#pragma clang diagnostic pop
 }
 #endif /* HAVE_PAM_VSYSLOG */
 
@@ -714,6 +719,11 @@ static int _make_remark(struct pwb_context *ctx,
 static int _make_remark_v(struct pwb_context *ctx,
 			  int type,
 			  const char *format,
+			  va_list args) PRINTF_ATTRIBUTE(3, 0);
+
+static int _make_remark_v(struct pwb_context *ctx,
+			  int type,
+			  const char *format,
 			  va_list args)
 {
 	char *var;
-- 
2.9.5


From 68ce648f8158867bf04542cb6b3c651ae69f373e Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 13:15:12 +0000
Subject: [PATCH v3 15/38] pam_winbind: fix const discard warnings

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 nsswitch/pam_winbind.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/nsswitch/pam_winbind.c b/nsswitch/pam_winbind.c
index cead147..fe28a34 100644
--- a/nsswitch/pam_winbind.c
+++ b/nsswitch/pam_winbind.c
@@ -676,7 +676,7 @@ static int converse(const pam_handle_t *pamh,
 		    struct pam_response **response)
 {
 	int retval;
-	struct pam_conv *conv;
+	const struct pam_conv *conv;
 
 	retval = pam_get_item(pamh, PAM_CONV, (const void **) &conv);
 	if (retval == PAM_SUCCESS) {
@@ -3003,7 +3003,7 @@ static bool _pam_require_krb5_auth_after_chauthtok(struct pwb_context *ctx,
 	 * --- BoYang
 	 * */
 
-	char *new_authtok_reqd_during_auth = NULL;
+	const char *new_authtok_reqd_during_auth = NULL;
 	struct passwd *pwd = NULL;
 
 	pam_get_data(ctx->pamh, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH,
-- 
2.9.5


From 33d6c9599997be5a9d67df85b0656da64937a761 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 20 Nov 2017 21:18:01 +0200
Subject: [PATCH v3 16/38] winbind_nss_freebsd: fix const discard warning

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 nsswitch/winbind_nss_freebsd.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/nsswitch/winbind_nss_freebsd.c b/nsswitch/winbind_nss_freebsd.c
index 476349f..e283872 100644
--- a/nsswitch/winbind_nss_freebsd.c
+++ b/nsswitch/winbind_nss_freebsd.c
@@ -129,8 +129,13 @@ __freebsd_getgroupmembership(void *retval, void *mdata, va_list ap)
 	/* insert primary membership(possibly already there) */
 	gr_addgid(group, groups, maxgrp, groupc);
 	/* Don't limit number of groups, we want to know total size */
-	ret = _nss_winbind_initgroups_dyn(uname, group, &lcount, &lsize,
-		&tmpgroups, 0, &errnop);
+	ret = _nss_winbind_initgroups_dyn(discard_const(uname),
+					  group,
+					  &lcount,
+					  &lsize,
+					  &tmpgroups,
+					  0,
+					  &errnop);
 	if (ret == NSS_STATUS_SUCCESS) {
 		/* lcount potentially can be bigger than maxgrp, so would groupc */
 		for (i = 0; i < lcount; i++)
-- 
2.9.5


From 10761b980fcad2d48321df92cbac9376a9df23a0 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 16:49:46 +0000
Subject: [PATCH v3 17/38] dns server: fix warning about enum mismatch

Fix picky developer clang warning about assignment
of an enum value to a variable of a different enum type.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/dns_server/dns_query.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/dns_server/dns_query.c b/source4/dns_server/dns_query.c
index fa92721..8d3f601 100644
--- a/source4/dns_server/dns_query.c
+++ b/source4/dns_server/dns_query.c
@@ -133,7 +133,7 @@ static WERROR add_response_rr(const char *name,
 
 	ans[ai].name = talloc_strdup(ans, name);
 	W_ERROR_HAVE_NO_MEMORY(ans[ai].name);
-	ans[ai].rr_type = rec->wType;
+	ans[ai].rr_type = (enum dns_qtype)rec->wType;
 	ans[ai].rr_class = DNS_QCLASS_IN;
 	ans[ai].ttl = rec->dwTtlSeconds;
 	ans[ai].length = UINT16_MAX;
-- 
2.9.5


From 46fd0b50d168a9b87889edbb66558059d1892912 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 16:51:30 +0000
Subject: [PATCH v3 18/38] s2-rpc-server: fix enum type in assignment

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/rpc_server/srvsvc/dcesrv_srvsvc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c
index 71f0ac4..4dd3e97 100644
--- a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c
+++ b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c
@@ -2101,7 +2101,7 @@ static WERROR dcesrv_srvsvc_NetSetFileSecurity(struct dcesrv_call_state *dce_cal
 	io = talloc(mem_ctx, union smb_setfileinfo);
 	W_ERROR_HAVE_NO_MEMORY(io);
 
-	io->set_secdesc.level			= RAW_FILEINFO_SEC_DESC;
+	io->set_secdesc.level			= RAW_SFILEINFO_SEC_DESC;
 	io->set_secdesc.in.file.path		= r->in.file;
 	io->set_secdesc.in.secinfo_flags	= r->in.securityinformation;
 	io->set_secdesc.in.sd			= r->in.sd_buf->sd;
-- 
2.9.5


From 552cf02f572ee869421f03faeb4756afae7cd930 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 17:11:28 +0000
Subject: [PATCH v3 19/38] s4-torture: fix truncation warnings

Fix various places where there is potential truncation
while doing time / size calculations.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/torture/basic/base.c    | 6 +++---
 source4/torture/raw/open.c      | 2 +-
 source4/torture/raw/qfileinfo.c | 2 +-
 source4/torture/raw/qfsinfo.c   | 5 +++--
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/source4/torture/basic/base.c b/source4/torture/basic/base.c
index 8e7ae49..314e8f2 100644
--- a/source4/torture/basic/base.c
+++ b/source4/torture/basic/base.c
@@ -190,7 +190,7 @@ static bool run_attrtest(struct torture_context *tctx,
 
 	torture_comment(tctx, "New file time is %s", ctime(&t));
 
-	if (abs(t - time(NULL)) > 60*60*24*10) {
+	if (labs(t - time(NULL)) > 60*60*24*10) {
 		torture_result(tctx, TORTURE_FAIL, "ERROR: SMBgetatr bug. time is %s",
 		       ctime(&t));
 		t = time(NULL);
@@ -289,13 +289,13 @@ static bool run_trans2test(struct torture_context *tctx,
 			torture_comment(tctx, "modify time=%s", ctime(&m_time));
 			torture_comment(tctx, "This system appears to have sticky create times\n");
 		}
-		if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
+		if ((labs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
 			torture_comment(tctx, "access time=%s", ctime(&a_time));
 			torture_result(tctx, TORTURE_FAIL, "This system appears to set a midnight access time\n");
 			correct = false;
 		}
 
-		if (abs(m_time - t) > 60*60*24*7) {
+		if (labs(m_time - t) > 60*60*24*7) {
 			torture_result(tctx, TORTURE_FAIL, "ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
 			correct = false;
 		}
diff --git a/source4/torture/raw/open.c b/source4/torture/raw/open.c
index c3cb484..12dc2fe 100644
--- a/source4/torture/raw/open.c
+++ b/source4/torture/raw/open.c
@@ -95,7 +95,7 @@ static const char *rdwr_string(enum rdwr_mode m)
 	CHECK_STATUS(status, NT_STATUS_OK); \
 	t1 = t & ~1; \
 	t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
-	if (abs(t1-t2) > 2) { \
+	if (labs(t1-t2) > 2) { \
 		torture_result(tctx, TORTURE_FAIL, \
 		       "(%s) wrong time for field %s  %s - %s\n", \
 		       __location__, #field, \
diff --git a/source4/torture/raw/qfileinfo.c b/source4/torture/raw/qfileinfo.c
index 3b89189..0c5daa3 100644
--- a/source4/torture/raw/qfileinfo.c
+++ b/source4/torture/raw/qfileinfo.c
@@ -140,7 +140,7 @@ static struct {
 static int dos_nt_time_cmp(time_t t, NTTIME nt)
 {
 	time_t t2 = nt_time_to_unix(nt);
-	if (abs(t2 - t) <= 2) return 0;
+	if (labs(t2 - t) <= 2) return 0;
 	return t2 > t ? 1 : -1;
 }
 
diff --git a/source4/torture/raw/qfsinfo.c b/source4/torture/raw/qfsinfo.c
index 259aee0..0f1717b 100644
--- a/source4/torture/raw/qfsinfo.c
+++ b/source4/torture/raw/qfsinfo.c
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include <math.h>
 #include "libcli/libcli.h"
 #include "torture/util.h"
 #include "torture/basic/proto.h"
@@ -206,7 +207,7 @@ bool torture_raw_qfsinfo(struct torture_context *torture,
 			s2->allocation.out.sectors_per_unit *
 			s2->allocation.out.total_alloc_units *
 			s2->allocation.out.bytes_per_sector / scale;
-		if (abs(size1 - size2) > 1) {
+		if (fabs(size1 - size2) > 1) {
 			printf("Inconsistent total size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", 
 			       size1, size2);
 			ret = false;
@@ -228,7 +229,7 @@ bool torture_raw_qfsinfo(struct torture_context *torture,
 			s2->allocation.out.sectors_per_unit *
 			s2->allocation.out.avail_alloc_units *
 			s2->allocation.out.bytes_per_sector / scale;
-		if (abs(size1 - size2) > 1) {
+		if (fabs(size1 - size2) > 1) {
 			printf("Inconsistent avail size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", 
 			       size1, size2);
 			ret = false;
-- 
2.9.5


From 5e82fccbc8e4c29a44ae6760d48d0ab897490939 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 17:13:26 +0000
Subject: [PATCH v3 20/38] s4-torture: fix file time checks

NTTIME is an unsigned quantity. When comparing two
of them, first calculate a signed difference, then
take absolute value.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/torture/raw/open.c    | 2 +-
 source4/torture/smb2/create.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/torture/raw/open.c b/source4/torture/raw/open.c
index 12dc2fe..5e8c81c 100644
--- a/source4/torture/raw/open.c
+++ b/source4/torture/raw/open.c
@@ -112,7 +112,7 @@ static const char *rdwr_string(enum rdwr_mode m)
 	status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
 	CHECK_STATUS(status, NT_STATUS_OK); \
 	t2 = finfo.all_info.out.field; \
-	if (abs(t-t2) > 20000) { \
+	if (llabs((int64_t)(t-t2)) > 20000) { \
 		torture_result(tctx, TORTURE_FAIL, \
 		       "(%s) wrong time for field %s  %s - %s\n", \
 		       __location__, #field, \
diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c
index 397c075..ead56eb 100644
--- a/source4/torture/smb2/create.c
+++ b/source4/torture/smb2/create.c
@@ -81,7 +81,7 @@
 	status = smb2_getinfo_file(tree, tctx, &finfo); \
 	CHECK_STATUS(status, NT_STATUS_OK); \
 	t2 = finfo.all_info.out.field; \
-	if (abs(t-t2) > 20000) { \
+	if (llabs((int64_t)(t-t2)) > 20000) { \
 		torture_result(tctx, TORTURE_FAIL, \
 			"(%s) wrong time for field %s  %s - %s\n", \
 		       __location__, #field, \
-- 
2.9.5


From 3535379d268d1e1c52f23169275fdb4f862aadba Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 17:54:32 +0000
Subject: [PATCH v3 21/38] s4-torture: fix type of enum in various places

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/torture/rpc/clusapi.c | 2 +-
 source4/torture/smb2/ioctl.c  | 4 ++--
 source4/torture/smb2/replay.c | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/source4/torture/rpc/clusapi.c b/source4/torture/rpc/clusapi.c
index eebfa38..6597b44 100644
--- a/source4/torture/rpc/clusapi.c
+++ b/source4/torture/rpc/clusapi.c
@@ -1152,7 +1152,7 @@ static bool test_ResourceTypeControl_int(struct torture_context *tctx,
 					 struct dcerpc_pipe *p,
 					 struct policy_handle *Cluster,
 					 const char *resource_type,
-					 enum clusapi_ClusterControlCode dwControlCode)
+					 enum clusapi_ResourceTypeControlCode dwControlCode)
 {
 	struct dcerpc_binding_handle *b = p->binding_handle;
 	struct clusapi_ResourceTypeControl r;
diff --git a/source4/torture/smb2/ioctl.c b/source4/torture/smb2/ioctl.c
index 90171e9..2b7df6e 100644
--- a/source4/torture/smb2/ioctl.c
+++ b/source4/torture/smb2/ioctl.c
@@ -2846,7 +2846,7 @@ static bool test_ioctl_compress_set_file_attr(struct torture_context *torture,
 		       "compression attr before set");
 
 	ZERO_STRUCT(set_io);
-	set_io.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
+	set_io.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
 	set_io.basic_info.in.file.handle = fh;
 	set_io.basic_info.in.create_time = io.basic_info.out.create_time;
 	set_io.basic_info.in.access_time = io.basic_info.out.access_time;
@@ -2885,7 +2885,7 @@ static bool test_ioctl_compress_set_file_attr(struct torture_context *torture,
 		       "compression attr before set");
 
 	ZERO_STRUCT(set_io);
-	set_io.generic.level = RAW_FILEINFO_BASIC_INFORMATION;
+	set_io.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
 	set_io.basic_info.in.file.handle = dirh;
 	set_io.basic_info.in.create_time = io.basic_info.out.create_time;
 	set_io.basic_info.in.access_time = io.basic_info.out.access_time;
diff --git a/source4/torture/smb2/replay.c b/source4/torture/smb2/replay.c
index a38518a..f15fc84 100644
--- a/source4/torture/smb2/replay.c
+++ b/source4/torture/smb2/replay.c
@@ -304,7 +304,7 @@ static bool test_replay_commands(struct torture_context *tctx, struct smb2_tree
 	CHECK_STATUS(status, NT_STATUS_OK);
 
 	qfinfo = (union smb_fileinfo) {
-		.generic.level = RAW_SFILEINFO_POSITION_INFORMATION,
+		.generic.level = RAW_FILEINFO_POSITION_INFORMATION,
 		.generic.in.file.handle = h
 	};
 	torture_comment(tctx, "Trying getinfo\n");
@@ -1677,7 +1677,7 @@ static bool test_channel_sequence_table(struct torture_context *tctx,
 		}
 
 		qfinfo = (union smb_fileinfo) {
-			.generic.level = RAW_SFILEINFO_POSITION_INFORMATION,
+			.generic.level = RAW_FILEINFO_POSITION_INFORMATION,
 			.generic.in.file.handle = handle
 		};
 
@@ -2350,7 +2350,7 @@ static bool test_replay6(struct torture_context *tctx, struct smb2_tree *tree)
 	torture_reset_break_info(tctx, &break_info);
 
 	qfinfo = (union smb_fileinfo) {
-		.generic.level = RAW_SFILEINFO_POSITION_INFORMATION,
+		.generic.level = RAW_FILEINFO_POSITION_INFORMATION,
 		.generic.in.file.handle = *h
 	};
 	torture_comment(tctx, "Trying getinfo\n");
-- 
2.9.5


From 2bc65556d7eb97aeadeea0b5540cb69a3dfc2e39 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 17:55:14 +0000
Subject: [PATCH v3 22/38] s4-torture: get rid of extra parentheses

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/torture/rpc/lsa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/torture/rpc/lsa.c b/source4/torture/rpc/lsa.c
index deb4b2a..988d534 100644
--- a/source4/torture/rpc/lsa.c
+++ b/source4/torture/rpc/lsa.c
@@ -2409,7 +2409,7 @@ static bool test_EnumTrustDom(struct dcerpc_binding_handle *b,
 
 		in_resume_handle = out_resume_handle;
 
-	} while ((NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)));
+	} while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES));
 
 	return ret;
 }
@@ -2507,7 +2507,7 @@ static bool test_EnumTrustDomEx(struct dcerpc_binding_handle *b,
 
 		ret &= test_query_each_TrustDomEx(b, tctx, handle, &domains_ex);
 
-	} while ((NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)));
+	} while (NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES));
 
 	return ret;
 }
-- 
2.9.5


From b4681b7bc6726f5d1efc84502cc092e12e8d948d Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 17:56:50 +0000
Subject: [PATCH v3 23/38] s4-lib-policy: fix type of enum

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source4/lib/policy/gp_filesys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/lib/policy/gp_filesys.c b/source4/lib/policy/gp_filesys.c
index a18c513..d48fc9f 100644
--- a/source4/lib/policy/gp_filesys.c
+++ b/source4/lib/policy/gp_filesys.c
@@ -644,7 +644,7 @@ NTSTATUS gp_set_gpt_security_descriptor(struct gp_context *gp_ctx,
 	}
 
 	/* Set the security descriptor on the directory */
-	fileinfo.generic.level = RAW_FILEINFO_SEC_DESC;
+	fileinfo.generic.level = RAW_SFILEINFO_SEC_DESC;
 	fileinfo.set_secdesc.in.file.fnum = io.ntcreatex.out.file.fnum;
 	fileinfo.set_secdesc.in.secinfo_flags = SECINFO_PROTECTED_DACL |
 	                                        SECINFO_OWNER |
-- 
2.9.5


From da58d09c42edaa77327370133079e84be8d04b1d Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 17:57:29 +0000
Subject: [PATCH v3 24/38] s3-rpc-server: fix type of enum in lsa server

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/rpc_server/lsa/srv_lsa_nt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/source3/rpc_server/lsa/srv_lsa_nt.c b/source3/rpc_server/lsa/srv_lsa_nt.c
index 2d0d29e..3cc87ad 100644
--- a/source3/rpc_server/lsa/srv_lsa_nt.c
+++ b/source3/rpc_server/lsa/srv_lsa_nt.c
@@ -4157,7 +4157,7 @@ static NTSTATUS make_ft_info(TALLOC_CTX *mem_ctx,
 
 		rec->flags = lrec->flags;
 		rec->timestamp = lrec->time;
-		rec->type = lrec->type;
+		rec->type = (enum ForestTrustInfoRecordType)lrec->type;
 
 		switch (lrec->type) {
 		case LSA_FOREST_TRUST_TOP_LEVEL_NAME:
@@ -4412,7 +4412,7 @@ static NTSTATUS own_ft_info(struct pdb_domain_info *dom_info,
 
 	rec->flags = 0;
 	rec->timestamp = 0;
-	rec->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
+	rec->type = FOREST_TRUST_TOP_LEVEL_NAME;
 
 	rec->data.name.string = talloc_strdup(fti, dom_info->dns_forest);
 	if (!rec->data.name.string) {
@@ -4425,7 +4425,7 @@ static NTSTATUS own_ft_info(struct pdb_domain_info *dom_info,
 
 	rec->flags = 0;
 	rec->timestamp = 0;
-	rec->type = LSA_FOREST_TRUST_DOMAIN_INFO;
+	rec->type = FOREST_TRUST_DOMAIN_INFO;
 
         info = &rec->data.info;
 
-- 
2.9.5


From e27b53ad4c2281583e3b66fef81e92825f6688c4 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 18:34:58 +0000
Subject: [PATCH v3 25/38] smbspool_krb5_wrapper: fix some error messages

Make cups_smb_debug declaration printf-aware to
avoid picky warning about printf with variable
format string. This in turn revealed some formatting
errors.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/client/smbspool_krb5_wrapper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/source3/client/smbspool_krb5_wrapper.c b/source3/client/smbspool_krb5_wrapper.c
index 9a82b2a..dee3b4c 100644
--- a/source3/client/smbspool_krb5_wrapper.c
+++ b/source3/client/smbspool_krb5_wrapper.c
@@ -37,7 +37,8 @@ enum cups_smb_dbglvl_e {
 	CUPS_SMB_LOG_DEBUG = 0,
 	CUPS_SMB_LOG_ERROR,
 };
-static void cups_smb_debug(enum cups_smb_dbglvl_e lvl, const char *format, ...);
+static void cups_smb_debug(enum cups_smb_dbglvl_e lvl, const char *format, ...)
+		PRINTF_ATTRIBUTE(2, 3);
 
 #define CUPS_SMB_DEBUG(...) cups_smb_debug(CUPS_SMB_LOG_DEBUG, __VA_ARGS__)
 #define CUPS_SMB_ERROR(...) cups_smb_debug(CUPS_SMB_LOG_DEBUG, __VA_ARGS__)
@@ -166,7 +167,7 @@ int main(int argc, char *argv[])
 	CUPS_SMB_DEBUG("Switching to gid=%d", gid);
 	rc = setgid(gid);
 	if (rc != 0) {
-		CUPS_SMB_ERROR("Failed to switch to gid=%u",
+		CUPS_SMB_ERROR("Failed to switch to gid=%u - %s",
 			       gid,
 			       strerror(errno));
 		return CUPS_BACKEND_FAILED;
@@ -175,7 +176,7 @@ int main(int argc, char *argv[])
 	CUPS_SMB_DEBUG("Switching to uid=%u", uid);
 	rc = setuid(uid);
 	if (rc != 0) {
-		CUPS_SMB_ERROR("Failed to switch to uid=%u",
+		CUPS_SMB_ERROR("Failed to switch to uid=%u - %s",
 			       uid,
 			       strerror(errno));
 		return CUPS_BACKEND_FAILED;
-- 
2.9.5


From c6d326bcdf5bab5647190620cb65376042c1d533 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 18:37:49 +0000
Subject: [PATCH v3 26/38] s3-torture: fix some truncation warnings

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/torture/torture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 360adad..b6807a6 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -3214,7 +3214,7 @@ static bool run_attrtest(int dummy)
 		correct = False;
 	}
 
-	if (abs(t - time(NULL)) > 60*60*24*10) {
+	if (labs(t - time(NULL)) > 60*60*24*10) {
 		printf("ERROR: SMBgetatr bug. time is %s",
 		       ctime(&t));
 		t = time(NULL);
@@ -3445,13 +3445,13 @@ static bool run_trans2test(int dummy)
 			printf("modify time=%s", ctime(&m_time));
 			printf("This system appears to have sticky create times\n");
 		}
-		if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
+		if ((labs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
 			printf("access time=%s", ctime(&a_time));
 			printf("This system appears to set a midnight access time\n");
 			correct = False;
 		}
 
-		if (abs(m_time - t) > 60*60*24*7) {
+		if (labs(m_time - t) > 60*60*24*7) {
 			printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
 			correct = False;
 		}
-- 
2.9.5


From fa4f27956e558ba0db40ac6d167c2a6779658fc7 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 18:38:28 +0000
Subject: [PATCH v3 27/38] s3-torture: fix an always-true comparison

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/torture/torture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index b6807a6..1e9af01 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -5219,7 +5219,7 @@ static bool run_rename_access(int dummy)
 	}
 
 	if (cli) {
-		if (fnum != (uint64_t)-1) {
+		if (fnum != (uint16_t)-1) {
 			cli_close(cli, fnum);
 		}
 		cli_unlink(cli, src,
-- 
2.9.5


From ca5fa6c5b7db41e6e0721c466162cd856eec800b Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 20 Nov 2017 10:17:16 +0200
Subject: [PATCH v3 28/38] build: disable format-zero-length warning

format-zero-length warns against printf-style calls with
zero-length format string. vfs_full_audit module has such
calls, and up until now there was no warning against it because
the do_log in vfs_full_audit is not recognized as printf-style
function. In a following commit the do_log will be converted to
a printf-style function, hence the need to disable this warning.

(an alternative would be to disable only for vfs_full_audit, but that
would complicate things needlessly).

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index 5b54af0..ed314e1 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -709,6 +709,7 @@ def SAMBA_CONFIG_H(conf, path=None):
                         testflags=True)
 
         conf.ADD_CFLAGS('-Wformat=2 -Wno-format-y2k', testflags=True)
+        conf.ADD_CFLAGS('-Wno-format-zero-length', testflags=True)
         conf.ADD_CFLAGS('-Werror=format-security -Wformat-security', testflags=True)
         # This check is because for ldb_search(), a NULL format string
         # is not an error, but some compilers complain about that.
-- 
2.9.5


From 8be25cea1a277429333bf07c87c4291bf44ff179 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 18:44:06 +0000
Subject: [PATCH v3 29/38] vfs_full_audit: make do_log() printf-aware

Add PRINTF_ATTRIBUTE() to do_log(). This removes
picky compiler warning about printf with variable
format string, and adds compiler checks for the format
strings supplied to do_log. This in turn spurred some
warnings which are fixed.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_full_audit.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index b847159..fbe1715 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -521,6 +521,9 @@ static TALLOC_CTX *do_log_ctx(void)
 }
 
 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
+		   const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
+
+static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
 		   const char *format, ...)
 {
 	struct vfs_full_audit_private_data *pd;
@@ -1411,7 +1414,7 @@ static uint64_t smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
 	result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
 
 	do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
-			"%llu", result);
+			"%llu", (unsigned long long)result);
 
 	return result;
 }
@@ -1783,7 +1786,10 @@ static NTSTATUS smb_full_audit_brl_lock_windows(struct vfs_handle_struct *handle
 	do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
 	    "%s:%llu-%llu. type=%d. blocking=%d",
 	       fsp_str_do_log(brl_fsp(br_lck)),
-	    plock->start, plock->size, plock->lock_type, blocking_lock);
+	       (unsigned long long)plock->start,
+	       (unsigned long long)plock->size,
+	       plock->lock_type,
+	       blocking_lock);
 
 	return result;
 }
@@ -1800,8 +1806,9 @@ static bool smb_full_audit_brl_unlock_windows(struct vfs_handle_struct *handle,
 
 	do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
 	       "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
-	       plock->start,
-	    plock->size, plock->lock_type);
+	       (unsigned long long)plock->start,
+	       (unsigned long long)plock->size,
+	       plock->lock_type);
 
 	return result;
 }
@@ -1816,8 +1823,9 @@ static bool smb_full_audit_brl_cancel_windows(struct vfs_handle_struct *handle,
 
 	do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
 	       "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
-	       plock->start,
-	    plock->size, plock->lock_type);
+	       (unsigned long long)plock->start,
+	       (unsigned long long)plock->size,
+	       plock->lock_type);
 
 	return result;
 }
@@ -1831,8 +1839,10 @@ static bool smb_full_audit_strict_lock_check(struct vfs_handle_struct *handle,
 	result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
 
 	do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
-	    "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
-	    plock->size, plock->lock_type);
+	       "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
+	       (unsigned long long)plock->start,
+	       (unsigned long long)plock->size,
+	       plock->lock_type);
 
 	return result;
 }
-- 
2.9.5


From 2c93dafc62e570c4e8781f9ebd43d7f167d654e4 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 19:30:15 +0000
Subject: [PATCH v3 30/38] build: remove -Wcast-align from developer build

-Wcast-align is a warning that warns against casting to a pointer
with greater alignment. On platform which care about alignment (e.g.
ARM and MIPS) this is important because the compiler cannot guarantee
proper alignment due to the casting. That would make -Wcast-align look
like a good idea.

However, GCC never emits aligment warnings on x86/x86_64 architectures
because they don't care about alignment. That makes the -Wcast-align
a no-op on autobuild. OTOH, clang does emit warnings (turned to errors
in developer build). It turns out the code is not quite ready for this
warning. There are two examples of perfectly valid code which triggers
this warning:

1. Casting from sockaddr * to sockaddr_in * - in that case the alignment
   of sockaddr is 2 (1 on FreeBSD) and 4 for sockaddr_in.

2. Converting from a pointer to a struct member to a pointer to the
   containing struct (this has workarounds, see the Linux kernel
   container_of macro).

So, this warning buys us nothing with x86_64+GCC, and breaks the
build with clang (and probably on ARM+GCC in developer mode).

Until the code is made "cast-align-clean", this warning is removed.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index ed314e1..8ad1b99 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -688,7 +688,7 @@ def SAMBA_CONFIG_H(conf, path=None):
         conf.ADD_CFLAGS('-Wno-unknown-pragmas', testflags=True)
         conf.ADD_CFLAGS('-Wshadow', testflags=True)
         conf.ADD_CFLAGS('-Wmissing-prototypes', testflags=True)
-        conf.ADD_CFLAGS('-Wcast-align -Wcast-qual', testflags=True)
+        conf.ADD_CFLAGS('-Wcast-qual', testflags=True)
         conf.ADD_CFLAGS('-fno-common', testflags=True)
 
         conf.ADD_CFLAGS('-Werror=address', testflags=True)
-- 
2.9.5


From 8f9b44be5c853d8d3d031655f5f11cb20a7482ea Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 20:22:33 +0000
Subject: [PATCH v3 31/38] lib/replace: ignore readline -Wstrict-prototypes
 warning

<readline/readline.h> seems to upset clang 4.0 -Wstrict-prototypes.
cf. https://www.spinics.net/linux/fedora/libvir/msg148578.html

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/replace/system/readline.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/replace/system/readline.h b/lib/replace/system/readline.h
index e6b8fb9..67870a9 100644
--- a/lib/replace/system/readline.h
+++ b/lib/replace/system/readline.h
@@ -26,7 +26,10 @@
 
 #ifdef HAVE_LIBREADLINE
 #  ifdef HAVE_READLINE_READLINE_H
+#    pragma clang diagnostic push
+#    pragma clang diagnostic ignored "-Wstrict-prototypes"
 #    include <readline/readline.h>
+#    pragma clang diagnostic pop
 #    ifdef HAVE_READLINE_HISTORY_H
 #      include <readline/history.h>
 #    endif
-- 
2.9.5


From 34a0ae847ca3bf058f6726a6d2faeaee199a99f1 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at pooh.localdomain>
Date: Sun, 19 Nov 2017 05:03:28 +0000
Subject: [PATCH v3 32/38] tevent: mark some functions as private

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/tevent/tevent_util.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/tevent/tevent_util.c b/lib/tevent/tevent_util.c
index 16af8f3..504e468 100644
--- a/lib/tevent/tevent_util.c
+++ b/lib/tevent/tevent_util.c
@@ -32,7 +32,7 @@
 /**
   return the number of elements in a string list
 */
-size_t ev_str_list_length(const char **list)
+_PRIVATE_ size_t ev_str_list_length(const char **list)
 {
 	size_t ret;
 	for (ret=0;list && list[ret];ret++) /* noop */ ;
@@ -42,7 +42,7 @@ size_t ev_str_list_length(const char **list)
 /**
   add an entry to a string list
 */
-const char **ev_str_list_add(const char **list, const char *s)
+_PRIVATE_ const char **ev_str_list_add(const char **list, const char *s)
 {
 	size_t len = ev_str_list_length(list);
 	const char **ret;
@@ -66,7 +66,7 @@ const char **ev_str_list_add(const char **list, const char *s)
   if BSD use FNDELAY
 **/
 
-int ev_set_blocking(int fd, bool set)
+_PRIVATE_ int ev_set_blocking(int fd, bool set)
 {
 	int val;
 #ifdef O_NONBLOCK
@@ -89,7 +89,7 @@ int ev_set_blocking(int fd, bool set)
 #undef FLAG_TO_SET
 }
 
-bool ev_set_close_on_exec(int fd)
+_PRIVATE_ bool ev_set_close_on_exec(int fd)
 {
 #ifdef FD_CLOEXEC
 	int val;
-- 
2.9.5


From d4805d91f41588314c89e06cd4308e811cdd2020 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 13:04:58 +0000
Subject: [PATCH v3 33/38] pam_wrapper: #ifdef-out unused functions

When pam_vsyslog is not available, avoid building functions
that are being used to wrap it, in order to avoid picky
compiler warnings.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/pam_wrapper/pam_wrapper.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/pam_wrapper/pam_wrapper.c b/lib/pam_wrapper/pam_wrapper.c
index 4be8146..03584be 100644
--- a/lib/pam_wrapper/pam_wrapper.c
+++ b/lib/pam_wrapper/pam_wrapper.c
@@ -508,6 +508,7 @@ static const char *libpam_pam_strerror(pam_handle_t *pamh, int errnum)
 	return pwrap.libpam.symbols._libpam_pam_strerror.f(discard_const_p(pam_handle_t, pamh), errnum);
 }
 
+#if defined(HAVE_PAM_VSYSLOG) || defined(HAVE_PAM_SYSLOG)
 static void libpam_pam_vsyslog(const pam_handle_t *pamh,
 			       int priority,
 			       const char *fmt,
@@ -522,6 +523,7 @@ static void libpam_pam_vsyslog(const pam_handle_t *pamh,
 						   args);
 #endif
 }
+#endif
 
 /*********************************************************
  * PWRAP INIT
@@ -1487,6 +1489,8 @@ const char *pam_strerror(pam_handle_t *pamh, int errnum)
 				  errnum);
 }
 
+#if defined(HAVE_PAM_VSYSLOG) || defined(HAVE_PAM_SYSLOG)
+
 static void pwrap_pam_vsyslog(const pam_handle_t *pamh,
 			      int priority,
 			      const char *fmt,
@@ -1533,6 +1537,7 @@ static void pwrap_pam_vsyslog(const pam_handle_t *pamh,
 
 	pwrap_vlog(dbglvl, syslog_str, fmt, args);
 }
+#endif /* defined(HAVE_PAM_VSYSLOG) || defined(HAVE_PAM_SYSLOG) */
 
 #ifdef HAVE_PAM_VSYSLOG
 void pam_vsyslog(const pam_handle_t *pamh,
-- 
2.9.5


From efbbd6231afeccb0ab361be8c86de4d4244b59c9 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 13:08:30 +0000
Subject: [PATCH v3 34/38] pam_wrapper: use uintptr_t as base for
 const-discarding

Seems like HAVE_INTPTR_T is not available on FreeBSD. Use
the uintptr_t-base const discarding to avoid picky compiler
warnings (other places in Samba also use uintptr_t).

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/pam_wrapper/python/pypamtest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/pam_wrapper/python/pypamtest.c b/lib/pam_wrapper/python/pypamtest.c
index a71fd35..c52e1bc 100644
--- a/lib/pam_wrapper/python/pypamtest.c
+++ b/lib/pam_wrapper/python/pypamtest.c
@@ -24,8 +24,8 @@
 #define PYTHON_MODULE_NAME  "pypamtest"
 
 #ifndef discard_const_p
-#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
-# define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr)))
+#if defined(__intptr_t_defined) || defined(HAVE_UINTPTR_T)
+# define discard_const_p(type, ptr) ((type *)((uintptr_t)(ptr)))
 #else
 # define discard_const_p(type, ptr) ((type *)(ptr))
 #endif
-- 
2.9.5


From f47f0bf09e822a7a9a137b68eb2e2c4f9c149edb Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sun, 19 Nov 2017 13:11:25 +0000
Subject: [PATCH v3 35/38] pam_wrapper: disable a picky clang warning in test

Disable warning about non-constant format specifier
in pam_wrapper test.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 lib/pam_wrapper/python/pypamtest.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/pam_wrapper/python/pypamtest.c b/lib/pam_wrapper/python/pypamtest.c
index c52e1bc..39656d6 100644
--- a/lib/pam_wrapper/python/pypamtest.c
+++ b/lib/pam_wrapper/python/pypamtest.c
@@ -67,6 +67,8 @@ static PyObject *PyExc_PamTestError;
  *** helper functions
  **********************************************************/
 
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+
 static const char *repr_fmt = "{ pam_operation [%d] "
 			      "expected_rv [%d] "
 			      "flags [%d] }";
-- 
2.9.5


From e9ce954a294858a16ae5ed8d11bdc082dea9f8ca Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 21 Nov 2017 20:53:30 +0200
Subject: [PATCH v3 36/38] build: allow specifying prerequisite flags when
 checking flags

In gcc, "-Wformat-security" is ignored unless "-Wformat" is also
specified. This patch allow adding a "prerequisite flag" to a flag
we're testing during configuration.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index 8ad1b99..3046f3c 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -771,14 +771,15 @@ def CONFIG_PATH(conf, name, default):
             conf.env[name] = conf.env['PREFIX'] + default
 
 @conf
-def ADD_NAMED_CFLAGS(conf, name, flags, testflags=False):
+def ADD_NAMED_CFLAGS(conf, name, flags, testflags=False, prereq_flags=[]):
     '''add some CFLAGS to the command line
        optionally set testflags to ensure all the flags work
     '''
+    prereq_flags = TO_LIST(prereq_flags)
     if testflags:
         ok_flags=[]
         for f in flags.split():
-            if CHECK_CFLAGS(conf, f):
+            if CHECK_CFLAGS(conf, [f] + prereq_flags):
                 ok_flags.append(f)
         flags = ok_flags
     if not name in conf.env:
@@ -786,11 +787,12 @@ def ADD_NAMED_CFLAGS(conf, name, flags, testflags=False):
     conf.env[name].extend(TO_LIST(flags))
 
 @conf
-def ADD_CFLAGS(conf, flags, testflags=False):
+def ADD_CFLAGS(conf, flags, testflags=False, prereq_flags=[]):
     '''add some CFLAGS to the command line
        optionally set testflags to ensure all the flags work
     '''
-    ADD_NAMED_CFLAGS(conf, 'EXTRA_CFLAGS', flags, testflags=testflags)
+    ADD_NAMED_CFLAGS(conf, 'EXTRA_CFLAGS', flags, testflags=testflags,
+                     prereq_flags=prereq_flags)
 
 @conf
 def ADD_LDFLAGS(conf, flags, testflags=False):
-- 
2.9.5


From 69b8491feaee5e4c519c2da177a3feeb73d14b69 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 21 Nov 2017 20:55:16 +0200
Subject: [PATCH v3 37/38] build: specify -Wformat as a prerequisite of
 -Wformat-security

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index 3046f3c..dfbe3c5 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -710,7 +710,8 @@ def SAMBA_CONFIG_H(conf, path=None):
 
         conf.ADD_CFLAGS('-Wformat=2 -Wno-format-y2k', testflags=True)
         conf.ADD_CFLAGS('-Wno-format-zero-length', testflags=True)
-        conf.ADD_CFLAGS('-Werror=format-security -Wformat-security', testflags=True)
+        conf.ADD_CFLAGS('-Werror=format-security -Wformat-security',
+                        testflags=True, prereq_flags='-Wformat')
         # This check is because for ldb_search(), a NULL format string
         # is not an error, but some compilers complain about that.
         if CHECK_CFLAGS(conf, ["-Werror=format", "-Wformat=2"], '''
-- 
2.9.5


From ed7f2ffd8342450e3fb70a5c3bb5675da186dd35 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 20 Nov 2017 20:53:12 +0000
Subject: [PATCH v3 38/38] build: ensure compiler flags are properly detected

While checking for compiler flag availability, treat warnings
as errors. Thus if the compiler only warns about unsupported flag,
it will fail the test and the flag shall be marked as unsupported.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 buildtools/wafsamba/samba_autoconf.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index dfbe3c5..6804169 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -473,10 +473,13 @@ def CHECK_STRUCTURE_MEMBER(conf, structname, member,
 def CHECK_CFLAGS(conf, cflags, fragment='int main(void) { return 0; }\n'):
     '''check if the given cflags are accepted by the compiler
     '''
+    check_cflags = TO_LIST(cflags)
+    if 'WERROR_CFLAGS' in conf.env:
+        check_cflags.extend(conf.env['WERROR_CFLAGS'])
     return conf.check(fragment=fragment,
                       execute=0,
                       type='nolink',
-                      ccflags=cflags,
+                      ccflags=check_cflags,
                       msg="Checking compiler accepts %s" % cflags)
 
 @conf
-- 
2.9.5



More information about the samba-technical mailing list