-/*
+/*
Unix SMB/CIFS implementation.
process incoming packets - main loop
Copyright (C) Andrew Tridgell 1992-1998
#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"
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;
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)) {
/*
}
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;
/*
(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);
}
/*
-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
#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!
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;
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);
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)) {
****************************************************************************/
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;
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) {
}
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;
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.");
}
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.");
}
{
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.");
}
****************************************************************************/
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;
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++;
}
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,
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;
}
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;
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);