2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-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 3 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, see <http://www.gnu.org/licenses/>.
20 This file handles the messaging system calls for winpopup style
26 #include "system/filesys.h"
27 #include "smbd/smbd.h"
28 #include "smbd/globals.h"
29 #include "smbprofile.h"
31 extern userdom_struct current_user_info;
39 /****************************************************************************
41 ****************************************************************************/
43 static void msg_deliver(struct msg_state *state)
45 TALLOC_CTX *frame = talloc_stackframe();
46 const struct loadparm_substitution *lp_sub =
47 loadparm_s3_global_substitution();
58 if (! (*lp_message_command(frame, lp_sub))) {
59 DEBUG(1,("no messaging command specified\n"));
63 /* put it in a temporary file */
64 name = talloc_asprintf(talloc_tos(), "%s/msg.XXXXXX", tmpdir());
68 mask = umask(S_IRWXO | S_IRWXG);
73 DEBUG(1, ("can't open message file %s: %s\n", name,
79 * Incoming message is in DOS codepage format. Convert to UNIX.
82 if (!convert_string_talloc(talloc_tos(), CH_DOS, CH_UNIX, state->msg,
83 talloc_get_size(state->msg), (void *)&msg,
85 DEBUG(3, ("Conversion failed, delivering message in DOS "
86 "codepage format\n"));
90 for (i = 0; i < len; i++) {
91 if ((msg[i] == '\r') &&
92 (i < (len-1)) && (msg[i+1] == '\n')) {
95 sz = write(fd, &msg[i], 1);
97 DEBUG(0, ("Write error to fd %d: %ld(%s)\n", fd,
98 (long)sz, strerror(errno)));
104 /* run the command */
105 s = lp_message_command(frame, lp_sub);
110 alpha_strcpy(alpha_buf, state->from, NULL, sizeof(alpha_buf));
112 s = talloc_string_sub(talloc_tos(), s, "%f", alpha_buf);
117 alpha_strcpy(alpha_buf, state->to, NULL, sizeof(alpha_buf));
119 s = talloc_string_sub(talloc_tos(), s, "%t", alpha_buf);
124 s = talloc_sub_basic(talloc_tos(), current_user_info.smb_name,
125 current_user_info.domain, s);
130 s = talloc_string_sub(talloc_tos(), s, "%s", name);
134 smbrun(s, NULL, NULL);
141 /****************************************************************************
143 conn POINTER CAN BE NULL HERE !
144 ****************************************************************************/
146 void reply_sends(struct smb_request *req)
148 const struct loadparm_substitution *lp_sub =
149 loadparm_s3_global_substitution();
150 struct msg_state *state;
155 START_PROFILE(SMBsends);
157 if (!(*lp_message_command(talloc_tos(), lp_sub))) {
158 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
159 END_PROFILE(SMBsends);
163 state = talloc(talloc_tos(), struct msg_state);
166 p += srvstr_pull_req_talloc(
167 state, req, &state->from, p, STR_ASCII|STR_TERMINATE) + 1;
168 p += srvstr_pull_req_talloc(
169 state, req, &state->to, p, STR_ASCII|STR_TERMINATE) + 1;
174 len = MIN(len, smbreq_bufrem(req, msg+2));
176 state->msg = talloc_array(state, char, len);
178 if (state->msg == NULL) {
179 reply_nterror(req, NT_STATUS_NO_MEMORY);
180 END_PROFILE(SMBsends);
184 memcpy(state->msg, msg+2, len);
188 reply_outbuf(req, 0, 0);
190 END_PROFILE(SMBsends);
194 /****************************************************************************
196 conn POINTER CAN BE NULL HERE !
197 ****************************************************************************/
199 void reply_sendstrt(struct smb_request *req)
201 const struct loadparm_substitution *lp_sub =
202 loadparm_s3_global_substitution();
203 struct smbXsrv_connection *xconn = req->xconn;
206 START_PROFILE(SMBsendstrt);
208 if (!(*lp_message_command(talloc_tos(), lp_sub))) {
209 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
210 END_PROFILE(SMBsendstrt);
214 TALLOC_FREE(xconn->smb1.msg_state);
216 xconn->smb1.msg_state = talloc_zero(xconn, struct msg_state);
218 if (xconn->smb1.msg_state == NULL) {
219 reply_nterror(req, NT_STATUS_NO_MEMORY);
220 END_PROFILE(SMBsendstrt);
225 p += srvstr_pull_req_talloc(
226 xconn->smb1.msg_state, req,
227 &xconn->smb1.msg_state->from, p,
228 STR_ASCII|STR_TERMINATE) + 1;
229 p += srvstr_pull_req_talloc(
230 xconn->smb1.msg_state, req,
231 &xconn->smb1.msg_state->to, p,
232 STR_ASCII|STR_TERMINATE) + 1;
234 DEBUG(3, ("SMBsendstrt (from %s to %s)\n",
235 xconn->smb1.msg_state->from,
236 xconn->smb1.msg_state->to));
238 reply_outbuf(req, 0, 0);
240 END_PROFILE(SMBsendstrt);
244 /****************************************************************************
246 conn POINTER CAN BE NULL HERE !
247 ****************************************************************************/
249 void reply_sendtxt(struct smb_request *req)
251 const struct loadparm_substitution *lp_sub =
252 loadparm_s3_global_substitution();
253 struct smbXsrv_connection *xconn = req->xconn;
259 START_PROFILE(SMBsendtxt);
261 if (! (*lp_message_command(talloc_tos(), lp_sub))) {
262 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
263 END_PROFILE(SMBsendtxt);
267 if ((xconn->smb1.msg_state == NULL) || (req->buflen < 3)) {
268 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
269 END_PROFILE(SMBsendtxt);
273 msg = (const char *)req->buf + 1;
275 old_len = talloc_get_size(xconn->smb1.msg_state->msg);
277 len = MIN(SVAL(msg, 0), smbreq_bufrem(req, msg+2));
279 tmp = talloc_realloc(xconn->smb1.msg_state,
280 xconn->smb1.msg_state->msg,
281 char, old_len + len);
284 reply_nterror(req, NT_STATUS_NO_MEMORY);
285 END_PROFILE(SMBsendtxt);
289 xconn->smb1.msg_state->msg = tmp;
291 memcpy(&xconn->smb1.msg_state->msg[old_len], msg+2, len);
293 DEBUG( 3, ( "SMBsendtxt\n" ) );
295 reply_outbuf(req, 0, 0);
297 END_PROFILE(SMBsendtxt);
301 /****************************************************************************
303 conn POINTER CAN BE NULL HERE !
304 ****************************************************************************/
306 void reply_sendend(struct smb_request *req)
308 const struct loadparm_substitution *lp_sub =
309 loadparm_s3_global_substitution();
310 struct smbXsrv_connection *xconn = req->xconn;
311 START_PROFILE(SMBsendend);
313 if (! (*lp_message_command(talloc_tos(), lp_sub))) {
314 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
315 END_PROFILE(SMBsendend);
319 if (xconn->smb1.msg_state == NULL) {
320 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
321 END_PROFILE(SMBsendend);
325 DEBUG(3,("SMBsendend\n"));
327 msg_deliver(xconn->smb1.msg_state);
329 TALLOC_FREE(xconn->smb1.msg_state);
331 reply_outbuf(req, 0, 0);
333 END_PROFILE(SMBsendend);