2 Unix SMB/CIFS implementation.
3 client message handling routines
4 Copyright (C) Andrew Tridgell 1994-1998
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 2 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /****************************************************************************
27 start a message sequence
28 ****************************************************************************/
29 int cli_message_start_build(struct cli_state *cli, char *host, char *username)
33 /* construct a SMBsendstrt command */
34 memset(cli->outbuf,'\0',smb_size);
35 set_message(cli->outbuf,0,0,True);
36 SCVAL(cli->outbuf,smb_com,SMBsendstrt);
37 SSVAL(cli->outbuf,smb_tid,cli->cnum);
38 cli_setup_packet(cli);
40 p = smb_buf(cli->outbuf);
42 p += clistr_push(cli, p, username, -1, STR_ASCII|STR_TERMINATE);
44 p += clistr_push(cli, p, host, -1, STR_ASCII|STR_TERMINATE);
46 cli_setup_bcc(cli, p);
48 return(PTR_DIFF(p, cli->outbuf));
51 BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
54 cli_message_start_build(cli, host, username);
58 if (!cli_receive_smb(cli)) {
62 if (cli_is_error(cli)) return False;
64 *grp = SVAL(cli->inbuf,smb_vwv0);
70 /****************************************************************************
72 ****************************************************************************/
73 int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
79 memset(cli->outbuf,'\0',smb_size);
80 set_message(cli->outbuf,1,0,True);
81 SCVAL(cli->outbuf,smb_com,SMBsendtxt);
82 SSVAL(cli->outbuf,smb_tid,cli->cnum);
83 cli_setup_packet(cli);
85 SSVAL(cli->outbuf,smb_vwv0,grp);
87 p = smb_buf(cli->outbuf);
90 if ((lendos = convert_string_allocate(CH_UNIX, CH_DOS, msg,len, (void **) &msgdos)) < 0 || !msgdos) {
91 DEBUG(3,("Conversion failed, sending message in UNIX charset\n"));
92 SSVAL(p, 0, len); p += 2;
96 SSVAL(p, 0, lendos); p += 2;
97 memcpy(p, msgdos, lendos);
102 cli_setup_bcc(cli, p);
104 return(PTR_DIFF(p, cli->outbuf));
107 BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
109 cli_message_text_build(cli, msg, len, grp);
113 if (!cli_receive_smb(cli)) {
117 if (cli_is_error(cli)) return False;
122 /****************************************************************************
124 ****************************************************************************/
125 int cli_message_end_build(struct cli_state *cli, int grp)
129 memset(cli->outbuf,'\0',smb_size);
130 set_message(cli->outbuf,1,0,True);
131 SCVAL(cli->outbuf,smb_com,SMBsendend);
132 SSVAL(cli->outbuf,smb_tid,cli->cnum);
134 SSVAL(cli->outbuf,smb_vwv0,grp);
136 cli_setup_packet(cli);
138 p = smb_buf(cli->outbuf);
140 return(PTR_DIFF(p, cli->outbuf));
143 BOOL cli_message_end(struct cli_state *cli, int grp)
145 cli_message_end_build(cli, grp);
149 if (!cli_receive_smb(cli)) {
153 if (cli_is_error(cli)) return False;