ctdb: Use str_list_add_printf() in lock_helper_args()
[samba.git] / source3 / smbd / smb1_process.c
index accda5368c4f8c61deb721b8805c5a7589f0d2b6..a1970b9e252a46281cb361d1235bab4edb2f5d5c 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    process incoming packets - main loop
    Copyright (C) Andrew Tridgell 1992-1998
@@ -23,6 +23,7 @@
 #include "system/filesys.h"
 #include "smbd/smbd.h"
 #include "smbd/globals.h"
+#include "source3/smbd/smbXsrv_session.h"
 #include "smbd/smbXsrv_open.h"
 #include "librpc/gen_ndr/netlogon.h"
 #include "../lib/async_req/async_sock.h"
@@ -56,7 +57,6 @@ struct pending_message_list {
        struct smbd_server_connection *sconn;
        struct smbXsrv_connection *xconn;
        struct tevent_timer *te;
-       struct smb_perfcount_data pcd;
        uint32_t seqnum;
        bool encrypted;
        bool processed;
@@ -208,14 +208,16 @@ void smbd_unlock_socket(struct smbXsrv_connection *xconn)
  Send an smb to a fd.
 ****************************************************************************/
 
-bool smb1_srv_send(struct smbXsrv_connection *xconn, char *buffer,
-                  bool do_signing, uint32_t seqnum,
-                  bool do_encrypt,
-                  struct smb_perfcount_data *pcd)
+bool smb1_srv_send(struct smbXsrv_connection *xconn,
+                  char *buffer,
+                  bool do_signing,
+                  uint32_t seqnum,
+                  bool do_encrypt)
 {
        size_t len = 0;
        ssize_t ret;
        char *buf_out = buffer;
+       char *encrypted_buf = NULL;
 
        if (!NT_STATUS_IS_OK(xconn->transport.status)) {
                /*
@@ -239,22 +241,21 @@ bool smb1_srv_send(struct smbXsrv_connection *xconn, char *buffer,
        }
 
        if (do_encrypt) {
-               char *enc = NULL;
-               NTSTATUS status = srv_encrypt_buffer(xconn, buffer, &enc);
+               NTSTATUS status = srv_encrypt_buffer(xconn, buffer, &encrypted_buf);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("send_smb: SMB encryption failed "
                                "on outgoing packet! Error %s\n",
                                nt_errstr(status) ));
-                       SAFE_FREE(enc);
                        ret = -1;
                        goto out;
                }
-               buf_out = enc;
+               buf_out = encrypted_buf;
        }
 
        len = smb_len_large(buf_out) + 4;
 
        ret = write_data(xconn->transport.sock, buf_out, len);
+       srv_free_enc_buffer(xconn, encrypted_buf);
        if (ret <= 0) {
                int saved_errno = errno;
                /*
@@ -267,11 +268,9 @@ bool smb1_srv_send(struct smbXsrv_connection *xconn, char *buffer,
                         (int)ret, strerror(saved_errno)));
                errno = saved_errno;
 
-               srv_free_enc_buffer(xconn, buf_out);
                goto out;
        }
 
-       srv_free_enc_buffer(xconn, buf_out);
 out:
        smbd_unlock_socket(xconn);
        return (ret > 0);
@@ -644,7 +643,7 @@ NTSTATUS allow_new_trans(struct trans_state *list, uint64_t mid)
 }
 
 /*
-These flags determine some of the permissions required to do an operation 
+These flags determine some of the permissions required to do an operation
 
 Note that I don't set NEED_WRITE on some write operations because they
 are used by some brain-dead clients when printing, and I don't want to
@@ -657,7 +656,7 @@ force write permissions on print services.
 #define AS_GUEST (1<<5) /* Must *NOT* be paired with AS_USER */
 #define DO_CHDIR (1<<6)
 
-/* 
+/*
    define a list of possible SMB messages and their corresponding
    functions. Any message that has a NULL function is unimplemented -
    please feel free to contribute implementations!
@@ -986,7 +985,7 @@ static void smb1srv_update_crypto_flags(struct smbXsrv_session *session,
                sign_flag = SMBXSRV_PROCESSED_SIGNED_PACKET;
        } else if ((type == SMBecho) || (type == SMBsesssetupX)) {
                /*
-                * echo can be unsigned. Sesssion setup except final
+                * echo can be unsigned. Session setup except final
                 * session setup response too
                 */
                sign_flag &= ~SMBXSRV_PROCESSED_UNSIGNED_PACKET;
@@ -1019,7 +1018,7 @@ static void set_current_case_sensitive(connection_struct *conn, uint16_t flags)
        enum remote_arch_types ra_type;
 
        SMB_ASSERT(conn != NULL);
-       SMB_ASSERT(!conn->sconn->using_smb2);
+       SMB_ASSERT(!conn_using_smb2(conn->sconn));
 
        snum = SNUM(conn);
 
@@ -1029,7 +1028,7 @@ static void set_current_case_sensitive(connection_struct *conn, uint16_t flags)
        switch (lp_case_sensitive(snum)) {
        case Auto:
                /*
-                * We need this uglyness due to DOS/Win9x clients that lie
+                * We need this ugliness due to DOS/Win9x clients that lie
                 * about case insensitivity. */
                ra_type = get_remote_arch();
                if ((ra_type != RA_SAMBA) && (ra_type != RA_CIFSFS)) {
@@ -1295,9 +1294,11 @@ static connection_struct *switch_message(uint8_t type, struct smb_request *req)
 ****************************************************************************/
 
 void construct_reply(struct smbXsrv_connection *xconn,
-                    char *inbuf, int size, size_t unread_bytes,
-                    uint32_t seqnum, bool encrypted,
-                    struct smb_perfcount_data *deferred_pcd)
+                    char *inbuf,
+                    int size,
+                    size_t unread_bytes,
+                    uint32_t seqnum,
+                    bool encrypted)
 {
        struct smbd_server_connection *sconn = xconn->client->sconn;
        struct smb_request *req;
@@ -1313,11 +1314,6 @@ void construct_reply(struct smbXsrv_connection *xconn,
 
        req->inbuf  = (uint8_t *)talloc_move(req, &inbuf);
 
-       /* we popped this message off the queue - keep original perf data */
-       if (deferred_pcd) {
-               req->pcd = *deferred_pcd;
-       }
-
        req->conn = switch_message(req->cmd, req);
 
        if (req->outbuf == NULL) {
@@ -1334,9 +1330,10 @@ void construct_reply(struct smbXsrv_connection *xconn,
 }
 
 static void construct_reply_chain(struct smbXsrv_connection *xconn,
-                                 char *inbuf, int size, uint32_t seqnum,
-                                 bool encrypted,
-                                 struct smb_perfcount_data *deferred_pcd)
+                                 char *inbuf,
+                                 int size,
+                                 uint32_t seqnum,
+                                 bool encrypted)
 {
        struct smb_request **reqs = NULL;
        struct smb_request *req;
@@ -1349,8 +1346,7 @@ static void construct_reply_chain(struct smbXsrv_connection *xconn,
                char errbuf[smb_size];
                error_packet(errbuf, 0, 0, NT_STATUS_INVALID_PARAMETER,
                             __LINE__, __FILE__);
-               if (!smb1_srv_send(xconn, errbuf, true, seqnum, encrypted,
-                                 NULL)) {
+               if (!smb1_srv_send(xconn, errbuf, true, seqnum, encrypted)) {
                        exit_server_cleanly("construct_reply_chain: "
                                            "smb1_srv_send failed.");
                }
@@ -1472,10 +1468,11 @@ void smb_request_done(struct smb_request *req)
 
 shipit:
        if (!smb1_srv_send(first_req->xconn,
-                         (char *)first_req->outbuf,
-                         true, first_req->seqnum+1,
-                         IS_CONN_ENCRYPTED(req->conn)||first_req->encrypted,
-                         &first_req->pcd)) {
+                          (char *)first_req->outbuf,
+                          true,
+                          first_req->seqnum + 1,
+                          IS_CONN_ENCRYPTED(req->conn) ||
+                                  first_req->encrypted)) {
                exit_server_cleanly("construct_reply_chain: smb1_srv_send "
                                    "failed.");
        }
@@ -1487,9 +1484,11 @@ error:
        {
                char errbuf[smb_size];
                error_packet(errbuf, 0, 0, status, __LINE__, __FILE__);
-               if (!smb1_srv_send(req->xconn, errbuf, true,
-                                 req->seqnum+1, req->encrypted,
-                                 NULL)) {
+               if (!smb1_srv_send(req->xconn,
+                                  errbuf,
+                                  true,
+                                  req->seqnum + 1,
+                                  req->encrypted)) {
                        exit_server_cleanly("construct_reply_chain: "
                                            "smb1_srv_send failed.");
                }
@@ -1503,9 +1502,11 @@ error:
 ****************************************************************************/
 
 void process_smb1(struct smbXsrv_connection *xconn,
-                 uint8_t *inbuf, size_t nread, size_t unread_bytes,
-                 uint32_t seqnum, bool encrypted,
-                 struct smb_perfcount_data *deferred_pcd)
+                 uint8_t *inbuf,
+                 size_t nread,
+                 size_t unread_bytes,
+                 uint32_t seqnum,
+                 bool encrypted)
 {
        struct smbd_server_connection *sconn = xconn->client->sconn;
 
@@ -1531,11 +1532,18 @@ void process_smb1(struct smbXsrv_connection *xconn,
        show_msg((char *)inbuf);
 
        if ((unread_bytes == 0) && smb1_is_chain(inbuf)) {
-               construct_reply_chain(xconn, (char *)inbuf, nread,
-                                     seqnum, encrypted, deferred_pcd);
+               construct_reply_chain(xconn,
+                                     (char *)inbuf,
+                                     nread,
+                                     seqnum,
+                                     encrypted);
        } else {
-               construct_reply(xconn, (char *)inbuf, nread, unread_bytes,
-                               seqnum, encrypted, deferred_pcd);
+               construct_reply(xconn,
+                               (char *)inbuf,
+                               nread,
+                               unread_bytes,
+                               seqnum,
+                               encrypted);
        }
 
        sconn->trans_num++;
@@ -2070,8 +2078,7 @@ void smbd_smb1_server_connection_read_handler(struct smbXsrv_connection *xconn,
        }
 
 process:
-       process_smb(xconn, inbuf, inbuf_len, unread_bytes,
-                   seqnum, encrypted, NULL);
+       process_smb(xconn, inbuf, inbuf_len, unread_bytes, seqnum, encrypted);
 }
 
 static void smbd_server_echo_handler(struct tevent_context *ev,
@@ -2113,7 +2120,7 @@ bool keepalive_fn(const struct timeval *now, void *private_data)
        struct smbXsrv_connection *xconn = NULL;
        bool ret;
 
-       if (sconn->using_smb2) {
+       if (conn_using_smb2(sconn)) {
                /* Don't do keepalives on an SMB2 connection. */
                return false;
        }
@@ -2392,8 +2399,7 @@ static bool smbd_echo_reply(struct smbd_echo_state *state,
        req.inbuf = inbuf;
 
        DEBUG(10, ("smbecho handler got cmd %d (%s)\n", (int)req.cmd,
-                  smb_messages[req.cmd].name
-                  ? smb_messages[req.cmd].name : "unknown"));
+                  smb_fn_name(req.cmd)));
 
        if (req.cmd != SMBecho) {
                return false;
@@ -2421,10 +2427,7 @@ static bool smbd_echo_reply(struct smbd_echo_state *state,
                memcpy(smb_buf(req.outbuf), req.buf, req.buflen);
        }
 
-       ok = smb1_srv_send(req.xconn,
-                         (char *)outbuf,
-                         true, seqnum+1,
-                         false, &req.pcd);
+       ok = smb1_srv_send(req.xconn, (char *)outbuf, true, seqnum + 1, false);
        TALLOC_FREE(outbuf);
        if (!ok) {
                exit(1);