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 "smbd/smbd.h"
27 #include "smbd/globals.h"
28 #include "smbprofile.h"
30 extern userdom_struct current_user_info;
38 /****************************************************************************
40 ****************************************************************************/
42 static void msg_deliver(struct msg_state *state)
44 TALLOC_CTX *frame = talloc_stackframe();
54 if (! (*lp_msg_command())) {
55 DEBUG(1,("no messaging command specified\n"));
59 /* put it in a temporary file */
60 name = talloc_asprintf(talloc_tos(), "%s/msg.XXXXXX", tmpdir());
67 DEBUG(1, ("can't open message file %s: %s\n", name,
73 * Incoming message is in DOS codepage format. Convert to UNIX.
76 if (!convert_string_talloc(talloc_tos(), CH_DOS, CH_UNIX, state->msg,
77 talloc_get_size(state->msg), (void *)&msg,
79 DEBUG(3, ("Conversion failed, delivering message in DOS "
80 "codepage format\n"));
84 for (i = 0; i < len; i++) {
85 if ((msg[i] == '\r') &&
86 (i < (len-1)) && (msg[i+1] == '\n')) {
89 sz = write(fd, &msg[i], 1);
91 DEBUG(0, ("Write error to fd %d: %ld(%s)\n", fd,
92 (long)sz, strerror(errno)));
99 s = talloc_strdup(talloc_tos(), lp_msg_command());
104 alpha_strcpy(alpha_buf, state->from, NULL, sizeof(alpha_buf));
106 s = talloc_string_sub(talloc_tos(), s, "%f", alpha_buf);
111 alpha_strcpy(alpha_buf, state->to, NULL, sizeof(alpha_buf));
113 s = talloc_string_sub(talloc_tos(), s, "%t", alpha_buf);
118 s = talloc_sub_basic(talloc_tos(), current_user_info.smb_name,
119 current_user_info.domain, s);
124 s = talloc_string_sub(talloc_tos(), s, "%s", name);
135 /****************************************************************************
137 conn POINTER CAN BE NULL HERE !
138 ****************************************************************************/
140 void reply_sends(struct smb_request *req)
142 struct msg_state *state;
147 START_PROFILE(SMBsends);
149 if (!(*lp_msg_command())) {
150 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
151 END_PROFILE(SMBsends);
155 state = talloc(talloc_tos(), struct msg_state);
157 p = (const char *)req->buf + 1;
158 p += srvstr_pull_req_talloc(
159 state, req, &state->from, p, STR_ASCII|STR_TERMINATE) + 1;
160 p += srvstr_pull_req_talloc(
161 state, req, &state->to, p, STR_ASCII|STR_TERMINATE) + 1;
166 len = MIN(len, smbreq_bufrem(req, msg+2));
168 state->msg = talloc_array(state, char, len);
170 if (state->msg == NULL) {
171 reply_nterror(req, NT_STATUS_NO_MEMORY);
172 END_PROFILE(SMBsends);
176 memcpy(state->msg, msg+2, len);
180 reply_outbuf(req, 0, 0);
182 END_PROFILE(SMBsends);
186 /****************************************************************************
188 conn POINTER CAN BE NULL HERE !
189 ****************************************************************************/
191 void reply_sendstrt(struct smb_request *req)
195 START_PROFILE(SMBsendstrt);
197 if (!(*lp_msg_command())) {
198 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
199 END_PROFILE(SMBsendstrt);
203 TALLOC_FREE(smbd_msg_state);
205 smbd_msg_state = talloc_zero(NULL, struct msg_state);
207 if (smbd_msg_state == NULL) {
208 reply_nterror(req, NT_STATUS_NO_MEMORY);
209 END_PROFILE(SMBsendstrt);
213 p = (const char *)req->buf+1;
214 p += srvstr_pull_req_talloc(
215 smbd_msg_state, req, &smbd_msg_state->from, p,
216 STR_ASCII|STR_TERMINATE) + 1;
217 p += srvstr_pull_req_talloc(
218 smbd_msg_state, req, &smbd_msg_state->to, p,
219 STR_ASCII|STR_TERMINATE) + 1;
221 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", smbd_msg_state->from,
222 smbd_msg_state->to ) );
224 reply_outbuf(req, 0, 0);
226 END_PROFILE(SMBsendstrt);
230 /****************************************************************************
232 conn POINTER CAN BE NULL HERE !
233 ****************************************************************************/
235 void reply_sendtxt(struct smb_request *req)
242 START_PROFILE(SMBsendtxt);
244 if (! (*lp_msg_command())) {
245 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
246 END_PROFILE(SMBsendtxt);
250 if ((smbd_msg_state == NULL) || (req->buflen < 3)) {
251 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
252 END_PROFILE(SMBsendtxt);
256 msg = (const char *)req->buf + 1;
258 old_len = talloc_get_size(smbd_msg_state->msg);
260 len = MIN(SVAL(msg, 0), smbreq_bufrem(req, msg+2));
262 tmp = talloc_realloc(smbd_msg_state, smbd_msg_state->msg,
263 char, old_len + len);
266 reply_nterror(req, NT_STATUS_NO_MEMORY);
267 END_PROFILE(SMBsendtxt);
271 smbd_msg_state->msg = tmp;
273 memcpy(&smbd_msg_state->msg[old_len], msg+2, len);
275 DEBUG( 3, ( "SMBsendtxt\n" ) );
277 reply_outbuf(req, 0, 0);
279 END_PROFILE(SMBsendtxt);
283 /****************************************************************************
285 conn POINTER CAN BE NULL HERE !
286 ****************************************************************************/
288 void reply_sendend(struct smb_request *req)
290 START_PROFILE(SMBsendend);
292 if (! (*lp_msg_command())) {
293 reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
294 END_PROFILE(SMBsendend);
298 DEBUG(3,("SMBsendend\n"));
300 msg_deliver(smbd_msg_state);
302 TALLOC_FREE(smbd_msg_state);
304 reply_outbuf(req, 0, 0);
306 END_PROFILE(SMBsendend);