The branch, master has been updated
       via  6539cc8 lib/util/run_cmd: use a cleanup function instead of a 
destructor
       via  94a8331 lib/util/run_cmd: remove a printf
       via  4aaf072 lib/util/run_cmd: ensure fd_stdin gets set to -1 in the 
destructor
       via  9a8eeab lib/util/run_cmd: prevent zombies in samba_runcmd_send on 
timeout
       via  ac521c2 lib: Fix a signed/unsigned hickup
       via  197304c lib: Remove talloc_dict
       via  762fba4 winbind: Remove the use of "talloc_dict"
      from  3794fa0 Changes in samba vxfs plugin.

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


- Log -----------------------------------------------------------------
commit 6539cc8a24204697b20506896c401e7b40eee928
Author: Ralph Boehme <[email protected]>
Date:   Fri Sep 29 13:07:53 2017 +0200

    lib/util/run_cmd: use a cleanup function instead of a destructor
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13062
    
    Pair-programmed-with: Stefan Metzmacher <[email protected]>
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Signed-off-by: Ralph Boehme <[email protected]>
    
    Autobuild-User(master): Ralph Böhme <[email protected]>
    Autobuild-Date(master): Sat Sep 30 12:14:57 CEST 2017 on sn-devel-144

commit 94a8331e5425b735f9e2c0121afc2fb108bec891
Author: Ralph Boehme <[email protected]>
Date:   Fri Sep 29 13:07:26 2017 +0200

    lib/util/run_cmd: remove a printf
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13062
    
    Pair-programmed-with: Stefan Metzmacher <[email protected]>
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Signed-off-by: Ralph Boehme <[email protected]>

commit 4aaf072d1fd732abf2cbea135d508260cdafa4eb
Author: Ralph Boehme <[email protected]>
Date:   Fri Sep 29 13:06:08 2017 +0200

    lib/util/run_cmd: ensure fd_stdin gets set to -1 in the destructor
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13062
    
    Pair-programmed-with: Stefan Metzmacher <[email protected]>
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Signed-off-by: Ralph Boehme <[email protected]>

commit 9a8eeabd95afca2e88666b3e8f2af954dbf23ba9
Author: Ralph Boehme <[email protected]>
Date:   Fri Sep 29 12:45:24 2017 +0200

    lib/util/run_cmd: prevent zombies in samba_runcmd_send on timeout
    
    Ensure the state desctructor calls tfork_destroy to reap the waiter and
    worker processes. Otherwise we leave the waiter process as a zombie
    behind us as we never call waitpid on it in case of a timeout
    or talloc_free() from the caller.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=13062
    
    Pair-programmed-with: Stefan Metzmacher <[email protected]>
    
    Signed-off-by: Stefan Metzmacher <[email protected]>
    Signed-off-by: Ralph Boehme <[email protected]>

commit ac521c2d7d2db3835f62d92d77c2e8dfc71ea523
Author: Volker Lendecke <[email protected]>
Date:   Wed Aug 30 13:53:02 2017 +0200

    lib: Fix a signed/unsigned hickup
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 197304c922ea93aa615d245bb06ec1903f1c48c6
Author: Volker Lendecke <[email protected]>
Date:   Sun Aug 6 15:51:49 2017 +0200

    lib: Remove talloc_dict
    
    Looked like a good idea at its time, but its only user did not need
    it anyway
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 762fba44d71d194c1f3799a8d5b671c1366da142
Author: Volker Lendecke <[email protected]>
Date:   Sun Aug 6 15:49:01 2017 +0200

    winbind: Remove the use of "talloc_dict"
    
    As members we only collect names, indexed by sids. This is served
    well by just a simple dbwrap_rbt.
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

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

Summary of changes:
 lib/util/debug.c                     |   2 +-
 lib/util/util_runcmd.c               |  19 ++--
 source3/include/talloc_dict.h        |  60 ------------
 source3/lib/talloc_dict.c            | 177 -----------------------------------
 source3/selftest/tests.py            |   1 -
 source3/torture/torture.c            |  57 -----------
 source3/winbindd/wb_getgrsid.c       |  13 +--
 source3/winbindd/wb_group_members.c  |  60 ++++--------
 source3/winbindd/wb_next_grent.c     |   4 +-
 source3/winbindd/winbindd.h          |   2 -
 source3/winbindd/winbindd_getgrent.c |   4 +-
 source3/winbindd/winbindd_getgrgid.c |   2 +-
 source3/winbindd/winbindd_getgrnam.c |   2 +-
 source3/winbindd/winbindd_group.c    |  48 +++++-----
 source3/winbindd/winbindd_proto.h    |  17 ++--
 source3/wscript_build                |   1 -
 16 files changed, 77 insertions(+), 392 deletions(-)
 delete mode 100644 source3/include/talloc_dict.h
 delete mode 100644 source3/lib/talloc_dict.c


Changeset truncated at 500 lines:

diff --git a/lib/util/debug.c b/lib/util/debug.c
index 8b28002..6428550 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -628,7 +628,7 @@ utility lists registered debug class names's
 char *debug_list_class_names_and_levels(void)
 {
        char *buf = NULL;
-       unsigned int i;
+       int i;
        /* prepare strings */
        for (i = 0; i < debug_num_classes; i++) {
                buf = talloc_asprintf_append(buf,
diff --git a/lib/util/util_runcmd.c b/lib/util/util_runcmd.c
index 6077fdd..42d84a8 100644
--- a/lib/util/util_runcmd.c
+++ b/lib/util/util_runcmd.c
@@ -32,18 +32,21 @@
 #include "../lib/util/tfork.h"
 #include "../lib/util/sys_rw.h"
 
-static int samba_runcmd_state_destructor(struct samba_runcmd_state *state)
+static void samba_runcmd_cleanup_fn(struct tevent_req *req,
+                                   enum tevent_req_state req_state)
 {
-       if (state->pid > 0) {
-               kill(state->pid, SIGKILL);
-               waitpid(state->pid, NULL, 0);
-               state->pid = -1;
+       struct samba_runcmd_state *state = tevent_req_data(
+               req, struct samba_runcmd_state);
+
+       if (state->tfork != NULL) {
+               tfork_destroy(&state->tfork);
        }
+       state->pid = -1;
 
        if (state->fd_stdin != -1) {
                close(state->fd_stdin);
+               state->fd_stdin = -1;
        }
-       return 0;
 }
 
 static void samba_runcmd_io_handler(struct tevent_context *ev,
@@ -110,7 +113,6 @@ struct tevent_req *samba_runcmd_send(TALLOC_CTX *mem_ctx,
 
        state->tfork = tfork_create();
        if (state->tfork == NULL) {
-               printf("state->tfork == NULL\n");
                close(p1[0]);
                close(p1[1]);
                close(p2[0]);
@@ -141,7 +143,7 @@ struct tevent_req *samba_runcmd_send(TALLOC_CTX *mem_ctx,
                smb_set_close_on_exec(state->fd_stderr);
                smb_set_close_on_exec(state->fd_status);
 
-               talloc_set_destructor(state, samba_runcmd_state_destructor);
+               tevent_req_set_cleanup_fn(req, samba_runcmd_cleanup_fn);
 
                state->fde_stdout = tevent_add_fd(ev, state,
                                                  state->fd_stdout,
@@ -275,6 +277,7 @@ static void samba_runcmd_io_handler(struct tevent_context 
*ev,
                        tevent_req_error(req, errno);
                        return;
                }
+               state->pid = -1;
                TALLOC_FREE(fde);
 
                if (WIFEXITED(status)) {
diff --git a/source3/include/talloc_dict.h b/source3/include/talloc_dict.h
deleted file mode 100644
index 8305f8d..0000000
--- a/source3/include/talloc_dict.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-   Little dictionary style data structure based on dbwrap_rbt
-   Copyright (C) Volker Lendecke 2009
-
-   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/>.
-*/
-
-#ifndef __TALLOC_DICT_H__
-#define __TALLOC_DICT_H__
-
-#include "includes.h"
-
-struct talloc_dict;
-
-/*
- * Create a talloc_dict structure.
- */
-
-struct talloc_dict *talloc_dict_init(TALLOC_CTX *mem_ctx);
-
-/*
- * Add a talloced object to the dict. Nulls out the pointer to indicate that
- * the talloc ownership has been taken. If an object for "key" already exists,
- * the existing object is talloc_free()ed and overwritten by the new
- * object. If "data" is NULL, object for key "key" is deleted. Return false
- * for "no memory".
- */
-
-bool talloc_dict_set(struct talloc_dict *dict, DATA_BLOB key, void *data);
-
-/*
- * Fetch a talloced object. If "mem_ctx!=NULL", talloc_move the object there
- * and delete it from the dict.
- */
-
-void *talloc_dict_fetch(struct talloc_dict *dict, DATA_BLOB key,
-                       TALLOC_CTX *mem_ctx);
-
-/*
- * Traverse a talloc_dict. If "fn" returns non-null, quit the traverse
- */
-
-int talloc_dict_traverse(struct talloc_dict *dict,
-                        int (*fn)(DATA_BLOB key, void *data,
-                                  void *private_data),
-                        void *private_data);
-
-#endif
diff --git a/source3/lib/talloc_dict.c b/source3/lib/talloc_dict.c
deleted file mode 100644
index 7594679..0000000
--- a/source3/lib/talloc_dict.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-   Little dictionary style data structure based on dbwrap_rbt
-   Copyright (C) Volker Lendecke 2009
-
-   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 "dbwrap/dbwrap.h"
-#include "dbwrap/dbwrap_rbt.h"
-#include "talloc_dict.h"
-#include "util_tdb.h"
-
-struct talloc_dict {
-       struct db_context *db;
-};
-
-struct talloc_dict *talloc_dict_init(TALLOC_CTX *mem_ctx)
-{
-       struct talloc_dict *result;
-
-       result = talloc(mem_ctx, struct talloc_dict);
-       if (result == NULL) {
-               return NULL;
-       }
-       result->db = db_open_rbt(result);
-       if (result->db == NULL) {
-               TALLOC_FREE(result);
-               return NULL;
-       }
-       return result;
-}
-
-/*
- * Add a talloced object to the dict. Nulls out the pointer to indicate that
- * the talloc ownership has been taken. If an object for "key" already exists,
- * the existing object is talloc_free()ed and overwritten by the new
- * object. If "data" is NULL, object for key "key" is deleted. Return false
- * for "no memory".
- */
-
-bool talloc_dict_set(struct talloc_dict *dict, DATA_BLOB key, void *pdata)
-{
-       struct db_record *rec;
-       NTSTATUS status = NT_STATUS_OK;
-       void *data = *(void **)pdata;
-       TDB_DATA value;
-
-       rec = dbwrap_fetch_locked(dict->db, talloc_tos(),
-                                 make_tdb_data(key.data, key.length));
-       if (rec == NULL) {
-               return false;
-       }
-
-       value = dbwrap_record_get_value(rec);
-
-       if (value.dsize != 0) {
-               void *old_data;
-               if (value.dsize != sizeof(void *)) {
-                       TALLOC_FREE(rec);
-                       return false;
-               }
-               memcpy(&old_data, value.dptr, sizeof(old_data));
-               TALLOC_FREE(old_data);
-               if (data == NULL) {
-                       status = dbwrap_record_delete(rec);
-               }
-       }
-       if (data != NULL) {
-               void *mydata = talloc_move(dict->db, &data);
-               *(void **)pdata = NULL;
-               status = dbwrap_record_store(rec,
-                                            make_tdb_data((uint8_t *)&mydata,
-                                            sizeof(mydata)), 0);
-       }
-       TALLOC_FREE(rec);
-       return NT_STATUS_IS_OK(status);
-}
-
-/*
- * Fetch a talloced object. If "mem_ctx!=NULL", talloc_move the object there
- * and delete it from the dict.
- */
-
-void *talloc_dict_fetch(struct talloc_dict *dict, DATA_BLOB key,
-                       TALLOC_CTX *mem_ctx)
-{
-       struct db_record *rec;
-       void *result;
-       TDB_DATA value;
-
-       rec = dbwrap_fetch_locked(dict->db, talloc_tos(),
-                                 make_tdb_data(key.data, key.length));
-       if (rec == NULL) {
-               return NULL;
-       }
-
-       value = dbwrap_record_get_value(rec);
-       if (value.dsize != sizeof(void *)) {
-               TALLOC_FREE(rec);
-               return NULL;
-       }
-       result = *(void **)value.dptr;
-
-       if (mem_ctx != NULL) {
-               NTSTATUS status;
-               status = dbwrap_record_delete(rec);
-               if (!NT_STATUS_IS_OK(status)) {
-                       TALLOC_FREE(rec);
-                       return NULL;
-               }
-               result = talloc_move(mem_ctx, &result);
-       }
-
-       return result;
-}
-
-struct talloc_dict_traverse_state {
-       int (*fn)(DATA_BLOB key, void *data, void *private_data);
-       void *private_data;
-};
-
-static int talloc_dict_traverse_fn(struct db_record *rec, void *private_data)
-{
-       TDB_DATA key;
-       TDB_DATA value;
-       struct talloc_dict_traverse_state *state =
-               (struct talloc_dict_traverse_state *)private_data;
-       void *p;
-
-       key = dbwrap_record_get_key(rec);
-       value = dbwrap_record_get_value(rec);
-
-       if (value.dsize != sizeof(void *)) {
-               return -1;
-       }
-
-       memcpy(&p, value.dptr, sizeof(p));
-       return state->fn(data_blob_const(key.dptr, key.dsize),
-                        p, state->private_data);
-}
-
-/*
- * Traverse a talloc_dict. If "fn" returns non-null, quit the traverse
- */
-
-int talloc_dict_traverse(struct talloc_dict *dict,
-                        int (*fn)(DATA_BLOB key, void *data,
-                                  void *private_data),
-                        void *private_data)
-{
-       struct talloc_dict_traverse_state state;
-       NTSTATUS status;
-       int count = 0;
-
-       state.fn = fn;
-       state.private_data = private_data;
-       status = dbwrap_traverse(dict->db, talloc_dict_traverse_fn, &state,
-                                &count);
-       if (!NT_STATUS_IS_OK(status)) {
-               return -1;
-       } else {
-               return count;
-       }
-}
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 73479fc..1c40e7e 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -124,7 +124,6 @@ plantestsuite("samba3.smbtorture_s3.plain(%s).%s" % (env, 
t), env, [os.path.join
 local_tests = [
     "LOCAL-SUBSTITUTE",
     "LOCAL-GENCACHE",
-    "LOCAL-TALLOC-DICT",
     "LOCAL-BASE64",
     "LOCAL-RBTREE",
     "LOCAL-MEMCACHE",
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 4667517..bb4908f 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -31,7 +31,6 @@
 #include "dbwrap/dbwrap.h"
 #include "dbwrap/dbwrap_open.h"
 #include "dbwrap/dbwrap_rbt.h"
-#include "talloc_dict.h"
 #include "async_smb.h"
 #include "libsmb/libsmb.h"
 #include "libsmb/clirap.h"
@@ -10314,61 +10313,6 @@ failed:
        return false;
 }
 
-
-struct talloc_dict_test {
-       int content;
-};
-
-static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
-{
-       int *count = (int *)priv;
-       *count += 1;
-       return 0;
-}
-
-static bool run_local_talloc_dict(int dummy)
-{
-       struct talloc_dict *dict;
-       struct talloc_dict_test *t;
-       int key, count, res;
-       bool ok;
-
-       dict = talloc_dict_init(talloc_tos());
-       if (dict == NULL) {
-               return false;
-       }
-
-       t = talloc(talloc_tos(), struct talloc_dict_test);
-       if (t == NULL) {
-               return false;
-       }
-
-       key = 1;
-       t->content = 1;
-       ok = talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), &t);
-       if (!ok) {
-               return false;
-       }
-
-       count = 0;
-       res = talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count);
-       if (res == -1) {
-               return false;
-       }
-
-       if (count != 1) {
-               return false;
-       }
-
-       if (count != res) {
-               return false;
-       }
-
-       TALLOC_FREE(dict);
-
-       return true;
-}
-
 static bool run_local_string_to_sid(int dummy) {
        struct dom_sid sid;
 
@@ -11657,7 +11601,6 @@ static struct {
        { "PIDHIGH", run_pidhigh },
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
-       { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
        { "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 },
        { "LOCAL-DBWRAP-WATCH2", run_dbwrap_watch2, 0 },
        { "LOCAL-DBWRAP-DO-LOCKED1", run_dbwrap_do_locked1, 0 },
diff --git a/source3/winbindd/wb_getgrsid.c b/source3/winbindd/wb_getgrsid.c
index 8e0eac7..b210645 100644
--- a/source3/winbindd/wb_getgrsid.c
+++ b/source3/winbindd/wb_getgrsid.c
@@ -21,6 +21,7 @@
 #include "winbindd.h"
 #include "librpc/gen_ndr/ndr_winbind_c.h"
 #include "../libcli/security/security.h"
+#include "lib/dbwrap/dbwrap_rbt.h"
 
 struct wb_getgrsid_state {
        struct tevent_context *ev;
@@ -30,7 +31,7 @@ struct wb_getgrsid_state {
        const char *name;
        enum lsa_SidType type;
        gid_t gid;
-       struct talloc_dict *members;
+       struct db_context *members;
 };
 
 static void wb_getgrsid_lookupsid_done(struct tevent_req *subreq);
@@ -156,7 +157,7 @@ static void wb_getgrsid_sid2gid_done(struct tevent_req 
*subreq)
                        return;
                }
 
-               state->members = talloc_dict_init(state);
+               state->members = db_open_rbt(state);
                if (tevent_req_nomem(state->members, req)) {
                        return;
                }
@@ -169,11 +170,7 @@ static void wb_getgrsid_sid2gid_done(struct tevent_req 
*subreq)
                        return;
                }
 
-               status = add_wbint_Principal_to_dict(talloc_tos(),
-                                                    &state->sid,
-                                                    &name,
-                                                    state->type,
-                                                    state->members);
+               status = add_member_to_db(state->members, &state->sid, name);
                if (!NT_STATUS_IS_OK(status)) {
                        tevent_req_nterror(req, status);
                        return;
@@ -213,7 +210,7 @@ static void wb_getgrsid_got_members(struct tevent_req 
*subreq)
 
 NTSTATUS wb_getgrsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                          const char **domname, const char **name, gid_t *gid,
-                         struct talloc_dict **members)
+                         struct db_context **members)
 {
        struct wb_getgrsid_state *state = tevent_req_data(
                req, struct wb_getgrsid_state);
diff --git a/source3/winbindd/wb_group_members.c 
b/source3/winbindd/wb_group_members.c
index 5a20d87..7978b18 100644
--- a/source3/winbindd/wb_group_members.c
+++ b/source3/winbindd/wb_group_members.c
@@ -22,6 +22,9 @@
 #include "librpc/gen_ndr/ndr_winbind_c.h"
 #include "../librpc/gen_ndr/ndr_security.h"
 #include "../libcli/security/security.h"
+#include "lib/util/util_tdb.h"
+#include "lib/dbwrap/dbwrap.h"
+#include "lib/dbwrap/dbwrap_rbt.h"
 
 /*
  * We have 3 sets of routines here:
@@ -268,14 +271,14 @@ static NTSTATUS wb_groups_members_recv(struct tevent_req 
*req,
 
 /*
  * This is the routine expanding a list of groups up to a certain level. We
- * collect the users in a talloc_dict: We have to add them without duplicates,
- * and talloc_dict is an indexed (here indexed by SID) data structure.
+ * collect the users in a rbt database: We have to add them without duplicates,
+ * and the db is indexed by SID.
  */
 
 struct wb_group_members_state {
        struct tevent_context *ev;
        int depth;
-       struct talloc_dict *users;
+       struct db_context *users;
        struct wbint_Principal *groups;
 };
 
@@ -301,7 +304,7 @@ struct tevent_req *wb_group_members_send(TALLOC_CTX 
*mem_ctx,
        }
        state->ev = ev;


-- 
Samba Shared Repository

Reply via email to