diff options
-rw-r--r-- | source4/Makefile.in | 53 | ||||
-rw-r--r-- | source4/aclocal.m4 | 32 | ||||
-rw-r--r-- | source4/configure.in | 89 | ||||
-rw-r--r-- | source4/include/context.h | 27 | ||||
-rw-r--r-- | source4/lib/iconv.m4 | 66 | ||||
-rw-r--r-- | source4/ntvfs/config.m4 | 20 | ||||
-rw-r--r-- | source4/rpc_server/config.m4 | 10 | ||||
-rw-r--r-- | source4/rpc_server/dcerpc_tcp.c | 4 | ||||
-rw-r--r-- | source4/smbd/process_model.c | 64 | ||||
-rw-r--r-- | source4/smbd/process_model.h | 69 | ||||
-rw-r--r-- | source4/smbd/process_model.m4 | 27 | ||||
-rw-r--r-- | source4/smbd/process_single.c | 27 | ||||
-rw-r--r-- | source4/smbd/process_standard.c | 26 | ||||
-rw-r--r-- | source4/smbd/process_thread.c | 28 | ||||
-rw-r--r-- | source4/smbd/server.c | 4 |
15 files changed, 350 insertions, 196 deletions
diff --git a/source4/Makefile.in b/source4/Makefile.in index 4f22898787..71525952a5 100644 --- a/source4/Makefile.in +++ b/source4/Makefile.in @@ -98,7 +98,9 @@ MODULES = $(CHARSET_MODULES) $(DCERPC_MODULES) $(NTVFS_MODULES) TDBBASE_OBJ = tdb/tdb.o tdb/spinlock.o TDB_OBJ = $(TDBBASE_OBJ) tdb/tdbutil.o -LIB_OBJ = lib/version.o lib/charcnv.o lib/debug.o lib/fault.o \ +CHARSET_OBJS = @CHARSET_OBJS@ + +LIB_OBJ = lib/version.o lib/debug.o lib/fault.o \ lib/getsmbpass.o lib/interface.o lib/md4.o \ lib/interfaces.o lib/pidfile.o lib/replace.o \ lib/signal.o lib/system.o lib/sendfile.o lib/time.o \ @@ -112,12 +114,12 @@ LIB_OBJ = lib/version.o lib/charcnv.o lib/debug.o lib/fault.o \ lib/talloc.o lib/substitute.o lib/fsusage.o \ lib/ms_fnmatch.o lib/select.o lib/messages.o \ lib/tallocmsg.o lib/dmallocmsg.o \ - lib/md5.o lib/hmacmd5.o lib/iconv.o lib/smbpasswd.o \ + lib/md5.o lib/hmacmd5.o lib/smbpasswd.o \ nsswitch/wb_client.o nsswitch/wb_common.o \ lib/pam_errors.o intl/lang_tdb.o lib/account_pol.o \ lib/gencache.o $(TDB_OBJ) \ lib/module.o \ - lib/ldap_escape.o lib/events.o lib/mutex.o + lib/ldap_escape.o lib/events.o lib/mutex.o $(CHARSET_OBJS) READLINE_OBJ = lib/readline.o @@ -197,42 +199,32 @@ AUTH_OBJ = auth/auth.o auth/auth_sam.o \ SMBD_OBJ_MAIN = smbd/server.o -NTVFS_CIFS_OBJ = ntvfs/cifs/vfs_cifs.o -NTVFS_SIMPLE_OBJ = ntvfs/simple/vfs_simple.o ntvfs/simple/svfs_util.o -NTVFS_IPC_OBJ = ntvfs/ipc/vfs_ipc.o -NTVFS_PRINT_OBJ = ntvfs/print/vfs_print.o -NTVFS_POSIX_OBJ = ntvfs/posix/vfs_posix.o - -SMBD_NTVFS_OBJ = ntvfs/ntvfs_base.o ntvfs/ntvfs_util.o \ - ntvfs/ntvfs_generic.o @NTVFS_STATIC@ +NTVFS_OBJS = @NTVFS_OBJS@ +NTVFS_LIBS = @NTVFS_LIBS@ -DCERPC_RPCECHO_OBJ = rpc_server/echo/rpc_echo.o -DCERPC_EPMAPPER_OBJ = rpc_server/epmapper/rpc_epmapper.o -DCERPC_REMOTE_OBJ = rpc_server/remote/dcesrv_remote.o - -SMBD_RPC_OBJ = rpc_server/dcerpc_server.o rpc_server/dcesrv_auth.o \ - rpc_server/dcerpc_tcp.o rpc_server/handles.o @DCERPC_STATIC@ +DCERPC_OBJS = @DCERPC_OBJS@ +DCERPC_LIBS = @DCERPC_LIBS@ SMBD_OBJ_SRV = smbd/connection.o \ - smbd/session.o \ + smbd/session.o smbd/process.o \ smbd/password.o smbd/conn.o \ smbd/negprot.o smbd/request.o \ smbd/reply.o smbd/sesssetup.o \ smbd/trans2.o smbd/search.o smbd/nttrans.o \ lib/server_mutex.o \ smbd/build_options.o smbd/service.o \ - smbd/rewrite.o $(SMBD_RPC_OBJ) \ - $(SMBD_NTVFS_OBJ) @SMBD_EXTRA_OBJS@ + smbd/rewrite.o $(DCERPC_OBJS) \ + $(NTVFS_OBJS) @SMBD_EXTRA_OBJS@ -PROCESS_MODEL_OBJ = smbd/process.o smbd/process_model.o smbd/process_standard.o \ - smbd/process_single.o +PROCESS_MODEL_OBJS = @PROCESS_MODEL_OBJS@ +PROCESS_MODEL_LIBS = @PROCESS_MODEL_LIBS@ -SMBD_OBJ_BASE = $(PROCESS_MODEL_OBJ) $(SMBD_OBJ_SRV) \ +SMBD_OBJ_BASE = $(PROCESS_MODEL_OBJS) $(SMBD_OBJ_SRV) \ $(PARAM_OBJ) $(SECRETS_OBJ) $(PASSDB_OBJ) \ $(AUTH_OBJ) $(LIB_OBJ) $(POPT_LIB_OBJ) $(LIBSMB_OBJ) -SMBD_OBJ = $(SMBD_OBJ_MAIN) $(SMBD_OBJ_BASE) - +SMBD_OBJS = $(SMBD_OBJ_MAIN) $(SMBD_OBJ_BASE) @BUILD_POPT@ +SMBD_LIBS = $(LIBS) $(PROCESS_MODEL_LIBS) $(DCERPC_LIBS) $(NTVFS_LIBS) CLIENT_OBJ1 = client/client.o client/clitar.o libcli/raw/clirewrite.o @@ -273,14 +265,14 @@ NDRDUMP_OBJ = utils/ndrdump.o utils/rewrite.o \ $(LIBSMB_OBJ) $(PARAM_OBJ) $(LIB_OBJ) PROTO_OBJ = $(SMBD_OBJ_SRV) \ - $(SMBD_OBJ_MAIN) $(PROCESS_MODEL_OBJ) \ + $(SMBD_OBJ_MAIN) $(PROCESS_MODEL_OBJS) \ $(LIBSMB_OBJ) \ $(LIBRAW_OBJ) $(LIBCLIAUTH_OBJ) \ $(SMBTORTURE_OBJ1) \ $(AUTH_OBJ) $(PARAM_OBJ) $(SECRETS_OBJ) \ $(PASSDB_OBJ) \ $(READLINE_OBJ) $(CLIENT_OBJ1) \ - $(LIB_OBJ) $(POPT_LIB_OBJ) + $(LIB_OBJ) $(POPT_LIB_OBJ) \ POPT_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \ popt/popthelp.o popt/poptparse.o @@ -398,10 +390,9 @@ bin/.dummy: dir=bin $(MAKEDIR); fi @: >> $@ || : > $@ # what a fancy emoticon! -bin/smbd@EXEEXT@: $(SMBD_OBJ) @BUILD_POPT@ bin/.dummy +bin/smbd@EXEEXT@: $(SMBD_OBJS) bin/.dummy @echo Linking $@ - @$(CC) $(FLAGS) -o $@ $(SMBD_OBJ) $(LDFLAGS) $(DYNEXP) \ - $(LIBS) @SMBD_EXTRA_LIBS@ @BUILD_POPT@ + @$(CC) $(FLAGS) -o $@ $(SMBD_OBJS) $(LDFLAGS) $(DYNEXP) $(SMBD_LIBS) bin/smbclient@EXEEXT@: $(CLIENT_OBJ) @BUILD_POPT@ bin/.dummy @echo Linking $@ @@ -528,7 +519,7 @@ proto_test: .PHONY: headers proto realclean: clean delheaders - -rm -f config.log $(BIN_PROGS) $(MODULES) $(SBIN_PROGS) bin/.dummy script/findsmb + -rm -f config.log $(BIN_PROGS) $(MODULES) $(SBIN_PROGS) bin/.dummy distclean: realclean -rm -f include/stamp-h diff --git a/source4/aclocal.m4 b/source4/aclocal.m4 index fc71845d01..b3f49dc8de 100644 --- a/source4/aclocal.m4 +++ b/source4/aclocal.m4 @@ -49,7 +49,7 @@ AC_DEFUN(SMB_MODULE_DEFAULT, ]) dnl Mark specified module as shared -dnl SMB_MODULE(1:name,2:subsystem,3:default_build,4:object_files,5:shared_object,6:libs,7:whatif-static,8:whatif-shared,9:whatif-not) +dnl SMB_MODULE(1:name,2:subsystem,3:default_build,4:object_files,5:private_proto_file,6:libs,7:whatif-static,8:whatif-shared,9:whatif-not) AC_DEFUN(SMB_MODULE, [ AC_MSG_CHECKING([how to build $1]) @@ -71,7 +71,8 @@ AC_DEFUN(SMB_MODULE, if test x"$DEST" = xSHARED; then AC_DEFINE([$1][_init], [init_module], [Whether to build $1 as shared module]) - $2_MODULES="$$2_MODULES $5" + $2_MODULES="$$2_MODULES bin/$1.$SHLIBEXT" + [MODULE_][$1][_PROTO]="$5" [MODULE_][$1][_LIBS]="$6" AC_MSG_RESULT([shared]) [$8] @@ -79,6 +80,7 @@ AC_DEFUN(SMB_MODULE, elif test x"$DEST" = xSTATIC; then [init_static_modules_]translit([$2], [A-Z], [a-z])="$[init_static_modules_]translit([$2], [A-Z], [a-z]) $1_init();" string_static_modules="$string_static_modules $1" + [MODULE_][$1][_PROTO]="$5" $2_STATIC="$$2_STATIC $4" $2_LIBS="$$2_LIBS $6" [$7] @@ -90,13 +92,35 @@ AC_DEFUN(SMB_MODULE, fi ]) -dnl Mark specified module as shared -dnl SMB_SUBSYSTEM(1:name,2:init_objectfile) +dnl SMB_SUBSYSTEM(1:name,2:init_objectfile,3:extra_objectfiles,4:public_proto_header,5:private_proto_header,6:libs) AC_DEFUN(SMB_SUBSYSTEM, [ + dnl the core object files of the subsystem + $1_BASE="$2 $3" + AC_SUBST($1_BASE) + + dnl the staticly linked modules of the subsystem AC_SUBST($1_STATIC) + + dnl all object files of the subsystem + $1_OBJS="$$1_BASE $$1_STATIC" + AC_SUBST($1_OBJS) + + dnl the libs required by the subsystem + $1_LIBS="$6 $$1_LIBS" AC_SUBST($1_LIBS) + + dnl the shared objects modules of the subsystem AC_SUBST($1_MODULES) + + dnl the public_prototype_header file + $1_PUBLIC_HEADER="$4" + AC_SUBST($1_PUBLIC_PROTO) + + dnl the private_prototype_header file + $1_PRIVATE_HEADER="$5" + AC_SUBST($1_PRIVATE_PROTO) + AC_DEFINE_UNQUOTED([static_init_]translit([$1], [A-Z], [a-z]), [{$init_static_modules_]translit([$1], [A-Z], [a-z])[}], [Static init functions]) ifelse([$2], , :, [rm -f $2]) ]) diff --git a/source4/configure.in b/source4/configure.in index 4c95e7e2a2..12998b1727 100644 --- a/source4/configure.in +++ b/source4/configure.in @@ -1248,70 +1248,6 @@ if test x"$samba_cv_HAVE_UTIMBUF" = x"yes"; then AC_DEFINE(HAVE_UTIMBUF,1,[Whether struct utimbuf is available]) fi -ICONV_LOCATION=standard -LOOK_DIRS="/usr /usr/local /sw" -AC_ARG_WITH(libiconv, -[ --with-libiconv=BASEDIR Use libiconv in BASEDIR/lib and BASEDIR/include (default=auto) ], -[ - if test "$withval" = "no" ; then - AC_MSG_ERROR(I won't take no for an answer) - else - if test "$withval" != "yes" ; then - LOOK_DIRS="$withval $LOOK_DIRS" - fi - fi -]) - -ICONV_FOUND="no" -for i in $LOOK_DIRS ; do - save_LIBS=$LIBS - save_LDFLAGS=$LDFLAGS - save_CPPFLAGS=$CPPFLAGS - CPPFLAGS="-I$i/include" - LDFLAGS="-L$i/lib" - LIBS= - export LDFLAGS LIBS CPPFLAGS -dnl Try to find iconv(3) - jm_ICONV($i) - - CPPFLAGS=$save_CPPFLAGS - if test -n "$ICONV_FOUND" ; then - LDFLAGS=$save_LDFLAGS - LIB_ADD_DIR(LDFLAGS, "$i/lib") - CFLAGS_ADD_DIR(CPPFLAGS, "$i/include") - LIBS="$save_LIBS $LIBS" - ICONV_LOCATION=$i - export LDFLAGS LIBS CPPFLAGS - break - else - LDFLAGS=$save_LDFLAGS - LIBS=$save_LIBS - export LDFLAGS LIBS CPPFLAGS - fi -done - -############ -# check for iconv in libc -AC_CACHE_CHECK([for working iconv],samba_cv_HAVE_NATIVE_ICONV,[ -AC_TRY_RUN([ -#include <iconv.h> -main() { - iconv_t cd = iconv_open("ASCII", "UCS-2LE"); - if (cd == 0 || cd == (iconv_t)-1) return -1; - return 0; -} -], -samba_cv_HAVE_NATIVE_ICONV=yes,samba_cv_HAVE_NATIVE_ICONV=no,samba_cv_HAVE_NATIVE_ICONV=cross)]) -if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes"; then - AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv]) -fi - -if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then - AC_MSG_WARN([Sufficient support for iconv function was not found. - Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!]) -fi - - AC_CACHE_CHECK([for Linux kernel oplocks],samba_cv_HAVE_KERNEL_OPLOCKS_LINUX,[ AC_TRY_RUN([ #include <sys/types.h> @@ -1778,25 +1714,6 @@ if test x"$samba_cv_BROKEN_NISPLUS_INCLUDE_FILES" = x"yes"; then AC_DEFINE(BROKEN_NISPLUS_INCLUDE_FILES,1,[Whether the nisplus include files are broken]) fi -################################################# -# check for pthread support -AC_MSG_CHECKING(whether to use pthreads) -AC_ARG_WITH(pthreads, -[ --with-pthreads Include pthreads (default=no) ], -[ case "$withval" in - yes) - AC_MSG_RESULT(yes) - AC_DEFINE(WITH_PTHREADS,1,[Whether to use pthreads]) - SMBD_EXTRA_OBJS="smbd/process_thread.o" - SMBD_EXTRA_LIBS="-lpthread" - ;; - *) - AC_MSG_RESULT(no) - ;; - esac ], - AC_MSG_RESULT(no) -) - AC_SUBST(SMBD_EXTRA_OBJS) AC_SUBST(SMBD_EXTRA_LIBS) @@ -2067,8 +1984,8 @@ AC_ARG_WITH(static-modules, done fi ]) -SMB_SUBSYSTEM(CHARSET,lib/iconv.o) - +sinclude(lib/iconv.m4) +sinclude(smbd/process_model.m4) sinclude(ntvfs/config.m4) sinclude(rpc_server/config.m4) @@ -2101,4 +2018,4 @@ dnl Remove -I/usr/include/? from CFLAGS and CPPFLAGS CFLAGS_REMOVE_USR_INCLUDE(CFLAGS) CFLAGS_REMOVE_USR_INCLUDE(CPPFLAGS) -AC_OUTPUT(include/stamp-h Makefile script/findsmb) +AC_OUTPUT(include/stamp-h Makefile) diff --git a/source4/include/context.h b/source4/include/context.h index 4cfe6c302b..7b156ed382 100644 --- a/source4/include/context.h +++ b/source4/include/context.h @@ -326,32 +326,7 @@ struct timers_context { time_t last_smb_conf_reload; }; - -/* the process model operations structure - contains function pointers to - the model-specific implementations of each operation */ -struct model_ops { - /* called at startup when the model is selected */ - void (*model_startup)(void); - - /* function to accept new connection */ - void (*accept_connection)(struct event_context *, struct fd_event *, time_t, uint16); - - /* function to accept new rpc over tcp connection */ - void (*accept_rpc_connection)(struct event_context *, struct fd_event *, time_t, uint16); - - /* function to terminate a connection */ - void (*terminate_connection)(struct server_context *smb, const char *reason); - - /* function to terminate a connection */ - void (*terminate_rpc_connection)(void *r, const char *reason); - - /* function to exit server */ - void (*exit_server)(struct server_context *smb, const char *reason); - - /* returns process or thread id */ - int (*get_id)(struct request_context *req); -}; - +#include "smbd/process_model.h" /* smb context structure. This should contain all the state * information associated with a SMB server */ diff --git a/source4/lib/iconv.m4 b/source4/lib/iconv.m4 new file mode 100644 index 0000000000..26512ff326 --- /dev/null +++ b/source4/lib/iconv.m4 @@ -0,0 +1,66 @@ +dnl # ICONV/CHARSET subsystem + +ICONV_LOCATION=standard +LOOK_DIRS="/usr /usr/local /sw" +AC_ARG_WITH(libiconv, +[ --with-libiconv=BASEDIR Use libiconv in BASEDIR/lib and BASEDIR/include (default=auto) ], +[ + if test "$withval" = "no" ; then + AC_MSG_ERROR(I won't take no for an answer) + else + if test "$withval" != "yes" ; then + LOOK_DIRS="$withval $LOOK_DIRS" + fi + fi +]) + +ICONV_FOUND="no" +for i in $LOOK_DIRS ; do + save_LIBS=$LIBS + save_LDFLAGS=$LDFLAGS + save_CPPFLAGS=$CPPFLAGS + CPPFLAGS="-I$i/include" + LDFLAGS="-L$i/lib" + LIBS= + export LDFLAGS LIBS CPPFLAGS +dnl Try to find iconv(3) + jm_ICONV($i) + + CPPFLAGS=$save_CPPFLAGS + if test -n "$ICONV_FOUND" ; then + LDFLAGS=$save_LDFLAGS + LIB_ADD_DIR(LDFLAGS, "$i/lib") + CFLAGS_ADD_DIR(CPPFLAGS, "$i/include") + LIBS="$save_LIBS $LIBS" + ICONV_LOCATION=$i + export LDFLAGS LIBS CPPFLAGS + break + else + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + export LDFLAGS LIBS CPPFLAGS + fi +done + +############ +# check for iconv in libc +AC_CACHE_CHECK([for working iconv],samba_cv_HAVE_NATIVE_ICONV,[ +AC_TRY_RUN([ +#include <iconv.h> +main() { + iconv_t cd = iconv_open("ASCII", "UCS-2LE"); + if (cd == 0 || cd == (iconv_t)-1) return -1; + return 0; +} +], +samba_cv_HAVE_NATIVE_ICONV=yes,samba_cv_HAVE_NATIVE_ICONV=no,samba_cv_HAVE_NATIVE_ICONV=cross)]) +if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes"; then + AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv]) +fi + +if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then + AC_MSG_WARN([Sufficient support for iconv function was not found. + Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!]) +fi + +SMB_SUBSYSTEM(CHARSET,lib/iconv.o,lib/charcnv.o) diff --git a/source4/ntvfs/config.m4 b/source4/ntvfs/config.m4 index c7d4f59c1f..aabaa7edfc 100644 --- a/source4/ntvfs/config.m4 +++ b/source4/ntvfs/config.m4 @@ -1,9 +1,17 @@ dnl # NTVFS Server subsystem -SMB_MODULE(ntvfs_cifs, NTVFS, STATIC, \$(NTVFS_CIFS_OBJ), "bin/cifs.$SHLIBEXT$") -SMB_MODULE(ntvfs_simple, NTVFS, STATIC, \$(NTVFS_SIMPLE_OBJ), "bin/ntvfs_simple.$SHLIBEXT$") -SMB_MODULE(ntvfs_print, NTVFS, STATIC, \$(NTVFS_PRINT_OBJ), "bin/ntvfs_print.$SHLIBEXT$") -SMB_MODULE(ntvfs_ipc, NTVFS, STATIC, \$(NTVFS_IPC_OBJ), "bin/ntvfs_ipc.$SHLIBEXT$") -SMB_MODULE(ntvfs_posix, NTVFS, NOT, \$(NTVFS_POSIX_OBJ), "bin/ntvfs_posix.$SHLIBEXT$") +SMB_MODULE(ntvfs_cifs, NTVFS, STATIC, [ntvfs/cifs/vfs_cifs.o]) -SMB_SUBSYSTEM(NTVFS,ntvfs/ntvfs_base.o) +SMB_MODULE(ntvfs_simple, NTVFS, STATIC, + [ntvfs/simple/vfs_simple.o ntvfs/simple/svfs_util.o], + ntvfs/simple/svfs_private.h) + +SMB_MODULE(ntvfs_print, NTVFS, STATIC, [ntvfs/print/vfs_print.o]) + +SMB_MODULE(ntvfs_ipc, NTVFS, STATIC, [ntvfs/ipc/vfs_ipc.o]) + +SMB_MODULE(ntvfs_posix, NTVFS, NOT, [ntvfs/posix/vfs_posix.o]) + +SMB_SUBSYSTEM(NTVFS,ntvfs/ntvfs_base.o, + [ntvfs/ntvfs_generic.o ntvfs/ntvfs_util.o], + ntvfs_public_proto.h) diff --git a/source4/rpc_server/config.m4 b/source4/rpc_server/config.m4 index 7396d19546..8de6d273b9 100644 --- a/source4/rpc_server/config.m4 +++ b/source4/rpc_server/config.m4 @@ -1,7 +1,9 @@ dnl # DCERPC Server subsystem -SMB_MODULE(dcerpc_rpcecho, DCERPC, STATIC, \$(DCERPC_RPCECHO_OBJ), "bin/dcerpc_rpcecho.$SHLIBEXT$") -SMB_MODULE(dcerpc_epmapper, DCERPC, STATIC, \$(DCERPC_EPMAPPER_OBJ), "bin/dcerpc_epmapper.$SHLIBEXT$") -SMB_MODULE(dcerpc_remote, DCERPC, STATIC, \$(DCERPC_REMOTE_OBJ), "bin/dcerpc_remote.$SHLIBEXT$") +SMB_MODULE(dcerpc_rpcecho,DCERPC,STATIC,[rpc_server/echo/rpc_echo.o]) +SMB_MODULE(dcerpc_epmapper,DCERPC,STATIC,[rpc_server/epmapper/rpc_epmapper.o]) +SMB_MODULE(dcerpc_remote,DCERPC,STATIC,[rpc_server/remote/dcesrv_remote.o]) -SMB_SUBSYSTEM(DCERPC,rpc_server/dcerpc_server.o) +SMB_SUBSYSTEM(DCERPC,rpc_server/dcerpc_server.o, + [rpc_server/dcerpc_tcp.o rpc_server/dcesrv_auth.o rpc_server/handles.o], + rpc_server/dcesrv_public_proto.h) diff --git a/source4/rpc_server/dcerpc_tcp.c b/source4/rpc_server/dcerpc_tcp.c index cc7581ee2f..69cd9cad35 100644 --- a/source4/rpc_server/dcerpc_tcp.c +++ b/source4/rpc_server/dcerpc_tcp.c @@ -255,7 +255,7 @@ static void setup_listen_rpc(struct event_context *events, add a socket address to the list of events, one event per dcerpc endpoint */ static void add_socket_rpc(struct event_context *events, - struct model_ops *model_ops, + const struct model_ops *model_ops, struct in_addr *ifip) { struct dcesrv_endpoint *e; @@ -289,7 +289,7 @@ static void add_socket_rpc(struct event_context *events, Open the listening sockets for RPC over TCP ****************************************************************************/ void open_sockets_rpc(struct event_context *events, - struct model_ops *model_ops) + const struct model_ops *model_ops) { if (lp_interfaces() && lp_bind_interfaces_only()) { int num_interfaces = iface_count(); diff --git a/source4/smbd/process_model.c b/source4/smbd/process_model.c index 06127d1364..121b35aba4 100644 --- a/source4/smbd/process_model.c +++ b/source4/smbd/process_model.c @@ -24,7 +24,6 @@ /* the list of currently registered process models */ static struct { - const char *name; struct model_ops *ops; } *models = NULL; static int num_models; @@ -35,13 +34,15 @@ static int num_models; The 'name' can be later used by other backends to find the operations structure for this backend. */ -BOOL register_process_model(const char *name, struct model_ops *ops) +static NTSTATUS register_process_model(void *_ops) { - if (process_model_byname(name) != NULL) { + const struct model_ops *ops = _ops; + + if (process_model_byname(ops->name) != NULL) { /* its already registered! */ - DEBUG(2,("process_model '%s' already registered\n", - name)); - return False; + DEBUG(0,("PROCESS_MODEL '%s' already registered\n", + ops->name)); + return NT_STATUS_OBJECT_NAME_COLLISION; } models = Realloc(models, sizeof(models[0]) * (num_models+1)); @@ -49,23 +50,26 @@ BOOL register_process_model(const char *name, struct model_ops *ops) smb_panic("out of memory in register_process_model"); } - models[num_models].name = smb_xstrdup(name); models[num_models].ops = smb_xmemdup(ops, sizeof(*ops)); + models[num_models].ops->name = smb_xstrdup(ops->name); num_models++; - return True; + DEBUG(3,("PROCESS_MODEL '%s' registered\n", + ops->name)); + + return NT_STATUS_OK; } /* return the operations structure for a named backend of the specified type */ -struct model_ops *process_model_byname(const char *name) +const struct model_ops *process_model_byname(const char *name) { int i; for (i=0;i<num_models;i++) { - if (strcmp(models[i].name, name) == 0) { + if (strcmp(models[i].ops->name, name) == 0) { return models[i].ops; } } @@ -73,13 +77,39 @@ struct model_ops *process_model_byname(const char *name) return NULL; } +/* + return the PROCESS_MODEL module version, and the size of some critical types + This can be used by process model modules to either detect compilation errors, or provide + multiple implementations for different smbd compilation options in one module +*/ +const struct process_model_critical_sizes *process_model_version(void) +{ + static const struct process_model_critical_sizes critical_sizes = { + PROCESS_MODEL_VERSION, + sizeof(struct model_ops), + sizeof(struct server_context), + sizeof(struct event_context), + sizeof(struct fd_event) + }; + + return &critical_sizes; +} -/* initialise the builtin process models */ -void process_model_init(void) +/* + initialise the PROCESS_MODEL subsystem +*/ +BOOL process_model_init(void) { - process_model_standard_init(); - process_model_single_init(); -#ifdef WITH_PTHREADS - process_model_thread_init(); -#endif + NTSTATUS status; + + status = register_subsystem("process_model", register_process_model); + if (!NT_STATUS_IS_OK(status)) { + return False; + } + + /* FIXME: Perhaps panic if a basic process model, such as simple, fails to initialise? */ + static_init_process_model; + + DEBUG(3,("PROCESS subsystem version %d initialised\n", PROCESS_MODEL_VERSION)); + return True; } diff --git a/source4/smbd/process_model.h b/source4/smbd/process_model.h new file mode 100644 index 0000000000..688ae65226 --- /dev/null +++ b/source4/smbd/process_model.h @@ -0,0 +1,69 @@ +/* + Unix SMB/CIFS implementation. + process model manager - main loop + Copyright (C) Andrew Tridgell 1992-2003 + Copyright (C) James J Myers 2003 <myersjj@samba.org> + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef SAMBA_PROCESS_MODEL_H +#define SAMBA_PROCESS_MODEL_H + +/* modules can use the following to determine if the interface has changed + * please increment the version number after each interface change + * with a comment and maybe update struct process_model_critical_sizes. + */ +/* version 1 - initial version - metze */ +#define PROCESS_MODEL_VERSION 1 + +/* the process model operations structure - contains function pointers to + the model-specific implementations of each operation */ +struct model_ops { + /* the name of the process_model */ + const char *name; + + /* called at startup when the model is selected */ + void (*model_startup)(void); + + /* function to accept new connection */ + void (*accept_connection)(struct event_context *, struct fd_event *, time_t, uint16); + + /* function to accept new rpc over tcp connection */ + void (*accept_rpc_connection)(struct event_context *, struct fd_event *, time_t, uint16); + + /* function to terminate a connection */ + void (*terminate_connection)(struct server_context *smb, const char *reason); + + /* function to terminate a connection */ + void (*terminate_rpc_connection)(void *r, const char *reason); + + /* function to exit server */ + void (*exit_server)(struct server_context *smb, const char *reason); + + /* returns process or thread id */ + int (*get_id)(struct request_context *req); +}; + +/* this structure is used by modules to determine the size of some critical types */ +struct process_model_critical_sizes { + int interface_version; + int sizeof_model_ops; + int sizeof_server_context; + int sizeof_event_context; + int sizeof_fd_event; +}; + +#endif /* SAMBA_PROCESS_MODEL_H */ diff --git a/source4/smbd/process_model.m4 b/source4/smbd/process_model.m4 new file mode 100644 index 0000000000..a7f6fb0793 --- /dev/null +++ b/source4/smbd/process_model.m4 @@ -0,0 +1,27 @@ +dnl # Server process model subsystem + +SMB_MODULE(process_model_single,PROCESS_MODEL,STATIC,[smbd/process_single.o]) +SMB_MODULE(process_model_standard,PROCESS_MODEL,STATIC,[smbd/process_standard.o]) + +################################################# +# check for pthread support +AC_MSG_CHECKING(whether to use pthreads) +AC_ARG_WITH(pthreads, +[ --with-pthreads Include pthreads (default=no) ], +[ case "$withval" in + yes) + AC_MSG_RESULT(yes) + SMB_MODULE_DEFAULT(process_model_thread,STATIC) + ;; + *) + AC_MSG_RESULT(no) + ;; + esac ], +AC_MSG_RESULT(no) +) + +SMB_MODULE(process_model_thread,PROCESS_MODEL,NOT, + [smbd/process_thread.o],[],[-lpthread]) + +SMB_SUBSYSTEM(PROCESS_MODEL,smbd/process_model.o, + [],smbd/process_model_public_proto.h) diff --git a/source4/smbd/process_single.c b/source4/smbd/process_single.c index 8f1362bed3..0c626e45c6 100644 --- a/source4/smbd/process_single.c +++ b/source4/smbd/process_single.c @@ -92,24 +92,39 @@ static int get_id(struct request_context *req) return (int)req->smb->pid; } +static void single_exit_server(struct server_context *smb, const char *reason) +{ + DEBUG(1,("single_exit_server: reason[%s]\n",reason)); +} + /* - initialise the single process model, registering ourselves with the model subsystem + initialise the single process model, registering ourselves with the process model subsystem */ -void process_model_single_init(void) +NTSTATUS process_model_single_init(void) { + NTSTATUS ret; struct model_ops ops; ZERO_STRUCT(ops); - + + /* fill in our name */ + ops.name = "single"; + /* fill in all the operations */ ops.model_startup = model_startup; ops.accept_connection = accept_connection; ops.accept_rpc_connection = accept_rpc_connection; ops.terminate_connection = terminate_connection; ops.terminate_rpc_connection = terminate_rpc_connection; - ops.exit_server = NULL; + ops.exit_server = single_exit_server; ops.get_id = get_id; - /* register ourselves with the process model subsystem. We register under the name 'single'. */ - register_process_model("single", &ops); + /* register ourselves with the PROCESS_MODEL subsystem. */ + ret = register_backend("process_model", &ops); + if (!NT_STATUS_IS_OK(ret)) { + DEBUG(0,("Failed to register process_model 'single'!\n")); + return ret; + } + + return ret; } diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c index 505c2aafbf..8a71739d2a 100644 --- a/source4/smbd/process_standard.c +++ b/source4/smbd/process_standard.c @@ -134,23 +134,39 @@ static int get_id(struct request_context *req) return (int)req->smb->pid; } +static void standard_exit_server(struct server_context *smb, const char *reason) +{ + DEBUG(1,("standard_exit_server: reason[%s]\n",reason)); +} + /* - initialise the standard process model, registering ourselves with the model subsystem + initialise the standard process model, registering ourselves with the process model subsystem */ -void process_model_standard_init(void) +NTSTATUS process_model_standard_init(void) { + NTSTATUS ret; struct model_ops ops; ZERO_STRUCT(ops); - + + /* fill in our name */ + ops.name = "standard"; + /* fill in all the operations */ ops.model_startup = model_startup; ops.accept_connection = accept_connection; ops.accept_rpc_connection = accept_rpc_connection; ops.terminate_connection = terminate_connection; ops.terminate_rpc_connection = terminate_rpc_connection; + ops.exit_server = standard_exit_server; ops.get_id = get_id; - /* register ourselves with the process model subsystem. We register under the name 'standard'. */ - register_process_model("standard", &ops); + /* register ourselves with the PROCESS_MODEL subsystem. */ + ret = register_backend("process_model", &ops); + if (!NT_STATUS_IS_OK(ret)) { + DEBUG(0,("Failed to register process_model 'standard'!\n")); + return ret; + } + + return ret; } diff --git a/source4/smbd/process_thread.c b/source4/smbd/process_thread.c index bd64166355..dcd2f456af 100644 --- a/source4/smbd/process_thread.c +++ b/source4/smbd/process_thread.c @@ -465,25 +465,39 @@ static void model_startup(void) register_debug_handlers("thread", &d_ops); } +static void thread_exit_server(struct server_context *smb, const char *reason) +{ + DEBUG(1,("thread_exit_server: reason[%s]\n",reason)); +} + /* initialise the thread process model, registering ourselves with the model subsystem */ -void process_model_thread_init(void) +NTSTATUS process_model_thread_init(void) { + NTSTATUS ret; struct model_ops ops; ZERO_STRUCT(ops); - + + /* fill in our name */ + ops.name = "thread"; + /* fill in all the operations */ ops.model_startup = model_startup; ops.accept_connection = accept_connection; ops.accept_rpc_connection = accept_rpc_connection; ops.terminate_connection = terminate_connection; ops.terminate_rpc_connection = terminate_rpc_connection; - ops.exit_server = NULL; + ops.exit_server = thread_exit_server; ops.get_id = get_id; - - /* register ourselves with the process model subsystem. We - register under the name 'thread'. */ - register_process_model("thread", &ops); + + /* register ourselves with the PROCESS_MODEL subsystem. */ + ret = register_backend("process_model", &ops); + if (!NT_STATUS_IS_OK(ret)) { + DEBUG(0,("Failed to register process_model 'thread'!\n")); + return ret; + } + + return ret; } diff --git a/source4/smbd/server.c b/source4/smbd/server.c index 67bf07c7f8..2ed74a8c4d 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -91,7 +91,7 @@ static void add_socket(struct event_context *events, Open the socket communication. ****************************************************************************/ static void open_sockets_smbd(struct event_context *events, - struct model_ops *model_ops) + const struct model_ops *model_ops) { if (lp_interfaces() && lp_bind_interfaces_only()) { int num_interfaces = iface_count(); @@ -194,7 +194,7 @@ static BOOL init_structs(void) static void setup_process_model(struct event_context *events, const char *model) { - struct model_ops *ops; + const struct model_ops *ops; process_model_init(); |