s4:s3compat Provide replacement machine_sid functions based on LDB
authorAndrew Bartlett <abartlet@samba.org>
Thu, 6 May 2010 06:49:49 +0000 (16:49 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 3 Jun 2010 01:12:34 +0000 (11:12 +1000)
This ensures that Samba3 has the right machine sid at all times.

Andrew Bartlett

source4/s3compat/machine_sid.c [new file with mode: 0644]
source4/s3compat/s3compat.c
source4/s3compat/wscript_build

diff --git a/source4/s3compat/machine_sid.c b/source4/s3compat/machine_sid.c
new file mode 100644 (file)
index 0000000..a02e768
--- /dev/null
@@ -0,0 +1,73 @@
+/* 
+   Unix SMB/CIFS implementation.
+   Password and authentication handling
+   Copyright (C) Jeremy Allison                1996-2002
+   Copyright (C) Andrew Tridgell               2002
+   Copyright (C) Gerald (Jerry) Carter         2000
+   Copyright (C) Stefan (metze) Metzmacher     2002
+
+   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 "auth/auth.h"
+#include "auth/auth_sam_reply.h"
+#include "s3_smbd_proto.h"
+#include "smbd/service.h"
+#include "libcli/security/dom_sid.h"
+#include "dsdb/samdb/samdb.h"
+
+/* NOTE! the global_sam_sid is the SID of our local SAM. This is only
+   equal to the domain SID when we are a DC, otherwise its our
+   workstation SID */
+
+/****************************************************************************
+ Read a SID from a file. This is for compatibility with the old MACHINE.SID
+ style of SID storage
+****************************************************************************/
+/* return our global_sam_sid */
+_PUBLIC_ const struct dom_sid *get_global_sam_sid(void)
+{
+
+       struct stream_connection *samba3_conn = s3compat_get_conn();
+       struct ldb_context *samdb = samdb_connect(samba3_conn, samba3_conn->event.ctx, samba3_conn->lp_ctx, system_session(samba3_conn->lp_ctx));
+
+       return samdb_domain_sid(samdb);
+}
+
+/** 
+ * Force get_global_sam_sid to requery the backends 
+ */
+_PUBLIC_ void reset_global_sam_sid(void) 
+{
+       
+}
+
+/*****************************************************************
+ Check if the SID is our domain SID (S-1-5-21-x-y-z).
+*****************************************************************/  
+
+_PUBLIC_ bool sid_check_is_domain(const struct dom_sid *sid)
+{
+       return dom_sid_equal(sid, get_global_sam_sid());
+}
+
+/*****************************************************************
+ Check if the SID is our domain SID (S-1-5-21-x-y-z).
+*****************************************************************/  
+
+_PUBLIC_ bool sid_check_is_in_our_domain(const struct dom_sid *sid)
+{
+       return dom_sid_in_domain(get_global_sam_sid(), sid);
+}
index 7307cc90ba25b9e46111e99c9f186fdf8cbb977e..52aece0b4093c690126b64cc4473ece5b97f9c2d 100644 (file)
@@ -57,7 +57,6 @@ void s3compat_initialise(const char *config_file, bool interactive)
        serverid_parent_init();
        namecache_enable();
        print_backend_init(smbd_messaging_context());
-       init_guest_info();
        share_info_db_init();
 
        /* Register our 'imposter' auth module, which redirects to samba4 */
@@ -92,5 +91,7 @@ _PUBLIC_
 void s3compat_smbd_process(void)
 {
        void smbd_process(void);
+       /* This needs samba3_conn to be set up first, so run per-connection */
+       init_guest_info();
        smbd_process();
 }
index 0bd7af521658b330ba3476a9a9966e4b4762cc02..7fef038fd7302c6002a11982fe1d225ae9d5b5dc 100644 (file)
@@ -410,7 +410,7 @@ PASSDB_GET_SET_SRC = '''passdb/pdb_get_set.c'''
 PDB_STATIC = 'passdb/pdb_tdb.c'
 
 PASSDB_MODULES_SRC = '''passdb/pdb_wbc_sam.c passdb/pdb_ads.c
-passdb/pdb_smbpasswd.c passdb/secrets.c passdb/machine_sid.c'''
+passdb/pdb_smbpasswd.c passdb/secrets.c'''
 #passdb/pdb_ldap.c passdb/pdb_nds.c'''
 
 PASSDB_SRC = '''${PASSDB_GET_SET_SRC} passdb/passdb.c passdb/pdb_interface.c
@@ -880,7 +880,7 @@ bld.SAMBA_LIBRARY('s3compatcore',
                   hide_symbols=True)
 
 bld.SAMBA_SUBSYSTEM('s3compat_authenticate',
-                    source='s3compat_authenticate.c',
+                    source='s3compat_authenticate.c machine_sid.c',
                     autoproto='s3compat_authenticate.h',
                     deps='auth')