Change uint_t to unsigned int in source4
[garming/samba-autobuild/.git] / source4 / smb_server / smb / trans2.c
index 45ea234d09094af1e1e2a8d79a8d5b042060d647..36dc3175e8d25c56b7fd40c1dbf1836a6d8d4c4c 100644 (file)
 */
 
 #include "includes.h"
-#include "lib/util/dlinklist.h"
 #include "smb_server/smb_server.h"
-#include "librpc/gen_ndr/ndr_misc.h"
 #include "ntvfs/ntvfs.h"
 #include "libcli/raw/libcliraw.h"
+#include "libcli/raw/raw_proto.h"
 
 #define TRANS2_CHECK_ASYNC_STATUS_SIMPLE do { \
        if (!NT_STATUS_IS_OK(req->ntvfs->async_states->status)) { \
@@ -63,7 +62,7 @@ struct trans_op {
 /* setup a trans2 reply, given the data and params sizes */
 static NTSTATUS trans2_setup_reply(struct smb_trans2 *trans,
                                   uint16_t param_size, uint16_t data_size,
-                                  uint16_t setup_count)
+                                  uint8_t setup_count)
 {
        trans->out.setup_count = setup_count;
        if (setup_count > 0) {
@@ -248,7 +247,7 @@ static NTSTATUS trans2_open(struct smbsrv_request *req, struct trans_op *op)
        io->t2open.in.num_eas      = 0;
        io->t2open.in.eas          = NULL;
 
-       smbsrv_blob_pull_string(req, &trans->in.params, 28, &io->t2open.in.fname, 0);
+       smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 28, &io->t2open.in.fname, 0);
        if (io->t2open.in.fname == NULL) {
                return NT_STATUS_FOOBAR;
        }
@@ -296,7 +295,7 @@ static NTSTATUS trans2_mkdir(struct smbsrv_request *req, struct trans_op *op)
        NT_STATUS_HAVE_NO_MEMORY(io);
 
        io->t2mkdir.level = RAW_MKDIR_T2MKDIR;
-       smbsrv_blob_pull_string(req, &trans->in.params, 4, &io->t2mkdir.in.path, 0);
+       smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 4, &io->t2mkdir.in.path, 0);
        if (io->t2mkdir.in.path == NULL) {
                return NT_STATUS_FOOBAR;
        }
@@ -461,7 +460,7 @@ static NTSTATUS trans2_qpathinfo(struct smbsrv_request *req, struct trans_op *op
 
        level = SVAL(trans->in.params.data, 0);
 
-       smbsrv_blob_pull_string(req, &trans->in.params, 6, &st->generic.in.file.path, 0);
+       smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 6, &st->generic.in.file.path, 0);
        if (st->generic.in.file.path == NULL) {
                return NT_STATUS_FOOBAR;
        }
@@ -587,12 +586,20 @@ static NTSTATUS trans2_parse_sfileinfo(struct smbsrv_request *req,
        case RAW_SFILEINFO_UNIX_BASIC:
        case RAW_SFILEINFO_UNIX_LINK:
        case RAW_SFILEINFO_UNIX_HLINK:
-       case RAW_SFILEINFO_1023:
+       case RAW_SFILEINFO_PIPE_INFORMATION:
+       case RAW_SFILEINFO_VALID_DATA_INFORMATION:
+       case RAW_SFILEINFO_SHORT_NAME_INFORMATION:
        case RAW_SFILEINFO_1025:
+       case RAW_SFILEINFO_1027:
        case RAW_SFILEINFO_1029:
+       case RAW_SFILEINFO_1030:
+       case RAW_SFILEINFO_1031:
        case RAW_SFILEINFO_1032:
-       case RAW_SFILEINFO_1039:
-       case RAW_SFILEINFO_1040:
+       case RAW_SFILEINFO_1036:
+       case RAW_SFILEINFO_1041:
+       case RAW_SFILEINFO_1042:
+       case RAW_SFILEINFO_1043:
+       case RAW_SFILEINFO_1044:
                return NT_STATUS_INVALID_LEVEL;
 
        default:
@@ -602,7 +609,7 @@ static NTSTATUS trans2_parse_sfileinfo(struct smbsrv_request *req,
 
        return smbsrv_pull_passthru_sfileinfo(st, passthru_level, st,
                                              blob, SMBSRV_REQ_DEFAULT_STR_FLAGS(req),
-                                             req);
+                                             &req->in.bufinfo);
 }
 
 /*
@@ -661,7 +668,7 @@ static NTSTATUS trans2_setpathinfo(struct smbsrv_request *req, struct trans_op *
 
        level = SVAL(trans->in.params.data, 0);
 
-       smbsrv_blob_pull_string(req, &trans->in.params, 6, &st->generic.in.file.path, 0);
+       smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 6, &st->generic.in.file.path, 0);
        if (st->generic.in.file.path == NULL) {
                return NT_STATUS_FOOBAR;
        }
@@ -699,7 +706,7 @@ static NTSTATUS find_fill_info(struct find_state *state,
        struct smbsrv_request *req = state->op->req;
        struct smb_trans2 *trans = state->op->trans;
        uint8_t *data;
-       uint_t ofs = trans->out.data.length;
+       unsigned int ofs = trans->out.data.length;
        uint32_t ea_size;
 
        switch (state->data_level) {
@@ -783,6 +790,7 @@ static NTSTATUS find_fill_info(struct find_state *state,
                                                   SMBSRV_REQ_DEFAULT_STR_FLAGS(req));
 
        case RAW_SEARCH_DATA_UNIX_INFO:
+       case RAW_SEARCH_DATA_UNIX_INFO2:
                return NT_STATUS_INVALID_LEVEL;
        }
 
@@ -790,11 +798,11 @@ static NTSTATUS find_fill_info(struct find_state *state,
 }
 
 /* callback function for trans2 findfirst/findnext */
-static bool find_callback(void *private, const union smb_search_data *file)
+static bool find_callback(void *private_data, const union smb_search_data *file)
 {
-       struct find_state *state = talloc_get_type(private, struct find_state);
+       struct find_state *state = talloc_get_type(private_data, struct find_state);
        struct smb_trans2 *trans = state->op->trans;
-       uint_t old_length;
+       unsigned int old_length;
 
        old_length = trans->out.data.length;
 
@@ -859,7 +867,7 @@ static NTSTATUS trans2_findfirst(struct smbsrv_request *req, struct trans_op *op
        level                             = SVAL(trans->in.params.data, 6);
        search->t2ffirst.in.storage_type  = IVAL(trans->in.params.data, 8);
 
-       smbsrv_blob_pull_string(req, &trans->in.params, 12, &search->t2ffirst.in.pattern, 0);
+       smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 12, &search->t2ffirst.in.pattern, 0);
        if (search->t2ffirst.in.pattern == NULL) {
                return NT_STATUS_FOOBAR;
        }
@@ -945,7 +953,7 @@ static NTSTATUS trans2_findnext(struct smbsrv_request *req, struct trans_op *op)
        search->t2fnext.in.resume_key    = IVAL(trans->in.params.data, 6);
        search->t2fnext.in.flags         = SVAL(trans->in.params.data, 10);
 
-       smbsrv_blob_pull_string(req, &trans->in.params, 12, &search->t2fnext.in.last_name, 0);
+       smbsrv_blob_pull_string(&req->in.bufinfo, &trans->in.params, 12, &search->t2fnext.in.last_name, 0);
        if (search->t2fnext.in.last_name == NULL) {
                return NT_STATUS_FOOBAR;
        }
@@ -1026,6 +1034,12 @@ static NTSTATUS trans2_backend(struct smbsrv_request *req, struct trans_op *op)
        return NT_STATUS_FOOBAR;
 }
 
+int smbsrv_trans_partial_destructor(struct smbsrv_trans_partial *tp)
+{
+       DLIST_REMOVE(tp->req->smb_conn->trans_partial, tp);
+       return 0;
+}
+
 
 /*
   send a continue request
@@ -1033,6 +1047,7 @@ static NTSTATUS trans2_backend(struct smbsrv_request *req, struct trans_op *op)
 static void reply_trans_continue(struct smbsrv_request *req, uint8_t command,
                                 struct smb_trans2 *trans)
 {
+       struct smbsrv_request *req2;
        struct smbsrv_trans_partial *tp;
        int count;
 
@@ -1045,15 +1060,18 @@ static void reply_trans_continue(struct smbsrv_request *req, uint8_t command,
 
        tp = talloc(req, struct smbsrv_trans_partial);
 
-       tp->req = talloc_reference(tp, req);
-       tp->trans = trans;
+       tp->req = req;
+       tp->u.trans = trans;
        tp->command = command;
 
        DLIST_ADD(req->smb_conn->trans_partial, tp);
+       talloc_set_destructor(tp, smbsrv_trans_partial_destructor);
+
+       req2 = smbsrv_setup_secondary_request(req);
 
        /* send a 'please continue' reply */
-       smbsrv_setup_reply(req, 0, 0);
-       smbsrv_send_reply(req);
+       smbsrv_setup_reply(req2, 0, 0);
+       smbsrv_send_reply(req2);
 }
 
 
@@ -1098,7 +1116,7 @@ static void reply_trans_send(struct ntvfs_request *ntvfs)
           the negotiated buffer size */
        do {
                uint16_t this_data, this_param, max_bytes;
-               uint_t align1 = 1, align2 = (params_left ? 2 : 0);
+               unsigned int align1 = 1, align2 = (params_left ? 2 : 0);
                struct smbsrv_request *this_req;
 
                max_bytes = req_max_data(req) - (align1 + align2);
@@ -1137,7 +1155,8 @@ static void reply_trans_send(struct ntvfs_request *ntvfs)
                      PTR_DIFF(this_req->out.data + this_param, this_req->out.hdr));
                SSVAL(this_req->out.vwv, VWV(8), PTR_DIFF(data, trans->out.data.data));
 
-               SSVAL(this_req->out.vwv, VWV(9), trans->out.setup_count);
+               SCVAL(this_req->out.vwv, VWV(9), trans->out.setup_count);
+               SCVAL(this_req->out.vwv, VWV(9)+1, 0); /* reserved */
                for (i=0;i<trans->out.setup_count;i++) {
                        SSVAL(this_req->out.vwv, VWV(10+i), trans->out.setup[i]);
                }
@@ -1240,11 +1259,11 @@ static void reply_trans_generic(struct smbsrv_request *req, uint8_t command)
        }
 
        if (command == SMBtrans) {
-               req_pull_string(req, &trans->in.trans_name, req->in.data, -1, STR_TERMINATE);
+               req_pull_string(&req->in.bufinfo, &trans->in.trans_name, req->in.data, -1, STR_TERMINATE);
        }
 
-       if (!req_pull_blob(req, req->in.hdr + param_ofs, param_count, &trans->in.params) ||
-           !req_pull_blob(req, req->in.hdr + data_ofs, data_count, &trans->in.data)) {
+       if (!req_pull_blob(&req->in.bufinfo, req->in.hdr + param_ofs, param_count, &trans->in.params) ||
+           !req_pull_blob(&req->in.bufinfo, req->in.hdr + data_ofs, data_count, &trans->in.data)) {
                smbsrv_send_error(req, NT_STATUS_FOOBAR);
                return;
        }
@@ -1271,9 +1290,20 @@ static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
        uint16_t param_disp, data_disp;
        uint16_t param_total, data_total;
        DATA_BLOB params, data;
+       uint8_t wct;
+
+       if (command == SMBtrans2) {
+               wct = 9;
+       } else {
+               wct = 8;
+       }
 
        /* parse request */
-       if (req->in.wct < 8) {
+       if (req->in.wct != wct) {
+               /*
+                * TODO: add some error code tests
+                *       w2k3 returns NT_STATUS_DOS(ERRSRV, ERRerror) here
+                */
                smbsrv_send_error(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
@@ -1291,7 +1321,7 @@ static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
                return;
        }
 
-       trans = tp->trans;
+       trans = tp->u.trans;
 
        param_total           = SVAL(req->in.vwv, VWV(0));
        data_total            = SVAL(req->in.vwv, VWV(1));
@@ -1302,8 +1332,8 @@ static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
        data_ofs              = SVAL(req->in.vwv, VWV(6));
        data_disp             = SVAL(req->in.vwv, VWV(7));
 
-       if (!req_pull_blob(req, req->in.hdr + param_ofs, param_count, &params) ||
-           !req_pull_blob(req, req->in.hdr + data_ofs, data_count, &data)) {
+       if (!req_pull_blob(&req->in.bufinfo, req->in.hdr + param_ofs, param_count, &params) ||
+           !req_pull_blob(&req->in.bufinfo, req->in.hdr + data_ofs, data_count, &data)) {
                smbsrv_send_error(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
@@ -1324,7 +1354,8 @@ static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
                                                         uint8_t, 
                                                         param_disp + param_count);
                if (trans->in.params.data == NULL) {
-                       goto failed;
+                       smbsrv_send_error(tp->req, NT_STATUS_NO_MEMORY);
+                       return;
                }
                trans->in.params.length = param_disp + param_count;
        }
@@ -1335,7 +1366,8 @@ static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
                                                       uint8_t, 
                                                       data_disp + data_count);
                if (trans->in.data.data == NULL) {
-                       goto failed;
+                       smbsrv_send_error(tp->req, NT_STATUS_NO_MEMORY);
+                       return;
                }
                trans->in.data.length = data_disp + data_count;
        }
@@ -1353,16 +1385,11 @@ static void reply_transs_generic(struct smbsrv_request *req, uint8_t command)
        if (trans->in.params.length == param_total &&
            trans->in.data.length == data_total) {
                /* its now complete */
-               DLIST_REMOVE(tp->req->smb_conn->trans_partial, tp);
-               reply_trans_complete(tp->req, command, trans);
+               req = tp->req;
+               talloc_free(tp);
+               reply_trans_complete(req, command, trans);
        }
        return;
-
-failed:        
-       smbsrv_send_error(tp->req, NT_STATUS_NO_MEMORY);
-       DLIST_REMOVE(req->smb_conn->trans_partial, tp);
-       talloc_free(req);
-       talloc_free(tp);
 }