Convert SMB and SMB2 code to use a common buffer handling structure
[kai/samba-autobuild/.git] / source4 / libcli / raw / rawfile.c
index 2873011aa2731b506ceb7fc8e8eca7bb7a5e00f0..d9383401b7af00f2155d652ea445adac5c9599a1 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -264,7 +263,6 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr
        uint16_t fname_len;
        DATA_BLOB sd_blob, ea_blob;
        struct smbcli_request *req;
-       NTSTATUS status;
 
        nt.in.max_setup = 0;
        nt.in.max_param = 101;
@@ -277,10 +275,11 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr
        ea_blob = data_blob(NULL, 0);
 
        if (parms->ntcreatex.in.sec_desc) {
-               status = ndr_push_struct_blob(&sd_blob, mem_ctx, 
-                                             parms->ntcreatex.in.sec_desc, 
-                                             (ndr_push_flags_fn_t)ndr_push_security_descriptor);
-               if (!NT_STATUS_IS_OK(status)) {
+               enum ndr_err_code ndr_err;
+               ndr_err = ndr_push_struct_blob(&sd_blob, mem_ctx, NULL,
+                                              parms->ntcreatex.in.sec_desc,
+                                              (ndr_push_flags_fn_t)ndr_push_security_descriptor);
+               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                        talloc_free(mem_ctx);
                        return NULL;
                }
@@ -427,7 +426,7 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope
 {
        int len;
        struct smbcli_request *req = NULL; 
-       BOOL bigoffset = False;
+       bool bigoffset = false;
 
        switch (parms->generic.level) {
        case RAW_OPEN_T2OPEN:
@@ -528,7 +527,7 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope
                smbcli_req_append_string(req, parms->openxreadx.in.fname, STR_TERMINATE);
 
                if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) {
-                       bigoffset = True;
+                       bigoffset = true;
                }
 
                smbcli_chained_request_setup(req, SMBreadX, bigoffset ? 12 : 10, 0);
@@ -545,6 +544,8 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope
                        SIVAL(req->out.vwv, VWV(10),parms->openxreadx.in.offset>>32);
                }
                break;
+       case RAW_OPEN_SMB2:
+               return NULL;
        }
 
        if (!smbcli_request_send(req)) {
@@ -615,7 +616,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio
        case RAW_OPEN_CTEMP:
                SMBCLI_CHECK_WCT(req, 1);
                parms->ctemp.out.file.fnum = SVAL(req->in.vwv, VWV(0));
-               smbcli_req_pull_string(req, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII);
+               smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII);
                break;
 
        case RAW_OPEN_SPLOPEN:
@@ -674,12 +675,15 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio
                parms->openxreadx.out.nread = SVAL(req->in.vwv, VWV(5));
                if (parms->openxreadx.out.nread > 
                    MAX(parms->openxreadx.in.mincnt, parms->openxreadx.in.maxcnt) ||
-                   !smbcli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), 
+                   !smbcli_raw_pull_data(&req->in.bufinfo, req->in.hdr + SVAL(req->in.vwv, VWV(6)), 
                                          parms->openxreadx.out.nread, 
                                          parms->openxreadx.out.data)) {
                        req->status = NT_STATUS_BUFFER_TOO_SMALL;
                }
                break;
+       case RAW_OPEN_SMB2:
+               req->status = NT_STATUS_INTERNAL_ERROR;
+               break;
        }
 
 failed:
@@ -717,6 +721,9 @@ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_cl
                SSVAL(req->out.vwv, VWV(0), parms->splclose.in.file.fnum);
                SIVAL(req->out.vwv, VWV(1), 0); /* reserved */
                break;
+
+       case RAW_CLOSE_SMB2:
+               return NULL;
        }
 
        if (!req) return NULL;
@@ -793,7 +800,10 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc
                                SIVAL(p, 6, lockp[i].count);
                        }
                }       
+               break;
        }
+       case RAW_LOCK_SMB2:
+               return NULL;
        }
 
        if (!smbcli_request_send(req)) {
@@ -844,14 +854,26 @@ NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms)
 
 /****************************************************************************
  flush a file - async send
- a flush to fnum 0xFFFF will flush all files
+ a flush with RAW_FLUSH_ALL will flush all files
 ****************************************************************************/
 struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_flush *parms)
 {
        struct smbcli_request *req; 
+       uint16_t fnum=0;
+
+       switch (parms->generic.level) {
+       case RAW_FLUSH_FLUSH:
+               fnum = parms->flush.in.file.fnum;
+               break;
+       case RAW_FLUSH_ALL:
+               fnum = 0xFFFF;
+               break;
+       case RAW_FLUSH_SMB2:
+               return NULL;
+       }
 
        SETUP_REQUEST(SMBflush, 1, 0);
-       SSVAL(req->out.vwv, VWV(0), parms->flush.in.file.fnum);
+       SSVAL(req->out.vwv, VWV(0), fnum);
 
        if (!smbcli_request_send(req)) {
                smbcli_request_destroy(req);