Skip to content

Commit

Permalink
Revert making public of the samba-module library.
Browse files Browse the repository at this point in the history
This library was tiny - containing just two public functions than were
themselves trivial. The amount of overhead this causes isn't really worth the
benefits of sharing the code with other projects like OpenChange. In addition, this code
isn't really generically useful anyway, as it can only load from the module path
set for Samba at configure time.

Adding a new library was breaking the API/ABI anyway, so OpenChange had to be
updated to cope with the new situation one way or another. I've added a simpler
(compatible) routine for loading modules to OpenChange, which is less than 100 lines of code.

Autobuild-User: Jelmer Vernooij <[email protected]>
Autobuild-Date: Sat Dec  3 08:36:33 CET 2011 on sn-devel-104
  • Loading branch information
jelmer committed Dec 3, 2011
1 parent d74b3f9 commit 05bc4de
Show file tree
Hide file tree
Showing 40 changed files with 145 additions and 225 deletions.
14 changes: 7 additions & 7 deletions auth/gensec/gensec_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "auth/gensec/gensec.h"
#include "lib/param/param.h"
#include "lib/util/tsort.h"
#include "lib/util/samba_module.h"
#include "lib/util/samba_modules.h"

/* the list of currently registered GENSEC backends */
static struct gensec_security_ops **generic_security_ops;
Expand Down Expand Up @@ -878,19 +878,19 @@ _PUBLIC_ NTSTATUS gensec_init(void)
#define _MODULE_PROTO(init) extern NTSTATUS init(void);
#ifdef STATIC_gensec_MODULES
STATIC_gensec_MODULES_PROTO;
samba_module_init_fn static_init[] = { STATIC_gensec_MODULES };
init_module_fn static_init[] = { STATIC_gensec_MODULES };
#else
samba_module_init_fn *static_init = NULL;
init_module_fn *static_init = NULL;
#endif
samba_module_init_fn *shared_init;
init_module_fn *shared_init;

if (initialized) return NT_STATUS_OK;
initialized = true;

shared_init = samba_module_init_fns_for_subsystem(NULL, "gensec");
shared_init = load_samba_modules(NULL, "gensec");

samba_module_init_fns_run(static_init);
samba_module_init_fns_run(shared_init);
run_init_functions(static_init);
run_init_functions(shared_init);

talloc_free(shared_init);

Expand Down
2 changes: 1 addition & 1 deletion auth/gensec/wscript_build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bld.SAMBA_LIBRARY('gensec',
source='gensec.c gensec_start.c',
pc_files='gensec.pc',
autoproto='gensec_toplevel_proto.h',
public_deps='tevent-util samba-util errors LIBPACKET auth_system_session samba-module gensec_util',
public_deps='tevent-util samba-util errors LIBPACKET auth_system_session samba-modules gensec_util',
public_headers='gensec.h',
deps='com_err',
vnum='0.0.1'
Expand Down
2 changes: 1 addition & 1 deletion buildtools/wafsamba/wafsamba.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def SAMBA_MODULE(bld, modname, source,
includes='',
subsystem=None,
init_function=None,
module_init_name='samba_module_init',
module_init_name='samba_init_module',
autoproto=None,
autoproto_extra_source='',
cflags='',
Expand Down
2 changes: 0 additions & 2 deletions lib/util/ABI/samba-module-0.0.1.sigs

This file was deleted.

42 changes: 0 additions & 42 deletions lib/util/internal_module.h

This file was deleted.

55 changes: 46 additions & 9 deletions lib/util/internal_module.c → lib/util/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

#include "includes.h"
#include "dynconfig/dynconfig.h"
#include "lib/util/internal_module.h"
#include "lib/util/samba_modules.h"
#include "system/filesys.h"
#include "system/dir.h"

/**
* Obtain the init function from a shared library file
*/
samba_module_init_fn load_module(const char *path, bool is_probe, void **handle_out)
init_module_fn load_module(const char *path, bool is_probe, void **handle_out)
{
void *handle;
void *init_fn;
Expand Down Expand Up @@ -57,15 +57,15 @@ samba_module_init_fn load_module(const char *path, bool is_probe, void **handle_
return NULL;
}

init_fn = (samba_module_init_fn)dlsym(handle, SAMBA_MODULE_INIT);
init_fn = (init_module_fn)dlsym(handle, SAMBA_INIT_MODULE);

/* we could check dlerror() to determine if it worked, because
dlsym() can validly return NULL, but what would we do with
a NULL pointer as a module init function? */

if (init_fn == NULL) {
DEBUG(0, ("Unable to find %s() in %s: %s\n",
SAMBA_MODULE_INIT, path, dlerror()));
SAMBA_INIT_MODULE, path, dlerror()));
DEBUG(1, ("Loading module '%s' failed\n", path));
dlclose(handle);
return NULL;
Expand All @@ -75,20 +75,20 @@ samba_module_init_fn load_module(const char *path, bool is_probe, void **handle_
*handle_out = handle;
}

return (samba_module_init_fn)init_fn;
return (init_module_fn)init_fn;
}

/**
* Obtain list of init functions from the modules in the specified
* directory
*/
samba_module_init_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
static init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
{
DIR *dir;
struct dirent *entry;
char *filename;
int success = 0;
samba_module_init_fn *ret = talloc_array(mem_ctx, samba_module_init_fn, 2);
init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2);

ret[0] = NULL;

Expand All @@ -106,7 +106,7 @@ samba_module_init_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)

ret[success] = load_module(filename, true, NULL);
if (ret[success]) {
ret = talloc_realloc(mem_ctx, ret, samba_module_init_fn, success+2);
ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2);
success++;
ret[success] = NULL;
}
Expand All @@ -119,13 +119,50 @@ samba_module_init_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
return ret;
}

/**
* Run the specified init functions.
*
* @return true if all functions ran successfully, false otherwise
*/
bool run_init_functions(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]()); }

return ret;
}

/**
* Load the initialization functions from DSO files for a specific subsystem.
*
* Will return an array of function pointers to initialization functions
*/

init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem)
{
char *path = modules_path(mem_ctx, subsystem);
init_module_fn *ret;

ret = load_modules(mem_ctx, path);

talloc_free(path);

return ret;
}


/* Load a dynamic module. Only log a level 0 error if we are not checking
for the existence of a module (probling). */

static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe)
{
void *handle;
samba_module_init_fn init;
init_module_fn init;
NTSTATUS status;

init = load_module(module_name, is_probe, &handle);
Expand Down
11 changes: 0 additions & 11 deletions lib/util/samba-module.pc.in

This file was deleted.

62 changes: 0 additions & 62 deletions lib/util/samba_module.c

This file was deleted.

20 changes: 15 additions & 5 deletions lib/util/samba_module.h → lib/util/samba_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,38 @@
#define _SAMBA_MODULES_H

/* Module support */
typedef NTSTATUS (*samba_module_init_fn) (void);
typedef NTSTATUS (*init_module_fn) (void);

NTSTATUS samba_module_init(void);
NTSTATUS samba_init_module(void);

/* this needs to be a string which is not in the C library. We
previously used "init_module", but that meant that modules which
did not define this function ended up calling the C library
function init_module() which makes a system call */
#define SAMBA_MODULE_INIT "samba_module_init"
#define SAMBA_INIT_MODULE "samba_init_module"

/**
* Obtain the init function from a shared library file.
*
* The handle to dlclose() in case of error is returns in *handle if handle is not NULL
*/
init_module_fn load_module(const char *path, bool is_probe, void **handle);

/**
* Run the specified init functions.
*
* @return true if all functions ran successfully, false otherwise
*/
bool samba_module_init_fns_run(samba_module_init_fn *fns);
bool run_init_functions(init_module_fn *fns);

/**
* Load the initialization functions from DSO files for a specific subsystem.
*
* Will return an array of function pointers to initialization functions
*/
samba_module_init_fn *samba_module_init_fns_for_subsystem(TALLOC_CTX *mem_ctx, const char *subsystem);
init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem);

int smb_load_modules(const char **modules);
NTSTATUS smb_probe_module(const char *subsystem, const char *module);

#endif /* _SAMBA_MODULES_H */
16 changes: 3 additions & 13 deletions lib/util/wscript_build
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@ bld.SAMBA_LIBRARY('samba-util',
pc_files='samba-util.pc'
)

bld.SAMBA_LIBRARY('samba-module',
source='samba_module.c',
deps='errors samba-util samba-internal-module',
local_include=False,
public_headers='samba_module.h',
vnum='0.0.1',
abi_directory='ABI',
abi_match='samba_module_*',
pc_files='samba-module.pc')

bld.SAMBA_LIBRARY('samba-internal-module',
source='internal_module.c',
bld.SAMBA_LIBRARY('samba-modules',
source='modules.c',
deps='errors samba-util',
local_include=False,
private_library=True)
private_library=True)

bld.SAMBA_LIBRARY('asn1util',
source='asn1.c',
Expand Down
2 changes: 1 addition & 1 deletion source3/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \
../lib/util/charset/charset_macosxfs.o intl/lang_tdb.o \
lib/conn_tdb.o lib/adt_tree.o lib/gencache.o \
lib/sessionid_tdb.o \
../lib/util/internal_module.o ../lib/util/samba_module.o lib/events.o @LIBTEVENT_OBJ0@ \
../lib/util/modules.o lib/events.o @LIBTEVENT_OBJ0@ \
@CCAN_OBJ@ \
lib/server_contexts.o \
lib/server_prefork.o \
Expand Down
2 changes: 1 addition & 1 deletion source3/exports/modules-darwin.syms
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_samba_module_init
_samba_init_module
2 changes: 1 addition & 1 deletion source3/include/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ typedef char fstring[FSTRING_LEN];
#include "smb.h"
#include "../lib/util/byteorder.h"

#include "../lib/util/internal_module.h"
#include "../lib/util/samba_modules.h"
#include "../lib/util/talloc_stack.h"
#include "../lib/util/smb_threads.h"
#include "../lib/util/smb_threads_internal.h"
Expand Down
2 changes: 1 addition & 1 deletion source3/m4/aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ AC_DEFUN(SMB_MODULE,
fi
if test x"$DEST" = xSHARED; then
AC_DEFINE([$1][_init], [samba_module_init], [Whether to build $1 as shared module])
AC_DEFINE([$1][_init], [samba_init_module], [Whether to build $1 as shared module])
$4_MODULES="$$4_MODULES $3"
AC_MSG_RESULT([shared])
[$6]
Expand Down
Loading

0 comments on commit 05bc4de

Please sign in to comment.