Apply the changes to libsmbclient that derrell has contributed. Fix some
[Samba/gebeck_regimport.git] / source3 / libsmb / climessage.c
blob035088212c7a40e109f0be56aebddfd6d512a12b
1 /*
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.
21 #define NO_SYSLOG
23 #include "includes.h"
26 /****************************************************************************
27 start a message sequence
28 ****************************************************************************/
29 int cli_message_start_build(struct cli_state *cli, char *host, char *username)
31 char *p;
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);
41 *p++ = 4;
42 p += clistr_push(cli, p, username, -1, STR_ASCII|STR_TERMINATE);
43 *p++ = 4;
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,
52 int *grp)
54 cli_message_start_build(cli, host, username);
56 cli_send_smb(cli);
58 if (!cli_receive_smb(cli)) {
59 return False;
62 if (cli_is_error(cli)) return False;
64 *grp = SVAL(cli->inbuf,smb_vwv0);
66 return True;
70 /****************************************************************************
71 send a message
72 ****************************************************************************/
73 int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
75 char *msgdos;
76 int lendos;
77 char *p;
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);
88 *p++ = 1;
90 if ((lendos = convert_string_allocate(NULL,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;
93 memcpy(p, msg, len);
94 p += len;
95 } else {
96 SSVAL(p, 0, lendos); p += 2;
97 memcpy(p, msgdos, lendos);
98 p += lendos;
99 SAFE_FREE(msgdos);
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);
111 cli_send_smb(cli);
113 if (!cli_receive_smb(cli)) {
114 return False;
117 if (cli_is_error(cli)) return False;
119 return True;
122 /****************************************************************************
123 end a message
124 ****************************************************************************/
125 int cli_message_end_build(struct cli_state *cli, int grp)
127 char *p;
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);
147 cli_send_smb(cli);
149 if (!cli_receive_smb(cli)) {
150 return False;
153 if (cli_is_error(cli)) return False;
155 return True;