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/nttrans.c

    r597 r740  
    2020
    2121#include "includes.h"
     22#include "system/filesys.h"
     23#include "smbd/smbd.h"
    2224#include "smbd/globals.h"
     25#include "fake_file.h"
     26#include "../libcli/security/security.h"
     27#include "../librpc/gen_ndr/ndr_security.h"
     28#include "passdb/lookup_sid.h"
     29#include "auth.h"
     30#include "ntioctl.h"
     31#include "smbprofile.h"
     32#include "libsmb/libsmb.h"
    2333
    2434extern const struct generic_mapping file_generic_mapping;
     
    5666        char *pd = pdata;
    5767        int params_sent_thistime, data_sent_thistime, total_sent_thistime;
    58         int alignment_offset = 3;
     68        int alignment_offset = 1;
    5969        int data_alignment_offset = 0;
    60         struct smbd_server_connection *sconn = smbd_server_conn;
     70        struct smbd_server_connection *sconn = req->sconn;
    6171        int max_send = sconn->smb1.sessions.max_send;
    6272
     
    7484                }
    7585                show_msg((char *)req->outbuf);
    76                 if (!srv_send_smb(smbd_server_fd(),
     86                if (!srv_send_smb(sconn,
    7787                                (char *)req->outbuf,
    7888                                true, req->seqnum+1,
     
    243253                /* Send the packet */
    244254                show_msg((char *)req->outbuf);
    245                 if (!srv_send_smb(smbd_server_fd(),
     255                if (!srv_send_smb(sconn,
    246256                                (char *)req->outbuf,
    247257                                true, req->seqnum+1,
     
    472482        root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
    473483
    474         allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
    475 #ifdef LARGE_SMB_OFF_T
    476         allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
    477 #endif
     484        allocation_size = BVAL(req->vwv+9, 1);
    478485
    479486        srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
     
    571578                oplock_request,                         /* oplock_request */
    572579                allocation_size,                        /* allocation_size */
     580                0,                                      /* private_flags */
    573581                NULL,                                   /* sd */
    574582                NULL,                                   /* ea_list */
     
    651659           write time. JRA. */
    652660        ZERO_STRUCT(write_time_ts);
    653         get_file_infos(fsp->file_id, NULL, &write_time_ts);
     661        get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
    654662        if (!null_timespec(write_time_ts)) {
    655663                update_stat_ex_mtime(&smb_fname->st, write_time_ts);
     
    828836****************************************************************************/
    829837
    830 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
    831                        uint32 security_info_sent)
     838NTSTATUS set_sd(files_struct *fsp, uint8_t *data, uint32_t sd_len,
     839                       uint32_t security_info_sent)
    832840{
    833         SEC_DESC *psd = NULL;
     841        struct security_descriptor *psd = NULL;
    834842        NTSTATUS status;
    835843
     
    853861
    854862        if (psd->owner_sid == NULL) {
    855                 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
     863                security_info_sent &= ~SECINFO_OWNER;
    856864        }
    857865        if (psd->group_sid == NULL) {
    858                 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
     866                security_info_sent &= ~SECINFO_GROUP;
    859867        }
    860868
     
    10231031        ea_len = IVAL(params,40);
    10241032        root_dir_fid = (uint16)IVAL(params,4);
    1025         allocation_size = (uint64_t)IVAL(params,12);
    1026 #ifdef LARGE_SMB_OFF_T
    1027         allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
    1028 #endif
     1033        allocation_size = BVAL(params,12);
    10291034
    10301035        /*
     
    11481153                oplock_request,                         /* oplock_request */
    11491154                allocation_size,                        /* allocation_size */
     1155                0,                                      /* private_flags */
    11501156                sd,                                     /* sd */
    11511157                ea_list,                                /* ea_list */
     
    12281234           write time. JRA. */
    12291235        ZERO_STRUCT(write_time_ts);
    1230         get_file_infos(fsp->file_id, NULL, &write_time_ts);
     1236        get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
    12311237        if (!null_timespec(write_time_ts)) {
    12321238                update_stat_ex_mtime(&smb_fname->st, write_time_ts);
     
    12611267        p += 8;
    12621268        if (flags & EXTENDED_RESPONSE_REQUIRED) {
    1263                 SSVAL(p,2,0x7);
     1269                uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
     1270                size_t num_names = 0;
     1271                unsigned int num_streams;
     1272                struct stream_struct *streams = NULL;
     1273
     1274                /* Do we have any EA's ? */
     1275                status = get_ea_names_from_file(ctx, conn, fsp,
     1276                                smb_fname->base_name, NULL, &num_names);
     1277                if (NT_STATUS_IS_OK(status) && num_names) {
     1278                        file_status &= ~NO_EAS;
     1279                }
     1280                status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
     1281                        &num_streams, &streams);
     1282                /* There is always one stream, ::$DATA. */
     1283                if (NT_STATUS_IS_OK(status) && num_streams > 1) {
     1284                        file_status &= ~NO_SUBSTREAMS;
     1285                }
     1286                TALLOC_FREE(streams);
     1287                SSVAL(p,2,file_status);
    12641288        }
    12651289        p += 4;
     
    12991323
    13001324        START_PROFILE(SMBntcancel);
    1301         srv_cancel_sign_response(smbd_server_conn);
    1302         remove_pending_change_notify_requests_by_mid(req->mid);
    1303         remove_pending_lock_requests_by_mid(req->mid);
    1304 
    1305         DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
     1325        srv_cancel_sign_response(req->sconn);
     1326        remove_pending_change_notify_requests_by_mid(req->sconn, req->mid);
     1327        remove_pending_lock_requests_by_mid_smb1(req->sconn, req->mid);
     1328
     1329        DEBUG(3,("reply_ntcancel: cancel called on mid = %llu.\n",
     1330                (unsigned long long)req->mid));
    13061331
    13071332        END_PROFILE(SMBntcancel);
     
    13401365        /* Ensure attributes match. */
    13411366        fattr = dos_mode(conn, smb_fname_src);
    1342         if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
     1367        if ((fattr & ~attrs) & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
    13431368                status = NT_STATUS_NO_SUCH_FILE;
    13441369                goto out;
     
    13661391                0,                                      /* root_dir_fid */
    13671392                smb_fname_src,                          /* fname */
    1368                 FILE_READ_DATA,                         /* access_mask */
     1393                FILE_READ_DATA|FILE_READ_ATTRIBUTES|
     1394                        FILE_READ_EA,                   /* access_mask */
    13691395                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
    13701396                    FILE_SHARE_DELETE),
     
    13741400                NO_OPLOCK,                              /* oplock_request */
    13751401                0,                                      /* allocation_size */
     1402                0,                                      /* private_flags */
    13761403                NULL,                                   /* sd */
    13771404                NULL,                                   /* ea_list */
     
    13881415                0,                                      /* root_dir_fid */
    13891416                smb_fname_dst,                          /* fname */
    1390                 FILE_WRITE_DATA,                        /* access_mask */
     1417                FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|
     1418                        FILE_WRITE_EA,                  /* access_mask */
    13911419                (FILE_SHARE_READ | FILE_SHARE_WRITE |   /* share_access */
    13921420                    FILE_SHARE_DELETE),
     
    13961424                NO_OPLOCK,                              /* oplock_request */
    13971425                0,                                      /* allocation_size */
     1426                0,                                      /* private_flags */
    13981427                NULL,                                   /* sd */
    13991428                NULL,                                   /* ea_list */
     
    14231452        status = close_file(NULL, fsp2, NORMAL_CLOSE);
    14241453
    1425         /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
     1454        /* Grrr. We have to do this as open_file_ntcreate adds FILE_ATTRIBUTE_ARCHIVE when it
    14261455           creates the file. This isn't the correct thing to do in the copy
    14271456           case. JRA */
     
    14681497        uint16 rename_type;
    14691498        TALLOC_CTX *ctx = talloc_tos();
     1499        bool stream_rename = false;
    14701500
    14711501        START_PROFILE(SMBntrename);
     
    15001530        }
    15011531
    1502         /* The newname must begin with a ':' if the oldname contains a ':'. */
    1503         if (strchr_m(oldname, ':') && (newname[0] != ':')) {
    1504                 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    1505                 goto out;
     1532        if (!lp_posix_pathnames()) {
     1533                /* The newname must begin with a ':' if the
     1534                   oldname contains a ':'. */
     1535                if (strchr_m(oldname, ':')) {
     1536                        if (newname[0] != ':') {
     1537                                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     1538                                goto out;
     1539                        }
     1540                        stream_rename = true;
     1541                }
    15061542        }
    15071543
     
    15521588        }
    15531589
     1590        if (stream_rename) {
     1591                /* smb_fname_new must be the same as smb_fname_old. */
     1592                TALLOC_FREE(smb_fname_new->base_name);
     1593                smb_fname_new->base_name = talloc_strdup(smb_fname_new,
     1594                                                smb_fname_old->base_name);
     1595                if (!smb_fname_new->base_name) {
     1596                        reply_nterror(req, NT_STATUS_NO_MEMORY);
     1597                        goto out;
     1598                }
     1599        }
     1600
    15541601        DEBUG(3,("reply_ntrename: %s -> %s\n",
    15551602                 smb_fname_str_dbg(smb_fname_old),
     
    15701617                        } else {
    15711618                                status = hardlink_internals(ctx, conn,
     1619                                                            req,
     1620                                                            false,
    15721621                                                            smb_fname_old,
    15731622                                                            smb_fname_new);
     
    16961745                 */
    16971746
    1698                 change_notify_reply(fsp->conn, req,
     1747                change_notify_reply(req,
    16991748                                    NT_STATUS_OK,
    17001749                                    max_param_count,
     
    17751824*******************************************************************************/
    17761825
    1777 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
     1826static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, struct security_descriptor **ppsd)
    17781827{
    17791828        size_t sd_size;
     
    17901839/****************************************************************************
    17911840 Reply to query a security descriptor.
     1841 Callable from SMB2 and SMB2.
     1842 If it returns NT_STATUS_BUFFER_TOO_SMALL, pdata_size is initialized with
     1843 the required size.
     1844****************************************************************************/
     1845
     1846NTSTATUS smbd_do_query_security_desc(connection_struct *conn,
     1847                                        TALLOC_CTX *mem_ctx,
     1848                                        files_struct *fsp,
     1849                                        uint32_t security_info_wanted,
     1850                                        uint32_t max_data_count,
     1851                                        uint8_t **ppmarshalled_sd,
     1852                                        size_t *psd_size)
     1853{
     1854        NTSTATUS status;
     1855        struct security_descriptor *psd = NULL;
     1856
     1857        /*
     1858         * Get the permissions to return.
     1859         */
     1860
     1861        if ((security_info_wanted & SECINFO_SACL) &&
     1862                        !(fsp->access_mask & SEC_FLAG_SYSTEM_SECURITY)) {
     1863                return NT_STATUS_ACCESS_DENIED;
     1864        }
     1865
     1866        if ((security_info_wanted & (SECINFO_DACL|SECINFO_OWNER|SECINFO_GROUP)) &&
     1867                        !(fsp->access_mask & SEC_STD_READ_CONTROL)) {
     1868                return NT_STATUS_ACCESS_DENIED;
     1869        }
     1870
     1871        if (!lp_nt_acl_support(SNUM(conn))) {
     1872                status = get_null_nt_acl(mem_ctx, &psd);
     1873        } else {
     1874                status = SMB_VFS_FGET_NT_ACL(
     1875                        fsp, security_info_wanted, &psd);
     1876        }
     1877        if (!NT_STATUS_IS_OK(status)) {
     1878                return status;
     1879        }
     1880
     1881        if (!(security_info_wanted & SECINFO_OWNER)) {
     1882                psd->owner_sid = NULL;
     1883        }
     1884        if (!(security_info_wanted & SECINFO_GROUP)) {
     1885                psd->group_sid = NULL;
     1886        }
     1887        if (!(security_info_wanted & SECINFO_DACL)) {
     1888                psd->dacl = NULL;
     1889        }
     1890        if (!(security_info_wanted & SECINFO_SACL)) {
     1891                psd->sacl = NULL;
     1892        }
     1893
     1894        /* If the SACL/DACL is NULL, but was requested, we mark that it is
     1895         * present in the reply to match Windows behavior */
     1896        if (psd->sacl == NULL &&
     1897            security_info_wanted & SECINFO_SACL)
     1898                psd->type |= SEC_DESC_SACL_PRESENT;
     1899        if (psd->dacl == NULL &&
     1900            security_info_wanted & SECINFO_DACL)
     1901                psd->type |= SEC_DESC_DACL_PRESENT;
     1902
     1903        *psd_size = ndr_size_security_descriptor(psd, 0);
     1904
     1905        DEBUG(3,("smbd_do_query_security_desc: sd_size = %lu.\n",
     1906                (unsigned long)*psd_size));
     1907
     1908        if (DEBUGLEVEL >= 10) {
     1909                DEBUG(10,("smbd_do_query_security_desc for file %s\n",
     1910                          fsp_str_dbg(fsp)));
     1911                NDR_PRINT_DEBUG(security_descriptor, psd);
     1912        }
     1913
     1914        if (max_data_count < *psd_size) {
     1915                TALLOC_FREE(psd);
     1916                return NT_STATUS_BUFFER_TOO_SMALL;
     1917        }
     1918
     1919        status = marshall_sec_desc(mem_ctx, psd,
     1920                                   ppmarshalled_sd, psd_size);
     1921
     1922        if (!NT_STATUS_IS_OK(status)) {
     1923                TALLOC_FREE(psd);
     1924                return status;
     1925        }
     1926
     1927        TALLOC_FREE(psd);
     1928        return NT_STATUS_OK;
     1929}
     1930
     1931/****************************************************************************
     1932 SMB1 reply to query a security descriptor.
    17921933****************************************************************************/
    17931934
     
    18041945        char *params = *ppparams;
    18051946        char *data = *ppdata;
    1806         SEC_DESC *psd = NULL;
    1807         size_t sd_size;
     1947        size_t sd_size = 0;
    18081948        uint32 security_info_wanted;
    18091949        files_struct *fsp = NULL;
    18101950        NTSTATUS status;
    1811         DATA_BLOB blob;
     1951        uint8_t *marshalled_sd = NULL;
    18121952
    18131953        if(parameter_count < 8) {
     
    18381978         */
    18391979
    1840         if ((security_info_wanted & SECINFO_SACL) &&
    1841                         !(fsp->access_mask & SEC_FLAG_SYSTEM_SECURITY)) {
    1842                 reply_nterror(req,  NT_STATUS_ACCESS_DENIED);
    1843                 return;
    1844         }
    1845 
    1846         if ((security_info_wanted & (SECINFO_DACL|SECINFO_OWNER|SECINFO_GROUP)) &&
    1847                         !(fsp->access_mask & SEC_STD_READ_CONTROL)) {
    1848                 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    1849                 return;
    1850         }
    1851 
    1852         if (!lp_nt_acl_support(SNUM(conn))) {
    1853                 status = get_null_nt_acl(talloc_tos(), &psd);
    1854         } else {
    1855                 status = SMB_VFS_FGET_NT_ACL(
    1856                         fsp, security_info_wanted, &psd);
    1857         }
     1980        status = smbd_do_query_security_desc(conn,
     1981                                        talloc_tos(),
     1982                                        fsp,
     1983                                        security_info_wanted,
     1984                                        max_data_count,
     1985                                        &marshalled_sd,
     1986                                        &sd_size);
     1987
     1988        if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
     1989                SIVAL(params,0,(uint32_t)sd_size);
     1990                send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
     1991                        params, 4, NULL, 0);
     1992                return;
     1993        }
     1994
    18581995        if (!NT_STATUS_IS_OK(status)) {
    18591996                reply_nterror(req, status);
     
    18611998        }
    18621999
    1863         if (!(security_info_wanted & SECINFO_OWNER)) {
    1864                 psd->owner_sid = NULL;
    1865         }
    1866         if (!(security_info_wanted & SECINFO_GROUP)) {
    1867                 psd->group_sid = NULL;
    1868         }
    1869         if (!(security_info_wanted & SECINFO_DACL)) {
    1870                 psd->dacl = NULL;
    1871         }
    1872         if (!(security_info_wanted & SECINFO_SACL)) {
    1873                 psd->sacl = NULL;
    1874         }
    1875 
    1876         /* If the SACL/DACL is NULL, but was requested, we mark that it is
    1877          * present in the reply to match Windows behavior */
    1878         if (psd->sacl == NULL &&
    1879             security_info_wanted & SACL_SECURITY_INFORMATION)
    1880                 psd->type |= SEC_DESC_SACL_PRESENT;
    1881         if (psd->dacl == NULL &&
    1882             security_info_wanted & DACL_SECURITY_INFORMATION)
    1883                 psd->type |= SEC_DESC_DACL_PRESENT;
    1884 
    1885         sd_size = ndr_size_security_descriptor(psd, NULL, 0);
    1886 
    1887         DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
    1888 
    1889         if (DEBUGLEVEL >= 10) {
    1890                 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
    1891                           fsp_str_dbg(fsp)));
    1892                 NDR_PRINT_DEBUG(security_descriptor, psd);
    1893         }
    1894 
    1895         SIVAL(params,0,(uint32)sd_size);
     2000        SMB_ASSERT(sd_size > 0);
     2001
     2002        SIVAL(params,0,(uint32_t)sd_size);
    18962003
    18972004        if (max_data_count < sd_size) {
    18982005                send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
    1899                                 params, 4, *ppdata, 0);
     2006                                params, 4, NULL, 0);
    19002007                return;
    19012008        }
    19022009
    19032010        /*
    1904          * Allocate the data we will point this at.
     2011         * Allocate the data we will return.
    19052012         */
    19062013
     
    19112018        }
    19122019
    1913         status = marshall_sec_desc(talloc_tos(), psd,
    1914                                    &blob.data, &blob.length);
    1915 
    1916         if (!NT_STATUS_IS_OK(status)) {
    1917                 reply_nterror(req, status);
    1918                 return;
    1919         }
    1920 
    1921         SMB_ASSERT(sd_size == blob.length);
    1922         memcpy(data, blob.data, sd_size);
     2020        memcpy(data, marshalled_sd, sd_size);
    19232021
    19242022        send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
     
    19572055        }
    19582056
     2057        if (!CAN_WRITE(fsp->conn)) {
     2058                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
     2059                return;
     2060        }
     2061
    19592062        if(!lp_nt_acl_support(SNUM(conn))) {
    19602063                goto done;
     
    20242127        switch (function) {
    20252128        case FSCTL_SET_SPARSE:
    2026                 /* pretend this succeeded - tho strictly we should
    2027                    mark the file sparse (if the local fs supports it)
    2028                    so we can know if we need to pre-allocate or not */
    2029 
    2030                 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
     2129        {
     2130                bool set_sparse = true;
     2131                NTSTATUS status;
     2132
     2133                if (data_count >= 1 && pdata[0] == 0) {
     2134                        set_sparse = false;
     2135                }
     2136
     2137                DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X]set[%u]\n",
     2138                         fidnum, set_sparse));
     2139
     2140                if (!check_fsp_open(conn, req, fsp)) {
     2141                        return;
     2142                }
     2143
     2144                status = file_set_sparse(conn, fsp, set_sparse);
     2145                if (!NT_STATUS_IS_OK(status)) {
     2146                        DEBUG(9,("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
     2147                                 smb_fname_str_dbg(fsp->fsp_name), set_sparse, nt_errstr(status)));
     2148                        reply_nterror(req, status);
     2149                        return;
     2150                }
     2151
     2152                DEBUG(10,("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
     2153                         smb_fname_str_dbg(fsp->fsp_name), set_sparse, nt_errstr(status)));
    20312154                send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
    20322155                return;
    2033 
     2156        }
    20342157        case FSCTL_CREATE_OR_GET_OBJECT_ID:
    20352158        {
     
    20422165                DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
    20432166
    2044                 if (!fsp_belongs_conn(conn, req, fsp)) {
     2167                if (!check_fsp_open(conn, req, fsp)) {
    20452168                        return;
    20462169                }
     
    20922215                 * it be deallocated when we return.
    20932216                 */
    2094                 SHADOW_COPY_DATA *shadow_data = NULL;
    2095                 TALLOC_CTX *shadow_mem_ctx = NULL;
     2217                struct shadow_copy_data *shadow_data = NULL;
    20962218                bool labels = False;
    20972219                uint32 labels_data_count = 0;
     
    20992221                char *cur_pdata;
    21002222
    2101                 if (!fsp_belongs_conn(conn, req, fsp)) {
     2223                if (!check_fsp_open(conn, req, fsp)) {
    21022224                        return;
    21032225                }
     
    21142236                }
    21152237
    2116                 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
    2117                 if (shadow_mem_ctx == NULL) {
    2118                         DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
     2238                shadow_data = TALLOC_ZERO_P(talloc_tos(),
     2239                                            struct shadow_copy_data);
     2240                if (shadow_data == NULL) {
     2241                        DEBUG(0,("TALLOC_ZERO() failed!\n"));
    21192242                        reply_nterror(req, NT_STATUS_NO_MEMORY);
    21202243                        return;
    21212244                }
    2122 
    2123                 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
    2124                 if (shadow_data == NULL) {
    2125                         DEBUG(0,("TALLOC_ZERO() failed!\n"));
    2126                         talloc_destroy(shadow_mem_ctx);
    2127                         reply_nterror(req, NT_STATUS_NO_MEMORY);
    2128                         return;
    2129                 }
    2130 
    2131                 shadow_data->mem_ctx = shadow_mem_ctx;
    21322245
    21332246                /*
     
    21352248                 */
    21362249                if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
    2137                         talloc_destroy(shadow_data->mem_ctx);
     2250                        TALLOC_FREE(shadow_data);
    21382251                        if (errno == ENOSYS) {
    21392252                                DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
     
    21602273                        DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
    21612274                                max_data_count,data_count));
    2162                         talloc_destroy(shadow_data->mem_ctx);
     2275                        TALLOC_FREE(shadow_data);
    21632276                        reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
    21642277                        return;
     
    21672280                pdata = nttrans_realloc(ppdata, data_count);
    21682281                if (pdata == NULL) {
    2169                         talloc_destroy(shadow_data->mem_ctx);
     2282                        TALLOC_FREE(shadow_data);
    21702283                        reply_nterror(req, NT_STATUS_NO_MEMORY);
    21712284                        return;
     
    22002313                }
    22012314
    2202                 talloc_destroy(shadow_data->mem_ctx);
     2315                TALLOC_FREE(shadow_data);
    22032316
    22042317                send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
     
    22162329                 * but I have to check that --metze
    22172330                 */
    2218                 DOM_SID sid;
     2331                struct dom_sid sid;
    22192332                uid_t uid;
    2220                 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
     2333                size_t sid_len;
    22212334
    22222335                DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
    22232336
    2224                 if (!fsp_belongs_conn(conn, req, fsp)) {
     2337                if (!check_fsp_open(conn, req, fsp)) {
    22252338                        return;
    22262339                }
     2340
     2341                if (data_count < 8) {
     2342                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     2343                        return;
     2344                }
     2345
     2346                sid_len = MIN(data_count-4,SID_MAX_SIZE);
    22272347
    22282348                /* unknown 4 bytes: this is not the length of the sid :-(  */
     
    22332353                        return;
    22342354                }
    2235 
    22362355                DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
    22372356
     
    22652384                return;
    22662385        }
     2386        case FSCTL_QUERY_ALLOCATED_RANGES:
     2387        {
     2388                /* FIXME: This is just a dummy reply, telling that all of the
     2389                 * file is allocated. MKS cp needs that.
     2390                 * Adding the real allocated ranges via FIEMAP on Linux
     2391                 * and SEEK_DATA/SEEK_HOLE on Solaris is needed to make
     2392                 * this FSCTL correct for sparse files.
     2393                 */
     2394                NTSTATUS status;
     2395                uint64_t offset, length;
     2396
     2397                if (!check_fsp_open(conn, req, fsp)) {
     2398                        return;
     2399                }
     2400
     2401                if (data_count != 16) {
     2402                        DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: data_count(%u) != 16 is invalid!\n",
     2403                                data_count));
     2404                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     2405                        return;
     2406                }
     2407
     2408                if (max_data_count < 16) {
     2409                        DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_data_count(%u) < 16 is invalid!\n",
     2410                                max_data_count));
     2411                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     2412                        return;
     2413                }
     2414
     2415                offset = BVAL(pdata,0);
     2416                length = BVAL(pdata,8);
     2417
     2418                if (offset + length < offset) {
     2419                        /* No 64-bit integer wrap. */
     2420                        reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     2421                        return;
     2422                }
     2423
     2424                status = vfs_stat_fsp(fsp);
     2425                if (!NT_STATUS_IS_OK(status)) {
     2426                        reply_nterror(req, status);
     2427                        return;
     2428                }
     2429
     2430                if (offset > fsp->fsp_name->st.st_ex_size ||
     2431                                fsp->fsp_name->st.st_ex_size == 0 ||
     2432                                length == 0) {
     2433                        send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
     2434                } else {
     2435                        uint64_t end = offset + length;
     2436                        end = MIN(end, fsp->fsp_name->st.st_ex_size);
     2437                        SBVAL(pdata,0,0);
     2438                        SBVAL(pdata,8,end);
     2439                        send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
     2440                                pdata, 16);
     2441                }
     2442                return;
     2443        }
     2444        case FSCTL_IS_VOLUME_DIRTY:
     2445                DEBUG(10,("FSCTL_IS_VOLUME_DIRTY: called on FID[0x%04X] "
     2446                          "(but not implemented)\n", (int)fidnum));
     2447                /*
     2448                 * http://msdn.microsoft.com/en-us/library/cc232128%28PROT.10%29.aspx
     2449                 * says we have to respond with NT_STATUS_INVALID_PARAMETER
     2450                 */
     2451                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     2452                return;
    22672453        default:
     2454                /* Only print this once... */
    22682455                if (!logged_ioctl_message) {
    2269                         logged_ioctl_message = true; /* Only print this once... */
    2270                         DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
     2456                        logged_ioctl_message = true;
     2457                        DEBUG(2,("call_nt_transact_ioctl(0x%x): "
     2458                                 "Currently not implemented.\n",
    22712459                                 function));
    22722460                }
     
    23022490        uint16 level = 0;
    23032491        size_t sid_len;
    2304         DOM_SID sid;
     2492        struct dom_sid sid;
    23052493        bool start_enum = True;
    23062494        SMB_NTQUOTA_STRUCT qt;
     
    23112499
    23122500        /* access check */
    2313         if (conn->server_info->utok.uid != 0 && !conn->admin_user) {
     2501        if (get_current_uid(conn) != 0) {
    23142502                DEBUG(1,("get_user_quota: access_denied service [%s] user "
    23152503                         "[%s]\n", lp_servicename(SNUM(conn)),
    2316                          conn->server_info->unix_name));
     2504                         conn->session_info->unix_name));
    23172505                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    23182506                return;
     
    24182606
    24192607                                sid_len = ndr_size_dom_sid(
    2420                                         &tmp_list->quotas->sid, NULL, 0);
     2608                                        &tmp_list->quotas->sid, 0);
    24212609                                entry_len = 40 + sid_len;
    24222610
     
    25752763        SMB_NTQUOTA_STRUCT qt;
    25762764        size_t sid_len;
    2577         DOM_SID sid;
     2765        struct dom_sid sid;
    25782766        files_struct *fsp = NULL;
    25792767
     
    25812769
    25822770        /* access check */
    2583         if (conn->server_info->utok.uid != 0 && !conn->admin_user) {
     2771        if (get_current_uid(conn) != 0) {
    25842772                DEBUG(1,("set_user_quota: access_denied service [%s] user "
    25852773                         "[%s]\n", lp_servicename(SNUM(conn)),
    2586                          conn->server_info->unix_name));
     2774                         conn->session_info->unix_name));
    25872775                reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    25882776                return;
     
    26092797        if (data_count < 40) {
    26102798                DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
    2611                 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
     2799                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    26122800                return;
    26132801        }
     
    26212809        sid_len = IVAL(pdata,4);
    26222810
    2623         if (data_count < 40+sid_len) {
     2811        if (data_count < 40+sid_len || (40+sid_len < sid_len)) {
    26242812                DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
    2625                 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
     2813                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    26262814                return;
    26272815        }
     
    26322820
    26332821        /* the used space 8 bytes (uint64_t)*/
    2634         qt.usedspace = (uint64_t)IVAL(pdata,16);
    2635 #ifdef LARGE_SMB_OFF_T
    2636         qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
    2637 #else /* LARGE_SMB_OFF_T */
    2638         if ((IVAL(pdata,20) != 0)&&
    2639                 ((qt.usedspace != 0xFFFFFFFF)||
    2640                 (IVAL(pdata,20)!=0xFFFFFFFF))) {
    2641                 /* more than 32 bits? */
    2642                 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
    2643                 return;
    2644         }
    2645 #endif /* LARGE_SMB_OFF_T */
     2822        qt.usedspace = BVAL(pdata,16);
    26462823
    26472824        /* the soft quotas 8 bytes (uint64_t)*/
    2648         qt.softlim = (uint64_t)IVAL(pdata,24);
    2649 #ifdef LARGE_SMB_OFF_T
    2650         qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
    2651 #else /* LARGE_SMB_OFF_T */
    2652         if ((IVAL(pdata,28) != 0)&&
    2653                 ((qt.softlim != 0xFFFFFFFF)||
    2654                 (IVAL(pdata,28)!=0xFFFFFFFF))) {
    2655                 /* more than 32 bits? */
    2656                 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
    2657                 return;
    2658         }
    2659 #endif /* LARGE_SMB_OFF_T */
     2825        qt.softlim = BVAL(pdata,24);
    26602826
    26612827        /* the hard quotas 8 bytes (uint64_t)*/
    2662         qt.hardlim = (uint64_t)IVAL(pdata,32);
    2663 #ifdef LARGE_SMB_OFF_T
    2664         qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
    2665 #else /* LARGE_SMB_OFF_T */
    2666         if ((IVAL(pdata,36) != 0)&&
    2667                 ((qt.hardlim != 0xFFFFFFFF)||
    2668                 (IVAL(pdata,36)!=0xFFFFFFFF))) {
    2669                 /* more than 32 bits? */
    2670                 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
    2671                 return;
    2672         }
    2673 #endif /* LARGE_SMB_OFF_T */
     2828        qt.hardlim = BVAL(pdata,32);
    26742829
    26752830        if (!sid_parse(pdata+40,sid_len,&sid)) {
Note: See TracChangeset for help on using the changeset viewer.