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"
30 #include "source3/lib/substitute.h"
38 /****************************************************************************
40 ****************************************************************************/
42 static void msg_deliver(struct msg_state *state)
44 TALLOC_CTX *frame = talloc_stackframe();
45 const struct loadparm_substitution *lp_sub =
46 loadparm_s3_global_substitution();
57 if (! (*lp_message_command(frame, lp_sub))) {
58 DEBUG(1,("no messaging command specified\n"));
62 /* put it in a temporary file */
63 name = talloc_asprintf(talloc_tos(), "%s/msg.XXXXXX", tmpdir());
67 mask = umask(S_IRWXO | S_IRWXG);
72 DEBUG(1, ("can't open message file %s: %s\n", name,
78 * Incoming message is in DOS codepage format. Convert to UNIX.
81 if (!convert_string_talloc(talloc_tos(), CH_DOS, CH_UNIX, state->msg,
82 talloc_get_size(state->msg), (void *)&msg,
84 DEBUG(3, ("Conversion failed, delivering message in DOS "
85 "codepage format\n"));
89 for (i = 0; i < len; i++) {
90 if ((msg[i] == '\r') &&
91 (i < (len-1)) && (msg[i+1] == '\n')) {
94 sz = write(fd, &msg[i], 1);
96 DEBUG(0, ("Write error to fd %d: %ld(%s)\n", fd,
97 (long)sz, strerror(errno)));
103 /* run the command */
104 s = lp_message_command(frame, lp_sub);
109 alpha_strcpy(alpha_buf, state->from, NULL, sizeof(alpha_buf));
111 s = talloc_string_sub(talloc_tos(), s, "%f", alpha_buf);
116 alpha_strcpy(alpha_buf, state->to, NULL, sizeof(alpha_buf));
118 s = talloc_string_sub(talloc_tos(), s, "%t", alpha_buf);
123 s = talloc_sub_basic(talloc_tos(), get_current_username(),
124 get_current_user_info_domain(), s);
129 s = talloc_string_sub(talloc_tos(), s, "%s", name);
133 smbrun(s, NULL, NULL);
140 /****************************************************************************
142 conn POINTER CAN BE NULL HERE !
143 ****************************************************************************/
145 void reply_sends(struct smb_request *req)
147 const struct loadparm_substitution *lp_sub =
148 loadparm_s3_global_substitution();
149 struct msg_state *state;
154 START_PROFILE(SMBsends);
156 if (!(*lp_message_command(talloc_tos(), lp_sub))) {
157 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
158 END_PROFILE(SMBsends);
162 state = talloc_zero(talloc_tos(), struct msg_state);
165 p += srvstr_pull_req_talloc(
166 state, req, &state->from, p, STR_ASCII|STR_TERMINATE) + 1;
167 p += srvstr_pull_req_talloc(
168 state, req, &state->to, p, STR_ASCII|STR_TERMINATE) + 1;
173 len = MIN(len, smbreq_bufrem(req, msg+2));
175 state->msg = talloc_array(state, char, len);
177 if (state->msg == NULL) {
178 reply_nterror(req, NT_STATUS_NO_MEMORY);
179 END_PROFILE(SMBsends);
183 memcpy(state->msg, msg+2, len);
187 reply_smb1_outbuf(req, 0, 0);
189 END_PROFILE(SMBsends);
193 /****************************************************************************
195 conn POINTER CAN BE NULL HERE !
196 ****************************************************************************/
198 void reply_sendstrt(struct smb_request *req)
200 const struct loadparm_substitution *lp_sub =
201 loadparm_s3_global_substitution();
202 struct smbXsrv_connection *xconn = req->xconn;
205 START_PROFILE(SMBsendstrt);
207 if (!(*lp_message_command(talloc_tos(), lp_sub))) {
208 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
209 END_PROFILE(SMBsendstrt);
213 TALLOC_FREE(xconn->smb1.msg_state);
215 xconn->smb1.msg_state = talloc_zero(xconn, struct msg_state);
217 if (xconn->smb1.msg_state == NULL) {
218 reply_nterror(req, NT_STATUS_NO_MEMORY);
219 END_PROFILE(SMBsendstrt);
224 p += srvstr_pull_req_talloc(
225 xconn->smb1.msg_state, req,
226 &xconn->smb1.msg_state->from, p,
227 STR_ASCII|STR_TERMINATE) + 1;
228 p += srvstr_pull_req_talloc(
229 xconn->smb1.msg_state, req,
230 &xconn->smb1.msg_state->to, p,
231 STR_ASCII|STR_TERMINATE) + 1;
233 DEBUG(3, ("SMBsendstrt (from %s to %s)\n",
234 xconn->smb1.msg_state->from,
235 xconn->smb1.msg_state->to));
237 reply_smb1_outbuf(req, 0, 0);
239 END_PROFILE(SMBsendstrt);
243 /****************************************************************************
245 conn POINTER CAN BE NULL HERE !
246 ****************************************************************************/
248 void reply_sendtxt(struct smb_request *req)
250 const struct loadparm_substitution *lp_sub =
251 loadparm_s3_global_substitution();
252 struct smbXsrv_connection *xconn = req->xconn;
258 START_PROFILE(SMBsendtxt);
260 if (! (*lp_message_command(talloc_tos(), lp_sub))) {
261 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
262 END_PROFILE(SMBsendtxt);
266 if ((xconn->smb1.msg_state == NULL) || (req->buflen < 3)) {
267 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
268 END_PROFILE(SMBsendtxt);
272 msg = (const char *)req->buf + 1;
274 old_len = talloc_get_size(xconn->smb1.msg_state->msg);
276 len = MIN(SVAL(msg, 0), smbreq_bufrem(req, msg+2));
278 tmp = talloc_realloc(xconn->smb1.msg_state,
279 xconn->smb1.msg_state->msg,
280 char, old_len + len);
283 reply_nterror(req, NT_STATUS_NO_MEMORY);
284 END_PROFILE(SMBsendtxt);
288 xconn->smb1.msg_state->msg = tmp;
290 memcpy(&xconn->smb1.msg_state->msg[old_len], msg+2, len);
292 DEBUG( 3, ( "SMBsendtxt\n" ) );
294 reply_smb1_outbuf(req, 0, 0);
296 END_PROFILE(SMBsendtxt);
300 /****************************************************************************
302 conn POINTER CAN BE NULL HERE !
303 ****************************************************************************/
305 void reply_sendend(struct smb_request *req)
307 const struct loadparm_substitution *lp_sub =
308 loadparm_s3_global_substitution();
309 struct smbXsrv_connection *xconn = req->xconn;
310 START_PROFILE(SMBsendend);
312 if (! (*lp_message_command(talloc_tos(), lp_sub))) {
313 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
314 END_PROFILE(SMBsendend);
318 if (xconn->smb1.msg_state == NULL) {
319 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
320 END_PROFILE(SMBsendend);
324 DEBUG(3,("SMBsendend\n"));
326 msg_deliver(xconn->smb1.msg_state);
328 TALLOC_FREE(xconn->smb1.msg_state);
330 reply_smb1_outbuf(req, 0, 0);
332 END_PROFILE(SMBsendend);