c15fdbce8c5d477ea47a291a377ca1e08e9323a7
[ira/wip.git] / source3 / 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         CVAL(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         pstrcpy(p,username);
45         unix_to_dos(p,True);
46         p = skip_string(p,1);
47         *p++ = 4;
48         pstrcpy(p,host);
49         unix_to_dos(p,True);
50         p = skip_string(p,1);
51         
52         set_message(cli->outbuf,0,PTR_DIFF(p,smb_buf(cli->outbuf)),False);
53         
54         cli_send_smb(cli);      
55         
56         if (!cli_receive_smb(cli)) {
57                 return False;
58         }
59
60         if (cli_error(cli, NULL, NULL, NULL)) return False;
61
62         *grp = SVAL(cli->inbuf,smb_vwv0);
63
64         return True;
65 }
66
67
68 /****************************************************************************
69 send a message 
70 ****************************************************************************/
71 BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
72 {
73         char *p;
74
75         memset(cli->outbuf,'\0',smb_size);
76         set_message(cli->outbuf,1,len+3,True);
77         CVAL(cli->outbuf,smb_com) = SMBsendtxt;
78         SSVAL(cli->outbuf,smb_tid,cli->cnum);
79         cli_setup_packet(cli);
80
81         SSVAL(cli->outbuf,smb_vwv0,grp);
82         
83         p = smb_buf(cli->outbuf);
84         *p = 1;
85         SSVAL(p,1,len);
86         memcpy(p+3,msg,len);
87         cli_send_smb(cli);
88
89         if (!cli_receive_smb(cli)) {
90                 return False;
91         }
92
93         if (cli_error(cli, NULL, NULL, NULL)) return False;
94
95         return True;
96 }      
97
98 /****************************************************************************
99 end a message 
100 ****************************************************************************/
101 BOOL cli_message_end(struct cli_state *cli, int grp)
102 {
103         memset(cli->outbuf,'\0',smb_size);
104         set_message(cli->outbuf,1,0,True);
105         CVAL(cli->outbuf,smb_com) = SMBsendend;
106         SSVAL(cli->outbuf,smb_tid,cli->cnum);
107
108         SSVAL(cli->outbuf,smb_vwv0,grp);
109
110         cli_setup_packet(cli);
111         
112         cli_send_smb(cli);
113
114         if (!cli_receive_smb(cli)) {
115                 return False;
116         }
117
118         if (cli_error(cli, NULL, NULL, NULL)) return False;
119
120         return True;
121 }      
122