Same fix as went into 2.2 (I'm waiting for jerry to finish some code).
[samba.git] / source / libsmb / climessage.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    client message handling routines
5    Copyright (C) Andrew Tridgell 1994-1998
6    
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.
11    
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.
16    
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.
20 */
21
22 #define NO_SYSLOG
23
24 #include "includes.h"
25
26
27 /****************************************************************************
28 start a message sequence
29 ****************************************************************************/
30 BOOL cli_message_start(struct cli_state *cli, char *host, char *username, 
31                               int *grp)
32 {
33         char *p;
34
35         /* send a SMBsendstrt command */
36         memset(cli->outbuf,'\0',smb_size);
37         set_message(cli->outbuf,0,0,True);
38         SCVAL(cli->outbuf,smb_com,SMBsendstrt);
39         SSVAL(cli->outbuf,smb_tid,cli->cnum);
40         cli_setup_packet(cli);
41         
42         p = smb_buf(cli->outbuf);
43         *p++ = 4;
44         p += clistr_push(cli, p, username, -1, STR_TERMINATE);
45         *p++ = 4;
46         p += clistr_push(cli, p, host, -1, STR_TERMINATE);
47         
48         cli_setup_bcc(cli, p);
49         
50         cli_send_smb(cli);      
51         
52         if (!cli_receive_smb(cli)) {
53                 return False;
54         }
55
56         if (cli_is_error(cli)) return False;
57
58         *grp = SVAL(cli->inbuf,smb_vwv0);
59
60         return True;
61 }
62
63
64 /****************************************************************************
65 send a message 
66 ****************************************************************************/
67 BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
68 {
69         char *p;
70
71         memset(cli->outbuf,'\0',smb_size);
72         set_message(cli->outbuf,1,0,True);
73         SCVAL(cli->outbuf,smb_com,SMBsendtxt);
74         SSVAL(cli->outbuf,smb_tid,cli->cnum);
75         cli_setup_packet(cli);
76
77         SSVAL(cli->outbuf,smb_vwv0,grp);
78         
79         p = smb_buf(cli->outbuf);
80         *p++ = 1;
81         SSVAL(p,0,len); p += 2;
82         memcpy(p,msg,len);
83         p += len;
84
85         cli_setup_bcc(cli, p);
86         cli_send_smb(cli);
87
88         if (!cli_receive_smb(cli)) {
89                 return False;
90         }
91
92         if (cli_is_error(cli)) return False;
93
94         return True;
95 }      
96
97 /****************************************************************************
98 end a message 
99 ****************************************************************************/
100 BOOL cli_message_end(struct cli_state *cli, int grp)
101 {
102         memset(cli->outbuf,'\0',smb_size);
103         set_message(cli->outbuf,1,0,True);
104         SCVAL(cli->outbuf,smb_com,SMBsendend);
105         SSVAL(cli->outbuf,smb_tid,cli->cnum);
106
107         SSVAL(cli->outbuf,smb_vwv0,grp);
108
109         cli_setup_packet(cli);
110         
111         cli_send_smb(cli);
112
113         if (!cli_receive_smb(cli)) {
114                 return False;
115         }
116
117         if (cli_is_error(cli)) return False;
118
119         return True;
120 }      
121