[PATCHES v4] Another round of FreeBSD developer build fixes

Uri Simchoni uri at samba.org
Thu Nov 23 22:58:24 UTC 2017


Hi,

After Andrew committed some of the FreeBSD build fixes, here's another
round of reduced patch set. It includes:

- Patches which were not explicitly nacked but did not land yet
- Reworked pam_wrapper patches, already upstream and reviewed by Andreas
- Reworked pragma-less handling of readline.h issues, according to tip
by Timur Bakeyev

It does not include parts of the original patch set which still require
rework:
- the sysacls patch (v3 1/38) which Andrew felt was smelly - after
closer examination I think it would have broken other
non-Linux/nop-FreeBSD builds.
- remaining #pragma-bearing patchs in pam_winbind (v3 13/38 and 14/38)

Review appreciated,
Uri.
-------------- next part --------------
From 93902057a3be73606a88cd9e91a1d58a72cde6e8 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 v4 01/13] 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 f32a745843bdfda9b59e9a83ac4b0d31536c3b53 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 v4 02/13] 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 5ad03aa14e833c14c7a86679c9cfdd189e62cae3 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 v4 03/13] 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 4ae6464..3723b17 100644
--- a/nsswitch/pam_winbind.c
+++ b/nsswitch/pam_winbind.c
@@ -671,7 +671,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) {
@@ -2993,7 +2993,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 9f23d76091c1d66f08ff13637bbbf59140165c91 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 v4 04/13] 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 7964d181dc3354259b10ee0bb3a6458d2b4cc395 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 v4 05/13] 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 44b04ac..5e8c81c 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 4ebc6ec37fc4bb3ce5faf13ae7f9503053089727 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 v4 06/13] 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 13e9017fbe67a93da14b7e4704b05b8a8a3786af 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 v4 07/13] 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 25f7f2c0923f8806cc1554ab4009015ca5f6ec98 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 v4 08/13] 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 7940a7d..cb2c338 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -690,7 +690,7 @@ def SAMBA_CONFIG_H(conf, path=None):
         conf.ADD_CFLAGS('-Wall', 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 06c5feae0dab874c2385fc8953389f89d65b29b0 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 v4 09/13] 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 b8f780d942458ce7e144d729583a1fe9efa7b897 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 v4 10/13] 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>
Reviewed-by: Andreas Schneider <asn at samba.org>
(ported from pam_wrapper c611121eec7b5f2c39cab7b1c0295eddefdddb1d)
---
 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 2b6ad6bcfff6fac06a2c438b5fec918f193a5140 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 22 Nov 2017 20:48:23 +0000
Subject: [PATCH v4 11/13] pam_wrapper: Use a constant string format specifier
 in test

This fixes a warning about non-constant format specifier.
clang 4.0.0 warns against non-constant format specifier since
it cannot validate the format against the parameters.

Signed-off-by: Uri Simchoni <uri at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
(ported from pam_wrapper 9265da3857e9cfa7a00d1ab35aae1e0b0286efad)
---
 lib/pam_wrapper/python/pypamtest.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/pam_wrapper/python/pypamtest.c b/lib/pam_wrapper/python/pypamtest.c
index c52e1bc..e25900f 100644
--- a/lib/pam_wrapper/python/pypamtest.c
+++ b/lib/pam_wrapper/python/pypamtest.c
@@ -67,9 +67,9 @@ static PyObject *PyExc_PamTestError;
  *** helper functions
  **********************************************************/
 
-static const char *repr_fmt = "{ pam_operation [%d] "
-			      "expected_rv [%d] "
-			      "flags [%d] }";
+#define REPR_FMT "{ pam_operation [%d] " \
+			      "expected_rv [%d] " \
+			      "flags [%d] }"
 
 static char *py_strdup(const char *string)
 {
@@ -267,7 +267,7 @@ set_pypamtest_exception(PyObject *exc,
 			size_t num_tests)
 {
 	PyObject *obj = NULL;
-	/* repr_fmt is fixed and contains just %d expansions, so this is safe */
+	/* REPR_FMT contains just %d expansions, so this is safe */
 	char test_repr[256] = { '\0' };
 	union {
 		char *str;
@@ -286,7 +286,7 @@ set_pypamtest_exception(PyObject *exc,
 	if (perr == PAMTEST_ERR_CASE) {
 		failed = _pamtest_failed_case(tests, num_tests);
 		if (failed) {
-			snprintf(test_repr, sizeof(test_repr), repr_fmt,
+			snprintf(test_repr, sizeof(test_repr), REPR_FMT,
 				 failed->pam_operation,
 				 failed->expected_rv,
 				 failed->flags);
@@ -422,7 +422,7 @@ static int TestCase_init(TestCaseObject *self,
  */
 static PyObject *TestCase_repr(TestCaseObject *self)
 {
-	return PyUnicode_FromFormat(repr_fmt,
+	return PyUnicode_FromFormat(REPR_FMT,
 				    self->pam_operation,
 				    self->expected_rv,
 				    self->flags);
-- 
2.9.5


From 63a99567330b831b66afe7c233ca969b5f5f478e Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 23 Nov 2017 22:20:52 +0200
Subject: [PATCH v4 12/13] lib/smbreadline: detect picky compile issue with
 readline.h

readline.h has build issues with clang if -Wstrict-prototypes
is enabled. Detect this and also detect whether the known
workaround works.

Fix suggested by Timur I. Bakeyev <timur at freebsd.org>

cf. https://lists.gnu.org/archive/html/bug-readline/2014-04/msg00018.html
cf. https://lists.samba.org/archive/samba-technical/2017-November/123923.html

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 libcli/smbreadline/wscript_configure | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/libcli/smbreadline/wscript_configure b/libcli/smbreadline/wscript_configure
index b4d1be2..912ff53 100644
--- a/libcli/smbreadline/wscript_configure
+++ b/libcli/smbreadline/wscript_configure
@@ -7,8 +7,38 @@ for termlib in ['ncurses', 'curses', 'termcap', 'terminfo', 'termlib', 'tinfo']:
         conf.env['READLINE_TERMLIB'] = termlib
         break
 
+#
+# Check if we need to work around readline/readline.h
+# deprecated declarations
+#
+if conf.CONFIG_SET('HAVE_READLINE_READLINE_H'):
+    if not conf.CHECK_CODE('''
+                    #include <readline/readline.h>
+                    int main() {return 0;}
+                    ''',
+                    define='HAVE_WORKING_READLINE_READLINE_WITH_STRICT_PROTO',
+                    cflags=conf.env['WERROR_CFLAGS'] +
+                           ['-Wstrict-prototypes',
+                            '-Werror=strict-prototypes'],
+                    msg='for compiling <readline/readline.h> with strict prototypes',
+                    addmain=False):
+                conf.CHECK_CODE('''
+                    #define _FUNCTION_DEF
+                    #include <readline/readline.h>
+                    int main() {return 0;}
+                    ''',
+                    cflags=conf.env['WERROR_CFLAGS'] +
+                           ['-Wstrict-prototypes',
+                            '-Werror=strict-prototypes'],
+                    msg='for workaround to <readline/readline.h> strict prototypes issue',
+                    define='HAVE_READLINE_READLINE_WORKAROUND',
+                    addmain=False)
+
 conf.CHECK_CODE('''
 #ifdef HAVE_READLINE_READLINE_H
+#  ifdef HAVE_READLINE_READLINE_WORKAROUND
+#    define _FUNCTION_DEF
+#  endif
 #  include <readline/readline.h>
 #  ifdef HAVE_READLINE_HISTORY_H
 #    include <readline/history.h>
@@ -28,6 +58,9 @@ msg='Checking for rl_completion_t')
 
 conf.CHECK_CODE('''
 #ifdef HAVE_READLINE_READLINE_H
+#  ifdef HAVE_READLINE_READLINE_WORKAROUND
+#    define _FUNCTION_DEF
+#  endif
 #  include <readline/readline.h>
 #  ifdef HAVE_READLINE_HISTORY_H
 #    include <readline/history.h>
-- 
2.9.5


From 9225a8c83c38587fba649b35958ff6e002a06136 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 v4 13/13] lib/replace: apply readline -Wstrict-prototypes
 workaround

clang -Wstrict-prototypes has issues with readline > 6.3.
Fix suggested by Timur I. Bakeyev <timur at freebsd.org>

cf. https://lists.gnu.org/archive/html/bug-readline/2014-04/msg00018.html
cf. https://lists.samba.org/archive/samba-technical/2017-November/123923.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..5dc3e75 100644
--- a/lib/replace/system/readline.h
+++ b/lib/replace/system/readline.h
@@ -26,6 +26,9 @@
 
 #ifdef HAVE_LIBREADLINE
 #  ifdef HAVE_READLINE_READLINE_H
+#    ifdef HAVE_READLINE_READLINE_WORKAROUND
+#      define _FUNCTION_DEF
+#    endif
 #    include <readline/readline.h>
 #    ifdef HAVE_READLINE_HISTORY_H
 #      include <readline/history.h>
-- 
2.9.5



More information about the samba-technical mailing list