[206] | 1 | /*
|
---|
| 2 | Unix SMB/CIFS implementation.
|
---|
| 3 | client message handling routines
|
---|
| 4 | Copyright (C) Andrew Tridgell 1994-1998
|
---|
| 5 |
|
---|
| 6 | This program is free software; you can redistribute it and/or modify
|
---|
| 7 | it under the terms of the GNU General Public License as published by
|
---|
| 8 | the Free Software Foundation; either version 3 of the License, or
|
---|
| 9 | (at your option) any later version.
|
---|
| 10 |
|
---|
| 11 | This program is distributed in the hope that it will be useful,
|
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | You should have received a copy of the GNU General Public License
|
---|
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | #include "includes.h"
|
---|
| 21 |
|
---|
| 22 | /****************************************************************************
|
---|
| 23 | Start a message sequence.
|
---|
| 24 | ****************************************************************************/
|
---|
| 25 |
|
---|
| 26 | int cli_message_start_build(struct cli_state *cli, const char *host, const char *username)
|
---|
| 27 | {
|
---|
| 28 | char *p;
|
---|
| 29 |
|
---|
| 30 | /* construct a SMBsendstrt command */
|
---|
| 31 | memset(cli->outbuf,'\0',smb_size);
|
---|
| 32 | cli_set_message(cli->outbuf,0,0,True);
|
---|
| 33 | SCVAL(cli->outbuf,smb_com,SMBsendstrt);
|
---|
| 34 | SSVAL(cli->outbuf,smb_tid,cli->cnum);
|
---|
| 35 | cli_setup_packet(cli);
|
---|
| 36 |
|
---|
| 37 | p = smb_buf(cli->outbuf);
|
---|
| 38 | *p++ = 4;
|
---|
| 39 | p += clistr_push(cli, p, username,
|
---|
| 40 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_ASCII|STR_TERMINATE);
|
---|
| 41 | *p++ = 4;
|
---|
| 42 | p += clistr_push(cli, p, host,
|
---|
| 43 | cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_ASCII|STR_TERMINATE);
|
---|
| 44 |
|
---|
| 45 | cli_setup_bcc(cli, p);
|
---|
| 46 |
|
---|
| 47 | return(PTR_DIFF(p, cli->outbuf));
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | bool cli_message_start(struct cli_state *cli, const char *host, const char *username,
|
---|
| 51 | int *grp)
|
---|
| 52 | {
|
---|
| 53 | cli_message_start_build(cli, host, username);
|
---|
| 54 | cli_send_smb(cli);
|
---|
| 55 |
|
---|
| 56 | if (!cli_receive_smb(cli)) {
|
---|
| 57 | return False;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | if (cli_is_error(cli)) return False;
|
---|
| 61 |
|
---|
| 62 | *grp = SVAL(cli->inbuf,smb_vwv0);
|
---|
| 63 |
|
---|
| 64 | return True;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /****************************************************************************
|
---|
| 68 | Send a message
|
---|
| 69 | ****************************************************************************/
|
---|
| 70 |
|
---|
| 71 | int cli_message_text_build(struct cli_state *cli, const char *msg, int len, int grp)
|
---|
| 72 | {
|
---|
| 73 | char *msgdos;
|
---|
| 74 | size_t lendos;
|
---|
| 75 | char *p;
|
---|
| 76 |
|
---|
| 77 | memset(cli->outbuf,'\0',smb_size);
|
---|
| 78 | cli_set_message(cli->outbuf,1,0,True);
|
---|
| 79 | SCVAL(cli->outbuf,smb_com,SMBsendtxt);
|
---|
| 80 | SSVAL(cli->outbuf,smb_tid,cli->cnum);
|
---|
| 81 | cli_setup_packet(cli);
|
---|
| 82 |
|
---|
| 83 | SSVAL(cli->outbuf,smb_vwv0,grp);
|
---|
| 84 |
|
---|
| 85 | p = smb_buf(cli->outbuf);
|
---|
| 86 | *p++ = 1;
|
---|
| 87 |
|
---|
| 88 | if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, msg, len,
|
---|
| 89 | (void **)(void *)&msgdos, &lendos, True) || !msgdos) {
|
---|
| 90 | DEBUG(3,("Conversion failed, sending message in UNIX charset\n"));
|
---|
| 91 | SSVAL(p, 0, len); p += 2;
|
---|
| 92 | if (len > cli->bufsize - PTR_DIFF(p,cli->outbuf)) {
|
---|
| 93 | return -1;
|
---|
| 94 | }
|
---|
| 95 | memcpy(p, msg, len);
|
---|
| 96 | p += len;
|
---|
| 97 | } else {
|
---|
| 98 | SSVAL(p, 0, lendos); p += 2;
|
---|
| 99 | if (lendos > cli->bufsize - PTR_DIFF(p,cli->outbuf)) {
|
---|
| 100 | return -1;
|
---|
| 101 | }
|
---|
| 102 | memcpy(p, msgdos, lendos);
|
---|
| 103 | p += lendos;
|
---|
| 104 | SAFE_FREE(msgdos);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | cli_setup_bcc(cli, p);
|
---|
| 108 |
|
---|
| 109 | return(PTR_DIFF(p, cli->outbuf));
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | bool cli_message_text(struct cli_state *cli, const char *msg, int len, int grp)
|
---|
| 113 | {
|
---|
| 114 | cli_message_text_build(cli, msg, len, grp);
|
---|
| 115 |
|
---|
| 116 | cli_send_smb(cli);
|
---|
| 117 |
|
---|
| 118 | if (!cli_receive_smb(cli)) {
|
---|
| 119 | return False;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | if (cli_is_error(cli)) return False;
|
---|
| 123 |
|
---|
| 124 | return True;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /****************************************************************************
|
---|
| 128 | End a message.
|
---|
| 129 | ****************************************************************************/
|
---|
| 130 |
|
---|
| 131 | int cli_message_end_build(struct cli_state *cli, int grp)
|
---|
| 132 | {
|
---|
| 133 | char *p;
|
---|
| 134 |
|
---|
| 135 | memset(cli->outbuf,'\0',smb_size);
|
---|
| 136 | cli_set_message(cli->outbuf,1,0,True);
|
---|
| 137 | SCVAL(cli->outbuf,smb_com,SMBsendend);
|
---|
| 138 | SSVAL(cli->outbuf,smb_tid,cli->cnum);
|
---|
| 139 |
|
---|
| 140 | SSVAL(cli->outbuf,smb_vwv0,grp);
|
---|
| 141 |
|
---|
| 142 | cli_setup_packet(cli);
|
---|
| 143 |
|
---|
| 144 | p = smb_buf(cli->outbuf);
|
---|
| 145 |
|
---|
| 146 | return(PTR_DIFF(p, cli->outbuf));
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | bool cli_message_end(struct cli_state *cli, int grp)
|
---|
| 150 | {
|
---|
| 151 | cli_message_end_build(cli, grp);
|
---|
| 152 |
|
---|
| 153 | cli_send_smb(cli);
|
---|
| 154 |
|
---|
| 155 | if (!cli_receive_smb(cli)) {
|
---|
| 156 | return False;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | if (cli_is_error(cli)) return False;
|
---|
| 160 |
|
---|
| 161 | return True;
|
---|
| 162 | }
|
---|