~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/lib/tdb_wrap.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
   Unix SMB/CIFS implementation.
3
 
   TDB wrap functions
4
 
 
5
 
   Copyright (C) Andrew Tridgell 2004
6
 
   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
7
 
   
8
 
   This program is free software; you can redistribute it and/or modify
9
 
   it under the terms of the GNU General Public License as published by
10
 
   the Free Software Foundation; either version 3 of the License, or
11
 
   (at your option) any later version.
12
 
   
13
 
   This program is distributed in the hope that it will be useful,
14
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
   GNU General Public License for more details.
17
 
   
18
 
   You should have received a copy of the GNU General Public License
19
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
*/
21
 
 
22
 
#include "includes.h"
23
 
#include "../tdb/include/tdb.h"
24
 
#include "../lib/util/dlinklist.h"
25
 
#include "tdb_wrap.h"
26
 
#include "tdb.h"
27
 
 
28
 
static struct tdb_wrap *tdb_list;
29
 
 
30
 
/* destroy the last connection to a tdb */
31
 
static int tdb_wrap_destructor(struct tdb_wrap *w)
32
 
{
33
 
        tdb_close(w->tdb);
34
 
        DLIST_REMOVE(tdb_list, w);
35
 
        return 0;
36
 
}                                
37
 
 
38
 
/*
39
 
 Log tdb messages via DEBUG().
40
 
*/
41
 
static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, 
42
 
                         const char *format, ...) PRINTF_ATTRIBUTE(3,4);
43
 
 
44
 
static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level, 
45
 
                         const char *format, ...)
46
 
{
47
 
        va_list ap;
48
 
        char *ptr = NULL;
49
 
        int dl;
50
 
 
51
 
        va_start(ap, format);
52
 
        vasprintf(&ptr, format, ap);
53
 
        va_end(ap);
54
 
        
55
 
        switch (level) {
56
 
        case TDB_DEBUG_FATAL:
57
 
                dl = 0;
58
 
                break;
59
 
        case TDB_DEBUG_ERROR:
60
 
                dl = 1;
61
 
                break;
62
 
        case TDB_DEBUG_WARNING:
63
 
                dl = 2;
64
 
                break;
65
 
        case TDB_DEBUG_TRACE:
66
 
                dl = 5;
67
 
                break;
68
 
        default:
69
 
                dl = 0;
70
 
        }               
71
 
 
72
 
        if (ptr != NULL) {
73
 
                const char *name = tdb_name(tdb);
74
 
                DEBUG(dl, ("tdb(%s): %s", name ? name : "unnamed", ptr));
75
 
                free(ptr);
76
 
        }
77
 
}
78
 
 
79
 
 
80
 
/*
81
 
  wrapped connection to a tdb database
82
 
  to close just talloc_free() the tdb_wrap pointer
83
 
 */
84
 
struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
85
 
                               const char *name, int hash_size, int tdb_flags,
86
 
                               int open_flags, mode_t mode)
87
 
{
88
 
        struct tdb_wrap *w;
89
 
        struct tdb_logging_context log_ctx;
90
 
        log_ctx.log_fn = tdb_wrap_log;
91
 
 
92
 
        for (w=tdb_list;w;w=w->next) {
93
 
                if (strcmp(name, w->name) == 0) {
94
 
                        return talloc_reference(mem_ctx, w);
95
 
                }
96
 
        }
97
 
 
98
 
        w = talloc(mem_ctx, struct tdb_wrap);
99
 
        if (w == NULL) {
100
 
                return NULL;
101
 
        }
102
 
 
103
 
        w->name = talloc_strdup(w, name);
104
 
 
105
 
        w->tdb = tdb_open_ex(name, hash_size, tdb_flags, 
106
 
                             open_flags, mode, &log_ctx, NULL);
107
 
        if (w->tdb == NULL) {
108
 
                talloc_free(w);
109
 
                return NULL;
110
 
        }
111
 
 
112
 
        talloc_set_destructor(w, tdb_wrap_destructor);
113
 
 
114
 
        DLIST_ADD(tdb_list, w);
115
 
 
116
 
        return w;
117
 
}