[PATCH] Cleanup notifyd and fix a crash bug

Volker Lendecke vl at samba.org
Fri Sep 9 06:25:42 UTC 2016


Hi!

Review appreciated!

Thanks, Volker
-------------- next part --------------
>From 7de781dcbdd9ccf84c181462acd64b298a51e5e7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 8 Sep 2016 11:44:23 +0200
Subject: [PATCH 1/4] notifyd: Fix bad comment wording

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

diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c
index 69d30f7..8e52eea 100644
--- a/source3/smbd/notifyd/notifyd.c
+++ b/source3/smbd/notifyd/notifyd.c
@@ -61,7 +61,7 @@ struct notifyd_state {
 	 *
 	 * struct notifyd_instance
 	 *
-	 * to be maintained by parsed by notifyd_entry_parse()
+	 * to be maintained and parsed by notifyd_entry_parse()
 	 */
 	struct db_context *entries;
 
-- 
2.1.4


>From b8c5d187e84da076d355e2c9ebf6e3f1537d9bc1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 8 Sep 2016 11:44:36 +0200
Subject: [PATCH 2/4] notifyd: Avoid "includes.h"

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

diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c
index 8e52eea..b34b89e 100644
--- a/source3/smbd/notifyd/notifyd.c
+++ b/source3/smbd/notifyd/notifyd.c
@@ -17,14 +17,15 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "includes.h"
+#include "replace.h"
+#include <tevent.h>
+#include "lib/util/data_blob.h"
 #include "librpc/gen_ndr/notify.h"
 #include "librpc/gen_ndr/messaging.h"
 #include "librpc/gen_ndr/server_id.h"
 #include "lib/dbwrap/dbwrap.h"
 #include "lib/dbwrap/dbwrap_rbt.h"
 #include "messages.h"
-#include "proto.h"
 #include "tdb.h"
 #include "util_tdb.h"
 #include "notifyd.h"
@@ -32,7 +33,6 @@
 #include "lib/util/tevent_unix.h"
 #include "ctdbd_conn.h"
 #include "ctdb_srvids.h"
-#include "source3/smbd/proto.h"
 #include "server_id_db_util.h"
 #include "lib/util/iov_buf.h"
 #include "messages_util.h"
-- 
2.1.4


>From 2fe56f33d91ce7a6e466795564bf2fd32c92dbb4 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 8 Sep 2016 15:23:59 +0200
Subject: [PATCH 3/4] notifyd: Trim down the noncluster case

Without a cluster, notifyd does not have to receive databases

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

diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c
index b34b89e..ce2da54 100644
--- a/source3/smbd/notifyd/notifyd.c
+++ b/source3/smbd/notifyd/notifyd.c
@@ -130,11 +130,11 @@ static bool notifyd_trigger(struct messaging_context *msg_ctx,
 static bool notifyd_get_db(struct messaging_context *msg_ctx,
 			   struct messaging_rec **prec,
 			   void *private_data);
+
+#ifdef CLUSTER_SUPPORT
 static bool notifyd_got_db(struct messaging_context *msg_ctx,
 			   struct messaging_rec **prec,
 			   void *private_data);
-
-#ifdef CLUSTER_SUPPORT
 static void notifyd_broadcast_reclog(struct ctdbd_connection *ctdbd_conn,
 				     struct server_id src,
 				     struct messaging_reclog *log);
@@ -240,6 +240,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
 	}
 	tevent_req_set_callback(subreq, notifyd_handler_done, req);
 
+#ifdef CLUSTER_SUPPORT
 	subreq = messaging_handler_send(state, ev, msg_ctx,
 					MSG_SMB_NOTIFY_DB,
 					notifyd_got_db, state);
@@ -247,6 +248,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
 		return tevent_req_post(req, ev);
 	}
 	tevent_req_set_callback(subreq, notifyd_handler_done, req);
+#endif
 
 	names_db = messaging_names_db(msg_ctx);
 
@@ -901,6 +903,8 @@ static bool notifyd_get_db(struct messaging_context *msg_ctx,
 	return true;
 }
 
+#ifdef CLUSTER_SUPPORT
+
 static int notifyd_add_proxy_syswatches(struct db_record *rec,
 					void *private_data);
 
@@ -966,8 +970,6 @@ static bool notifyd_got_db(struct messaging_context *msg_ctx,
 	return true;
 }
 
-#ifdef CLUSTER_SUPPORT
-
 static void notifyd_broadcast_reclog(struct ctdbd_connection *ctdbd_conn,
 				     struct server_id src,
 				     struct messaging_reclog *log)
@@ -1169,8 +1171,6 @@ static int notifyd_clean_peers_recv(struct tevent_req *req)
 	return tevent_req_simple_recv_unix(req);
 }
 
-#endif
-
 static int notifyd_add_proxy_syswatches(struct db_record *rec,
 					void *private_data)
 {
@@ -1216,8 +1216,6 @@ static int notifyd_add_proxy_syswatches(struct db_record *rec,
 	return 0;
 }
 
-#ifdef CLUSTER_SUPPORT
-
 static int notifyd_db_del_syswatches(struct db_record *rec, void *private_data)
 {
 	TDB_DATA key = dbwrap_record_get_key(rec);
-- 
2.1.4


>From 11554e9ce720fa629aa18e89ac870fa77ac5be7e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 8 Sep 2016 15:18:39 +0200
Subject: [PATCH 4/4] notifyd: Don't trust remote pointers

Not a security hole IMO: Only root can send us messages, that's at least our
assumption.

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

diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c
index ce2da54..70f52cd 100644
--- a/source3/smbd/notifyd/notifyd.c
+++ b/source3/smbd/notifyd/notifyd.c
@@ -1202,6 +1202,13 @@ static int notifyd_add_proxy_syswatches(struct db_record *rec,
 		uint32_t subdir_filter = instance->instance.subdir_filter;
 		int ret;
 
+		/*
+		 * This is a remote database. Pointers that we were
+		 * given don't make sense locally. Initialize to NULL
+		 * in case sys_notify_watch fails.
+		 */
+		instances[i].sys_watch = NULL;
+
 		ret = state->sys_notify_watch(
 			db, state->sys_notify_ctx, path,
 			&filter, &subdir_filter,
-- 
2.1.4



More information about the samba-technical mailing list