Merge branch 'master' of ssh://git.samba.org/data/git/samba
authorAndrew Tridgell <tridge@samba.org>
Thu, 28 May 2009 12:12:00 +0000 (22:12 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 28 May 2009 12:12:00 +0000 (22:12 +1000)
lib/tdb/common/transaction.c
lib/tdb/tools/tdbbackup.c
source4/auth/sam.c
source4/dsdb/schema/schema_set.c
source4/lib/ldb/ldb_tdb/ldb_index.c
source4/lib/ldb/ldb_tdb/ldb_search.c

index cb723ed1343e9e08be09f93afcfd6fc3564564bb..f5c04a69cc01e8abecf5c53d6ac92aed7ae68d4b 100644 (file)
@@ -522,6 +522,10 @@ fail:
 */
 static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t length)
 {      
+       if (tdb->flags & TDB_NOSYNC) {
+               return 0;
+       }
+
        if (fsync(tdb->fd) != 0) {
                tdb->ecode = TDB_ERR_IO;
                TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n"));
@@ -1030,11 +1034,9 @@ int tdb_transaction_commit(struct tdb_context *tdb)
        SAFE_FREE(tdb->transaction->blocks);
        tdb->transaction->num_blocks = 0;
 
-       if (!(tdb->flags & TDB_NOSYNC)) {
-               /* ensure the new data is on disk */
-               if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
-                       return -1;
-               }
+       /* ensure the new data is on disk */
+       if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
+               return -1;
        }
 
        tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1);
index 83c0e16399e1e1792559882e7dec73ca623e32ee..6aca8dd99c50bfdcef1c26cd2bc4bd2e154fcaaa 100644 (file)
 
 static int failed;
 
+static struct tdb_logging_context log_ctx;
+
+#ifdef PRINTF_ATTRIBUTE
+static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4);
+#endif
+static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...)
+{
+       va_list ap;
+    
+       va_start(ap, format);
+       vfprintf(stdout, format, ap);
+       va_end(ap);
+       fflush(stdout);
+}
+
 static char *add_suffix(const char *name, const char *suffix)
 {
        char *ret;
@@ -107,7 +122,8 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
        }
 
        /* open the old tdb */
-       tdb = tdb_open(old_name, 0, 0, O_RDWR, 0);
+       tdb = tdb_open_ex(old_name, 0, 0, 
+                         O_RDWR, 0, &log_ctx, NULL);
        if (!tdb) {
                printf("Failed to open %s\n", old_name);
                free(tmp_name);
@@ -116,10 +132,11 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
 
        /* create the new tdb */
        unlink(tmp_name);
-       tdb_new = tdb_open(tmp_name,
-                          hash_size ? hash_size : tdb_hash_size(tdb),
-                          TDB_DEFAULT, O_RDWR|O_CREAT|O_EXCL, 
-                          st.st_mode & 0777);
+       tdb_new = tdb_open_ex(tmp_name, 
+                             hash_size ? hash_size : tdb_hash_size(tdb), 
+                             TDB_DEFAULT, 
+                             O_RDWR|O_CREAT|O_EXCL, st.st_mode & 0777, 
+                             &log_ctx, NULL);
        if (!tdb_new) {
                perror(tmp_name);
                free(tmp_name);
@@ -170,7 +187,11 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
 
        /* close the new tdb and re-open read-only */
        tdb_close(tdb_new);
-       tdb_new = tdb_open(tmp_name, 0, TDB_DEFAULT, O_RDONLY, 0);
+       tdb_new = tdb_open_ex(tmp_name, 
+                             0,
+                             TDB_DEFAULT, 
+                             O_RDONLY, 0,
+                             &log_ctx, NULL);
        if (!tdb_new) {
                fprintf(stderr,"failed to reopen %s\n", tmp_name);
                unlink(tmp_name);
@@ -211,7 +232,8 @@ static int verify_tdb(const char *fname, const char *bak_name)
        int count = -1;
 
        /* open the tdb */
-       tdb = tdb_open(fname, 0, 0, O_RDONLY, 0);
+       tdb = tdb_open_ex(fname, 0, 0, 
+                         O_RDONLY, 0, &log_ctx, NULL);
 
        /* traverse the tdb, then close it */
        if (tdb) {
@@ -264,6 +286,8 @@ static void usage(void)
        int hashsize = 0;
        const char *suffix = ".bak";
 
+       log_ctx.log_fn = tdb_log;
+
        while ((c = getopt(argc, argv, "vhs:n:")) != -1) {
                switch (c) {
                case 'h':
index ebdf1932af403c70f3e658566b96fb0e96c99a83..c70c02cb3c8bb6e8abcdd8981fdcb89c48a76ddc 100644 (file)
@@ -269,7 +269,6 @@ _PUBLIC_ NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_conte
        struct dom_sid *account_sid;
        struct dom_sid *primary_group_sid;
        const char *str;
-       struct ldb_dn *ncname;
        int i;
        uint_t rid;
        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
@@ -358,10 +357,10 @@ _PUBLIC_ NTSTATUS authsam_make_server_info(TALLOC_CTX *mem_ctx, struct ldb_conte
 
        server_info->allow_password_change
                = samdb_result_allow_password_change(sam_ctx, mem_ctx, 
-                                                    ncname, msg, "pwdLastSet");
+                                                    domain_dn, msg, "pwdLastSet");
        server_info->force_password_change
                = samdb_result_force_password_change(sam_ctx, mem_ctx, 
-                                                    ncname, msg);
+                                                    domain_dn, msg);
        
        server_info->logon_count = samdb_result_uint(msg, "logonCount", 0);
        server_info->bad_password_count = samdb_result_uint(msg, "badPwdCount", 0);
index dcaeb4fc89b06b58e01843ff0c7992d81e816627..b94993574c3edb3da45537a5fbaad9e9c9d3665c 100644 (file)
@@ -86,6 +86,11 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem
                goto op_error;
        }
 
+       ret = ldb_msg_add_string(msg_idx, "@IDXONE", "1");
+       if (ret != LDB_SUCCESS) {
+               goto op_error;
+       }
+
        for (attr = schema->attributes; attr; attr = attr->next) {
                const char *syntax = attr->syntax->ldb_syntax;
                
index c99c2936d850236720c070fcfe0435b26f0581e7..db0c31572e0f6a3c7a0f4a7f09871de3cd4f2856 100644 (file)
@@ -1121,14 +1121,10 @@ int ltdb_search_indexed(struct ltdb_context *ac)
 
        if (ac->scope != LDB_SCOPE_BASE && idxattr == 1) {
                ret = ltdb_index_dn(ac->module, ac->tree, ltdb->cache->indexlist, dn_list);
-
-               if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_OBJECT) {
-                       talloc_free(dn_list);
-                       return ret;
-               }
        }
 
-       if (ac->scope == LDB_SCOPE_ONELEVEL && idxone == 1) {
+       if (ret == LDB_ERR_OPERATIONS_ERROR &&
+           ac->scope == LDB_SCOPE_ONELEVEL && idxone == 1) {
                ret = ltdb_index_dn_one(ac->module, ac->base, dn_list);
        }
 
index d395c28f287a922e45bd1b85c88032445ed8777d..b307c5fb2f349d40cde4bd048934a2e3a8784686 100644 (file)
@@ -546,6 +546,13 @@ int ltdb_search(struct ltdb_context *ctx)
                 * callback error */
                if ( ! ctx->request_terminated && ret != LDB_SUCCESS) {
                        /* Not indexed, so we need to do a full scan */
+#if 0
+                       /* useful for debugging when slow performance
+                        * is caused by unindexed searches */
+                       char *expression = ldb_filter_from_tree(ctx, ctx->tree);
+                       printf("FULL SEARCH: %s\n", expression);
+                       talloc_free(expression);
+#endif
                        ret = ltdb_search_full(ctx);
                        if (ret != LDB_SUCCESS) {
                                ldb_set_errstring(ldb, "Indexed and full searches both failed!\n");