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

« back to all changes in this revision

Viewing changes to source3/smbd/trans2.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:
24
24
*/
25
25
 
26
26
#include "includes.h"
 
27
#include "system/filesys.h"
27
28
#include "version.h"
 
29
#include "smbd/smbd.h"
28
30
#include "smbd/globals.h"
29
31
#include "../libcli/auth/libcli_auth.h"
 
32
#include "../librpc/gen_ndr/xattr.h"
 
33
#include "../librpc/gen_ndr/ndr_security.h"
 
34
#include "libcli/security/security.h"
 
35
#include "trans2.h"
 
36
#include "auth.h"
 
37
#include "smbprofile.h"
 
38
#include "rpc_server/srv_pipe_hnd.h"
 
39
#include "libsmb/libsmb.h"
30
40
 
31
41
#define DIR_ENTRY_SAFETY_MARGIN 4096
32
42
 
501
511
                return NT_STATUS_EAS_NOT_SUPPORTED;
502
512
        }
503
513
 
 
514
        if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
 
515
                return NT_STATUS_ACCESS_DENIED;
 
516
        }
 
517
 
504
518
        /* For now setting EAs on streams isn't supported. */
505
519
        fname = smb_fname->base_name;
506
520
 
778
792
        int alignment_offset = 1; /* JRA. This used to be 3. Set to 1 to make netmon parse ok. */
779
793
        int data_alignment_offset = 0;
780
794
        bool overflow = False;
781
 
        struct smbd_server_connection *sconn = smbd_server_conn;
 
795
        struct smbd_server_connection *sconn = req->sconn;
782
796
        int max_send = sconn->smb1.sessions.max_send;
783
797
 
784
798
        /* Modify the data_to_send and datasize and set the error if
798
812
        if(params_to_send == 0 && data_to_send == 0) {
799
813
                reply_outbuf(req, 10, 0);
800
814
                show_msg((char *)req->outbuf);
801
 
                if (!srv_send_smb(smbd_server_fd(),
 
815
                if (!srv_send_smb(sconn,
802
816
                                (char *)req->outbuf,
803
817
                                true, req->seqnum+1,
804
818
                                IS_CONN_ENCRYPTED(conn),
937
951
 
938
952
                /* Send the packet */
939
953
                show_msg((char *)req->outbuf);
940
 
                if (!srv_send_smb(smbd_server_fd(),
 
954
                if (!srv_send_smb(sconn,
941
955
                                (char *)req->outbuf,
942
956
                                true, req->seqnum+1,
943
957
                                IS_CONN_ENCRYPTED(conn),
1000
1014
        uint32 share_mode;
1001
1015
        uint32 create_disposition;
1002
1016
        uint32 create_options = 0;
 
1017
        uint32_t private_flags = 0;
1003
1018
        TALLOC_CTX *ctx = talloc_tos();
1004
1019
 
1005
1020
        /*
1068
1083
                goto out;
1069
1084
        }
1070
1085
 
1071
 
        if (!map_open_params_to_ntcreate(smb_fname, deny_mode, open_ofun,
 
1086
        if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
 
1087
                                         open_ofun,
1072
1088
                                         &access_mask, &share_mode,
1073
1089
                                         &create_disposition,
1074
 
                                         &create_options)) {
 
1090
                                         &create_options,
 
1091
                                         &private_flags)) {
1075
1092
                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
1076
1093
                goto out;
1077
1094
        }
1115
1132
                open_attr,                              /* file_attributes */
1116
1133
                oplock_request,                         /* oplock_request */
1117
1134
                open_size,                              /* allocation_size */
 
1135
                private_flags,
1118
1136
                NULL,                                   /* sd */
1119
1137
                ea_list,                                /* ea_list */
1120
1138
                &fsp,                                   /* result */
1133
1151
        fattr = dos_mode(conn, smb_fname);
1134
1152
        mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
1135
1153
        inode = smb_fname->st.st_ex_ino;
1136
 
        if (fattr & aDIR) {
 
1154
        if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
1137
1155
                close_file(req, fsp, ERROR_CLOSE);
1138
1156
                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
1139
1157
                goto out;
1478
1496
                                    uint32_t mode,
1479
1497
                                    const char *fname,
1480
1498
                                    const struct smb_filename *smb_fname,
1481
 
                                    uint64_t space_remaining,
 
1499
                                    int space_remaining,
1482
1500
                                    uint8_t align,
1483
1501
                                    bool do_pad,
1484
1502
                                    char *base_data,
1499
1517
        char *nameptr;
1500
1518
        char *last_entry_ptr;
1501
1519
        bool was_8_3;
1502
 
        off_t off;
1503
 
        off_t pad = 0;
 
1520
        int off;
 
1521
        int pad = 0;
1504
1522
 
1505
1523
        *out_of_space = false;
1506
1524
 
1509
1527
        ZERO_STRUCT(create_date_ts);
1510
1528
        ZERO_STRUCT(cdate_ts);
1511
1529
 
1512
 
        if (!(mode & aDIR)) {
 
1530
        if (!(mode & FILE_ATTRIBUTE_DIRECTORY)) {
1513
1531
                file_size = get_file_size_stat(&smb_fname->st);
1514
1532
        }
1515
1533
        allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
1534
1552
        c_date = convert_timespec_to_time_t(cdate_ts);
1535
1553
 
1536
1554
        /* align the record */
1537
 
        off = PTR_DIFF(pdata, base_data);
 
1555
        SMB_ASSERT(align >= 1);
 
1556
 
 
1557
        off = (int)PTR_DIFF(pdata, base_data);
1538
1558
        pad = (off + (align-1)) & ~(align-1);
1539
1559
        pad -= off;
 
1560
 
 
1561
        if (pad && pad > space_remaining) {
 
1562
                *out_of_space = true;
 
1563
                DEBUG(9,("smbd_marshall_dir_entry: out of space "
 
1564
                        "for padding (wanted %u, had %d)\n",
 
1565
                        (unsigned int)pad,
 
1566
                        space_remaining ));
 
1567
                return false; /* Not finished - just out of space */
 
1568
        }
 
1569
 
1540
1570
        off += pad;
1541
1571
        /* initialize padding to 0 */
1542
1572
        if (pad) {
1544
1574
        }
1545
1575
        space_remaining -= pad;
1546
1576
 
 
1577
        DEBUG(10,("smbd_marshall_dir_entry: space_remaining = %d\n",
 
1578
                space_remaining ));
 
1579
 
1547
1580
        pdata += pad;
1548
1581
        p = pdata;
1549
1582
        last_entry_ptr = p;
1658
1691
                /* Max string size is 255 bytes. */
1659
1692
                if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
1660
1693
                        *out_of_space = true;
1661
 
                        DEBUG(9,("smbd_marshall_dir_entry: out of space\n"));
 
1694
                        DEBUG(9,("smbd_marshall_dir_entry: out of space "
 
1695
                                "(wanted %u, had %d)\n",
 
1696
                                (unsigned int)PTR_DIFF(p + 255 + ea_len,pdata),
 
1697
                                space_remaining ));
1662
1698
                        return False; /* Not finished - just out of space */
1663
1699
                }
1664
1700
 
2036
2072
 
2037
2073
        if (PTR_DIFF(p,pdata) > space_remaining) {
2038
2074
                *out_of_space = true;
2039
 
                DEBUG(9,("smbd_marshall_dir_entry: out of space\n"));
 
2075
                DEBUG(9,("smbd_marshall_dir_entry: out of space "
 
2076
                        "(wanted %u, had %d)\n",
 
2077
                        (unsigned int)PTR_DIFF(p,pdata),
 
2078
                        space_remaining ));
2040
2079
                return false; /* Not finished - just out of space */
2041
2080
        }
2042
2081
 
2231
2270
        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
2232
2271
        TALLOC_CTX *ctx = talloc_tos();
2233
2272
        struct dptr_struct *dirptr = NULL;
2234
 
        struct smbd_server_connection *sconn = smbd_server_conn;
 
2273
        struct smbd_server_connection *sconn = req->sconn;
2235
2274
 
2236
2275
        if (total_params < 13) {
2237
2276
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2321
2360
                        }
2322
2361
                        mask_contains_wcard = True;
2323
2362
                }
2324
 
                directory = talloc_strdup(talloc_tos(), "./");
2325
 
                if (!directory) {
2326
 
                        reply_nterror(req, NT_STATUS_NO_MEMORY);
2327
 
                        goto out;
2328
 
                }
2329
2363
        } else {
2330
2364
                *p = 0;
2331
2365
        }
2332
2366
 
 
2367
        if (p == NULL || p == directory) {
 
2368
                /* Ensure we don't have a directory name of "". */
 
2369
                directory = talloc_strdup(talloc_tos(), ".");
 
2370
                if (!directory) {
 
2371
                        reply_nterror(req, NT_STATUS_NO_MEMORY);
 
2372
                        goto out;
 
2373
                }
 
2374
        }
 
2375
 
2333
2376
        DEBUG(5,("dir=%s, mask = %s\n",directory, mask));
2334
2377
 
2335
2378
        if (info_level == SMB_FIND_EA_LIST) {
2382
2425
                needed as lanman2 assumes these are being saved between calls */
2383
2426
 
2384
2427
        ntstatus = dptr_create(conn,
 
2428
                                NULL, /* fsp */
2385
2429
                                directory,
2386
2430
                                False,
2387
2431
                                True,
2570
2614
        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
2571
2615
        TALLOC_CTX *ctx = talloc_tos();
2572
2616
        struct dptr_struct *dirptr;
2573
 
        struct smbd_server_connection *sconn = smbd_server_conn;
 
2617
        struct smbd_server_connection *sconn = req->sconn;
2574
2618
 
2575
2619
        if (total_params < 13) {
2576
2620
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2865
2909
        extended_info->samba_subversion |= (SAMBA_VERSION_VENDOR_PATCH & 0xffff);
2866
2910
#endif
2867
2911
        extended_info->samba_gitcommitdate = 0;
2868
 
#ifdef SAMBA_VERSION_GIT_COMMIT_TIME
2869
 
        unix_to_nt_time(&extended_info->samba_gitcommitdate, SAMBA_VERSION_GIT_COMMIT_TIME);
 
2912
#ifdef SAMBA_VERSION_COMMIT_TIME
 
2913
        unix_to_nt_time(&extended_info->samba_gitcommitdate, SAMBA_VERSION_COMMIT_TIME);
2870
2914
#endif
2871
2915
 
2872
2916
        memset(extended_info->samba_version_string, 0,
3116
3160
 
3117
3161
                case SMB_QUERY_FS_DEVICE_INFO:
3118
3162
                case SMB_FS_DEVICE_INFORMATION:
 
3163
                {
 
3164
                        uint32_t characteristics = FILE_DEVICE_IS_MOUNTED;
 
3165
 
 
3166
                        if (!CAN_WRITE(conn)) {
 
3167
                                characteristics |= FILE_READ_ONLY_DEVICE;
 
3168
                        }
3119
3169
                        data_len = 8;
3120
 
                        SIVAL(pdata,0,0); /* dev type */
3121
 
                        SIVAL(pdata,4,0); /* characteristics */
 
3170
                        SIVAL(pdata,0,FILE_DEVICE_DISK); /* dev type */
 
3171
                        SIVAL(pdata,4,characteristics);
3122
3172
                        break;
 
3173
                }
3123
3174
 
3124
3175
#ifdef HAVE_SYS_QUOTAS
3125
3176
                case SMB_FS_QUOTA_INFORMATION:
3156
3207
                        fsp.fnum = -1;
3157
3208
 
3158
3209
                        /* access check */
3159
 
                        if (conn->server_info->utok.uid != sec_initial_uid() &&
3160
 
                                        !conn->admin_user) {
 
3210
                        if (get_current_uid(conn) != 0) {
3161
3211
                                DEBUG(0,("set_user_quota: access_denied "
3162
3212
                                         "service [%s] user [%s]\n",
3163
3213
                                         lp_servicename(SNUM(conn)),
3164
 
                                         conn->server_info->unix_name));
 
3214
                                         conn->session_info->unix_name));
3165
3215
                                return NT_STATUS_ACCESS_DENIED;
3166
3216
                        }
3167
3217
 
3219
3269
                case SMB_QUERY_CIFS_UNIX_INFO:
3220
3270
                {
3221
3271
                        bool large_write = lp_min_receive_file_size() &&
3222
 
                                        !srv_is_signing_active(smbd_server_conn);
3223
 
                        bool large_read = !srv_is_signing_active(smbd_server_conn);
 
3272
                                        !srv_is_signing_active(conn->sconn);
 
3273
                        bool large_read = !srv_is_signing_active(conn->sconn);
3224
3274
                        int encrypt_caps = 0;
3225
3275
 
3226
3276
                        if (!lp_unix_extensions()) {
3314
3364
                         * in our list of SIDs.
3315
3365
                         */
3316
3366
                        if (nt_token_check_sid(&global_sid_Builtin_Guests,
3317
 
                                               conn->server_info->ptok)) {
 
3367
                                               conn->session_info->security_token)) {
3318
3368
                                flags |= SMB_WHOAMI_GUEST;
3319
3369
                        }
3320
3370
 
3322
3372
                         * is in our list of SIDs.
3323
3373
                         */
3324
3374
                        if (nt_token_check_sid(&global_sid_Authenticated_Users,
3325
 
                                               conn->server_info->ptok)) {
 
3375
                                               conn->session_info->security_token)) {
3326
3376
                                flags &= ~SMB_WHOAMI_GUEST;
3327
3377
                        }
3328
3378
 
3338
3388
                            + 4 /* num_sids */
3339
3389
                            + 4 /* SID bytes */
3340
3390
                            + 4 /* pad/reserved */
3341
 
                            + (conn->server_info->utok.ngroups * 8)
 
3391
                            + (conn->session_info->utok.ngroups * 8)
3342
3392
                                /* groups list */
3343
 
                            + (conn->server_info->ptok->num_sids *
 
3393
                            + (conn->session_info->security_token->num_sids *
3344
3394
                                    SID_MAX_SIZE)
3345
3395
                                /* SID list */;
3346
3396
 
3347
3397
                        SIVAL(pdata, 0, flags);
3348
3398
                        SIVAL(pdata, 4, SMB_WHOAMI_MASK);
3349
3399
                        SBIG_UINT(pdata, 8,
3350
 
                                  (uint64_t)conn->server_info->utok.uid);
 
3400
                                  (uint64_t)conn->session_info->utok.uid);
3351
3401
                        SBIG_UINT(pdata, 16,
3352
 
                                  (uint64_t)conn->server_info->utok.gid);
 
3402
                                  (uint64_t)conn->session_info->utok.gid);
3353
3403
 
3354
3404
 
3355
3405
                        if (data_len >= max_data_bytes) {
3364
3414
                                break;
3365
3415
                        }
3366
3416
 
3367
 
                        SIVAL(pdata, 24, conn->server_info->utok.ngroups);
3368
 
                        SIVAL(pdata, 28, conn->server_info->num_sids);
 
3417
                        SIVAL(pdata, 24, conn->session_info->utok.ngroups);
 
3418
                        SIVAL(pdata, 28, conn->session_info->security_token->num_sids);
3369
3419
 
3370
3420
                        /* We walk the SID list twice, but this call is fairly
3371
3421
                         * infrequent, and I don't expect that it's performance
3372
3422
                         * sensitive -- jpeach
3373
3423
                         */
3374
3424
                        for (i = 0, sid_bytes = 0;
3375
 
                             i < conn->server_info->ptok->num_sids; ++i) {
 
3425
                             i < conn->session_info->security_token->num_sids; ++i) {
3376
3426
                                sid_bytes += ndr_size_dom_sid(
3377
 
                                        &conn->server_info->ptok->user_sids[i],
3378
 
                                        NULL, 
 
3427
                                        &conn->session_info->security_token->sids[i],
3379
3428
                                        0);
3380
3429
                        }
3381
3430
 
3387
3436
                        data_len = 40;
3388
3437
 
3389
3438
                        /* GID list */
3390
 
                        for (i = 0; i < conn->server_info->utok.ngroups; ++i) {
 
3439
                        for (i = 0; i < conn->session_info->utok.ngroups; ++i) {
3391
3440
                                SBIG_UINT(pdata, data_len,
3392
 
                                          (uint64_t)conn->server_info->utok.groups[i]);
 
3441
                                          (uint64_t)conn->session_info->utok.groups[i]);
3393
3442
                                data_len += 8;
3394
3443
                        }
3395
3444
 
3396
3445
                        /* SID list */
3397
3446
                        for (i = 0;
3398
 
                            i < conn->server_info->ptok->num_sids; ++i) {
 
3447
                            i < conn->session_info->security_token->num_sids; ++i) {
3399
3448
                                int sid_len = ndr_size_dom_sid(
3400
 
                                        &conn->server_info->ptok->user_sids[i],
3401
 
                                        NULL,
 
3449
                                        &conn->session_info->security_token->sids[i],
3402
3450
                                        0);
3403
3451
 
3404
3452
                                sid_linearize(pdata + data_len, sid_len,
3405
 
                                    &conn->server_info->ptok->user_sids[i]);
 
3453
                                    &conn->session_info->security_token->sids[i]);
3406
3454
                                data_len += sid_len;
3407
3455
                        }
3408
3456
 
3601
3649
                                        return;
3602
3650
                                }
3603
3651
 
 
3652
                                if (req->sconn->smb1.echo_handler.trusted_fde) {
 
3653
                                        DEBUG( 2,("call_trans2setfsinfo: "
 
3654
                                                "request transport encryption disabled"
 
3655
                                                "with 'fork echo handler = yes'\n"));
 
3656
                                        reply_nterror(
 
3657
                                                req,
 
3658
                                                NT_STATUS_NOT_SUPPORTED);
 
3659
                                        return;
 
3660
                                }
 
3661
 
3604
3662
                                DEBUG( 4,("call_trans2setfsinfo: "
3605
3663
                                        "request transport encryption.\n"));
3606
3664
 
3644
3702
                                ZERO_STRUCT(quotas);
3645
3703
 
3646
3704
                                /* access check */
3647
 
                                if (((conn->server_info->utok.uid != sec_initial_uid()) && !conn->admin_user)
3648
 
                                    ||!CAN_WRITE(conn)) {
 
3705
                                if ((get_current_uid(conn) != 0) || !CAN_WRITE(conn)) {
3649
3706
                                        DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
3650
3707
                                                 lp_servicename(SNUM(conn)),
3651
 
                                                 conn->server_info->unix_name));
 
3708
                                                 conn->session_info->unix_name));
3652
3709
                                        reply_nterror(req, NT_STATUS_ACCESS_DENIED);
3653
3710
                                        return;
3654
3711
                                }
3679
3736
                                /* unknown_1 24 NULL bytes in pdata*/
3680
3737
 
3681
3738
                                /* the soft quotas 8 bytes (uint64_t)*/
3682
 
                                quotas.softlim = (uint64_t)IVAL(pdata,24);
3683
 
#ifdef LARGE_SMB_OFF_T
3684
 
                                quotas.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
3685
 
#else /* LARGE_SMB_OFF_T */
3686
 
                                if ((IVAL(pdata,28) != 0)&&
3687
 
                                        ((quotas.softlim != 0xFFFFFFFF)||
3688
 
                                        (IVAL(pdata,28)!=0xFFFFFFFF))) {
3689
 
                                        /* more than 32 bits? */
3690
 
                                        reply_nterror(
3691
 
                                                req,
3692
 
                                                NT_STATUS_INVALID_PARAMETER);
3693
 
                                        return;
3694
 
                                }
3695
 
#endif /* LARGE_SMB_OFF_T */
 
3739
                                quotas.softlim = BVAL(pdata,24);
3696
3740
 
3697
3741
                                /* the hard quotas 8 bytes (uint64_t)*/
3698
 
                                quotas.hardlim = (uint64_t)IVAL(pdata,32);
3699
 
#ifdef LARGE_SMB_OFF_T
3700
 
                                quotas.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
3701
 
#else /* LARGE_SMB_OFF_T */
3702
 
                                if ((IVAL(pdata,36) != 0)&&
3703
 
                                        ((quotas.hardlim != 0xFFFFFFFF)||
3704
 
                                        (IVAL(pdata,36)!=0xFFFFFFFF))) {
3705
 
                                        /* more than 32 bits? */
3706
 
                                        reply_nterror(
3707
 
                                                req,
3708
 
                                                NT_STATUS_INVALID_PARAMETER);
3709
 
                                        return;
3710
 
                                }
3711
 
#endif /* LARGE_SMB_OFF_T */
 
3742
                                quotas.hardlim = BVAL(pdata,32);
3712
3743
 
3713
3744
                                /* quota_flags 2 bytes **/
3714
3745
                                quotas.qflags = SVAL(pdata,40);
4162
4193
                               struct smb_filename *smb_fname,
4163
4194
                               bool delete_pending,
4164
4195
                               struct timespec write_time_ts,
4165
 
                               bool ms_dfs_link,
4166
4196
                               struct ea_list *ea_list,
4167
4197
                               int lock_data_count,
4168
4198
                               char *lock_data,
4197
4227
                 smb_fname_str_dbg(smb_fname), fsp ? fsp->fnum : -1,
4198
4228
                 info_level, max_data_bytes));
4199
4229
 
4200
 
        if (ms_dfs_link) {
4201
 
                mode = dos_mode_msdfs(conn, smb_fname);
4202
 
        } else {
4203
 
                mode = dos_mode(conn, smb_fname);
4204
 
        }
4205
 
 
 
4230
        mode = dos_mode(conn, smb_fname);
4206
4231
        nlink = psbuf->st_ex_nlink;
4207
4232
 
4208
 
        if (nlink && (mode&aDIR)) {
 
4233
        if (nlink && (mode&FILE_ATTRIBUTE_DIRECTORY)) {
4209
4234
                nlink = 1;
4210
4235
        }
4211
4236
 
4280
4305
                /* Do we have this path open ? */
4281
4306
                files_struct *fsp1;
4282
4307
                struct file_id fileid = vfs_file_id_from_sbuf(conn, psbuf);
4283
 
                fsp1 = file_find_di_first(fileid);
 
4308
                fsp1 = file_find_di_first(conn->sconn, fileid);
4284
4309
                if (fsp1 && fsp1->initial_allocation_size) {
4285
4310
                        allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp1, psbuf);
4286
4311
                }
4287
4312
        }
4288
4313
 
4289
 
        if (!(mode & aDIR)) {
 
4314
        if (!(mode & FILE_ATTRIBUTE_DIRECTORY)) {
4290
4315
                file_size = get_file_size_stat(psbuf);
4291
4316
        }
4292
4317
 
4456
4481
                        SOFF_T(pdata,8,file_size);
4457
4482
                        SIVAL(pdata,16,nlink);
4458
4483
                        SCVAL(pdata,20,delete_pending?1:0);
4459
 
                        SCVAL(pdata,21,(mode&aDIR)?1:0);
 
4484
                        SCVAL(pdata,21,(mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
4460
4485
                        SSVAL(pdata,22,0); /* Padding. */
4461
4486
                        break;
4462
4487
 
4539
4564
                        SOFF_T(pdata,8,file_size);
4540
4565
                        SIVAL(pdata,16,nlink);
4541
4566
                        SCVAL(pdata,20,delete_pending);
4542
 
                        SCVAL(pdata,21,(mode&aDIR)?1:0);
 
4567
                        SCVAL(pdata,21,(mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
4543
4568
                        SSVAL(pdata,22,0);
4544
4569
                        pdata += 24;
4545
4570
                        SIVAL(pdata,0,ea_size);
4570
4595
                        SBVAL(pdata,    0x30, file_size);
4571
4596
                        SIVAL(pdata,    0x38, nlink);
4572
4597
                        SCVAL(pdata,    0x3C, delete_pending);
4573
 
                        SCVAL(pdata,    0x3D, (mode&aDIR)?1:0);
 
4598
                        SCVAL(pdata,    0x3D, (mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
4574
4599
                        SSVAL(pdata,    0x3E, 0); /* padding */
4575
4600
                        SBVAL(pdata,    0x40, file_index);
4576
4601
                        SIVAL(pdata,    0x48, ea_size);
4720
4745
                        pdata = store_file_unix_basic(conn, pdata, fsp, psbuf);
4721
4746
                        data_size = PTR_DIFF(pdata,(*ppdata));
4722
4747
 
4723
 
                        {
4724
 
                                int i;
4725
 
                                DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
4726
 
 
4727
 
                                for (i=0; i<100; i++)
4728
 
                                        DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
4729
 
                                DEBUG(4,("\n"));
4730
 
                        }
 
4748
                        DEBUG(4,("smbd_do_qfilepathinfo: "
 
4749
                                 "SMB_QUERY_FILE_UNIX_BASIC\n"));
 
4750
                        dump_data(4, (uint8_t *)(*ppdata), data_size);
4731
4751
 
4732
4752
                        break;
4733
4753
 
4789
4809
                                uint16 num_file_acls = 0;
4790
4810
                                uint16 num_def_acls = 0;
4791
4811
 
4792
 
                                if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
 
4812
                                if (fsp && fsp->fh->fd != -1) {
4793
4813
                                        file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp);
4794
4814
                                } else {
4795
4815
                                        file_acl =
4878
4898
                {
4879
4899
                        uint64_t count;
4880
4900
                        uint64_t offset;
4881
 
                        uint32 lock_pid;
 
4901
                        uint64_t smblctx;
4882
4902
                        enum brl_type lock_type;
4883
4903
 
4884
4904
                        /* We need an open file with a real fd for this. */
4885
 
                        if (!fsp || fsp->is_directory || fsp->fh->fd == -1) {
 
4905
                        if (!fsp || fsp->fh->fd == -1) {
4886
4906
                                return NT_STATUS_INVALID_LEVEL;
4887
4907
                        }
4888
4908
 
4903
4923
                                        return NT_STATUS_INVALID_PARAMETER;
4904
4924
                        }
4905
4925
 
4906
 
                        lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
 
4926
                        smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET);
4907
4927
#if defined(HAVE_LONGLONG)
4908
4928
                        offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
4909
4929
                                        ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
4915
4935
#endif /* HAVE_LONGLONG */
4916
4936
 
4917
4937
                        status = query_lock(fsp,
4918
 
                                        &lock_pid,
 
4938
                                        &smblctx,
4919
4939
                                        &count,
4920
4940
                                        &offset,
4921
4941
                                        &lock_type,
4927
4947
 
4928
4948
                                SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, lock_type);
4929
4949
                                SSVAL(pdata, POSIX_LOCK_FLAGS_OFFSET, 0);
4930
 
                                SIVAL(pdata, POSIX_LOCK_PID_OFFSET, lock_pid);
 
4950
                                SIVAL(pdata, POSIX_LOCK_PID_OFFSET, (uint32_t)smblctx);
4931
4951
#if defined(HAVE_LONGLONG)
4932
4952
                                SIVAL(pdata, POSIX_LOCK_START_OFFSET, (uint32)(offset & 0xFFFFFFFF));
4933
4953
                                SIVAL(pdata, POSIX_LOCK_START_OFFSET + 4, (uint32)((offset >> 32) & 0xFFFFFFFF));
4983
5003
        struct ea_list *ea_list = NULL;
4984
5004
        int lock_data_count = 0;
4985
5005
        char *lock_data = NULL;
4986
 
        bool ms_dfs_link = false;
4987
5006
        NTSTATUS status = NT_STATUS_OK;
4988
5007
 
4989
5008
        if (!params) {
5036
5055
 
5037
5056
                        /* We know this name is ok, it's already passed the checks. */
5038
5057
 
5039
 
                } else if(fsp->is_directory || fsp->fh->fd == -1) {
 
5058
                } else if(fsp->fh->fd == -1) {
5040
5059
                        /*
5041
5060
                         * This is actually a QFILEINFO on a directory
5042
5061
                         * handle (returned from an NT SMB). NT5.0 seems
5066
5085
                        }
5067
5086
 
5068
5087
                        fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
5069
 
                        get_file_infos(fileid, &delete_pending, &write_time_ts);
 
5088
                        get_file_infos(fileid, fsp->name_hash, &delete_pending, &write_time_ts);
5070
5089
                } else {
5071
5090
                        /*
5072
5091
                         * Original code - this is an open file.
5073
5092
                         */
5074
 
                        if (!check_fsp(conn, req, fsp)) {
5075
 
                                return;
5076
 
                        }
5077
 
 
5078
5093
                        if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
5079
5094
                                DEBUG(3, ("fstat of fnum %d failed (%s)\n",
5080
5095
                                          fsp->fnum, strerror(errno)));
5083
5098
                                return;
5084
5099
                        }
5085
5100
                        fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
5086
 
                        get_file_infos(fileid, &delete_pending, &write_time_ts);
 
5101
                        get_file_infos(fileid, fsp->name_hash, &delete_pending, &write_time_ts);
5087
5102
                }
5088
5103
 
5089
5104
        } else {
 
5105
                uint32_t name_hash;
5090
5106
                char *fname = NULL;
5091
5107
 
5092
5108
                /* qpathinfo */
5173
5189
                                }
5174
5190
                        }
5175
5191
 
 
5192
                        status = file_name_hash(conn,
 
5193
                                        smb_fname_str_dbg(smb_fname_base),
 
5194
                                        &name_hash);
 
5195
                        if (!NT_STATUS_IS_OK(status)) {
 
5196
                                TALLOC_FREE(smb_fname_base);
 
5197
                                reply_nterror(req, status);
 
5198
                                return;
 
5199
                        }
 
5200
 
5176
5201
                        fileid = vfs_file_id_from_sbuf(conn,
5177
5202
                                                       &smb_fname_base->st);
5178
5203
                        TALLOC_FREE(smb_fname_base);
5179
 
                        get_file_infos(fileid, &delete_pending, NULL);
 
5204
                        get_file_infos(fileid, name_hash, &delete_pending, NULL);
5180
5205
                        if (delete_pending) {
5181
5206
                                reply_nterror(req, NT_STATUS_DELETE_PENDING);
5182
5207
                                return;
5195
5220
                                return;
5196
5221
                        }
5197
5222
 
5198
 
                } else if (!VALID_STAT(smb_fname->st) &&
5199
 
                           SMB_VFS_STAT(conn, smb_fname) &&
5200
 
                           (info_level != SMB_INFO_IS_NAME_VALID)) {
5201
 
                        ms_dfs_link = check_msdfs_link(conn,
5202
 
                                                       smb_fname->base_name,
5203
 
                                                       &smb_fname->st);
5204
 
 
5205
 
                        if (!ms_dfs_link) {
 
5223
                } else {
 
5224
                        if (SMB_VFS_STAT(conn, smb_fname) != 0) {
5206
5225
                                DEBUG(3,("call_trans2qfilepathinfo: "
5207
5226
                                         "SMB_VFS_STAT of %s failed (%s)\n",
5208
5227
                                         smb_fname_str_dbg(smb_fname),
5213
5232
                        }
5214
5233
                }
5215
5234
 
 
5235
                status = file_name_hash(conn,
 
5236
                                smb_fname_str_dbg(smb_fname),
 
5237
                                &name_hash);
 
5238
                if (!NT_STATUS_IS_OK(status)) {
 
5239
                        reply_nterror(req, status);
 
5240
                        return;
 
5241
                }
 
5242
 
5216
5243
                fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
5217
 
                get_file_infos(fileid, &delete_pending, &write_time_ts);
 
5244
                get_file_infos(fileid, name_hash, &delete_pending, &write_time_ts);
5218
5245
                if (delete_pending) {
5219
5246
                        reply_nterror(req, NT_STATUS_DELETE_PENDING);
5220
5247
                        return;
5326
5353
        status = smbd_do_qfilepathinfo(conn, req, info_level,
5327
5354
                                       fsp, smb_fname,
5328
5355
                                       delete_pending, write_time_ts,
5329
 
                                       ms_dfs_link, ea_list,
 
5356
                                       ea_list,
5330
5357
                                       lock_data_count, lock_data,
5331
5358
                                       req->flags2, max_data_bytes,
5332
5359
                                       ppdata, &data_size);
5348
5375
 
5349
5376
NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
5350
5377
                connection_struct *conn,
 
5378
                struct smb_request *req,
 
5379
                bool overwrite_if_exists,
5351
5380
                const struct smb_filename *smb_fname_old,
5352
 
                const struct smb_filename *smb_fname_new)
 
5381
                struct smb_filename *smb_fname_new)
5353
5382
{
5354
5383
        NTSTATUS status = NT_STATUS_OK;
5355
5384
 
5358
5387
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5359
5388
        }
5360
5389
 
5361
 
        /* Disallow if newname already exists. */
5362
5390
        if (VALID_STAT(smb_fname_new->st)) {
5363
 
                return NT_STATUS_OBJECT_NAME_COLLISION;
 
5391
                if (overwrite_if_exists) {
 
5392
                        if (S_ISDIR(smb_fname_new->st.st_ex_mode)) {
 
5393
                                return NT_STATUS_FILE_IS_A_DIRECTORY;
 
5394
                        }
 
5395
                        status = unlink_internals(conn,
 
5396
                                                req,
 
5397
                                                FILE_ATTRIBUTE_NORMAL,
 
5398
                                                smb_fname_new,
 
5399
                                                false);
 
5400
                        if (!NT_STATUS_IS_OK(status)) {
 
5401
                                return status;
 
5402
                        }
 
5403
                } else {
 
5404
                        /* Disallow if newname already exists. */
 
5405
                        return NT_STATUS_OBJECT_NAME_COLLISION;
 
5406
                }
5364
5407
        }
5365
5408
 
5366
5409
        /* No links from a directory. */
5407
5450
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5408
5451
        }
5409
5452
 
 
5453
        if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
 
5454
                return NT_STATUS_ACCESS_DENIED;
 
5455
        }
 
5456
 
5410
5457
        /* get some defaults (no modifications) if any info is zero or -1. */
5411
5458
        if (null_timespec(ft->create_time)) {
5412
5459
                action &= ~FILE_NOTIFY_CHANGE_CREATION;
5510
5557
 
5511
5558
        if (dosmode) {
5512
5559
                if (S_ISDIR(smb_fname_base->st.st_ex_mode)) {
5513
 
                        dosmode |= aDIR;
 
5560
                        dosmode |= FILE_ATTRIBUTE_DIRECTORY;
5514
5561
                } else {
5515
 
                        dosmode &= ~aDIR;
 
5562
                        dosmode &= ~FILE_ATTRIBUTE_DIRECTORY;
5516
5563
                }
5517
5564
        }
5518
5565
 
5560
5607
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
5561
5608
        }
5562
5609
 
 
5610
        if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
 
5611
                return NT_STATUS_ACCESS_DENIED;
 
5612
        }
 
5613
 
5563
5614
        DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size));
5564
5615
 
5565
5616
        if (size == get_file_size_stat(psbuf)) {
5590
5641
                req,                                    /* req */
5591
5642
                0,                                      /* root_dir_fid */
5592
5643
                smb_fname_tmp,                          /* fname */
5593
 
                FILE_WRITE_ATTRIBUTES,                  /* access_mask */
 
5644
                FILE_WRITE_DATA,                        /* access_mask */
5594
5645
                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
5595
5646
                    FILE_SHARE_DELETE),
5596
5647
                FILE_OPEN,                              /* create_disposition*/
5598
5649
                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
5599
5650
                FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
5600
5651
                0,                                      /* allocation_size */
 
5652
                0,                                      /* private_flags */
5601
5653
                NULL,                                   /* sd */
5602
5654
                NULL,                                   /* ea_list */
5603
5655
                &new_fsp,                               /* result */
5665
5717
        if (!ea_list) {
5666
5718
                return NT_STATUS_INVALID_PARAMETER;
5667
5719
        }
 
5720
 
 
5721
        if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
 
5722
                return NT_STATUS_ACCESS_DENIED;
 
5723
        }
 
5724
 
5668
5725
        status = set_ea(conn, fsp, smb_fname, ea_list);
5669
5726
 
5670
5727
        return status;
5707
5764
        if (!ea_list) {
5708
5765
                return NT_STATUS_INVALID_PARAMETER;
5709
5766
        }
 
5767
 
 
5768
        if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
 
5769
                return NT_STATUS_ACCESS_DENIED;
 
5770
        }
 
5771
 
5710
5772
        status = set_ea(conn, fsp, fsp->fsp_name, ea_list);
5711
5773
 
5712
5774
        DEBUG(10, ("smb_set_file_full_ea_info on file %s returned %s\n",
5757
5819
 
5758
5820
        /* The set is across all open files on this dev/inode pair. */
5759
5821
        if (!set_delete_on_close(fsp, delete_on_close,
5760
 
                                 &conn->server_info->utok)) {
 
5822
                                 &conn->session_info->utok)) {
5761
5823
                return NT_STATUS_ACCESS_DENIED;
5762
5824
        }
5763
5825
        return NT_STATUS_OK;
5869
5931
static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
5870
5932
                                        struct smb_request *req,
5871
5933
                                        const char *pdata, int total_data,
5872
 
                                        const struct smb_filename *smb_fname_new)
 
5934
                                        struct smb_filename *smb_fname_new)
5873
5935
{
5874
5936
        char *oldname = NULL;
5875
5937
        struct smb_filename *smb_fname_old = NULL;
5901
5963
                return status;
5902
5964
        }
5903
5965
 
5904
 
        return hardlink_internals(ctx, conn, smb_fname_old, smb_fname_new);
 
5966
        return hardlink_internals(ctx, conn, req, false,
 
5967
                        smb_fname_old, smb_fname_new);
 
5968
}
 
5969
 
 
5970
/****************************************************************************
 
5971
 Deal with SMB2_FILE_RENAME_INFORMATION_INTERNAL
 
5972
****************************************************************************/
 
5973
 
 
5974
static NTSTATUS smb2_file_rename_information(connection_struct *conn,
 
5975
                                            struct smb_request *req,
 
5976
                                            const char *pdata,
 
5977
                                            int total_data,
 
5978
                                            files_struct *fsp,
 
5979
                                            struct smb_filename *smb_fname_src)
 
5980
{
 
5981
        bool overwrite;
 
5982
        uint32_t len;
 
5983
        char *newname = NULL;
 
5984
        struct smb_filename *smb_fname_dst = NULL;
 
5985
        NTSTATUS status = NT_STATUS_OK;
 
5986
        TALLOC_CTX *ctx = talloc_tos();
 
5987
 
 
5988
        if (!fsp) {
 
5989
                return NT_STATUS_INVALID_HANDLE;
 
5990
        }
 
5991
 
 
5992
        if (total_data < 20) {
 
5993
                return NT_STATUS_INVALID_PARAMETER;
 
5994
        }
 
5995
 
 
5996
        overwrite = (CVAL(pdata,0) ? True : False);
 
5997
        len = IVAL(pdata,16);
 
5998
 
 
5999
        if (len > (total_data - 20) || (len == 0)) {
 
6000
                return NT_STATUS_INVALID_PARAMETER;
 
6001
        }
 
6002
 
 
6003
        srvstr_get_path(ctx, pdata, req->flags2, &newname,
 
6004
                                &pdata[20], len, STR_TERMINATE,
 
6005
                                &status);
 
6006
        if (!NT_STATUS_IS_OK(status)) {
 
6007
                return status;
 
6008
        }
 
6009
 
 
6010
        DEBUG(10,("smb2_file_rename_information: got name |%s|\n",
 
6011
                                newname));
 
6012
 
 
6013
        status = filename_convert(ctx,
 
6014
                                conn,
 
6015
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
 
6016
                                newname,
 
6017
                                UCF_SAVE_LCOMP,
 
6018
                                NULL,
 
6019
                                &smb_fname_dst);
 
6020
        if (!NT_STATUS_IS_OK(status)) {
 
6021
                return status;
 
6022
        }
 
6023
 
 
6024
        if (fsp->base_fsp) {
 
6025
                /* newname must be a stream name. */
 
6026
                if (newname[0] != ':') {
 
6027
                        return NT_STATUS_NOT_SUPPORTED;
 
6028
                }
 
6029
 
 
6030
                /* Create an smb_fname to call rename_internals_fsp() with. */
 
6031
                status = create_synthetic_smb_fname(talloc_tos(),
 
6032
                    fsp->base_fsp->fsp_name->base_name, newname, NULL,
 
6033
                    &smb_fname_dst);
 
6034
                if (!NT_STATUS_IS_OK(status)) {
 
6035
                        goto out;
 
6036
                }
 
6037
 
 
6038
                /*
 
6039
                 * Set the original last component, since
 
6040
                 * rename_internals_fsp() requires it.
 
6041
                 */
 
6042
                smb_fname_dst->original_lcomp = talloc_strdup(smb_fname_dst,
 
6043
                                                              newname);
 
6044
                if (smb_fname_dst->original_lcomp == NULL) {
 
6045
                        status = NT_STATUS_NO_MEMORY;
 
6046
                        goto out;
 
6047
                }
 
6048
 
 
6049
        }
 
6050
 
 
6051
        DEBUG(10,("smb2_file_rename_information: "
 
6052
                  "SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
 
6053
                  fsp->fnum, fsp_str_dbg(fsp),
 
6054
                  smb_fname_str_dbg(smb_fname_dst)));
 
6055
        status = rename_internals_fsp(conn, fsp, smb_fname_dst,
 
6056
                                (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM),
 
6057
                                overwrite);
 
6058
 
 
6059
 out:
 
6060
        TALLOC_FREE(smb_fname_dst);
 
6061
        return status;
 
6062
}
 
6063
 
 
6064
static NTSTATUS smb_file_link_information(connection_struct *conn,
 
6065
                                            struct smb_request *req,
 
6066
                                            const char *pdata,
 
6067
                                            int total_data,
 
6068
                                            files_struct *fsp,
 
6069
                                            struct smb_filename *smb_fname_src)
 
6070
{
 
6071
        bool overwrite;
 
6072
        uint32_t len;
 
6073
        char *newname = NULL;
 
6074
        struct smb_filename *smb_fname_dst = NULL;
 
6075
        NTSTATUS status = NT_STATUS_OK;
 
6076
        TALLOC_CTX *ctx = talloc_tos();
 
6077
 
 
6078
        if (!fsp) {
 
6079
                return NT_STATUS_INVALID_HANDLE;
 
6080
        }
 
6081
 
 
6082
        if (total_data < 20) {
 
6083
                return NT_STATUS_INVALID_PARAMETER;
 
6084
        }
 
6085
 
 
6086
        overwrite = (CVAL(pdata,0) ? true : false);
 
6087
        len = IVAL(pdata,16);
 
6088
 
 
6089
        if (len > (total_data - 20) || (len == 0)) {
 
6090
                return NT_STATUS_INVALID_PARAMETER;
 
6091
        }
 
6092
 
 
6093
        srvstr_get_path(ctx, pdata, req->flags2, &newname,
 
6094
                                &pdata[20], len, STR_TERMINATE,
 
6095
                                &status);
 
6096
        if (!NT_STATUS_IS_OK(status)) {
 
6097
                return status;
 
6098
        }
 
6099
 
 
6100
        DEBUG(10,("smb_file_link_information: got name |%s|\n",
 
6101
                                newname));
 
6102
 
 
6103
        status = filename_convert(ctx,
 
6104
                                conn,
 
6105
                                req->flags2 & FLAGS2_DFS_PATHNAMES,
 
6106
                                newname,
 
6107
                                UCF_SAVE_LCOMP,
 
6108
                                NULL,
 
6109
                                &smb_fname_dst);
 
6110
        if (!NT_STATUS_IS_OK(status)) {
 
6111
                return status;
 
6112
        }
 
6113
 
 
6114
        if (fsp->base_fsp) {
 
6115
                /* No stream names. */
 
6116
                return NT_STATUS_NOT_SUPPORTED;
 
6117
        }
 
6118
 
 
6119
        DEBUG(10,("smb_file_link_information: "
 
6120
                  "SMB_FILE_LINK_INFORMATION (fnum %d) %s -> %s\n",
 
6121
                  fsp->fnum, fsp_str_dbg(fsp),
 
6122
                  smb_fname_str_dbg(smb_fname_dst)));
 
6123
        status = hardlink_internals(ctx,
 
6124
                                conn,
 
6125
                                req,
 
6126
                                overwrite,
 
6127
                                fsp->fsp_name,
 
6128
                                smb_fname_dst);
 
6129
 
 
6130
        TALLOC_FREE(smb_fname_dst);
 
6131
        return status;
5905
6132
}
5906
6133
 
5907
6134
/****************************************************************************
6012
6239
                if (p) {
6013
6240
                        p[1] = '\0';
6014
6241
                } else {
6015
 
                        base_name = talloc_strdup(ctx, "./");
 
6242
                        base_name = talloc_strdup(ctx, "");
6016
6243
                        if (!base_name) {
6017
6244
                                return NT_STATUS_NO_MEMORY;
6018
6245
                        }
6148
6375
{
6149
6376
        uint64_t count;
6150
6377
        uint64_t offset;
6151
 
        uint32 lock_pid;
 
6378
        uint64_t smblctx;
6152
6379
        bool blocking_lock = False;
6153
6380
        enum brl_type lock_type;
6154
6381
 
6192
6419
                blocking_lock = False;
6193
6420
        }
6194
6421
 
6195
 
        lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
 
6422
        smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET);
6196
6423
#if defined(HAVE_LONGLONG)
6197
6424
        offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
6198
6425
                        ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
6204
6431
#endif /* HAVE_LONGLONG */
6205
6432
 
6206
6433
        DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u,"
6207
 
                        "lock_pid = %u, count = %.0f, offset = %.0f\n",
 
6434
                        "smblctx = %llu, count = %.0f, offset = %.0f\n",
6208
6435
                fsp_str_dbg(fsp),
6209
6436
                (unsigned int)lock_type,
6210
 
                (unsigned int)lock_pid,
 
6437
                (unsigned long long)smblctx,
6211
6438
                (double)count,
6212
6439
                (double)offset ));
6213
6440
 
6214
6441
        if (lock_type == UNLOCK_LOCK) {
6215
 
                status = do_unlock(smbd_messaging_context(),
 
6442
                status = do_unlock(req->sconn->msg_ctx,
6216
6443
                                fsp,
6217
 
                                lock_pid,
 
6444
                                smblctx,
6218
6445
                                count,
6219
6446
                                offset,
6220
6447
                                POSIX_LOCK);
6221
6448
        } else {
6222
 
                uint32 block_smbpid;
 
6449
                uint64_t block_smblctx;
6223
6450
 
6224
 
                struct byte_range_lock *br_lck = do_lock(smbd_messaging_context(),
 
6451
                struct byte_range_lock *br_lck = do_lock(req->sconn->msg_ctx,
6225
6452
                                                        fsp,
6226
 
                                                        lock_pid,
 
6453
                                                        smblctx,
6227
6454
                                                        count,
6228
6455
                                                        offset,
6229
6456
                                                        lock_type,
6230
6457
                                                        POSIX_LOCK,
6231
6458
                                                        blocking_lock,
6232
6459
                                                        &status,
6233
 
                                                        &block_smbpid,
 
6460
                                                        &block_smblctx,
6234
6461
                                                        NULL);
6235
6462
 
6236
6463
                if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
6244
6471
                                                fsp,
6245
6472
                                                -1, /* infinite timeout. */
6246
6473
                                                0,
6247
 
                                                lock_pid,
 
6474
                                                smblctx,
6248
6475
                                                lock_type,
6249
6476
                                                POSIX_LOCK,
6250
6477
                                                offset,
6251
6478
                                                count,
6252
 
                                                block_smbpid)) {
 
6479
                                                block_smblctx)) {
6253
6480
                                TALLOC_FREE(br_lck);
6254
6481
                                return status;
6255
6482
                        }
6281
6508
                return NT_STATUS_INVALID_PARAMETER;
6282
6509
        }
6283
6510
 
 
6511
        if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
 
6512
                return NT_STATUS_ACCESS_DENIED;
 
6513
        }
 
6514
 
6284
6515
        /* Set the attributes */
6285
6516
        dosmode = IVAL(pdata,32);
6286
6517
        status = smb_set_file_dosmode(conn, smb_fname, dosmode);
6325
6556
                return NT_STATUS_INVALID_PARAMETER;
6326
6557
        }
6327
6558
 
 
6559
        if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
 
6560
                return NT_STATUS_ACCESS_DENIED;
 
6561
        }
 
6562
 
6328
6563
        /* create time */
6329
6564
        ft.create_time = convert_time_t_to_timespec(srv_make_unix_date2(pdata));
6330
6565
        /* access time */
6383
6618
                allocation_size = smb_roundup(conn, allocation_size);
6384
6619
        }
6385
6620
 
 
6621
        if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
 
6622
                return NT_STATUS_ACCESS_DENIED;
 
6623
        }
 
6624
 
6386
6625
        DEBUG(10,("smb_set_file_allocation_info: file %s : setting new "
6387
6626
                  "allocation size to %.0f\n", smb_fname_str_dbg(smb_fname),
6388
6627
                  (double)allocation_size));
6418
6657
                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
6419
6658
                FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
6420
6659
                0,                                      /* allocation_size */
 
6660
                0,                                      /* private_flags */
6421
6661
                NULL,                                   /* sd */
6422
6662
                NULL,                                   /* ea_list */
6423
6663
                &new_fsp,                               /* result */
6479
6719
                  "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
6480
6720
                  (double)size));
6481
6721
 
 
6722
        if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
 
6723
                return NT_STATUS_ACCESS_DENIED;
 
6724
        }
 
6725
 
6482
6726
        return smb_set_file_size(conn, req,
6483
6727
                                fsp,
6484
6728
                                smb_fname,
6783
7027
        }
6784
7028
 
6785
7029
        id = vfs_file_id_from_sbuf(conn, &sbuf);
6786
 
        for(all_fsps = file_find_di_first(id); all_fsps;
 
7030
        for(all_fsps = file_find_di_first(conn->sconn, id); all_fsps;
6787
7031
                        all_fsps = file_find_di_next(all_fsps)) {
6788
7032
                /*
6789
7033
                 * We're setting the time explicitly for UNIX.
6927
7171
                mod_unixmode,                           /* file_attributes */
6928
7172
                0,                                      /* oplock_request */
6929
7173
                0,                                      /* allocation_size */
 
7174
                0,                                      /* private_flags */
6930
7175
                NULL,                                   /* sd */
6931
7176
                NULL,                                   /* ea_list */
6932
7177
                &fsp,                                   /* result */
6984
7229
 Open/Create a file with POSIX semantics.
6985
7230
****************************************************************************/
6986
7231
 
 
7232
#define SMB_O_RDONLY_MAPPING (FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA)
 
7233
#define SMB_O_WRONLY_MAPPING (FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA)
 
7234
 
6987
7235
static NTSTATUS smb_posix_open(connection_struct *conn,
6988
7236
                               struct smb_request *req,
6989
7237
                                char **ppdata,
6999
7247
        uint32 mod_unixmode = 0;
7000
7248
        uint32 create_disp = 0;
7001
7249
        uint32 access_mask = 0;
7002
 
        uint32 create_options = 0;
 
7250
        uint32 create_options = FILE_NON_DIRECTORY_FILE;
7003
7251
        NTSTATUS status = NT_STATUS_OK;
7004
7252
        mode_t unixmode = (mode_t)0;
7005
7253
        files_struct *fsp = NULL;
7029
7277
 
7030
7278
        switch (wire_open_mode & SMB_ACCMODE) {
7031
7279
                case SMB_O_RDONLY:
7032
 
                        access_mask = FILE_READ_DATA;
 
7280
                        access_mask = SMB_O_RDONLY_MAPPING;
7033
7281
                        break;
7034
7282
                case SMB_O_WRONLY:
7035
 
                        access_mask = FILE_WRITE_DATA;
 
7283
                        access_mask = SMB_O_WRONLY_MAPPING;
7036
7284
                        break;
7037
7285
                case SMB_O_RDWR:
7038
 
                        access_mask = FILE_READ_DATA|FILE_WRITE_DATA;
 
7286
                        access_mask = (SMB_O_RDONLY_MAPPING|
 
7287
                                        SMB_O_WRONLY_MAPPING);
7039
7288
                        break;
7040
7289
                default:
7041
7290
                        DEBUG(5,("smb_posix_open: invalid open mode 0x%x\n",
7120
7369
                mod_unixmode |= FILE_FLAG_NO_BUFFERING;
7121
7370
        }
7122
7371
 
 
7372
        if ((wire_open_mode & SMB_O_DIRECTORY) ||
 
7373
                        VALID_STAT_OF_DIR(smb_fname->st)) {
 
7374
                if (access_mask != SMB_O_RDONLY_MAPPING) {
 
7375
                        return NT_STATUS_FILE_IS_A_DIRECTORY;
 
7376
                }
 
7377
                create_options &= ~FILE_NON_DIRECTORY_FILE;
 
7378
                create_options |= FILE_DIRECTORY_FILE;
 
7379
        }
 
7380
 
7123
7381
        DEBUG(10,("smb_posix_open: file %s, smb_posix_flags = %u, mode 0%o\n",
7124
7382
                smb_fname_str_dbg(smb_fname),
7125
7383
                (unsigned int)wire_open_mode,
7134
7392
                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
7135
7393
                    FILE_SHARE_DELETE),
7136
7394
                create_disp,                            /* create_disposition*/
7137
 
                FILE_NON_DIRECTORY_FILE,                /* create_options */
 
7395
                create_options,                         /* create_options */
7138
7396
                mod_unixmode,                           /* file_attributes */
7139
7397
                oplock_request,                         /* oplock_request */
7140
7398
                0,                                      /* allocation_size */
 
7399
                0,                                      /* private_flags */
7141
7400
                NULL,                                   /* sd */
7142
7401
                NULL,                                   /* ea_list */
7143
7402
                &fsp,                                   /* result */
7267
7526
                FILE_FLAG_POSIX_SEMANTICS|0777,         /* file_attributes */
7268
7527
                0,                                      /* oplock_request */
7269
7528
                0,                                      /* allocation_size */
 
7529
                0,                                      /* private_flags */
7270
7530
                NULL,                                   /* sd */
7271
7531
                NULL,                                   /* ea_list */
7272
7532
                &fsp,                                   /* result */
7530
7790
                        break;
7531
7791
                }
7532
7792
 
 
7793
                case SMB2_FILE_RENAME_INFORMATION_INTERNAL:
 
7794
                {
 
7795
                        /* SMB2 rename information. */
 
7796
                        status = smb2_file_rename_information(conn, req,
 
7797
                                                             pdata, total_data,
 
7798
                                                             fsp, smb_fname);
 
7799
                        break;
 
7800
                }
 
7801
 
 
7802
                case SMB_FILE_LINK_INFORMATION:
 
7803
                {
 
7804
                        status = smb_file_link_information(conn, req,
 
7805
                                                        pdata, total_data,
 
7806
                                                        fsp, smb_fname);
 
7807
                        break;
 
7808
                }
 
7809
 
7533
7810
#if defined(HAVE_POSIX_ACLS)
7534
7811
                case SMB_SET_POSIX_ACL:
7535
7812
                {
7637
7914
                        return;
7638
7915
                }
7639
7916
 
7640
 
                if(fsp->is_directory || fsp->fh->fd == -1) {
 
7917
                if(fsp->fh->fd == -1) {
7641
7918
                        /*
7642
7919
                         * This is actually a SETFILEINFO on a directory
7643
7920
                         * handle (returned from an NT SMB). NT5.0 seems
7669
7946
                         * Doing a DELETE_ON_CLOSE should cancel a print job.
7670
7947
                         */
7671
7948
                        if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
7672
 
                                fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
 
7949
                                fsp->fh->private_options |= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE;
7673
7950
 
7674
7951
                                DEBUG(3,("call_trans2setfilepathinfo: "
7675
7952
                                         "Cancelling print job (%s)\n",
7689
7966
                        /*
7690
7967
                         * Original code - this is an open file.
7691
7968
                         */
7692
 
                        if (!check_fsp(conn, req, fsp)) {
7693
 
                                return;
7694
 
                        }
7695
 
 
7696
7969
                        if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
7697
7970
                                DEBUG(3,("call_trans2setfilepathinfo: fstat "
7698
7971
                                         "of fnum %d failed (%s)\n", fsp->fnum,
7780
8053
                        /* We have re-scheduled this call. */
7781
8054
                        return;
7782
8055
                }
7783
 
                if (blocking_lock_was_deferred(req->mid)) {
 
8056
                if (blocking_lock_was_deferred_smb1(req->sconn, req->mid)) {
7784
8057
                        /* We have re-scheduled this call. */
7785
8058
                        return;
7786
8059
                }
8099
8372
                /* NOTE - THIS IS ASCII ONLY AT THE MOMENT - NOT SURE IF OS/2
8100
8373
                        CAN ACCEPT THIS IN UNICODE. JRA. */
8101
8374
 
8102
 
                SSVAL(pdata,0,fsp->rap_print_jobid);                     /* Job number */
 
8375
                /* Job number */
 
8376
                if (fsp->print_file) {
 
8377
                        SSVAL(pdata, 0, fsp->print_file->rap_jobid);
 
8378
                } else {
 
8379
                        SSVAL(pdata, 0, 0);
 
8380
                }
8103
8381
                srvstr_push(pdata, req->flags2, pdata + 2,
8104
8382
                            global_myname(), 15,
8105
8383
                            STR_ASCII|STR_TERMINATE); /* Our NetBIOS name */
8122
8400
void reply_findclose(struct smb_request *req)
8123
8401
{
8124
8402
        int dptr_num;
8125
 
        struct smbd_server_connection *sconn = smbd_server_conn;
 
8403
        struct smbd_server_connection *sconn = req->sconn;
8126
8404
 
8127
8405
        START_PROFILE(SMBfindclose);
8128
8406