[PATCH] Change module interface to pass in a TALLOC_CTX pointer.

Ralph Böhme slow at samba.org
Fri Apr 21 12:29:23 UTC 2017


Hi Jeremy,

On Fri, Apr 21, 2017 at 03:01:41AM +0000, Jeremy Allison wrote:
> Currently the initialization function of all our modules are called with a
> function signature of:
> 
> NTSTATUS XXX_init(void)
> 
> The following patch changes this to be:
> 
> NTSTATUS XXX_init(TALLOC_CTX *ctx)
> 
> instead. The patch (for 4.7.x naturally) merely changes
> the definition of the initialization functions and their
> callers, and implements *no* logic changes (all of the changed
> callers in this patch pass NULL in as the new TALLOC_CTX *ctx
> and the modules ignore it).

Nice!

One thing: you missed the static initializers and declarations, eg for the VFS:

vfs_init_custom() uses "static_init_vfs;" which expands to

  #define static_init_vfs { vfs_default_init();  vfs_posixacl_init();  vfs_dfs_samba4_init(); }

But the vfs init functions now take a TALLOC_CTX arg, eg

   NTSTATUS vfs_default_init(TALLOC_CTX *ctx)

The compiler doesn't complain, because the static_decl_vfs contains the same
wrong function signatures:

  #define static_decl_vfs extern NTSTATUS vfs_default_init(void); extern NTSTATUS vfs_posixacl_init(void); extern NTSTATUS vfs_dfs_samba4_init(void);

Attached patch should fix this. Fixup your commit with mine if happy.

-slow
-------------- next part --------------
From 7a67d69685324175f7fa74b1776c0bf694a6b096 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Fri, 21 Apr 2017 14:09:44 +0200
Subject: [PATCH] !fixup: lib: modules: Change XXX_init interface from
 XXX_init(void) to XXX_init(TALLOC_CTX *)

Previous commit missed to update the static initializers...
---
 buildtools/wafsamba/samba_patterns.py     |  3 +++
 source3/auth/auth.c                       |  2 +-
 source3/auth/auth_builtin.c               |  2 +-
 source3/auth/auth_domain.c                |  2 +-
 source3/auth/auth_sam.c                   |  2 +-
 source3/auth/auth_samba4.c                |  4 ++--
 source3/auth/auth_unix.c                  |  2 +-
 source3/auth/auth_winbind.c               |  2 +-
 source3/auth/proto.h                      | 12 ++++++------
 source3/include/nss_info.h                |  2 +-
 source3/passdb/pdb_interface.c            |  2 +-
 source3/rpc_server/mdssvc/srv_mdssvc_nt.c |  2 +-
 source3/rpc_server/rpc_service_setup.c    |  2 +-
 source3/smbd/vfs.c                        |  2 +-
 source3/winbindd/idmap.c                  |  2 +-
 source3/winbindd/idmap_ad.c               |  2 +-
 source3/winbindd/idmap_ad_nss.c           |  2 +-
 source3/winbindd/idmap_nss.c              |  2 +-
 source3/winbindd/idmap_passdb.c           |  2 +-
 source3/winbindd/idmap_proto.h            |  8 ++++----
 source3/winbindd/idmap_tdb.c              |  2 +-
 source3/winbindd/nss_info.c               |  2 +-
 source3/winbindd/nss_info_template.c      |  2 +-
 source3/wscript                           |  4 ++--
 24 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/buildtools/wafsamba/samba_patterns.py b/buildtools/wafsamba/samba_patterns.py
index ceca2cc..0481520 100644
--- a/buildtools/wafsamba/samba_patterns.py
+++ b/buildtools/wafsamba/samba_patterns.py
@@ -178,6 +178,9 @@ def write_build_options(task):
                 keys_header_other.append(key)
             else:
                 keys_option_have.append(key)
+        elif key.startswith("static_init_"):
+            l = key.split("(")
+            keys_misc.append(l[0])
         else:
             keys_misc.append(key)
 
diff --git a/source3/auth/auth.c b/source3/auth/auth.c
index ba6245d..54e9433 100644
--- a/source3/auth/auth.c
+++ b/source3/auth/auth.c
@@ -392,7 +392,7 @@ bool load_auth_module(struct auth_context *auth_context,
 
 	/* Initialise static modules if not done so yet */
 	if(!initialised_static_modules) {
-		static_init_auth;
+		static_init_auth(NULL);
 		initialised_static_modules = True;
 	}
 
diff --git a/source3/auth/auth_builtin.c b/source3/auth/auth_builtin.c
index 7480799..0fa95d9 100644
--- a/source3/auth/auth_builtin.c
+++ b/source3/auth/auth_builtin.c
@@ -167,7 +167,7 @@ static NTSTATUS auth_init_name_to_ntstatus(struct auth_context *auth_context, co
 
 #endif /* DEVELOPER */
 
-NTSTATUS auth_builtin_init(void)
+NTSTATUS auth_builtin_init(TALLOC_CTX *mem_ctx)
 {
 	smb_register_auth(AUTH_INTERFACE_VERSION, "guest", auth_init_guest);
 #ifdef DEVELOPER
diff --git a/source3/auth/auth_domain.c b/source3/auth/auth_domain.c
index b3ff518..40d717d 100644
--- a/source3/auth/auth_domain.c
+++ b/source3/auth/auth_domain.c
@@ -406,7 +406,7 @@ static NTSTATUS auth_init_trustdomain(struct auth_context *auth_context, const c
 	return NT_STATUS_OK;
 }
 
-NTSTATUS auth_domain_init(void) 
+NTSTATUS auth_domain_init(TALLOC_CTX *mem_ctx)
 {
 	smb_register_auth(AUTH_INTERFACE_VERSION, "trustdomain", auth_init_trustdomain);
 	smb_register_auth(AUTH_INTERFACE_VERSION, "ntdomain", auth_init_ntdomain);
diff --git a/source3/auth/auth_sam.c b/source3/auth/auth_sam.c
index 634386f..4bcb792 100644
--- a/source3/auth/auth_sam.c
+++ b/source3/auth/auth_sam.c
@@ -188,7 +188,7 @@ static NTSTATUS auth_init_sam_netlogon3(struct auth_context *auth_context,
 	return NT_STATUS_OK;
 }
 
-NTSTATUS auth_sam_init(void)
+NTSTATUS auth_sam_init(TALLOC_CTX *mem_ctx)
 {
 	smb_register_auth(AUTH_INTERFACE_VERSION, "sam", auth_init_sam);
 	smb_register_auth(AUTH_INTERFACE_VERSION, "sam_ignoredomain", auth_init_sam_ignoredomain);
diff --git a/source3/auth/auth_samba4.c b/source3/auth/auth_samba4.c
index 4c83c2a..46c8f9f 100644
--- a/source3/auth/auth_samba4.c
+++ b/source3/auth/auth_samba4.c
@@ -391,8 +391,8 @@ static NTSTATUS auth_init_samba4(struct auth_context *auth_context,
 	return NT_STATUS_OK;
 }
 
-NTSTATUS auth_samba4_init(void);
-NTSTATUS auth_samba4_init(void)
+NTSTATUS auth_samba4_init(TALLOC_CTX *mem_ctx);
+NTSTATUS auth_samba4_init(TALLOC_CTX *mem_ctx)
 {
 	smb_register_auth(AUTH_INTERFACE_VERSION, "samba4",
 			  auth_init_samba4);
diff --git a/source3/auth/auth_unix.c b/source3/auth/auth_unix.c
index a4e5b74..08d4e00 100644
--- a/source3/auth/auth_unix.c
+++ b/source3/auth/auth_unix.c
@@ -98,7 +98,7 @@ static NTSTATUS auth_init_unix(struct auth_context *auth_context, const char* pa
 	return NT_STATUS_OK;
 }
 
-NTSTATUS auth_unix_init(void)
+NTSTATUS auth_unix_init(TALLOC_CTX *mem_ctx)
 {
 	return smb_register_auth(AUTH_INTERFACE_VERSION, "unix", auth_init_unix);
 }
diff --git a/source3/auth/auth_winbind.c b/source3/auth/auth_winbind.c
index e6a6296..6bf2118 100644
--- a/source3/auth/auth_winbind.c
+++ b/source3/auth/auth_winbind.c
@@ -178,7 +178,7 @@ static NTSTATUS auth_init_winbind(struct auth_context *auth_context, const char
 	return NT_STATUS_OK;
 }
 
-NTSTATUS auth_winbind_init(void)
+NTSTATUS auth_winbind_init(TALLOC_CTX *mem_ctx)
 {
 	return smb_register_auth(AUTH_INTERFACE_VERSION, "winbind", auth_init_winbind);
 }
diff --git a/source3/auth/proto.h b/source3/auth/proto.h
index 348b882..4a1aa24 100644
--- a/source3/auth/proto.h
+++ b/source3/auth/proto.h
@@ -95,12 +95,12 @@ NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
 
 /* The following definitions come from auth/auth_builtin.c  */
 
-NTSTATUS auth_builtin_init(void);
+NTSTATUS auth_builtin_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from auth/auth_domain.c  */
 
 void attempt_machine_password_change(void);
-NTSTATUS auth_domain_init(void);
+NTSTATUS auth_domain_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from auth/auth_generic.c  */
 
@@ -149,11 +149,11 @@ NTSTATUS check_sam_security_info3(const DATA_BLOB *challenge,
 				  TALLOC_CTX *mem_ctx,
 				  const struct auth_usersupplied_info *user_info,
 				  struct netr_SamInfo3 **pinfo3);
-NTSTATUS auth_sam_init(void);
+NTSTATUS auth_sam_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from auth/auth_unix.c  */
 
-NTSTATUS auth_unix_init(void);
+NTSTATUS auth_unix_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from auth/auth_util.c  */
 struct tsocket_address;
@@ -302,7 +302,7 @@ NTSTATUS do_map_to_guest_server_info(TALLOC_CTX *mem_ctx,
 
 /* The following definitions come from auth/auth_winbind.c  */
 
-NTSTATUS auth_winbind_init(void);
+NTSTATUS auth_winbind_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from auth/server_info.c  */
 
@@ -409,6 +409,6 @@ NTSTATUS make_session_info_krb5(TALLOC_CTX *mem_ctx,
 
 /* The following definitions come from auth/auth_samba4.c  */
 
-NTSTATUS auth_samba4_init(void);
+NTSTATUS auth_samba4_init(TALLOC_CTX *mem_ctx);
 
 #endif /* _AUTH_PROTO_H_ */
diff --git a/source3/include/nss_info.h b/source3/include/nss_info.h
index 54b4399..448f884 100644
--- a/source3/include/nss_info.h
+++ b/source3/include/nss_info.h
@@ -90,7 +90,7 @@ NTSTATUS nss_close( const char *parameters );
 
 /* The following definitions come from winbindd/nss_info_template.c  */
 
-NTSTATUS nss_info_template_init( void );
+NTSTATUS nss_info_template_init(TALLOC_CTX *mem_ctx);
 
 #endif /* _IDMAP_NSS_H_ */
 
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index 36ae576..49752dd 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -51,7 +51,7 @@ static void lazy_initialize_passdb(void)
 	if(initialized) {
 		return;
 	}
-	static_init_pdb;
+	static_init_pdb(NULL);
 	initialized = True;
 }
 
diff --git a/source3/rpc_server/mdssvc/srv_mdssvc_nt.c b/source3/rpc_server/mdssvc/srv_mdssvc_nt.c
index 37b13e7..c2770a2 100644
--- a/source3/rpc_server/mdssvc/srv_mdssvc_nt.c
+++ b/source3/rpc_server/mdssvc/srv_mdssvc_nt.c
@@ -86,7 +86,7 @@ static struct rpc_module_fns rpc_module_mdssvc_fns = {
 };
 
 static_decl_rpc;
-NTSTATUS rpc_mdssvc_module_init(void)
+NTSTATUS rpc_mdssvc_module_init(TALLOC_CTX *mem_ctx)
 {
 	DBG_DEBUG("Registering mdsvc RPC service\n");
 
diff --git a/source3/rpc_server/rpc_service_setup.c b/source3/rpc_server/rpc_service_setup.c
index 8813325..9c755e6 100644
--- a/source3/rpc_server/rpc_service_setup.c
+++ b/source3/rpc_server/rpc_service_setup.c
@@ -531,7 +531,7 @@ bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
 	}
 
 	/* Initialize static subsystems */
-	static_init_rpc;
+	static_init_rpc(NULL);
 
 	/* Initialize shared modules */
 	mod_init_fns = load_samba_modules(tmp_ctx, "rpc");
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index b7364b7..f75172a 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -133,7 +133,7 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
 	}
 
 	if(!backends) {
-		static_init_vfs;
+		static_init_vfs(NULL);
 	}
 
 	DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
diff --git a/source3/winbindd/idmap.c b/source3/winbindd/idmap.c
index dda8d0a..70f35ae 100644
--- a/source3/winbindd/idmap.c
+++ b/source3/winbindd/idmap.c
@@ -143,7 +143,7 @@ static bool idmap_init(void)
 
 	DEBUG(10, ("idmap_init(): calling static_init_idmap\n"));
 
-	static_init_idmap;
+	static_init_idmap(NULL);
 
 	initialized = true;
 
diff --git a/source3/winbindd/idmap_ad.c b/source3/winbindd/idmap_ad.c
index dac374e..8c9e97b 100644
--- a/source3/winbindd/idmap_ad.c
+++ b/source3/winbindd/idmap_ad.c
@@ -941,7 +941,7 @@ NTSTATUS idmap_ad_init(TALLOC_CTX *ctx)
 		return status;
 	}
 
-	status = idmap_ad_nss_init();
+	status = idmap_ad_nss_init(ctx);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
diff --git a/source3/winbindd/idmap_ad_nss.c b/source3/winbindd/idmap_ad_nss.c
index 8b27b36..87c7814 100644
--- a/source3/winbindd/idmap_ad_nss.c
+++ b/source3/winbindd/idmap_ad_nss.c
@@ -394,7 +394,7 @@ static struct nss_info_methods nss_sfu20_methods = {
  Initialize the plugins
  ***********************************************************************/
 
-NTSTATUS idmap_ad_nss_init(void)
+NTSTATUS idmap_ad_nss_init(TALLOC_CTX *mem_ctx)
 {
 	NTSTATUS status;
 
diff --git a/source3/winbindd/idmap_nss.c b/source3/winbindd/idmap_nss.c
index 24f8217..3fe98cb 100644
--- a/source3/winbindd/idmap_nss.c
+++ b/source3/winbindd/idmap_nss.c
@@ -202,7 +202,7 @@ static struct idmap_methods nss_methods = {
 	.sids_to_unixids = idmap_nss_sids_to_unixids,
 };
 
-NTSTATUS idmap_nss_init(void)
+NTSTATUS idmap_nss_init(TALLOC_CTX *mem_ctx)
 {
 	return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "nss", &nss_methods);
 }
diff --git a/source3/winbindd/idmap_passdb.c b/source3/winbindd/idmap_passdb.c
index cf8ad74..75fc732 100644
--- a/source3/winbindd/idmap_passdb.c
+++ b/source3/winbindd/idmap_passdb.c
@@ -86,7 +86,7 @@ static struct idmap_methods passdb_methods = {
 	.sids_to_unixids = idmap_pdb_sids_to_unixids,
 };
 
-NTSTATUS idmap_passdb_init(void)
+NTSTATUS idmap_passdb_init(TALLOC_CTX *mem_ctx)
 {
 	return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "passdb", &passdb_methods);
 }
diff --git a/source3/winbindd/idmap_proto.h b/source3/winbindd/idmap_proto.h
index 0e25963..596c22f 100644
--- a/source3/winbindd/idmap_proto.h
+++ b/source3/winbindd/idmap_proto.h
@@ -40,15 +40,15 @@ struct idmap_domain *idmap_find_domain(const char *domname);
 
 /* The following definitions come from winbindd/idmap_nss.c  */
 
-NTSTATUS idmap_nss_init(void);
+NTSTATUS idmap_nss_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from winbindd/idmap_passdb.c  */
 
-NTSTATUS idmap_passdb_init(void);
+NTSTATUS idmap_passdb_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from winbindd/idmap_tdb.c  */
 
-NTSTATUS idmap_tdb_init(void);
+NTSTATUS idmap_tdb_init(TALLOC_CTX *mem_ctx);
 
 /* The following definitions come from winbindd/idmap_util.c  */
 
@@ -64,6 +64,6 @@ struct id_map **id_map_ptrs_init(TALLOC_CTX *mem_ctx, size_t num_ids);
 /* max number of ids requested per LDAP batch query */
 #define IDMAP_LDAP_MAX_IDS 30
 
-NTSTATUS idmap_ad_nss_init(void);
+NTSTATUS idmap_ad_nss_init(TALLOC_CTX *mem_ctx);
 
 #endif /* _WINBINDD_IDMAP_PROTO_H_ */
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c
index a04295f..24ef118 100644
--- a/source3/winbindd/idmap_tdb.c
+++ b/source3/winbindd/idmap_tdb.c
@@ -434,7 +434,7 @@ static struct idmap_methods db_methods = {
 	.allocate_id = idmap_tdb_common_get_new_id,
 };
 
-NTSTATUS idmap_tdb_init(void)
+NTSTATUS idmap_tdb_init(TALLOC_CTX *mem_ctx)
 {
 	DEBUG(10, ("calling idmap_tdb_init\n"));
 
diff --git a/source3/winbindd/nss_info.c b/source3/winbindd/nss_info.c
index 2c6bb01..9ef7e20 100644
--- a/source3/winbindd/nss_info.c
+++ b/source3/winbindd/nss_info.c
@@ -173,7 +173,7 @@ static NTSTATUS nss_init(const char **nss_list)
 
 	nss_backend = nss_get_backend("template");
 	if (nss_backend == NULL) {
-		static_init_nss_info;
+		static_init_nss_info(NULL);
 	}
 
 	/* Create the list of nss_domains (loading any shared plugins
diff --git a/source3/winbindd/nss_info_template.c b/source3/winbindd/nss_info_template.c
index 53159b6..c58a7fc 100644
--- a/source3/winbindd/nss_info_template.c
+++ b/source3/winbindd/nss_info_template.c
@@ -71,7 +71,7 @@ static struct nss_info_methods nss_template_methods = {
 	.close_fn       = nss_template_close
 };
 
-NTSTATUS nss_info_template_init( void )
+NTSTATUS nss_info_template_init(TALLOC_CTX *mem_ctx)
 {
 	return smb_register_idmap_nss(SMB_NSS_INFO_INTERFACE_VERSION, 
 				      "template", 
diff --git a/source3/wscript b/source3/wscript
index c526fc5..1bfb6c0 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -1857,11 +1857,11 @@ main() {
         if p in static_list:
             decl_list=""
             for entry in static_list[p]:
-                decl_list += "extern NTSTATUS %s_init(void); " % entry
+                decl_list += "extern NTSTATUS %s_init(TALLOC_CTX *mem_ctx); " % entry
                 conf.env[static_env].append('%s' % entry)
             decl_list = decl_list.rstrip()
             conf.DEFINE('static_decl_%s' % p, decl_list)
-            conf.DEFINE('static_init_%s' % p, '{ %s_init(); }' % '_init();  '.join(static_list[p]))
+            conf.DEFINE('static_init_%s(mem_ctx)' % p, '{ %s_init((mem_ctx)); }' % '_init((mem_ctx));  '.join(static_list[p]))
         else:
             conf.DEFINE('static_decl_%s' % p, '')
             conf.DEFINE('static_init_%s' % p, '{}')
-- 
2.9.3



More information about the samba-technical mailing list