Removed version number from file header.
[ira/wip.git] / source3 / libsmb / climessage.c
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 2 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, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #define NO_SYSLOG
22
23 #include "includes.h"
24
25
26 /****************************************************************************
27 start a message sequence
28 ****************************************************************************/
29 BOOL cli_message_start(struct cli_state *cli, char *host, char *username, 
30                               int *grp)
31 {
32         char *p;
33
34         /* send a SMBsendstrt command */
35         memset(cli->outbuf,'\0',smb_size);
36         set_message(cli->outbuf,0,0,True);
37         SCVAL(cli->outbuf,smb_com,SMBsendstrt);
38         SSVAL(cli->outbuf,smb_tid,cli->cnum);
39         cli_setup_packet(cli);
40         
41         p = smb_buf(cli->outbuf);
42         *p++ = 4;
43         p += clistr_push(cli, p, username, -1, STR_TERMINATE);
44         *p++ = 4;
45         p += clistr_push(cli, p, host, -1, STR_TERMINATE);
46         
47         cli_setup_bcc(cli, p);
48         
49         cli_send_smb(cli);      
50         
51         if (!cli_receive_smb(cli)) {
52                 return False;
53         }
54
55         if (cli_is_error(cli)) return False;
56
57         *grp = SVAL(cli->inbuf,smb_vwv0);
58
59         return True;
60 }
61
62
63 /****************************************************************************
64 send a message 
65 ****************************************************************************/
66 BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
67 {
68         char *p;
69
70         memset(cli->outbuf,'\0',smb_size);
71         set_message(cli->outbuf,1,0,True);
72         SCVAL(cli->outbuf,smb_com,SMBsendtxt);
73         SSVAL(cli->outbuf,smb_tid,cli->cnum);
74         cli_setup_packet(cli);
75
76         SSVAL(cli->outbuf,smb_vwv0,grp);
77         
78         p = smb_buf(cli->outbuf);
79         *p++ = 1;
80         SSVAL(p,0,len); p += 2;
81         memcpy(p,msg,len);
82         p += len;
83
84         cli_setup_bcc(cli, p);
85         cli_send_smb(cli);
86
87         if (!cli_receive_smb(cli)) {
88                 return False;
89         }
90
91         if (cli_is_error(cli)) return False;
92
93         return True;
94 }      
95
96 /****************************************************************************
97 end a message 
98 ****************************************************************************/
99 BOOL cli_message_end(struct cli_state *cli, int grp)
100 {
101         memset(cli->outbuf,'\0',smb_size);
102         set_message(cli->outbuf,1,0,True);
103         SCVAL(cli->outbuf,smb_com,SMBsendend);
104         SSVAL(cli->outbuf,smb_tid,cli->cnum);
105
106         SSVAL(cli->outbuf,smb_vwv0,grp);
107
108         cli_setup_packet(cli);
109         
110         cli_send_smb(cli);
111
112         if (!cli_receive_smb(cli)) {
113                 return False;
114         }
115
116         if (cli_is_error(cli)) return False;
117
118         return True;
119 }      
120