libsmb/climessage.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    client message handling routines
00004    Copyright (C) Andrew Tridgell 1994-1998
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "includes.h"
00022 
00023 
00024 /****************************************************************************
00025 start a message sequence
00026 ****************************************************************************/
00027 int cli_message_start_build(struct cli_state *cli, char *host, char *username)
00028 {
00029         char *p;
00030 
00031         /* construct a SMBsendstrt command */
00032         memset(cli->outbuf,'\0',smb_size);
00033         set_message(cli->outbuf,0,0,True);
00034         SCVAL(cli->outbuf,smb_com,SMBsendstrt);
00035         SSVAL(cli->outbuf,smb_tid,cli->cnum);
00036         cli_setup_packet(cli);
00037         
00038         p = smb_buf(cli->outbuf);
00039         *p++ = 4;
00040         p += clistr_push(cli, p, username, -1, STR_ASCII|STR_TERMINATE);
00041         *p++ = 4;
00042         p += clistr_push(cli, p, host, -1, STR_ASCII|STR_TERMINATE);
00043         
00044         cli_setup_bcc(cli, p);
00045 
00046         return(PTR_DIFF(p, cli->outbuf));
00047 }
00048 
00049 BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
00050                               int *grp)
00051 {
00052         cli_message_start_build(cli, host, username);
00053         
00054         cli_send_smb(cli);      
00055         
00056         if (!cli_receive_smb(cli)) {
00057                 return False;
00058         }
00059 
00060         if (cli_is_error(cli)) return False;
00061 
00062         *grp = SVAL(cli->inbuf,smb_vwv0);
00063 
00064         return True;
00065 }
00066 
00067 
00068 /****************************************************************************
00069 send a message 
00070 ****************************************************************************/
00071 int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp)
00072 {
00073         char *msgdos;
00074         int lendos;
00075         char *p;
00076 
00077         memset(cli->outbuf,'\0',smb_size);
00078         set_message(cli->outbuf,1,0,True);
00079         SCVAL(cli->outbuf,smb_com,SMBsendtxt);
00080         SSVAL(cli->outbuf,smb_tid,cli->cnum);
00081         cli_setup_packet(cli);
00082 
00083         SSVAL(cli->outbuf,smb_vwv0,grp);
00084         
00085         p = smb_buf(cli->outbuf);
00086         *p++ = 1;
00087 
00088         if ((lendos = (int)convert_string_allocate(NULL,CH_UNIX, CH_DOS, msg,len, (void **)(void *)&msgdos, True)) < 0 || !msgdos) {
00089                 DEBUG(3,("Conversion failed, sending message in UNIX charset\n"));
00090                 SSVAL(p, 0, len); p += 2;
00091                 memcpy(p, msg, len);
00092                 p += len;
00093         } else {
00094                 SSVAL(p, 0, lendos); p += 2;
00095                 memcpy(p, msgdos, lendos);
00096                 p += lendos;
00097                 SAFE_FREE(msgdos);
00098         }
00099 
00100         cli_setup_bcc(cli, p);
00101 
00102         return(PTR_DIFF(p, cli->outbuf));
00103 }
00104 
00105 BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp)
00106 {
00107         cli_message_text_build(cli, msg, len, grp);
00108 
00109         cli_send_smb(cli);
00110 
00111         if (!cli_receive_smb(cli)) {
00112                 return False;
00113         }
00114 
00115         if (cli_is_error(cli)) return False;
00116 
00117         return True;
00118 }      
00119 
00120 /****************************************************************************
00121 end a message 
00122 ****************************************************************************/
00123 int cli_message_end_build(struct cli_state *cli, int grp)
00124 {
00125         char *p;
00126 
00127         memset(cli->outbuf,'\0',smb_size);
00128         set_message(cli->outbuf,1,0,True);
00129         SCVAL(cli->outbuf,smb_com,SMBsendend);
00130         SSVAL(cli->outbuf,smb_tid,cli->cnum);
00131 
00132         SSVAL(cli->outbuf,smb_vwv0,grp);
00133 
00134         cli_setup_packet(cli);
00135 
00136         p = smb_buf(cli->outbuf);
00137 
00138         return(PTR_DIFF(p, cli->outbuf));
00139 }
00140 
00141 BOOL cli_message_end(struct cli_state *cli, int grp)
00142 {
00143         cli_message_end_build(cli, grp);
00144 
00145         cli_send_smb(cli);
00146 
00147         if (!cli_receive_smb(cli)) {
00148                 return False;
00149         }
00150 
00151         if (cli_is_error(cli)) return False;
00152 
00153         return True;
00154 }      

Sambaに対してSat Aug 29 21:23:04 2009に生成されました。  doxygen 1.4.7