merge from 2.2
[Samba/gbeck.git] / source / libsmb / climessage.c
blob87f817545996a8561e825d478b353081a29d3b69
1 /*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 client message handling routines
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define NO_SYSLOG
24 #include "includes.h"
27 /****************************************************************************
28 start a message sequence
29 ****************************************************************************/
30 BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
31 int *grp)
33 char *p;
35 /* send a SMBsendstrt command */
36 memset(cli->outbuf,'\0',smb_size);
37 set_message(cli->outbuf,0,0,True);
38 CVAL(cli->outbuf,smb_com) = SMBsendstrt;
39 SSVAL(cli->outbuf,smb_tid,cli->cnum);
40 cli_setup_packet(cli);
42 p = smb_buf(cli->outbuf);
43 *p++ = 4;
44 p += clistr_push(cli, p, username, -1,
45 STR_TERMINATE|STR_CONVERT);
46 *p++ = 4;
47 p += clistr_push(cli, p, host, -1,
48 STR_TERMINATE|STR_CONVERT);
50 cli_setup_bcc(cli, p);
52 cli_send_smb(cli);
54 if (!cli_receive_smb(cli)) {
55 return False;
58 if (cli_error(cli, NULL, NULL, NULL)) return False;
60 *grp = SVAL(cli->inbuf,smb_vwv0);
62 return True;
66 /****************************************************************************
67 send a message
68 ****************************************************************************/
69 BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
71 char *p;
73 memset(cli->outbuf,'\0',smb_size);
74 set_message(cli->outbuf,1,len+3,True);
75 CVAL(cli->outbuf,smb_com) = SMBsendtxt;
76 SSVAL(cli->outbuf,smb_tid,cli->cnum);
77 cli_setup_packet(cli);
79 SSVAL(cli->outbuf,smb_vwv0,grp);
81 p = smb_buf(cli->outbuf);
82 *p = 1;
83 SSVAL(p,1,len);
84 memcpy(p+3,msg,len);
85 cli_send_smb(cli);
87 if (!cli_receive_smb(cli)) {
88 return False;
91 if (cli_error(cli, NULL, NULL, NULL)) return False;
93 return True;
96 /****************************************************************************
97 end a message
98 ****************************************************************************/
99 BOOL cli_message_end(struct cli_state *cli, int grp)
101 memset(cli->outbuf,'\0',smb_size);
102 set_message(cli->outbuf,1,0,True);
103 CVAL(cli->outbuf,smb_com) = SMBsendend;
104 SSVAL(cli->outbuf,smb_tid,cli->cnum);
106 SSVAL(cli->outbuf,smb_vwv0,grp);
108 cli_setup_packet(cli);
110 cli_send_smb(cli);
112 if (!cli_receive_smb(cli)) {
113 return False;
116 if (cli_error(cli, NULL, NULL, NULL)) return False;
118 return True;