pipe opening now works with unicode
authorAndrew Tridgell <tridge@samba.org>
Tue, 20 Feb 2001 10:11:40 +0000 (10:11 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 20 Feb 2001 10:11:40 +0000 (10:11 +0000)
source/include/proto.h
source/libsmb/cliconnect.c
source/libsmb/clilist.c
source/libsmb/clirap.c
source/libsmb/clistr.c
source/libsmb/clitrans.c
source/rpc_client/cli_pipe.c

index 2e3800256d26b45eb32065c47c62c7e4e6f369b4..6efb6f99e4cb103858d362e5c496908ff181ded5 100644 (file)
@@ -859,7 +859,7 @@ int cli_printjob_del(struct cli_state *cli, int job);
 
 /*The following definitions come from  libsmb/clirap.c  */
 
-BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, int pipe_name_len,
+BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, 
                   uint16 *setup, uint32 setup_count, uint32 max_setup_count,
                   char *params, uint32 param_count, uint32 max_param_count,
                   char *data, uint32 data_count, uint32 max_data_count,
@@ -906,7 +906,7 @@ BOOL cli_set_secdesc(struct cli_state *cli,int fd, SEC_DESC *sd);
 /*The following definitions come from  libsmb/clistr.c  */
 
 int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int flags);
-int clistr_push_size(struct cli_state *cli, char *src, int dest_len, int flags);
+int clistr_push_size(struct cli_state *cli, void *dest, char *src, int dest_len, int flags);
 int clistr_pull(struct cli_state *cli, char *dest, void *src, int dest_len, int src_len, int flags);
 int clistr_pull_size(struct cli_state *cli, void *src, int src_len);
 int clistr_align(struct cli_state *cli, int offset);
@@ -914,7 +914,7 @@ int clistr_align(struct cli_state *cli, int offset);
 /*The following definitions come from  libsmb/clitrans.c  */
 
 BOOL cli_send_trans(struct cli_state *cli, int trans, 
-                   char *name, int pipe_name_len
+                   char *pipe_name
                    int fid, int flags,
                    uint16 *setup, int lsetup, int msetup,
                    char *param, int lparam, int mparam,
index 74a10ddf8b5185cc884142548ddfc7a33f1daff0..4f9c5ad61507d2a895381372ecd3f156eb743721 100644 (file)
@@ -123,10 +123,7 @@ BOOL cli_session_setup(struct cli_state *cli,
 
        if (cli->protocol < PROTOCOL_NT1)
        {
-               set_message(cli->outbuf,10,
-                           clistr_align(cli, 1) + 
-                           clistr_push_size(cli, user, -1, CLISTR_TERMINATE|CLISTR_CONVERT) + 
-                           passlen,True);
+               set_message(cli->outbuf,10, 0, True);
                CVAL(cli->outbuf,smb_com) = SMBsesssetupX;
                cli_setup_packet(cli);
 
@@ -137,10 +134,10 @@ BOOL cli_session_setup(struct cli_state *cli,
                SIVAL(cli->outbuf,smb_vwv5,cli->sesskey);
                SSVAL(cli->outbuf,smb_vwv7,passlen);
                p = smb_buf(cli->outbuf);
-               p += clistr_align(cli, PTR_DIFF(p,cli->outbuf));
                memcpy(p,pword,passlen);
                p += passlen;
-               clistr_push(cli, p, user, -1, CLISTR_CONVERT|CLISTR_UPPER|CLISTR_TERMINATE);
+               p += clistr_push(cli, p, user, -1, CLISTR_CONVERT|CLISTR_UPPER|CLISTR_TERMINATE);
+               set_message(cli->outbuf,10,PTR_DIFF(p,smb_buf(cli->outbuf)),False);
        }
        else
        {
@@ -157,7 +154,6 @@ BOOL cli_session_setup(struct cli_state *cli,
                SSVAL(cli->outbuf,smb_vwv8,ntpasslen);
                SSVAL(cli->outbuf,smb_vwv11,CAP_NT_SMBS|(cli->use_level_II_oplocks ? CAP_LEVEL_II_OPLOCKS : 0));
                p = smb_buf(cli->outbuf);
-               p += clistr_align(cli, PTR_DIFF(p,cli->outbuf));
                memcpy(p,pword,passlen); 
                p += SVAL(cli->outbuf,smb_vwv7);
                memcpy(p,ntpword,ntpasslen); 
@@ -188,7 +184,6 @@ BOOL cli_session_setup(struct cli_state *cli,
               * info.
               */
              char *p = smb_buf(cli->inbuf);
-             p += clistr_align(cli, PTR_DIFF(p,cli->outbuf));
              p += clistr_pull(cli, cli->server_os, p, sizeof(fstring), -1, CLISTR_TERMINATE|CLISTR_CONVERT);
              p += clistr_pull(cli, cli->server_type, p, sizeof(fstring), -1, CLISTR_TERMINATE|CLISTR_CONVERT);
              p += clistr_pull(cli, cli->server_domain, p, sizeof(fstring), -1, CLISTR_TERMINATE|CLISTR_CONVERT);
@@ -262,11 +257,7 @@ BOOL cli_send_tconX(struct cli_state *cli,
        unix_to_dos(fullshare, True);
        strupper(fullshare);
 
-       set_message(cli->outbuf,4,
-                   clistr_push_size(cli, fullshare, -1, CLISTR_TERMINATE | CLISTR_CONVERT) +
-                   passlen + 
-                   1+strlen(dev),
-                   True);
+       set_message(cli->outbuf,4, 0, True);
        CVAL(cli->outbuf,smb_com) = SMBtconX;
        cli_setup_packet(cli);
 
index ae1607c1c4b32410872f144a606e5a5aac3a87d7..d4c67fd9e4fb578db9c43be8e4adaad9be5bee54 100644 (file)
@@ -205,7 +205,7 @@ int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
                }
 
                if (!cli_send_trans(cli, SMBtrans2, 
-                                   NULL, 0,                /* Name, length */
+                                   NULL,                   /* Name */
                                    -1, 0,                  /* fid, flags */
                                    &setup, 1, 0,           /* setup, length, max */
                                    param, param_len, 10,   /* param, length, max */
index cd261eac595745b2de59cec57283486d31bc9965..cd0e5ab73fd8aae7cb340a73f0d2f3a8836e2672 100644 (file)
 /****************************************************************************
 Call a remote api on an arbitrary pipe.  takes param, data and setup buffers.
 ****************************************************************************/
-BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, int pipe_name_len,
+BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, 
                   uint16 *setup, uint32 setup_count, uint32 max_setup_count,
                   char *params, uint32 param_count, uint32 max_param_count,
                   char *data, uint32 data_count, uint32 max_data_count,
                   char **rparam, uint32 *rparam_count,
                   char **rdata, uint32 *rdata_count)
 {
-  if (pipe_name_len == 0)
-    pipe_name_len = strlen(pipe_name);
-
   cli_send_trans(cli, SMBtrans, 
-                 pipe_name, pipe_name_len,
+                 pipe_name, 
                  0,0,                         /* fid, flags */
                  setup, setup_count, max_setup_count,
                  params, param_count, max_param_count,
@@ -59,8 +56,8 @@ BOOL cli_api(struct cli_state *cli,
             char **rdata, int *rdrcnt)
 {
   cli_send_trans(cli,SMBtrans,
-                 PIPE_LANMAN,strlen(PIPE_LANMAN), /* Name, length */
-                 0,0,                             /* fid, flags */
+                 PIPE_LANMAN,             /* Name */
+                 0,0,                     /* fid, flags */
                  NULL,0,0,                /* Setup, length, max */
                  param, prcnt, mprcnt,    /* Params, length, max */
                  data, drcnt, mdrcnt      /* Data, length, max */ 
@@ -385,7 +382,7 @@ BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char
   data_len = 532;
     
   if (cli_send_trans(cli,SMBtrans,
-                    PIPE_LANMAN,strlen(PIPE_LANMAN),      /* name, length */
+                    PIPE_LANMAN,                          /* name */
                     0,0,                                  /* fid, flags */
                     NULL,0,0,                             /* setup, length, max */
                     param,param_len,2,                    /* param, length, max */
@@ -437,7 +434,7 @@ BOOL cli_qpathinfo(struct cli_state *cli, const char *fname,
 
        do {
                ret = (cli_send_trans(cli, SMBtrans2, 
-                                     NULL, 0,        /* Name, length */
+                                     NULL,           /* Name */
                                      -1, 0,          /* fid, flags */
                                      &setup, 1, 0,   /* setup, length, max */
                                      param, param_len, 10, /* param, length, max */
@@ -510,7 +507,7 @@ BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname,
     unix_to_dos(&param[6],True);
 
        if (!cli_send_trans(cli, SMBtrans2, 
-                            NULL, 0,                      /* name, length */
+                            NULL,                         /* name */
                             -1, 0,                        /* fid, flags */
                             &setup, 1, 0,                 /* setup, length, max */
                             param, param_len, 10,         /* param, length, max */
@@ -582,7 +579,7 @@ BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
        SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
 
        if (!cli_send_trans(cli, SMBtrans2, 
-                            NULL, 0,                        /* name, length */
+                            NULL,                           /* name */
                             -1, 0,                          /* fid, flags */
                             &setup, 1, 0,                   /* setup, length, max */
                             param, param_len, 2,            /* param, length, max */
index 839dec75928d925c3bb294bd94ac928323aa00e8..eb66d08c302e053024f516d82991c081f0cb4b1d 100644 (file)
@@ -47,6 +47,11 @@ int clistr_push(struct cli_state *cli, void *dest, char *src, int dest_len, int
                dest_len = sizeof(pstring);
        }
 
+       if (clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) {
+               dest++;
+               dest_len--;
+       }
+
        if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) {
                /* the server doesn't want unicode */
                safe_strcpy(dest, src, dest_len);
@@ -77,12 +82,18 @@ return the length that a string would occupy when copied with clistr_push()
   CLISTR_TERMINATE means include the null termination
   CLISTR_CONVERT   means convert from unix to dos codepage
   CLISTR_UPPER     means uppercase in the destination
+note that dest is only used for alignment purposes. No data is written.
 ****************************************************************************/
-int clistr_push_size(struct cli_state *cli, char *src, int dest_len, int flags)
+int clistr_push_size(struct cli_state *cli, void *dest, char *src, int dest_len, int flags)
 {
        int len = strlen(src);
        if (flags & CLISTR_TERMINATE) len++;
        if (cli_use_unicode && (cli->capabilities & CAP_UNICODE)) len *= 2;
+
+       if (clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) {
+               len++;
+       }
+
        return len;
 }
 
@@ -104,6 +115,11 @@ int clistr_pull(struct cli_state *cli, char *dest, void *src, int dest_len, int
                dest_len = sizeof(pstring);
        }
 
+       if (clistr_align(cli, PTR_DIFF(cli->inbuf, src))) {
+               src++;
+               if (src_len > 0) src_len--;
+       }
+
        if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) {
                /* the server doesn't want unicode */
                if (flags & CLISTR_TERMINATE) {
@@ -143,6 +159,11 @@ if src_len is -1 then assume the source is null terminated
 ****************************************************************************/
 int clistr_pull_size(struct cli_state *cli, void *src, int src_len)
 {
+       if (clistr_align(cli, PTR_DIFF(cli->inbuf, src))) {
+               src++;
+               if (src_len > 0) src_len--;
+       }
+
        if (!cli_use_unicode || !(cli->capabilities & CAP_UNICODE)) {
                return strlen(src);
        }       
index 5cd6ae30ce0938d7e09b4fdc7fb608cf15da8aa4..3afca997cc8829ce1a6e9666dd14a374540e79c3 100644 (file)
@@ -28,7 +28,7 @@
   send a SMB trans or trans2 request
   ****************************************************************************/
 BOOL cli_send_trans(struct cli_state *cli, int trans, 
-                   char *name, int pipe_name_len
+                   char *pipe_name
                    int fid, int flags,
                    uint16 *setup, int lsetup, int msetup,
                    char *param, int lparam, int mparam,
@@ -39,6 +39,7 @@ BOOL cli_send_trans(struct cli_state *cli, int trans,
        int tot_data=0,tot_param=0;
        char *outdata,*outparam;
        char *p;
+       int pipe_name_len=0;
 
        this_lparam = MIN(lparam,cli->max_xmit - (500+lsetup*2)); /* hack */
        this_ldata = MIN(ldata,cli->max_xmit - (500+lsetup*2+this_lparam));
@@ -49,7 +50,13 @@ BOOL cli_send_trans(struct cli_state *cli, int trans,
        SSVAL(cli->outbuf,smb_tid, cli->cnum);
        cli_setup_packet(cli);
 
-       outparam = smb_buf(cli->outbuf)+(trans==SMBtrans ? pipe_name_len+1 : 3);
+       if (pipe_name) {
+               pipe_name_len = clistr_push_size(cli, smb_buf(cli->outbuf), 
+                                                pipe_name, -1, 
+                                                CLISTR_TERMINATE);
+       }
+
+       outparam = smb_buf(cli->outbuf)+(trans==SMBtrans ? pipe_name_len : 3);
        outdata = outparam+this_lparam;
 
        /* primary request */
@@ -69,7 +76,7 @@ BOOL cli_send_trans(struct cli_state *cli, int trans,
                SSVAL(cli->outbuf,smb_setup+i*2,setup[i]);
        p = smb_buf(cli->outbuf);
        if (trans==SMBtrans) {
-               memcpy(p,name, pipe_name_len + 1);  /* name[] */
+               clistr_push(cli, p, pipe_name, -1, CLISTR_TERMINATE);
        } else {
                *p++ = 0;  /* put in a null smb_name */
                *p++ = 'D'; *p++ = ' '; /* observed in OS/2 */
index 0b119de5a1e1d1334ea6c378af0d9c5c477fc1f3..67cf65a4ff3e68a2c07e99a0f263694af834c8f0 100644 (file)
@@ -336,7 +336,7 @@ static BOOL rpc_api_pipe(struct cli_state *cli, uint16 cmd, prs_struct *data, pr
        DEBUG(5,("rpc_api_pipe: cmd:%x fnum:%x\n", (int)cmd, (int)cli->nt_pipe_fnum));
 
        /* send the data: receive a response. */
-       if (!cli_api_pipe(cli, "\\PIPE\\\0\0\0", 8,
+       if (!cli_api_pipe(cli, "\\PIPE\\",
                  setup, 2, 0,                     /* Setup, length, max */
                  NULL, 0, 0,                      /* Params, length, max */
                  pdata, data_len, data_len,       /* data, length, max */                  
@@ -889,7 +889,7 @@ static BOOL rpc_pipe_set_hnd_state(struct cli_state *cli, char *pipe_name, uint1
        setup[1] = cli->nt_pipe_fnum; /* pipe file handle.  got this from an SMBOpenX. */
 
        /* send the data on \PIPE\ */
-       if (cli_api_pipe(cli, "\\PIPE\\\0\0\0", 8,
+       if (cli_api_pipe(cli, "\\PIPE\\",
                    setup, 2, 0,                /* setup, length, max */
                    param, 2, 0,                /* param, length, max */
                    NULL, 0, 1024,              /* data, length, max */