s4:s3compat Provide hooks to get and set 'samba3' and 'samba4' globals
authorAndrew Bartlett <abartlet@samba.org>
Tue, 11 May 2010 10:55:30 +0000 (20:55 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 3 Jun 2010 01:14:03 +0000 (11:14 +1000)
This avoids the need to compile smbd/server.c and ensures closer
control over these important global variables.

Andrew Bartlett

source4/s3compat/s3_smbd.c
source4/s3compat/s3compat.c
source4/s3compat/s3compat_authenticate.c
source4/s3compat/s3compat_globals.c [new file with mode: 0644]
source4/s3compat/s3compat_globals.h [new file with mode: 0644]
source4/s3compat/s3replace.c
source4/s3compat/s3replace_public.h [deleted file]
source4/s3compat/wscript_build

index 49013341127ffe41a7693b9b4a6c2bb7a4350aed..4be2caa89a1a88933a289aeae7257c57dae58f97 100644 (file)
 #include "dynconfig/dynconfig.h"
 #include "smbd/process_model.h"
 #include "tevent/tevent.h"
-#include "s3compat.h"
-#include "s3replace.h"
-#include "s3replace_public.h"
-#include "s3_smbd_proto.h"
+#include "s3compat_wrapper.h"
+#include "s3compat_proto.h"
+#include "s3compat_globals.h"
 static struct stream_connection *samba3_conn;
 
 struct stream_connection *s3compat_get_conn(void) 
@@ -48,7 +47,6 @@ struct stream_connection *s3compat_get_conn(void)
 */
 static void s3compat_smb_accept(struct stream_connection *conn)
 {
-       int fd = socket_get_fd(conn->socket);
        if (lp_parm_bool(conn->lp_ctx, NULL, "s3compat", "gdb", false)) {
                char *cmd = talloc_asprintf(conn, "gnome-terminal -e \"gdb --pid %u\"", getpid());
                system(cmd);
@@ -57,10 +55,10 @@ static void s3compat_smb_accept(struct stream_connection *conn)
        DEBUG(0,(__location__ ": new s3compat smbd connection\n"));
        samba3_conn = conn;
 
-       s3replace_set_lp_ctx(conn->lp_ctx);
+       s3compat_set_lp_ctx(conn->lp_ctx);
 
-       s3compat_set_server_fd(fd);
-       s3compat_set_event_ctx(conn->event.ctx);
+       s3compat_set_tevent_ctx(conn->event.ctx);
+       s3compat_set_msg_ctx(conn->msg_ctx);
        tevent_re_initialise(conn->event.ctx);
        s3compat_smbd_process();
        _exit(1);
index 52aece0b4093c690126b64cc4473ece5b97f9c2d..75b315faadd150de0b47e059fb0457283ecdf69e 100644 (file)
 
 #include "includes.h"
 #include "source3/smbd/globals.h"
-#include "s3compat.h"
-
-_PUBLIC_ const char *s3compat_samba_version_string(void)
-{
-       const char *samba_version_string(void);
-       return samba_version_string();
-}
+#include "s3compat_wrapper.h"
 
 _PUBLIC_
 void s3compat_initialise(const char *config_file, bool interactive)
@@ -63,32 +57,10 @@ void s3compat_initialise(const char *config_file, bool interactive)
        auth_samba4_init();
 
        DEBUG(0,("s3compat: initialised samba3 version: %s\n",
-                s3compat_samba_version_string()));
-}
-
-_PUBLIC_
-void s3compat_set_server_fd(int fd)
-{
-       extern int server_fd;
-       server_fd = fd;
-}
-
-_PUBLIC_
-void s3compat_set_event_ctx(struct tevent_context *ctx)
-{
-       extern struct tevent_context *smbd_event_ctx;
-       smbd_event_ctx = ctx;
-}
-
-_PUBLIC_
-struct tevent_context *s3compat_get_event_ctx(void)
-{
-       extern struct tevent_context *smbd_event_ctx;
-       return smbd_event_ctx;
+                samba_version_string()));
 }
 
-_PUBLIC_
-void s3compat_smbd_process(void)
+_PUBLIC_ void s3compat_smbd_process(void)
 {
        void smbd_process(void);
        /* This needs samba3_conn to be set up first, so run per-connection */
index faf19d97a82896ce369a681a9b4db1f0de8f1c45..407a7dc4fe22e1a4850d2a5e2e176b2622859326 100644 (file)
 #include "auth/auth.h"
 #include "auth/auth_sam_reply.h"
 #include "s3_smbd_proto.h"
+#include "s3compat_globals.h"
 #include "s3compat_authenticate.h"
-#include "smbd/service.h"
 #include "auth/credentials/credentials.h"
 #include "auth/gensec/gensec.h"
 #include "libcli/security/dom_sid.h"
 
 NTSTATUS s3compat_authenticate(TALLOC_CTX *mem_ctx, uint8_t chall[8], const struct auth_usersupplied_info *user_info, struct netr_SamInfo3 **info3) 
 {
-       struct stream_connection *samba3_conn;
        struct auth_context *auth_context;
        struct auth_serversupplied_info *server_info;
        NTSTATUS nt_status;
-       samba3_conn = s3compat_get_conn();
 
        nt_status = auth_context_create(mem_ctx,
-                                       samba3_conn->event.ctx, samba3_conn->msg_ctx, samba3_conn->lp_ctx,
+                                       s3compat_get_tevent_ctx(), s3compat_get_msg_ctx(), s3compat_get_lp_ctx(),
                                        &auth_context);
        NT_STATUS_NOT_OK_RETURN(nt_status);
                
@@ -70,25 +68,22 @@ _PUBLIC_ NTSTATUS ads_verify_ticket(TALLOC_CTX *mem_ctx,
                                    DATA_BLOB *session_key,
                                    bool use_replay_cache)
 {
-        struct stream_connection *samba3_conn;
         struct cli_credentials *server_credentials;
         struct auth_session_info *session_info;
         struct gensec_security *gensec_server_context;
         struct netr_SamInfo3 *info3;
+       struct loadparm_context *lp_ctx = s3compat_get_lp_ctx();
         NTSTATUS nt_status;
 
         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
         NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
        
-       /* This context pointer helps us get at loadparm etc */
-       samba3_conn = s3compat_get_conn();
-
        /* Get the keytab from the credentials subsystem */
        server_credentials = cli_credentials_init(tmp_ctx);
        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(server_credentials, tmp_ctx);
        
-       cli_credentials_set_conf(server_credentials, samba3_conn->lp_ctx);
-       nt_status = cli_credentials_set_machine_account(server_credentials, samba3_conn->lp_ctx);
+       cli_credentials_set_conf(server_credentials, lp_ctx);
+       nt_status = cli_credentials_set_machine_account(server_credentials, lp_ctx);
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(1, ("Failed to obtain server credentials, can not validate a Kerberos ticket: %s\n", nt_errstr(nt_status)));
                talloc_free(tmp_ctx);
@@ -97,9 +92,9 @@ _PUBLIC_ NTSTATUS ads_verify_ticket(TALLOC_CTX *mem_ctx,
 
        /* Start up GENSEC in the same way a native Samba4 task would */
        nt_status = samba_server_gensec_start(tmp_ctx,
-                                             samba3_conn->event.ctx,
-                                             samba3_conn->msg_ctx,
-                                             samba3_conn->lp_ctx,
+                                             s3compat_get_tevent_ctx(),
+                                             s3compat_get_msg_ctx(),
+                                             lp_ctx,
                                              server_credentials,
                                              "cifs",
                                              &gensec_server_context);
diff --git a/source4/s3compat/s3compat_globals.c b/source4/s3compat/s3compat_globals.c
new file mode 100644 (file)
index 0000000..be26378
--- /dev/null
@@ -0,0 +1,64 @@
+/* Global variables that may be needed in s3compat code on the Samba4
+ * side that cannot be passed around as parameters */
+
+#include "includes.h"
+#include "s3compat_globals.h"
+#include "s3compat_proto.h"
+#include "smbd/service.h"
+#include "lib/socket/socket.h"
+
+static struct loadparm_context *s3compat_lp_ctx;
+void s3compat_set_lp_ctx(struct loadparm_context *lp_ctx)
+{
+       s3compat_lp_ctx = lp_ctx;
+}
+
+struct loadparm_context *s3compat_get_lp_ctx(void)
+{
+       return s3compat_lp_ctx;
+}
+
+static struct tevent_context *s3compat_tevent_ctx;
+void s3compat_set_tevent_ctx(struct tevent_context *ctx)
+{
+       s3compat_tevent_ctx = ctx;
+}
+
+struct tevent_context *s3compat_get_tevent_ctx(void)
+{
+       return s3compat_tevent_ctx;
+}
+
+static struct messaging_context *s3compat_messaging_context;
+void s3compat_set_msg_ctx(struct messaging_context *msg_ctx)
+{
+       s3compat_messaging_context = msg_ctx;
+}
+
+struct messaging_context *s3compat_get_msg_ctx(void)
+{
+       return s3compat_messaging_context;
+}
+
+
+int smbd_server_fd(void) 
+{
+       struct stream_connection *samba3_conn;
+       samba3_conn = s3compat_get_conn();
+       return socket_get_fd(samba3_conn->socket);
+}
+
+int get_client_fd(void)
+{
+       return smbd_server_fd();
+}
+
+struct tevent_context *smbd_event_context(void)
+{
+       return s3compat_get_tevent_ctx();
+}
+
+struct tevent_context *winbind_event_context(void)
+{
+       return s3compat_get_tevent_ctx();
+}
diff --git a/source4/s3compat/s3compat_globals.h b/source4/s3compat/s3compat_globals.h
new file mode 100644 (file)
index 0000000..57db8da
--- /dev/null
@@ -0,0 +1,3 @@
+#include "lib/messaging/messaging.h"
+#include "param/param.h"
+#include "s3compat_globals_proto.h"
index f27ac979ef8f536878ec27b276d3b7444543d220..16526ec6d4dd0c1b7bfcd5a510df08df14ccb968 100644 (file)
@@ -40,15 +40,3 @@ krb5_realm *krb5_princ_realm(krb5_context context, krb5_principal principal)
 {
        DEBUG(2,("WARNING: krb5_princ_set_realm not implemented in s3replace\n"));
 }
-
-static struct loadparm_context *s3replace_lp_ctx;
-
-_PUBLIC_ void s3replace_set_lp_ctx(struct loadparm_context *lp_ctx)
-{
-       s3replace_lp_ctx = lp_ctx;
-}
-
-_PUBLIC_ struct loadparm_context *s3replace_get_lp_ctx(void)
-{
-       return s3replace_lp_ctx;
-}
diff --git a/source4/s3compat/s3replace_public.h b/source4/s3compat/s3replace_public.h
deleted file mode 100644 (file)
index b009f59..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-
-struct loadparm_context;
-_PUBLIC_ void s3replace_set_lp_ctx(struct loadparm_context *lp_ctx);
-_PUBLIC_ struct loadparm_context *s3replace_get_lp_ctx(void);
index 7fef038fd7302c6002a11982fe1d225ae9d5b5dc..c72667244553614dfcf26ad3027d4dd00fbc1806 100644 (file)
@@ -735,7 +735,6 @@ SMBD_SRC_BASE = '''${LIBADS_SRC} ${SMBD_SRC_SRV}
 
                 ${SECRETS_SRC}
                 ${LIBSMBCONF_SRC}
-                smbd/server.c
                 '''
 
 PRINTING_SRC = '''printing/pcap.c printing/print_svid.c printing/print_aix.c
@@ -851,19 +850,32 @@ S3_SUBSYSTEM('LIBSMB',
                     deps='LIBSAMBA',
                     vars=locals())
 
+S3_SUBSYSTEM('S3_SERVER_LIBS',
+                    source=S3_SERVER_LIBS_SRC,
+                    deps = 'NDR_STANDARD',
+             vars=locals())
+
 
 bld.SAMBA_SUBSYSTEM('s3_smbd',
                     bld.SUBDIR('../../source3', SMBD_SRC),
                     includes=SAMBA3_INCLUDES,
                     deps='''tdb tevent popt dl
                     crypt nsl resolv z PASSDB
-                    PARAM_WITHOUT_REG LIBS LIBSMB''',
+                    PARAM_WITHOUT_REG LIBS LIBSMB S3_SERVER_LIBS''',
+                    hide_symbols=True)
+
+bld.SAMBA_SUBSYSTEM('s3_winbind',
+                    bld.SUBDIR('../../source3', WINBINDD_SRC),
+                    includes=SAMBA3_INCLUDES,
+                    deps='''tdb tevent popt dl
+                    crypt nsl resolv z PASSDB
+                    PARAM_WITHOUT_REG LIBS LIBSMB S3_SERVER_LIBS''',
                     hide_symbols=True)
 
 bld.SAMBA_SUBSYSTEM('s3compat_wrapper',
                     includes=SAMBA3_INCLUDES,
-                    autoproto='s3compat.h',
                     source='s3compat.c auth_samba4.c',
+                    autoproto='s3compat_wrapper_proto.h',
                     deps='tdb tevent',
                     hide_symbols=True)
 
@@ -876,7 +888,7 @@ bld.SAMBA_SUBSYSTEM('s3replace',
 
 bld.SAMBA_LIBRARY('s3compatcore',
                   source=[],
-                  deps='s3replace s3compat_wrapper LIBSECURITY_COMMON LIBCRYPTO LIBSAMBA-UTIL s3_smbd HEIMDAL_GSSAPI HEIMDAL_COM_ERR lber ldap tdb tevent talloc',
+                  deps='s3replace s3compat_wrapper LIBSECURITY_COMMON LIBCRYPTO LIBSAMBA-UTIL s3_smbd s3_winbind HEIMDAL_GSSAPI HEIMDAL_COM_ERR lber ldap tdb tevent talloc',
                   hide_symbols=True)
 
 bld.SAMBA_SUBSYSTEM('s3compat_authenticate',
@@ -884,8 +896,12 @@ bld.SAMBA_SUBSYSTEM('s3compat_authenticate',
                     autoproto='s3compat_authenticate.h',
                     deps='auth')
 
+bld.SAMBA_SUBSYSTEM('s3compat_globals',
+                    source='s3compat_globals.c',
+                    autoproto='s3compat_globals_proto.h')
+
 bld.SAMBA_SUBSYSTEM('s3compat',
-                    source='s3_smbd.c',
-                    deps='s3compatcore s3compat_authenticate',
-                    autoproto='s3_smbd_proto.h',
+                    source='s3_smbd.c s3_winbind.c',
+                    deps='s3compatcore s3compat_authenticate s3compat_globals',
+                    autoproto='s3compat_proto.h',
                     hide_symbols=True)