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
27 extern userdom_struct current_user_info;
35 static struct msg_state *smbd_msg_state;
37 /****************************************************************************
39 ****************************************************************************/
41 static void msg_deliver(struct msg_state *state)
43 TALLOC_CTX *frame = talloc_stackframe();
53 if (! (*lp_msg_command())) {
54 DEBUG(1,("no messaging command specified\n"));
58 /* put it in a temporary file */
59 name = talloc_asprintf(talloc_tos(), "%s/msg.XXXXXX", tmpdir());
63 fd = smb_mkstemp(name);
66 DEBUG(1, ("can't open message file %s: %s\n", name,
72 * Incoming message is in DOS codepage format. Convert to UNIX.
75 len = convert_string_talloc(
76 talloc_tos(), CH_DOS, CH_UNIX, state->msg,
77 talloc_get_size(state->msg), (void *)&msg, true);
80 DEBUG(3, ("Conversion failed, delivering message in DOS "
81 "codepage format\n"));
85 for (i = 0; i < len; i++) {
86 if ((msg[i] == '\r') && (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(connection_struct *conn, struct smb_request *req)
142 struct msg_state *state;
147 START_PROFILE(SMBsends);
149 if (!(*lp_msg_command())) {
150 reply_doserror(req, ERRSRV, ERRmsgoff);
151 END_PROFILE(SMBsends);
155 state = talloc(talloc_tos(), struct msg_state);
157 p = smb_buf(req->inbuf)+1;
158 p += srvstr_pull_buf_talloc(
159 state, (char *)req->inbuf, req->flags2, &state->from, p,
160 STR_ASCII|STR_TERMINATE) + 1;
161 p += srvstr_pull_buf_talloc(
162 state, (char *)req->inbuf, req->flags2, &state->to, p,
163 STR_ASCII|STR_TERMINATE) + 1;
168 len = MIN(len, smb_bufrem(req->inbuf, msg+2));
170 state->msg = talloc_array(state, char, len);
172 if (state->msg == NULL) {
173 reply_nterror(req, NT_STATUS_NO_MEMORY);
174 END_PROFILE(SMBsends);
178 memcpy(state->msg, msg+2, len);
182 reply_outbuf(req, 0, 0);
184 END_PROFILE(SMBsends);
188 /****************************************************************************
190 conn POINTER CAN BE NULL HERE !
191 ****************************************************************************/
193 void reply_sendstrt(connection_struct *conn, struct smb_request *req)
197 START_PROFILE(SMBsendstrt);
199 if (!(*lp_msg_command())) {
200 reply_doserror(req, ERRSRV, ERRmsgoff);
201 END_PROFILE(SMBsendstrt);
205 TALLOC_FREE(smbd_msg_state);
207 smbd_msg_state = TALLOC_ZERO_P(NULL, struct msg_state);
209 if (smbd_msg_state == NULL) {
210 reply_nterror(req, NT_STATUS_NO_MEMORY);
211 END_PROFILE(SMBsendstrt);
215 p = smb_buf(req->inbuf)+1;
216 p += srvstr_pull_buf_talloc(
217 smbd_msg_state, (char *)req->inbuf, req->flags2,
218 &smbd_msg_state->from, p, STR_ASCII|STR_TERMINATE) + 1;
219 p += srvstr_pull_buf_talloc(
220 smbd_msg_state, (char *)req->inbuf, req->flags2,
221 &smbd_msg_state->to, p, STR_ASCII|STR_TERMINATE) + 1;
223 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", smbd_msg_state->from,
224 smbd_msg_state->to ) );
226 reply_outbuf(req, 0, 0);
228 END_PROFILE(SMBsendstrt);
232 /****************************************************************************
234 conn POINTER CAN BE NULL HERE !
235 ****************************************************************************/
237 void reply_sendtxt(connection_struct *conn, struct smb_request *req)
244 START_PROFILE(SMBsendtxt);
246 if (! (*lp_msg_command())) {
247 reply_doserror(req, ERRSRV, ERRmsgoff);
248 END_PROFILE(SMBsendtxt);
252 if (smbd_msg_state == NULL) {
253 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
254 END_PROFILE(SMBsendtxt);
258 msg = smb_buf(req->inbuf) + 1;
260 old_len = talloc_get_size(smbd_msg_state->msg);
262 len = MIN(SVAL(msg, 0), smb_bufrem(req->inbuf, msg+2));
264 tmp = TALLOC_REALLOC_ARRAY(smbd_msg_state, smbd_msg_state->msg,
265 char, old_len + len);
268 reply_nterror(req, NT_STATUS_NO_MEMORY);
269 END_PROFILE(SMBsendtxt);
273 smbd_msg_state->msg = tmp;
275 memcpy(&smbd_msg_state->msg[old_len], msg+2, len);
277 DEBUG( 3, ( "SMBsendtxt\n" ) );
279 reply_outbuf(req, 0, 0);
281 END_PROFILE(SMBsendtxt);
285 /****************************************************************************
287 conn POINTER CAN BE NULL HERE !
288 ****************************************************************************/
290 void reply_sendend(connection_struct *conn, struct smb_request *req)
292 START_PROFILE(SMBsendend);
294 if (! (*lp_msg_command())) {
295 reply_doserror(req, ERRSRV, ERRmsgoff);
296 END_PROFILE(SMBsendend);
300 DEBUG(3,("SMBsendend\n"));
302 msg_deliver(smbd_msg_state);
304 TALLOC_FREE(smbd_msg_state);
306 reply_outbuf(req, 0, 0);
308 END_PROFILE(SMBsendend);