r9476: Make intention to ignore result of receiving excplicit. Fixes warning found...
[bbaumbach/samba-autobuild/.git] / source / libcli / raw / rawsearch.c
index 67410283ed64b92bd52f5700b45e6a7e5171ae5f..65928d11548c15d678fff2a1d2cea3d79798eae8 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "libcli/raw/libcliraw.h"
 
 /****************************************************************************
  Old style search backend - process output.
@@ -32,7 +33,7 @@ static void smb_raw_search_backend(struct smbcli_request *req,
 {
        union smb_search_data search_data;
        int i;
-       char *p;
+       uint8_t *p;
 
        if (req->in.data_size < 3 + count*43) {
                req->status = NT_STATUS_INVALID_PARAMETER;
@@ -42,12 +43,19 @@ static void smb_raw_search_backend(struct smbcli_request *req,
        p = req->in.data + 3;
 
        for (i=0; i < count; i++) {
-               search_data.search.search_id  = smbcli_req_pull_blob(req, mem_ctx, p, 21);
-               search_data.search.attrib     = CVAL(p,            21);
-               search_data.search.write_time = raw_pull_dos_date(req->transport,
-                                                                 p + 22);
-               search_data.search.size       = IVAL(p,            26);
-               smbcli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII);
+               char *name;
+
+               search_data.search.id.reserved      = CVAL(p, 0);
+               memcpy(search_data.search.id.name,    p+1, 11);
+               search_data.search.id.handle        = CVAL(p, 12);
+               search_data.search.id.server_cookie = IVAL(p, 13);
+               search_data.search.id.client_cookie = IVAL(p, 17);
+               search_data.search.attrib           = CVAL(p, 21);
+               search_data.search.write_time       = raw_pull_dos_date(req->transport,
+                                                                       p + 22);
+               search_data.search.size             = IVAL(p, 26);
+               smbcli_req_pull_ascii(req, mem_ctx, &name, p+30, 13, STR_ASCII);
+               search_data.search.name = name;
                if (!callback(private, &search_data)) {
                        break;
                }
@@ -65,8 +73,15 @@ static NTSTATUS smb_raw_search_first_old(struct smbcli_tree *tree,
 
 {
        struct smbcli_request *req; 
-       
-       req = smbcli_request_setup(tree, SMBsearch, 2, 0);
+       uint8_t op = SMBsearch;
+
+       if (io->generic.level == RAW_SEARCH_FFIRST) {
+               op = SMBffirst;
+       } else if (io->generic.level == RAW_SEARCH_FUNIQUE) {
+               op = SMBfunique;
+       }
+
+       req = smbcli_request_setup(tree, op, 2, 0);
        if (!req) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -99,8 +114,14 @@ static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree,
 
 {
        struct smbcli_request *req; 
+       uint8_t var_block[21];
+       uint8_t op = SMBsearch;
+
+       if (io->generic.level == RAW_SEARCH_FFIRST) {
+               op = SMBffirst;
+       }
        
-       req = smbcli_request_setup(tree, SMBsearch, 2, 0);
+       req = smbcli_request_setup(tree, op, 2, 0);
        if (!req) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -108,7 +129,14 @@ static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree,
        SSVAL(req->out.vwv, VWV(0), io->search_next.in.max_count);
        SSVAL(req->out.vwv, VWV(1), io->search_next.in.search_attrib);
        smbcli_req_append_ascii4(req, "", STR_TERMINATE);
-       smbcli_req_append_var_block(req, io->search_next.in.search_id.data, 21);
+
+       SCVAL(var_block,  0, io->search_next.in.id.reserved);
+       memcpy(&var_block[1], io->search_next.in.id.name, 11);
+       SCVAL(var_block, 12, io->search_next.in.id.handle);
+       SIVAL(var_block, 13, io->search_next.in.id.server_cookie);
+       SIVAL(var_block, 17, io->search_next.in.id.client_cookie);
+
+       smbcli_req_append_var_block(req, var_block, 21);
 
        if (!smbcli_request_send(req) ||
            !smbcli_request_receive(req)) {
@@ -123,6 +151,43 @@ static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree,
        return smbcli_request_destroy(req);
 }
 
+
+/****************************************************************************
+ Old style search next.
+****************************************************************************/
+static NTSTATUS smb_raw_search_close_old(struct smbcli_tree *tree,
+                                        union smb_search_close *io)
+{
+       struct smbcli_request *req; 
+       uint8_t var_block[21];
+
+       req = smbcli_request_setup(tree, SMBfclose, 2, 0);
+       if (!req) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       
+       SSVAL(req->out.vwv, VWV(0), io->fclose.in.max_count);
+       SSVAL(req->out.vwv, VWV(1), io->fclose.in.search_attrib);
+       smbcli_req_append_ascii4(req, "", STR_TERMINATE);
+
+       SCVAL(var_block,  0, io->fclose.in.id.reserved);
+       memcpy(&var_block[1], io->fclose.in.id.name, 11);
+       SCVAL(var_block, 12, io->fclose.in.id.handle);
+       SIVAL(var_block, 13, io->fclose.in.id.server_cookie);
+       SIVAL(var_block, 17, io->fclose.in.id.client_cookie);
+
+       smbcli_req_append_var_block(req, var_block, 21);
+
+       if (!smbcli_request_send(req) ||
+           !smbcli_request_receive(req)) {
+               return smbcli_request_destroy(req);
+       }
+
+       return smbcli_request_destroy(req);
+}
+
+
+
 /****************************************************************************
  Very raw search first - returns param/data blobs.
 ****************************************************************************/
@@ -142,9 +207,18 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree,
        tp.in.timeout = 0;
        tp.in.setup_count = 1;
        tp.in.data = data_blob(NULL, 0);
-       tp.in.max_param = 1024;
-       tp.in.max_data = 8192;
+       tp.in.max_param = 10;
+       tp.in.max_data = 0xFFFF;
        tp.in.setup = &setup;
+
+       if (info_level == RAW_SEARCH_EA_LIST) {
+               if (!ea_push_name_list(mem_ctx, 
+                                      &tp.in.data,
+                                      io->t2ffirst.in.num_names,
+                                      io->t2ffirst.in.ea_names)) {
+                       return NT_STATUS_NO_MEMORY;
+               }               
+       }
        
        tp.in.params = data_blob_talloc(mem_ctx, NULL, 12);
        if (!tp.in.params.data) {
@@ -158,7 +232,7 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree,
        SIVAL(tp.in.params.data, 8, io->t2ffirst.in.storage_type);
 
        smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params,
-                              io->t2ffirst.in.pattern, STR_TERMINATE);
+                                 io->t2ffirst.in.pattern, STR_TERMINATE);
 
        status = smb_raw_trans2(tree, mem_ctx, &tp);
        if (!NT_STATUS_IS_OK(status)) {
@@ -194,9 +268,18 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree,
        tp.in.timeout = 0;
        tp.in.setup_count = 1;
        tp.in.data = data_blob(NULL, 0);
-       tp.in.max_param = 1024;
-       tp.in.max_data = 8192;
+       tp.in.max_param = 10;
+       tp.in.max_data = 0xFFFF;
        tp.in.setup = &setup;
+
+       if (info_level == RAW_SEARCH_EA_LIST) {
+               if (!ea_push_name_list(mem_ctx, 
+                                      &tp.in.data,
+                                      io->t2fnext.in.num_names,
+                                      io->t2fnext.in.ea_names)) {
+                       return NT_STATUS_NO_MEMORY;
+               }               
+       }
        
        tp.in.params = data_blob_talloc(mem_ctx, NULL, 12);
        if (!tp.in.params.data) {
@@ -241,10 +324,15 @@ static int parse_trans2_search(struct smbcli_tree *tree,
                               union smb_search_data *data)
 {
        uint_t len, ofs;
+       uint32_t ea_size;
+       DATA_BLOB eablob;
+       NTSTATUS status;
 
        switch (level) {
        case RAW_SEARCH_GENERIC:
        case RAW_SEARCH_SEARCH:
+       case RAW_SEARCH_FFIRST:
+       case RAW_SEARCH_FUNIQUE:
                /* handled elsewhere */
                return -1;
 
@@ -293,6 +381,44 @@ static int parse_trans2_search(struct smbcli_tree *tree,
                                           26, 27, STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN);
                return len + 27 + 1;
 
+       case RAW_SEARCH_EA_LIST:
+               if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) {
+                       if (blob->length < 4) return -1;
+                       data->ea_list.resume_key = IVAL(blob->data, 0);
+                       blob->data += 4;
+                       blob->length -= 4;
+               }
+               if (blob->length < 28) return -1;
+               data->ea_list.create_time = raw_pull_dos_date2(tree->session->transport,
+                                                              blob->data + 0);
+               data->ea_list.access_time = raw_pull_dos_date2(tree->session->transport,
+                                                              blob->data + 4);
+               data->ea_list.write_time  = raw_pull_dos_date2(tree->session->transport,
+                                                              blob->data + 8);
+               data->ea_list.size        = IVAL(blob->data, 12);
+               data->ea_list.alloc_size  = IVAL(blob->data, 16);
+               data->ea_list.attrib      = SVAL(blob->data, 20);
+               ea_size                   = IVAL(blob->data, 22);
+               if (ea_size > 0xFFFF) {
+                       return -1;
+               }
+               eablob.data = blob->data + 22;
+               eablob.length = ea_size;
+               if (eablob.length > blob->length - 24) {
+                       return -1;
+               }
+               status = ea_pull_list(&eablob, mem_ctx, 
+                                     &data->ea_list.eas.num_eas,
+                                     &data->ea_list.eas.eas);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return -1;
+               }
+               len = smbcli_blob_pull_string(tree->session, mem_ctx, blob,
+                                             &data->ea_list.name,
+                                             22+ea_size, 23+ea_size, 
+                                             STR_LEN8BIT | STR_NOALIGN);
+               return len + ea_size + 23 + 1;
+
        case RAW_SEARCH_DIRECTORY_INFO:
                if (blob->length < 65) return -1;
                ofs                                     = IVAL(blob->data,             0);
@@ -499,7 +625,9 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree,
        DATA_BLOB p_blob, d_blob;
        NTSTATUS status;
                        
-       if (io->generic.level == RAW_SEARCH_SEARCH) {
+       if (io->generic.level == RAW_SEARCH_SEARCH ||
+           io->generic.level == RAW_SEARCH_FFIRST ||
+           io->generic.level == RAW_SEARCH_FUNIQUE) {
                return smb_raw_search_first_old(tree, mem_ctx, io, private, callback);
        }
        if (io->generic.level >= RAW_SEARCH_GENERIC) {
@@ -515,7 +643,7 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree,
        
        if (p_blob.length < 10) {
                DEBUG(1,("smb_raw_search_first: parms wrong size %d != expected_param_size\n",
-                       p_blob.length));
+                       (int)p_blob.length));
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -543,7 +671,8 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree,
        DATA_BLOB p_blob, d_blob;
        NTSTATUS status;
 
-       if (io->generic.level == RAW_SEARCH_SEARCH) {
+       if (io->generic.level == RAW_SEARCH_SEARCH ||
+           io->generic.level == RAW_SEARCH_FFIRST) {
                return smb_raw_search_next_old(tree, mem_ctx, io, private, callback);
        }
        if (io->generic.level >= RAW_SEARCH_GENERIC) {
@@ -559,7 +688,7 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree,
        
        if (p_blob.length != 8) {
                DEBUG(1,("smb_raw_search_next: parms wrong size %d != expected_param_size\n",
-                       p_blob.length));
+                       (int)p_blob.length));
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -582,6 +711,10 @@ NTSTATUS smb_raw_search_close(struct smbcli_tree *tree,
                              union smb_search_close *io)
 {
        struct smbcli_request *req;
+
+       if (io->generic.level == RAW_FINDCLOSE_FCLOSE) {
+               return smb_raw_search_close_old(tree, io);
+       }
        
        req = smbcli_request_setup(tree, SMBfindclose, 1, 0);
        if (!req) {
@@ -591,7 +724,7 @@ NTSTATUS smb_raw_search_close(struct smbcli_tree *tree,
        SSVAL(req->out.vwv, VWV(0), io->findclose.in.handle);
 
        if (smbcli_request_send(req)) {
-               smbcli_request_receive(req);
+               (void) smbcli_request_receive(req);
        }
 
        return smbcli_request_destroy(req);