~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/lib/sessionid_tdb.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
   Low-level sessionid.tdb access functions
 
4
   Copyright (C) Volker Lendecke 2010
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 3 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#include "includes.h"
 
21
#include "system/filesys.h"
 
22
#include "dbwrap.h"
 
23
#include "session.h"
 
24
#include "util_tdb.h"
 
25
 
 
26
static struct db_context *session_db_ctx(void)
 
27
{
 
28
        static struct db_context *session_db_ctx_ptr;
 
29
 
 
30
        if (session_db_ctx_ptr != NULL) {
 
31
                return session_db_ctx_ptr;
 
32
        }
 
33
 
 
34
        session_db_ctx_ptr = db_open(NULL, lock_path("sessionid.tdb"), 0,
 
35
                                     TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
 
36
                                     O_RDWR | O_CREAT, 0644);
 
37
        return session_db_ctx_ptr;
 
38
}
 
39
 
 
40
bool sessionid_init(void)
 
41
{
 
42
        if (session_db_ctx() == NULL) {
 
43
                DEBUG(1,("session_init: failed to open sessionid tdb\n"));
 
44
                return False;
 
45
        }
 
46
 
 
47
        return True;
 
48
}
 
49
 
 
50
struct db_record *sessionid_fetch_record(TALLOC_CTX *mem_ctx, const char *key)
 
51
{
 
52
        struct db_context *db;
 
53
 
 
54
        db = session_db_ctx();
 
55
        if (db == NULL) {
 
56
                return NULL;
 
57
        }
 
58
        return db->fetch_locked(db, mem_ctx, string_term_tdb_data(key));
 
59
}
 
60
 
 
61
struct sessionid_traverse_state {
 
62
        int (*fn)(struct db_record *rec, const char *key,
 
63
                  struct sessionid *session, void *private_data);
 
64
        void *private_data;
 
65
};
 
66
 
 
67
static int sessionid_traverse_fn(struct db_record *rec, void *private_data)
 
68
{
 
69
        struct sessionid_traverse_state *state =
 
70
                (struct sessionid_traverse_state *)private_data;
 
71
        struct sessionid session;
 
72
 
 
73
        if ((rec->key.dptr[rec->key.dsize-1] != '\0')
 
74
            || (rec->value.dsize != sizeof(struct sessionid))) {
 
75
                DEBUG(1, ("Found invalid record in sessionid.tdb\n"));
 
76
                return 0;
 
77
        }
 
78
 
 
79
        memcpy(&session, rec->value.dptr, sizeof(session));
 
80
 
 
81
        return state->fn(rec, (char *)rec->key.dptr, &session,
 
82
                         state->private_data);
 
83
}
 
84
 
 
85
int sessionid_traverse(int (*fn)(struct db_record *rec, const char *key,
 
86
                                 struct sessionid *session,
 
87
                                 void *private_data),
 
88
                       void *private_data)
 
89
{
 
90
        struct db_context *db;
 
91
        struct sessionid_traverse_state state;
 
92
 
 
93
        db = session_db_ctx();
 
94
        if (db == NULL) {
 
95
                return -1;
 
96
        }
 
97
        state.fn = fn;
 
98
        state.private_data = private_data;
 
99
        return db->traverse(db, sessionid_traverse_fn, &state);
 
100
}
 
101
 
 
102
struct sessionid_traverse_read_state {
 
103
        int (*fn)(const char *key, struct sessionid *session,
 
104
                  void *private_data);
 
105
        void *private_data;
 
106
};
 
107
 
 
108
static int sessionid_traverse_read_fn(struct db_record *rec,
 
109
                                      void *private_data)
 
110
{
 
111
        struct sessionid_traverse_read_state *state =
 
112
                (struct sessionid_traverse_read_state *)private_data;
 
113
        struct sessionid session;
 
114
 
 
115
        if ((rec->key.dptr[rec->key.dsize-1] != '\0')
 
116
            || (rec->value.dsize != sizeof(struct sessionid))) {
 
117
                DEBUG(1, ("Found invalid record in sessionid.tdb\n"));
 
118
                return 0;
 
119
        }
 
120
 
 
121
        memcpy(&session, rec->value.dptr, sizeof(session));
 
122
 
 
123
        return state->fn((char *)rec->key.dptr, &session,
 
124
                         state->private_data);
 
125
}
 
126
 
 
127
int sessionid_traverse_read(int (*fn)(const char *key,
 
128
                                      struct sessionid *session,
 
129
                                      void *private_data),
 
130
                            void *private_data)
 
131
{
 
132
        struct db_context *db;
 
133
        struct sessionid_traverse_read_state state;
 
134
 
 
135
        db = session_db_ctx();
 
136
        if (db == NULL) {
 
137
                return -1;
 
138
        }
 
139
        state.fn = fn;
 
140
        state.private_data = private_data;
 
141
        return db->traverse(db, sessionid_traverse_read_fn, &state);
 
142
}