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();
56 if (! (*lp_message_command(frame
))) {
57 DEBUG(1,("no messaging command specified\n"));
61 /* put it in a temporary file */
62 name
= talloc_asprintf(talloc_tos(), "%s/msg.XXXXXX", tmpdir());
66 mask
= umask(S_IRWXO
| S_IRWXG
);
71 DEBUG(1, ("can't open message file %s: %s\n", name
,
77 * Incoming message is in DOS codepage format. Convert to UNIX.
80 if (!convert_string_talloc(talloc_tos(), CH_DOS
, CH_UNIX
, state
->msg
,
81 talloc_get_size(state
->msg
), (void *)&msg
,
83 DEBUG(3, ("Conversion failed, delivering message in DOS "
84 "codepage format\n"));
88 for (i
= 0; i
< len
; i
++) {
89 if ((msg
[i
] == '\r') &&
90 (i
< (len
-1)) && (msg
[i
+1] == '\n')) {
93 sz
= write(fd
, &msg
[i
], 1);
95 DEBUG(0, ("Write error to fd %d: %ld(%s)\n", fd
,
96 (long)sz
, strerror(errno
)));
102 /* run the command */
103 s
= lp_message_command(frame
);
108 alpha_strcpy(alpha_buf
, state
->from
, NULL
, sizeof(alpha_buf
));
110 s
= talloc_string_sub(talloc_tos(), s
, "%f", alpha_buf
);
115 alpha_strcpy(alpha_buf
, state
->to
, NULL
, sizeof(alpha_buf
));
117 s
= talloc_string_sub(talloc_tos(), s
, "%t", alpha_buf
);
122 s
= talloc_sub_basic(talloc_tos(), current_user_info
.smb_name
,
123 current_user_info
.domain
, s
);
128 s
= talloc_string_sub(talloc_tos(), s
, "%s", name
);
139 /****************************************************************************
141 conn POINTER CAN BE NULL HERE !
142 ****************************************************************************/
144 void reply_sends(struct smb_request
*req
)
146 struct msg_state
*state
;
151 START_PROFILE(SMBsends
);
153 if (!(*lp_message_command(talloc_tos()))) {
154 reply_nterror(req
, NT_STATUS_REQUEST_NOT_ACCEPTED
);
155 END_PROFILE(SMBsends
);
159 state
= talloc(talloc_tos(), struct msg_state
);
162 p
+= srvstr_pull_req_talloc(
163 state
, req
, &state
->from
, p
, STR_ASCII
|STR_TERMINATE
) + 1;
164 p
+= srvstr_pull_req_talloc(
165 state
, req
, &state
->to
, p
, STR_ASCII
|STR_TERMINATE
) + 1;
170 len
= MIN(len
, smbreq_bufrem(req
, msg
+2));
172 state
->msg
= talloc_array(state
, char, len
);
174 if (state
->msg
== NULL
) {
175 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
176 END_PROFILE(SMBsends
);
180 memcpy(state
->msg
, msg
+2, len
);
184 reply_outbuf(req
, 0, 0);
186 END_PROFILE(SMBsends
);
190 /****************************************************************************
192 conn POINTER CAN BE NULL HERE !
193 ****************************************************************************/
195 void reply_sendstrt(struct smb_request
*req
)
199 START_PROFILE(SMBsendstrt
);
201 if (!(*lp_message_command(talloc_tos()))) {
202 reply_nterror(req
, NT_STATUS_REQUEST_NOT_ACCEPTED
);
203 END_PROFILE(SMBsendstrt
);
207 TALLOC_FREE(req
->sconn
->conn
->msg_state
);
209 req
->sconn
->conn
->msg_state
= talloc_zero(NULL
, struct msg_state
);
211 if (req
->sconn
->conn
->msg_state
== NULL
) {
212 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
213 END_PROFILE(SMBsendstrt
);
218 p
+= srvstr_pull_req_talloc(
219 req
->sconn
->conn
->msg_state
, req
,
220 &req
->sconn
->conn
->msg_state
->from
, p
,
221 STR_ASCII
|STR_TERMINATE
) + 1;
222 p
+= srvstr_pull_req_talloc(
223 req
->sconn
->conn
->msg_state
, req
,
224 &req
->sconn
->conn
->msg_state
->to
, p
,
225 STR_ASCII
|STR_TERMINATE
) + 1;
227 DEBUG(3, ("SMBsendstrt (from %s to %s)\n",
228 req
->sconn
->conn
->msg_state
->from
,
229 req
->sconn
->conn
->msg_state
->to
));
231 reply_outbuf(req
, 0, 0);
233 END_PROFILE(SMBsendstrt
);
237 /****************************************************************************
239 conn POINTER CAN BE NULL HERE !
240 ****************************************************************************/
242 void reply_sendtxt(struct smb_request
*req
)
249 START_PROFILE(SMBsendtxt
);
251 if (! (*lp_message_command(talloc_tos()))) {
252 reply_nterror(req
, NT_STATUS_REQUEST_NOT_ACCEPTED
);
253 END_PROFILE(SMBsendtxt
);
257 if ((req
->sconn
->conn
->msg_state
== NULL
) || (req
->buflen
< 3)) {
258 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
259 END_PROFILE(SMBsendtxt
);
263 msg
= (const char *)req
->buf
+ 1;
265 old_len
= talloc_get_size(req
->sconn
->conn
->msg_state
->msg
);
267 len
= MIN(SVAL(msg
, 0), smbreq_bufrem(req
, msg
+2));
269 tmp
= talloc_realloc(req
->sconn
->conn
->msg_state
,
270 req
->sconn
->conn
->msg_state
->msg
,
271 char, old_len
+ len
);
274 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
275 END_PROFILE(SMBsendtxt
);
279 req
->sconn
->conn
->msg_state
->msg
= tmp
;
281 memcpy(&req
->sconn
->conn
->msg_state
->msg
[old_len
], msg
+2, len
);
283 DEBUG( 3, ( "SMBsendtxt\n" ) );
285 reply_outbuf(req
, 0, 0);
287 END_PROFILE(SMBsendtxt
);
291 /****************************************************************************
293 conn POINTER CAN BE NULL HERE !
294 ****************************************************************************/
296 void reply_sendend(struct smb_request
*req
)
298 START_PROFILE(SMBsendend
);
300 if (! (*lp_message_command(talloc_tos()))) {
301 reply_nterror(req
, NT_STATUS_REQUEST_NOT_ACCEPTED
);
302 END_PROFILE(SMBsendend
);
306 DEBUG(3,("SMBsendend\n"));
308 msg_deliver(req
->sconn
->conn
->msg_state
);
310 TALLOC_FREE(req
->sconn
->conn
->msg_state
);
312 reply_outbuf(req
, 0, 0);
314 END_PROFILE(SMBsendend
);