Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/trans2.c

    r597 r740  
    2525
    2626#include "includes.h"
     27#include "system/filesys.h"
    2728#include "version.h"
     29#include "smbd/smbd.h"
    2830#include "smbd/globals.h"
    2931#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"
    3040
    3141#define DIR_ENTRY_SAFETY_MARGIN 4096
     
    500510        if (!lp_ea_support(SNUM(conn))) {
    501511                return NT_STATUS_EAS_NOT_SUPPORTED;
     512        }
     513
     514        if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
     515                return NT_STATUS_ACCESS_DENIED;
    502516        }
    503517
     
    779793        int data_alignment_offset = 0;
    780794        bool overflow = False;
    781         struct smbd_server_connection *sconn = smbd_server_conn;
     795        struct smbd_server_connection *sconn = req->sconn;
    782796        int max_send = sconn->smb1.sessions.max_send;
    783797
     
    799813                reply_outbuf(req, 10, 0);
    800814                show_msg((char *)req->outbuf);
    801                 if (!srv_send_smb(smbd_server_fd(),
     815                if (!srv_send_smb(sconn,
    802816                                (char *)req->outbuf,
    803817                                true, req->seqnum+1,
     
    938952                /* Send the packet */
    939953                show_msg((char *)req->outbuf);
    940                 if (!srv_send_smb(smbd_server_fd(),
     954                if (!srv_send_smb(sconn,
    941955                                (char *)req->outbuf,
    942956                                true, req->seqnum+1,
     
    10011015        uint32 create_disposition;
    10021016        uint32 create_options = 0;
     1017        uint32_t private_flags = 0;
    10031018        TALLOC_CTX *ctx = talloc_tos();
    10041019
     
    10721087                                         &access_mask, &share_mode,
    10731088                                         &create_disposition,
    1074                                          &create_options)) {
     1089                                         &create_options,
     1090                                         &private_flags)) {
    10751091                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    10761092                goto out;
     
    11161132                oplock_request,                         /* oplock_request */
    11171133                open_size,                              /* allocation_size */
     1134                private_flags,
    11181135                NULL,                                   /* sd */
    11191136                ea_list,                                /* ea_list */
     
    11341151        mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
    11351152        inode = smb_fname->st.st_ex_ino;
    1136         if (fattr & aDIR) {
     1153        if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
    11371154                close_file(req, fsp, ERROR_CLOSE);
    11381155                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
     
    14791496                                    const char *fname,
    14801497                                    const struct smb_filename *smb_fname,
    1481                                     uint64_t space_remaining,
     1498                                    int space_remaining,
    14821499                                    uint8_t align,
    14831500                                    bool do_pad,
     
    15001517        char *last_entry_ptr;
    15011518        bool was_8_3;
    1502         off_t off;
    1503         off_t pad = 0;
     1519        int off;
     1520        int pad = 0;
    15041521
    15051522        *out_of_space = false;
     
    15101527        ZERO_STRUCT(cdate_ts);
    15111528
    1512         if (!(mode & aDIR)) {
     1529        if (!(mode & FILE_ATTRIBUTE_DIRECTORY)) {
    15131530                file_size = get_file_size_stat(&smb_fname->st);
    15141531        }
     
    15351552
    15361553        /* align the record */
    1537         off = PTR_DIFF(pdata, base_data);
     1554        SMB_ASSERT(align >= 1);
     1555
     1556        off = (int)PTR_DIFF(pdata, base_data);
    15381557        pad = (off + (align-1)) & ~(align-1);
    15391558        pad -= off;
     1559
     1560        if (pad && pad > space_remaining) {
     1561                *out_of_space = true;
     1562                DEBUG(9,("smbd_marshall_dir_entry: out of space "
     1563                        "for padding (wanted %u, had %d)\n",
     1564                        (unsigned int)pad,
     1565                        space_remaining ));
     1566                return false; /* Not finished - just out of space */
     1567        }
     1568
    15401569        off += pad;
    15411570        /* initialize padding to 0 */
     
    15441573        }
    15451574        space_remaining -= pad;
     1575
     1576        DEBUG(10,("smbd_marshall_dir_entry: space_remaining = %d\n",
     1577                space_remaining ));
    15461578
    15471579        pdata += pad;
     
    16591691                if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
    16601692                        *out_of_space = true;
    1661                         DEBUG(9,("smbd_marshall_dir_entry: out of space\n"));
     1693                        DEBUG(9,("smbd_marshall_dir_entry: out of space "
     1694                                "(wanted %u, had %d)\n",
     1695                                (unsigned int)PTR_DIFF(p + 255 + ea_len,pdata),
     1696                                space_remaining ));
    16621697                        return False; /* Not finished - just out of space */
    16631698                }
     
    20372072        if (PTR_DIFF(p,pdata) > space_remaining) {
    20382073                *out_of_space = true;
    2039                 DEBUG(9,("smbd_marshall_dir_entry: out of space\n"));
     2074                DEBUG(9,("smbd_marshall_dir_entry: out of space "
     2075                        "(wanted %u, had %d)\n",
     2076                        (unsigned int)PTR_DIFF(p,pdata),
     2077                        space_remaining ));
    20402078                return false; /* Not finished - just out of space */
    20412079        }
     
    22322270        TALLOC_CTX *ctx = talloc_tos();
    22332271        struct dptr_struct *dirptr = NULL;
    2234         struct smbd_server_connection *sconn = smbd_server_conn;
     2272        struct smbd_server_connection *sconn = req->sconn;
    22352273
    22362274        if (total_params < 13) {
     
    23222360                        mask_contains_wcard = True;
    23232361                }
    2324                 directory = talloc_strdup(talloc_tos(), "./");
     2362        } else {
     2363                *p = 0;
     2364        }
     2365
     2366        if (p == NULL || p == directory) {
     2367                /* Ensure we don't have a directory name of "". */
     2368                directory = talloc_strdup(talloc_tos(), ".");
    23252369                if (!directory) {
    23262370                        reply_nterror(req, NT_STATUS_NO_MEMORY);
    23272371                        goto out;
    23282372                }
    2329         } else {
    2330                 *p = 0;
    23312373        }
    23322374
     
    23832425
    23842426        ntstatus = dptr_create(conn,
     2427                                NULL, /* fsp */
    23852428                                directory,
    23862429                                False,
     
    25712614        TALLOC_CTX *ctx = talloc_tos();
    25722615        struct dptr_struct *dirptr;
    2573         struct smbd_server_connection *sconn = smbd_server_conn;
     2616        struct smbd_server_connection *sconn = req->sconn;
    25742617
    25752618        if (total_params < 13) {
     
    28662909#endif
    28672910        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);
     2911#ifdef SAMBA_VERSION_COMMIT_TIME
     2912        unix_to_nt_time(&extended_info->samba_gitcommitdate, SAMBA_VERSION_COMMIT_TIME);
    28702913#endif
    28712914
     
    31173160                case SMB_QUERY_FS_DEVICE_INFO:
    31183161                case SMB_FS_DEVICE_INFORMATION:
     3162                {
     3163                        uint32_t characteristics = FILE_DEVICE_IS_MOUNTED;
     3164
     3165                        if (!CAN_WRITE(conn)) {
     3166                                characteristics |= FILE_READ_ONLY_DEVICE;
     3167                        }
    31193168                        data_len = 8;
    3120                         SIVAL(pdata,0,0); /* dev type */
    3121                         SIVAL(pdata,4,0); /* characteristics */
    3122                         break;
     3169                        SIVAL(pdata,0,FILE_DEVICE_DISK); /* dev type */
     3170                        SIVAL(pdata,4,characteristics);
     3171                        break;
     3172                }
    31233173
    31243174#ifdef HAVE_SYS_QUOTAS
     
    31573207
    31583208                        /* access check */
    3159                         if (conn->server_info->utok.uid != sec_initial_uid() &&
    3160                                         !conn->admin_user) {
     3209                        if (get_current_uid(conn) != 0) {
    31613210                                DEBUG(0,("set_user_quota: access_denied "
    31623211                                         "service [%s] user [%s]\n",
    31633212                                         lp_servicename(SNUM(conn)),
    3164                                          conn->server_info->unix_name));
     3213                                         conn->session_info->unix_name));
    31653214                                return NT_STATUS_ACCESS_DENIED;
    31663215                        }
     
    32203269                {
    32213270                        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);
     3271                                        !srv_is_signing_active(conn->sconn);
     3272                        bool large_read = !srv_is_signing_active(conn->sconn);
    32243273                        int encrypt_caps = 0;
    32253274
     
    33153364                         */
    33163365                        if (nt_token_check_sid(&global_sid_Builtin_Guests,
    3317                                                conn->server_info->ptok)) {
     3366                                               conn->session_info->security_token)) {
    33183367                                flags |= SMB_WHOAMI_GUEST;
    33193368                        }
     
    33233372                         */
    33243373                        if (nt_token_check_sid(&global_sid_Authenticated_Users,
    3325                                                conn->server_info->ptok)) {
     3374                                               conn->session_info->security_token)) {
    33263375                                flags &= ~SMB_WHOAMI_GUEST;
    33273376                        }
     
    33393388                            + 4 /* SID bytes */
    33403389                            + 4 /* pad/reserved */
    3341                             + (conn->server_info->utok.ngroups * 8)
     3390                            + (conn->session_info->utok.ngroups * 8)
    33423391                                /* groups list */
    3343                             + (conn->server_info->ptok->num_sids *
     3392                            + (conn->session_info->security_token->num_sids *
    33443393                                    SID_MAX_SIZE)
    33453394                                /* SID list */;
     
    33483397                        SIVAL(pdata, 4, SMB_WHOAMI_MASK);
    33493398                        SBIG_UINT(pdata, 8,
    3350                                   (uint64_t)conn->server_info->utok.uid);
     3399                                  (uint64_t)conn->session_info->utok.uid);
    33513400                        SBIG_UINT(pdata, 16,
    3352                                   (uint64_t)conn->server_info->utok.gid);
     3401                                  (uint64_t)conn->session_info->utok.gid);
    33533402
    33543403
     
    33653414                        }
    33663415
    3367                         SIVAL(pdata, 24, conn->server_info->utok.ngroups);
    3368                         SIVAL(pdata, 28, conn->server_info->num_sids);
     3416                        SIVAL(pdata, 24, conn->session_info->utok.ngroups);
     3417                        SIVAL(pdata, 28, conn->session_info->security_token->num_sids);
    33693418
    33703419                        /* We walk the SID list twice, but this call is fairly
     
    33733422                         */
    33743423                        for (i = 0, sid_bytes = 0;
    3375                              i < conn->server_info->ptok->num_sids; ++i) {
     3424                             i < conn->session_info->security_token->num_sids; ++i) {
    33763425                                sid_bytes += ndr_size_dom_sid(
    3377                                         &conn->server_info->ptok->user_sids[i],
    3378                                         NULL,
     3426                                        &conn->session_info->security_token->sids[i],
    33793427                                        0);
    33803428                        }
     
    33883436
    33893437                        /* GID list */
    3390                         for (i = 0; i < conn->server_info->utok.ngroups; ++i) {
     3438                        for (i = 0; i < conn->session_info->utok.ngroups; ++i) {
    33913439                                SBIG_UINT(pdata, data_len,
    3392                                           (uint64_t)conn->server_info->utok.groups[i]);
     3440                                          (uint64_t)conn->session_info->utok.groups[i]);
    33933441                                data_len += 8;
    33943442                        }
     
    33963444                        /* SID list */
    33973445                        for (i = 0;
    3398                             i < conn->server_info->ptok->num_sids; ++i) {
     3446                            i < conn->session_info->security_token->num_sids; ++i) {
    33993447                                int sid_len = ndr_size_dom_sid(
    3400                                         &conn->server_info->ptok->user_sids[i],
    3401                                         NULL,
     3448                                        &conn->session_info->security_token->sids[i],
    34023449                                        0);
    34033450
    34043451                                sid_linearize(pdata + data_len, sid_len,
    3405                                     &conn->server_info->ptok->user_sids[i]);
     3452                                    &conn->session_info->security_token->sids[i]);
    34063453                                data_len += sid_len;
    34073454                        }
     
    36023649                                }
    36033650
     3651                                if (req->sconn->smb1.echo_handler.trusted_fde) {
     3652                                        DEBUG( 2,("call_trans2setfsinfo: "
     3653                                                "request transport encryption disabled"
     3654                                                "with 'fork echo handler = yes'\n"));
     3655                                        reply_nterror(
     3656                                                req,
     3657                                                NT_STATUS_NOT_SUPPORTED);
     3658                                        return;
     3659                                }
     3660
    36043661                                DEBUG( 4,("call_trans2setfsinfo: "
    36053662                                        "request transport encryption.\n"));
     
    36453702
    36463703                                /* access check */
    3647                                 if (((conn->server_info->utok.uid != sec_initial_uid()) && !conn->admin_user)
    3648                                     ||!CAN_WRITE(conn)) {
     3704                                if ((get_current_uid(conn) != 0) || !CAN_WRITE(conn)) {
    36493705                                        DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
    36503706                                                 lp_servicename(SNUM(conn)),
    3651                                                  conn->server_info->unix_name));
     3707                                                 conn->session_info->unix_name));
    36523708                                        reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    36533709                                        return;
     
    36803736
    36813737                                /* 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 */
     3738                                quotas.softlim = BVAL(pdata,24);
    36963739
    36973740                                /* 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 */
     3741                                quotas.hardlim = BVAL(pdata,32);
    37123742
    37133743                                /* quota_flags 2 bytes **/
     
    41634193                               bool delete_pending,
    41644194                               struct timespec write_time_ts,
    4165                                bool ms_dfs_link,
    41664195                               struct ea_list *ea_list,
    41674196                               int lock_data_count,
     
    41984227                 info_level, max_data_bytes));
    41994228
    4200         if (ms_dfs_link) {
    4201                 mode = dos_mode_msdfs(conn, smb_fname);
    4202         } else {
    4203                 mode = dos_mode(conn, smb_fname);
    4204         }
    4205 
     4229        mode = dos_mode(conn, smb_fname);
    42064230        nlink = psbuf->st_ex_nlink;
    42074231
    4208         if (nlink && (mode&aDIR)) {
     4232        if (nlink && (mode&FILE_ATTRIBUTE_DIRECTORY)) {
    42094233                nlink = 1;
    42104234        }
     
    42814305                files_struct *fsp1;
    42824306                struct file_id fileid = vfs_file_id_from_sbuf(conn, psbuf);
    4283                 fsp1 = file_find_di_first(fileid);
     4307                fsp1 = file_find_di_first(conn->sconn, fileid);
    42844308                if (fsp1 && fsp1->initial_allocation_size) {
    42854309                        allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp1, psbuf);
     
    42874311        }
    42884312
    4289         if (!(mode & aDIR)) {
     4313        if (!(mode & FILE_ATTRIBUTE_DIRECTORY)) {
    42904314                file_size = get_file_size_stat(psbuf);
    42914315        }
     
    44574481                        SIVAL(pdata,16,nlink);
    44584482                        SCVAL(pdata,20,delete_pending?1:0);
    4459                         SCVAL(pdata,21,(mode&aDIR)?1:0);
     4483                        SCVAL(pdata,21,(mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
    44604484                        SSVAL(pdata,22,0); /* Padding. */
    44614485                        break;
     
    45404564                        SIVAL(pdata,16,nlink);
    45414565                        SCVAL(pdata,20,delete_pending);
    4542                         SCVAL(pdata,21,(mode&aDIR)?1:0);
     4566                        SCVAL(pdata,21,(mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
    45434567                        SSVAL(pdata,22,0);
    45444568                        pdata += 24;
     
    45714595                        SIVAL(pdata,    0x38, nlink);
    45724596                        SCVAL(pdata,    0x3C, delete_pending);
    4573                         SCVAL(pdata,    0x3D, (mode&aDIR)?1:0);
     4597                        SCVAL(pdata,    0x3D, (mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
    45744598                        SSVAL(pdata,    0x3E, 0); /* padding */
    45754599                        SBVAL(pdata,    0x40, file_index);
     
    47214745                        data_size = PTR_DIFF(pdata,(*ppdata));
    47224746
    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                         }
     4747                        DEBUG(4,("smbd_do_qfilepathinfo: "
     4748                                 "SMB_QUERY_FILE_UNIX_BASIC\n"));
     4749                        dump_data(4, (uint8_t *)(*ppdata), data_size);
    47314750
    47324751                        break;
     
    47904809                                uint16 num_def_acls = 0;
    47914810
    4792                                 if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
     4811                                if (fsp && fsp->fh->fd != -1) {
    47934812                                        file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp);
    47944813                                } else {
     
    48794898                        uint64_t count;
    48804899                        uint64_t offset;
    4881                         uint32 lock_pid;
     4900                        uint64_t smblctx;
    48824901                        enum brl_type lock_type;
    48834902
    48844903                        /* We need an open file with a real fd for this. */
    4885                         if (!fsp || fsp->is_directory || fsp->fh->fd == -1) {
     4904                        if (!fsp || fsp->fh->fd == -1) {
    48864905                                return NT_STATUS_INVALID_LEVEL;
    48874906                        }
     
    49044923                        }
    49054924
    4906                         lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
     4925                        smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET);
    49074926#if defined(HAVE_LONGLONG)
    49084927                        offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
     
    49164935
    49174936                        status = query_lock(fsp,
    4918                                         &lock_pid,
     4937                                        &smblctx,
    49194938                                        &count,
    49204939                                        &offset,
     
    49284947                                SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, lock_type);
    49294948                                SSVAL(pdata, POSIX_LOCK_FLAGS_OFFSET, 0);
    4930                                 SIVAL(pdata, POSIX_LOCK_PID_OFFSET, lock_pid);
     4949                                SIVAL(pdata, POSIX_LOCK_PID_OFFSET, (uint32_t)smblctx);
    49314950#if defined(HAVE_LONGLONG)
    49324951                                SIVAL(pdata, POSIX_LOCK_START_OFFSET, (uint32)(offset & 0xFFFFFFFF));
     
    49845003        int lock_data_count = 0;
    49855004        char *lock_data = NULL;
    4986         bool ms_dfs_link = false;
    49875005        NTSTATUS status = NT_STATUS_OK;
    49885006
     
    50375055                        /* We know this name is ok, it's already passed the checks. */
    50385056
    5039                 } else if(fsp->is_directory || fsp->fh->fd == -1) {
     5057                } else if(fsp->fh->fd == -1) {
    50405058                        /*
    50415059                         * This is actually a QFILEINFO on a directory
     
    50675085
    50685086                        fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
    5069                         get_file_infos(fileid, &delete_pending, &write_time_ts);
     5087                        get_file_infos(fileid, fsp->name_hash, &delete_pending, &write_time_ts);
    50705088                } else {
    50715089                        /*
    50725090                         * Original code - this is an open file.
    50735091                         */
    5074                         if (!check_fsp(conn, req, fsp)) {
    5075                                 return;
    5076                         }
    5077 
    50785092                        if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
    50795093                                DEBUG(3, ("fstat of fnum %d failed (%s)\n",
     
    50845098                        }
    50855099                        fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
    5086                         get_file_infos(fileid, &delete_pending, &write_time_ts);
     5100                        get_file_infos(fileid, fsp->name_hash, &delete_pending, &write_time_ts);
    50875101                }
    50885102
    50895103        } else {
     5104                uint32_t name_hash;
    50905105                char *fname = NULL;
    50915106
     
    51745189                        }
    51755190
     5191                        status = file_name_hash(conn,
     5192                                        smb_fname_str_dbg(smb_fname_base),
     5193                                        &name_hash);
     5194                        if (!NT_STATUS_IS_OK(status)) {
     5195                                TALLOC_FREE(smb_fname_base);
     5196                                reply_nterror(req, status);
     5197                                return;
     5198                        }
     5199
    51765200                        fileid = vfs_file_id_from_sbuf(conn,
    51775201                                                       &smb_fname_base->st);
    51785202                        TALLOC_FREE(smb_fname_base);
    5179                         get_file_infos(fileid, &delete_pending, NULL);
     5203                        get_file_infos(fileid, name_hash, &delete_pending, NULL);
    51805204                        if (delete_pending) {
    51815205                                reply_nterror(req, NT_STATUS_DELETE_PENDING);
     
    51965220                        }
    51975221
    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) {
     5222                } else {
     5223                        if (SMB_VFS_STAT(conn, smb_fname) != 0) {
    52065224                                DEBUG(3,("call_trans2qfilepathinfo: "
    52075225                                         "SMB_VFS_STAT of %s failed (%s)\n",
     
    52145232                }
    52155233
     5234                status = file_name_hash(conn,
     5235                                smb_fname_str_dbg(smb_fname),
     5236                                &name_hash);
     5237                if (!NT_STATUS_IS_OK(status)) {
     5238                        reply_nterror(req, status);
     5239                        return;
     5240                }
     5241
    52165242                fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
    5217                 get_file_infos(fileid, &delete_pending, &write_time_ts);
     5243                get_file_infos(fileid, name_hash, &delete_pending, &write_time_ts);
    52185244                if (delete_pending) {
    52195245                        reply_nterror(req, NT_STATUS_DELETE_PENDING);
     
    53275353                                       fsp, smb_fname,
    53285354                                       delete_pending, write_time_ts,
    5329                                        ms_dfs_link, ea_list,
     5355                                       ea_list,
    53305356                                       lock_data_count, lock_data,
    53315357                                       req->flags2, max_data_bytes,
     
    53495375NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
    53505376                connection_struct *conn,
     5377                struct smb_request *req,
     5378                bool overwrite_if_exists,
    53515379                const struct smb_filename *smb_fname_old,
    5352                 const struct smb_filename *smb_fname_new)
     5380                struct smb_filename *smb_fname_new)
    53535381{
    53545382        NTSTATUS status = NT_STATUS_OK;
     
    53595387        }
    53605388
    5361         /* Disallow if newname already exists. */
    53625389        if (VALID_STAT(smb_fname_new->st)) {
    5363                 return NT_STATUS_OBJECT_NAME_COLLISION;
     5390                if (overwrite_if_exists) {
     5391                        if (S_ISDIR(smb_fname_new->st.st_ex_mode)) {
     5392                                return NT_STATUS_FILE_IS_A_DIRECTORY;
     5393                        }
     5394                        status = unlink_internals(conn,
     5395                                                req,
     5396                                                FILE_ATTRIBUTE_NORMAL,
     5397                                                smb_fname_new,
     5398                                                false);
     5399                        if (!NT_STATUS_IS_OK(status)) {
     5400                                return status;
     5401                        }
     5402                } else {
     5403                        /* Disallow if newname already exists. */
     5404                        return NT_STATUS_OBJECT_NAME_COLLISION;
     5405                }
    53645406        }
    53655407
     
    54085450        }
    54095451
     5452        if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
     5453                return NT_STATUS_ACCESS_DENIED;
     5454        }
     5455
    54105456        /* get some defaults (no modifications) if any info is zero or -1. */
    54115457        if (null_timespec(ft->create_time)) {
     
    55115557        if (dosmode) {
    55125558                if (S_ISDIR(smb_fname_base->st.st_ex_mode)) {
    5513                         dosmode |= aDIR;
     5559                        dosmode |= FILE_ATTRIBUTE_DIRECTORY;
    55145560                } else {
    5515                         dosmode &= ~aDIR;
     5561                        dosmode &= ~FILE_ATTRIBUTE_DIRECTORY;
    55165562                }
    55175563        }
     
    55615607        }
    55625608
     5609        if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
     5610                return NT_STATUS_ACCESS_DENIED;
     5611        }
     5612
    55635613        DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size));
    55645614
     
    55915641                0,                                      /* root_dir_fid */
    55925642                smb_fname_tmp,                          /* fname */
    5593                 FILE_WRITE_ATTRIBUTES,                  /* access_mask */
     5643                FILE_WRITE_DATA,                        /* access_mask */
    55945644                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
    55955645                    FILE_SHARE_DELETE),
     
    55995649                FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
    56005650                0,                                      /* allocation_size */
     5651                0,                                      /* private_flags */
    56015652                NULL,                                   /* sd */
    56025653                NULL,                                   /* ea_list */
     
    56665717                return NT_STATUS_INVALID_PARAMETER;
    56675718        }
     5719
     5720        if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
     5721                return NT_STATUS_ACCESS_DENIED;
     5722        }
     5723
    56685724        status = set_ea(conn, fsp, smb_fname, ea_list);
    56695725
     
    57085764                return NT_STATUS_INVALID_PARAMETER;
    57095765        }
     5766
     5767        if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
     5768                return NT_STATUS_ACCESS_DENIED;
     5769        }
     5770
    57105771        status = set_ea(conn, fsp, fsp->fsp_name, ea_list);
    57115772
     
    57585819        /* The set is across all open files on this dev/inode pair. */
    57595820        if (!set_delete_on_close(fsp, delete_on_close,
    5760                                  &conn->server_info->utok)) {
     5821                                 &conn->session_info->utok)) {
    57615822                return NT_STATUS_ACCESS_DENIED;
    57625823        }
     
    58705931                                        struct smb_request *req,
    58715932                                        const char *pdata, int total_data,
    5872                                         const struct smb_filename *smb_fname_new)
     5933                                        struct smb_filename *smb_fname_new)
    58735934{
    58745935        char *oldname = NULL;
     
    59025963        }
    59035964
    5904         return hardlink_internals(ctx, conn, smb_fname_old, smb_fname_new);
     5965        return hardlink_internals(ctx, conn, req, false,
     5966                        smb_fname_old, smb_fname_new);
     5967}
     5968
     5969/****************************************************************************
     5970 Deal with SMB2_FILE_RENAME_INFORMATION_INTERNAL
     5971****************************************************************************/
     5972
     5973static NTSTATUS smb2_file_rename_information(connection_struct *conn,
     5974                                            struct smb_request *req,
     5975                                            const char *pdata,
     5976                                            int total_data,
     5977                                            files_struct *fsp,
     5978                                            struct smb_filename *smb_fname_src)
     5979{
     5980        bool overwrite;
     5981        uint32_t len;
     5982        char *newname = NULL;
     5983        struct smb_filename *smb_fname_dst = NULL;
     5984        NTSTATUS status = NT_STATUS_OK;
     5985        TALLOC_CTX *ctx = talloc_tos();
     5986
     5987        if (!fsp) {
     5988                return NT_STATUS_INVALID_HANDLE;
     5989        }
     5990
     5991        if (total_data < 20) {
     5992                return NT_STATUS_INVALID_PARAMETER;
     5993        }
     5994
     5995        overwrite = (CVAL(pdata,0) ? True : False);
     5996        len = IVAL(pdata,16);
     5997
     5998        if (len > (total_data - 20) || (len == 0)) {
     5999                return NT_STATUS_INVALID_PARAMETER;
     6000        }
     6001
     6002        srvstr_get_path(ctx, pdata, req->flags2, &newname,
     6003                                &pdata[20], len, STR_TERMINATE,
     6004                                &status);
     6005        if (!NT_STATUS_IS_OK(status)) {
     6006                return status;
     6007        }
     6008
     6009        DEBUG(10,("smb2_file_rename_information: got name |%s|\n",
     6010                                newname));
     6011
     6012        status = filename_convert(ctx,
     6013                                conn,
     6014                                req->flags2 & FLAGS2_DFS_PATHNAMES,
     6015                                newname,
     6016                                UCF_SAVE_LCOMP,
     6017                                NULL,
     6018                                &smb_fname_dst);
     6019        if (!NT_STATUS_IS_OK(status)) {
     6020                return status;
     6021        }
     6022
     6023        if (fsp->base_fsp) {
     6024                /* newname must be a stream name. */
     6025                if (newname[0] != ':') {
     6026                        return NT_STATUS_NOT_SUPPORTED;
     6027                }
     6028
     6029                /* Create an smb_fname to call rename_internals_fsp() with. */
     6030                status = create_synthetic_smb_fname(talloc_tos(),
     6031                    fsp->base_fsp->fsp_name->base_name, newname, NULL,
     6032                    &smb_fname_dst);
     6033                if (!NT_STATUS_IS_OK(status)) {
     6034                        goto out;
     6035                }
     6036
     6037                /*
     6038                 * Set the original last component, since
     6039                 * rename_internals_fsp() requires it.
     6040                 */
     6041                smb_fname_dst->original_lcomp = talloc_strdup(smb_fname_dst,
     6042                                                              newname);
     6043                if (smb_fname_dst->original_lcomp == NULL) {
     6044                        status = NT_STATUS_NO_MEMORY;
     6045                        goto out;
     6046                }
     6047
     6048        }
     6049
     6050        DEBUG(10,("smb2_file_rename_information: "
     6051                  "SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
     6052                  fsp->fnum, fsp_str_dbg(fsp),
     6053                  smb_fname_str_dbg(smb_fname_dst)));
     6054        status = rename_internals_fsp(conn, fsp, smb_fname_dst,
     6055                                (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM),
     6056                                overwrite);
     6057
     6058 out:
     6059        TALLOC_FREE(smb_fname_dst);
     6060        return status;
     6061}
     6062
     6063static NTSTATUS smb_file_link_information(connection_struct *conn,
     6064                                            struct smb_request *req,
     6065                                            const char *pdata,
     6066                                            int total_data,
     6067                                            files_struct *fsp,
     6068                                            struct smb_filename *smb_fname_src)
     6069{
     6070        bool overwrite;
     6071        uint32_t len;
     6072        char *newname = NULL;
     6073        struct smb_filename *smb_fname_dst = NULL;
     6074        NTSTATUS status = NT_STATUS_OK;
     6075        TALLOC_CTX *ctx = talloc_tos();
     6076
     6077        if (!fsp) {
     6078                return NT_STATUS_INVALID_HANDLE;
     6079        }
     6080
     6081        if (total_data < 20) {
     6082                return NT_STATUS_INVALID_PARAMETER;
     6083        }
     6084
     6085        overwrite = (CVAL(pdata,0) ? true : false);
     6086        len = IVAL(pdata,16);
     6087
     6088        if (len > (total_data - 20) || (len == 0)) {
     6089                return NT_STATUS_INVALID_PARAMETER;
     6090        }
     6091
     6092        srvstr_get_path(ctx, pdata, req->flags2, &newname,
     6093                                &pdata[20], len, STR_TERMINATE,
     6094                                &status);
     6095        if (!NT_STATUS_IS_OK(status)) {
     6096                return status;
     6097        }
     6098
     6099        DEBUG(10,("smb_file_link_information: got name |%s|\n",
     6100                                newname));
     6101
     6102        status = filename_convert(ctx,
     6103                                conn,
     6104                                req->flags2 & FLAGS2_DFS_PATHNAMES,
     6105                                newname,
     6106                                UCF_SAVE_LCOMP,
     6107                                NULL,
     6108                                &smb_fname_dst);
     6109        if (!NT_STATUS_IS_OK(status)) {
     6110                return status;
     6111        }
     6112
     6113        if (fsp->base_fsp) {
     6114                /* No stream names. */
     6115                return NT_STATUS_NOT_SUPPORTED;
     6116        }
     6117
     6118        DEBUG(10,("smb_file_link_information: "
     6119                  "SMB_FILE_LINK_INFORMATION (fnum %d) %s -> %s\n",
     6120                  fsp->fnum, fsp_str_dbg(fsp),
     6121                  smb_fname_str_dbg(smb_fname_dst)));
     6122        status = hardlink_internals(ctx,
     6123                                conn,
     6124                                req,
     6125                                overwrite,
     6126                                fsp->fsp_name,
     6127                                smb_fname_dst);
     6128
     6129        TALLOC_FREE(smb_fname_dst);
     6130        return status;
    59056131}
    59066132
     
    60136239                        p[1] = '\0';
    60146240                } else {
    6015                         base_name = talloc_strdup(ctx, "./");
     6241                        base_name = talloc_strdup(ctx, "");
    60166242                        if (!base_name) {
    60176243                                return NT_STATUS_NO_MEMORY;
     
    61496375        uint64_t count;
    61506376        uint64_t offset;
    6151         uint32 lock_pid;
     6377        uint64_t smblctx;
    61526378        bool blocking_lock = False;
    61536379        enum brl_type lock_type;
     
    61936419        }
    61946420
    6195         lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
     6421        smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET);
    61966422#if defined(HAVE_LONGLONG)
    61976423        offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
     
    62056431
    62066432        DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u,"
    6207                         "lock_pid = %u, count = %.0f, offset = %.0f\n",
     6433                        "smblctx = %llu, count = %.0f, offset = %.0f\n",
    62086434                fsp_str_dbg(fsp),
    62096435                (unsigned int)lock_type,
    6210                 (unsigned int)lock_pid,
     6436                (unsigned long long)smblctx,
    62116437                (double)count,
    62126438                (double)offset ));
    62136439
    62146440        if (lock_type == UNLOCK_LOCK) {
    6215                 status = do_unlock(smbd_messaging_context(),
     6441                status = do_unlock(req->sconn->msg_ctx,
    62166442                                fsp,
    6217                                 lock_pid,
     6443                                smblctx,
    62186444                                count,
    62196445                                offset,
    62206446                                POSIX_LOCK);
    62216447        } else {
    6222                 uint32 block_smbpid;
    6223 
    6224                 struct byte_range_lock *br_lck = do_lock(smbd_messaging_context(),
     6448                uint64_t block_smblctx;
     6449
     6450                struct byte_range_lock *br_lck = do_lock(req->sconn->msg_ctx,
    62256451                                                        fsp,
    6226                                                         lock_pid,
     6452                                                        smblctx,
    62276453                                                        count,
    62286454                                                        offset,
     
    62316457                                                        blocking_lock,
    62326458                                                        &status,
    6233                                                         &block_smbpid,
     6459                                                        &block_smblctx,
    62346460                                                        NULL);
    62356461
     
    62456471                                                -1, /* infinite timeout. */
    62466472                                                0,
    6247                                                 lock_pid,
     6473                                                smblctx,
    62486474                                                lock_type,
    62496475                                                POSIX_LOCK,
    62506476                                                offset,
    62516477                                                count,
    6252                                                 block_smbpid)) {
     6478                                                block_smblctx)) {
    62536479                                TALLOC_FREE(br_lck);
    62546480                                return status;
     
    62826508        }
    62836509
     6510        if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
     6511                return NT_STATUS_ACCESS_DENIED;
     6512        }
     6513
    62846514        /* Set the attributes */
    62856515        dosmode = IVAL(pdata,32);
     
    63246554        if (total_data < 12) {
    63256555                return NT_STATUS_INVALID_PARAMETER;
     6556        }
     6557
     6558        if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
     6559                return NT_STATUS_ACCESS_DENIED;
    63266560        }
    63276561
     
    63826616        if (allocation_size) {
    63836617                allocation_size = smb_roundup(conn, allocation_size);
     6618        }
     6619
     6620        if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
     6621                return NT_STATUS_ACCESS_DENIED;
    63846622        }
    63856623
     
    64196657                FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
    64206658                0,                                      /* allocation_size */
     6659                0,                                      /* private_flags */
    64216660                NULL,                                   /* sd */
    64226661                NULL,                                   /* ea_list */
     
    64796718                  "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
    64806719                  (double)size));
     6720
     6721        if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
     6722                return NT_STATUS_ACCESS_DENIED;
     6723        }
    64816724
    64826725        return smb_set_file_size(conn, req,
     
    67847027
    67857028        id = vfs_file_id_from_sbuf(conn, &sbuf);
    6786         for(all_fsps = file_find_di_first(id); all_fsps;
     7029        for(all_fsps = file_find_di_first(conn->sconn, id); all_fsps;
    67877030                        all_fsps = file_find_di_next(all_fsps)) {
    67887031                /*
     
    69287171                0,                                      /* oplock_request */
    69297172                0,                                      /* allocation_size */
     7173                0,                                      /* private_flags */
    69307174                NULL,                                   /* sd */
    69317175                NULL,                                   /* ea_list */
     
    69847228 Open/Create a file with POSIX semantics.
    69857229****************************************************************************/
     7230
     7231#define SMB_O_RDONLY_MAPPING (FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA)
     7232#define SMB_O_WRONLY_MAPPING (FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA)
    69867233
    69877234static NTSTATUS smb_posix_open(connection_struct *conn,
     
    70007247        uint32 create_disp = 0;
    70017248        uint32 access_mask = 0;
    7002         uint32 create_options = 0;
     7249        uint32 create_options = FILE_NON_DIRECTORY_FILE;
    70037250        NTSTATUS status = NT_STATUS_OK;
    70047251        mode_t unixmode = (mode_t)0;
     
    70307277        switch (wire_open_mode & SMB_ACCMODE) {
    70317278                case SMB_O_RDONLY:
    7032                         access_mask = FILE_READ_DATA;
     7279                        access_mask = SMB_O_RDONLY_MAPPING;
    70337280                        break;
    70347281                case SMB_O_WRONLY:
    7035                         access_mask = FILE_WRITE_DATA;
     7282                        access_mask = SMB_O_WRONLY_MAPPING;
    70367283                        break;
    70377284                case SMB_O_RDWR:
    7038                         access_mask = FILE_READ_DATA|FILE_WRITE_DATA;
     7285                        access_mask = (SMB_O_RDONLY_MAPPING|
     7286                                        SMB_O_WRONLY_MAPPING);
    70397287                        break;
    70407288                default:
     
    71217369        }
    71227370
     7371        if ((wire_open_mode & SMB_O_DIRECTORY) ||
     7372                        VALID_STAT_OF_DIR(smb_fname->st)) {
     7373                if (access_mask != SMB_O_RDONLY_MAPPING) {
     7374                        return NT_STATUS_FILE_IS_A_DIRECTORY;
     7375                }
     7376                create_options &= ~FILE_NON_DIRECTORY_FILE;
     7377                create_options |= FILE_DIRECTORY_FILE;
     7378        }
     7379
    71237380        DEBUG(10,("smb_posix_open: file %s, smb_posix_flags = %u, mode 0%o\n",
    71247381                smb_fname_str_dbg(smb_fname),
     
    71357392                    FILE_SHARE_DELETE),
    71367393                create_disp,                            /* create_disposition*/
    7137                 FILE_NON_DIRECTORY_FILE,                /* create_options */
     7394                create_options,                         /* create_options */
    71387395                mod_unixmode,                           /* file_attributes */
    71397396                oplock_request,                         /* oplock_request */
    71407397                0,                                      /* allocation_size */
     7398                0,                                      /* private_flags */
    71417399                NULL,                                   /* sd */
    71427400                NULL,                                   /* ea_list */
     
    72687526                0,                                      /* oplock_request */
    72697527                0,                                      /* allocation_size */
     7528                0,                                      /* private_flags */
    72707529                NULL,                                   /* sd */
    72717530                NULL,                                   /* ea_list */
     
    75287787                                                             pdata, total_data,
    75297788                                                             fsp, smb_fname);
     7789                        break;
     7790                }
     7791
     7792                case SMB2_FILE_RENAME_INFORMATION_INTERNAL:
     7793                {
     7794                        /* SMB2 rename information. */
     7795                        status = smb2_file_rename_information(conn, req,
     7796                                                             pdata, total_data,
     7797                                                             fsp, smb_fname);
     7798                        break;
     7799                }
     7800
     7801                case SMB_FILE_LINK_INFORMATION:
     7802                {
     7803                        status = smb_file_link_information(conn, req,
     7804                                                        pdata, total_data,
     7805                                                        fsp, smb_fname);
    75307806                        break;
    75317807                }
     
    76387914                }
    76397915
    7640                 if(fsp->is_directory || fsp->fh->fd == -1) {
     7916                if(fsp->fh->fd == -1) {
    76417917                        /*
    76427918                         * This is actually a SETFILEINFO on a directory
     
    76707946                         */
    76717947                        if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
    7672                                 fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
     7948                                fsp->fh->private_options |= NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE;
    76737949
    76747950                                DEBUG(3,("call_trans2setfilepathinfo: "
     
    76907966                         * Original code - this is an open file.
    76917967                         */
    7692                         if (!check_fsp(conn, req, fsp)) {
    7693                                 return;
    7694                         }
    7695 
    76967968                        if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
    76977969                                DEBUG(3,("call_trans2setfilepathinfo: fstat "
     
    77818053                        return;
    77828054                }
    7783                 if (blocking_lock_was_deferred(req->mid)) {
     8055                if (blocking_lock_was_deferred_smb1(req->sconn, req->mid)) {
    77848056                        /* We have re-scheduled this call. */
    77858057                        return;
     
    81008372                        CAN ACCEPT THIS IN UNICODE. JRA. */
    81018373
    8102                 SSVAL(pdata,0,fsp->rap_print_jobid);                     /* Job number */
     8374                /* Job number */
     8375                if (fsp->print_file) {
     8376                        SSVAL(pdata, 0, fsp->print_file->rap_jobid);
     8377                } else {
     8378                        SSVAL(pdata, 0, 0);
     8379                }
    81038380                srvstr_push(pdata, req->flags2, pdata + 2,
    81048381                            global_myname(), 15,
     
    81238400{
    81248401        int dptr_num;
    8125         struct smbd_server_connection *sconn = smbd_server_conn;
     8402        struct smbd_server_connection *sconn = req->sconn;
    81268403
    81278404        START_PROFILE(SMBfindclose);
Note: See TracChangeset for help on using the changeset viewer.