Ignore:
Timestamp:
Nov 27, 2012, 4:56:06 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated vendor to 3.6.9

File:
1 edited

Legend:

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

    r740 r746  
    143143                             total_sent_thistime + alignment_offset
    144144                             + data_alignment_offset);
    145 
    146                 /*
    147                  * We might have had SMBnttranss in req->inbuf, fix that.
    148                  */
    149                 SCVAL(req->outbuf, smb_com, SMBnttrans);
    150145
    151146                /*
     
    694689                uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
    695690                size_t num_names = 0;
    696                 unsigned int num_streams;
     691                unsigned int num_streams = 0;
    697692                struct stream_struct *streams = NULL;
    698693
     
    703698                        file_status &= ~NO_EAS;
    704699                }
    705                 status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
     700                status = vfs_streaminfo(conn, NULL, smb_fname->base_name, ctx,
    706701                        &num_streams, &streams);
    707702                /* There is always one stream, ::$DATA. */
     
    832827}
    833828
     829/*********************************************************************
     830 Windows seems to do canonicalization of inheritance bits. Do the
     831 same.
     832*********************************************************************/
     833
     834static void canonicalize_inheritance_bits(struct security_descriptor *psd)
     835{
     836        bool set_auto_inherited = false;
     837
     838        /*
     839         * We need to filter out the
     840         * SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ
     841         * bits. If both are set we store SEC_DESC_DACL_AUTO_INHERITED
     842         * as this alters whether SEC_ACE_FLAG_INHERITED_ACE is set
     843         * when an ACE is inherited. Otherwise we zero these bits out.
     844         * See:
     845         *
     846         * http://social.msdn.microsoft.com/Forums/eu/os_fileservices/thread/11f77b68-731e-407d-b1b3-064750716531
     847         *
     848         * for details.
     849         */
     850
     851        if ((psd->type & (SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ))
     852                        == (SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ)) {
     853                set_auto_inherited = true;
     854        }
     855
     856        psd->type &= ~(SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ);
     857        if (set_auto_inherited) {
     858                psd->type |= SEC_DESC_DACL_AUTO_INHERITED;
     859        }
     860}
     861
    834862/****************************************************************************
    835863 Internal fn to set security descriptors.
    836864****************************************************************************/
    837865
    838 NTSTATUS set_sd(files_struct *fsp, uint8_t *data, uint32_t sd_len,
     866NTSTATUS set_sd(files_struct *fsp, struct security_descriptor *psd,
     867                       uint32_t security_info_sent)
     868{
     869        NTSTATUS status;
     870
     871        if (!CAN_WRITE(fsp->conn)) {
     872                return NT_STATUS_ACCESS_DENIED;
     873        }
     874
     875        if (!lp_nt_acl_support(SNUM(fsp->conn))) {
     876                return NT_STATUS_OK;
     877        }
     878
     879        if (psd->owner_sid == NULL) {
     880                security_info_sent &= ~SECINFO_OWNER;
     881        }
     882        if (psd->group_sid == NULL) {
     883                security_info_sent &= ~SECINFO_GROUP;
     884        }
     885
     886        /* Ensure we have at least one thing set. */
     887        if ((security_info_sent & (SECINFO_OWNER|SECINFO_GROUP|SECINFO_DACL|SECINFO_SACL)) == 0) {
     888                if (security_info_sent & SECINFO_LABEL) {
     889                        /* Only consider SECINFO_LABEL if no other
     890                           bits are set. Just like W2K3 we don't
     891                           store this. */
     892                        return NT_STATUS_OK;
     893                }
     894                return NT_STATUS_INVALID_PARAMETER;
     895        }
     896
     897        /* Ensure we have the rights to do this. */
     898        if (security_info_sent & SECINFO_OWNER) {
     899                if (!(fsp->access_mask & SEC_STD_WRITE_OWNER)) {
     900                        return NT_STATUS_ACCESS_DENIED;
     901                }
     902        }
     903
     904        if (security_info_sent & SECINFO_GROUP) {
     905                if (!(fsp->access_mask & SEC_STD_WRITE_OWNER)) {
     906                        return NT_STATUS_ACCESS_DENIED;
     907                }
     908        }
     909
     910        if (security_info_sent & SECINFO_DACL) {
     911                if (!(fsp->access_mask & SEC_STD_WRITE_DAC)) {
     912                        return NT_STATUS_ACCESS_DENIED;
     913                }
     914                /* Convert all the generic bits. */
     915                if (psd->dacl) {
     916                        security_acl_map_generic(psd->dacl, &file_generic_mapping);
     917                }
     918        }
     919
     920        if (security_info_sent & SECINFO_SACL) {
     921                if (!(fsp->access_mask & SEC_FLAG_SYSTEM_SECURITY)) {
     922                        return NT_STATUS_ACCESS_DENIED;
     923                }
     924                /* Convert all the generic bits. */
     925                if (psd->sacl) {
     926                        security_acl_map_generic(psd->sacl, &file_generic_mapping);
     927                }
     928        }
     929
     930        canonicalize_inheritance_bits(psd);
     931
     932        if (DEBUGLEVEL >= 10) {
     933                DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
     934                NDR_PRINT_DEBUG(security_descriptor, psd);
     935        }
     936
     937        status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
     938
     939        TALLOC_FREE(psd);
     940
     941        return status;
     942}
     943
     944/****************************************************************************
     945 Internal fn to set security descriptors from a data blob.
     946****************************************************************************/
     947
     948NTSTATUS set_sd_blob(files_struct *fsp, uint8_t *data, uint32_t sd_len,
    839949                       uint32_t security_info_sent)
    840950{
     
    846956        }
    847957
    848         if (!CAN_WRITE(fsp->conn)) {
    849                 return NT_STATUS_ACCESS_DENIED;
    850         }
    851 
    852         if (!lp_nt_acl_support(SNUM(fsp->conn))) {
    853                 return NT_STATUS_OK;
    854         }
    855 
    856958        status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
    857959
     
    860962        }
    861963
    862         if (psd->owner_sid == NULL) {
    863                 security_info_sent &= ~SECINFO_OWNER;
    864         }
    865         if (psd->group_sid == NULL) {
    866                 security_info_sent &= ~SECINFO_GROUP;
    867         }
    868 
    869         /* Ensure we have at least one thing set. */
    870         if ((security_info_sent & (SECINFO_OWNER|SECINFO_GROUP|SECINFO_DACL|SECINFO_SACL)) == 0) {
    871                 return NT_STATUS_INVALID_PARAMETER;
    872         }
    873 
    874         /* Ensure we have the rights to do this. */
    875         if (security_info_sent & SECINFO_OWNER) {
    876                 if (!(fsp->access_mask & SEC_STD_WRITE_OWNER)) {
    877                         return NT_STATUS_ACCESS_DENIED;
    878                 }
    879         }
    880 
    881         if (security_info_sent & SECINFO_GROUP) {
    882                 if (!(fsp->access_mask & SEC_STD_WRITE_OWNER)) {
    883                         return NT_STATUS_ACCESS_DENIED;
    884                 }
    885         }
    886 
    887         if (security_info_sent & SECINFO_DACL) {
    888                 if (!(fsp->access_mask & SEC_STD_WRITE_DAC)) {
    889                         return NT_STATUS_ACCESS_DENIED;
    890                 }
    891                 /* Convert all the generic bits. */
    892                 if (psd->dacl) {
    893                         security_acl_map_generic(psd->dacl, &file_generic_mapping);
    894                 }
    895         }
    896 
    897         if (security_info_sent & SECINFO_SACL) {
    898                 if (!(fsp->access_mask & SEC_FLAG_SYSTEM_SECURITY)) {
    899                         return NT_STATUS_ACCESS_DENIED;
    900                 }
    901                 /* Convert all the generic bits. */
    902                 if (psd->sacl) {
    903                         security_acl_map_generic(psd->sacl, &file_generic_mapping);
    904                 }
    905         }
    906 
    907         if (DEBUGLEVEL >= 10) {
    908                 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
    909                 NDR_PRINT_DEBUG(security_descriptor, psd);
    910         }
    911 
    912         status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
    913 
    914         TALLOC_FREE(psd);
    915 
    916         return status;
     964        return set_sd(fsp, psd, security_info_sent);
    917965}
    918966
     
    12691317                uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
    12701318                size_t num_names = 0;
    1271                 unsigned int num_streams;
     1319                unsigned int num_streams = 0;
    12721320                struct stream_struct *streams = NULL;
    12731321
     
    12781326                        file_status &= ~NO_EAS;
    12791327                }
    1280                 status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
     1328                status = vfs_streaminfo(conn, NULL, smb_fname->base_name, ctx,
    12811329                        &num_streams, &streams);
    12821330                /* There is always one stream, ::$DATA. */
     
    18691917        }
    18701918
     1919        if (security_info_wanted & (SECINFO_DACL|SECINFO_OWNER|
     1920                        SECINFO_GROUP|SECINFO_SACL)) {
     1921                /* Don't return SECINFO_LABEL if anything else was
     1922                   requested. See bug #8458. */
     1923                security_info_wanted &= ~SECINFO_LABEL;
     1924        }
     1925
    18711926        if (!lp_nt_acl_support(SNUM(conn))) {
     1927                status = get_null_nt_acl(mem_ctx, &psd);
     1928        } else if (security_info_wanted & SECINFO_LABEL) {
     1929                /* Like W2K3 return a null object. */
    18721930                status = get_null_nt_acl(mem_ctx, &psd);
    18731931        } else {
     
    18861944        }
    18871945        if (!(security_info_wanted & SECINFO_DACL)) {
     1946                psd->type &= ~SEC_DESC_DACL_PRESENT;
    18881947                psd->dacl = NULL;
    18891948        }
    18901949        if (!(security_info_wanted & SECINFO_SACL)) {
     1950                psd->type &= ~SEC_DESC_SACL_PRESENT;
    18911951                psd->sacl = NULL;
    18921952        }
     
    19001960            security_info_wanted & SECINFO_DACL)
    19011961                psd->type |= SEC_DESC_DACL_PRESENT;
     1962
     1963        if (security_info_wanted & SECINFO_LABEL) {
     1964                /* Like W2K3 return a null object. */
     1965                psd->owner_sid = NULL;
     1966                psd->group_sid = NULL;
     1967                psd->dacl = NULL;
     1968                psd->sacl = NULL;
     1969                psd->type &= ~(SEC_DESC_DACL_PRESENT|SEC_DESC_SACL_PRESENT);
     1970        }
    19021971
    19031972        *psd_size = ndr_size_security_descriptor(psd, 0);
     
    20742143        }
    20752144
    2076         status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
     2145        status = set_sd_blob(fsp, (uint8 *)data, data_count, security_info_sent);
    20772146
    20782147        if (!NT_STATUS_IS_OK(status)) {
     
    20862155}
    20872156
    2088 /****************************************************************************
    2089  Reply to NT IOCTL
    2090 ****************************************************************************/
    2091 
    2092 static void call_nt_transact_ioctl(connection_struct *conn,
    2093                                    struct smb_request *req,
    2094                                    uint16 **ppsetup, uint32 setup_count,
    2095                                    char **ppparams, uint32 parameter_count,
    2096                                    char **ppdata, uint32 data_count,
    2097                                    uint32 max_data_count)
     2157/*
     2158 * Implement the default fsctl operation.
     2159 */
     2160
     2161static bool vfswrap_logged_ioctl_message = false;
     2162
     2163/*
     2164 * In 3.6 we do not have a SMB_VFS_FSCTL() function
     2165 * it's just faked to make it more look like
     2166 * master (4.0)
     2167 */
     2168NTSTATUS smb_fsctl(struct files_struct *fsp,
     2169                       TALLOC_CTX *ctx,
     2170                       uint32_t function,
     2171                       uint16_t req_flags,  /* Needed for UNICODE ... */
     2172                       const uint8_t *_in_data,
     2173                       uint32_t in_len,
     2174                       uint8_t **_out_data,
     2175                       uint32_t max_out_len,
     2176                       uint32_t *out_len)
    20982177{
    2099         uint32 function;
    2100         uint16 fidnum;
    2101         files_struct *fsp;
    2102         uint8 isFSctl;
    2103         uint8 compfilter;
    2104         char *pdata = *ppdata;
    2105 
    2106         if (setup_count != 8) {
    2107                 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
    2108                 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
    2109                 return;
    2110         }
    2111 
    2112         function = IVAL(*ppsetup, 0);
    2113         fidnum = SVAL(*ppsetup, 4);
    2114         isFSctl = CVAL(*ppsetup, 6);
    2115         compfilter = CVAL(*ppsetup, 7);
    2116 
    2117         DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
    2118                  function, fidnum, isFSctl, compfilter));
    2119 
    2120         fsp=file_fsp(req, fidnum);
    2121         /* this check is done in each implemented function case for now
    2122            because I don't want to break anything... --metze
    2123         FSP_BELONGS_CONN(fsp,conn);*/
    2124 
    2125         SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
     2178        const char *in_data = (const char *)_in_data;
     2179        char **out_data = (char **)_out_data;
    21262180
    21272181        switch (function) {
     
    21312185                NTSTATUS status;
    21322186
    2133                 if (data_count >= 1 && pdata[0] == 0) {
     2187                if (in_len >= 1 && in_data[0] == 0) {
    21342188                        set_sparse = false;
    21352189                }
    21362190
    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)));
    2154                 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
    2155                 return;
    2156         }
     2191                status = file_set_sparse(fsp->conn, fsp, set_sparse);
     2192
     2193                DEBUG(NT_STATUS_IS_OK(status) ? 10 : 9,
     2194                      ("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
     2195                       smb_fname_str_dbg(fsp->fsp_name), set_sparse,
     2196                       nt_errstr(status)));
     2197
     2198                return status;
     2199        }
     2200
    21572201        case FSCTL_CREATE_OR_GET_OBJECT_ID:
    21582202        {
    21592203                unsigned char objid[16];
     2204                char *return_data = NULL;
    21602205
    21612206                /* This should return the object-id on this file.
     
    21632208                 */
    21642209
    2165                 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
    2166 
    2167                 if (!check_fsp_open(conn, req, fsp)) {
    2168                         return;
    2169                 }
    2170 
    2171                 data_count = 64;
    2172                 pdata = nttrans_realloc(ppdata, data_count);
    2173                 if (pdata == NULL) {
    2174                         reply_nterror(req, NT_STATUS_NO_MEMORY);
    2175                         return;
     2210                DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fsp->fnum));
     2211
     2212                *out_len = (max_out_len >= 64) ? 64 : max_out_len;
     2213                /* Hmmm, will this cause problems if less data asked for? */
     2214                return_data = talloc_array(ctx, char, 64);
     2215                if (return_data == NULL) {
     2216                        return NT_STATUS_NO_MEMORY;
    21762217                }
    21772218
    21782219                /* For backwards compatibility only store the dev/inode. */
    2179                 push_file_id_16(pdata, &fsp->file_id);
    2180                 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
    2181                 push_file_id_16(pdata+32, &fsp->file_id);
    2182                 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
    2183                                 pdata, data_count);
    2184                 return;
     2220                push_file_id_16(return_data, &fsp->file_id);
     2221                memcpy(return_data+16,create_volume_objectid(fsp->conn,objid),16);
     2222                push_file_id_16(return_data+32, &fsp->file_id);
     2223                *out_data = return_data;
     2224                return NT_STATUS_OK;
    21852225        }
    21862226
    21872227        case FSCTL_GET_REPARSE_POINT:
    2188                 /* pretend this fail - my winXP does it like this
    2189                  * --metze
    2190                  */
    2191 
    2192                 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
    2193                 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
    2194                 return;
     2228        {
     2229                /* Fail it with STATUS_NOT_A_REPARSE_POINT */
     2230                DEBUG(10, ("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp->fnum));
     2231                return NT_STATUS_NOT_A_REPARSE_POINT;
     2232        }
    21952233
    21962234        case FSCTL_SET_REPARSE_POINT:
    2197                 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
    2198                  * --metze
    2199                  */
    2200 
    2201                 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
    2202                 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
    2203                 return;
    2204 
    2205         case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
     2235        {
     2236                /* Fail it with STATUS_NOT_A_REPARSE_POINT */
     2237                DEBUG(10, ("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp->fnum));
     2238                return NT_STATUS_NOT_A_REPARSE_POINT;
     2239        }
     2240
     2241        case FSCTL_GET_SHADOW_COPY_DATA:
    22062242        {
    22072243                /*
     
    22192255                uint32 labels_data_count = 0;
    22202256                uint32 i;
    2221                 char *cur_pdata;
    2222 
    2223                 if (!check_fsp_open(conn, req, fsp)) {
    2224                         return;
    2225                 }
    2226 
    2227                 if (max_data_count < 16) {
     2257                char *cur_pdata = NULL;
     2258
     2259                if (max_out_len < 16) {
    22282260                        DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
    2229                                 max_data_count));
    2230                         reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    2231                         return;
    2232                 }
    2233 
    2234                 if (max_data_count > 16) {
     2261                                max_out_len));
     2262                        return NT_STATUS_INVALID_PARAMETER;
     2263                }
     2264
     2265                if (max_out_len > 16) {
    22352266                        labels = True;
    22362267                }
    22372268
    2238                 shadow_data = TALLOC_ZERO_P(talloc_tos(),
    2239                                             struct shadow_copy_data);
     2269                shadow_data = talloc_zero(ctx, struct shadow_copy_data);
    22402270                if (shadow_data == NULL) {
    22412271                        DEBUG(0,("TALLOC_ZERO() failed!\n"));
    2242                         reply_nterror(req, NT_STATUS_NO_MEMORY);
    2243                         return;
     2272                        return NT_STATUS_NO_MEMORY;
    22442273                }
    22452274
     
    22512280                        if (errno == ENOSYS) {
    22522281                                DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
    2253                                         conn->connectpath));
    2254                                 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
    2255                                 return;
     2282                                        fsp->conn->connectpath));
     2283                                return NT_STATUS_NOT_SUPPORTED;
    22562284                        } else {
    22572285                                DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
    2258                                         conn->connectpath));
    2259                                 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
    2260                                 return;
     2286                                        fsp->conn->connectpath));
     2287                                return NT_STATUS_UNSUCCESSFUL;
    22612288                        }
    22622289                }
    22632290
    2264                 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
     2291                labels_data_count = (shadow_data->num_volumes * 2 *
     2292                                        sizeof(SHADOW_COPY_LABEL)) + 2;
    22652293
    22662294                if (!labels) {
    2267                         data_count = 16;
     2295                        *out_len = 16;
    22682296                } else {
    2269                         data_count = 12+labels_data_count+4;
    2270                 }
    2271 
    2272                 if (max_data_count<data_count) {
     2297                        *out_len = 12 + labels_data_count + 4;
     2298                }
     2299
     2300                if (max_out_len < *out_len) {
    22732301                        DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
    2274                                 max_data_count,data_count));
     2302                                max_out_len, *out_len));
    22752303                        TALLOC_FREE(shadow_data);
    2276                         reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
    2277                         return;
    2278                 }
    2279 
    2280                 pdata = nttrans_realloc(ppdata, data_count);
    2281                 if (pdata == NULL) {
     2304                        return NT_STATUS_BUFFER_TOO_SMALL;
     2305                }
     2306
     2307                cur_pdata = talloc_array(ctx, char, *out_len);
     2308                if (cur_pdata == NULL) {
    22822309                        TALLOC_FREE(shadow_data);
    2283                         reply_nterror(req, NT_STATUS_NO_MEMORY);
    2284                         return;
    2285                 }
    2286 
    2287                 cur_pdata = pdata;
     2310                        return NT_STATUS_NO_MEMORY;
     2311                }
     2312
     2313                *out_data = cur_pdata;
    22882314
    22892315                /* num_volumes 4 bytes */
    2290                 SIVAL(pdata,0,shadow_data->num_volumes);
     2316                SIVAL(cur_pdata, 0, shadow_data->num_volumes);
    22912317
    22922318                if (labels) {
    22932319                        /* num_labels 4 bytes */
    2294                         SIVAL(pdata,4,shadow_data->num_volumes);
     2320                        SIVAL(cur_pdata, 4, shadow_data->num_volumes);
    22952321                }
    22962322
    22972323                /* needed_data_count 4 bytes */
    2298                 SIVAL(pdata, 8, labels_data_count+4);
    2299 
    2300                 cur_pdata+=12;
     2324                SIVAL(cur_pdata, 8, labels_data_count + 4);
     2325
     2326                cur_pdata += 12;
    23012327
    23022328                DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
    23032329                          shadow_data->num_volumes, fsp_str_dbg(fsp)));
    23042330                if (labels && shadow_data->labels) {
    2305                         for (i=0;i<shadow_data->num_volumes;i++) {
    2306                                 srvstr_push(pdata, req->flags2,
     2331                        for (i=0; i<shadow_data->num_volumes; i++) {
     2332                                srvstr_push(cur_pdata, req_flags,
    23072333                                            cur_pdata, shadow_data->labels[i],
    2308                                             2*sizeof(SHADOW_COPY_LABEL),
     2334                                            2 * sizeof(SHADOW_COPY_LABEL),
    23092335                                            STR_UNICODE|STR_TERMINATE);
    2310                                 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
     2336                                cur_pdata += 2 * sizeof(SHADOW_COPY_LABEL);
    23112337                                DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
    23122338                        }
     
    23152341                TALLOC_FREE(shadow_data);
    23162342
    2317                 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
    2318                                 pdata, data_count);
    2319 
    2320                 return;
    2321         }
    2322 
    2323         case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
     2343                return NT_STATUS_OK;
     2344        }
     2345
     2346        case FSCTL_FIND_FILES_BY_SID:
    23242347        {
    23252348                /* pretend this succeeded -
     
    23332356                size_t sid_len;
    23342357
    2335                 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
    2336 
    2337                 if (!check_fsp_open(conn, req, fsp)) {
    2338                         return;
    2339                 }
    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);
     2358                DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n", fsp->fnum));
     2359
     2360                if (in_len < 8) {
     2361                        /* NT_STATUS_BUFFER_TOO_SMALL maybe? */
     2362                        return NT_STATUS_INVALID_PARAMETER;
     2363                }
     2364
     2365                sid_len = MIN(in_len - 4,SID_MAX_SIZE);
    23472366
    23482367                /* unknown 4 bytes: this is not the length of the sid :-(  */
    23492368                /*unknown = IVAL(pdata,0);*/
    23502369
    2351                 if (!sid_parse(pdata+4,sid_len,&sid)) {
    2352                         reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    2353                         return;
     2370                if (!sid_parse(in_data + 4, sid_len, &sid)) {
     2371                        return NT_STATUS_INVALID_PARAMETER;
    23542372                }
    23552373                DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
     
    23732391                 * (maybe we can hang the result anywhere in the fsp struct)
    23742392                 *
     2393                 * but I don't know how to deal with the paged results
     2394                 * (maybe we can hang the result anywhere in the fsp struct)
     2395                 *
    23752396                 * we don't send all files at once
    23762397                 * and at the next we should *not* start from the beginning,
     
    23812402
    23822403                /* this works for now... */
    2383                 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
    2384                 return;
    2385         }
     2404                return NT_STATUS_OK;
     2405        }
     2406
    23862407        case FSCTL_QUERY_ALLOCATED_RANGES:
    23872408        {
     
    23942415                NTSTATUS status;
    23952416                uint64_t offset, length;
    2396 
    2397                 if (!check_fsp_open(conn, req, fsp)) {
    2398                         return;
    2399                 }
    2400 
    2401                 if (data_count != 16) {
     2417                char *out_data_tmp = NULL;
     2418
     2419                if (in_len != 16) {
    24022420                        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);
     2421                                in_len));
     2422                        return NT_STATUS_INVALID_PARAMETER;
     2423                }
     2424
     2425                if (max_out_len < 16) {
     2426                        DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_out_len (%u) < 16 is invalid!\n",
     2427                                max_out_len));
     2428                        return NT_STATUS_INVALID_PARAMETER;
     2429                }
     2430
     2431                offset = BVAL(in_data,0);
     2432                length = BVAL(in_data,8);
    24172433
    24182434                if (offset + length < offset) {
    24192435                        /* No 64-bit integer wrap. */
    2420                         reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    2421                         return;
    2422                 }
    2423 
     2436                        return NT_STATUS_INVALID_PARAMETER;
     2437                }
     2438
     2439                /* Shouldn't this be SMB_VFS_STAT ... ? */
    24242440                status = vfs_stat_fsp(fsp);
    24252441                if (!NT_STATUS_IS_OK(status)) {
    2426                         reply_nterror(req, status);
    2427                         return;
     2442                        return status;
     2443                }
     2444
     2445                *out_len = 16;
     2446                out_data_tmp = talloc_array(ctx, char, *out_len);
     2447                if (out_data_tmp == NULL) {
     2448                        DEBUG(10, ("unable to allocate memory for response\n"));
     2449                        return NT_STATUS_NO_MEMORY;
    24282450                }
    24292451
     
    24312453                                fsp->fsp_name->st.st_ex_size == 0 ||
    24322454                                length == 0) {
    2433                         send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
     2455                        memset(out_data_tmp, 0, *out_len);
    24342456                } else {
    24352457                        uint64_t end = offset + length;
    24362458                        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         }
     2459                        SBVAL(out_data_tmp, 0, 0);
     2460                        SBVAL(out_data_tmp, 8, end);
     2461                }
     2462
     2463                *out_data = out_data_tmp;
     2464
     2465                return NT_STATUS_OK;
     2466        }
     2467
    24442468        case FSCTL_IS_VOLUME_DIRTY:
     2469        {
    24452470                DEBUG(10,("FSCTL_IS_VOLUME_DIRTY: called on FID[0x%04X] "
    2446                           "(but not implemented)\n", (int)fidnum));
     2471                          "(but not implemented)\n", fsp->fnum));
    24472472                /*
    24482473                 * http://msdn.microsoft.com/en-us/library/cc232128%28PROT.10%29.aspx
    24492474                 * says we have to respond with NT_STATUS_INVALID_PARAMETER
    24502475                 */
    2451                 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
    2452                 return;
     2476                return NT_STATUS_INVALID_PARAMETER;
     2477        }
     2478
    24532479        default:
    2454                 /* Only print this once... */
    2455                 if (!logged_ioctl_message) {
    2456                         logged_ioctl_message = true;
    2457                         DEBUG(2,("call_nt_transact_ioctl(0x%x): "
    2458                                  "Currently not implemented.\n",
    2459                                  function));
    2460                 }
    2461         }
    2462 
    2463         reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
     2480                /*
     2481                 * Only print once ... unfortunately there could be lots of
     2482                 * different FSCTLs that are called.
     2483                 */
     2484                if (!vfswrap_logged_ioctl_message) {
     2485                        vfswrap_logged_ioctl_message = true;
     2486                        DEBUG(2, ("%s (0x%x): Currently not implemented.\n",
     2487                        __FUNCTION__, function));
     2488                }
     2489        }
     2490
     2491        return NT_STATUS_NOT_SUPPORTED;
     2492}
     2493
     2494/****************************************************************************
     2495 Reply to NT IOCTL
     2496****************************************************************************/
     2497
     2498static void call_nt_transact_ioctl(connection_struct *conn,
     2499                                   struct smb_request *req,
     2500                                   uint16 **ppsetup, uint32 setup_count,
     2501                                   char **ppparams, uint32 parameter_count,
     2502                                   char **ppdata, uint32 data_count,
     2503                                   uint32 max_data_count)
     2504{
     2505        NTSTATUS status;
     2506        uint32 function;
     2507        uint16 fidnum;
     2508        files_struct *fsp;
     2509        uint8 isFSctl;
     2510        uint8 compfilter;
     2511        char *out_data = NULL;
     2512        uint32 out_data_len = 0;
     2513        char *pdata = *ppdata;
     2514        TALLOC_CTX *ctx = talloc_tos();
     2515
     2516        if (setup_count != 8) {
     2517                DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
     2518                reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
     2519                return;
     2520        }
     2521
     2522        function = IVAL(*ppsetup, 0);
     2523        fidnum = SVAL(*ppsetup, 4);
     2524        isFSctl = CVAL(*ppsetup, 6);
     2525        compfilter = CVAL(*ppsetup, 7);
     2526
     2527        DEBUG(10, ("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
     2528                 function, fidnum, isFSctl, compfilter));
     2529
     2530        fsp=file_fsp(req, fidnum);
     2531
     2532        /*
     2533         * We don't really implement IOCTLs, especially on files.
     2534         */
     2535        if (!isFSctl) {
     2536                DEBUG(10, ("isFSctl: 0x%02X indicates IOCTL, not FSCTL!\n",
     2537                        isFSctl));
     2538                reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
     2539                return;
     2540        }
     2541
     2542        /* Has to be for an open file! */
     2543        if (!check_fsp_open(conn, req, fsp)) {
     2544                return;
     2545        }
     2546
     2547        /*
     2548         * out_data might be allocated by the VFS module, but talloc should be
     2549         * used, and should be cleaned up when the request ends.
     2550         */
     2551        status = smb_fsctl(fsp,
     2552                               ctx,
     2553                               function,
     2554                               req->flags2,
     2555                               (uint8_t *)pdata,
     2556                               data_count,
     2557                               (uint8_t **)&out_data,
     2558                               max_data_count,
     2559                               &out_data_len);
     2560        if (!NT_STATUS_IS_OK(status)) {
     2561                reply_nterror(req, status);
     2562        } else {
     2563                send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, out_data, out_data_len);
     2564        }
    24642565}
    24652566
     
    31973298        show_msg((char *)req->inbuf);
    31983299
     3300        /* Windows clients expect all replies to
     3301           an NT transact secondary (SMBnttranss 0xA1)
     3302           to have a command code of NT transact
     3303           (SMBnttrans 0xA0). See bug #8989 for details. */
     3304        req->cmd = SMBnttrans;
     3305
    31993306        if (req->wct < 18) {
    32003307                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
Note: See TracChangeset for help on using the changeset viewer.