The branch, master has been updated
       via  926e7a7 lib/replace: apply readline -Wstrict-prototypes workaround
       via  16cedcb lib/smbreadline: detect picky compile issue with readline.h
       via  4fc4e41 pam_wrapper: Use a constant string format specifier in test
       via  98b1bee pam_wrapper: use uintptr_t as base for const-discarding
       via  d97feb4 vfs_full_audit: make do_log() printf-aware
       via  2bf01b2 s4-torture: fix type of enum in various places
       via  559367e s4-torture: fix truncation warnings
       via  8990570 winbind_nss_freebsd: fix const discard warning
       via  786e3c1 pam_winbind: fix const discard warnings
       via  11c95b8 s3:torture: Fix building with -O3 and gcc 7
       via  8eb95bc schema_set: Add comment about set schema from ldif in a 
transaction
       via  17f1c6f schema: Make writing indices flag an enum for a new state
       via  84a7bae python:tests: Use bin/tdbdump only if built
      from  667335a build: ensure compiler flags are properly detected

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


- Log -----------------------------------------------------------------
commit 926e7a7cb46ef2b243f1247eee48c87ea546849b
Author: Uri Simchoni <[email protected]>
Date:   Sun Nov 19 20:22:33 2017 +0000

    lib/replace: apply readline -Wstrict-prototypes workaround
    
    clang -Wstrict-prototypes has issues with readline > 6.3.
    Fix suggested by Timur I. Bakeyev <[email protected]>
    
    cf. https://lists.gnu.org/archive/html/bug-readline/2014-04/msg00018.html
    cf. 
https://lists.samba.org/archive/samba-technical/2017-November/123923.html
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>
    
    Autobuild-User(master): Andrew Bartlett <[email protected]>
    Autobuild-Date(master): Fri Nov 24 05:16:10 CET 2017 on sn-devel-144

commit 16cedcb173da89a9d6f8894e6ff4a42158c5c3b2
Author: Uri Simchoni <[email protected]>
Date:   Thu Nov 23 22:20:52 2017 +0200

    lib/smbreadline: detect picky compile issue with readline.h
    
    readline.h has build issues with clang if -Wstrict-prototypes
    is enabled. Detect this and also detect whether the known
    workaround works.
    
    Fix suggested by Timur I. Bakeyev <[email protected]>
    
    cf. https://lists.gnu.org/archive/html/bug-readline/2014-04/msg00018.html
    cf. 
https://lists.samba.org/archive/samba-technical/2017-November/123923.html
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 4fc4e41760af91fb1fa28f6a9a8b1ee7e4d47dbc
Author: Uri Simchoni <[email protected]>
Date:   Wed Nov 22 20:48:23 2017 +0000

    pam_wrapper: Use a constant string format specifier in test
    
    This fixes a warning about non-constant format specifier.
    clang 4.0.0 warns against non-constant format specifier since
    it cannot validate the format against the parameters.
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>
    (ported from pam_wrapper 9265da3857e9cfa7a00d1ab35aae1e0b0286efad)

commit 98b1beee721c0ca32e10f4331e767d07be471dd3
Author: Uri Simchoni <[email protected]>
Date:   Sun Nov 19 13:08:30 2017 +0000

    pam_wrapper: use uintptr_t as base for const-discarding
    
    Seems like HAVE_INTPTR_T is not available on FreeBSD. Use
    the uintptr_t-base const discarding to avoid picky compiler
    warnings (other places in Samba also use uintptr_t).
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>
    (ported from pam_wrapper c611121eec7b5f2c39cab7b1c0295eddefdddb1d)

commit d97feb40e543dfc122569d4ac2dcb208ba661bc7
Author: Uri Simchoni <[email protected]>
Date:   Sun Nov 19 18:44:06 2017 +0000

    vfs_full_audit: make do_log() printf-aware
    
    Add PRINTF_ATTRIBUTE() to do_log(). This removes
    picky compiler warning about printf with variable
    format string, and adds compiler checks for the format
    strings supplied to do_log. This in turn spurred some
    warnings which are fixed.
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 2bf01b286c36e635b1ee0469c97394b6c075b3a3
Author: Uri Simchoni <[email protected]>
Date:   Sun Nov 19 17:54:32 2017 +0000

    s4-torture: fix type of enum in various places
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 559367ed60a316943d97a10a14ba11bcc01204c5
Author: Uri Simchoni <[email protected]>
Date:   Sun Nov 19 17:11:28 2017 +0000

    s4-torture: fix truncation warnings
    
    Fix various places where there is potential truncation
    while doing time / size calculations.
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 899057012187954179297e1b3ae110e717702eba
Author: Uri Simchoni <[email protected]>
Date:   Mon Nov 20 21:18:01 2017 +0200

    winbind_nss_freebsd: fix const discard warning
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 786e3c1d82fdb25510d4d257ec993e5b236f78b3
Author: Uri Simchoni <[email protected]>
Date:   Sun Nov 19 13:15:12 2017 +0000

    pam_winbind: fix const discard warnings
    
    Signed-off-by: Uri Simchoni <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 11c95b8c8dc8ba9db5b7a657ca1e77fac63b8cf0
Author: Andreas Schneider <[email protected]>
Date:   Thu Nov 23 17:10:42 2017 +0100

    s3:torture: Fix building with -O3 and gcc 7
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 8eb95bc1d1ef3d9f6eb41d628b8fb0c8f98cc3c6
Author: Garming Sam <[email protected]>
Date:   Wed Nov 22 12:46:31 2017 +1300

    schema_set: Add comment about set schema from ldif in a transaction
    
    This is normally called with a transaction or before access is shared.
    The python code and some tests may also cause an issue, but as these are
    fixed at runtime, this is only a temporary issue that resolves itself.
    
    Signed-off-by: Garming Sam <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 17f1c6f9f4c6d14c69d0d7030fcd919fbc0f6231
Author: Garming Sam <[email protected]>
Date:   Wed Nov 22 12:34:01 2017 +1300

    schema: Make writing indices flag an enum for a new state
    
    In schema_load_init, we find that the writing of indices is not locked
    in any way. This leads to race conditions. To resolve this, we need to
    have a new state (SCHEMA_COMPARE) which can report to the caller that we
    need to open a transaction to write the indices.
    
    Signed-off-by: Garming Sam <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

commit 84a7baeef30a41d51eff8e6486ed67ed3318b115
Author: Andreas Schneider <[email protected]>
Date:   Wed Nov 22 16:53:52 2017 +0100

    python:tests: Use bin/tdbdump only if built
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Andrew Bartlett <[email protected]>

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

Summary of changes:
 lib/pam_wrapper/python/pypamtest.c           | 16 +++----
 lib/replace/system/readline.h                |  3 ++
 libcli/smbreadline/wscript_configure         | 33 +++++++++++++++
 nsswitch/pam_winbind.c                       |  4 +-
 nsswitch/winbind_nss_freebsd.c               |  9 +++-
 python/samba/tests/registry.py               |  6 ++-
 source3/modules/vfs_full_audit.c             | 26 ++++++++----
 source3/torture/torture.c                    |  3 +-
 source4/dsdb/pydsdb.c                        |  2 +-
 source4/dsdb/repl/replicated_objects.c       | 14 +++----
 source4/dsdb/samdb/ldb_modules/schema_load.c | 63 ++++++++++++++++++++++++----
 source4/dsdb/schema/schema.h                 |  6 +++
 source4/dsdb/schema/schema_set.c             | 51 +++++++++++++++++++---
 source4/dsdb/schema/tests/schema_syntax.c    |  2 +-
 source4/libnet/libnet_vampire.c              |  4 +-
 source4/torture/basic/base.c                 |  6 +--
 source4/torture/drs/drs_util.c               |  2 +-
 source4/torture/raw/open.c                   |  2 +-
 source4/torture/raw/qfileinfo.c              |  2 +-
 source4/torture/raw/qfsinfo.c                |  5 ++-
 source4/torture/rpc/clusapi.c                |  2 +-
 source4/torture/smb2/ioctl.c                 |  4 +-
 source4/torture/smb2/replay.c                |  6 +--
 23 files changed, 210 insertions(+), 61 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/pam_wrapper/python/pypamtest.c 
b/lib/pam_wrapper/python/pypamtest.c
index a71fd35..e25900f 100644
--- a/lib/pam_wrapper/python/pypamtest.c
+++ b/lib/pam_wrapper/python/pypamtest.c
@@ -24,8 +24,8 @@
 #define PYTHON_MODULE_NAME  "pypamtest"
 
 #ifndef discard_const_p
-#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
-# define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr)))
+#if defined(__intptr_t_defined) || defined(HAVE_UINTPTR_T)
+# define discard_const_p(type, ptr) ((type *)((uintptr_t)(ptr)))
 #else
 # define discard_const_p(type, ptr) ((type *)(ptr))
 #endif
@@ -67,9 +67,9 @@ static PyObject *PyExc_PamTestError;
  *** helper functions
  **********************************************************/
 
-static const char *repr_fmt = "{ pam_operation [%d] "
-                             "expected_rv [%d] "
-                             "flags [%d] }";
+#define REPR_FMT "{ pam_operation [%d] " \
+                             "expected_rv [%d] " \
+                             "flags [%d] }"
 
 static char *py_strdup(const char *string)
 {
@@ -267,7 +267,7 @@ set_pypamtest_exception(PyObject *exc,
                        size_t num_tests)
 {
        PyObject *obj = NULL;
-       /* repr_fmt is fixed and contains just %d expansions, so this is safe */
+       /* REPR_FMT contains just %d expansions, so this is safe */
        char test_repr[256] = { '\0' };
        union {
                char *str;
@@ -286,7 +286,7 @@ set_pypamtest_exception(PyObject *exc,
        if (perr == PAMTEST_ERR_CASE) {
                failed = _pamtest_failed_case(tests, num_tests);
                if (failed) {
-                       snprintf(test_repr, sizeof(test_repr), repr_fmt,
+                       snprintf(test_repr, sizeof(test_repr), REPR_FMT,
                                 failed->pam_operation,
                                 failed->expected_rv,
                                 failed->flags);
@@ -422,7 +422,7 @@ static int TestCase_init(TestCaseObject *self,
  */
 static PyObject *TestCase_repr(TestCaseObject *self)
 {
-       return PyUnicode_FromFormat(repr_fmt,
+       return PyUnicode_FromFormat(REPR_FMT,
                                    self->pam_operation,
                                    self->expected_rv,
                                    self->flags);
diff --git a/lib/replace/system/readline.h b/lib/replace/system/readline.h
index e6b8fb9..5dc3e75 100644
--- a/lib/replace/system/readline.h
+++ b/lib/replace/system/readline.h
@@ -26,6 +26,9 @@
 
 #ifdef HAVE_LIBREADLINE
 #  ifdef HAVE_READLINE_READLINE_H
+#    ifdef HAVE_READLINE_READLINE_WORKAROUND
+#      define _FUNCTION_DEF
+#    endif
 #    include <readline/readline.h>
 #    ifdef HAVE_READLINE_HISTORY_H
 #      include <readline/history.h>
diff --git a/libcli/smbreadline/wscript_configure 
b/libcli/smbreadline/wscript_configure
index b4d1be2..912ff53 100644
--- a/libcli/smbreadline/wscript_configure
+++ b/libcli/smbreadline/wscript_configure
@@ -7,8 +7,38 @@ for termlib in ['ncurses', 'curses', 'termcap', 'terminfo', 
'termlib', 'tinfo']:
         conf.env['READLINE_TERMLIB'] = termlib
         break
 
+#
+# Check if we need to work around readline/readline.h
+# deprecated declarations
+#
+if conf.CONFIG_SET('HAVE_READLINE_READLINE_H'):
+    if not conf.CHECK_CODE('''
+                    #include <readline/readline.h>
+                    int main() {return 0;}
+                    ''',
+                    define='HAVE_WORKING_READLINE_READLINE_WITH_STRICT_PROTO',
+                    cflags=conf.env['WERROR_CFLAGS'] +
+                           ['-Wstrict-prototypes',
+                            '-Werror=strict-prototypes'],
+                    msg='for compiling <readline/readline.h> with strict 
prototypes',
+                    addmain=False):
+                conf.CHECK_CODE('''
+                    #define _FUNCTION_DEF
+                    #include <readline/readline.h>
+                    int main() {return 0;}
+                    ''',
+                    cflags=conf.env['WERROR_CFLAGS'] +
+                           ['-Wstrict-prototypes',
+                            '-Werror=strict-prototypes'],
+                    msg='for workaround to <readline/readline.h> strict 
prototypes issue',
+                    define='HAVE_READLINE_READLINE_WORKAROUND',
+                    addmain=False)
+
 conf.CHECK_CODE('''
 #ifdef HAVE_READLINE_READLINE_H
+#  ifdef HAVE_READLINE_READLINE_WORKAROUND
+#    define _FUNCTION_DEF
+#  endif
 #  include <readline/readline.h>
 #  ifdef HAVE_READLINE_HISTORY_H
 #    include <readline/history.h>
@@ -28,6 +58,9 @@ msg='Checking for rl_completion_t')
 
 conf.CHECK_CODE('''
 #ifdef HAVE_READLINE_READLINE_H
+#  ifdef HAVE_READLINE_READLINE_WORKAROUND
+#    define _FUNCTION_DEF
+#  endif
 #  include <readline/readline.h>
 #  ifdef HAVE_READLINE_HISTORY_H
 #    include <readline/history.h>
diff --git a/nsswitch/pam_winbind.c b/nsswitch/pam_winbind.c
index 4ae6464..3723b17 100644
--- a/nsswitch/pam_winbind.c
+++ b/nsswitch/pam_winbind.c
@@ -671,7 +671,7 @@ static int converse(const pam_handle_t *pamh,
                    struct pam_response **response)
 {
        int retval;
-       struct pam_conv *conv;
+       const struct pam_conv *conv;
 
        retval = pam_get_item(pamh, PAM_CONV, (const void **) &conv);
        if (retval == PAM_SUCCESS) {
@@ -2993,7 +2993,7 @@ static bool _pam_require_krb5_auth_after_chauthtok(struct 
pwb_context *ctx,
         * --- BoYang
         * */
 
-       char *new_authtok_reqd_during_auth = NULL;
+       const char *new_authtok_reqd_during_auth = NULL;
        struct passwd *pwd = NULL;
 
        pam_get_data(ctx->pamh, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH,
diff --git a/nsswitch/winbind_nss_freebsd.c b/nsswitch/winbind_nss_freebsd.c
index 476349f..e283872 100644
--- a/nsswitch/winbind_nss_freebsd.c
+++ b/nsswitch/winbind_nss_freebsd.c
@@ -129,8 +129,13 @@ __freebsd_getgroupmembership(void *retval, void *mdata, 
va_list ap)
        /* insert primary membership(possibly already there) */
        gr_addgid(group, groups, maxgrp, groupc);
        /* Don't limit number of groups, we want to know total size */
-       ret = _nss_winbind_initgroups_dyn(uname, group, &lcount, &lsize,
-               &tmpgroups, 0, &errnop);
+       ret = _nss_winbind_initgroups_dyn(discard_const(uname),
+                                         group,
+                                         &lcount,
+                                         &lsize,
+                                         &tmpgroups,
+                                         0,
+                                         &errnop);
        if (ret == NSS_STATUS_SUCCESS) {
                /* lcount potentially can be bigger than maxgrp, so would 
groupc */
                for (i = 0; i < lcount; i++)
diff --git a/python/samba/tests/registry.py b/python/samba/tests/registry.py
index 1a8a126..f6af5f7 100644
--- a/python/samba/tests/registry.py
+++ b/python/samba/tests/registry.py
@@ -56,7 +56,11 @@ class HiveTests(samba.tests.TestCaseInTempDir):
         self.assertIsNone(self.hive.set_value('foo2', 1, 'bar2'))
         self.assertIsNone(self.hive.flush())
 
-        proc = Popen(['bin/tdbdump', self.hive_path], stdout=PIPE, stderr=PIPE)
+        tdbdump_tool = 'tdbdump'
+        if os.path.isfile('bin/tdbdump'):
+            tdbdump_tool = 'bin/tdbdump'
+
+        proc = Popen([tdbdump_tool, self.hive_path], stdout=PIPE, stderr=PIPE)
         tdb_dump, err = proc.communicate()
         self.assertTrue(b'DN=VALUE=FOO2,HIVE=NONE' in tdb_dump)
 
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index b847159..fbe1715 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -521,6 +521,9 @@ static TALLOC_CTX *do_log_ctx(void)
 }
 
 static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
+                  const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
+
+static void do_log(vfs_op_type op, bool success, vfs_handle_struct *handle,
                   const char *format, ...)
 {
        struct vfs_full_audit_private_data *pd;
@@ -1411,7 +1414,7 @@ static uint64_t 
smb_full_audit_get_alloc_size(vfs_handle_struct *handle,
        result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
 
        do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
-                       "%llu", result);
+                       "%llu", (unsigned long long)result);
 
        return result;
 }
@@ -1783,7 +1786,10 @@ static NTSTATUS smb_full_audit_brl_lock_windows(struct 
vfs_handle_struct *handle
        do_log(SMB_VFS_OP_BRL_LOCK_WINDOWS, NT_STATUS_IS_OK(result), handle,
            "%s:%llu-%llu. type=%d. blocking=%d",
               fsp_str_do_log(brl_fsp(br_lck)),
-           plock->start, plock->size, plock->lock_type, blocking_lock);
+              (unsigned long long)plock->start,
+              (unsigned long long)plock->size,
+              plock->lock_type,
+              blocking_lock);
 
        return result;
 }
@@ -1800,8 +1806,9 @@ static bool smb_full_audit_brl_unlock_windows(struct 
vfs_handle_struct *handle,
 
        do_log(SMB_VFS_OP_BRL_UNLOCK_WINDOWS, (result == 0), handle,
               "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
-              plock->start,
-           plock->size, plock->lock_type);
+              (unsigned long long)plock->start,
+              (unsigned long long)plock->size,
+              plock->lock_type);
 
        return result;
 }
@@ -1816,8 +1823,9 @@ static bool smb_full_audit_brl_cancel_windows(struct 
vfs_handle_struct *handle,
 
        do_log(SMB_VFS_OP_BRL_CANCEL_WINDOWS, (result == 0), handle,
               "%s:%llu-%llu:%d", fsp_str_do_log(brl_fsp(br_lck)),
-              plock->start,
-           plock->size, plock->lock_type);
+              (unsigned long long)plock->start,
+              (unsigned long long)plock->size,
+              plock->lock_type);
 
        return result;
 }
@@ -1831,8 +1839,10 @@ static bool smb_full_audit_strict_lock_check(struct 
vfs_handle_struct *handle,
        result = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
 
        do_log(SMB_VFS_OP_STRICT_LOCK_CHECK, result, handle,
-           "%s:%llu-%llu:%d", fsp_str_do_log(fsp), plock->start,
-           plock->size, plock->lock_type);
+              "%s:%llu-%llu:%d", fsp_str_do_log(fsp),
+              (unsigned long long)plock->start,
+              (unsigned long long)plock->size,
+              plock->lock_type);
 
        return result;
 }
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index f3da67c..5a29f79 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -1478,7 +1478,8 @@ static bool tcon_devtest(struct cli_state *cli,
 
        if (NT_STATUS_IS_OK(expected_error)) {
                if (NT_STATUS_IS_OK(status)) {
-                       if (strcmp(cli->dev, return_devtype) == 0) {
+                       if (return_devtype != NULL &&
+                           strequal(cli->dev, return_devtype)) {
                                ret = True;
                        } else { 
                                printf("tconX to share %s with type %s "
diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c
index 09623a6..4d811b0 100644
--- a/source4/dsdb/pydsdb.c
+++ b/source4/dsdb/pydsdb.c
@@ -919,7 +919,7 @@ static PyObject *py_dsdb_set_schema_from_ldb(PyObject 
*self, PyObject *args)
        struct ldb_context *from_ldb;
        struct dsdb_schema *schema;
        int ret;
-       char write_indices_and_attributes = true;
+       char write_indices_and_attributes = SCHEMA_WRITE;
        if (!PyArg_ParseTuple(args, "OO|b",
                              &py_ldb, &py_from_ldb, 
&write_indices_and_attributes))
                return NULL;
diff --git a/source4/dsdb/repl/replicated_objects.c 
b/source4/dsdb/repl/replicated_objects.c
index d9365ae..0c44960 100644
--- a/source4/dsdb/repl/replicated_objects.c
+++ b/source4/dsdb/repl/replicated_objects.c
@@ -867,7 +867,7 @@ WERROR dsdb_replicated_objects_commit(struct ldb_context 
*ldb,
                cur_schema = dsdb_get_schema(ldb, tmp_ctx);
                used_global_schema = dsdb_uses_global_schema(ldb);
 
-               ret = dsdb_reference_schema(ldb, working_schema, false);
+               ret = dsdb_reference_schema(ldb, working_schema, 
SCHEMA_MEMORY_ONLY);
                if (ret != LDB_SUCCESS) {
                        DEBUG(0,(__location__ "Failed to reference working 
schema - %s\n",
                                 ldb_strerror(ret)));
@@ -884,7 +884,7 @@ WERROR dsdb_replicated_objects_commit(struct ldb_context 
*ldb,
                if (used_global_schema) { 
                        dsdb_set_global_schema(ldb);
                } else if (cur_schema) {
-                       dsdb_reference_schema(ldb, cur_schema, false);
+                       dsdb_reference_schema(ldb, cur_schema, 
SCHEMA_MEMORY_ONLY);
                }
 
                if (W_ERROR_EQUAL(objects->error, WERR_DS_DRA_RECYCLED_TARGET)) 
{
@@ -917,7 +917,7 @@ WERROR dsdb_replicated_objects_commit(struct ldb_context 
*ldb,
                        if (used_global_schema) { 
                                dsdb_set_global_schema(ldb);
                        } else if (cur_schema ) {
-                               dsdb_reference_schema(ldb, cur_schema, false);
+                               dsdb_reference_schema(ldb, cur_schema, 
SCHEMA_MEMORY_ONLY);
                        }
                        DEBUG(0,("Failed to save updated prefixMap: %s\n",
                                 win_errstr(werr)));
@@ -932,7 +932,7 @@ WERROR dsdb_replicated_objects_commit(struct ldb_context 
*ldb,
                if (used_global_schema) { 
                        dsdb_set_global_schema(ldb);
                } else if (cur_schema ) {
-                       dsdb_reference_schema(ldb, cur_schema, false);
+                       dsdb_reference_schema(ldb, cur_schema, 
SCHEMA_MEMORY_ONLY);
                }
                DEBUG(0,(__location__ " Failed to prepare commit of 
transaction: %s\n",
                         ldb_errstring(ldb)));
@@ -946,7 +946,7 @@ WERROR dsdb_replicated_objects_commit(struct ldb_context 
*ldb,
                if (used_global_schema) { 
                        dsdb_set_global_schema(ldb);
                } else if (cur_schema ) {
-                       dsdb_reference_schema(ldb, cur_schema, false);
+                       dsdb_reference_schema(ldb, cur_schema, 
SCHEMA_MEMORY_ONLY);
                }
                DEBUG(0,(__location__ " Failed to load partition uSN\n"));
                ldb_transaction_cancel(ldb);
@@ -960,7 +960,7 @@ WERROR dsdb_replicated_objects_commit(struct ldb_context 
*ldb,
                if (used_global_schema) { 
                        dsdb_set_global_schema(ldb);
                } else if (cur_schema ) {
-                       dsdb_reference_schema(ldb, cur_schema, false);
+                       dsdb_reference_schema(ldb, cur_schema, 
SCHEMA_MEMORY_ONLY);
                }
                DEBUG(0,(__location__ " Failed to commit transaction\n"));
                TALLOC_FREE(tmp_ctx);
@@ -1005,7 +1005,7 @@ WERROR dsdb_replicated_objects_commit(struct ldb_context 
*ldb,
                                new_schema != NULL ?
                                new_schema->metadata_usn : 0,
                                working_schema, working_schema->metadata_usn);
-                       dsdb_reference_schema(ldb, cur_schema, false);
+                       dsdb_reference_schema(ldb, cur_schema, 
SCHEMA_MEMORY_ONLY);
                        if (used_global_schema) {
                                dsdb_set_global_schema(ldb);
                        }
diff --git a/source4/dsdb/samdb/ldb_modules/schema_load.c 
b/source4/dsdb/samdb/ldb_modules/schema_load.c
index b3313b4..4013cdf 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_load.c
+++ b/source4/dsdb/samdb/ldb_modules/schema_load.c
@@ -246,7 +246,7 @@ static struct dsdb_schema *dsdb_schema_refresh(struct 
ldb_module *module, struct
                return schema;
        }
 
-       ret = dsdb_set_schema(ldb, new_schema, false);
+       ret = dsdb_set_schema(ldb, new_schema, SCHEMA_MEMORY_ONLY);
        if (ret != LDB_SUCCESS) {
                ldb_debug_set(ldb, LDB_DEBUG_FATAL,
                              "dsdb_set_schema() failed: %d:%s: %s",
@@ -359,7 +359,8 @@ failed:
 }      
 
 static int schema_load(struct ldb_context *ldb,
-                      struct ldb_module *module)
+                      struct ldb_module *module,
+                      bool *need_write)
 {
        struct dsdb_schema *schema;
        void *readOnlySchema;
@@ -406,7 +407,7 @@ static int schema_load(struct ldb_context *ldb,
                }
 
                /* "dsdb_set_schema()" steals schema into the ldb_context */
-               ret = dsdb_set_schema(ldb, new_schema, false);
+               ret = dsdb_set_schema(ldb, new_schema, SCHEMA_MEMORY_ONLY);
                if (ret != LDB_SUCCESS) {
                        ldb_debug_set(ldb, LDB_DEBUG_FATAL,
                                      "schema_load_init: dsdb_set_schema() 
failed: %d:%s: %s",
@@ -444,7 +445,14 @@ static int schema_load(struct ldb_context *ldb,
 
        /* Now check the @INDEXLIST is correct, or fix it up */
        ret = dsdb_schema_set_indices_and_attributes(ldb, schema,
-                                                    true);
+                                                    SCHEMA_COMPARE);
+       if (ret == LDB_ERR_BUSY) {
+               *need_write = true;
+               ret = LDB_SUCCESS;
+       } else {
+               *need_write = false;
+       }
+
        if (ret != LDB_SUCCESS) {
                ldb_asprintf_errstring(ldb, "Failed to update "
                                       "@INDEXLIST and @ATTRIBUTES "
@@ -463,6 +471,7 @@ static int schema_load_init(struct ldb_module *module)
        struct ldb_context *ldb = ldb_module_get_ctx(module);
        struct schema_load_private_data *private_data;
        int ret;
+       bool need_write = false;
 
        private_data = talloc_zero(module, struct schema_load_private_data);
        if (private_data == NULL) {
@@ -477,11 +486,49 @@ static int schema_load_init(struct ldb_module *module)
                return ret;
        }
 
-       ret = schema_load(ldb, module);
-       if (ret != LDB_SUCCESS) {
-               return ret;
+       ret = schema_load(ldb, module, &need_write);
+
+       if (ret == LDB_SUCCESS && need_write) {
+               TALLOC_CTX *frame = talloc_stackframe();
+               struct dsdb_schema *schema = NULL;
+
+               ret = ldb_transaction_start(ldb);
+               if (ret != LDB_SUCCESS) {
+                       ldb_debug_set(ldb, LDB_DEBUG_FATAL,
+                                     "schema_load_init: transaction start 
failed");
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+
+               schema = dsdb_get_schema(ldb, frame);
+               if (schema == NULL) {
+                       ldb_debug_set(ldb, LDB_DEBUG_FATAL,
+                                     "schema_load_init: dsdb_get_schema 
failed");
+                       ldb_transaction_cancel(ldb);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+               ret = dsdb_schema_set_indices_and_attributes(ldb, schema,
+                                                            SCHEMA_WRITE);
+
+               TALLOC_FREE(frame);
+
+               if (ret != LDB_SUCCESS) {
+                       ldb_asprintf_errstring(ldb, "Failed to write new "
+                                              "@INDEXLIST and @ATTRIBUTES "
+                                              "records for updated schema: %s",
+                                              ldb_errstring(ldb));
+                       ldb_transaction_cancel(ldb);
+                       return ret;
+               }
+
+               ret = ldb_transaction_commit(ldb);
+               if (ret != LDB_SUCCESS) {
+                       ldb_debug_set(ldb, LDB_DEBUG_FATAL,
+                                     "schema_load_init: transaction commit 
failed");
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
        }
 
+
        return ret;
 }
 
@@ -549,7 +596,7 @@ static int schema_load_extended(struct ldb_module *module, 
struct ldb_request *r
 
        ret = dsdb_schema_set_indices_and_attributes(ldb,
                                                     schema,
-                                                    true);
+                                                    SCHEMA_WRITE);
 
        if (ret != LDB_SUCCESS) {
                ldb_asprintf_errstring(ldb, "Failed to write new "
diff --git a/source4/dsdb/schema/schema.h b/source4/dsdb/schema/schema.h
index 75e4886..9b27fd2 100644
--- a/source4/dsdb/schema/schema.h
+++ b/source4/dsdb/schema/schema.h
@@ -192,6 +192,12 @@ struct dsdb_class {
        } tmp;
 };
 
+enum schema_set_enum {
+       SCHEMA_MEMORY_ONLY = 0,
+       SCHEMA_WRITE = 1,
+       SCHEMA_COMPARE = 2,
+};
+
 /**
  * data stored in schemaInfo attribute
  */
diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c
index ca7a307..226e31e 100644
--- a/source4/dsdb/schema/schema_set.c
+++ b/source4/dsdb/schema/schema_set.c
@@ -58,7 +58,7 @@ const struct ldb_schema_attribute 
*dsdb_attribute_handler_override(struct ldb_co
  */
 int dsdb_schema_set_indices_and_attributes(struct ldb_context *ldb,
                                           struct dsdb_schema *schema,
-                                          bool write_indices_and_attributes)
+                                          enum schema_set_enum mode)
 {
        int ret = LDB_SUCCESS;
        struct ldb_result *res;
@@ -80,7 +80,7 @@ int dsdb_schema_set_indices_and_attributes(struct ldb_context 
*ldb,
                ldb_schema_set_override_GUID_index(ldb, "objectGUID", "GUID");
        }
 
-       if (!write_indices_and_attributes) {


-- 
Samba Shared Repository

Reply via email to