diff --git a/.bzrignore b/.bzrignore
index 6f04c266038..30535bffb6f 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -1,3 +1,4 @@
+source/lib/gencache/gencache.h
 source/lib/ldb/bin
 *.pc
 autom4te.cache
diff --git a/source4/auth/auth.c b/source4/auth/auth.c
index f79e2f7bbde..9100891d524 100644
--- a/source4/auth/auth.c
+++ b/source4/auth/auth.c
@@ -51,7 +51,7 @@ BOOL auth_challenge_may_be_modified(struct auth_context *auth_ctx)
  Try to get a challenge out of the various authentication modules.
  Returns a const char of length 8 bytes.
 ****************************************************************************/
-NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, const uint8_t **_chal)
+_PUBLIC_ NTSTATUS auth_get_challenge(struct auth_context *auth_ctx, const uint8_t **_chal)
 {
 	NTSTATUS nt_status;
 	struct auth_method_context *method;
diff --git a/source4/auth/config.mk b/source4/auth/config.mk
index d692115321d..968072b918c 100644
--- a/source4/auth/config.mk
+++ b/source4/auth/config.mk
@@ -65,7 +65,9 @@ OBJ_FILES = pam_errors.o
 
 #######################
 # Start SUBSYSTEM auth
-[SUBSYSTEM::auth]
+[LIBRARY::auth]
+VERSION = 0.0.1
+SO_VERSION = 0
 PUBLIC_HEADERS = auth.h
 PUBLIC_PROTO_HEADER = auth_proto.h
 OBJ_FILES = \
diff --git a/source4/auth/gensec/config.mk b/source4/auth/gensec/config.mk
index cb8b2edc85e..84947785db3 100644
--- a/source4/auth/gensec/config.mk
+++ b/source4/auth/gensec/config.mk
@@ -48,7 +48,7 @@ PUBLIC_DEPENDENCIES = SASL auth
 SUBSYSTEM = gensec
 INIT_FUNCTION = gensec_spnego_init
 PRIVATE_PROTO_HEADER = spnego_proto.h
-PRIVATE_DEPENDENCIES = ASN1_UTIL
+PRIVATE_DEPENDENCIES = ASN1_UTIL GENSEC_SOCKET
 OBJ_FILES = spnego.o \
 			spnego_parse.o
 # End MODULE gensec_spnego
@@ -82,7 +82,7 @@ OBJ_FILES = \
 [SUBSYSTEM::GENSEC_SOCKET]
 OBJ_FILES = \
 		socket.o
-PUBLIC_DEPENDENCIES = samba-socket
+PUBLIC_DEPENDENCIES = samba-socket LIBPACKET
 #PUBLIC_DEPENDENCIES =  gensec
 #
 # End SUBSYSTEM GENSEC_SOCKET
diff --git a/source4/auth/gensec/socket.c b/source4/auth/gensec/socket.c
index cf7b196f9d7..11db252e172 100644
--- a/source4/auth/gensec/socket.c
+++ b/source4/auth/gensec/socket.c
@@ -60,7 +60,7 @@ static NTSTATUS gensec_socket_init_fn(struct socket_context *sock)
 
 /* These functions are for use here only (public because SPNEGO must
  * use them for recursion) */
-NTSTATUS gensec_wrap_packets(struct gensec_security *gensec_security, 
+_PUBLIC_ NTSTATUS gensec_wrap_packets(struct gensec_security *gensec_security, 
 			     TALLOC_CTX *mem_ctx, 
 			     const DATA_BLOB *in, 
 			     DATA_BLOB *out,
diff --git a/source4/build/m4/check_ld.m4 b/source4/build/m4/check_ld.m4
index 515c720c069..e44c29d0e33 100644
--- a/source4/build/m4/check_ld.m4
+++ b/source4/build/m4/check_ld.m4
@@ -157,6 +157,7 @@ AC_MSG_RESULT([$SHLD])
 AC_MSG_CHECKING([SHLD_FLAGS])
 AC_MSG_RESULT([$SHLD_FLAGS])
 
+AC_DEFINE_UNQUOTED(SHLIBEXT, "$SHLIBEXT", [Shared library extension])
 AC_MSG_CHECKING([SHLIBEXT])
 AC_MSG_RESULT([$SHLIBEXT])
 AC_MSG_CHECKING([SONAMEFLAG])
diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm
index 30ebf962e08..259256b9b5c 100644
--- a/source4/build/smb_build/makefile.pm
+++ b/source4/build/smb_build/makefile.pm
@@ -123,7 +123,7 @@ SHELL=$self->{config}->{SHELL}
 PERL=$self->{config}->{PERL}
 
 CPP=$self->{config}->{CPP}
-CPPFLAGS=$builddir_headers-I\$(srcdir)/include -I\$(srcdir) -I\$(srcdir)/lib -D_SAMBA_BUILD_=4 -DHAVE_CONFIG_H $self->{config}->{CPPFLAGS}
+CPPFLAGS=$builddir_headers-I\$(srcdir)/include -I\$(srcdir) -I\$(srcdir)/lib -I\$(srcdir)/lib/replace -D_SAMBA_BUILD_=4 -DHAVE_CONFIG_H $self->{config}->{CPPFLAGS}
 
 CC=$self->{config}->{CC}
 CFLAGS=$self->{config}->{CFLAGS} \$(CPPFLAGS)
diff --git a/source4/configure.ac b/source4/configure.ac
index 548db4d7202..be9f627d69e 100644
--- a/source4/configure.ac
+++ b/source4/configure.ac
@@ -32,7 +32,6 @@ m4_include(lib/ldb/libldb.m4)
 m4_include(lib/tls/config.m4)
 m4_include(lib/events/config.m4)
 
-dnl disabled until we support external heimdal again
 dnl m4_include(auth/kerberos/config.m4)
 
 m4_include(auth/gensec/config.m4)
@@ -51,6 +50,15 @@ m4_include(lib/appweb/config.m4)
 m4_include(nsswitch/config.m4)
 m4_include(libcli/config.m4)
 
+dnl disabled until we support external heimdal again
+AC_ARG_ENABLE(dso,
+[  --enable-dso 		Enable building internal libraries as DSO's (experimental)],
+[ if test x$enable_dso != xno; then
+ 	BLDSHARED=true
+  fi], 
+[BLDSHARED=false])
+
+
 #################################################
 # add *_CFLAGS only for the real build
 CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
diff --git a/source4/dsdb/samdb/ldb_modules/config.mk b/source4/dsdb/samdb/ldb_modules/config.mk
index 725d98ac7e7..bf286b4828d 100644
--- a/source4/dsdb/samdb/ldb_modules/config.mk
+++ b/source4/dsdb/samdb/ldb_modules/config.mk
@@ -28,7 +28,7 @@ OBJ_FILES = \
 [MODULE::ldb_samba3sam]
 SUBSYSTEM = ldb
 INIT_FUNCTION = ldb_samba3sam_module_init
-PRIVATE_DEPENDENCIES = LIBTALLOC
+PRIVATE_DEPENDENCIES = LIBTALLOC ldb_map
 OBJ_FILES = \
 		samba3sam.o
 #
diff --git a/source4/dynconfig.c b/source4/dynconfig.c
index 34a8cbec992..4517a4f551b 100644
--- a/source4/dynconfig.c
+++ b/source4/dynconfig.c
@@ -61,9 +61,6 @@ _PUBLIC_ const char *dyn_DATADIR = DATADIR;
 
 _PUBLIC_ const char *dyn_MODULESDIR = MODULESDIR;
 
-/** Shared library extension */
-_PUBLIC_ const char *dyn_SHLIBEXT = SHLIBEXT;
-
 /**
  * @brief Directory holding lock files.
  *
diff --git a/source4/dynconfig.h b/source4/dynconfig.h
index c0854b99512..d3badc73e59 100644
--- a/source4/dynconfig.h
+++ b/source4/dynconfig.h
@@ -32,7 +32,6 @@ extern const char *dyn_LOGFILEBASE;
 extern const char *dyn_LMHOSTSFILE;
 extern const char *dyn_DATADIR;
 extern const char *dyn_MODULESDIR;
-extern const char *dyn_SHLIBEXT;
 extern const char *dyn_LOCKDIR; 
 extern const char *dyn_PIDDIR;
 extern const char *dyn_PRIVATE_DIR;
diff --git a/source4/dynconfig.mk b/source4/dynconfig.mk
index c17e2638ada..2172ca31d81 100644
--- a/source4/dynconfig.mk
+++ b/source4/dynconfig.mk
@@ -6,7 +6,7 @@ OBJ_FILES = dynconfig.o
 PATH_FLAGS = -DCONFIGFILE=\"$(CONFIGFILE)\" \
 	 -DBINDIR=\"$(BINDIR)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" \
 	 -DLOCKDIR=\"$(LOCKDIR)\" -DPIDDIR=\"$(PIDDIR)\" -DDATADIR=\"$(DATADIR)\" \
-	 -DLOGFILEBASE=\"$(LOGFILEBASE)\" -DSHLIBEXT=\"$(SHLIBEXT)\" \
+	 -DLOGFILEBASE=\"$(LOGFILEBASE)\" \
 	 -DCONFIGDIR=\"$(CONFIGDIR)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\" \
 	 -DSWATDIR=\"$(SWATDIR)\" -DSERVICESDIR=\"$(SERVICESDIR)\" \
 	 -DPRIVATE_DIR=\"$(PRIVATEDIR)\" \
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index ada3d999309..f1138afd81f 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -207,17 +207,26 @@ int ldb_try_load_dso(struct ldb_context *ldb, const char *name)
 	char *path;
 	void *handle;
 	int (*init_fn) (void);
+	char *modulesdir;
 
 #ifdef HAVE_DLOPEN
+	if (getenv("LD_LDB_MODULE_PATH") != NULL) {
+		modulesdir = talloc_strdup(ldb, getenv("LD_LDB_MODULE_PATH"));
+	} else {
 #ifdef _SAMBA_BUILD_
-	path = talloc_asprintf(ldb, "%s/ldb/%s.%s", dyn_MODULESDIR, name, dyn_SHLIBEXT);
+		modulesdir = talloc_asprintf(ldb, "%s/ldb", dyn_MODULESDIR);
 #else
-	path = talloc_asprintf(ldb, "%s/%s.%s", MODULESDIR, name, SHLIBEXT);
+		modulesdir = talloc_strdup(ldb, MODULESDIR);
 #endif
+	}
+
+	path = talloc_asprintf(ldb, "%s/%s.%s", modulesdir, name, SHLIBEXT);
+
+	talloc_free(modulesdir);
 
 	ldb_debug(ldb, LDB_DEBUG_TRACE, "trying to load %s from %s\n", name, path);
 
-	handle = dlopen(path, 0);
+	handle = dlopen(path, RTLD_NOW);
 	if (handle == NULL) {
 		ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror());
 		return -1;
diff --git a/source4/lib/ldb/modules/ldb_map.c b/source4/lib/ldb/modules/ldb_map.c
index 1cdeeeb2934..9146f2d863b 100644
--- a/source4/lib/ldb/modules/ldb_map.c
+++ b/source4/lib/ldb/modules/ldb_map.c
@@ -1296,13 +1296,13 @@ static int map_init_maps(struct ldb_module *module, struct ldb_map_context *data
 }
 
 /* Copy the list of provided module operations. */
-struct ldb_module_ops ldb_map_get_ops(void)
+_PUBLIC_ struct ldb_module_ops ldb_map_get_ops(void)
 {
 	return map_ops;
 }
 
 /* Initialize global private data. */
-int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, 
+_PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, 
 		 const struct ldb_map_objectclass *ocls,
 		 const char * const *wildcard_attributes,
 		 const char *name)
diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c
index 7bb4d0c79a1..2c2cd0dd662 100644
--- a/source4/libcli/ldap/ldap_client.c
+++ b/source4/libcli/ldap/ldap_client.c
@@ -432,7 +432,7 @@ static void ldap_connect_recv_unix_conn(struct composite_context *ctx)
 	ldap_connect_got_sock(state->ctx, conn);
 }
 
-NTSTATUS ldap_connect_recv(struct composite_context *ctx)
+_PUBLIC_ NTSTATUS ldap_connect_recv(struct composite_context *ctx)
 {
 	NTSTATUS status = composite_wait(ctx);
 	talloc_free(ctx);
diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk
index cf58e40c266..eeb4506219e 100644
--- a/source4/librpc/config.mk
+++ b/source4/librpc/config.mk
@@ -665,7 +665,7 @@ PUBLIC_DEPENDENCIES = dcerpc NDR_DFS EJSRPC
 INIT_FUNCTION = ejs_init_drsuapi
 OBJ_FILES = gen_ndr/ndr_drsuapi_ejs.o
 SUBSYSTEM = smbcalls
-PUBLIC_DEPENDENCIES = dcerpc NDR_DRSUAPI EJSRPC RPC_EJS_MISC
+PUBLIC_DEPENDENCIES = dcerpc NDR_DRSUAPI EJSRPC RPC_EJS_MISC RPC_EJS_SAMR
 
 [MODULE::RPC_EJS_SPOOLSS]
 INIT_FUNCTION = ejs_init_spoolss
diff --git a/source4/main.mk b/source4/main.mk
index 378152c40f0..5b9cda6c938 100644
--- a/source4/main.mk
+++ b/source4/main.mk
@@ -408,4 +408,3 @@ configure:
 clean::
 	@echo Removing dependency files
 	@find . -name \*.d -o -name \*.hd | xargs rm -f
-
diff --git a/source4/ntptr/config.mk b/source4/ntptr/config.mk
index 84e6aaffe25..a80002662e5 100644
--- a/source4/ntptr/config.mk
+++ b/source4/ntptr/config.mk
@@ -14,7 +14,7 @@ PUBLIC_DEPENDENCIES = \
 
 ################################################
 # Start SUBSYSTEM ntptr
-[SUBSYSTEM::ntptr]
+[LIBRARY::ntptr]
 PRIVATE_PROTO_HEADER = ntptr_proto.h
 OBJ_FILES = \
 		ntptr_base.o \
diff --git a/source4/ntvfs/posix/config.mk b/source4/ntvfs/posix/config.mk
index ed182d9a987..5fd6e58d2e1 100644
--- a/source4/ntvfs/posix/config.mk
+++ b/source4/ntvfs/posix/config.mk
@@ -2,9 +2,10 @@
 # Start MODULE pvfs_acl_xattr
 [MODULE::pvfs_acl_xattr]
 INIT_FUNCTION = pvfs_acl_xattr_init 
-SUBSYSTEM = ntvfs
+SUBSYSTEM = ntvfs_posix
 OBJ_FILES = \
 		pvfs_acl_xattr.o
+PRIVATE_DEPENDENCIES = NDR_XATTR
 # End MODULE pvfs_acl_xattr
 ################################################
 
@@ -52,7 +53,7 @@ OBJ_FILES = \
 		pvfs_notify.o \
 		xattr_system.o \
 		xattr_tdb.o
-PRIVATE_DEPENDENCIES = pvfs_acl_xattr pvfs_acl_nfs4
+#PRIVATE_DEPENDENCIES = pvfs_acl_xattr pvfs_acl_nfs4
 PUBLIC_DEPENDENCIES = NDR_XATTR WRAP_XATTR BLKID ntvfs_common MESSAGING
 # End MODULE ntvfs_posix
 ################################################
diff --git a/source4/ntvfs/posix/pvfs_xattr.c b/source4/ntvfs/posix/pvfs_xattr.c
index ab2f3fef6c5..fcc2d351c97 100644
--- a/source4/ntvfs/posix/pvfs_xattr.c
+++ b/source4/ntvfs/posix/pvfs_xattr.c
@@ -101,7 +101,7 @@ NTSTATUS pvfs_xattr_unlink_hook(struct pvfs_state *pvfs, const char *fname)
 /*
   load a NDR structure from a xattr
 */
-NTSTATUS pvfs_xattr_ndr_load(struct pvfs_state *pvfs,
+_PUBLIC_ NTSTATUS pvfs_xattr_ndr_load(struct pvfs_state *pvfs,
 			     TALLOC_CTX *mem_ctx,
 			     const char *fname, int fd, const char *attr_name,
 			     void *p, void *pull_fn)
@@ -126,7 +126,7 @@ NTSTATUS pvfs_xattr_ndr_load(struct pvfs_state *pvfs,
 /*
   save a NDR structure into a xattr
 */
-NTSTATUS pvfs_xattr_ndr_save(struct pvfs_state *pvfs,
+_PUBLIC_ NTSTATUS pvfs_xattr_ndr_save(struct pvfs_state *pvfs,
 			     const char *fname, int fd, const char *attr_name, 
 			     void *p, void *push_fn)
 {
diff --git a/source4/param/util.c b/source4/param/util.c
index af97903277f..2453094798b 100644
--- a/source4/param/util.c
+++ b/source4/param/util.c
@@ -169,7 +169,10 @@ _PUBLIC_ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name)
 
 static char *modules_path(TALLOC_CTX* mem_ctx, const char *name)
 {
-	return talloc_asprintf(mem_ctx, "%s/%s", lp_modulesdir(), name);
+	const char *env_moduledir = getenv("LD_SAMBA_MODULE_PATH");
+	return talloc_asprintf(mem_ctx, "%s/%s", 
+						   env_moduledir?env_moduledir:lp_modulesdir(), 
+						   name);
 }
 
 /**
diff --git a/source4/rpc_server/config.mk b/source4/rpc_server/config.mk
index 23245218a42..d1c2bf8d922 100644
--- a/source4/rpc_server/config.mk
+++ b/source4/rpc_server/config.mk
@@ -141,7 +141,8 @@ PUBLIC_DEPENDENCIES = \
 		SAMDB \
 		DCERPC_COMMON \
 		NDR_LSA \
-		LIBCLI_AUTH
+		LIBCLI_AUTH \
+		NDR_DSSETUP
 # End MODULE dcerpc_lsa
 ################################################
 
diff --git a/source4/script/tests/selftest.sh b/source4/script/tests/selftest.sh
index 48db3eccf2b..6d997669959 100755
--- a/source4/script/tests/selftest.sh
+++ b/source4/script/tests/selftest.sh
@@ -38,6 +38,12 @@ else
 fi
 export TLS_ENABLED
 
+LD_LDB_MODULE_PATH=$OLD_PWD/bin/modules/ldb
+export LD_LDB_MODULE_PATH
+
+LD_SAMBA_MODULE_PATH=$OLD_PWD/bin/modules
+export LD_SAMBA_MODULE_PATH
+
 LD_LIBRARY_PATH=$OLD_PWD/bin:$LD_LIBRARY_PATH
 export LD_LIBRARY_PATH
 
diff --git a/source4/smbd/config.mk b/source4/smbd/config.mk
index 569a1f0d380..918288f0fe9 100644
--- a/source4/smbd/config.mk
+++ b/source4/smbd/config.mk
@@ -12,7 +12,7 @@ PUBLIC_DEPENDENCIES = \
 
 #######################
 # Start SUBSERVICE
-[SUBSYSTEM::service]
+[LIBRARY::service]
 PRIVATE_PROTO_HEADER = service_proto.h
 OBJ_FILES = \
 		service.o \
diff --git a/source4/torture/auth/ntlmssp.c b/source4/torture/auth/ntlmssp.c
index ff111faf85e..b6d1ccee625 100644
--- a/source4/torture/auth/ntlmssp.c
+++ b/source4/torture/auth/ntlmssp.c
@@ -118,7 +118,7 @@ static bool torture_ntlmssp_self_check(struct torture_context *tctx)
 	return true;
 }
 
-struct torture_suite *torture_ntlmssp(TALLOC_CTX *mem_ctx)
+_PUBLIC_ struct torture_suite *torture_ntlmssp(TALLOC_CTX *mem_ctx)
 {
 	struct torture_suite *suite = torture_suite_create(mem_ctx, 
 													   "NTLMSSP");
diff --git a/source4/torture/auth/pac.c b/source4/torture/auth/pac.c
index fffec86c0d1..629b573ec3a 100644
--- a/source4/torture/auth/pac.c
+++ b/source4/torture/auth/pac.c
@@ -626,7 +626,7 @@ static bool torture_pac_saved_check(struct torture_context *tctx)
 	return true;
 }
 
-struct torture_suite *torture_pac(TALLOC_CTX *mem_ctx)
+_PUBLIC_ struct torture_suite *torture_pac(TALLOC_CTX *mem_ctx)
 {
 	struct torture_suite *suite = torture_suite_create(mem_ctx, "PAC");
 
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index 1edaa694475..630c557d28a 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -14,6 +14,7 @@ PUBLIC_DEPENDENCIES = \
 
 [SUBSYSTEM::TORTURE_UTIL]
 OBJ_FILES = util.o util_smb.o
+PRIVATE_DEPENDENCIES = LIBCLI_RAW
 PUBLIC_PROTO_HEADER = util.h
 PUBLIC_DEPENDENCIES = POPT_CREDENTIALS
 
@@ -50,7 +51,8 @@ OBJ_FILES = \
 		basic/properties.o 
 PUBLIC_DEPENDENCIES = \
 		LIBCLI_SMB POPT_CREDENTIALS \
-		TORTURE_UTIL
+		TORTURE_UTIL LIBCLI_RAW
+PRIVATE_DEPENDENCIES = TORTURE_RAW
 # End SUBSYSTEM TORTURE_BASIC
 #################################
 
@@ -91,6 +93,7 @@ OBJ_FILES = \
 PUBLIC_DEPENDENCIES = \
 		LIBCLI_SMB LIBCLI_LSA LIBCLI_SMB_COMPOSITE \
 		POPT_CREDENTIALS
+PRIVATE_DEPENDENCIES = TORTURE_UTIL
 # End SUBSYSTEM TORTURE_RAW
 #################################
 
@@ -152,6 +155,7 @@ PUBLIC_DEPENDENCIES = \
 		RPC_NDR_SRVSVC RPC_NDR_WKSSVC RPC_NDR_ROT RPC_NDR_DSSETUP \
 		RPC_NDR_REMACT RPC_NDR_OXIDRESOLVER WB_HELPER LIBSAMBA-NET \
 		LIBCLI_AUTH POPT_CREDENTIALS
+PRIVATE_DEPENDENCIES = TORTURE_LDAP TORTURE_UTIL TORTURE_RAP
 
 #################################
 # Start SUBSYSTEM TORTURE_RAP
@@ -162,6 +166,7 @@ PRIVATE_PROTO_HEADER = \
 		rap/proto.h
 OBJ_FILES = \
 		rap/rap.o
+PRIVATE_DEPENDENCIES = TORTURE_UTIL
 PUBLIC_DEPENDENCIES = \
 		LIBCLI_SMB
 # End SUBSYSTEM TORTURE_RAP
@@ -189,6 +194,7 @@ include local/config.mk
 [MODULE::TORTURE_NBENCH]
 SUBSYSTEM = torture
 INIT_FUNCTION = torture_nbench_init
+PRIVATE_DEPENDENCIES = TORTURE_UTIL 
 PRIVATE_PROTO_HEADER = \
 		nbench/proto.h
 OBJ_FILES = \
@@ -232,6 +238,7 @@ OBJ_FILES = \
 		nbt/nbt.o
 PUBLIC_DEPENDENCIES = \
 		LIBCLI_SMB LIBCLI_NBT LIBCLI_DGRAM LIBCLI_WREPL
+PRIVATE_DEPENDENCIES = torture_rpc
 # End SUBSYSTEM TORTURE_NBT
 #################################
 
@@ -255,6 +262,7 @@ OBJ_FILES = \
 PUBLIC_DEPENDENCIES = \
 		LIBSAMBA-NET \
 		POPT_CREDENTIALS
+PRIVATE_DEPENDENCIES = torture_rpc
 # End SUBSYSTEM TORTURE_NET
 #################################
 
diff --git a/source4/torture/ldap/common.c b/source4/torture/ldap/common.c
index 5b28e825f2b..071f0faa2da 100644
--- a/source4/torture/ldap/common.c
+++ b/source4/torture/ldap/common.c
@@ -39,7 +39,7 @@ NTSTATUS torture_ldap_bind(struct ldap_connection *conn, const char *userdn, con
 	return status;
 }
 
-NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn, 
+_PUBLIC_ NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn, 
 				struct cli_credentials *creds)
 {
         NTSTATUS status;
@@ -54,7 +54,7 @@ NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn,
 }
 
 /* open a ldap connection to a server */
-NTSTATUS torture_ldap_connection(TALLOC_CTX *mem_ctx, struct ldap_connection **conn, 
+_PUBLIC_ NTSTATUS torture_ldap_connection(TALLOC_CTX *mem_ctx, struct ldap_connection **conn, 
 				const char *url)
 {
 	NTSTATUS status;
diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk
index 9917dcb128a..9e1fe32147a 100644
--- a/source4/torture/local/config.mk
+++ b/source4/torture/local/config.mk
@@ -38,7 +38,9 @@ PUBLIC_DEPENDENCIES = \
 		registry \
 		LIBCRYPTO \
 		POPT_CREDENTIALS \
-		TORTURE_UI
+		TORTURE_UI \
+		TORTURE_AUTH \
+		TORTURE_UTIL
 # End SUBSYSTEM TORTURE_LOCAL
 #################################
 
diff --git a/source4/torture/rap/rap.c b/source4/torture/rap/rap.c
index f05183a0336..682bfdb0eb0 100644
--- a/source4/torture/rap/rap.c
+++ b/source4/torture/rap/rap.c
@@ -419,7 +419,7 @@ static BOOL test_netserverenum(struct smbcli_tree *tree)
 	return True;
 }
 
-NTSTATUS smbcli_rap_netservergetinfo(struct smbcli_tree *tree,
+_PUBLIC_ NTSTATUS smbcli_rap_netservergetinfo(struct smbcli_tree *tree,
 				     TALLOC_CTX *mem_ctx,
 				     struct rap_WserverGetInfo *r)
 {
diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c
index 26b542c27af..56a49663286 100644
--- a/source4/torture/raw/search.c
+++ b/source4/torture/raw/search.c
@@ -43,7 +43,7 @@ static BOOL single_search_callback(void *private, union smb_search_data *file)
 /*
   do a single file (non-wildcard) search 
 */
-NTSTATUS torture_single_search(struct smbcli_state *cli, 
+_PUBLIC_ NTSTATUS torture_single_search(struct smbcli_state *cli, 
 			       TALLOC_CTX *mem_ctx,
 			       const char *pattern,
 			       enum smb_search_level level,
diff --git a/source4/torture/rpc/testjoin.c b/source4/torture/rpc/testjoin.c
index 16060851b25..83ecc4b4c99 100644
--- a/source4/torture/rpc/testjoin.c
+++ b/source4/torture/rpc/testjoin.c
@@ -280,7 +280,7 @@ failed:
 }
 
 
-struct test_join *torture_join_domain(const char *machine_name, 
+_PUBLIC_ struct test_join *torture_join_domain(const char *machine_name, 
 				      uint32_t acct_flags,
 				      struct cli_credentials **machine_credentials)
 {
@@ -462,7 +462,7 @@ NTSTATUS torture_leave_ads_domain(TALLOC_CTX *mem_ctx, struct libnet_JoinDomain
   leave the domain, deleting the machine acct
 */
 
-void torture_leave_domain(struct test_join *join)
+_PUBLIC_ void torture_leave_domain(struct test_join *join)
 {
 	struct samr_DeleteUser d;
 	NTSTATUS status;
@@ -491,7 +491,7 @@ void torture_leave_domain(struct test_join *join)
 /*
   return the dom sid for a test join
 */
-const struct dom_sid *torture_join_sid(struct test_join *join)
+_PUBLIC_ const struct dom_sid *torture_join_sid(struct test_join *join)
 {
 	return join->dom_sid;
 }
diff --git a/source4/torture/util_smb.c b/source4/torture/util_smb.c
index 0fee43f6023..9473ab018bc 100644
--- a/source4/torture/util_smb.c
+++ b/source4/torture/util_smb.c
@@ -462,7 +462,7 @@ NTSTATUS torture_check_ea(struct smbcli_state *cli,
 	return NT_STATUS_EA_CORRUPT_ERROR;
 }
 
-bool torture_open_connection_share(TALLOC_CTX *mem_ctx,
+_PUBLIC_ bool torture_open_connection_share(TALLOC_CTX *mem_ctx,
 				   struct smbcli_state **c, 
 				   const char *hostname, 
 				   const char *sharename,
diff --git a/source4/winbind/config.mk b/source4/winbind/config.mk
index 3ecf489a93d..6b63e090ee6 100644
--- a/source4/winbind/config.mk
+++ b/source4/winbind/config.mk
@@ -31,7 +31,8 @@ PUBLIC_DEPENDENCIES = \
 		process_model \
 		RPC_NDR_LSA \
 		RPC_NDR_SAMR \
-		PAM_ERRORS
+		PAM_ERRORS \
+		LIBCLI_LDAP
 # End SUBSYSTEM WINBIND
 #######################