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

« back to all changes in this revision

Viewing changes to source3/smbd/session.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:
27
27
*/
28
28
 
29
29
#include "includes.h"
 
30
#include "smbd/smbd.h"
30
31
#include "smbd/globals.h"
31
 
 
32
 
/********************************************************************
33
 
********************************************************************/
34
 
 
35
 
static struct db_context *session_db_ctx(void)
36
 
{
37
 
        if (session_db_ctx_ptr)
38
 
                return session_db_ctx_ptr;
39
 
 
40
 
        session_db_ctx_ptr = db_open(NULL, lock_path("sessionid.tdb"), 0,
41
 
                                     TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
42
 
                                     O_RDWR | O_CREAT, 0644);
43
 
        return session_db_ctx_ptr;
44
 
}
45
 
 
46
 
bool session_init(void)
47
 
{
48
 
        if (session_db_ctx() == NULL) {
49
 
                DEBUG(1,("session_init: failed to open sessionid tdb\n"));
50
 
                return False;
51
 
        }
52
 
 
53
 
        return True;
54
 
}
 
32
#include "dbwrap.h"
 
33
#include "session.h"
 
34
#include "auth.h"
55
35
 
56
36
/********************************************************************
57
37
 called when a session is created
58
38
********************************************************************/
59
39
 
60
 
bool session_claim(user_struct *vuser)
 
40
bool session_claim(struct smbd_server_connection *sconn, user_struct *vuser)
61
41
{
62
 
        TDB_DATA key, data;
 
42
        struct server_id pid = sconn_server_id(sconn);
 
43
        TDB_DATA data;
63
44
        int i = 0;
64
45
        struct sessionid sessionid;
65
 
        struct server_id pid = procid_self();
66
46
        fstring keystr;
67
 
        const char * hostname;
68
 
        struct db_context *ctx;
69
47
        struct db_record *rec;
70
48
        NTSTATUS status;
71
 
        char addr[INET6_ADDRSTRLEN];
72
49
 
73
50
        vuser->session_keystr = NULL;
74
51
 
75
52
        /* don't register sessions for the guest user - its just too
76
53
           expensive to go through pam session code for browsing etc */
77
 
        if (vuser->server_info->guest) {
 
54
        if (vuser->session_info->guest) {
78
55
                return True;
79
56
        }
80
57
 
81
 
        if (!(ctx = session_db_ctx())) {
 
58
        if (!sessionid_init()) {
82
59
                return False;
83
60
        }
84
61
 
98
75
                        struct server_id sess_pid;
99
76
 
100
77
                        snprintf(keystr, sizeof(keystr), "ID/%d", i);
101
 
                        key = string_term_tdb_data(keystr);
102
 
 
103
 
                        rec = ctx->fetch_locked(ctx, NULL, key);
104
 
 
 
78
 
 
79
                        rec = sessionid_fetch_record(NULL, keystr);
105
80
                        if (rec == NULL) {
106
81
                                DEBUG(1, ("Could not lock \"%s\"\n", keystr));
107
82
                                return False;
139
114
        {
140
115
                snprintf(keystr, sizeof(keystr), "ID/%s/%u",
141
116
                         procid_str_static(&pid), vuser->vuid);
142
 
                key = string_term_tdb_data(keystr);
143
 
 
144
 
                rec = ctx->fetch_locked(ctx, NULL, key);
145
 
 
 
117
 
 
118
                rec = sessionid_fetch_record(NULL, keystr);
146
119
                if (rec == NULL) {
147
120
                        DEBUG(1, ("Could not lock \"%s\"\n", keystr));
148
121
                        return False;
161
134
           client_name() handles this case internally.
162
135
        */
163
136
 
164
 
        hostname = client_name(get_client_fd());
165
 
        if (strcmp(hostname, "UNKNOWN") == 0) {
166
 
                hostname = client_addr(get_client_fd(),addr,sizeof(addr));
167
 
        }
168
 
 
169
 
        fstrcpy(sessionid.username, vuser->server_info->unix_name);
170
 
        fstrcpy(sessionid.hostname, hostname);
 
137
        fstrcpy(sessionid.username, vuser->session_info->unix_name);
 
138
        fstrcpy(sessionid.hostname, sconn->client_id.name);
171
139
        sessionid.id_num = i;  /* Only valid for utmp sessions */
172
140
        sessionid.pid = pid;
173
 
        sessionid.uid = vuser->server_info->utok.uid;
174
 
        sessionid.gid = vuser->server_info->utok.gid;
 
141
        sessionid.uid = vuser->session_info->utok.uid;
 
142
        sessionid.gid = vuser->session_info->utok.gid;
175
143
        fstrcpy(sessionid.remote_machine, get_remote_machine_name());
176
 
        fstrcpy(sessionid.ip_addr_str,
177
 
                client_addr(get_client_fd(),addr,sizeof(addr)));
 
144
        fstrcpy(sessionid.ip_addr_str, sconn->client_id.addr);
178
145
        sessionid.connect_start = time(NULL);
179
146
 
180
147
        if (!smb_pam_claim_session(sessionid.username, sessionid.id_str,
219
186
 
220
187
void session_yield(user_struct *vuser)
221
188
{
222
 
        TDB_DATA key;
223
189
        struct sessionid sessionid;
224
 
        struct db_context *ctx;
225
190
        struct db_record *rec;
226
191
 
227
 
        if (!(ctx = session_db_ctx())) return;
228
 
 
229
192
        if (!vuser->session_keystr) {
230
193
                return;
231
194
        }
232
195
 
233
 
        key = string_term_tdb_data(vuser->session_keystr);
234
 
 
235
 
        if (!(rec = ctx->fetch_locked(ctx, NULL, key))) {
 
196
        rec = sessionid_fetch_record(NULL, vuser->session_keystr);
 
197
        if (rec == NULL) {
236
198
                return;
237
199
        }
238
200
 
258
220
/********************************************************************
259
221
********************************************************************/
260
222
 
261
 
static bool session_traverse(int (*fn)(struct db_record *db,
262
 
                                       void *private_data),
263
 
                             void *private_data)
264
 
{
265
 
        struct db_context *ctx;
266
 
 
267
 
        if (!(ctx = session_db_ctx())) {
268
 
                DEBUG(3, ("No tdb opened\n"));
269
 
                return False;
270
 
        }
271
 
 
272
 
        ctx->traverse_read(ctx, fn, private_data);
273
 
        return True;
274
 
}
275
 
 
276
 
/********************************************************************
277
 
********************************************************************/
278
 
 
279
223
struct session_list {
280
224
        TALLOC_CTX *mem_ctx;
281
225
        int count;
282
226
        struct sessionid *sessions;
283
227
};
284
228
 
285
 
static int gather_sessioninfo(struct db_record *rec, void *state)
 
229
static int gather_sessioninfo(const char *key, struct sessionid *session,
 
230
                              void *private_data)
286
231
{
287
 
        struct session_list *sesslist = (struct session_list *) state;
288
 
        const struct sessionid *current =
289
 
                (const struct sessionid *) rec->value.dptr;
 
232
        struct session_list *sesslist = (struct session_list *)private_data;
290
233
 
291
234
        sesslist->sessions = TALLOC_REALLOC_ARRAY(
292
235
                sesslist->mem_ctx, sesslist->sessions, struct sessionid,
297
240
                return -1;
298
241
        }
299
242
 
300
 
        memcpy(&sesslist->sessions[sesslist->count], current,
 
243
        memcpy(&sesslist->sessions[sesslist->count], session,
301
244
               sizeof(struct sessionid));
302
245
 
303
246
        sesslist->count++;
304
247
 
305
 
        DEBUG(7,("gather_sessioninfo session from %s@%s\n", 
306
 
                 current->username, current->remote_machine));
 
248
        DEBUG(7, ("gather_sessioninfo session from %s@%s\n",
 
249
                  session->username, session->remote_machine));
307
250
 
308
251
        return 0;
309
252
}
314
257
int list_sessions(TALLOC_CTX *mem_ctx, struct sessionid **session_list)
315
258
{
316
259
        struct session_list sesslist;
 
260
        int ret;
317
261
 
318
262
        sesslist.mem_ctx = mem_ctx;
319
263
        sesslist.count = 0;
320
264
        sesslist.sessions = NULL;
321
 
        
322
 
        if (!session_traverse(gather_sessioninfo, (void *) &sesslist)) {
 
265
 
 
266
        ret = sessionid_traverse_read(gather_sessioninfo, (void *) &sesslist);
 
267
        if (ret == -1) {
323
268
                DEBUG(3, ("Session traverse failed\n"));
324
269
                SAFE_FREE(sesslist.sessions);
325
270
                *session_list = NULL;