samldb: Allow automatic generation of mAPIIDs
[sfrench/samba-autobuild/.git] / source4 / libcli / clireadwrite.c
index 45c99f4f8988634ea5fe918d698b8ed3953712c7..7d8f34a42874ff1fa402c68633cb6439d114b6d4 100644 (file)
@@ -6,7 +6,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,
    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"
+#include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
+#include "libcli/libcli.h"
 
 /****************************************************************************
   Read size bytes at offset offset using SMBreadX.
 ****************************************************************************/
-ssize_t smbcli_read(struct smbcli_tree *tree, int fnum, char *buf, off_t offset, 
+ssize_t smbcli_read(struct smbcli_tree *tree, int fnum, void *_buf, off_t offset, 
                 size_t size)
 {
+       uint8_t *buf = (uint8_t *)_buf;
        union smb_read parms;
        int readsize;
        ssize_t total = 0;
@@ -36,14 +39,13 @@ ssize_t smbcli_read(struct smbcli_tree *tree, int fnum, char *buf, off_t offset,
        }
 
        parms.readx.level = RAW_READ_READX;
-       parms.readx.in.fnum = fnum;
+       parms.readx.in.file.fnum = fnum;
 
        /*
         * Set readsize to the maximum size we can handle in one readX,
         * rounded down to a multiple of 1024.
         */
-       readsize = (tree->session->transport->negotiate.max_xmit - 
-                   (MIN_SMB_SIZE+32)) & ~1023;
+       readsize = (tree->session->transport->negotiate.max_xmit - (MIN_SMB_SIZE+32));
        if (readsize > 0xFFFF) readsize = 0xFFFF;
 
        while (total < size) {
@@ -55,6 +57,7 @@ ssize_t smbcli_read(struct smbcli_tree *tree, int fnum, char *buf, off_t offset,
                parms.readx.in.mincnt    = readsize;
                parms.readx.in.maxcnt    = readsize;
                parms.readx.in.remaining = size - total;
+               parms.readx.in.read_for_execute = false;
                parms.readx.out.data     = buf + total;
                
                status = smb_raw_read(tree, &parms);
@@ -84,10 +87,11 @@ ssize_t smbcli_read(struct smbcli_tree *tree, int fnum, char *buf, off_t offset,
 ****************************************************************************/
 ssize_t smbcli_write(struct smbcli_tree *tree,
                     int fnum, uint16_t write_mode,
-                    const uint8_t *buf, off_t offset, size_t size)
+                    const void *_buf, off_t offset, size_t size)
 {
+       const uint8_t *buf = (const uint8_t *)_buf;
        union smb_write parms;
-       int block = (tree->session->transport->negotiate.max_xmit - (MIN_SMB_SIZE+32)) & ~1023;
+       int block = (tree->session->transport->negotiate.max_xmit - (MIN_SMB_SIZE+32));
        ssize_t total = 0;
 
        if (size == 0) {
@@ -98,11 +102,11 @@ ssize_t smbcli_write(struct smbcli_tree *tree,
 
 
        parms.writex.level = RAW_WRITE_WRITEX;
-       parms.writex.in.fnum = fnum;
+       parms.writex.in.file.fnum = fnum;
        parms.writex.in.wmode = write_mode;
        parms.writex.in.remaining = 0;
-       
-       while (total < size) {
+
+       do {
                NTSTATUS status;
 
                block = MIN(block, size - total);
@@ -120,7 +124,7 @@ ssize_t smbcli_write(struct smbcli_tree *tree,
                offset += parms.writex.out.nwritten;
                total += parms.writex.out.nwritten;
                buf += parms.writex.out.nwritten;
-       }
+       } while (total < size);
 
        return total;
 }
@@ -129,8 +133,9 @@ ssize_t smbcli_write(struct smbcli_tree *tree,
   write to a file using a SMBwrite and not bypassing 0 byte writes
 ****************************************************************************/
 ssize_t smbcli_smbwrite(struct smbcli_tree *tree,
-                    int fnum, char *buf, off_t offset, size_t size1)
+                    int fnum, const void *_buf, off_t offset, size_t size1)
 {
+       const uint8_t *buf = (const uint8_t *)_buf;
        union smb_write parms;
        ssize_t total = 0;
 
@@ -141,7 +146,7 @@ ssize_t smbcli_smbwrite(struct smbcli_tree *tree,
                size_t size = MIN(size1, tree->session->transport->negotiate.max_xmit - 48);
                if (size > 0xFFFF) size = 0xFFFF;
                
-               parms.write.in.fnum = fnum;
+               parms.write.in.file.fnum = fnum;
                parms.write.in.offset = offset;
                parms.write.in.count = size;
                parms.write.in.data = buf + total;