smbd/message.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    SMB messaging
00004    Copyright (C) Andrew Tridgell 1992-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    This file handles the messaging system calls for winpopup style
00022    messages
00023 */
00024 
00025 
00026 #include "includes.h"
00027 
00028 extern userdom_struct current_user_info;
00029 
00030 /* look in server.c for some explanation of these variables */
00031 static char msgbuf[1600];
00032 static int msgpos;
00033 static fstring msgfrom;
00034 static fstring msgto;
00035 
00036 /****************************************************************************
00037  Deliver the message.
00038 ****************************************************************************/
00039 
00040 static void msg_deliver(void)
00041 {
00042         pstring name;
00043         int i;
00044         int fd;
00045         char *msg;
00046         int len;
00047         ssize_t sz;
00048 
00049         if (! (*lp_msg_command())) {
00050                 DEBUG(1,("no messaging command specified\n"));
00051                 msgpos = 0;
00052                 return;
00053         }
00054 
00055         /* put it in a temporary file */
00056         slprintf(name,sizeof(name)-1, "%s/msg.XXXXXX",tmpdir());
00057         fd = smb_mkstemp(name);
00058 
00059         if (fd == -1) {
00060                 DEBUG(1,("can't open message file %s\n",name));
00061                 return;
00062         }
00063 
00064         /*
00065          * Incoming message is in DOS codepage format. Convert to UNIX.
00066          */
00067   
00068         if ((len = (int)convert_string_allocate(NULL,CH_DOS, CH_UNIX, msgbuf, msgpos, (void **)(void *)&msg, True)) < 0 || !msg) {
00069                 DEBUG(3,("Conversion failed, delivering message in DOS codepage format\n"));
00070                 for (i = 0; i < msgpos;) {
00071                         if (msgbuf[i] == '\r' && i < (msgpos-1) && msgbuf[i+1] == '\n') {
00072                                 i++;
00073                                 continue;
00074                         }
00075                         sz = write(fd, &msgbuf[i++], 1);
00076                         if ( sz != 1 ) {
00077                                 DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
00078                         }
00079                 }
00080         } else {
00081                 for (i = 0; i < len;) {
00082                         if (msg[i] == '\r' && i < (len-1) && msg[i+1] == '\n') {
00083                                 i++;
00084                                 continue;
00085                         }
00086                         sz = write(fd, &msg[i++],1);
00087                         if ( sz != 1 ) {
00088                                 DEBUG(0,("Write error to fd %d: %ld(%d)\n",fd, (long)sz, errno ));
00089                         }
00090                 }
00091                 SAFE_FREE(msg);
00092         }
00093         close(fd);
00094 
00095         /* run the command */
00096         if (*lp_msg_command()) {
00097                 fstring alpha_msgfrom;
00098                 fstring alpha_msgto;
00099                 pstring s;
00100 
00101                 pstrcpy(s,lp_msg_command());
00102                 pstring_sub(s,"%f",alpha_strcpy(alpha_msgfrom,msgfrom,NULL,sizeof(alpha_msgfrom)));
00103                 pstring_sub(s,"%t",alpha_strcpy(alpha_msgto,msgto,NULL,sizeof(alpha_msgto)));
00104                 standard_sub_basic(current_user_info.smb_name,
00105                                 current_user_info.domain, s, sizeof(s));
00106                 pstring_sub(s,"%s",name);
00107                 smbrun(s,NULL);
00108         }
00109 
00110         msgpos = 0;
00111 }
00112 
00113 /****************************************************************************
00114  Reply to a sends.
00115  conn POINTER CAN BE NULL HERE !
00116 ****************************************************************************/
00117 
00118 int reply_sends(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
00119 {
00120         int len;
00121         char *msg;
00122         int outsize = 0;
00123         char *p;
00124 
00125         START_PROFILE(SMBsends);
00126 
00127         msgpos = 0;
00128 
00129         if (! (*lp_msg_command())) {
00130                 END_PROFILE(SMBsends);
00131                 return(ERROR_DOS(ERRSRV,ERRmsgoff));
00132         }
00133 
00134         outsize = set_message(outbuf,0,0,True);
00135 
00136         p = smb_buf(inbuf)+1;
00137         p += srvstr_pull_buf(inbuf, msgfrom, p, sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
00138         p += srvstr_pull_buf(inbuf, msgto, p, sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
00139 
00140         msg = p;
00141 
00142         len = SVAL(msg,0);
00143         len = MIN(len,sizeof(msgbuf)-msgpos);
00144 
00145         memset(msgbuf,'\0',sizeof(msgbuf));
00146 
00147         memcpy(&msgbuf[msgpos],msg+2,len);
00148         msgpos += len;
00149 
00150         msg_deliver();
00151 
00152         END_PROFILE(SMBsends);
00153         return(outsize);
00154 }
00155 
00156 /****************************************************************************
00157  Reply to a sendstrt.
00158  conn POINTER CAN BE NULL HERE !
00159 ****************************************************************************/
00160 
00161 int reply_sendstrt(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
00162 {
00163         int outsize = 0;
00164         char *p;
00165 
00166         START_PROFILE(SMBsendstrt);
00167 
00168         if (! (*lp_msg_command())) {
00169                 END_PROFILE(SMBsendstrt);
00170                 return(ERROR_DOS(ERRSRV,ERRmsgoff));
00171         }
00172 
00173         outsize = set_message(outbuf,1,0,True);
00174 
00175         memset(msgbuf,'\0',sizeof(msgbuf));
00176         msgpos = 0;
00177 
00178         p = smb_buf(inbuf)+1;
00179         p += srvstr_pull_buf(inbuf, msgfrom, p, sizeof(msgfrom), STR_ASCII|STR_TERMINATE) + 1;
00180         p += srvstr_pull_buf(inbuf, msgto, p, sizeof(msgto), STR_ASCII|STR_TERMINATE) + 1;
00181 
00182         DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", msgfrom, msgto ) );
00183 
00184         END_PROFILE(SMBsendstrt);
00185         return(outsize);
00186 }
00187 
00188 /****************************************************************************
00189  Reply to a sendtxt.
00190  conn POINTER CAN BE NULL HERE !
00191 ****************************************************************************/
00192 
00193 int reply_sendtxt(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
00194 {
00195         int len;
00196         int outsize = 0;
00197         char *msg;
00198         START_PROFILE(SMBsendtxt);
00199 
00200         if (! (*lp_msg_command())) {
00201                 END_PROFILE(SMBsendtxt);
00202                 return(ERROR_DOS(ERRSRV,ERRmsgoff));
00203         }
00204 
00205         outsize = set_message(outbuf,0,0,True);
00206 
00207         msg = smb_buf(inbuf) + 1;
00208 
00209         len = SVAL(msg,0);
00210         len = MIN(len,sizeof(msgbuf)-msgpos);
00211 
00212         memcpy(&msgbuf[msgpos],msg+2,len);
00213         msgpos += len;
00214 
00215         DEBUG( 3, ( "SMBsendtxt\n" ) );
00216 
00217         END_PROFILE(SMBsendtxt);
00218         return(outsize);
00219 }
00220 
00221 /****************************************************************************
00222  Reply to a sendend.
00223  conn POINTER CAN BE NULL HERE !
00224 ****************************************************************************/
00225 
00226 int reply_sendend(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
00227 {
00228         int outsize = 0;
00229         START_PROFILE(SMBsendend);
00230 
00231         if (! (*lp_msg_command())) {
00232                 END_PROFILE(SMBsendend);
00233                 return(ERROR_DOS(ERRSRV,ERRmsgoff));
00234         }
00235 
00236         outsize = set_message(outbuf,0,0,True);
00237 
00238         DEBUG(3,("SMBsendend\n"));
00239 
00240         msg_deliver();
00241 
00242         END_PROFILE(SMBsendend);
00243         return(outsize);
00244 }

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