s3/smbd: update some more DEBUG macros in smbd_smb2_create_send
[nivanova/samba-autobuild/.git] / source3 / smbd / message.c
index d0b524da0e65adbb39aa70f2d3fcbf11606d6feb..1c3976dd3e9edb822cd200d4f9d8db5bed4c6112 100644 (file)
 
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
+#include "smbd/globals.h"
+#include "smbprofile.h"
 
 extern userdom_struct current_user_info;
 
@@ -32,8 +36,6 @@ struct msg_state {
        char *msg;
 };
 
-static struct msg_state *smbd_msg_state;
-
 /****************************************************************************
  Deliver the message.
 ****************************************************************************/
@@ -45,12 +47,13 @@ static void msg_deliver(struct msg_state *state)
        int i;
        int fd;
        char *msg;
-       int len;
+       size_t len;
        ssize_t sz;
        fstring alpha_buf;
        char *s;
+       mode_t mask;
 
-       if (! (*lp_msg_command())) {
+       if (! (*lp_message_command(frame))) {
                DEBUG(1,("no messaging command specified\n"));
                goto done;
        }
@@ -60,7 +63,9 @@ static void msg_deliver(struct msg_state *state)
        if (!name) {
                goto done;
        }
-       fd = smb_mkstemp(name);
+       mask = umask(S_IRWXO | S_IRWXG);
+       fd = mkstemp(name);
+       umask(mask);
 
        if (fd == -1) {
                DEBUG(1, ("can't open message file %s: %s\n", name,
@@ -72,18 +77,17 @@ static void msg_deliver(struct msg_state *state)
         * Incoming message is in DOS codepage format. Convert to UNIX.
         */
 
-       len = convert_string_talloc(
-               talloc_tos(), CH_DOS, CH_UNIX, state->msg,
-               talloc_get_size(state->msg), (void *)&msg, true);
-
-       if (len == -1) {
+       if (!convert_string_talloc(talloc_tos(), CH_DOS, CH_UNIX, state->msg,
+                                  talloc_get_size(state->msg), (void *)&msg,
+                                  &len)) {
                DEBUG(3, ("Conversion failed, delivering message in DOS "
                          "codepage format\n"));
                msg = state->msg;
        }
 
        for (i = 0; i < len; i++) {
-               if ((msg[i] == '\r') && (i < (len-1)) && (msg[i+1] == '\n')) {
+               if ((msg[i] == '\r') &&
+                   (i < (len-1)) && (msg[i+1] == '\n')) {
                        continue;
                }
                sz = write(fd, &msg[i], 1);
@@ -96,7 +100,7 @@ static void msg_deliver(struct msg_state *state)
        close(fd);
 
        /* run the command */
-       s = talloc_strdup(talloc_tos(), lp_msg_command());
+       s = lp_message_command(frame);
        if (s == NULL) {
                goto done;
        }
@@ -125,7 +129,7 @@ static void msg_deliver(struct msg_state *state)
        if (s == NULL) {
                goto done;
        }
-       smbrun(s,NULL);
+       smbrun(s, NULL, NULL);
 
  done:
        TALLOC_FREE(frame);
@@ -137,35 +141,33 @@ static void msg_deliver(struct msg_state *state)
  conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
-void reply_sends(connection_struct *conn, struct smb_request *req)
+void reply_sends(struct smb_request *req)
 {
        struct msg_state *state;
        int len;
-       char *msg;
-       char *p;
+       const uint8_t *msg;
+       const uint8_t *p;
 
        START_PROFILE(SMBsends);
 
-       if (!(*lp_msg_command())) {
-               reply_doserror(req, ERRSRV, ERRmsgoff);
+       if (!(*lp_message_command(talloc_tos()))) {
+               reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
                END_PROFILE(SMBsends);
                return;
        }
 
        state = talloc(talloc_tos(), struct msg_state);
 
-       p = smb_buf(req->inbuf)+1;
-       p += srvstr_pull_buf_talloc(
-               state, (char *)req->inbuf, req->flags2, &state->from, p,
-               STR_ASCII|STR_TERMINATE) + 1;
-       p += srvstr_pull_buf_talloc(
-               state, (char *)req->inbuf, req->flags2, &state->to, p,
-               STR_ASCII|STR_TERMINATE) + 1;
+       p = req->buf + 1;
+       p += srvstr_pull_req_talloc(
+               state, req, &state->from, p, STR_ASCII|STR_TERMINATE) + 1;
+       p += srvstr_pull_req_talloc(
+               state, req, &state->to, p, STR_ASCII|STR_TERMINATE) + 1;
 
        msg = p;
 
        len = SVAL(msg,0);
-       len = MIN(len, smb_bufrem(req->inbuf, msg+2));
+       len = MIN(len, smbreq_bufrem(req, msg+2));
 
        state->msg = talloc_array(state, char, len);
 
@@ -190,38 +192,42 @@ void reply_sends(connection_struct *conn, struct smb_request *req)
  conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
-void reply_sendstrt(connection_struct *conn, struct smb_request *req)
+void reply_sendstrt(struct smb_request *req)
 {
-       char *p;
+       struct smbXsrv_connection *xconn = req->xconn;
+       const uint8_t *p;
 
        START_PROFILE(SMBsendstrt);
 
-       if (!(*lp_msg_command())) {
-               reply_doserror(req, ERRSRV, ERRmsgoff);
+       if (!(*lp_message_command(talloc_tos()))) {
+               reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
                END_PROFILE(SMBsendstrt);
                return;
        }
 
-       TALLOC_FREE(smbd_msg_state);
+       TALLOC_FREE(xconn->smb1.msg_state);
 
-       smbd_msg_state = TALLOC_ZERO_P(NULL, struct msg_state);
+       xconn->smb1.msg_state = talloc_zero(xconn, struct msg_state);
 
-       if (smbd_msg_state == NULL) {
+       if (xconn->smb1.msg_state == NULL) {
                reply_nterror(req, NT_STATUS_NO_MEMORY);
                END_PROFILE(SMBsendstrt);
                return;
        }
 
-       p = smb_buf(req->inbuf)+1;
-       p += srvstr_pull_buf_talloc(
-               smbd_msg_state, (char *)req->inbuf, req->flags2,
-               &smbd_msg_state->from, p, STR_ASCII|STR_TERMINATE) + 1;
-       p += srvstr_pull_buf_talloc(
-               smbd_msg_state, (char *)req->inbuf, req->flags2,
-               &smbd_msg_state->to, p, STR_ASCII|STR_TERMINATE) + 1;
+       p = req->buf+1;
+       p += srvstr_pull_req_talloc(
+               xconn->smb1.msg_state, req,
+               &xconn->smb1.msg_state->from, p,
+               STR_ASCII|STR_TERMINATE) + 1;
+       p += srvstr_pull_req_talloc(
+               xconn->smb1.msg_state, req,
+               &xconn->smb1.msg_state->to, p,
+               STR_ASCII|STR_TERMINATE) + 1;
 
-       DEBUG( 3, ( "SMBsendstrt (from %s to %s)\n", smbd_msg_state->from,
-                   smbd_msg_state->to ) );
+       DEBUG(3, ("SMBsendstrt (from %s to %s)\n",
+                 xconn->smb1.msg_state->from,
+                 xconn->smb1.msg_state->to));
 
        reply_outbuf(req, 0, 0);
 
@@ -234,35 +240,37 @@ void reply_sendstrt(connection_struct *conn, struct smb_request *req)
  conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
-void reply_sendtxt(connection_struct *conn, struct smb_request *req)
+void reply_sendtxt(struct smb_request *req)
 {
+       struct smbXsrv_connection *xconn = req->xconn;
        int len;
-       char *msg;
+       const char *msg;
        char *tmp;
        size_t old_len;
 
        START_PROFILE(SMBsendtxt);
 
-       if (! (*lp_msg_command())) {
-               reply_doserror(req, ERRSRV, ERRmsgoff);
+       if (! (*lp_message_command(talloc_tos()))) {
+               reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
                END_PROFILE(SMBsendtxt);
                return;
        }
 
-       if (smbd_msg_state == NULL) {
+       if ((xconn->smb1.msg_state == NULL) || (req->buflen < 3)) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
                END_PROFILE(SMBsendtxt);
                return;
        }
 
-       msg = smb_buf(req->inbuf) + 1;
+       msg = (const char *)req->buf + 1;
 
-       old_len = talloc_get_size(smbd_msg_state->msg);
+       old_len = talloc_get_size(xconn->smb1.msg_state->msg);
 
-       len = MIN(SVAL(msg, 0), smb_bufrem(req->inbuf, msg+2));
+       len = MIN(SVAL(msg, 0), smbreq_bufrem(req, msg+2));
 
-       tmp = TALLOC_REALLOC_ARRAY(smbd_msg_state, smbd_msg_state->msg,
-                                  char, old_len + len);
+       tmp = talloc_realloc(xconn->smb1.msg_state,
+                            xconn->smb1.msg_state->msg,
+                            char, old_len + len);
 
        if (tmp == NULL) {
                reply_nterror(req, NT_STATUS_NO_MEMORY);
@@ -270,9 +278,9 @@ void reply_sendtxt(connection_struct *conn, struct smb_request *req)
                return;
        }
 
-       smbd_msg_state->msg = tmp;
+       xconn->smb1.msg_state->msg = tmp;
 
-       memcpy(&smbd_msg_state->msg[old_len], msg+2, len);
+       memcpy(&xconn->smb1.msg_state->msg[old_len], msg+2, len);
 
        DEBUG( 3, ( "SMBsendtxt\n" ) );
 
@@ -287,21 +295,22 @@ void reply_sendtxt(connection_struct *conn, struct smb_request *req)
  conn POINTER CAN BE NULL HERE !
 ****************************************************************************/
 
-void reply_sendend(connection_struct *conn, struct smb_request *req)
+void reply_sendend(struct smb_request *req)
 {
+       struct smbXsrv_connection *xconn = req->xconn;
        START_PROFILE(SMBsendend);
 
-       if (! (*lp_msg_command())) {
-               reply_doserror(req, ERRSRV, ERRmsgoff);
+       if (! (*lp_message_command(talloc_tos()))) {
+               reply_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED);
                END_PROFILE(SMBsendend);
                return;
        }
 
        DEBUG(3,("SMBsendend\n"));
 
-       msg_deliver(smbd_msg_state);
+       msg_deliver(xconn->smb1.msg_state);
 
-       TALLOC_FREE(smbd_msg_state);
+       TALLOC_FREE(xconn->smb1.msg_state);
 
        reply_outbuf(req, 0, 0);