The branch, master has been updated
       via  dba03a6 s3:registry: change reg_import.c according to coding 
guidelines.
       via  7bc1172 s3:registry: use TALLOC_CTX * instead of const void * in 
reg_import_adapter()
       via  c4be17f s3: add a tool "cclean" to cleanup orphaned entries from 
connections.tdb
       via  088e505 s3:conn_tdb: add a function connections_fetch_entry_ext() 
that also takes the cnum
       via  c71062f s3:lib:dbwrap: fix return value of db_ctdb_traverse[_read] 
for non-persistent dbs
      from  082b906 s3-printing: fix broken print_job_get_name() return

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


- Log -----------------------------------------------------------------
commit dba03a644d9e9211d4876597a51a83656fc5b625
Author: Michael Adam <[email protected]>
Date:   Wed Jun 27 08:20:59 2012 +0200

    s3:registry: change reg_import.c according to coding guidelines.
    
    Autobuild-User(master): Michael Adam <[email protected]>
    Autobuild-Date(master): Wed Jun 27 10:07:54 CEST 2012 on sn-devel-104

commit 7bc1172c5f36619fad2acd5a863054b472a036e8
Author: Michael Adam <[email protected]>
Date:   Wed Jun 27 08:20:31 2012 +0200

    s3:registry: use TALLOC_CTX * instead of const void * in 
reg_import_adapter()

commit c4be17f804a857630b4c5f9d0aad70b508e56e2e
Author: Gregor Beck <[email protected]>
Date:   Thu Jun 7 13:34:35 2012 +0200

    s3: add a tool "cclean" to cleanup orphaned entries from connections.tdb
    
    Signed-off-by: Michael Adam <[email protected]>

commit 088e505e84c18709a30301aa410792f5a434c27d
Author: Gregor Beck <[email protected]>
Date:   Thu Jun 7 13:25:17 2012 +0200

    s3:conn_tdb: add a function connections_fetch_entry_ext() that also takes 
the cnum
    
    and have connections_fetch_entry() call connections_fetch_entry_ext().
    
    Signed-off-by: Michael Adam <[email protected]>

commit c71062fcf4ca192e94ecd32268f79e2bef19428a
Author: Gregor Beck <[email protected]>
Date:   Tue Jun 12 10:10:36 2012 +0200

    s3:lib:dbwrap: fix return value of db_ctdb_traverse[_read] for 
non-persistent dbs
    
    to return the number of traversed records upon successful traverse.
    
    Signed-off-by: Michael Adam <[email protected]>

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

Summary of changes:
 source3/Makefile.in              |   13 ++-
 source3/lib/conn_tdb.c           |   20 ++-
 source3/lib/conn_tdb.h           |    4 +
 source3/lib/dbwrap/dbwrap_ctdb.c |   23 ++-
 source3/registry/reg_import.c    |  102 ++++++-------
 source3/registry/reg_import.h    |    2 +-
 source3/utils/cclean.c           |  300 ++++++++++++++++++++++++++++++++++++++
 source3/wscript_build            |   12 ++
 8 files changed, 409 insertions(+), 67 deletions(-)
 create mode 100644 source3/utils/cclean.c


Changeset truncated at 500 lines:

diff --git a/source3/Makefile.in b/source3/Makefile.in
index 148de92..41f6683 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -212,7 +212,7 @@ SBIN_PROGS = bin/smbd bin/nmbd @SWAT_SBIN_TARGETS@ 
@EXTRA_SBIN_PROGS@
 
 BIN_PROGS1 = bin/smbclient bin/net bin/smbspool \
        bin/testparm bin/smbstatus bin/smbget \
-       bin/smbta-util
+       bin/smbta-util bin/cclean
 BIN_PROGS2 = bin/smbcontrol bin/smbtree $(TDBBACKUP) \
        bin/nmblookup bin/pdbedit $(TDBDUMP) \
        $(TDBRESTORE) $(TDBTOOL) bin/dbwrap_tool
@@ -1049,6 +1049,12 @@ STATUS_OBJ = utils/status.o utils/status_profile.o \
              $(PROFILE_OBJ) $(LIB_NONSMBD_OBJ) $(POPT_LIB_OBJ) \
             $(LIBSMB_ERR_OBJ) $(FNAME_UTIL_OBJ)
 
+CCLEAN_OBJ = utils/cclean.o utils/interact.o \
+       $(LOCKING_OBJ) $(PARAM_OBJ) \
+        $(PROFILE_OBJ) $(LIB_NONSMBD_OBJ) $(POPT_LIB_OBJ) \
+        $(LIBSMB_ERR_OBJ) $(FNAME_UTIL_OBJ)
+
+
 SMBCONTROL_OBJ = utils/smbcontrol.o $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \
        $(LIBSMB_ERR_OBJ) $(POPT_LIB_OBJ) $(PRINTBASE_OBJ)
 
@@ -1965,6 +1971,11 @@ bin/smbstatus: $(BINARY_PREREQS) $(STATUS_OBJ) 
@BUILD_POPT@ $(LIBTALLOC) $(LIBTD
        @$(CC) -o $@ $(STATUS_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) \
                $(LDAP_LIBS) $(POPT_LIBS) $(LIBTALLOC_LIBS) $(LIBTDB_LIBS)
 
+bin/cclean: $(BINARY_PREREQS) $(CCLEAN_OBJ) @BUILD_POPT@ $(LIBTALLOC) $(LIBTDB)
+       @echo Linking $@
+       @$(CC) -o $@ $(CCLEAN_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) \
+               $(LDAP_LIBS) $(POPT_LIBS) $(LIBTALLOC_LIBS) $(LIBTDB_LIBS)
+
 bin/smbcontrol: $(BINARY_PREREQS) $(SMBCONTROL_OBJ) @BUILD_POPT@ $(LIBTALLOC) 
$(LIBTDB)
        @echo Linking $@
        @$(CC) -DUSING_SMBCONTROL -o $@ \
diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c
index 776f53c..fb605e1 100644
--- a/source3/lib/conn_tdb.c
+++ b/source3/lib/conn_tdb.c
@@ -54,16 +54,17 @@ static struct db_record 
*connections_fetch_record(TALLOC_CTX *mem_ctx,
        return dbwrap_fetch_locked(ctx, mem_ctx, key);
 }
 
-struct db_record *connections_fetch_entry(TALLOC_CTX *mem_ctx,
-                                         connection_struct *conn,
-                                         const char *name)
+struct db_record *connections_fetch_entry_ext(TALLOC_CTX *mem_ctx,
+                                             struct server_id id,
+                                             int cnum,
+                                             const char *name)
 {
        struct connections_key ckey;
        TDB_DATA key;
 
        ZERO_STRUCT(ckey);
-       ckey.pid = messaging_server_id(conn->sconn->msg_ctx);
-       ckey.cnum = conn->cnum;
+       ckey.pid = id;
+       ckey.cnum = cnum;
        strlcpy(ckey.name, name, sizeof(ckey.name));
 
        key.dsize = sizeof(ckey);
@@ -72,6 +73,15 @@ struct db_record *connections_fetch_entry(TALLOC_CTX 
*mem_ctx,
        return connections_fetch_record(mem_ctx, key);
 }
 
+struct db_record *connections_fetch_entry(TALLOC_CTX *mem_ctx,
+                                         connection_struct *conn,
+                                         const char *name)
+{
+       struct server_id id = messaging_server_id(conn->sconn->msg_ctx);
+       return connections_fetch_entry_ext(mem_ctx, id, conn->cnum, name);
+}
+
+
 struct conn_traverse_state {
        int (*fn)(struct db_record *rec,
                  const struct connections_key *key,
diff --git a/source3/lib/conn_tdb.h b/source3/lib/conn_tdb.h
index ee4befe..9b63364 100644
--- a/source3/lib/conn_tdb.h
+++ b/source3/lib/conn_tdb.h
@@ -47,6 +47,10 @@ struct connections_data {
 struct db_record *connections_fetch_entry(TALLOC_CTX *mem_ctx,
                                          connection_struct *conn,
                                          const char *name);
+struct db_record *connections_fetch_entry_ext(TALLOC_CTX *mem_ctx,
+                                             struct server_id id,
+                                             int cnum,
+                                             const char *name);
 int connections_traverse(int (*fn)(struct db_record *rec,
                                   void *private_data),
                         void *private_data);
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 7df025f..7bb206b 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1283,6 +1283,7 @@ struct traverse_state {
        struct db_context *db;
        int (*fn)(struct db_record *rec, void *private_data);
        void *private_data;
+       int count;
 };
 
 static void traverse_callback(TDB_DATA key, TDB_DATA data, void *private_data)
@@ -1339,6 +1340,7 @@ static int db_ctdb_traverse(struct db_context *db,
                                      void *private_data),
                            void *private_data)
 {
+       NTSTATUS status;
         struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data,
                                                         struct db_ctdb_ctx);
        struct traverse_state state;
@@ -1346,6 +1348,7 @@ static int db_ctdb_traverse(struct db_context *db,
        state.db = db;
        state.fn = fn;
        state.private_data = private_data;
+       state.count = 0;
 
        if (db->persistent) {
                struct tdb_context *ltdb = ctx->wtdb->tdb;
@@ -1365,7 +1368,6 @@ static int db_ctdb_traverse(struct db_context *db,
                        struct db_context *newkeys = db_open_rbt(talloc_tos());
                        struct ctdb_marshall_buffer *mbuf = 
ctx->transaction->m_write;
                        struct ctdb_rec_data *rec=NULL;
-                       NTSTATUS status;
                        int i;
                        int count = 0;
 
@@ -1397,9 +1399,11 @@ static int db_ctdb_traverse(struct db_context *db,
                return ret;
        }
 
-
-       ctdbd_traverse(ctx->db_id, traverse_callback, &state);
-       return 0;
+       status = ctdbd_traverse(ctx->db_id, traverse_callback, &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               return -1;
+       }
+       return state.count;
 }
 
 static NTSTATUS db_ctdb_store_deny(struct db_record *rec, TDB_DATA data, int 
flag)
@@ -1422,6 +1426,7 @@ static void traverse_read_callback(TDB_DATA key, TDB_DATA 
data, void *private_da
        rec.delete_rec = db_ctdb_delete_deny;
        rec.private_data = state->db;
        state->fn(&rec, state->private_data);
+       state->count++;
 }
 
 static int traverse_persistent_callback_read(TDB_CONTEXT *tdb, TDB_DATA kbuf, 
TDB_DATA dbuf,
@@ -1453,6 +1458,7 @@ static int traverse_persistent_callback_read(TDB_CONTEXT 
*tdb, TDB_DATA kbuf, TD
        rec.value.dsize -= sizeof(struct ctdb_ltdb_header);
        rec.value.dptr += sizeof(struct ctdb_ltdb_header);
 
+       state->count++;
        return state->fn(&rec, state->private_data);
 }
 
@@ -1461,6 +1467,7 @@ static int db_ctdb_traverse_read(struct db_context *db,
                                           void *private_data),
                                 void *private_data)
 {
+       NTSTATUS status;
         struct db_ctdb_ctx *ctx = talloc_get_type_abort(db->private_data,
                                                         struct db_ctdb_ctx);
        struct traverse_state state;
@@ -1468,6 +1475,7 @@ static int db_ctdb_traverse_read(struct db_context *db,
        state.db = db;
        state.fn = fn;
        state.private_data = private_data;
+       state.count = 0;
 
        if (db->persistent) {
                /* for persistent databases we don't need to do a ctdb traverse,
@@ -1475,8 +1483,11 @@ static int db_ctdb_traverse_read(struct db_context *db,
                return tdb_traverse_read(ctx->wtdb->tdb, 
traverse_persistent_callback_read, &state);
        }
 
-       ctdbd_traverse(ctx->db_id, traverse_read_callback, &state);
-       return 0;
+       status = ctdbd_traverse(ctx->db_id, traverse_read_callback, &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               return -1;
+       }
+       return state.count;
 }
 
 static int db_ctdb_get_seqnum(struct db_context *db)
diff --git a/source3/registry/reg_import.c b/source3/registry/reg_import.c
index 5f99b07..8bcce68 100644
--- a/source3/registry/reg_import.c
+++ b/source3/registry/reg_import.c
@@ -28,52 +28,47 @@
 /* Debuglevel for tracing */
 static const int TL = 2;
 
-struct reg_import
-{
+struct reg_import {
        struct reg_parse_callback reg_parse_callback;
        struct reg_import_callback call;
-       void* open_key;
+       void *open_key;
 };
 
-static int
-reg_parse_callback_key(struct reg_import* cb_private,
-                      const char* key[], size_t n,
-                      bool del);
+static int reg_parse_callback_key(struct reg_import *cb_private,
+                                 const char *key[], size_t n, bool del);
 
-static int
-reg_parse_callback_val(struct reg_import* cb_private,
-                      const char* name, uint32_t type,
-                      const uint8_t* data, uint32_t len);
+static int reg_parse_callback_val(struct reg_import *cb_private,
+                                 const char *name, uint32_t type,
+                                 const uint8_t *data, uint32_t len);
 
-static int
-reg_parse_callback_val_registry_value(struct reg_import* cb_private,
-                                     const char* name, uint32_t type,
-                                     const uint8_t* data, uint32_t len);
+static int reg_parse_callback_val_registry_value(struct reg_import *cb_private,
+                                                const char *name,
+                                                uint32_t type,
+                                                const uint8_t *data,
+                                                uint32_t len);
 
-static int
-reg_parse_callback_val_regval_blob(struct reg_import* cb_private,
-                                  const char* name, uint32_t type,
-                                  const uint8_t* data, uint32_t len);
+static int reg_parse_callback_val_regval_blob(struct reg_import *cb_private,
+                                             const char *name, uint32_t type,
+                                             const uint8_t *data,
+                                             uint32_t len);
 
-static int
-reg_parse_callback_val_del(struct reg_import* cb_private,
-                          const char* name);
+static int reg_parse_callback_val_del(struct reg_import *cb_private,
+                                     const char *name);
 
-static int
-reg_parse_callback_comment(struct reg_import* cb_private,
-                          const char* txt);
+static int reg_parse_callback_comment(struct reg_import *cb_private,
+                                     const char *txt);
 
 
 
/*******************************************************************************/
 
-int reg_parse_callback_key(struct reg_import* p,
-                          const char* key[], size_t n, bool del)
+int reg_parse_callback_key(struct reg_import *p,
+                          const char *key[], size_t n, bool del)
 {
        WERROR werr = WERR_OK;
 
        DEBUG(TL, ("%s: %s\n", __FUNCTION__, key[0]));
 
-       if (p->open_key != NULL ) {
+       if (p->open_key != NULL) {
                werr = p->call.closekey(p->call.data, p->open_key);
                p->open_key = NULL;
                if (!W_ERROR_IS_OK(werr)) {
@@ -91,8 +86,7 @@ int reg_parse_callback_key(struct reg_import* p,
                        DEBUG(0, ("deletekey %s failed: %s\n",
                                  key[0], win_errstr(werr)));
                }
-       }
-       else {
+       } else {
                bool existing;
                werr = p->call.createkey(p->call.data, NULL, key[0],
                                         &p->open_key, &existing);
@@ -122,9 +116,9 @@ int reg_parse_callback_key(struct reg_import* p,
        } while(0)
 
 
/*----------------------------------------------------------------------------*/
-int reg_parse_callback_val(struct reg_import* p,
-                          const char* name, uint32_t type,
-                          const uint8_t* data, uint32_t len)
+int reg_parse_callback_val(struct reg_import *p,
+                          const char *name, uint32_t type,
+                          const uint8_t *data, uint32_t len)
 {
        WERROR werr = WERR_OK;
 
@@ -142,9 +136,9 @@ int reg_parse_callback_val(struct reg_import* p,
 }
 
 
/*----------------------------------------------------------------------------*/
-int reg_parse_callback_val_registry_value(struct reg_import* p,
-                                         const char* name, uint32_t type,
-                                         const uint8_t* data, uint32_t len)
+int reg_parse_callback_val_registry_value(struct reg_import *p,
+                                         const char *name, uint32_t type,
+                                         const uint8_t *data, uint32_t len)
 {
        WERROR werr = WERR_OK;
        struct registry_value val = {
@@ -167,13 +161,13 @@ int reg_parse_callback_val_registry_value(struct 
reg_import* p,
 }
 
 
/*----------------------------------------------------------------------------*/
-int reg_parse_callback_val_regval_blob(struct reg_import* p,
-                                      const char* name, uint32_t type,
-                                      const uint8_t* data, uint32_t len)
+int reg_parse_callback_val_regval_blob(struct reg_import *p,
+                                      const char *name, uint32_t type,
+                                      const uint8_t *data, uint32_t len)
 {
        WERROR werr = WERR_OK;
        void* mem_ctx = talloc_new(p);
-       struct regval_blob* v = NULL;
+       struct regval_blob *v = NULL;
 
        DEBUG(TL, ("%s(%x): >%s< = [%x]\n", __FUNCTION__, type, name, len));
        DEBUG_ADD_HEX(TL, data, len);
@@ -200,8 +194,8 @@ done:
 
 
/*----------------------------------------------------------------------------*/
 
-int reg_parse_callback_val_del(struct reg_import* p,
-                              const char* name)
+int reg_parse_callback_val_del(struct reg_import *p,
+                              const char *name)
 {
        WERROR werr = WERR_OK;
 
@@ -217,41 +211,41 @@ int reg_parse_callback_val_del(struct reg_import* p,
 }
 
 
-int reg_parse_callback_comment(struct reg_import* cb_private,
-                              const char* txt)
+int reg_parse_callback_comment(struct reg_import *cb_private,
+                              const char *txt)
 {
        DEBUG(TL, ("%s: %s\n", __FUNCTION__, txt));
        return 0;
 }
 
 
/******************************************************************************/
-static int nop(void* data)
+static int nop(void *data)
 {
        return 0;
 }
 
 
-struct reg_parse_callback* reg_import_adapter(const void* talloc_ctx,
+struct reg_parse_callback *reg_import_adapter(TALLOC_CTX *talloc_ctx,
                                              struct reg_import_callback cb)
 {
-       struct reg_parse_callback* ret;
-       struct reg_import* p = talloc_zero(talloc_ctx, struct reg_import);
+       struct reg_parse_callback *ret;
+       struct reg_import *p = talloc_zero(talloc_ctx, struct reg_import);
        if (p == NULL) {
                goto fail;
        }
-       if (cb.openkey == NULL ) {
+       if (cb.openkey == NULL) {
                cb.openkey = (reg_import_callback_openkey_t)&nop;
        }
-       if (cb.closekey == NULL ) {
+       if (cb.closekey == NULL) {
                cb.closekey = (reg_import_callback_closekey_t)&nop;
        }
-       if (cb.createkey == NULL ) {
+       if (cb.createkey == NULL) {
                cb.createkey = (reg_import_callback_createkey_t)&nop;
        }
-       if (cb.deletekey == NULL ) {
+       if (cb.deletekey == NULL) {
                cb.deletekey = (reg_import_callback_deletekey_t)&nop;
        }
-       if (cb.deleteval == NULL ) {
+       if (cb.deleteval == NULL) {
                cb.deleteval = (reg_import_callback_deleteval_t)&nop;
        }
 
@@ -283,7 +277,7 @@ struct reg_parse_callback* reg_import_adapter(const void* 
talloc_ctx,
                assert(false);
        }
 
-       assert((struct reg_parse_callback*)p == ret);
+       assert((struct reg_parse_callback *)p == ret);
        return ret;
 fail:
        talloc_free(p);
diff --git a/source3/registry/reg_import.h b/source3/registry/reg_import.h
index 5922f9d..70db4ac 100644
--- a/source3/registry/reg_import.h
+++ b/source3/registry/reg_import.h
@@ -194,6 +194,6 @@ struct reg_import_callback {
  *
  * @return a talloc'ed reg_import object, NULL on error
  */
-struct reg_parse_callback* reg_import_adapter(const void* talloc_ctx,
+struct reg_parse_callback* reg_import_adapter(TALLOC_CTX *talloc_ctx,
                                              struct reg_import_callback cb);
 #endif
diff --git a/source3/utils/cclean.c b/source3/utils/cclean.c
new file mode 100644
index 0000000..b035d33
--- /dev/null
+++ b/source3/utils/cclean.c
@@ -0,0 +1,300 @@
+/*
+   Unix SMB/CIFS implementation.
+   cleanup connections tdb
+   Copyright (C) Gregor Beck 2012
+
+   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 "serverid.h"
+#include "popt_common.h"
+#include "dbwrap/dbwrap.h"
+#include "util_tdb.h"
+#include "messages.h"
+#include "system/filesys.h"
+#include "interact.h"
+#include "lib/conn_tdb.h"
+
+static bool verbose = false;
+static bool dry_run = false;
+static bool automatic = false;
+
+struct cclean_ctx {
+       struct server_id *ids;
+       int *cnums;
+       const char **names;
+       unsigned num;
+
+       bool *exists;
+       unsigned num_orphans;
+};
+
+
+static char *serverid_str(const struct server_id id)
+{
+       return talloc_asprintf(talloc_tos(), "pid %u, vnn %u, uid %lu",
+                              (unsigned)id.pid, (unsigned)id.vnn, 
id.unique_id);
+}
+
+static void print_record(const char *msg,
+                        const struct connections_key *k,
+                        const struct connections_data *d)
+{
+       char *idstr = serverid_str(k->pid);
+       d_printf("%s: connection %d (%s) to \"%s\" from %u:%u@%s[%s] %s\n", msg,
+                k->cnum, idstr, d->servicename, (unsigned)d->uid,
+                (unsigned)d->gid, d->machine, d->addr, time_to_asc(d->start));
+       talloc_free(idstr);
+}
+
+static int read_connections_fn(const struct connections_key *key,
+                              const struct connections_data *data,
+                              void *cclean_ctx)
+{
+       struct cclean_ctx *ctx = (struct cclean_ctx *)cclean_ctx;
+       unsigned length = talloc_array_length(ctx->cnums);
+       if (length <= ctx->num) {
+               int n = 2*length;
+               void *tmp;
+
+               tmp = talloc_realloc(ctx, ctx->ids, struct server_id, n);
+               if (tmp == NULL) {
+                       goto talloc_failed;
+               }
+               ctx->ids = (struct server_id *)tmp;
+
+               tmp = talloc_realloc(ctx, ctx->cnums, int, n);
+               if (tmp == NULL) {
+                       goto talloc_failed;
+               }
+               ctx->cnums = (int *)tmp;


-- 
Samba Shared Repository

Reply via email to