Skip to content

Commit

Permalink
lib: modules: Change XXX_init interface from XXX_init(void) to XXX_in…
Browse files Browse the repository at this point in the history
…it(TALLOC_CTX *)

Not currently used - no logic changes inside.

This will make it possible to pass down a long-lived talloc
context from the loading function for modules to use instead
of having them internally all use talloc_autofree_context()
which is a hidden global.

Updated all known module interface numbers, and added a
WHATSNEW.

Signed-off-by: Jeremy Allison <[email protected]>
Signed-off-by: Ralph Böhme <[email protected]>

Autobuild-User(master): Jeremy Allison <[email protected]>
Autobuild-Date(master): Sat Apr 22 01:17:00 CEST 2017 on sn-devel-144
  • Loading branch information
jrasamba committed Apr 21, 2017
1 parent 9342b3e commit 306783d
Show file tree
Hide file tree
Showing 205 changed files with 373 additions and 335 deletions.
19 changes: 19 additions & 0 deletions WHATSNEW.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ was using this call please raise the issue on
[email protected] in order to design a supported
way of obtaining the same functionality.

Change of loadable module interface
-----------------------------------

The _init function of all loadable modules in Samba has changed
from:

NTSTATUS _init(void);

to:

NTSTATUS _init(TALLOC_CTX *);

This allows a program loading a module to pass in a long-lived
talloc context (which must be guaranteed to be alive for the
lifetime of the module). This allows modules to avoid use of
the talloc_autofree_context() (which is inherently thread-unsafe)
and still be valgrind-clean on exit. Modules that don't need to
free long-lived data on exist should use the NULL talloc context.

KNOWN ISSUES
============

Expand Down
4 changes: 2 additions & 2 deletions auth/gensec/external.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* layer is already mutually authenticated.
*/

NTSTATUS gensec_external_init(void);
NTSTATUS gensec_external_init(TALLOC_CTX *ctx);

static NTSTATUS gensec_external_start(struct gensec_security *gensec_security)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ static const struct gensec_security_ops gensec_external_ops = {
};


NTSTATUS gensec_external_init(void)
NTSTATUS gensec_external_init(TALLOC_CTX *ctx)
{
NTSTATUS ret;

Expand Down
3 changes: 2 additions & 1 deletion auth/gensec/gensec.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ struct gensec_settings {
struct gensec_security_ops;
struct gensec_security_ops_wrapper;

#define GENSEC_INTERFACE_VERSION 0
/* Change to 1, loadable modules now take a TALLOC_CTX * init() parameter. */
#define GENSEC_INTERFACE_VERSION 1

/* this structure is used by backends to determine the size of some critical types */
struct gensec_critical_sizes;
Expand Down
6 changes: 3 additions & 3 deletions auth/gensec/gensec_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ bool gensec_setting_bool(struct gensec_settings *settings, const char *mechanism
_PUBLIC_ NTSTATUS gensec_init(void)
{
static bool initialized = false;
#define _MODULE_PROTO(init) extern NTSTATUS init(void);
#define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *);
#ifdef STATIC_gensec_MODULES
STATIC_gensec_MODULES_PROTO;
init_module_fn static_init[] = { STATIC_gensec_MODULES };
Expand All @@ -970,8 +970,8 @@ _PUBLIC_ NTSTATUS gensec_init(void)

shared_init = load_samba_modules(NULL, "gensec");

run_init_functions(static_init);
run_init_functions(shared_init);
run_init_functions(NULL, static_init);
run_init_functions(NULL, shared_init);

talloc_free(shared_init);

Expand Down
4 changes: 2 additions & 2 deletions auth/gensec/ncalrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "lib/param/param.h"
#include "tsocket.h"

_PUBLIC_ NTSTATUS gensec_ncalrpc_as_system_init(void);
_PUBLIC_ NTSTATUS gensec_ncalrpc_as_system_init(TALLOC_CTX *ctx);

struct gensec_ncalrpc_state {
enum {
Expand Down Expand Up @@ -338,7 +338,7 @@ static const struct gensec_security_ops gensec_ncalrpc_security_ops = {
.priority = GENSEC_EXTERNAL,
};

_PUBLIC_ NTSTATUS gensec_ncalrpc_as_system_init(void)
_PUBLIC_ NTSTATUS gensec_ncalrpc_as_system_init(TALLOC_CTX *ctx)
{
NTSTATUS status;

Expand Down
4 changes: 2 additions & 2 deletions auth/gensec/schannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ static NTSTATUS netsec_outgoing_packet(struct schannel_state *state,
return NT_STATUS_OK;
}

_PUBLIC_ NTSTATUS gensec_schannel_init(void);
_PUBLIC_ NTSTATUS gensec_schannel_init(TALLOC_CTX *ctx);

static size_t schannel_sig_size(struct gensec_security *gensec_security, size_t data_size)
{
Expand Down Expand Up @@ -849,7 +849,7 @@ static const struct gensec_security_ops gensec_schannel_security_ops = {
.priority = GENSEC_SCHANNEL
};

_PUBLIC_ NTSTATUS gensec_schannel_init(void)
_PUBLIC_ NTSTATUS gensec_schannel_init(TALLOC_CTX *ctx)
{
NTSTATUS ret;
ret = gensec_register(&gensec_schannel_security_ops);
Expand Down
4 changes: 2 additions & 2 deletions auth/gensec/spnego.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#undef strcasecmp

_PUBLIC_ NTSTATUS gensec_spnego_init(void);
_PUBLIC_ NTSTATUS gensec_spnego_init(TALLOC_CTX *ctx);

enum spnego_state_position {
SPNEGO_SERVER_START,
Expand Down Expand Up @@ -1694,7 +1694,7 @@ static const struct gensec_security_ops gensec_spnego_security_ops = {
.priority = GENSEC_SPNEGO
};

_PUBLIC_ NTSTATUS gensec_spnego_init(void)
_PUBLIC_ NTSTATUS gensec_spnego_init(TALLOC_CTX *ctx)
{
NTSTATUS ret;
ret = gensec_register(&gensec_spnego_security_ops);
Expand Down
2 changes: 1 addition & 1 deletion auth/ntlmssp/ntlmssp.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static const struct gensec_security_ops gensec_ntlmssp_resume_ccache_ops = {
.priority = GENSEC_NTLMSSP
};

_PUBLIC_ NTSTATUS gensec_ntlmssp_init(void)
_PUBLIC_ NTSTATUS gensec_ntlmssp_init(TALLOC_CTX *ctx)
{
NTSTATUS ret;

Expand Down
2 changes: 1 addition & 1 deletion auth/ntlmssp/ntlmssp.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool ntlmssp_blob_matches_magic(const DATA_BLOB *blob);

/* The following definitions come from auth/ntlmssp/gensec_ntlmssp.c */

NTSTATUS gensec_ntlmssp_init(void);
NTSTATUS gensec_ntlmssp_init(TALLOC_CTX *ctx);

uint32_t gensec_ntlmssp_neg_flags(struct gensec_security *gensec_security);
const char *gensec_ntlmssp_server_domain(struct gensec_security *gensec_security);
3 changes: 3 additions & 0 deletions buildtools/wafsamba/samba_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 12 additions & 2 deletions docs-xml/Samba3-Developers-Guide/modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The prototype for these functions is:
</para>

<para><programlisting>
NTSTATUS init_module(void);
NTSTATUS init_module(TALLOC_CTX *);
</programlisting></para>

<para>This function should call one or more
Expand All @@ -111,14 +111,24 @@ NT_STATUS_UNSUCCESSFUL or a more useful nt error code on failure.</para>
<para>For example, pdb_ldap_init() contains: </para>

<para><programlisting>
NTSTATUS pdb_ldap_init(void)
NTSTATUS pdb_ldap_init(TALLOC_CTX *)
{
smb_register_passdb(PASSDB_INTERFACE_VERSION, "ldapsam", pdb_init_ldapsam);
smb_register_passdb(PASSDB_INTERFACE_VERSION, "ldapsam_nua", pdb_init_ldapsam_nua);
return NT_STATUS_OK;
}
</programlisting></para>

<para>
The TALLOC_CTX pointer passed as a parameter must be a long-lived context,
that will stay around for as long as the program that loads the module
exists. It allows the caller to taloc_free any long lived data the
module choses to place on this context on program exit (giving a cleaner
valgrind trace). It should be used by modules in place of talloc_autofree_context(),
use of which makes programs thread-unsafe. Modules that don't care about
free on exist should use the NULL talloc context.
</para>

<sect2>
<title>Static/Shared selection in configure.in</title>

Expand Down
2 changes: 1 addition & 1 deletion examples/VFS/shadow_copy_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static struct vfs_fn_pointers vfs_test_shadow_copy_fns = {
};

static_decl_vfs;
NTSTATUS vfs_shadow_copy_test_init(void)
NTSTATUS vfs_shadow_copy_test_init(TALLOC_CTX *ctx)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
"shadow_copy_test",
Expand Down
2 changes: 1 addition & 1 deletion examples/VFS/skel_opaque.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ struct vfs_fn_pointers skel_opaque_fns = {
};

static_decl_vfs;
NTSTATUS vfs_skel_opaque_init(void)
NTSTATUS vfs_skel_opaque_init(TALLOC_CTX *ctx)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "skel_opaque",
&skel_opaque_fns);
Expand Down
2 changes: 1 addition & 1 deletion examples/VFS/skel_transparent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ struct vfs_fn_pointers skel_transparent_fns = {
};

static_decl_vfs;
NTSTATUS vfs_skel_transparent_init(void)
NTSTATUS vfs_skel_transparent_init(TALLOC_CTX *ctx)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "skel_transparent",
&skel_transparent_fns);
Expand Down
4 changes: 2 additions & 2 deletions examples/auth/auth_skel.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static NTSTATUS auth_init_skel(struct auth_context *auth_context, const char *pa
return NT_STATUS_OK;
}

NTSTATUS auth_skel_init(void);
NTSTATUS auth_skel_init(void)
NTSTATUS auth_skel_init(TALLOC_CTX *ctx);
NTSTATUS auth_skel_init(TALLOC_CTX *ctx)
{
return smb_register_auth(AUTH_INTERFACE_VERSION, "skel", auth_init_skel);
}
2 changes: 1 addition & 1 deletion examples/pdb/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static NTSTATUS testsam_init(struct pdb_methods **pdb_method, const char *locati
}

static_decl_pdb;
NTSTATUS pdb_test_init(void)
NTSTATUS pdb_test_init(TALLOC_CTX *ctx)
{
return smb_register_passdb(PASSDB_INTERFACE_VERSION, "testsam",
testsam_init);
Expand Down
4 changes: 2 additions & 2 deletions file_server/file_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ static void s3fs_task_init(struct task_server *task)
}

/* called at smbd startup - register ourselves as a server service */
NTSTATUS server_service_s3fs_init(void);
NTSTATUS server_service_s3fs_init(TALLOC_CTX *);

NTSTATUS server_service_s3fs_init(void)
NTSTATUS server_service_s3fs_init(TALLOC_CTX *ctx)
{
return register_server_service("s3fs", s3fs_task_init);
}
6 changes: 3 additions & 3 deletions lib/util/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ static init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
*
* @return true if all functions ran successfully, false otherwise
*/
bool run_init_functions(init_module_fn *fns)
bool run_init_functions(TALLOC_CTX *ctx, init_module_fn *fns)
{
int i;
bool ret = true;

if (fns == NULL)
return true;

for (i = 0; fns[i]; i++) { ret &= (bool)NT_STATUS_IS_OK(fns[i]()); }
for (i = 0; fns[i]; i++) { ret &= (bool)NT_STATUS_IS_OK(fns[i](ctx)); }

return ret;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ static NTSTATUS do_smb_load_module(const char *subsystem,

DEBUG(2, ("Module '%s' loaded\n", module_name));

status = init();
status = init(NULL);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Module '%s' initialization failed: %s\n",
module_name, get_friendly_nt_error_msg(status)));
Expand Down
6 changes: 3 additions & 3 deletions lib/util/samba_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#define _SAMBA_MODULES_H

/* Module support */
typedef NTSTATUS (*init_module_fn) (void);
typedef NTSTATUS (*init_module_fn) (TALLOC_CTX *ctx);

NTSTATUS samba_init_module(void);
NTSTATUS samba_init_module(TALLOC_CTX *ctx);

/* this needs to be a string which is not in the C library. We
previously used "init_module", but that meant that modules which
Expand All @@ -44,7 +44,7 @@ init_module_fn load_module(const char *path, bool is_probe, void **handle);
*
* @return true if all functions ran successfully, false otherwise
*/
bool run_init_functions(init_module_fn *fns);
bool run_init_functions(TALLOC_CTX *ctx, init_module_fn *fns);

/**
* Load the initialization functions from DSO files for a specific subsystem.
Expand Down
4 changes: 2 additions & 2 deletions libcli/echo/tests/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "libcli/util/ntstatus.h"
#include "libcli/echo/libecho.h"

NTSTATUS torture_libcli_echo_init(void);
NTSTATUS torture_libcli_echo_init(TALLOC_CTX *);

/* Basic test function that sends an echo request and checks the reply */
static bool echo_udp_basic(struct torture_context *tctx, const char *address)
Expand Down Expand Up @@ -81,7 +81,7 @@ static bool torture_echo_udp(struct torture_context *tctx)
}

/* Test suite that bundles all the libecho tests */
NTSTATUS torture_libcli_echo_init(void)
NTSTATUS torture_libcli_echo_init(TALLOC_CTX *ctx)
{
struct torture_suite *suite;

Expand Down
4 changes: 2 additions & 2 deletions pidl/lib/Parse/Pidl/Samba4/NDR/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static bool $name\__op_interface_by_name(struct dcesrv_interface *iface, const c
return false;
}
NTSTATUS dcerpc_server_$name\_init(void)
NTSTATUS dcerpc_server_$name\_init(TALLOC_CTX *ctx)
{
NTSTATUS ret;
static const struct dcesrv_endpoint_server ep_server = {
Expand Down Expand Up @@ -296,7 +296,7 @@ sub ParseInterface($)
my($interface) = shift;
my $count = 0;

$res .= "NTSTATUS dcerpc_server_$interface->{NAME}\_init(void);\n";
$res .= "NTSTATUS dcerpc_server_$interface->{NAME}\_init(TALLOC_CTX *);\n";
$res .= "\n";

if (!defined $interface->{PROPERTIES}->{uuid}) {
Expand Down
2 changes: 1 addition & 1 deletion source3/auth/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion source3/auth/auth_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source3/auth/auth_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source3/auth/auth_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions source3/auth/auth_samba4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions source3/auth/auth_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ static NTSTATUS auth_init_script(struct auth_context *auth_context, const char *
return NT_STATUS_OK;
}

NTSTATUS auth_script_init(void);
NTSTATUS auth_script_init(void)
NTSTATUS auth_script_init(TALLOC_CTX *);
NTSTATUS auth_script_init(TALLOC_CTX *ctx)
{
return smb_register_auth(AUTH_INTERFACE_VERSION, "script", auth_init_script);
}
Loading

0 comments on commit 306783d

Please sign in to comment.