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/globals.h"
28 extern userdom_struct current_user_info
;
36 /****************************************************************************
38 ****************************************************************************/
40 static void msg_deliver(struct msg_state
*state
)
42 TALLOC_CTX
*frame
= talloc_stackframe();
52 if (! (*lp_msg_command())) {
53 DEBUG(1,("no messaging command specified\n"));
57 /* put it in a temporary file */
58 name
= talloc_asprintf(talloc_tos(), "%s/msg.XXXXXX", tmpdir());
62 fd
= smb_mkstemp(name
);
65 DEBUG(1, ("can't open message file %s: %s\n", name
,
71 * Incoming message is in DOS codepage format. Convert to UNIX.
74 if (!convert_string_talloc(talloc_tos(), CH_DOS
, CH_UNIX
, state
->msg
,
75 talloc_get_size(state
->msg
), (void *)&msg
,
77 DEBUG(3, ("Conversion failed, delivering message in DOS "
78 "codepage format\n"));
82 for (i
= 0; i
< len
; i
++) {
83 if ((msg
[i
] == '\r') &&
84 (i
< (len
-1)) && (msg
[i
+1] == '\n')) {
87 sz
= write(fd
, &msg
[i
], 1);
89 DEBUG(0, ("Write error to fd %d: %ld(%s)\n", fd
,
90 (long)sz
, strerror(errno
)));
97 s
= talloc_strdup(talloc_tos(), lp_msg_command());
102 alpha_strcpy(alpha_buf
, state
->from
, NULL
, sizeof(alpha_buf
));
104 s
= talloc_string_sub(talloc_tos(), s
, "%f", alpha_buf
);
109 alpha_strcpy(alpha_buf
, state
->to
, NULL
, sizeof(alpha_buf
));
111 s
= talloc_string_sub(talloc_tos(), s
, "%t", alpha_buf
);
116 s
= talloc_sub_basic(talloc_tos(), current_user_info
.smb_name
,
117 current_user_info
.domain
, s
);
122 s
= talloc_string_sub(talloc_tos(), s
, "%s", name
);
133 /****************************************************************************
135 conn POINTER CAN BE NULL HERE !
136 ****************************************************************************/
138 void reply_sends(struct smb_request
*req
)
140 struct msg_state
*state
;
145 START_PROFILE(SMBsends
);
147 if (!(*lp_msg_command())) {
148 reply_doserror(req
, ERRSRV
, ERRmsgoff
);
149 END_PROFILE(SMBsends
);
153 state
= talloc(talloc_tos(), struct msg_state
);
155 p
= (const char *)req
->buf
+ 1;
156 p
+= srvstr_pull_req_talloc(
157 state
, req
, &state
->from
, p
, STR_ASCII
|STR_TERMINATE
) + 1;
158 p
+= srvstr_pull_req_talloc(
159 state
, req
, &state
->to
, p
, STR_ASCII
|STR_TERMINATE
) + 1;
164 len
= MIN(len
, smbreq_bufrem(req
, msg
+2));
166 state
->msg
= talloc_array(state
, char, len
);
168 if (state
->msg
== NULL
) {
169 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
170 END_PROFILE(SMBsends
);
174 memcpy(state
->msg
, msg
+2, len
);
178 reply_outbuf(req
, 0, 0);
180 END_PROFILE(SMBsends
);
184 /****************************************************************************
186 conn POINTER CAN BE NULL HERE !
187 ****************************************************************************/
189 void reply_sendstrt(struct smb_request
*req
)
193 START_PROFILE(SMBsendstrt
);
195 if (!(*lp_msg_command())) {
196 reply_doserror(req
, ERRSRV
, ERRmsgoff
);
197 END_PROFILE(SMBsendstrt
);
201 TALLOC_FREE(smbd_msg_state
);
203 smbd_msg_state
= TALLOC_ZERO_P(NULL
, struct msg_state
);
205 if (smbd_msg_state
== NULL
) {
206 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
207 END_PROFILE(SMBsendstrt
);
211 p
= (const char *)req
->buf
+1;
212 p
+= srvstr_pull_req_talloc(
213 smbd_msg_state
, req
, &smbd_msg_state
->from
, p
,
214 STR_ASCII
|STR_TERMINATE
) + 1;
215 p
+= srvstr_pull_req_talloc(
216 smbd_msg_state
, req
, &smbd_msg_state
->to
, p
,
217 STR_ASCII
|STR_TERMINATE
) + 1;
219 DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", smbd_msg_state
->from
,
220 smbd_msg_state
->to
) );
222 reply_outbuf(req
, 0, 0);
224 END_PROFILE(SMBsendstrt
);
228 /****************************************************************************
230 conn POINTER CAN BE NULL HERE !
231 ****************************************************************************/
233 void reply_sendtxt(struct smb_request
*req
)
240 START_PROFILE(SMBsendtxt
);
242 if (! (*lp_msg_command())) {
243 reply_doserror(req
, ERRSRV
, ERRmsgoff
);
244 END_PROFILE(SMBsendtxt
);
248 if (smbd_msg_state
== NULL
) {
249 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
250 END_PROFILE(SMBsendtxt
);
254 msg
= (const char *)req
->buf
+ 1;
256 old_len
= talloc_get_size(smbd_msg_state
->msg
);
258 len
= MIN(SVAL(msg
, 0), smbreq_bufrem(req
, msg
+2));
260 tmp
= TALLOC_REALLOC_ARRAY(smbd_msg_state
, smbd_msg_state
->msg
,
261 char, old_len
+ len
);
264 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
265 END_PROFILE(SMBsendtxt
);
269 smbd_msg_state
->msg
= tmp
;
271 memcpy(&smbd_msg_state
->msg
[old_len
], msg
+2, len
);
273 DEBUG( 3, ( "SMBsendtxt\n" ) );
275 reply_outbuf(req
, 0, 0);
277 END_PROFILE(SMBsendtxt
);
281 /****************************************************************************
283 conn POINTER CAN BE NULL HERE !
284 ****************************************************************************/
286 void reply_sendend(struct smb_request
*req
)
288 START_PROFILE(SMBsendend
);
290 if (! (*lp_msg_command())) {
291 reply_doserror(req
, ERRSRV
, ERRmsgoff
);
292 END_PROFILE(SMBsendend
);
296 DEBUG(3,("SMBsendend\n"));
298 msg_deliver(smbd_msg_state
);
300 TALLOC_FREE(smbd_msg_state
);
302 reply_outbuf(req
, 0, 0);
304 END_PROFILE(SMBsendend
);