~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/smbd/smb2_getinfo.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:
3
3
   Core SMB2 server
4
4
 
5
5
   Copyright (C) Stefan Metzmacher 2009
 
6
   Copyright (C) Jeremy Allison 2010
6
7
 
7
8
   This program is free software; you can redistribute it and/or modify
8
9
   it under the terms of the GNU General Public License as published by
19
20
*/
20
21
 
21
22
#include "includes.h"
 
23
#include "smbd/smbd.h"
22
24
#include "smbd/globals.h"
23
25
#include "../libcli/smb/smb_common.h"
 
26
#include "trans2.h"
 
27
#include "../lib/util/tevent_ntstatus.h"
24
28
 
25
29
static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
26
30
                                                 struct tevent_context *ev,
34
38
                                                 uint64_t in_file_id_volatile);
35
39
static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
36
40
                                       TALLOC_CTX *mem_ctx,
37
 
                                       DATA_BLOB *out_output_buffer);
 
41
                                       DATA_BLOB *out_output_buffer,
 
42
                                       NTSTATUS *p_call_status);
38
43
 
39
44
static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq);
40
45
NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req)
41
46
{
42
 
        const uint8_t *inhdr;
 
47
        NTSTATUS status;
43
48
        const uint8_t *inbody;
44
49
        int i = req->current_idx;
45
 
        size_t expected_body_size = 0x29;
46
 
        size_t body_size;
47
50
        uint8_t in_info_type;
48
51
        uint8_t in_file_info_class;
49
52
        uint32_t in_output_buffer_length;
56
59
        uint64_t in_file_id_volatile;
57
60
        struct tevent_req *subreq;
58
61
 
59
 
        inhdr = (const uint8_t *)req->in.vector[i+0].iov_base;
60
 
        if (req->in.vector[i+1].iov_len != (expected_body_size & 0xFFFFFFFE)) {
61
 
                return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
 
62
        status = smbd_smb2_request_verify_sizes(req, 0x29);
 
63
        if (!NT_STATUS_IS_OK(status)) {
 
64
                return smbd_smb2_request_error(req, status);
62
65
        }
63
 
 
64
66
        inbody = (const uint8_t *)req->in.vector[i+1].iov_base;
65
67
 
66
 
        body_size = SVAL(inbody, 0x00);
67
 
        if (body_size != expected_body_size) {
68
 
                return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
69
 
        }
70
 
 
71
68
        in_info_type                    = CVAL(inbody, 0x02);
72
69
        in_file_info_class              = CVAL(inbody, 0x03);
73
70
        in_output_buffer_length         = IVAL(inbody, 0x04);
82
79
        if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
83
80
                /* This is ok */
84
81
        } else if (in_input_buffer_offset !=
85
 
                   (SMB2_HDR_BODY + (body_size & 0xFFFFFFFE))) {
 
82
                   (SMB2_HDR_BODY + req->in.vector[i+1].iov_len)) {
86
83
                return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
87
84
        }
88
85
 
93
90
        in_input_buffer.data = (uint8_t *)req->in.vector[i+2].iov_base;
94
91
        in_input_buffer.length = in_input_buffer_length;
95
92
 
 
93
        if (in_input_buffer.length > req->sconn->smb2.max_trans) {
 
94
                return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
 
95
        }
 
96
        if (in_output_buffer_length > req->sconn->smb2.max_trans) {
 
97
                return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
 
98
        }
 
99
 
96
100
        if (req->compat_chain_fsp) {
97
101
                /* skip check */
98
 
        } else if (in_file_id_persistent != 0) {
 
102
        } else if (in_file_id_persistent != in_file_id_volatile) {
99
103
                return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
100
104
        }
101
105
 
128
132
        uint16_t out_output_buffer_offset;
129
133
        DATA_BLOB out_output_buffer = data_blob_null;
130
134
        NTSTATUS status;
 
135
        NTSTATUS call_status = NT_STATUS_OK;
131
136
        NTSTATUS error; /* transport error */
132
137
 
133
138
        status = smbd_smb2_getinfo_recv(subreq,
134
139
                                        req,
135
 
                                        &out_output_buffer);
 
140
                                        &out_output_buffer,
 
141
                                        &call_status);
136
142
        TALLOC_FREE(subreq);
137
143
        if (!NT_STATUS_IS_OK(status)) {
138
144
                error = smbd_smb2_request_error(req, status);
144
150
                return;
145
151
        }
146
152
 
 
153
        if (!NT_STATUS_IS_OK(call_status)) {
 
154
                /* Return a specific error with data. */
 
155
                error = smbd_smb2_request_error_ex(req,
 
156
                                                call_status,
 
157
                                                &out_output_buffer,
 
158
                                                __location__);
 
159
                if (!NT_STATUS_IS_OK(error)) {
 
160
                        smbd_server_connection_terminate(req->sconn,
 
161
                                                         nt_errstr(error));
 
162
                        return;
 
163
                }
 
164
                return;
 
165
        }
 
166
 
147
167
        out_output_buffer_offset = SMB2_HDR_BODY + 0x08;
148
168
 
149
169
        outhdr = (uint8_t *)req->out.vector[i].iov_base;
181
201
        DATA_BLOB out_output_buffer;
182
202
};
183
203
 
 
204
static void smb2_ipc_getinfo(struct tevent_req *req,
 
205
                                struct smbd_smb2_getinfo_state *state,
 
206
                                struct tevent_context *ev,
 
207
                                uint8_t in_info_type,
 
208
                                uint8_t in_file_info_class)
 
209
{
 
210
        /* We want to reply to SMB2_GETINFO_FILE
 
211
           with a class of SMB2_FILE_STANDARD_INFO as
 
212
           otherwise a Win7 client issues this request
 
213
           twice (2xroundtrips) if we return NOT_SUPPORTED.
 
214
           NB. We do the same for SMB1 in call_trans2qpipeinfo() */
 
215
 
 
216
        if (in_info_type == 0x01 && /* SMB2_GETINFO_FILE */
 
217
                        in_file_info_class == 0x05) { /* SMB2_FILE_STANDARD_INFO */
 
218
                state->out_output_buffer = data_blob_talloc(state,
 
219
                                                NULL, 24);
 
220
                if (tevent_req_nomem(state->out_output_buffer.data, req)) {
 
221
                        return;
 
222
                }
 
223
 
 
224
                memset(state->out_output_buffer.data,0,24);
 
225
                SOFF_T(state->out_output_buffer.data,0,4096LL);
 
226
                SIVAL(state->out_output_buffer.data,16,1);
 
227
                SIVAL(state->out_output_buffer.data,20,1);
 
228
                tevent_req_done(req);
 
229
        } else {
 
230
                tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
 
231
        }
 
232
}
 
233
 
184
234
static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
185
235
                                                 struct tevent_context *ev,
186
236
                                                 struct smbd_smb2_request *smb2req,
197
247
        struct smb_request *smbreq;
198
248
        connection_struct *conn = smb2req->tcon->compat_conn;
199
249
        files_struct *fsp;
 
250
        NTSTATUS status;
200
251
 
201
252
        req = tevent_req_create(mem_ctx, &state,
202
253
                                struct smbd_smb2_getinfo_state);
204
255
                return NULL;
205
256
        }
206
257
        state->smb2req = smb2req;
207
 
        state->status = NT_STATUS_INTERNAL_ERROR;
 
258
        state->status = NT_STATUS_OK;
208
259
        state->out_output_buffer = data_blob_null;
209
260
 
210
261
        DEBUG(10,("smbd_smb2_getinfo_send: file_id[0x%016llX]\n",
230
281
        }
231
282
 
232
283
        if (IS_IPC(conn)) {
233
 
                tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
 
284
                smb2_ipc_getinfo(req, state, ev,
 
285
                        in_info_type, in_file_info_class);
234
286
                return tevent_req_post(req, ev);
235
287
        }
236
288
 
246
298
                struct ea_list *ea_list = NULL;
247
299
                int lock_data_count = 0;
248
300
                char *lock_data = NULL;
249
 
                bool ms_dfs_link = false;
250
 
                NTSTATUS status;
251
301
 
252
302
                ZERO_STRUCT(write_time_ts);
253
303
 
273
323
 
274
324
                        /* We know this name is ok, it's already passed the checks. */
275
325
 
276
 
                } else if (fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
 
326
                } else if (fsp && fsp->fh->fd == -1) {
277
327
                        /*
278
328
                         * This is actually a QFILEINFO on a directory
279
329
                         * handle (returned from an NT SMB). NT5.0 seems
303
353
 
304
354
                        fileid = vfs_file_id_from_sbuf(conn,
305
355
                                                       &fsp->fsp_name->st);
306
 
                        get_file_infos(fileid, &delete_pending, &write_time_ts);
 
356
                        get_file_infos(fileid, fsp->name_hash,
 
357
                                &delete_pending, &write_time_ts);
307
358
                } else {
308
359
                        /*
309
360
                         * Original code - this is an open file.
319
370
                        }
320
371
                        fileid = vfs_file_id_from_sbuf(conn,
321
372
                                                       &fsp->fsp_name->st);
322
 
                        get_file_infos(fileid, &delete_pending, &write_time_ts);
 
373
                        get_file_infos(fileid, fsp->name_hash,
 
374
                                &delete_pending, &write_time_ts);
323
375
                }
324
376
 
325
377
                status = smbd_do_qfilepathinfo(conn, state,
328
380
                                               fsp->fsp_name,
329
381
                                               delete_pending,
330
382
                                               write_time_ts,
331
 
                                               ms_dfs_link,
332
383
                                               ea_list,
333
384
                                               lock_data_count,
334
385
                                               lock_data,
362
413
                uint16_t file_info_level;
363
414
                char *data = NULL;
364
415
                int data_size = 0;
365
 
                NTSTATUS status;
366
416
 
367
417
                /* the levels directly map to the passthru levels */
368
418
                file_info_level = in_file_info_class + 1000;
394
444
                break;
395
445
        }
396
446
 
 
447
        case 0x03:/* SMB2_GETINFO_SEC */
 
448
        {
 
449
                uint8_t *p_marshalled_sd = NULL;
 
450
                size_t sd_size = 0;
 
451
 
 
452
                status = smbd_do_query_security_desc(conn,
 
453
                                state,
 
454
                                fsp,
 
455
                                /* Security info wanted. */
 
456
                                in_additional_information,
 
457
                                in_output_buffer_length,
 
458
                                &p_marshalled_sd,
 
459
                                &sd_size);
 
460
 
 
461
                if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
 
462
                        /* Return needed size. */
 
463
                        state->out_output_buffer = data_blob_talloc(state,
 
464
                                                                    NULL,
 
465
                                                                    4);
 
466
                        if (tevent_req_nomem(state->out_output_buffer.data, req)) {
 
467
                                return tevent_req_post(req, ev);
 
468
                        }
 
469
                        SIVAL(state->out_output_buffer.data,0,(uint32_t)sd_size);
 
470
                        state->status = NT_STATUS_BUFFER_TOO_SMALL;
 
471
                        break;
 
472
                }
 
473
                if (!NT_STATUS_IS_OK(status)) {
 
474
                        DEBUG(10,("smbd_smb2_getinfo_send: "
 
475
                                 "smbd_do_query_security_desc of %s failed "
 
476
                                 "(%s)\n", fsp_str_dbg(fsp),
 
477
                                 nt_errstr(status)));
 
478
                        tevent_req_nterror(req, status);
 
479
                        return tevent_req_post(req, ev);
 
480
                }
 
481
 
 
482
                if (sd_size > 0) {
 
483
                        state->out_output_buffer = data_blob_talloc(state,
 
484
                                                                    p_marshalled_sd,
 
485
                                                                    sd_size);
 
486
                        if (tevent_req_nomem(state->out_output_buffer.data, req)) {
 
487
                                return tevent_req_post(req, ev);
 
488
                        }
 
489
                }
 
490
                break;
 
491
        }
 
492
 
397
493
        default:
 
494
                DEBUG(10,("smbd_smb2_getinfo_send: "
 
495
                        "unknown in_info_type of %u "
 
496
                        " for file %s\n",
 
497
                        (unsigned int)in_info_type,
 
498
                        fsp_str_dbg(fsp) ));
 
499
 
398
500
                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
399
501
                return tevent_req_post(req, ev);
400
502
        }
405
507
 
406
508
static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
407
509
                                       TALLOC_CTX *mem_ctx,
408
 
                                       DATA_BLOB *out_output_buffer)
 
510
                                       DATA_BLOB *out_output_buffer,
 
511
                                       NTSTATUS *pstatus)
409
512
{
410
513
        NTSTATUS status;
411
514
        struct smbd_smb2_getinfo_state *state = tevent_req_data(req,
418
521
 
419
522
        *out_output_buffer = state->out_output_buffer;
420
523
        talloc_steal(mem_ctx, out_output_buffer->data);
 
524
        *pstatus = state->status;
421
525
 
422
526
        tevent_req_received(req);
423
527
        return NT_STATUS_OK;