[PATCH] reduce some code duplication

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Nov 17 13:38:49 UTC 2015


Hi!

Review&push appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 80b1e9940657cf9cc34861d369dba589ebb46e59 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 17 Nov 2015 13:21:13 +0100
Subject: [PATCH 1/6] smbd: Streamline dos_mode_debug_print

One line per flag is a bit overkill

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/dosmode.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index 72acd4e..89224e5 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -33,34 +33,36 @@ static NTSTATUS get_file_handle_for_metadata(connection_struct *conn,
 
 static void dos_mode_debug_print(uint32_t mode)
 {
-	DEBUG(8,("dos_mode returning "));
+	fstring modestr;
+
+	modestr[0] = '\0';
 
 	if (mode & FILE_ATTRIBUTE_HIDDEN) {
-		DEBUG(8, ("h"));
+		fstrcat(modestr, "h");
 	}
 	if (mode & FILE_ATTRIBUTE_READONLY) {
-		DEBUG(8, ("r"));
+		fstrcat(modestr, "r");
 	}
 	if (mode & FILE_ATTRIBUTE_SYSTEM) {
-		DEBUG(8, ("s"));
+		fstrcat(modestr, "s");
 	}
 	if (mode & FILE_ATTRIBUTE_DIRECTORY) {
-		DEBUG(8, ("d"));
+		fstrcat(modestr, "d");
 	}
 	if (mode & FILE_ATTRIBUTE_ARCHIVE) {
-		DEBUG(8, ("a"));
+		fstrcat(modestr, "a");
 	}
 	if (mode & FILE_ATTRIBUTE_SPARSE) {
-		DEBUG(8, ("[sparse]"));
+		fstrcat(modestr, "[sparse]");
 	}
 	if (mode & FILE_ATTRIBUTE_OFFLINE) {
-		DEBUG(8, ("[offline]"));
+		fstrcat(modestr, "[offline]");
 	}
 	if (mode & FILE_ATTRIBUTE_COMPRESSED) {
-		DEBUG(8, ("[compressed]"));
+		fstrcat(modestr, "[compressed]");
 	}
 
-	DEBUG(8,("\n"));
+	DBG_INFO("dos_mode returning %s\n", modestr);
 }
 
 static uint32_t filter_mode_by_protocol(uint32_t mode)
-- 
1.9.1


From ec4a2930b28d69dba93af31d6ed7294bcfd90577 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 17 Nov 2015 13:37:14 +0100
Subject: [PATCH 2/6] smbd: Use dos_mode_debug_print in dos_mode_msdfs

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/dosmode.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index 89224e5..c4e6007 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -31,7 +31,7 @@ static NTSTATUS get_file_handle_for_metadata(connection_struct *conn,
 				files_struct **ret_fsp,
 				bool *need_close);
 
-static void dos_mode_debug_print(uint32_t mode)
+static void dos_mode_debug_print(const char *func, uint32_t mode)
 {
 	fstring modestr;
 
@@ -62,7 +62,7 @@ static void dos_mode_debug_print(uint32_t mode)
 		fstrcat(modestr, "[compressed]");
 	}
 
-	DBG_INFO("dos_mode returning %s\n", modestr);
+	DBG_INFO("%s returning %s\n", func, modestr);
 }
 
 static uint32_t filter_mode_by_protocol(uint32_t mode)
@@ -541,16 +541,7 @@ uint32_t dos_mode_msdfs(connection_struct *conn,
 	 */
 	result |= FILE_ATTRIBUTE_REPARSE_POINT;
 
-	DEBUG(8,("dos_mode_msdfs returning "));
-
-	if (result & FILE_ATTRIBUTE_HIDDEN) DEBUG(8, ("h"));
-	if (result & FILE_ATTRIBUTE_READONLY ) DEBUG(8, ("r"));
-	if (result & FILE_ATTRIBUTE_SYSTEM) DEBUG(8, ("s"));
-	if (result & FILE_ATTRIBUTE_DIRECTORY   ) DEBUG(8, ("d"));
-	if (result & FILE_ATTRIBUTE_ARCHIVE  ) DEBUG(8, ("a"));
-	if (result & FILE_ATTRIBUTE_SPARSE ) DEBUG(8, ("[sparse]"));
-
-	DEBUG(8,("\n"));
+	dos_mode_debug_print(__func__, result);
 
 	return(result);
 }
@@ -655,7 +646,7 @@ uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname)
 
 	result = filter_mode_by_protocol(result);
 
-	dos_mode_debug_print(result);
+	dos_mode_debug_print(__func__, result);
 
 	return result;
 }
-- 
1.9.1


From 9664204299cee46d267cd148e61e40e99cff2821 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 17 Nov 2015 13:41:29 +0100
Subject: [PATCH 3/6] smbd: Use dos_mode_debug_print in dos_mode_from_sbuf

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/dosmode.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index c4e6007..9e164bc 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -242,15 +242,8 @@ static uint32_t dos_mode_from_sbuf(connection_struct *conn,
 
 	result |= set_link_read_only_flag(&smb_fname->st);
 
-	DEBUG(8,("dos_mode_from_sbuf returning "));
-
-	if (result & FILE_ATTRIBUTE_HIDDEN) DEBUG(8, ("h"));
-	if (result & FILE_ATTRIBUTE_READONLY ) DEBUG(8, ("r"));
-	if (result & FILE_ATTRIBUTE_SYSTEM) DEBUG(8, ("s"));
-	if (result & FILE_ATTRIBUTE_DIRECTORY   ) DEBUG(8, ("d"));
-	if (result & FILE_ATTRIBUTE_ARCHIVE  ) DEBUG(8, ("a"));
+	dos_mode_debug_print(__func__, result);
 
-	DEBUG(8,("\n"));
 	return result;
 }
 
-- 
1.9.1


From abedd4d85f26ed143f864b02e590274e3e1cedac Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 17 Nov 2015 13:43:10 +0100
Subject: [PATCH 4/6] smbd: Use dos_mode_debug_print in get_ea_dos_attribute

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/dosmode.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index 9e164bc..b2476ce 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -362,15 +362,7 @@ static bool get_ea_dos_attribute(connection_struct *conn,
 	/* FILE_ATTRIBUTE_SPARSE is valid on get but not on set. */
 	*pattr = (uint32_t)(dosattr & (SAMBA_ATTRIBUTES_MASK|FILE_ATTRIBUTE_SPARSE));
 
-	DEBUG(8,("get_ea_dos_attribute returning (0x%x)", dosattr));
-
-	if (dosattr & FILE_ATTRIBUTE_HIDDEN) DEBUG(8, ("h"));
-	if (dosattr & FILE_ATTRIBUTE_READONLY ) DEBUG(8, ("r"));
-	if (dosattr & FILE_ATTRIBUTE_SYSTEM) DEBUG(8, ("s"));
-	if (dosattr & FILE_ATTRIBUTE_DIRECTORY   ) DEBUG(8, ("d"));
-	if (dosattr & FILE_ATTRIBUTE_ARCHIVE  ) DEBUG(8, ("a"));
-
-	DEBUG(8,("\n"));
+	dos_mode_debug_print(__func__, *pattr);
 
 	return True;
 }
-- 
1.9.1


From ff929f90ff2b712d9cf1459e729b1aaf469b0ec1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 17 Nov 2015 13:44:30 +0100
Subject: [PATCH 5/6] smbd: Add hex value to dos_mode_debug_print

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/dosmode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index b2476ce..09bb1f3 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -62,7 +62,8 @@ static void dos_mode_debug_print(const char *func, uint32_t mode)
 		fstrcat(modestr, "[compressed]");
 	}
 
-	DBG_INFO("%s returning %s\n", func, modestr);
+	DBG_INFO("%s returning (0x%x): \"%s\"\n", func, (unsigned)mode,
+		 modestr);
 }
 
 static uint32_t filter_mode_by_protocol(uint32_t mode)
-- 
1.9.1


From 099d4c265e137be85d9d675c59ccb3861c6e10f3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 17 Nov 2015 13:49:30 +0100
Subject: [PATCH 6/6] smbd: Early return from dos_mode_debug_print

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/smbd/dosmode.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index 09bb1f3..0f3eef0 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -35,6 +35,10 @@ static void dos_mode_debug_print(const char *func, uint32_t mode)
 {
 	fstring modestr;
 
+	if (DEBUGLEVEL < DBGLVL_INFO) {
+		return;
+	}
+
 	modestr[0] = '\0';
 
 	if (mode & FILE_ATTRIBUTE_HIDDEN) {
-- 
1.9.1



More information about the samba-technical mailing list