The branch, master has been updated
       via  334d5bf... s3: Convert cli_get_ea_list_path to cli_qpathinfo_send
       via  5380f67... s3: Factor out parse_ea_blob
       via  d5e285a... s3: Convert cli_posix_stat to cli_qpathinfo_send
       via  786e4cd... s3: Convert cli_posix_getfacl to cli_qpathinfo_send
       via  cb9baa7... s3: Convert cli_posix_readlink to cli_qpathinfo_send
       via  535774d... s3: Add async cli_qpathinfo
       via  ce3dfd7... s3: cli_qpathinfo->cli_qpathinfo1
      from  b04eba1... s3: Fix cli_posix_stat

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 334d5bfe30188a42af758db3f6a3551dd074900a
Author: Volker Lendecke <[email protected]>
Date:   Sun Jul 25 21:32:13 2010 +0200

    s3: Convert cli_get_ea_list_path to cli_qpathinfo_send

commit 5380f67730154d872ad21a3d9908cfc2bb91edbd
Author: Volker Lendecke <[email protected]>
Date:   Sun Jul 25 19:42:22 2010 +0200

    s3: Factor out parse_ea_blob

commit d5e285abae34339f6eabc54a17049dcc5b56a6b0
Author: Volker Lendecke <[email protected]>
Date:   Sun Jul 25 17:49:20 2010 +0200

    s3: Convert cli_posix_stat to cli_qpathinfo_send

commit 786e4cd0980f0562b28ac74612a72faa4e2050cc
Author: Volker Lendecke <[email protected]>
Date:   Sun Jul 25 17:46:01 2010 +0200

    s3: Convert cli_posix_getfacl to cli_qpathinfo_send

commit cb9baa7c2c6edafd835bc6e36a385b0d00f5277e
Author: Volker Lendecke <[email protected]>
Date:   Sun Jul 25 17:37:16 2010 +0200

    s3: Convert cli_posix_readlink to cli_qpathinfo_send

commit 535774d88068052accedb21b626fd97a79502c0e
Author: Volker Lendecke <[email protected]>
Date:   Sun Jul 25 17:26:43 2010 +0200

    s3: Add async cli_qpathinfo

commit ce3dfd777f8f2da4cb08f6c91a465e647b84a8f1
Author: Volker Lendecke <[email protected]>
Date:   Sun Jul 25 13:19:34 2010 +0200

    s3: cli_qpathinfo->cli_qpathinfo1

-----------------------------------------------------------------------

Summary of changes:
 source3/include/proto.h   |   21 ++-
 source3/libsmb/clifile.c  |  566 +++++++++++++++++++++++++++------------------
 source3/libsmb/clirap.c   |    2 +-
 source3/torture/nbio.c    |    2 +-
 source3/torture/torture.c |   19 +-
 5 files changed, 376 insertions(+), 234 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 75e4aaf..3759a78 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2466,7 +2466,13 @@ NTSTATUS cli_ctemp(struct cli_state *cli,
 NTSTATUS cli_raw_ioctl(struct cli_state *cli, uint16_t fnum, uint32_t code, 
DATA_BLOB *blob);
 bool cli_set_ea_path(struct cli_state *cli, const char *path, const char 
*ea_name, const char *ea_val, size_t ea_len);
 bool cli_set_ea_fnum(struct cli_state *cli, uint16_t fnum, const char 
*ea_name, const char *ea_val, size_t ea_len);
-bool cli_get_ea_list_path(struct cli_state *cli, const char *path,
+struct tevent_req *cli_get_ea_list_path_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct cli_state *cli,
+                                            const char *fname);
+NTSTATUS cli_get_ea_list_path_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                  size_t *pnum_eas, struct ea_struct **peas);
+NTSTATUS cli_get_ea_list_path(struct cli_state *cli, const char *path,
                TALLOC_CTX *ctx,
                size_t *pnum_eas,
                struct ea_struct **pea_list);
@@ -2636,7 +2642,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char 
*workgroup, uint32 stype,
                       void *state);
 bool cli_oem_change_password(struct cli_state *cli, const char *user, const 
char *new_password,
                              const char *old_password);
-bool cli_qpathinfo(struct cli_state *cli,
+bool cli_qpathinfo1(struct cli_state *cli,
                        const char *fname,
                        time_t *change_time,
                        time_t *access_time,
@@ -2672,6 +2678,17 @@ NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, 
const char *name,
                             SMB_STRUCT_STAT *sbuf, uint32 *attributes);
 bool cli_qfileinfo_test(struct cli_state *cli, uint16_t fnum, int level, char 
**poutdata, uint32 *poutlen);
 NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, 
fstring alt_name);
+struct tevent_req *cli_qpathinfo_send(TALLOC_CTX *mem_ctx,
+                                     struct tevent_context *ev,
+                                     struct cli_state *cli, const char *fname,
+                                     uint16_t level, uint32_t min_rdata,
+                                     uint32_t max_rdata);
+NTSTATUS cli_qpathinfo_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                           uint8_t **rdata, uint32_t *num_rdata);
+NTSTATUS cli_qpathinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli,
+                      const char *fname, uint16_t level, uint32_t min_rdata,
+                      uint32_t max_rdata,
+                      uint8_t **rdata, uint32_t *num_rdata);
 
 /* The following definitions come from libsmb/clirap2.c  */
 struct rap_group_info_1;
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index de2d185..3198123 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -273,30 +273,7 @@ struct readlink_state {
        uint32_t num_data;
 };
 
-static void cli_posix_readlink_done(struct tevent_req *subreq)
-{
-       struct tevent_req *req = tevent_req_callback_data(
-                               subreq, struct tevent_req);
-       struct readlink_state *state = tevent_req_data(req, struct 
readlink_state);
-       NTSTATUS status;
-
-       status = cli_trans_recv(subreq, state, NULL, 0, NULL, NULL, 0, NULL,
-                               &state->data, 0, &state->num_data);
-       TALLOC_FREE(subreq);
-       if (!NT_STATUS_IS_OK(status)) {
-               tevent_req_nterror(req, status);
-               return;
-       }
-       if (state->num_data == 0) {
-               tevent_req_nterror(req, NT_STATUS_DATA_ERROR);
-               return;
-       }
-       if (state->data[state->num_data-1] != '\0') {
-               tevent_req_nterror(req, NT_STATUS_DATA_ERROR);
-               return;
-       }
-       tevent_req_done(req);
-}
+static void cli_posix_readlink_done(struct tevent_req *subreq);
 
 struct tevent_req *cli_posix_readlink_send(TALLOC_CTX *mem_ctx,
                                        struct event_context *ev,
@@ -308,51 +285,21 @@ struct tevent_req *cli_posix_readlink_send(TALLOC_CTX 
*mem_ctx,
        struct readlink_state *state = NULL;
        uint32_t maxbytelen = (uint32_t)(cli_ucs2(cli) ? len*3 : len);
 
-       if (maxbytelen < len) {
-               return NULL;
-       }
-
        req = tevent_req_create(mem_ctx, &state, struct readlink_state);
        if (req == NULL) {
                return NULL;
        }
 
-       /* Setup setup word. */
-       SSVAL(&state->setup, 0, TRANSACT2_QPATHINFO);
-
-       /* Setup param array. */
-       state->param = talloc_array(state, uint8_t, 6);
-       if (tevent_req_nomem(state->param, req)) {
-               return tevent_req_post(req, ev);
-       }
-       memset(state->param, '\0', 6);
-       SSVAL(state->param,0,SMB_QUERY_FILE_UNIX_LINK);
-
-       state->param = trans2_bytes_push_str(state->param, cli_ucs2(cli), fname,
-                                  strlen(fname)+1, NULL);
-
-       if (tevent_req_nomem(state->param, req)) {
+       /*
+        * Len is in bytes, we need it in UCS2 units.
+        */
+       if ((2*len < len) || (maxbytelen < len)) {
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return tevent_req_post(req, ev);
        }
 
-       subreq = cli_trans_send(state,                  /* mem ctx. */
-                               ev,                     /* event ctx. */
-                               cli,                    /* cli_state. */
-                               SMBtrans2,              /* cmd. */
-                               NULL,                   /* pipe name. */
-                               -1,                     /* fid. */
-                               0,                      /* function. */
-                               0,                      /* flags. */
-                               &state->setup,          /* setup. */
-                               1,                      /* num setup uint16_t 
words. */
-                               0,                      /* max returned setup. 
*/
-                               state->param,           /* param. */
-                               talloc_get_size(state->param),  /* num param. */
-                               2,                      /* max returned param. 
*/
-                               NULL,                   /* data. */
-                               0,                      /* num data. */
-                               maxbytelen);            /* max returned data. */
-
+       subreq = cli_qpathinfo_send(state, ev, cli, fname,
+                                   SMB_QUERY_FILE_UNIX_LINK, 1, maxbytelen);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -360,6 +307,31 @@ struct tevent_req *cli_posix_readlink_send(TALLOC_CTX 
*mem_ctx,
        return req;
 }
 
+static void cli_posix_readlink_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct readlink_state *state = tevent_req_data(
+               req, struct readlink_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       /*
+        * num_data is > 1, we've given 1 as minimum to cli_qpathinfo_send
+        */
+       if (state->data[state->num_data-1] != '\0') {
+               tevent_req_nterror(req, NT_STATUS_DATA_ERROR);
+               return;
+       }
+       tevent_req_done(req);
+}
+
 NTSTATUS cli_posix_readlink_recv(struct tevent_req *req, struct cli_state *cli,
                                char *retpath, size_t len)
 {
@@ -413,12 +385,6 @@ NTSTATUS cli_posix_readlink(struct cli_state *cli, const 
char *fname,
                goto fail;
        }
 
-       /* Len is in bytes, we need it in UCS2 units. */
-       if (2*len < len) {
-               status = NT_STATUS_INVALID_PARAMETER;
-               goto fail;
-       }
-
        req = cli_posix_readlink_send(frame,
                                ev,
                                cli,
@@ -621,22 +587,7 @@ struct getfacl_state {
        uint8_t *data;
 };
 
-static void cli_posix_getfacl_done(struct tevent_req *subreq)
-{
-       struct tevent_req *req = tevent_req_callback_data(
-                               subreq, struct tevent_req);
-       struct getfacl_state *state = tevent_req_data(req, struct 
getfacl_state);
-       NTSTATUS status;
-
-       status = cli_trans_recv(subreq, state, NULL, 0, NULL, NULL, 0, NULL,
-                               &state->data, 0, &state->num_data);
-       TALLOC_FREE(subreq);
-       if (!NT_STATUS_IS_OK(status)) {
-               tevent_req_nterror(req, status);
-               return;
-       }
-       tevent_req_done(req);
-}
+static void cli_posix_getfacl_done(struct tevent_req *subreq);
 
 struct tevent_req *cli_posix_getfacl_send(TALLOC_CTX *mem_ctx,
                                        struct event_context *ev,
@@ -650,43 +601,8 @@ struct tevent_req *cli_posix_getfacl_send(TALLOC_CTX 
*mem_ctx,
        if (req == NULL) {
                return NULL;
        }
-
-       /* Setup setup word. */
-       SSVAL(&state->setup, 0, TRANSACT2_QPATHINFO);
-
-       /* Setup param array. */
-       state->param = talloc_array(state, uint8_t, 6);
-       if (tevent_req_nomem(state->param, req)) {
-               return tevent_req_post(req, ev);
-       }
-       memset(state->param, '\0', 6);
-       SSVAL(state->param, 0, SMB_QUERY_POSIX_ACL);
-
-       state->param = trans2_bytes_push_str(state->param, cli_ucs2(cli), fname,
-                                  strlen(fname)+1, NULL);
-
-       if (tevent_req_nomem(state->param, req)) {
-               return tevent_req_post(req, ev);
-       }
-
-       subreq = cli_trans_send(state,                  /* mem ctx. */
-                               ev,                     /* event ctx. */
-                               cli,                    /* cli_state. */
-                               SMBtrans2,              /* cmd. */
-                               NULL,                   /* pipe name. */
-                               -1,                     /* fid. */
-                               0,                      /* function. */
-                               0,                      /* flags. */
-                               &state->setup,          /* setup. */
-                               1,                      /* num setup uint16_t 
words. */
-                               0,                      /* max returned setup. 
*/
-                               state->param,           /* param. */
-                               talloc_get_size(state->param),  /* num param. */
-                               2,                      /* max returned param. 
*/
-                               NULL,                   /* data. */
-                               0,                      /* num data. */
-                               cli->max_xmit);         /* max returned data. */
-
+       subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_QUERY_POSIX_ACL,
+                                   0, cli->max_xmit);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -694,6 +610,24 @@ struct tevent_req *cli_posix_getfacl_send(TALLOC_CTX 
*mem_ctx,
        return req;
 }
 
+static void cli_posix_getfacl_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct getfacl_state *state = tevent_req_data(
+               req, struct getfacl_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
+
 NTSTATUS cli_posix_getfacl_recv(struct tevent_req *req,
                                TALLOC_CTX *mem_ctx,
                                size_t *prb_size,
@@ -770,22 +704,7 @@ struct stat_state {
        uint8_t *data;
 };
 
-static void cli_posix_stat_done(struct tevent_req *subreq)
-{
-       struct tevent_req *req = tevent_req_callback_data(
-                               subreq, struct tevent_req);
-       struct stat_state *state = tevent_req_data(req, struct stat_state);
-       NTSTATUS status;
-
-       status = cli_trans_recv(subreq, state, NULL, 0, NULL, NULL, 0, NULL,
-                               &state->data, 100, &state->num_data);
-       TALLOC_FREE(subreq);
-       if (!NT_STATUS_IS_OK(status)) {
-               tevent_req_nterror(req, status);
-               return;
-       }
-       tevent_req_done(req);
-}
+static void cli_posix_stat_done(struct tevent_req *subreq);
 
 struct tevent_req *cli_posix_stat_send(TALLOC_CTX *mem_ctx,
                                        struct event_context *ev,
@@ -799,43 +718,8 @@ struct tevent_req *cli_posix_stat_send(TALLOC_CTX *mem_ctx,
        if (req == NULL) {
                return NULL;
        }
-
-       /* Setup setup word. */
-       SSVAL(&state->setup, 0, TRANSACT2_QPATHINFO);
-
-       /* Setup param array. */
-       state->param = talloc_array(state, uint8_t, 6);
-       if (tevent_req_nomem(state->param, req)) {
-               return tevent_req_post(req, ev);
-       }
-       memset(state->param, '\0', 6);
-       SSVAL(state->param, 0, SMB_QUERY_FILE_UNIX_BASIC);
-
-       state->param = trans2_bytes_push_str(state->param, cli_ucs2(cli), fname,
-                                  strlen(fname)+1, NULL);
-
-       if (tevent_req_nomem(state->param, req)) {
-               return tevent_req_post(req, ev);
-       }
-
-       subreq = cli_trans_send(state,                  /* mem ctx. */
-                               ev,                     /* event ctx. */
-                               cli,                    /* cli_state. */
-                               SMBtrans2,              /* cmd. */
-                               NULL,                   /* pipe name. */
-                               -1,                     /* fid. */
-                               0,                      /* function. */
-                               0,                      /* flags. */
-                               &state->setup,          /* setup. */
-                               1,                      /* num setup uint16_t 
words. */
-                               0,                      /* max returned setup. 
*/
-                               state->param,           /* param. */
-                               talloc_get_size(state->param),  /* num param. */
-                               2,                      /* max returned param. 
*/
-                               NULL,                   /* data. */
-                               0,                      /* num data. */
-                               100);                   /* max returned data. */
-
+       subreq = cli_qpathinfo_send(state, ev, cli, fname,
+                                   SMB_QUERY_FILE_UNIX_BASIC, 100, 100);
        if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
@@ -843,6 +727,23 @@ struct tevent_req *cli_posix_stat_send(TALLOC_CTX *mem_ctx,
        return req;
 }
 
+static void cli_posix_stat_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                               subreq, struct tevent_req);
+       struct stat_state *state = tevent_req_data(req, struct stat_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
+
 NTSTATUS cli_posix_stat_recv(struct tevent_req *req,
                                SMB_STRUCT_STAT *sbuf)
 {
@@ -853,10 +754,6 @@ NTSTATUS cli_posix_stat_recv(struct tevent_req *req,
                return status;
        }
 
-       if (state->num_data != 100) {
-               return NT_STATUS_DATA_ERROR;
-       }
-
        sbuf->st_ex_size = IVAL2_TO_SMB_BIG_UINT(state->data,0);     /* total 
size, in bytes */
        sbuf->st_ex_blocks = IVAL2_TO_SMB_BIG_UINT(state->data,8);   /* number 
of blocks allocated */
 #if defined (HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
@@ -4291,6 +4188,10 @@ bool cli_set_ea_fnum(struct cli_state *cli, uint16_t 
fnum, const char *ea_name,
  Get an extended attribute list utility fn.
 *********************************************************/
 
+static bool parse_ea_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
+                         size_t rdata_len,
+                         size_t *pnum_eas, struct ea_struct **pea_list);
+
 static bool cli_get_ea_list(struct cli_state *cli,
                uint16_t setup, char *param, unsigned int param_len,
                TALLOC_CTX *ctx,
@@ -4300,11 +4201,7 @@ static bool cli_get_ea_list(struct cli_state *cli,
        unsigned int data_len = 0;
        unsigned int rparam_len, rdata_len;
        char *rparam=NULL, *rdata=NULL;
-       char *p;
-       size_t ea_size;
-       size_t num_eas;
        bool ret = False;
-       struct ea_struct *ea_list;
 
        *pnum_eas = 0;
        if (pea_list) {
@@ -4327,19 +4224,35 @@ static bool cli_get_ea_list(struct cli_state *cli,
                return False;
        }
 
-       if (!rdata || rdata_len < 4) {
-               goto out;
+       ret = parse_ea_blob(ctx, (uint8_t *)rdata, rdata_len, pnum_eas,
+                           pea_list);
+       SAFE_FREE(rparam);
+       SAFE_FREE(rdata);
+       return ret;
+}
+
+static bool parse_ea_blob(TALLOC_CTX *ctx, const uint8_t *rdata,
+                         size_t rdata_len,
+                         size_t *pnum_eas, struct ea_struct **pea_list)
+{
+       struct ea_struct *ea_list = NULL;
+       size_t num_eas;
+       size_t ea_size;
+       const uint8_t *p;
+
+       if (rdata_len < 4) {
+               return false;
        }
 
        ea_size = (size_t)IVAL(rdata,0);
        if (ea_size > rdata_len) {
-               goto out;
+               return false;
        }
 
        if (ea_size == 0) {
                /* No EA's present. */
-               ret = True;
-               goto out;
+               *pnum_eas = 0;
+               return true;
        }
 
        p = rdata + 4;
@@ -4350,30 +4263,29 @@ static bool cli_get_ea_list(struct cli_state *cli,
                unsigned int ea_namelen = CVAL(p,1);
                unsigned int ea_valuelen = SVAL(p,2);
                if (ea_namelen == 0) {
-                       goto out;
+                       return false;
                }
                if (4 + ea_namelen + 1 + ea_valuelen > ea_size) {
-                       goto out;
+                       return false;
                }
                ea_size -= 4 + ea_namelen + 1 + ea_valuelen;
                p += 4 + ea_namelen + 1 + ea_valuelen;
        }
 
        if (num_eas == 0) {
-               ret = True;
-               goto out;
+               *pnum_eas = 0;
+               return true;
        }
 
        *pnum_eas = num_eas;
        if (!pea_list) {
                /* Caller only wants number of EA's. */
-               ret = True;
-               goto out;
+               return true;
        }
 
        ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas);
        if (!ea_list) {
-               goto out;
+               return false;
        }
 
        ea_size = (size_t)IVAL(rdata,0);
@@ -4388,11 +4300,14 @@ static bool cli_get_ea_list(struct cli_state *cli,
                ea->flags = CVAL(p,0);
                unix_ea_name[0] = '\0';
                pull_ascii_fstring(unix_ea_name, p + 4);
-               ea->name = talloc_strdup(ctx, unix_ea_name);
+               ea->name = talloc_strdup(ea_list, unix_ea_name);
+               if (!ea->name) {
+                       goto fail;
+               }
                /* Ensure the value is null terminated (in case it's a string). 
*/
-               ea->value = data_blob_talloc(ctx, NULL, ea_valuelen + 1);
+               ea->value = data_blob_talloc(ea_list, NULL, ea_valuelen + 1);
                if (!ea->value.data) {


-- 
Samba Shared Repository

Reply via email to