[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Fri May 14 07:26:15 MDT 2010


The branch, master has been updated
       via  b5dc394... s4:gensec expose gensec_set_target_principal for use outside GENSEC
       via  8da50c8... s4:winbindd Rework some winbind structures to make s3compat easier
       via  ad197f6... s4:process_model Fix process_standard and process_onefork not to use multiple event contexts
       via  6f859f5... s4:process_modals Add another process modal - 'onefork'
       via  bb2f7e3... s4:credentials Allow setting of an empty Kerberos CCACHE
       via  81407b1... s4:ntvfs Prepare for a possible future sharing of notify.idl
       via  79bd6a6... waf: Make waf handle IDL files from Samba3
       via  9de745f... s3compat: use right variable for STATEDIR
       via  3043c19... s4-dynconfig: make dynconfig more compatible with s3
       via  ba4842a... Revert "s4: remove unused references to swat"
      from  3b8d9cd... Revert "wafsamba: use -D_XOPEN_SOURCE=700 for the build"

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b5dc39496272cbccdd45152f349362c2b779c326
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Thu May 13 07:59:41 2010 +1000

    s4:gensec expose gensec_set_target_principal for use outside GENSEC
    
    This allows for the rare case where the caller knows the target
    principal.  The check for lp_client_use_spnego_principal() is moved to
    the spengo code to make this work.
    
    Andrew Bartlett

commit 8da50c8da1527bafbb0ff4e86cc12fb54dd2b4b7
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri May 14 17:31:33 2010 +1000

    s4:winbindd Rework some winbind structures to make s3compat easier
    
    By making the winbindd_request and winbindd_response structures
    pointers, we can more easily integrate with the winbindd from
    source3/winbindd
    
    Andrew Bartlett

commit ad197f6f15054e398c0bf4f27388a86a384c09ba
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri May 14 21:51:48 2010 +1000

    s4:process_model Fix process_standard and process_onefork not to use
    multiple event contexts
    
    It is NEVER valid to free an event context that anybody else may have
    a reference to, and never normally valid to have two 'live' at once.
    We must instead call tevent_re_initialise() to wipe clean an existing
    pointer.
    
    Andrew Bartlett

commit 6f859f58afff10f708bf06d55d1cfab575875627
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Mon May 10 13:47:42 2010 +1000

    s4:process_modals Add another process modal - 'onefork'
    
    This will fork off exactly one child to handle some task, ensuring
    that if it dies or changes global state, that this does not change
    everything.
    
    Andrew Bartlett

commit bb2f7e3aee7e9b8437d7313800be0c2370da5ca1
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed May 12 12:34:15 2010 +1000

    s4:credentials Allow setting of an empty Kerberos CCACHE
    
    This allows us to tell the credentials code where we want the
    credentials put.
    
    Andrew Bartlett

commit 81407b1bffed137c02790d908893bac7b99ce956
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed May 5 12:47:07 2010 +1000

    s4:ntvfs Prepare for a possible future sharing of notify.idl
    
    I would love for notify.idl to be shared between Samba4 and Samba3
    some day, and this seems to be the point at which the structure is
    initialised.
    
    Andrew Bartlett

commit 79bd6a6764079e982fb7e1ba1c24a9037e126175
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Wed May 5 12:40:20 2010 +1000

    waf: Make waf handle IDL files from Samba3
    
    For s3compat, we need to handle IDL files not in the current directory
    (so the incoming file names have a directory prefix - so we must use
    os.path.basename()).
    
    We also need to be able to disable the addition of some IDL files into
    the tables.c/tables.h - some of the Samba3 IDL files are in conflict
    with Samba4.
    
    Andrew Bartlett

commit 9de745fd5327901846c9b8c6533b7e8156d71a30
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Apr 25 21:25:01 2010 +1000

    s3compat: use right variable for STATEDIR
    
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>

commit 3043c1924d55615e6fc50f7643edc9143814dd8a
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sun Apr 25 18:08:00 2010 +1000

    s4-dynconfig: make dynconfig more compatible with s3

commit ba4842a88076133b012cbcef632edb0fb822a56d
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Apr 30 18:20:54 2010 +1000

    Revert "s4: remove unused references to swat"
    
    This reverts most of commit 1765732f82719a4bc925f21ef4999bd19a8d1f6c.
    
    The s3compat build needs the SWAT location to be compatible with
    Samba3.

-----------------------------------------------------------------------

Summary of changes:
 buildtools/wafsamba/samba_pidl.py           |   12 +-
 source4/Makefile.in                         |    1 +
 source4/auth/credentials/credentials_krb5.c |   30 +--
 source4/auth/gensec/gensec.c                |    2 +-
 source4/auth/gensec/gensec.h                |    2 +
 source4/auth/gensec/gensec_krb5.c           |    2 +-
 source4/auth/gensec/spnego.c                |    5 +-
 source4/dynconfig/config.mk                 |    1 +
 source4/dynconfig/dynconfig.c               |  101 ++++-----
 source4/dynconfig/dynconfig.h               |    2 +
 source4/dynconfig/wscript                   |    7 +
 source4/ntvfs/posix/pvfs_notify.c           |    4 +
 source4/smbd/process_model.c                |    1 +
 source4/smbd/process_onefork.c              |  161 ++++++++++++++
 source4/smbd/process_standard.c             |   48 +---
 source4/smbd/server.c                       |    1 +
 source4/smbd/wscript_build                  |    7 +
 source4/winbind/wb_samba3_cmd.c             |  320 +++++++++++++-------------
 source4/winbind/wb_samba3_protocol.c        |   39 ++--
 source4/winbind/wb_server.h                 |    4 +-
 20 files changed, 461 insertions(+), 289 deletions(-)
 create mode 100644 source4/smbd/process_onefork.c


Changeset truncated at 500 lines:

diff --git a/buildtools/wafsamba/samba_pidl.py b/buildtools/wafsamba/samba_pidl.py
index bd8324f..b932f59 100644
--- a/buildtools/wafsamba/samba_pidl.py
+++ b/buildtools/wafsamba/samba_pidl.py
@@ -7,11 +7,13 @@ from samba_utils import *
 def SAMBA_PIDL(bld, pname, source,
                options='',
                output_dir='.',
-               symlink=False):
+               symlink=False,
+               generate_tables=True):
     '''Build a IDL file using pidl.
        This will produce up to 13 output files depending on the options used'''
 
     bname = source[0:-4]; # strip off the .idl suffix
+    bname = os.path.basename(bname)
     name = "%s_%s" % (pname, bname.upper())
 
     if not SET_TARGET_TYPE(bld, name, 'PIDL'):
@@ -86,7 +88,7 @@ def SAMBA_PIDL(bld, pname, source,
     real_outputdir = os.path.realpath(outdir)
     t.env.OUTPUTDIR = os_path_relpath(real_outputdir, os.path.dirname(bld.env.BUILD_DIRECTORY))
 
-    if table_header_idx is not None:
+    if generate_tables and table_header_idx is not None:
         pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS')
         pidl_headers[name] = [bld.path.find_or_declare(out_files[table_header_idx])]
 
@@ -97,10 +99,11 @@ Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
 def SAMBA_PIDL_LIST(bld, name, source,
                     options='',
                     output_dir='.',
-                    symlink=False):
+                    symlink=False,
+                    generate_tables=True):
     '''A wrapper for building a set of IDL files'''
     for p in TO_LIST(source):
-        bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, symlink=symlink)
+        bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, symlink=symlink, generate_tables=generate_tables)
 Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
 
 
@@ -116,6 +119,7 @@ def collect(self):
         self.bld.ASSERT(y is not None, 'Failed to find PIDL header %s' % name)
         y.post()
         for node in hd:
+            self.bld.ASSERT(node is not None, 'Got None as build node generating PIDL table for %s' % name)
             self.source += " " + node.relpath_gen(self.path)
 
 
diff --git a/source4/Makefile.in b/source4/Makefile.in
index 45f2f16..40ea286 100644
--- a/source4/Makefile.in
+++ b/source4/Makefile.in
@@ -11,6 +11,7 @@ include mkconfig.mk
 pidldir := $(srcdir)/../pidl
 
 basedir = $(prefix)
+swatdir = $(datadir)/swat
 setupdir = $(datadir)/setup
 ncalrpcdir = $(localstatedir)/ncalrpc
 shliboutputdir = $(builddir)/bin/shared
diff --git a/source4/auth/credentials/credentials_krb5.c b/source4/auth/credentials/credentials_krb5.c
index 12bf610..f4ee264 100644
--- a/source4/auth/credentials/credentials_krb5.c
+++ b/source4/auth/credentials/credentials_krb5.c
@@ -182,28 +182,22 @@ _PUBLIC_ int cli_credentials_set_ccache(struct cli_credentials *cred,
 
 	ret = krb5_cc_get_principal(ccc->smb_krb5_context->krb5_context, ccc->ccache, &princ);
 
-	if (ret) {
-		(*error_string) = talloc_asprintf(cred, "failed to get principal from default ccache: %s\n",
-						  smb_get_krb5_error_message(ccc->smb_krb5_context->krb5_context,
-									     ret, ccc));
-		talloc_free(ccc);
-		return ret;
-	}
+	if (ret == 0) {
+		krb5_free_principal(ccc->smb_krb5_context->krb5_context, princ);
+		ret = cli_credentials_set_from_ccache(cred, ccc, obtained, error_string);
 
-	krb5_free_principal(ccc->smb_krb5_context->krb5_context, princ);
+		if (ret) {
+			(*error_string) = error_message(ret);
+			return ret;
+		}
 
-	ret = cli_credentials_set_from_ccache(cred, ccc, obtained, error_string);
+		cred->ccache = ccc;
+		cred->ccache_obtained = obtained;
+		talloc_steal(cred, ccc);
 
-	if (ret) {
-		(*error_string) = error_message(ret);
-		return ret;
+		cli_credentials_invalidate_client_gss_creds(cred, cred->ccache_obtained);
+		return 0;
 	}
-
-	cred->ccache = ccc;
-	cred->ccache_obtained = obtained;
-	talloc_steal(cred, ccc);
-
-	cli_credentials_invalidate_client_gss_creds(cred, cred->ccache_obtained);
 	return 0;
 }
 
diff --git a/source4/auth/gensec/gensec.c b/source4/auth/gensec/gensec.c
index b532c15..c19d5ff 100644
--- a/source4/auth/gensec/gensec.c
+++ b/source4/auth/gensec/gensec.c
@@ -1302,7 +1302,7 @@ _PUBLIC_ const struct tsocket_address *gensec_get_remote_address(struct gensec_s
  *
  */
 
-NTSTATUS gensec_set_target_principal(struct gensec_security *gensec_security, const char *principal) 
+_PUBLIC_ NTSTATUS gensec_set_target_principal(struct gensec_security *gensec_security, const char *principal)
 {
 	gensec_security->target.principal = talloc_strdup(gensec_security, principal);
 	if (!gensec_security->target.principal) {
diff --git a/source4/auth/gensec/gensec.h b/source4/auth/gensec/gensec.h
index 47adf03..45e24f1 100644
--- a/source4/auth/gensec/gensec.h
+++ b/source4/auth/gensec/gensec.h
@@ -311,4 +311,6 @@ NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security,
 int gensec_setting_int(struct gensec_settings *settings, const char *mechanism, const char *name, int default_value);
 bool gensec_setting_bool(struct gensec_settings *settings, const char *mechanism, const char *name, bool default_value);
 
+NTSTATUS gensec_set_target_principal(struct gensec_security *gensec_security, const char *principal);
+
 #endif /* __GENSEC_H__ */
diff --git a/source4/auth/gensec/gensec_krb5.c b/source4/auth/gensec/gensec_krb5.c
index c2f96d7..d051b7f 100644
--- a/source4/auth/gensec/gensec_krb5.c
+++ b/source4/auth/gensec/gensec_krb5.c
@@ -299,7 +299,7 @@ static NTSTATUS gensec_krb5_common_client_start(struct gensec_security *gensec_s
 	}
 	in_data.length = 0;
 	
-	if (principal && lp_client_use_spnego_principal(gensec_security->settings->lp_ctx)) {
+	if (principal) {
 		krb5_principal target_principal;
 		ret = krb5_parse_name(gensec_krb5_state->smb_krb5_context->krb5_context, principal,
 				      &target_principal);
diff --git a/source4/auth/gensec/spnego.c b/source4/auth/gensec/spnego.c
index a715085..bbcba8d 100644
--- a/source4/auth/gensec/spnego.c
+++ b/source4/auth/gensec/spnego.c
@@ -28,6 +28,7 @@
 #include "auth/credentials/credentials.h"
 #include "auth/gensec/gensec.h"
 #include "auth/gensec/gensec_proto.h"
+#include "param/param.h"
 
 enum spnego_state_position {
 	SPNEGO_SERVER_START,
@@ -826,7 +827,9 @@ static NTSTATUS gensec_spnego_update(struct gensec_security *gensec_security, TA
 
 		if (spnego.negTokenInit.targetPrincipal) {
 			DEBUG(5, ("Server claims it's principal name is %s\n", spnego.negTokenInit.targetPrincipal));
-			gensec_set_target_principal(gensec_security, spnego.negTokenInit.targetPrincipal);
+			if (lp_client_use_spnego_principal(gensec_security->settings->lp_ctx)) {
+				gensec_set_target_principal(gensec_security, spnego.negTokenInit.targetPrincipal);
+			}
 		}
 
 		nt_status = gensec_spnego_parse_negTokenInit(gensec_security,
diff --git a/source4/dynconfig/config.mk b/source4/dynconfig/config.mk
index 0e7408a..976ca71 100644
--- a/source4/dynconfig/config.mk
+++ b/source4/dynconfig/config.mk
@@ -15,6 +15,7 @@ $(dynconfigsrcdir)/dynconfig.o: CFLAGS+=-DCONFIGFILE=\"$(CONFIG4FILE)\" -DBINDIR
 	 -DLOCKDIR=\"$(lockdir)\" -DPIDDIR=\"$(piddir)\" -DDATADIR=\"$(datadir)\" \
 	 -DLOGFILEBASE=\"$(logfilebase)\" \
 	 -DCONFIGDIR=\"$(sysconfdir)\" -DNCALRPCDIR=\"$(ncalrpcdir)\" \
+	 -DSWATDIR=\"$(swatdir)\" \
 	 -DPRIVATE_DIR=\"$(privatedir)\" \
 	 -DMODULESDIR=\"$(modulesdir)\" \
 	 -DSETUPDIR=\"$(setupdir)\" \
diff --git a/source4/dynconfig/dynconfig.c b/source4/dynconfig/dynconfig.c
index a56dd3d..358874e 100644
--- a/source4/dynconfig/dynconfig.c
+++ b/source4/dynconfig/dynconfig.c
@@ -40,54 +40,53 @@
  * table?  There's kind of a chicken-and-egg situation there...
  **/
 
-/** Directory with generic binaries */
-_PUBLIC_ const char *dyn_BINDIR = BINDIR;
-
-/** Directory with root use binaries */
-_PUBLIC_ const char *dyn_SBINDIR = SBINDIR;
-
-/**< Location of smb.conf file. **/
-_PUBLIC_ const char *dyn_CONFIGFILE = CONFIGFILE; 
-
-/** Log file directory. **/
-_PUBLIC_ const char *dyn_LOGFILEBASE = LOGFILEBASE; 
-
-/** Directory for local RPC (ncalrpc: transport) */
-_PUBLIC_ const char *dyn_NCALRPCDIR = NCALRPCDIR;
-
-/** Statically configured LanMan hosts. **/
-_PUBLIC_ const char *dyn_LMHOSTSFILE = LMHOSTSFILE; 
-
-/** Samba data directory. */
-_PUBLIC_ const char *dyn_DATADIR = DATADIR;
-
-_PUBLIC_ const char *dyn_MODULESDIR = MODULESDIR;
-
-/**
- * @brief Directory holding lock files.
- *
- * Not writable, but used to set a default in the parameter table.
- **/
-_PUBLIC_ const char *dyn_LOCKDIR = LOCKDIR;
-
-/** pid file directory */
-_PUBLIC_ const char *dyn_PIDDIR  = PIDDIR;
-
-/** Private data directory; holds ldb files and the like */
-_PUBLIC_ const char *dyn_PRIVATE_DIR = PRIVATE_DIR;
-
-/** SETUP files (source files used by the provision) */
-_PUBLIC_ const char *dyn_SETUPDIR = SETUPDIR;
-
-/** Where to find the winbindd socket */
-_PUBLIC_ const char *dyn_WINBINDD_SOCKET_DIR = WINBINDD_SOCKET_DIR;
-
-/** Where to find the winbindd privileged socket */
-_PUBLIC_ const char *dyn_WINBINDD_PRIVILEGED_SOCKET_DIR = WINBINDD_PRIVILEGED_SOCKET_DIR;
-
-/** Where to find the NTP signing daemon socket */
-_PUBLIC_ const char *dyn_NTP_SIGND_SOCKET_DIR = NTP_SIGND_SOCKET_DIR;
-
-/** Where to find python modules */
-_PUBLIC_ const char *dyn_PYTHONDIR = PYTHONDIR;
-
+#define DEFINE_DYN_CONFIG_PARAM(name) \
+const char *dyn_##name = name; \
+\
+ const char *get_dyn_##name(void) \
+{\
+	if (dyn_##name == NULL) {\
+		return name;\
+	}\
+	return dyn_##name;\
+}\
+\
+ const char *set_dyn_##name(const char *newpath) \
+{\
+	if (dyn_##name) {\
+		free(discard_const(dyn_##name));	\
+	}\
+	dyn_##name = strdup(newpath);\
+	return dyn_##name;\
+}\
+ bool is_default_dyn_##name(void) \
+{\
+	return (dyn_##name == NULL);\
+}
+
+/* these are in common with s3 */
+DEFINE_DYN_CONFIG_PARAM(SBINDIR)
+DEFINE_DYN_CONFIG_PARAM(BINDIR)
+DEFINE_DYN_CONFIG_PARAM(SWATDIR)
+DEFINE_DYN_CONFIG_PARAM(CONFIGFILE) /**< Location of smb.conf file. **/
+DEFINE_DYN_CONFIG_PARAM(LOGFILEBASE) /** Log file directory. **/
+DEFINE_DYN_CONFIG_PARAM(LMHOSTSFILE) /** Statically configured LanMan hosts. **/
+DEFINE_DYN_CONFIG_PARAM(CODEPAGEDIR)
+DEFINE_DYN_CONFIG_PARAM(LIBDIR)
+DEFINE_DYN_CONFIG_PARAM(MODULESDIR)
+DEFINE_DYN_CONFIG_PARAM(SHLIBEXT)
+DEFINE_DYN_CONFIG_PARAM(LOCKDIR)
+DEFINE_DYN_CONFIG_PARAM(STATEDIR) /** Persistent state files. Default LOCKDIR */
+DEFINE_DYN_CONFIG_PARAM(CACHEDIR) /** Temporary cache files. Default LOCKDIR */
+DEFINE_DYN_CONFIG_PARAM(PIDDIR)
+DEFINE_DYN_CONFIG_PARAM(NCALRPCDIR)
+DEFINE_DYN_CONFIG_PARAM(SMB_PASSWD_FILE)
+DEFINE_DYN_CONFIG_PARAM(PRIVATE_DIR)
+
+/* these are not in s3 */
+DEFINE_DYN_CONFIG_PARAM(DATADIR)
+DEFINE_DYN_CONFIG_PARAM(SETUPDIR)
+DEFINE_DYN_CONFIG_PARAM(WINBINDD_SOCKET_DIR)
+DEFINE_DYN_CONFIG_PARAM(WINBINDD_PRIVILEGED_SOCKET_DIR)
+DEFINE_DYN_CONFIG_PARAM(NTP_SIGND_SOCKET_DIR)
+DEFINE_DYN_CONFIG_PARAM(PYTHONDIR)
diff --git a/source4/dynconfig/dynconfig.h b/source4/dynconfig/dynconfig.h
index de9ff87..48f8ab6 100644
--- a/source4/dynconfig/dynconfig.h
+++ b/source4/dynconfig/dynconfig.h
@@ -35,6 +35,8 @@ extern const char *dyn_MODULESDIR;
 extern const char *dyn_LOCKDIR; 
 extern const char *dyn_PIDDIR;
 extern const char *dyn_PRIVATE_DIR;
+extern const char *dyn_SWATDIR;
+extern const char *dyn_JSDIR;
 extern const char *dyn_SETUPDIR;
 extern const char *dyn_WINBINDD_SOCKET_DIR;
 extern const char *dyn_WINBINDD_PRIVILEGED_SOCKET_DIR;
diff --git a/source4/dynconfig/wscript b/source4/dynconfig/wscript
index 4a48501..5be688c 100644
--- a/source4/dynconfig/wscript
+++ b/source4/dynconfig/wscript
@@ -34,6 +34,12 @@ dyn_cflags = {
     'MODULESDIR'                     : '${PREFIX}/modules',
     'INCLUDEDIR'                     : '${PREFIX}/include',
     'PKGCONFIGDIR'                   : '${LIBDIR}/pkgconfig',
+    'SWATDIR'                        : '${DATADIR}/swat',
+    'CODEPAGEDIR'                    : '${LIBDIR}/samba',
+    'LIBDIR'                         : '${LIBDIR}',
+    'STATEDIR'                       : '${LOCALSTATEDIR}',
+    'CACHEDIR'                       : '${LOCKDIR}',
+    'SMB_PASSWD_FILE'                : '${PRIVATEDIR}/smbpasswd',
     }
 
 # changes for when FHS is enabled
@@ -57,6 +63,7 @@ dyn_cflags_fhs = {
     'MODULESDIR'                     : '${LIBDIR}/samba',
     'INCLUDEDIR'                     : '${INCLUDEDIR}/samba-4.0',
     'PKGCONFIGDIR'                   : '${LIBDIR}/pkgconfig',
+    'SWATDIR'                        : '${DATADIR}/swat',
     }
 
 def get_varname(v):
diff --git a/source4/ntvfs/posix/pvfs_notify.c b/source4/ntvfs/posix/pvfs_notify.c
index 3e6f442..778897d 100644
--- a/source4/ntvfs/posix/pvfs_notify.c
+++ b/source4/ntvfs/posix/pvfs_notify.c
@@ -180,6 +180,10 @@ static NTSTATUS pvfs_notify_setup(struct pvfs_state *pvfs, struct pvfs_file *f,
 	NTSTATUS status;
 	struct notify_entry e;
 
+	/* We may not fill in all the elements in this entry -
+	 * structure may in future be shared with Samba3 */
+	ZERO_STRUCT(e);
+
 	f->notify_buffer = talloc_zero(f, struct pvfs_notify_buffer);
 	NT_STATUS_HAVE_NO_MEMORY(f->notify_buffer);
 
diff --git a/source4/smbd/process_model.c b/source4/smbd/process_model.c
index e3ea4db..d3f234e 100644
--- a/source4/smbd/process_model.c
+++ b/source4/smbd/process_model.c
@@ -86,6 +86,7 @@ _PUBLIC_ NTSTATUS process_model_init(struct loadparm_context *lp_ctx)
 	extern NTSTATUS process_model_thread_init(void);
 	extern NTSTATUS process_model_standard_init(void);
 	extern NTSTATUS process_model_prefork_init(void);
+	extern NTSTATUS process_model_onefork_init(void);
 	extern NTSTATUS process_model_single_init(void);
 	init_module_fn static_init[] = { STATIC_process_model_MODULES };
 	init_module_fn *shared_init = load_samba_modules(NULL, lp_ctx, "process_model");
diff --git a/source4/smbd/process_onefork.c b/source4/smbd/process_onefork.c
new file mode 100644
index 0000000..d1688ec
--- /dev/null
+++ b/source4/smbd/process_onefork.c
@@ -0,0 +1,161 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   process model: onefork (1 child process)
+
+   Copyright (C) Andrew Tridgell 1992-2005
+   Copyright (C) James J Myers 2003 <myersjj at samba.org>
+   Copyright (C) Stefan (metze) Metzmacher 2004
+   Copyright (C) Andrew Bartlett 2008 <abartlet at samba.org>
+   Copyright (C) David Disseldorp 2008 <ddiss at sgi.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/socket/socket.h"
+#include "smbd/process_model.h"
+#include "param/secrets.h"
+#include "system/filesys.h"
+#include "cluster/cluster.h"
+#include "param/param.h"
+#include "lib/ldb_wrap.h"
+
+#ifdef HAVE_SETPROCTITLE
+#ifdef HAVE_SETPROCTITLE_H
+#include <setproctitle.h>
+#endif
+#else
+#define setproctitle none_setproctitle
+static int none_setproctitle(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
+static int none_setproctitle(const char *fmt, ...)
+{
+	return 0;
+}
+#endif
+
+/*
+  called when the process model is selected
+*/
+static void onefork_model_init(struct tevent_context *ev)
+{
+	signal(SIGCHLD, SIG_IGN);
+}
+
+static void onefork_reload_after_fork(void)
+{
+	ldb_wrap_fork_hook();
+
+	/* Ensure that the forked children do not expose identical random streams */
+	set_need_random_reseed();
+}
+
+/*
+  called when a listening socket becomes readable.
+*/
+static void onefork_accept_connection(struct tevent_context *ev,
+				      struct loadparm_context *lp_ctx,
+				      struct socket_context *listen_socket,
+				       void (*new_conn)(struct tevent_context *,
+							struct loadparm_context *, struct socket_context *,
+							struct server_id , void *),
+				       void *private_data)
+{
+	NTSTATUS status;
+	struct socket_context *connected_socket;
+	pid_t pid = getpid();
+
+	/* accept an incoming connection. */
+	status = socket_accept(listen_socket, &connected_socket);
+	if (!NT_STATUS_IS_OK(status)) {
+		return;
+	}
+
+	talloc_steal(private_data, connected_socket);
+
+	new_conn(ev, lp_ctx, connected_socket, cluster_id(pid, socket_get_fd(connected_socket)), private_data);
+}
+
+/*
+  called to create a new server task
+*/
+static void onefork_new_task(struct tevent_context *ev,
+			     struct loadparm_context *lp_ctx,
+			     const char *service_name,
+			     void (*new_task_fn)(struct tevent_context *, struct loadparm_context *lp_ctx, struct server_id , void *),
+			     void *private_data)
+{
+	pid_t pid;
+
+	pid = fork();
+
+	if (pid != 0) {
+		/* parent or error code ... go back to the event loop */
+		return;
+	}
+
+	pid = getpid();
+
+	if (tevent_re_initialise(ev) != 0) {
+		smb_panic("Failed to re-initialise tevent after fork");
+	}
+
+	setproctitle("task %s server_id[%d]", service_name, pid);
+
+	onefork_reload_after_fork();
+
+	/* setup this new connection: process will bind to it's sockets etc */
+	new_task_fn(ev, lp_ctx, cluster_id(pid, 0), private_data);
+
+	event_loop_wait(ev);
+
+	talloc_free(ev);
+	exit(0);
+
+}
+
+
+/* called when a task goes down */
+static void onefork_terminate(struct tevent_context *ev, struct loadparm_context *lp_ctx, const char *reason)
+{
+	DEBUG(2,("onefork_terminate: reason[%s]\n",reason));
+}
+
+/* called to set a title of a task or connection */
+static void onefork_set_title(struct tevent_context *ev, const char *title)
+{
+	if (title) {
+		setproctitle("%s", title);
+	} else {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list