idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
1,900
|
const uint8_t *smb1cli_conn_server_challenge(struct smbXcli_conn *conn)
{
return conn->smb1.server.challenge;
}
| null | 0
|
const uint8_t *smb1cli_conn_server_challenge(struct smbXcli_conn *conn)
{
return conn->smb1.server.challenge;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,901
|
bool smb1cli_conn_server_lockread(struct smbXcli_conn *conn)
{
return conn->smb1.server.lockread;
}
| null | 0
|
bool smb1cli_conn_server_lockread(struct smbXcli_conn *conn)
{
return conn->smb1.server.lockread;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,902
|
bool smb1cli_conn_server_readbraw(struct smbXcli_conn *conn)
{
return conn->smb1.server.readbraw;
}
| null | 0
|
bool smb1cli_conn_server_readbraw(struct smbXcli_conn *conn)
{
return conn->smb1.server.readbraw;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,903
|
uint16_t smb1cli_conn_server_security_mode(struct smbXcli_conn *conn)
{
return conn->smb1.server.security_mode;
}
| null | 0
|
uint16_t smb1cli_conn_server_security_mode(struct smbXcli_conn *conn)
{
return conn->smb1.server.security_mode;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,904
|
uint32_t smb1cli_conn_server_session_key(struct smbXcli_conn *conn)
{
return conn->smb1.server.session_key;
}
| null | 0
|
uint32_t smb1cli_conn_server_session_key(struct smbXcli_conn *conn)
{
return conn->smb1.server.session_key;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,905
|
bool smb1cli_conn_server_writebraw(struct smbXcli_conn *conn)
{
return conn->smb1.server.writebraw;
}
| null | 0
|
bool smb1cli_conn_server_writebraw(struct smbXcli_conn *conn)
{
return conn->smb1.server.writebraw;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,906
|
bool smb1cli_conn_server_writeunlock(struct smbXcli_conn *conn)
{
return conn->smb1.server.writeunlock;
}
| null | 0
|
bool smb1cli_conn_server_writeunlock(struct smbXcli_conn *conn)
{
return conn->smb1.server.writeunlock;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,907
|
void smb1cli_conn_set_encryption(struct smbXcli_conn *conn,
struct smb_trans_enc_state *es)
{
/* Replace the old state, if any. */
if (conn->smb1.trans_enc) {
TALLOC_FREE(conn->smb1.trans_enc);
}
conn->smb1.trans_enc = es;
}
| null | 0
|
void smb1cli_conn_set_encryption(struct smbXcli_conn *conn,
struct smb_trans_enc_state *es)
{
/* Replace the old state, if any. */
if (conn->smb1.trans_enc) {
TALLOC_FREE(conn->smb1.trans_enc);
}
conn->smb1.trans_enc = es;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,908
|
bool smb1cli_conn_signing_is_active(struct smbXcli_conn *conn)
{
return smb_signing_is_active(conn->smb1.signing);
}
| null | 0
|
bool smb1cli_conn_signing_is_active(struct smbXcli_conn *conn)
{
return smb_signing_is_active(conn->smb1.signing);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,909
|
static NTSTATUS smb1cli_conn_signv(struct smbXcli_conn *conn,
struct iovec *iov, int iov_count,
uint32_t *seqnum,
bool one_way_seqnum)
{
TALLOC_CTX *frame = NULL;
uint8_t *buf;
/*
* Obvious optimization: Make cli_calculate_sign_mac work with struct
* iovec directly. MD5Update would do that just fine.
*/
if (iov_count < 4) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[0].iov_len != NBT_HDR_SIZE) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[1].iov_len != (MIN_SMB_SIZE-sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[2].iov_len > (0xFF * sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[3].iov_len != sizeof(uint16_t)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
frame = talloc_stackframe();
buf = smbXcli_iov_concat(frame, &iov[1], iov_count - 1);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
*seqnum = smb_signing_next_seqnum(conn->smb1.signing,
one_way_seqnum);
smb_signing_sign_pdu(conn->smb1.signing,
buf, talloc_get_size(buf),
*seqnum);
memcpy(iov[1].iov_base, buf, iov[1].iov_len);
TALLOC_FREE(frame);
return NT_STATUS_OK;
}
| null | 0
|
static NTSTATUS smb1cli_conn_signv(struct smbXcli_conn *conn,
struct iovec *iov, int iov_count,
uint32_t *seqnum,
bool one_way_seqnum)
{
TALLOC_CTX *frame = NULL;
uint8_t *buf;
/*
* Obvious optimization: Make cli_calculate_sign_mac work with struct
* iovec directly. MD5Update would do that just fine.
*/
if (iov_count < 4) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[0].iov_len != NBT_HDR_SIZE) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[1].iov_len != (MIN_SMB_SIZE-sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[2].iov_len > (0xFF * sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[3].iov_len != sizeof(uint16_t)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
frame = talloc_stackframe();
buf = smbXcli_iov_concat(frame, &iov[1], iov_count - 1);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
*seqnum = smb_signing_next_seqnum(conn->smb1.signing,
one_way_seqnum);
smb_signing_sign_pdu(conn->smb1.signing,
buf, talloc_get_size(buf),
*seqnum);
memcpy(iov[1].iov_base, buf, iov[1].iov_len);
TALLOC_FREE(frame);
return NT_STATUS_OK;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,910
|
static NTSTATUS smb1cli_inbuf_parse_chain(uint8_t *buf, TALLOC_CTX *mem_ctx,
struct iovec **piov, int *pnum_iov)
{
struct iovec *iov;
int num_iov;
size_t buflen;
size_t taken;
size_t remaining;
uint8_t *hdr;
uint8_t cmd;
uint32_t wct_ofs;
NTSTATUS status;
size_t min_size = MIN_SMB_SIZE;
buflen = smb_len_tcp(buf);
taken = 0;
hdr = buf + NBT_HDR_SIZE;
status = smb1cli_pull_raw_error(hdr);
if (NT_STATUS_IS_ERR(status)) {
/*
* This is an ugly hack to support OS/2
* which skips the byte_count in the DATA block
* on some error responses.
*
* See bug #9096
*/
min_size -= sizeof(uint16_t);
}
if (buflen < min_size) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
/*
* This returns iovec elements in the following order:
*
* - SMB header
*
* - Parameter Block
* - Data Block
*
* - Parameter Block
* - Data Block
*
* - Parameter Block
* - Data Block
*/
num_iov = 1;
iov = talloc_array(mem_ctx, struct iovec, num_iov);
if (iov == NULL) {
return NT_STATUS_NO_MEMORY;
}
iov[0].iov_base = hdr;
iov[0].iov_len = HDR_WCT;
taken += HDR_WCT;
cmd = CVAL(hdr, HDR_COM);
wct_ofs = HDR_WCT;
while (true) {
size_t len = buflen - taken;
struct iovec *cur;
struct iovec *iov_tmp;
uint8_t wct;
uint32_t bcc_ofs;
uint16_t bcc;
size_t needed;
/*
* we need at least WCT
*/
needed = sizeof(uint8_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
/*
* Now we check if the specified words are there
*/
wct = CVAL(hdr, wct_ofs);
needed += wct * sizeof(uint16_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
if ((num_iov == 1) &&
(len == needed) &&
NT_STATUS_IS_ERR(status))
{
/*
* This is an ugly hack to support OS/2
* which skips the byte_count in the DATA block
* on some error responses.
*
* See bug #9096
*/
iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec,
num_iov + 2);
if (iov_tmp == NULL) {
TALLOC_FREE(iov);
return NT_STATUS_NO_MEMORY;
}
iov = iov_tmp;
cur = &iov[num_iov];
num_iov += 2;
cur[0].iov_len = 0;
cur[0].iov_base = hdr + (wct_ofs + sizeof(uint8_t));
cur[1].iov_len = 0;
cur[1].iov_base = cur[0].iov_base;
taken += needed;
break;
}
/*
* we need at least BCC
*/
needed += sizeof(uint16_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
/*
* Now we check if the specified bytes are there
*/
bcc_ofs = wct_ofs + sizeof(uint8_t) + wct * sizeof(uint16_t);
bcc = SVAL(hdr, bcc_ofs);
needed += bcc * sizeof(uint8_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
/*
* we allocate 2 iovec structures for words and bytes
*/
iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec,
num_iov + 2);
if (iov_tmp == NULL) {
TALLOC_FREE(iov);
return NT_STATUS_NO_MEMORY;
}
iov = iov_tmp;
cur = &iov[num_iov];
num_iov += 2;
cur[0].iov_len = wct * sizeof(uint16_t);
cur[0].iov_base = hdr + (wct_ofs + sizeof(uint8_t));
cur[1].iov_len = bcc * sizeof(uint8_t);
cur[1].iov_base = hdr + (bcc_ofs + sizeof(uint16_t));
taken += needed;
if (!smb1cli_is_andx_req(cmd)) {
/*
* If the current command does not have AndX chanining
* we are done.
*/
break;
}
if (wct == 0 && bcc == 0) {
/*
* An empty response also ends the chain,
* most likely with an error.
*/
break;
}
if (wct < 2) {
DEBUG(10, ("%s: wct[%d] < 2 for cmd[0x%02X]\n",
__location__, (int)wct, (int)cmd));
goto inval;
}
cmd = CVAL(cur[0].iov_base, 0);
if (cmd == 0xFF) {
/*
* If it is the end of the chain we are also done.
*/
break;
}
wct_ofs = SVAL(cur[0].iov_base, 2);
if (wct_ofs < taken) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
if (wct_ofs > buflen) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
/*
* we consumed everything up to the start of the next
* parameter block.
*/
taken = wct_ofs;
}
remaining = buflen - taken;
if (remaining > 0 && num_iov >= 3) {
/*
* The last DATA block gets the remaining
* bytes, this is needed to support
* CAP_LARGE_WRITEX and CAP_LARGE_READX.
*/
iov[num_iov-1].iov_len += remaining;
}
*piov = iov;
*pnum_iov = num_iov;
return NT_STATUS_OK;
inval:
TALLOC_FREE(iov);
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
| null | 0
|
static NTSTATUS smb1cli_inbuf_parse_chain(uint8_t *buf, TALLOC_CTX *mem_ctx,
struct iovec **piov, int *pnum_iov)
{
struct iovec *iov;
int num_iov;
size_t buflen;
size_t taken;
size_t remaining;
uint8_t *hdr;
uint8_t cmd;
uint32_t wct_ofs;
NTSTATUS status;
size_t min_size = MIN_SMB_SIZE;
buflen = smb_len_tcp(buf);
taken = 0;
hdr = buf + NBT_HDR_SIZE;
status = smb1cli_pull_raw_error(hdr);
if (NT_STATUS_IS_ERR(status)) {
/*
* This is an ugly hack to support OS/2
* which skips the byte_count in the DATA block
* on some error responses.
*
* See bug #9096
*/
min_size -= sizeof(uint16_t);
}
if (buflen < min_size) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
/*
* This returns iovec elements in the following order:
*
* - SMB header
*
* - Parameter Block
* - Data Block
*
* - Parameter Block
* - Data Block
*
* - Parameter Block
* - Data Block
*/
num_iov = 1;
iov = talloc_array(mem_ctx, struct iovec, num_iov);
if (iov == NULL) {
return NT_STATUS_NO_MEMORY;
}
iov[0].iov_base = hdr;
iov[0].iov_len = HDR_WCT;
taken += HDR_WCT;
cmd = CVAL(hdr, HDR_COM);
wct_ofs = HDR_WCT;
while (true) {
size_t len = buflen - taken;
struct iovec *cur;
struct iovec *iov_tmp;
uint8_t wct;
uint32_t bcc_ofs;
uint16_t bcc;
size_t needed;
/*
* we need at least WCT
*/
needed = sizeof(uint8_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
/*
* Now we check if the specified words are there
*/
wct = CVAL(hdr, wct_ofs);
needed += wct * sizeof(uint16_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
if ((num_iov == 1) &&
(len == needed) &&
NT_STATUS_IS_ERR(status))
{
/*
* This is an ugly hack to support OS/2
* which skips the byte_count in the DATA block
* on some error responses.
*
* See bug #9096
*/
iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec,
num_iov + 2);
if (iov_tmp == NULL) {
TALLOC_FREE(iov);
return NT_STATUS_NO_MEMORY;
}
iov = iov_tmp;
cur = &iov[num_iov];
num_iov += 2;
cur[0].iov_len = 0;
cur[0].iov_base = hdr + (wct_ofs + sizeof(uint8_t));
cur[1].iov_len = 0;
cur[1].iov_base = cur[0].iov_base;
taken += needed;
break;
}
/*
* we need at least BCC
*/
needed += sizeof(uint16_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
/*
* Now we check if the specified bytes are there
*/
bcc_ofs = wct_ofs + sizeof(uint8_t) + wct * sizeof(uint16_t);
bcc = SVAL(hdr, bcc_ofs);
needed += bcc * sizeof(uint8_t);
if (len < needed) {
DEBUG(10, ("%s: %d bytes left, expected at least %d\n",
__location__, (int)len, (int)needed));
goto inval;
}
/*
* we allocate 2 iovec structures for words and bytes
*/
iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec,
num_iov + 2);
if (iov_tmp == NULL) {
TALLOC_FREE(iov);
return NT_STATUS_NO_MEMORY;
}
iov = iov_tmp;
cur = &iov[num_iov];
num_iov += 2;
cur[0].iov_len = wct * sizeof(uint16_t);
cur[0].iov_base = hdr + (wct_ofs + sizeof(uint8_t));
cur[1].iov_len = bcc * sizeof(uint8_t);
cur[1].iov_base = hdr + (bcc_ofs + sizeof(uint16_t));
taken += needed;
if (!smb1cli_is_andx_req(cmd)) {
/*
* If the current command does not have AndX chanining
* we are done.
*/
break;
}
if (wct == 0 && bcc == 0) {
/*
* An empty response also ends the chain,
* most likely with an error.
*/
break;
}
if (wct < 2) {
DEBUG(10, ("%s: wct[%d] < 2 for cmd[0x%02X]\n",
__location__, (int)wct, (int)cmd));
goto inval;
}
cmd = CVAL(cur[0].iov_base, 0);
if (cmd == 0xFF) {
/*
* If it is the end of the chain we are also done.
*/
break;
}
wct_ofs = SVAL(cur[0].iov_base, 2);
if (wct_ofs < taken) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
if (wct_ofs > buflen) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
/*
* we consumed everything up to the start of the next
* parameter block.
*/
taken = wct_ofs;
}
remaining = buflen - taken;
if (remaining > 0 && num_iov >= 3) {
/*
* The last DATA block gets the remaining
* bytes, this is needed to support
* CAP_LARGE_WRITEX and CAP_LARGE_READX.
*/
iov[num_iov-1].iov_len += remaining;
}
*piov = iov;
*pnum_iov = num_iov;
return NT_STATUS_OK;
inval:
TALLOC_FREE(iov);
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,911
|
bool smb1cli_is_andx_req(uint8_t cmd)
{
switch (cmd) {
case SMBtconX:
case SMBlockingX:
case SMBopenX:
case SMBreadX:
case SMBwriteX:
case SMBsesssetupX:
case SMBulogoffX:
case SMBntcreateX:
return true;
break;
default:
break;
}
return false;
}
| null | 0
|
bool smb1cli_is_andx_req(uint8_t cmd)
{
switch (cmd) {
case SMBtconX:
case SMBlockingX:
case SMBopenX:
case SMBreadX:
case SMBwriteX:
case SMBsesssetupX:
case SMBulogoffX:
case SMBntcreateX:
return true;
break;
default:
break;
}
return false;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,912
|
static NTSTATUS smb1cli_pull_raw_error(const uint8_t *hdr)
{
uint32_t flags2 = SVAL(hdr, HDR_FLG2);
NTSTATUS status = NT_STATUS(IVAL(hdr, HDR_RCLS));
if (NT_STATUS_IS_OK(status)) {
return NT_STATUS_OK;
}
if (flags2 & FLAGS2_32_BIT_ERROR_CODES) {
return status;
}
return NT_STATUS_DOS(CVAL(hdr, HDR_RCLS), SVAL(hdr, HDR_ERR));
}
| null | 0
|
static NTSTATUS smb1cli_pull_raw_error(const uint8_t *hdr)
{
uint32_t flags2 = SVAL(hdr, HDR_FLG2);
NTSTATUS status = NT_STATUS(IVAL(hdr, HDR_RCLS));
if (NT_STATUS_IS_OK(status)) {
return NT_STATUS_OK;
}
if (flags2 & FLAGS2_32_BIT_ERROR_CODES) {
return status;
}
return NT_STATUS_DOS(CVAL(hdr, HDR_RCLS), SVAL(hdr, HDR_ERR));
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,913
|
static bool smb1cli_req_cancel(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
uint8_t flags;
uint16_t flags2;
uint32_t pid;
uint16_t mid;
struct tevent_req *subreq;
NTSTATUS status;
flags = CVAL(state->smb1.hdr, HDR_FLG);
flags2 = SVAL(state->smb1.hdr, HDR_FLG2);
pid = SVAL(state->smb1.hdr, HDR_PID);
pid |= SVAL(state->smb1.hdr, HDR_PIDHIGH)<<16;
mid = SVAL(state->smb1.hdr, HDR_MID);
subreq = smb1cli_req_create(state, state->ev,
state->conn,
SMBntcancel,
flags, 0,
flags2, 0,
0, /* timeout */
pid,
state->tcon,
state->session,
0, NULL, /* vwv */
0, NULL); /* bytes */
if (subreq == NULL) {
return false;
}
smb1cli_req_set_mid(subreq, mid);
status = smb1cli_req_chain_submit(&subreq, 1);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(subreq);
return false;
}
smb1cli_req_set_mid(subreq, 0);
tevent_req_set_callback(subreq, smb1cli_req_cancel_done, NULL);
return true;
}
| null | 0
|
static bool smb1cli_req_cancel(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
uint8_t flags;
uint16_t flags2;
uint32_t pid;
uint16_t mid;
struct tevent_req *subreq;
NTSTATUS status;
flags = CVAL(state->smb1.hdr, HDR_FLG);
flags2 = SVAL(state->smb1.hdr, HDR_FLG2);
pid = SVAL(state->smb1.hdr, HDR_PID);
pid |= SVAL(state->smb1.hdr, HDR_PIDHIGH)<<16;
mid = SVAL(state->smb1.hdr, HDR_MID);
subreq = smb1cli_req_create(state, state->ev,
state->conn,
SMBntcancel,
flags, 0,
flags2, 0,
0, /* timeout */
pid,
state->tcon,
state->session,
0, NULL, /* vwv */
0, NULL); /* bytes */
if (subreq == NULL) {
return false;
}
smb1cli_req_set_mid(subreq, mid);
status = smb1cli_req_chain_submit(&subreq, 1);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(subreq);
return false;
}
smb1cli_req_set_mid(subreq, 0);
tevent_req_set_callback(subreq, smb1cli_req_cancel_done, NULL);
return true;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,914
|
static void smb1cli_req_cancel_done(struct tevent_req *subreq)
{
/* we do not care about the result */
TALLOC_FREE(subreq);
}
| null | 0
|
static void smb1cli_req_cancel_done(struct tevent_req *subreq)
{
/* we do not care about the result */
TALLOC_FREE(subreq);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,915
|
struct tevent_req *smb1cli_req_create(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint8_t smb_command,
uint8_t additional_flags,
uint8_t clear_flags,
uint16_t additional_flags2,
uint16_t clear_flags2,
uint32_t timeout_msec,
uint32_t pid,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
uint8_t wct, uint16_t *vwv,
int iov_count,
struct iovec *bytes_iov)
{
struct tevent_req *req;
struct smbXcli_req_state *state;
uint8_t flags = 0;
uint16_t flags2 = 0;
uint16_t uid = 0;
uint16_t tid = 0;
ssize_t num_bytes;
if (iov_count > MAX_SMB_IOV) {
/*
* Should not happen :-)
*/
return NULL;
}
req = tevent_req_create(mem_ctx, &state,
struct smbXcli_req_state);
if (req == NULL) {
return NULL;
}
state->ev = ev;
state->conn = conn;
state->session = session;
state->tcon = tcon;
if (session) {
uid = session->smb1.session_id;
}
if (tcon) {
tid = tcon->smb1.tcon_id;
if (tcon->fs_attributes & FILE_CASE_SENSITIVE_SEARCH) {
clear_flags |= FLAG_CASELESS_PATHNAMES;
} else {
/* Default setting, case insensitive. */
additional_flags |= FLAG_CASELESS_PATHNAMES;
}
if (smbXcli_conn_dfs_supported(conn) &&
smbXcli_tcon_is_dfs_share(tcon))
{
additional_flags2 |= FLAGS2_DFS_PATHNAMES;
}
}
state->smb1.recv_cmd = 0xFF;
state->smb1.recv_status = NT_STATUS_INTERNAL_ERROR;
state->smb1.recv_iov = talloc_zero_array(state, struct iovec, 3);
if (state->smb1.recv_iov == NULL) {
TALLOC_FREE(req);
return NULL;
}
smb1cli_req_flags(conn->protocol,
conn->smb1.capabilities,
smb_command,
additional_flags,
clear_flags,
&flags,
additional_flags2,
clear_flags2,
&flags2);
SIVAL(state->smb1.hdr, 0, SMB_MAGIC);
SCVAL(state->smb1.hdr, HDR_COM, smb_command);
SIVAL(state->smb1.hdr, HDR_RCLS, NT_STATUS_V(NT_STATUS_OK));
SCVAL(state->smb1.hdr, HDR_FLG, flags);
SSVAL(state->smb1.hdr, HDR_FLG2, flags2);
SSVAL(state->smb1.hdr, HDR_PIDHIGH, pid >> 16);
SSVAL(state->smb1.hdr, HDR_TID, tid);
SSVAL(state->smb1.hdr, HDR_PID, pid);
SSVAL(state->smb1.hdr, HDR_UID, uid);
SSVAL(state->smb1.hdr, HDR_MID, 0); /* this comes later */
SCVAL(state->smb1.hdr, HDR_WCT, wct);
state->smb1.vwv = vwv;
num_bytes = iov_buflen(bytes_iov, iov_count);
if (num_bytes == -1) {
/*
* I'd love to add a check for num_bytes<=UINT16_MAX here, but
* the smbclient->samba connections can lie and transfer more.
*/
TALLOC_FREE(req);
return NULL;
}
SSVAL(state->smb1.bytecount_buf, 0, num_bytes);
state->smb1.iov[0].iov_base = (void *)state->length_hdr;
state->smb1.iov[0].iov_len = sizeof(state->length_hdr);
state->smb1.iov[1].iov_base = (void *)state->smb1.hdr;
state->smb1.iov[1].iov_len = sizeof(state->smb1.hdr);
state->smb1.iov[2].iov_base = (void *)state->smb1.vwv;
state->smb1.iov[2].iov_len = wct * sizeof(uint16_t);
state->smb1.iov[3].iov_base = (void *)state->smb1.bytecount_buf;
state->smb1.iov[3].iov_len = sizeof(uint16_t);
if (iov_count != 0) {
memcpy(&state->smb1.iov[4], bytes_iov,
iov_count * sizeof(*bytes_iov));
}
state->smb1.iov_count = iov_count + 4;
if (timeout_msec > 0) {
struct timeval endtime;
endtime = timeval_current_ofs_msec(timeout_msec);
if (!tevent_req_set_endtime(req, ev, endtime)) {
return req;
}
}
switch (smb_command) {
case SMBtranss:
case SMBtranss2:
case SMBnttranss:
state->one_way = true;
break;
case SMBntcancel:
state->one_way = true;
state->smb1.one_way_seqnum = true;
break;
case SMBlockingX:
if ((wct == 8) &&
(CVAL(vwv+3, 0) == LOCKING_ANDX_OPLOCK_RELEASE)) {
state->one_way = true;
}
break;
}
return req;
}
| null | 0
|
struct tevent_req *smb1cli_req_create(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint8_t smb_command,
uint8_t additional_flags,
uint8_t clear_flags,
uint16_t additional_flags2,
uint16_t clear_flags2,
uint32_t timeout_msec,
uint32_t pid,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
uint8_t wct, uint16_t *vwv,
int iov_count,
struct iovec *bytes_iov)
{
struct tevent_req *req;
struct smbXcli_req_state *state;
uint8_t flags = 0;
uint16_t flags2 = 0;
uint16_t uid = 0;
uint16_t tid = 0;
ssize_t num_bytes;
if (iov_count > MAX_SMB_IOV) {
/*
* Should not happen :-)
*/
return NULL;
}
req = tevent_req_create(mem_ctx, &state,
struct smbXcli_req_state);
if (req == NULL) {
return NULL;
}
state->ev = ev;
state->conn = conn;
state->session = session;
state->tcon = tcon;
if (session) {
uid = session->smb1.session_id;
}
if (tcon) {
tid = tcon->smb1.tcon_id;
if (tcon->fs_attributes & FILE_CASE_SENSITIVE_SEARCH) {
clear_flags |= FLAG_CASELESS_PATHNAMES;
} else {
/* Default setting, case insensitive. */
additional_flags |= FLAG_CASELESS_PATHNAMES;
}
if (smbXcli_conn_dfs_supported(conn) &&
smbXcli_tcon_is_dfs_share(tcon))
{
additional_flags2 |= FLAGS2_DFS_PATHNAMES;
}
}
state->smb1.recv_cmd = 0xFF;
state->smb1.recv_status = NT_STATUS_INTERNAL_ERROR;
state->smb1.recv_iov = talloc_zero_array(state, struct iovec, 3);
if (state->smb1.recv_iov == NULL) {
TALLOC_FREE(req);
return NULL;
}
smb1cli_req_flags(conn->protocol,
conn->smb1.capabilities,
smb_command,
additional_flags,
clear_flags,
&flags,
additional_flags2,
clear_flags2,
&flags2);
SIVAL(state->smb1.hdr, 0, SMB_MAGIC);
SCVAL(state->smb1.hdr, HDR_COM, smb_command);
SIVAL(state->smb1.hdr, HDR_RCLS, NT_STATUS_V(NT_STATUS_OK));
SCVAL(state->smb1.hdr, HDR_FLG, flags);
SSVAL(state->smb1.hdr, HDR_FLG2, flags2);
SSVAL(state->smb1.hdr, HDR_PIDHIGH, pid >> 16);
SSVAL(state->smb1.hdr, HDR_TID, tid);
SSVAL(state->smb1.hdr, HDR_PID, pid);
SSVAL(state->smb1.hdr, HDR_UID, uid);
SSVAL(state->smb1.hdr, HDR_MID, 0); /* this comes later */
SCVAL(state->smb1.hdr, HDR_WCT, wct);
state->smb1.vwv = vwv;
num_bytes = iov_buflen(bytes_iov, iov_count);
if (num_bytes == -1) {
/*
* I'd love to add a check for num_bytes<=UINT16_MAX here, but
* the smbclient->samba connections can lie and transfer more.
*/
TALLOC_FREE(req);
return NULL;
}
SSVAL(state->smb1.bytecount_buf, 0, num_bytes);
state->smb1.iov[0].iov_base = (void *)state->length_hdr;
state->smb1.iov[0].iov_len = sizeof(state->length_hdr);
state->smb1.iov[1].iov_base = (void *)state->smb1.hdr;
state->smb1.iov[1].iov_len = sizeof(state->smb1.hdr);
state->smb1.iov[2].iov_base = (void *)state->smb1.vwv;
state->smb1.iov[2].iov_len = wct * sizeof(uint16_t);
state->smb1.iov[3].iov_base = (void *)state->smb1.bytecount_buf;
state->smb1.iov[3].iov_len = sizeof(uint16_t);
if (iov_count != 0) {
memcpy(&state->smb1.iov[4], bytes_iov,
iov_count * sizeof(*bytes_iov));
}
state->smb1.iov_count = iov_count + 4;
if (timeout_msec > 0) {
struct timeval endtime;
endtime = timeval_current_ofs_msec(timeout_msec);
if (!tevent_req_set_endtime(req, ev, endtime)) {
return req;
}
}
switch (smb_command) {
case SMBtranss:
case SMBtranss2:
case SMBnttranss:
state->one_way = true;
break;
case SMBntcancel:
state->one_way = true;
state->smb1.one_way_seqnum = true;
break;
case SMBlockingX:
if ((wct == 8) &&
(CVAL(vwv+3, 0) == LOCKING_ANDX_OPLOCK_RELEASE)) {
state->one_way = true;
}
break;
}
return req;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,916
|
static void smb1cli_req_flags(enum protocol_types protocol,
uint32_t smb1_capabilities,
uint8_t smb_command,
uint8_t additional_flags,
uint8_t clear_flags,
uint8_t *_flags,
uint16_t additional_flags2,
uint16_t clear_flags2,
uint16_t *_flags2)
{
uint8_t flags = 0;
uint16_t flags2 = 0;
if (protocol >= PROTOCOL_LANMAN1) {
flags |= FLAG_CASELESS_PATHNAMES;
flags |= FLAG_CANONICAL_PATHNAMES;
}
if (protocol >= PROTOCOL_LANMAN2) {
flags2 |= FLAGS2_LONG_PATH_COMPONENTS;
flags2 |= FLAGS2_EXTENDED_ATTRIBUTES;
}
if (protocol >= PROTOCOL_NT1) {
flags2 |= FLAGS2_IS_LONG_NAME;
if (smb1_capabilities & CAP_UNICODE) {
flags2 |= FLAGS2_UNICODE_STRINGS;
}
if (smb1_capabilities & CAP_STATUS32) {
flags2 |= FLAGS2_32_BIT_ERROR_CODES;
}
if (smb1_capabilities & CAP_EXTENDED_SECURITY) {
flags2 |= FLAGS2_EXTENDED_SECURITY;
}
}
flags |= additional_flags;
flags &= ~clear_flags;
flags2 |= additional_flags2;
flags2 &= ~clear_flags2;
*_flags = flags;
*_flags2 = flags2;
}
| null | 0
|
static void smb1cli_req_flags(enum protocol_types protocol,
uint32_t smb1_capabilities,
uint8_t smb_command,
uint8_t additional_flags,
uint8_t clear_flags,
uint8_t *_flags,
uint16_t additional_flags2,
uint16_t clear_flags2,
uint16_t *_flags2)
{
uint8_t flags = 0;
uint16_t flags2 = 0;
if (protocol >= PROTOCOL_LANMAN1) {
flags |= FLAG_CASELESS_PATHNAMES;
flags |= FLAG_CANONICAL_PATHNAMES;
}
if (protocol >= PROTOCOL_LANMAN2) {
flags2 |= FLAGS2_LONG_PATH_COMPONENTS;
flags2 |= FLAGS2_EXTENDED_ATTRIBUTES;
}
if (protocol >= PROTOCOL_NT1) {
flags2 |= FLAGS2_IS_LONG_NAME;
if (smb1_capabilities & CAP_UNICODE) {
flags2 |= FLAGS2_UNICODE_STRINGS;
}
if (smb1_capabilities & CAP_STATUS32) {
flags2 |= FLAGS2_32_BIT_ERROR_CODES;
}
if (smb1_capabilities & CAP_EXTENDED_SECURITY) {
flags2 |= FLAGS2_EXTENDED_SECURITY;
}
}
flags |= additional_flags;
flags &= ~clear_flags;
flags2 |= additional_flags2;
flags2 &= ~clear_flags2;
*_flags = flags;
*_flags2 = flags2;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,917
|
uint16_t smb1cli_req_mid(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
if (state->smb1.mid != 0) {
return state->smb1.mid;
}
return SVAL(state->smb1.hdr, HDR_MID);
}
| null | 0
|
uint16_t smb1cli_req_mid(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
if (state->smb1.mid != 0) {
return state->smb1.mid;
}
return SVAL(state->smb1.hdr, HDR_MID);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,918
|
NTSTATUS smb1cli_req_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
struct iovec **piov,
uint8_t **phdr,
uint8_t *pwct,
uint16_t **pvwv,
uint32_t *pvwv_offset,
uint32_t *pnum_bytes,
uint8_t **pbytes,
uint32_t *pbytes_offset,
uint8_t **pinbuf,
const struct smb1cli_req_expected_response *expected,
size_t num_expected)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
NTSTATUS status = NT_STATUS_OK;
struct iovec *recv_iov = NULL;
uint8_t *hdr = NULL;
uint8_t wct = 0;
uint32_t vwv_offset = 0;
uint16_t *vwv = NULL;
uint32_t num_bytes = 0;
uint32_t bytes_offset = 0;
uint8_t *bytes = NULL;
size_t i;
bool found_status = false;
bool found_size = false;
if (piov != NULL) {
*piov = NULL;
}
if (phdr != NULL) {
*phdr = 0;
}
if (pwct != NULL) {
*pwct = 0;
}
if (pvwv != NULL) {
*pvwv = NULL;
}
if (pvwv_offset != NULL) {
*pvwv_offset = 0;
}
if (pnum_bytes != NULL) {
*pnum_bytes = 0;
}
if (pbytes != NULL) {
*pbytes = NULL;
}
if (pbytes_offset != NULL) {
*pbytes_offset = 0;
}
if (pinbuf != NULL) {
*pinbuf = NULL;
}
if (state->inbuf != NULL) {
recv_iov = state->smb1.recv_iov;
state->smb1.recv_iov = NULL;
if (state->smb1.recv_cmd != SMBreadBraw) {
hdr = (uint8_t *)recv_iov[0].iov_base;
wct = recv_iov[1].iov_len/2;
vwv = (uint16_t *)recv_iov[1].iov_base;
vwv_offset = PTR_DIFF(vwv, hdr);
num_bytes = recv_iov[2].iov_len;
bytes = (uint8_t *)recv_iov[2].iov_base;
bytes_offset = PTR_DIFF(bytes, hdr);
}
}
if (tevent_req_is_nterror(req, &status)) {
for (i=0; i < num_expected; i++) {
if (NT_STATUS_EQUAL(status, expected[i].status)) {
found_status = true;
break;
}
}
if (found_status) {
return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
}
return status;
}
if (num_expected == 0) {
found_status = true;
found_size = true;
}
status = state->smb1.recv_status;
for (i=0; i < num_expected; i++) {
if (!NT_STATUS_EQUAL(status, expected[i].status)) {
continue;
}
found_status = true;
if (expected[i].wct == 0) {
found_size = true;
break;
}
if (expected[i].wct == wct) {
found_size = true;
break;
}
}
if (!found_status) {
return status;
}
if (!found_size) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
if (piov != NULL) {
*piov = talloc_move(mem_ctx, &recv_iov);
}
if (phdr != NULL) {
*phdr = hdr;
}
if (pwct != NULL) {
*pwct = wct;
}
if (pvwv != NULL) {
*pvwv = vwv;
}
if (pvwv_offset != NULL) {
*pvwv_offset = vwv_offset;
}
if (pnum_bytes != NULL) {
*pnum_bytes = num_bytes;
}
if (pbytes != NULL) {
*pbytes = bytes;
}
if (pbytes_offset != NULL) {
*pbytes_offset = bytes_offset;
}
if (pinbuf != NULL) {
*pinbuf = state->inbuf;
}
return status;
}
| null | 0
|
NTSTATUS smb1cli_req_recv(struct tevent_req *req,
TALLOC_CTX *mem_ctx,
struct iovec **piov,
uint8_t **phdr,
uint8_t *pwct,
uint16_t **pvwv,
uint32_t *pvwv_offset,
uint32_t *pnum_bytes,
uint8_t **pbytes,
uint32_t *pbytes_offset,
uint8_t **pinbuf,
const struct smb1cli_req_expected_response *expected,
size_t num_expected)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
NTSTATUS status = NT_STATUS_OK;
struct iovec *recv_iov = NULL;
uint8_t *hdr = NULL;
uint8_t wct = 0;
uint32_t vwv_offset = 0;
uint16_t *vwv = NULL;
uint32_t num_bytes = 0;
uint32_t bytes_offset = 0;
uint8_t *bytes = NULL;
size_t i;
bool found_status = false;
bool found_size = false;
if (piov != NULL) {
*piov = NULL;
}
if (phdr != NULL) {
*phdr = 0;
}
if (pwct != NULL) {
*pwct = 0;
}
if (pvwv != NULL) {
*pvwv = NULL;
}
if (pvwv_offset != NULL) {
*pvwv_offset = 0;
}
if (pnum_bytes != NULL) {
*pnum_bytes = 0;
}
if (pbytes != NULL) {
*pbytes = NULL;
}
if (pbytes_offset != NULL) {
*pbytes_offset = 0;
}
if (pinbuf != NULL) {
*pinbuf = NULL;
}
if (state->inbuf != NULL) {
recv_iov = state->smb1.recv_iov;
state->smb1.recv_iov = NULL;
if (state->smb1.recv_cmd != SMBreadBraw) {
hdr = (uint8_t *)recv_iov[0].iov_base;
wct = recv_iov[1].iov_len/2;
vwv = (uint16_t *)recv_iov[1].iov_base;
vwv_offset = PTR_DIFF(vwv, hdr);
num_bytes = recv_iov[2].iov_len;
bytes = (uint8_t *)recv_iov[2].iov_base;
bytes_offset = PTR_DIFF(bytes, hdr);
}
}
if (tevent_req_is_nterror(req, &status)) {
for (i=0; i < num_expected; i++) {
if (NT_STATUS_EQUAL(status, expected[i].status)) {
found_status = true;
break;
}
}
if (found_status) {
return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
}
return status;
}
if (num_expected == 0) {
found_status = true;
found_size = true;
}
status = state->smb1.recv_status;
for (i=0; i < num_expected; i++) {
if (!NT_STATUS_EQUAL(status, expected[i].status)) {
continue;
}
found_status = true;
if (expected[i].wct == 0) {
found_size = true;
break;
}
if (expected[i].wct == wct) {
found_size = true;
break;
}
}
if (!found_status) {
return status;
}
if (!found_size) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
if (piov != NULL) {
*piov = talloc_move(mem_ctx, &recv_iov);
}
if (phdr != NULL) {
*phdr = hdr;
}
if (pwct != NULL) {
*pwct = wct;
}
if (pvwv != NULL) {
*pvwv = vwv;
}
if (pvwv_offset != NULL) {
*pvwv_offset = vwv_offset;
}
if (pnum_bytes != NULL) {
*pnum_bytes = num_bytes;
}
if (pbytes != NULL) {
*pbytes = bytes;
}
if (pbytes_offset != NULL) {
*pbytes_offset = bytes_offset;
}
if (pinbuf != NULL) {
*pinbuf = state->inbuf;
}
return status;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,919
|
struct tevent_req *smb1cli_req_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint8_t smb_command,
uint8_t additional_flags,
uint8_t clear_flags,
uint16_t additional_flags2,
uint16_t clear_flags2,
uint32_t timeout_msec,
uint32_t pid,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
uint8_t wct, uint16_t *vwv,
uint32_t num_bytes,
const uint8_t *bytes)
{
struct tevent_req *req;
struct iovec iov;
NTSTATUS status;
iov.iov_base = discard_const_p(void, bytes);
iov.iov_len = num_bytes;
req = smb1cli_req_create(mem_ctx, ev, conn, smb_command,
additional_flags, clear_flags,
additional_flags2, clear_flags2,
timeout_msec,
pid, tcon, session,
wct, vwv, 1, &iov);
if (req == NULL) {
return NULL;
}
if (!tevent_req_is_in_progress(req)) {
return tevent_req_post(req, ev);
}
status = smb1cli_req_chain_submit(&req, 1);
if (tevent_req_nterror(req, status)) {
return tevent_req_post(req, ev);
}
return req;
}
| null | 0
|
struct tevent_req *smb1cli_req_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint8_t smb_command,
uint8_t additional_flags,
uint8_t clear_flags,
uint16_t additional_flags2,
uint16_t clear_flags2,
uint32_t timeout_msec,
uint32_t pid,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
uint8_t wct, uint16_t *vwv,
uint32_t num_bytes,
const uint8_t *bytes)
{
struct tevent_req *req;
struct iovec iov;
NTSTATUS status;
iov.iov_base = discard_const_p(void, bytes);
iov.iov_len = num_bytes;
req = smb1cli_req_create(mem_ctx, ev, conn, smb_command,
additional_flags, clear_flags,
additional_flags2, clear_flags2,
timeout_msec,
pid, tcon, session,
wct, vwv, 1, &iov);
if (req == NULL) {
return NULL;
}
if (!tevent_req_is_in_progress(req)) {
return tevent_req_post(req, ev);
}
status = smb1cli_req_chain_submit(&req, 1);
if (tevent_req_nterror(req, status)) {
return tevent_req_post(req, ev);
}
return req;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,920
|
void smb1cli_req_set_seqnum(struct tevent_req *req, uint32_t seqnum)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
state->smb1.seqnum = seqnum;
}
| null | 0
|
void smb1cli_req_set_seqnum(struct tevent_req *req, uint32_t seqnum)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
state->smb1.seqnum = seqnum;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,921
|
size_t smb1cli_req_wct_ofs(struct tevent_req **reqs, int num_reqs)
{
size_t wct_ofs;
int i;
wct_ofs = HDR_WCT;
for (i=0; i<num_reqs; i++) {
struct smbXcli_req_state *state;
state = tevent_req_data(reqs[i], struct smbXcli_req_state);
wct_ofs += smbXcli_iov_len(state->smb1.iov+2,
state->smb1.iov_count-2);
wct_ofs = (wct_ofs + 3) & ~3;
}
return wct_ofs;
}
| null | 0
|
size_t smb1cli_req_wct_ofs(struct tevent_req **reqs, int num_reqs)
{
size_t wct_ofs;
int i;
wct_ofs = HDR_WCT;
for (i=0; i<num_reqs; i++) {
struct smbXcli_req_state *state;
state = tevent_req_data(reqs[i], struct smbXcli_req_state);
wct_ofs += smbXcli_iov_len(state->smb1.iov+2,
state->smb1.iov_count-2);
wct_ofs = (wct_ofs + 3) & ~3;
}
return wct_ofs;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,922
|
static void smb1cli_req_writev_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
ssize_t nwritten;
int err;
state->write_req = NULL;
nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
if (nwritten == -1) {
/* here, we need to notify all pending requests */
NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
if (state->one_way) {
state->inbuf = NULL;
tevent_req_done(req);
return;
}
}
| null | 0
|
static void smb1cli_req_writev_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
ssize_t nwritten;
int err;
state->write_req = NULL;
nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
if (nwritten == -1) {
/* here, we need to notify all pending requests */
NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
if (state->one_way) {
state->inbuf = NULL;
tevent_req_done(req);
return;
}
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,923
|
static NTSTATUS smb1cli_req_writev_submit(struct tevent_req *req,
struct smbXcli_req_state *state,
struct iovec *iov, int iov_count)
{
struct tevent_req *subreq;
NTSTATUS status;
uint8_t cmd;
uint16_t mid;
ssize_t nbtlen;
if (!smbXcli_conn_is_connected(state->conn)) {
return NT_STATUS_CONNECTION_DISCONNECTED;
}
if (state->conn->protocol > PROTOCOL_NT1) {
return NT_STATUS_REVISION_MISMATCH;
}
if (iov_count < 4) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[0].iov_len != NBT_HDR_SIZE) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[1].iov_len != (MIN_SMB_SIZE-sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[2].iov_len > (0xFF * sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[3].iov_len != sizeof(uint16_t)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
cmd = CVAL(iov[1].iov_base, HDR_COM);
if (cmd == SMBreadBraw) {
if (smbXcli_conn_has_async_calls(state->conn)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
state->conn->smb1.read_braw_req = req;
}
if (state->smb1.mid != 0) {
mid = state->smb1.mid;
} else {
mid = smb1cli_alloc_mid(state->conn);
}
SSVAL(iov[1].iov_base, HDR_MID, mid);
nbtlen = iov_buflen(&iov[1], iov_count-1);
if ((nbtlen == -1) || (nbtlen > 0x1FFFF)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
_smb_setlen_nbt(iov[0].iov_base, nbtlen);
status = smb1cli_conn_signv(state->conn, iov, iov_count,
&state->smb1.seqnum,
state->smb1.one_way_seqnum);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
/*
* If we supported multiple encrytion contexts
* here we'd look up based on tid.
*/
if (common_encryption_on(state->conn->smb1.trans_enc)) {
char *buf, *enc_buf;
buf = (char *)smbXcli_iov_concat(talloc_tos(), iov, iov_count);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
status = common_encrypt_buffer(state->conn->smb1.trans_enc,
(char *)buf, &enc_buf);
TALLOC_FREE(buf);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Error in encrypting client message: %s\n",
nt_errstr(status)));
return status;
}
buf = (char *)talloc_memdup(state, enc_buf,
smb_len_nbt(enc_buf)+4);
SAFE_FREE(enc_buf);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
iov[0].iov_base = (void *)buf;
iov[0].iov_len = talloc_get_size(buf);
iov_count = 1;
}
if (state->conn->dispatch_incoming == NULL) {
state->conn->dispatch_incoming = smb1cli_conn_dispatch_incoming;
}
if (!smbXcli_req_set_pending(req)) {
return NT_STATUS_NO_MEMORY;
}
tevent_req_set_cancel_fn(req, smbXcli_req_cancel);
subreq = writev_send(state, state->ev, state->conn->outgoing,
state->conn->sock_fd, false, iov, iov_count);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
tevent_req_set_callback(subreq, smb1cli_req_writev_done, req);
state->write_req = subreq;
return NT_STATUS_OK;
}
| null | 0
|
static NTSTATUS smb1cli_req_writev_submit(struct tevent_req *req,
struct smbXcli_req_state *state,
struct iovec *iov, int iov_count)
{
struct tevent_req *subreq;
NTSTATUS status;
uint8_t cmd;
uint16_t mid;
ssize_t nbtlen;
if (!smbXcli_conn_is_connected(state->conn)) {
return NT_STATUS_CONNECTION_DISCONNECTED;
}
if (state->conn->protocol > PROTOCOL_NT1) {
return NT_STATUS_REVISION_MISMATCH;
}
if (iov_count < 4) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[0].iov_len != NBT_HDR_SIZE) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[1].iov_len != (MIN_SMB_SIZE-sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[2].iov_len > (0xFF * sizeof(uint16_t))) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (iov[3].iov_len != sizeof(uint16_t)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
cmd = CVAL(iov[1].iov_base, HDR_COM);
if (cmd == SMBreadBraw) {
if (smbXcli_conn_has_async_calls(state->conn)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
state->conn->smb1.read_braw_req = req;
}
if (state->smb1.mid != 0) {
mid = state->smb1.mid;
} else {
mid = smb1cli_alloc_mid(state->conn);
}
SSVAL(iov[1].iov_base, HDR_MID, mid);
nbtlen = iov_buflen(&iov[1], iov_count-1);
if ((nbtlen == -1) || (nbtlen > 0x1FFFF)) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
_smb_setlen_nbt(iov[0].iov_base, nbtlen);
status = smb1cli_conn_signv(state->conn, iov, iov_count,
&state->smb1.seqnum,
state->smb1.one_way_seqnum);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
/*
* If we supported multiple encrytion contexts
* here we'd look up based on tid.
*/
if (common_encryption_on(state->conn->smb1.trans_enc)) {
char *buf, *enc_buf;
buf = (char *)smbXcli_iov_concat(talloc_tos(), iov, iov_count);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
status = common_encrypt_buffer(state->conn->smb1.trans_enc,
(char *)buf, &enc_buf);
TALLOC_FREE(buf);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Error in encrypting client message: %s\n",
nt_errstr(status)));
return status;
}
buf = (char *)talloc_memdup(state, enc_buf,
smb_len_nbt(enc_buf)+4);
SAFE_FREE(enc_buf);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
iov[0].iov_base = (void *)buf;
iov[0].iov_len = talloc_get_size(buf);
iov_count = 1;
}
if (state->conn->dispatch_incoming == NULL) {
state->conn->dispatch_incoming = smb1cli_conn_dispatch_incoming;
}
if (!smbXcli_req_set_pending(req)) {
return NT_STATUS_NO_MEMORY;
}
tevent_req_set_cancel_fn(req, smbXcli_req_cancel);
subreq = writev_send(state, state->ev, state->conn->outgoing,
state->conn->sock_fd, false, iov, iov_count);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
tevent_req_set_callback(subreq, smb1cli_req_writev_done, req);
state->write_req = subreq;
return NT_STATUS_OK;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,924
|
uint16_t smb1cli_session_current_id(struct smbXcli_session *session)
{
return session->smb1.session_id;
}
| null | 0
|
uint16_t smb1cli_session_current_id(struct smbXcli_session *session)
{
return session->smb1.session_id;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,925
|
void smb1cli_session_set_id(struct smbXcli_session *session,
uint16_t session_id)
{
session->smb1.session_id = session_id;
}
| null | 0
|
void smb1cli_session_set_id(struct smbXcli_session *session,
uint16_t session_id)
{
session->smb1.session_id = session_id;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,926
|
NTSTATUS smb1cli_session_set_session_key(struct smbXcli_session *session,
const DATA_BLOB _session_key)
{
struct smbXcli_conn *conn = session->conn;
uint8_t session_key[16];
if (conn == NULL) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (session->smb1.application_key.length != 0) {
/*
* TODO: do not allow this...
*
* return NT_STATUS_INVALID_PARAMETER_MIX;
*/
data_blob_clear_free(&session->smb1.application_key);
session->smb1.protected_key = false;
}
if (_session_key.length == 0) {
return NT_STATUS_OK;
}
ZERO_STRUCT(session_key);
memcpy(session_key, _session_key.data,
MIN(_session_key.length, sizeof(session_key)));
session->smb1.application_key = data_blob_talloc(session,
session_key,
sizeof(session_key));
ZERO_STRUCT(session_key);
if (session->smb1.application_key.data == NULL) {
return NT_STATUS_NO_MEMORY;
}
session->smb1.protected_key = false;
return NT_STATUS_OK;
}
| null | 0
|
NTSTATUS smb1cli_session_set_session_key(struct smbXcli_session *session,
const DATA_BLOB _session_key)
{
struct smbXcli_conn *conn = session->conn;
uint8_t session_key[16];
if (conn == NULL) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
if (session->smb1.application_key.length != 0) {
/*
* TODO: do not allow this...
*
* return NT_STATUS_INVALID_PARAMETER_MIX;
*/
data_blob_clear_free(&session->smb1.application_key);
session->smb1.protected_key = false;
}
if (_session_key.length == 0) {
return NT_STATUS_OK;
}
ZERO_STRUCT(session_key);
memcpy(session_key, _session_key.data,
MIN(_session_key.length, sizeof(session_key)));
session->smb1.application_key = data_blob_talloc(session,
session_key,
sizeof(session_key));
ZERO_STRUCT(session_key);
if (session->smb1.application_key.data == NULL) {
return NT_STATUS_NO_MEMORY;
}
session->smb1.protected_key = false;
return NT_STATUS_OK;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,927
|
uint32_t smb2cli_conn_cc_chunk_len(struct smbXcli_conn *conn)
{
return conn->smb2.cc_chunk_len;
}
| null | 0
|
uint32_t smb2cli_conn_cc_chunk_len(struct smbXcli_conn *conn)
{
return conn->smb2.cc_chunk_len;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,928
|
static NTSTATUS smb2cli_conn_dispatch_incoming(struct smbXcli_conn *conn,
TALLOC_CTX *tmp_mem,
uint8_t *inbuf)
{
struct tevent_req *req;
struct smbXcli_req_state *state = NULL;
struct iovec *iov;
int i, num_iov;
NTSTATUS status;
bool defer = true;
struct smbXcli_session *last_session = NULL;
size_t inbuf_len = smb_len_tcp(inbuf);
status = smb2cli_inbuf_parse_compound(conn,
inbuf + NBT_HDR_SIZE,
inbuf_len,
tmp_mem,
&iov, &num_iov);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
for (i=0; i<num_iov; i+=4) {
uint8_t *inbuf_ref = NULL;
struct iovec *cur = &iov[i];
uint8_t *inhdr = (uint8_t *)cur[1].iov_base;
uint16_t opcode = SVAL(inhdr, SMB2_HDR_OPCODE);
uint32_t flags = IVAL(inhdr, SMB2_HDR_FLAGS);
uint64_t mid = BVAL(inhdr, SMB2_HDR_MESSAGE_ID);
uint16_t req_opcode;
uint32_t req_flags;
uint16_t credits = SVAL(inhdr, SMB2_HDR_CREDIT);
uint32_t new_credits;
struct smbXcli_session *session = NULL;
const DATA_BLOB *signing_key = NULL;
bool was_encrypted = false;
new_credits = conn->smb2.cur_credits;
new_credits += credits;
if (new_credits > UINT16_MAX) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
conn->smb2.cur_credits += credits;
req = smb2cli_conn_find_pending(conn, mid);
if (req == NULL) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
state = tevent_req_data(req, struct smbXcli_req_state);
req_opcode = SVAL(state->smb2.hdr, SMB2_HDR_OPCODE);
if (opcode != req_opcode) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
req_flags = SVAL(state->smb2.hdr, SMB2_HDR_FLAGS);
if (!(flags & SMB2_HDR_FLAG_REDIRECT)) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
status = NT_STATUS(IVAL(inhdr, SMB2_HDR_STATUS));
if ((flags & SMB2_HDR_FLAG_ASYNC) &&
NT_STATUS_EQUAL(status, STATUS_PENDING)) {
uint64_t async_id = BVAL(inhdr, SMB2_HDR_ASYNC_ID);
if (state->smb2.got_async) {
/* We only expect one STATUS_PENDING response */
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
state->smb2.got_async = true;
/*
* async interim responses are not signed,
* even if the SMB2_HDR_FLAG_SIGNED flag
* is set.
*/
state->smb2.cancel_flags = SMB2_HDR_FLAG_ASYNC;
state->smb2.cancel_mid = 0;
state->smb2.cancel_aid = async_id;
if (state->smb2.notify_async) {
tevent_req_defer_callback(req, state->ev);
tevent_req_notify_callback(req);
}
continue;
}
session = state->session;
if (req_flags & SMB2_HDR_FLAG_CHAINED) {
session = last_session;
}
last_session = session;
if (state->smb2.should_sign) {
if (!(flags & SMB2_HDR_FLAG_SIGNED)) {
return NT_STATUS_ACCESS_DENIED;
}
}
if (flags & SMB2_HDR_FLAG_SIGNED) {
uint64_t uid = BVAL(inhdr, SMB2_HDR_SESSION_ID);
if (session == NULL) {
struct smbXcli_session *s;
s = state->conn->sessions;
for (; s; s = s->next) {
if (s->smb2->session_id != uid) {
continue;
}
session = s;
break;
}
}
if (session == NULL) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
last_session = session;
signing_key = &session->smb2_channel.signing_key;
}
if (opcode == SMB2_OP_SESSSETUP) {
/*
* We prefer the channel signing key, if it is
* already there.
*
* If we do not have a channel signing key yet,
* we try the main signing key, if it is not
* the final response.
*/
if (signing_key && signing_key->length == 0 &&
!NT_STATUS_IS_OK(status)) {
signing_key = &session->smb2->signing_key;
}
if (signing_key && signing_key->length == 0) {
/*
* If we do not have a session key to
* verify the signature, we defer the
* signing check to the caller.
*
* The caller gets NT_STATUS_OK, it
* has to call
* smb2cli_session_set_session_key()
* or
* smb2cli_session_set_channel_key()
* which will check the signature
* with the channel signing key.
*/
signing_key = NULL;
}
}
if (cur[0].iov_len == SMB2_TF_HDR_SIZE) {
const uint8_t *tf = (const uint8_t *)cur[0].iov_base;
uint64_t uid = BVAL(tf, SMB2_TF_SESSION_ID);
/*
* If the response was encrypted in a SMB2_TRANSFORM
* pdu, which belongs to the correct session,
* we do not need to do signing checks
*
* It could be the session the response belongs to
* or the session that was used to encrypt the
* SMB2_TRANSFORM request.
*/
if ((session && session->smb2->session_id == uid) ||
(state->smb2.encryption_session_id == uid)) {
signing_key = NULL;
was_encrypted = true;
}
}
if (NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
/*
* if the server returns NT_STATUS_USER_SESSION_DELETED
* the response is not signed and we should
* propagate the NT_STATUS_USER_SESSION_DELETED
* status to the caller.
*/
state->smb2.signing_skipped = true;
signing_key = NULL;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
/*
* if the server returns
* NT_STATUS_INVALID_PARAMETER
* the response might not be encrypted.
*/
if (state->smb2.should_encrypt && !was_encrypted) {
state->smb2.signing_skipped = true;
signing_key = NULL;
}
}
if (state->smb2.should_encrypt && !was_encrypted) {
if (!state->smb2.signing_skipped) {
return NT_STATUS_ACCESS_DENIED;
}
}
if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) ||
NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) ||
NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
/*
* if the server returns
* NT_STATUS_NETWORK_NAME_DELETED
* NT_STATUS_FILE_CLOSED
* NT_STATUS_INVALID_PARAMETER
* the response might not be signed
* as this happens before the signing checks.
*
* If server echos the signature (or all zeros)
* we should report the status from the server
* to the caller.
*/
if (signing_key) {
int cmp;
cmp = memcmp(inhdr+SMB2_HDR_SIGNATURE,
state->smb2.hdr+SMB2_HDR_SIGNATURE,
16);
if (cmp == 0) {
state->smb2.signing_skipped = true;
signing_key = NULL;
}
}
if (signing_key) {
int cmp;
static const uint8_t zeros[16];
cmp = memcmp(inhdr+SMB2_HDR_SIGNATURE,
zeros,
16);
if (cmp == 0) {
state->smb2.signing_skipped = true;
signing_key = NULL;
}
}
}
if (signing_key) {
status = smb2_signing_check_pdu(*signing_key,
state->conn->protocol,
&cur[1], 3);
if (!NT_STATUS_IS_OK(status)) {
/*
* If the signing check fails, we disconnect
* the connection.
*/
return status;
}
}
if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_SESSION_EXPIRED) &&
(session != NULL) && session->disconnect_expired)
{
/*
* this should be a short term hack
* until the upper layers have implemented
* re-authentication.
*/
return status;
}
smbXcli_req_unset_pending(req);
/*
* There might be more than one response
* we need to defer the notifications
*/
if ((num_iov == 5) && (talloc_array_length(conn->pending) == 0)) {
defer = false;
}
if (defer) {
tevent_req_defer_callback(req, state->ev);
}
/*
* Note: here we use talloc_reference() in a way
* that does not expose it to the caller.
*/
inbuf_ref = talloc_reference(state->smb2.recv_iov, inbuf);
if (tevent_req_nomem(inbuf_ref, req)) {
continue;
}
/* copy the related buffers */
state->smb2.recv_iov[0] = cur[1];
state->smb2.recv_iov[1] = cur[2];
state->smb2.recv_iov[2] = cur[3];
tevent_req_done(req);
}
if (defer) {
return NT_STATUS_RETRY;
}
return NT_STATUS_OK;
}
| null | 0
|
static NTSTATUS smb2cli_conn_dispatch_incoming(struct smbXcli_conn *conn,
TALLOC_CTX *tmp_mem,
uint8_t *inbuf)
{
struct tevent_req *req;
struct smbXcli_req_state *state = NULL;
struct iovec *iov;
int i, num_iov;
NTSTATUS status;
bool defer = true;
struct smbXcli_session *last_session = NULL;
size_t inbuf_len = smb_len_tcp(inbuf);
status = smb2cli_inbuf_parse_compound(conn,
inbuf + NBT_HDR_SIZE,
inbuf_len,
tmp_mem,
&iov, &num_iov);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
for (i=0; i<num_iov; i+=4) {
uint8_t *inbuf_ref = NULL;
struct iovec *cur = &iov[i];
uint8_t *inhdr = (uint8_t *)cur[1].iov_base;
uint16_t opcode = SVAL(inhdr, SMB2_HDR_OPCODE);
uint32_t flags = IVAL(inhdr, SMB2_HDR_FLAGS);
uint64_t mid = BVAL(inhdr, SMB2_HDR_MESSAGE_ID);
uint16_t req_opcode;
uint32_t req_flags;
uint16_t credits = SVAL(inhdr, SMB2_HDR_CREDIT);
uint32_t new_credits;
struct smbXcli_session *session = NULL;
const DATA_BLOB *signing_key = NULL;
bool was_encrypted = false;
new_credits = conn->smb2.cur_credits;
new_credits += credits;
if (new_credits > UINT16_MAX) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
conn->smb2.cur_credits += credits;
req = smb2cli_conn_find_pending(conn, mid);
if (req == NULL) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
state = tevent_req_data(req, struct smbXcli_req_state);
req_opcode = SVAL(state->smb2.hdr, SMB2_HDR_OPCODE);
if (opcode != req_opcode) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
req_flags = SVAL(state->smb2.hdr, SMB2_HDR_FLAGS);
if (!(flags & SMB2_HDR_FLAG_REDIRECT)) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
status = NT_STATUS(IVAL(inhdr, SMB2_HDR_STATUS));
if ((flags & SMB2_HDR_FLAG_ASYNC) &&
NT_STATUS_EQUAL(status, STATUS_PENDING)) {
uint64_t async_id = BVAL(inhdr, SMB2_HDR_ASYNC_ID);
if (state->smb2.got_async) {
/* We only expect one STATUS_PENDING response */
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
state->smb2.got_async = true;
/*
* async interim responses are not signed,
* even if the SMB2_HDR_FLAG_SIGNED flag
* is set.
*/
state->smb2.cancel_flags = SMB2_HDR_FLAG_ASYNC;
state->smb2.cancel_mid = 0;
state->smb2.cancel_aid = async_id;
if (state->smb2.notify_async) {
tevent_req_defer_callback(req, state->ev);
tevent_req_notify_callback(req);
}
continue;
}
session = state->session;
if (req_flags & SMB2_HDR_FLAG_CHAINED) {
session = last_session;
}
last_session = session;
if (state->smb2.should_sign) {
if (!(flags & SMB2_HDR_FLAG_SIGNED)) {
return NT_STATUS_ACCESS_DENIED;
}
}
if (flags & SMB2_HDR_FLAG_SIGNED) {
uint64_t uid = BVAL(inhdr, SMB2_HDR_SESSION_ID);
if (session == NULL) {
struct smbXcli_session *s;
s = state->conn->sessions;
for (; s; s = s->next) {
if (s->smb2->session_id != uid) {
continue;
}
session = s;
break;
}
}
if (session == NULL) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
last_session = session;
signing_key = &session->smb2_channel.signing_key;
}
if (opcode == SMB2_OP_SESSSETUP) {
/*
* We prefer the channel signing key, if it is
* already there.
*
* If we do not have a channel signing key yet,
* we try the main signing key, if it is not
* the final response.
*/
if (signing_key && signing_key->length == 0 &&
!NT_STATUS_IS_OK(status)) {
signing_key = &session->smb2->signing_key;
}
if (signing_key && signing_key->length == 0) {
/*
* If we do not have a session key to
* verify the signature, we defer the
* signing check to the caller.
*
* The caller gets NT_STATUS_OK, it
* has to call
* smb2cli_session_set_session_key()
* or
* smb2cli_session_set_channel_key()
* which will check the signature
* with the channel signing key.
*/
signing_key = NULL;
}
}
if (cur[0].iov_len == SMB2_TF_HDR_SIZE) {
const uint8_t *tf = (const uint8_t *)cur[0].iov_base;
uint64_t uid = BVAL(tf, SMB2_TF_SESSION_ID);
/*
* If the response was encrypted in a SMB2_TRANSFORM
* pdu, which belongs to the correct session,
* we do not need to do signing checks
*
* It could be the session the response belongs to
* or the session that was used to encrypt the
* SMB2_TRANSFORM request.
*/
if ((session && session->smb2->session_id == uid) ||
(state->smb2.encryption_session_id == uid)) {
signing_key = NULL;
was_encrypted = true;
}
}
if (NT_STATUS_EQUAL(status, NT_STATUS_USER_SESSION_DELETED)) {
/*
* if the server returns NT_STATUS_USER_SESSION_DELETED
* the response is not signed and we should
* propagate the NT_STATUS_USER_SESSION_DELETED
* status to the caller.
*/
state->smb2.signing_skipped = true;
signing_key = NULL;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
/*
* if the server returns
* NT_STATUS_INVALID_PARAMETER
* the response might not be encrypted.
*/
if (state->smb2.should_encrypt && !was_encrypted) {
state->smb2.signing_skipped = true;
signing_key = NULL;
}
}
if (state->smb2.should_encrypt && !was_encrypted) {
if (!state->smb2.signing_skipped) {
return NT_STATUS_ACCESS_DENIED;
}
}
if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) ||
NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED) ||
NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
/*
* if the server returns
* NT_STATUS_NETWORK_NAME_DELETED
* NT_STATUS_FILE_CLOSED
* NT_STATUS_INVALID_PARAMETER
* the response might not be signed
* as this happens before the signing checks.
*
* If server echos the signature (or all zeros)
* we should report the status from the server
* to the caller.
*/
if (signing_key) {
int cmp;
cmp = memcmp(inhdr+SMB2_HDR_SIGNATURE,
state->smb2.hdr+SMB2_HDR_SIGNATURE,
16);
if (cmp == 0) {
state->smb2.signing_skipped = true;
signing_key = NULL;
}
}
if (signing_key) {
int cmp;
static const uint8_t zeros[16];
cmp = memcmp(inhdr+SMB2_HDR_SIGNATURE,
zeros,
16);
if (cmp == 0) {
state->smb2.signing_skipped = true;
signing_key = NULL;
}
}
}
if (signing_key) {
status = smb2_signing_check_pdu(*signing_key,
state->conn->protocol,
&cur[1], 3);
if (!NT_STATUS_IS_OK(status)) {
/*
* If the signing check fails, we disconnect
* the connection.
*/
return status;
}
}
if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_SESSION_EXPIRED) &&
(session != NULL) && session->disconnect_expired)
{
/*
* this should be a short term hack
* until the upper layers have implemented
* re-authentication.
*/
return status;
}
smbXcli_req_unset_pending(req);
/*
* There might be more than one response
* we need to defer the notifications
*/
if ((num_iov == 5) && (talloc_array_length(conn->pending) == 0)) {
defer = false;
}
if (defer) {
tevent_req_defer_callback(req, state->ev);
}
/*
* Note: here we use talloc_reference() in a way
* that does not expose it to the caller.
*/
inbuf_ref = talloc_reference(state->smb2.recv_iov, inbuf);
if (tevent_req_nomem(inbuf_ref, req)) {
continue;
}
/* copy the related buffers */
state->smb2.recv_iov[0] = cur[1];
state->smb2.recv_iov[1] = cur[2];
state->smb2.recv_iov[2] = cur[3];
tevent_req_done(req);
}
if (defer) {
return NT_STATUS_RETRY;
}
return NT_STATUS_OK;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,929
|
uint8_t smb2cli_conn_get_io_priority(struct smbXcli_conn *conn)
{
if (conn->protocol < PROTOCOL_SMB3_11) {
return 0;
}
return conn->smb2.io_priority;
}
| null | 0
|
uint8_t smb2cli_conn_get_io_priority(struct smbXcli_conn *conn)
{
if (conn->protocol < PROTOCOL_SMB3_11) {
return 0;
}
return conn->smb2.io_priority;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,930
|
uint32_t smb2cli_conn_max_read_size(struct smbXcli_conn *conn)
{
return conn->smb2.server.max_read_size;
}
| null | 0
|
uint32_t smb2cli_conn_max_read_size(struct smbXcli_conn *conn)
{
return conn->smb2.server.max_read_size;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,931
|
uint32_t smb2cli_conn_max_trans_size(struct smbXcli_conn *conn)
{
return conn->smb2.server.max_trans_size;
}
| null | 0
|
uint32_t smb2cli_conn_max_trans_size(struct smbXcli_conn *conn)
{
return conn->smb2.server.max_trans_size;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,932
|
uint32_t smb2cli_conn_max_write_size(struct smbXcli_conn *conn)
{
return conn->smb2.server.max_write_size;
}
| null | 0
|
uint32_t smb2cli_conn_max_write_size(struct smbXcli_conn *conn)
{
return conn->smb2.server.max_write_size;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,933
|
bool smb2cli_conn_req_possible(struct smbXcli_conn *conn, uint32_t *max_dyn_len)
{
uint16_t credits = 1;
if (conn->smb2.cur_credits == 0) {
if (max_dyn_len != NULL) {
*max_dyn_len = 0;
}
return false;
}
if (conn->smb2.server.capabilities & SMB2_CAP_LARGE_MTU) {
credits = conn->smb2.cur_credits;
}
if (max_dyn_len != NULL) {
*max_dyn_len = credits * 65536;
}
return true;
}
| null | 0
|
bool smb2cli_conn_req_possible(struct smbXcli_conn *conn, uint32_t *max_dyn_len)
{
uint16_t credits = 1;
if (conn->smb2.cur_credits == 0) {
if (max_dyn_len != NULL) {
*max_dyn_len = 0;
}
return false;
}
if (conn->smb2.server.capabilities & SMB2_CAP_LARGE_MTU) {
credits = conn->smb2.cur_credits;
}
if (max_dyn_len != NULL) {
*max_dyn_len = credits * 65536;
}
return true;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,934
|
uint16_t smb2cli_conn_server_security_mode(struct smbXcli_conn *conn)
{
return conn->smb2.server.security_mode;
}
| null | 0
|
uint16_t smb2cli_conn_server_security_mode(struct smbXcli_conn *conn)
{
return conn->smb2.server.security_mode;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,935
|
void smb2cli_conn_set_cc_max_chunks(struct smbXcli_conn *conn,
uint32_t max_chunks)
{
conn->smb2.cc_max_chunks = max_chunks;
}
| null | 0
|
void smb2cli_conn_set_cc_max_chunks(struct smbXcli_conn *conn,
uint32_t max_chunks)
{
conn->smb2.cc_max_chunks = max_chunks;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,936
|
void smb2cli_conn_set_io_priority(struct smbXcli_conn *conn,
uint8_t io_priority)
{
conn->smb2.io_priority = io_priority;
}
| null | 0
|
void smb2cli_conn_set_io_priority(struct smbXcli_conn *conn,
uint8_t io_priority)
{
conn->smb2.io_priority = io_priority;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,937
|
void smb2cli_conn_set_max_credits(struct smbXcli_conn *conn,
uint16_t max_credits)
{
conn->smb2.max_credits = max_credits;
}
| null | 0
|
void smb2cli_conn_set_max_credits(struct smbXcli_conn *conn,
uint16_t max_credits)
{
conn->smb2.max_credits = max_credits;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,938
|
static NTSTATUS smb2cli_inbuf_parse_compound(struct smbXcli_conn *conn,
uint8_t *buf,
size_t buflen,
TALLOC_CTX *mem_ctx,
struct iovec **piov, int *pnum_iov)
{
struct iovec *iov;
int num_iov = 0;
size_t taken = 0;
uint8_t *first_hdr = buf;
size_t verified_buflen = 0;
uint8_t *tf = NULL;
size_t tf_len = 0;
iov = talloc_array(mem_ctx, struct iovec, num_iov);
if (iov == NULL) {
return NT_STATUS_NO_MEMORY;
}
while (taken < buflen) {
size_t len = buflen - taken;
uint8_t *hdr = first_hdr + taken;
struct iovec *cur;
size_t full_size;
size_t next_command_ofs;
uint16_t body_size;
struct iovec *iov_tmp;
if (verified_buflen > taken) {
len = verified_buflen - taken;
} else {
tf = NULL;
tf_len = 0;
}
if (len < 4) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len, 4));
goto inval;
}
if (IVAL(hdr, 0) == SMB2_TF_MAGIC) {
struct smbXcli_session *s;
uint64_t uid;
struct iovec tf_iov[2];
size_t enc_len;
NTSTATUS status;
if (len < SMB2_TF_HDR_SIZE) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len, SMB2_TF_HDR_SIZE));
goto inval;
}
tf = hdr;
tf_len = SMB2_TF_HDR_SIZE;
taken += tf_len;
hdr = first_hdr + taken;
enc_len = IVAL(tf, SMB2_TF_MSG_SIZE);
uid = BVAL(tf, SMB2_TF_SESSION_ID);
if (len < SMB2_TF_HDR_SIZE + enc_len) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len,
(int)(SMB2_TF_HDR_SIZE + enc_len)));
goto inval;
}
s = conn->sessions;
for (; s; s = s->next) {
if (s->smb2->session_id != uid) {
continue;
}
break;
}
if (s == NULL) {
DEBUG(10, ("unknown session_id %llu\n",
(unsigned long long)uid));
goto inval;
}
tf_iov[0].iov_base = (void *)tf;
tf_iov[0].iov_len = tf_len;
tf_iov[1].iov_base = (void *)hdr;
tf_iov[1].iov_len = enc_len;
status = smb2_signing_decrypt_pdu(s->smb2->decryption_key,
conn->smb2.server.cipher,
tf_iov, 2);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(iov);
return status;
}
verified_buflen = taken + enc_len;
len = enc_len;
}
/*
* We need the header plus the body length field
*/
if (len < SMB2_HDR_BODY + 2) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len, SMB2_HDR_BODY));
goto inval;
}
if (IVAL(hdr, 0) != SMB2_MAGIC) {
DEBUG(10, ("Got non-SMB2 PDU: %x\n",
IVAL(hdr, 0)));
goto inval;
}
if (SVAL(hdr, 4) != SMB2_HDR_BODY) {
DEBUG(10, ("Got HDR len %d, expected %d\n",
SVAL(hdr, 4), SMB2_HDR_BODY));
goto inval;
}
full_size = len;
next_command_ofs = IVAL(hdr, SMB2_HDR_NEXT_COMMAND);
body_size = SVAL(hdr, SMB2_HDR_BODY);
if (next_command_ofs != 0) {
if (next_command_ofs < (SMB2_HDR_BODY + 2)) {
goto inval;
}
if (next_command_ofs > full_size) {
goto inval;
}
full_size = next_command_ofs;
}
if (body_size < 2) {
goto inval;
}
body_size &= 0xfffe;
if (body_size > (full_size - SMB2_HDR_BODY)) {
goto inval;
}
iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec,
num_iov + 4);
if (iov_tmp == NULL) {
TALLOC_FREE(iov);
return NT_STATUS_NO_MEMORY;
}
iov = iov_tmp;
cur = &iov[num_iov];
num_iov += 4;
cur[0].iov_base = tf;
cur[0].iov_len = tf_len;
cur[1].iov_base = hdr;
cur[1].iov_len = SMB2_HDR_BODY;
cur[2].iov_base = hdr + SMB2_HDR_BODY;
cur[2].iov_len = body_size;
cur[3].iov_base = hdr + SMB2_HDR_BODY + body_size;
cur[3].iov_len = full_size - (SMB2_HDR_BODY + body_size);
taken += full_size;
}
*piov = iov;
*pnum_iov = num_iov;
return NT_STATUS_OK;
inval:
TALLOC_FREE(iov);
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
| null | 0
|
static NTSTATUS smb2cli_inbuf_parse_compound(struct smbXcli_conn *conn,
uint8_t *buf,
size_t buflen,
TALLOC_CTX *mem_ctx,
struct iovec **piov, int *pnum_iov)
{
struct iovec *iov;
int num_iov = 0;
size_t taken = 0;
uint8_t *first_hdr = buf;
size_t verified_buflen = 0;
uint8_t *tf = NULL;
size_t tf_len = 0;
iov = talloc_array(mem_ctx, struct iovec, num_iov);
if (iov == NULL) {
return NT_STATUS_NO_MEMORY;
}
while (taken < buflen) {
size_t len = buflen - taken;
uint8_t *hdr = first_hdr + taken;
struct iovec *cur;
size_t full_size;
size_t next_command_ofs;
uint16_t body_size;
struct iovec *iov_tmp;
if (verified_buflen > taken) {
len = verified_buflen - taken;
} else {
tf = NULL;
tf_len = 0;
}
if (len < 4) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len, 4));
goto inval;
}
if (IVAL(hdr, 0) == SMB2_TF_MAGIC) {
struct smbXcli_session *s;
uint64_t uid;
struct iovec tf_iov[2];
size_t enc_len;
NTSTATUS status;
if (len < SMB2_TF_HDR_SIZE) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len, SMB2_TF_HDR_SIZE));
goto inval;
}
tf = hdr;
tf_len = SMB2_TF_HDR_SIZE;
taken += tf_len;
hdr = first_hdr + taken;
enc_len = IVAL(tf, SMB2_TF_MSG_SIZE);
uid = BVAL(tf, SMB2_TF_SESSION_ID);
if (len < SMB2_TF_HDR_SIZE + enc_len) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len,
(int)(SMB2_TF_HDR_SIZE + enc_len)));
goto inval;
}
s = conn->sessions;
for (; s; s = s->next) {
if (s->smb2->session_id != uid) {
continue;
}
break;
}
if (s == NULL) {
DEBUG(10, ("unknown session_id %llu\n",
(unsigned long long)uid));
goto inval;
}
tf_iov[0].iov_base = (void *)tf;
tf_iov[0].iov_len = tf_len;
tf_iov[1].iov_base = (void *)hdr;
tf_iov[1].iov_len = enc_len;
status = smb2_signing_decrypt_pdu(s->smb2->decryption_key,
conn->smb2.server.cipher,
tf_iov, 2);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(iov);
return status;
}
verified_buflen = taken + enc_len;
len = enc_len;
}
/*
* We need the header plus the body length field
*/
if (len < SMB2_HDR_BODY + 2) {
DEBUG(10, ("%d bytes left, expected at least %d\n",
(int)len, SMB2_HDR_BODY));
goto inval;
}
if (IVAL(hdr, 0) != SMB2_MAGIC) {
DEBUG(10, ("Got non-SMB2 PDU: %x\n",
IVAL(hdr, 0)));
goto inval;
}
if (SVAL(hdr, 4) != SMB2_HDR_BODY) {
DEBUG(10, ("Got HDR len %d, expected %d\n",
SVAL(hdr, 4), SMB2_HDR_BODY));
goto inval;
}
full_size = len;
next_command_ofs = IVAL(hdr, SMB2_HDR_NEXT_COMMAND);
body_size = SVAL(hdr, SMB2_HDR_BODY);
if (next_command_ofs != 0) {
if (next_command_ofs < (SMB2_HDR_BODY + 2)) {
goto inval;
}
if (next_command_ofs > full_size) {
goto inval;
}
full_size = next_command_ofs;
}
if (body_size < 2) {
goto inval;
}
body_size &= 0xfffe;
if (body_size > (full_size - SMB2_HDR_BODY)) {
goto inval;
}
iov_tmp = talloc_realloc(mem_ctx, iov, struct iovec,
num_iov + 4);
if (iov_tmp == NULL) {
TALLOC_FREE(iov);
return NT_STATUS_NO_MEMORY;
}
iov = iov_tmp;
cur = &iov[num_iov];
num_iov += 4;
cur[0].iov_base = tf;
cur[0].iov_len = tf_len;
cur[1].iov_base = hdr;
cur[1].iov_len = SMB2_HDR_BODY;
cur[2].iov_base = hdr + SMB2_HDR_BODY;
cur[2].iov_len = body_size;
cur[3].iov_base = hdr + SMB2_HDR_BODY + body_size;
cur[3].iov_len = full_size - (SMB2_HDR_BODY + body_size);
taken += full_size;
}
*piov = iov;
*pnum_iov = num_iov;
return NT_STATUS_OK;
inval:
TALLOC_FREE(iov);
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,939
|
static bool smb2cli_req_cancel(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
struct smbXcli_tcon *tcon = state->tcon;
struct smbXcli_session *session = state->session;
uint8_t *fixed = state->smb2.pad;
uint16_t fixed_len = 4;
struct tevent_req *subreq;
struct smbXcli_req_state *substate;
NTSTATUS status;
SSVAL(fixed, 0, 0x04);
SSVAL(fixed, 2, 0);
subreq = smb2cli_req_create(state, state->ev,
state->conn,
SMB2_OP_CANCEL,
0, 0, /* flags */
0, /* timeout */
tcon, session,
fixed, fixed_len,
NULL, 0, 0);
if (subreq == NULL) {
return false;
}
substate = tevent_req_data(subreq, struct smbXcli_req_state);
SIVAL(substate->smb2.hdr, SMB2_HDR_FLAGS, state->smb2.cancel_flags);
SBVAL(substate->smb2.hdr, SMB2_HDR_MESSAGE_ID, state->smb2.cancel_mid);
SBVAL(substate->smb2.hdr, SMB2_HDR_ASYNC_ID, state->smb2.cancel_aid);
status = smb2cli_req_compound_submit(&subreq, 1);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(subreq);
return false;
}
tevent_req_set_callback(subreq, smb2cli_req_cancel_done, NULL);
return true;
}
| null | 0
|
static bool smb2cli_req_cancel(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
struct smbXcli_tcon *tcon = state->tcon;
struct smbXcli_session *session = state->session;
uint8_t *fixed = state->smb2.pad;
uint16_t fixed_len = 4;
struct tevent_req *subreq;
struct smbXcli_req_state *substate;
NTSTATUS status;
SSVAL(fixed, 0, 0x04);
SSVAL(fixed, 2, 0);
subreq = smb2cli_req_create(state, state->ev,
state->conn,
SMB2_OP_CANCEL,
0, 0, /* flags */
0, /* timeout */
tcon, session,
fixed, fixed_len,
NULL, 0, 0);
if (subreq == NULL) {
return false;
}
substate = tevent_req_data(subreq, struct smbXcli_req_state);
SIVAL(substate->smb2.hdr, SMB2_HDR_FLAGS, state->smb2.cancel_flags);
SBVAL(substate->smb2.hdr, SMB2_HDR_MESSAGE_ID, state->smb2.cancel_mid);
SBVAL(substate->smb2.hdr, SMB2_HDR_ASYNC_ID, state->smb2.cancel_aid);
status = smb2cli_req_compound_submit(&subreq, 1);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(subreq);
return false;
}
tevent_req_set_callback(subreq, smb2cli_req_cancel_done, NULL);
return true;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,940
|
static void smb2cli_req_cancel_done(struct tevent_req *subreq)
{
/* we do not care about the result */
TALLOC_FREE(subreq);
}
| null | 0
|
static void smb2cli_req_cancel_done(struct tevent_req *subreq)
{
/* we do not care about the result */
TALLOC_FREE(subreq);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,941
|
NTSTATUS smb2cli_req_compound_submit(struct tevent_req **reqs,
int num_reqs)
{
struct smbXcli_req_state *state;
struct tevent_req *subreq;
struct iovec *iov;
int i, num_iov, nbt_len;
int tf_iov = -1;
const DATA_BLOB *encryption_key = NULL;
uint64_t encryption_session_id = 0;
uint64_t nonce_high = UINT64_MAX;
uint64_t nonce_low = UINT64_MAX;
/*
* 1 for the nbt length, optional TRANSFORM
* per request: HDR, fixed, dyn, padding
* -1 because the last one does not need padding
*/
iov = talloc_array(reqs[0], struct iovec, 1 + 1 + 4*num_reqs - 1);
if (iov == NULL) {
return NT_STATUS_NO_MEMORY;
}
num_iov = 1;
nbt_len = 0;
/*
* the session of the first request that requires encryption
* specifies the encryption key.
*/
for (i=0; i<num_reqs; i++) {
if (!tevent_req_is_in_progress(reqs[i])) {
return NT_STATUS_INTERNAL_ERROR;
}
state = tevent_req_data(reqs[i], struct smbXcli_req_state);
if (!smbXcli_conn_is_connected(state->conn)) {
return NT_STATUS_CONNECTION_DISCONNECTED;
}
if ((state->conn->protocol != PROTOCOL_NONE) &&
(state->conn->protocol < PROTOCOL_SMB2_02)) {
return NT_STATUS_REVISION_MISMATCH;
}
if (state->session == NULL) {
continue;
}
if (!state->smb2.should_encrypt) {
continue;
}
encryption_key = &state->session->smb2->encryption_key;
if (encryption_key->length == 0) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
encryption_session_id = state->session->smb2->session_id;
state->session->smb2->nonce_low += 1;
if (state->session->smb2->nonce_low == 0) {
state->session->smb2->nonce_high += 1;
state->session->smb2->nonce_low += 1;
}
/*
* CCM and GCM algorithms must never have their
* nonce wrap, or the security of the whole
* communication and the keys is destroyed.
* We must drop the connection once we have
* transfered too much data.
*
* NOTE: We assume nonces greater than 8 bytes.
*/
if (state->session->smb2->nonce_high >=
state->session->smb2->nonce_high_max)
{
return NT_STATUS_ENCRYPTION_FAILED;
}
nonce_high = state->session->smb2->nonce_high_random;
nonce_high += state->session->smb2->nonce_high;
nonce_low = state->session->smb2->nonce_low;
tf_iov = num_iov;
iov[num_iov].iov_base = state->smb2.transform;
iov[num_iov].iov_len = sizeof(state->smb2.transform);
num_iov += 1;
SBVAL(state->smb2.transform, SMB2_TF_PROTOCOL_ID, SMB2_TF_MAGIC);
SBVAL(state->smb2.transform, SMB2_TF_NONCE,
nonce_low);
SBVAL(state->smb2.transform, SMB2_TF_NONCE+8,
nonce_high);
SBVAL(state->smb2.transform, SMB2_TF_SESSION_ID,
encryption_session_id);
nbt_len += SMB2_TF_HDR_SIZE;
break;
}
for (i=0; i<num_reqs; i++) {
int hdr_iov;
size_t reqlen;
bool ret;
uint16_t opcode;
uint64_t avail;
uint16_t charge;
uint16_t credits;
uint64_t mid;
const DATA_BLOB *signing_key = NULL;
if (!tevent_req_is_in_progress(reqs[i])) {
return NT_STATUS_INTERNAL_ERROR;
}
state = tevent_req_data(reqs[i], struct smbXcli_req_state);
if (!smbXcli_conn_is_connected(state->conn)) {
return NT_STATUS_CONNECTION_DISCONNECTED;
}
if ((state->conn->protocol != PROTOCOL_NONE) &&
(state->conn->protocol < PROTOCOL_SMB2_02)) {
return NT_STATUS_REVISION_MISMATCH;
}
opcode = SVAL(state->smb2.hdr, SMB2_HDR_OPCODE);
if (opcode == SMB2_OP_CANCEL) {
goto skip_credits;
}
avail = UINT64_MAX - state->conn->smb2.mid;
if (avail < 1) {
return NT_STATUS_CONNECTION_ABORTED;
}
if (state->conn->smb2.server.capabilities & SMB2_CAP_LARGE_MTU) {
uint32_t max_dyn_len = 1;
max_dyn_len = MAX(max_dyn_len, state->smb2.dyn_len);
max_dyn_len = MAX(max_dyn_len, state->smb2.max_dyn_len);
charge = (max_dyn_len - 1)/ 65536 + 1;
} else {
charge = 1;
}
charge = MAX(state->smb2.credit_charge, charge);
avail = MIN(avail, state->conn->smb2.cur_credits);
if (avail < charge) {
return NT_STATUS_INTERNAL_ERROR;
}
credits = 0;
if (state->conn->smb2.max_credits > state->conn->smb2.cur_credits) {
credits = state->conn->smb2.max_credits -
state->conn->smb2.cur_credits;
}
if (state->conn->smb2.max_credits >= state->conn->smb2.cur_credits) {
credits += 1;
}
mid = state->conn->smb2.mid;
state->conn->smb2.mid += charge;
state->conn->smb2.cur_credits -= charge;
if (state->conn->smb2.server.capabilities & SMB2_CAP_LARGE_MTU) {
SSVAL(state->smb2.hdr, SMB2_HDR_CREDIT_CHARGE, charge);
}
SSVAL(state->smb2.hdr, SMB2_HDR_CREDIT, credits);
SBVAL(state->smb2.hdr, SMB2_HDR_MESSAGE_ID, mid);
state->smb2.cancel_flags = 0;
state->smb2.cancel_mid = mid;
state->smb2.cancel_aid = 0;
skip_credits:
if (state->session && encryption_key == NULL) {
/*
* We prefer the channel signing key if it is
* already there.
*/
if (state->smb2.should_sign) {
signing_key = &state->session->smb2_channel.signing_key;
}
/*
* If it is a channel binding, we already have the main
* signing key and try that one.
*/
if (signing_key && signing_key->length == 0) {
signing_key = &state->session->smb2->signing_key;
}
/*
* If we do not have any session key yet, we skip the
* signing of SMB2_OP_SESSSETUP requests.
*/
if (signing_key && signing_key->length == 0) {
signing_key = NULL;
}
}
hdr_iov = num_iov;
iov[num_iov].iov_base = state->smb2.hdr;
iov[num_iov].iov_len = sizeof(state->smb2.hdr);
num_iov += 1;
iov[num_iov].iov_base = discard_const(state->smb2.fixed);
iov[num_iov].iov_len = state->smb2.fixed_len;
num_iov += 1;
if (state->smb2.dyn != NULL) {
iov[num_iov].iov_base = discard_const(state->smb2.dyn);
iov[num_iov].iov_len = state->smb2.dyn_len;
num_iov += 1;
}
reqlen = sizeof(state->smb2.hdr);
reqlen += state->smb2.fixed_len;
reqlen += state->smb2.dyn_len;
if (i < num_reqs-1) {
if ((reqlen % 8) > 0) {
uint8_t pad = 8 - (reqlen % 8);
iov[num_iov].iov_base = state->smb2.pad;
iov[num_iov].iov_len = pad;
num_iov += 1;
reqlen += pad;
}
SIVAL(state->smb2.hdr, SMB2_HDR_NEXT_COMMAND, reqlen);
}
state->smb2.encryption_session_id = encryption_session_id;
if (signing_key != NULL) {
NTSTATUS status;
status = smb2_signing_sign_pdu(*signing_key,
state->session->conn->protocol,
&iov[hdr_iov], num_iov - hdr_iov);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
}
nbt_len += reqlen;
ret = smbXcli_req_set_pending(reqs[i]);
if (!ret) {
return NT_STATUS_NO_MEMORY;
}
}
state = tevent_req_data(reqs[0], struct smbXcli_req_state);
_smb_setlen_tcp(state->length_hdr, nbt_len);
iov[0].iov_base = state->length_hdr;
iov[0].iov_len = sizeof(state->length_hdr);
if (encryption_key != NULL) {
NTSTATUS status;
size_t buflen = nbt_len - SMB2_TF_HDR_SIZE;
uint8_t *buf;
int vi;
buf = talloc_array(iov, uint8_t, buflen);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
/*
* We copy the buffers before encrypting them,
* this is at least currently needed for the
* to keep state->smb2.hdr.
*
* Also the callers may expect there buffers
* to be const.
*/
for (vi = tf_iov + 1; vi < num_iov; vi++) {
struct iovec *v = &iov[vi];
const uint8_t *o = (const uint8_t *)v->iov_base;
memcpy(buf, o, v->iov_len);
v->iov_base = (void *)buf;
buf += v->iov_len;
}
status = smb2_signing_encrypt_pdu(*encryption_key,
state->conn->smb2.server.cipher,
&iov[tf_iov], num_iov - tf_iov);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
}
if (state->conn->dispatch_incoming == NULL) {
state->conn->dispatch_incoming = smb2cli_conn_dispatch_incoming;
}
subreq = writev_send(state, state->ev, state->conn->outgoing,
state->conn->sock_fd, false, iov, num_iov);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
tevent_req_set_callback(subreq, smb2cli_req_writev_done, reqs[0]);
state->write_req = subreq;
return NT_STATUS_OK;
}
| null | 0
|
NTSTATUS smb2cli_req_compound_submit(struct tevent_req **reqs,
int num_reqs)
{
struct smbXcli_req_state *state;
struct tevent_req *subreq;
struct iovec *iov;
int i, num_iov, nbt_len;
int tf_iov = -1;
const DATA_BLOB *encryption_key = NULL;
uint64_t encryption_session_id = 0;
uint64_t nonce_high = UINT64_MAX;
uint64_t nonce_low = UINT64_MAX;
/*
* 1 for the nbt length, optional TRANSFORM
* per request: HDR, fixed, dyn, padding
* -1 because the last one does not need padding
*/
iov = talloc_array(reqs[0], struct iovec, 1 + 1 + 4*num_reqs - 1);
if (iov == NULL) {
return NT_STATUS_NO_MEMORY;
}
num_iov = 1;
nbt_len = 0;
/*
* the session of the first request that requires encryption
* specifies the encryption key.
*/
for (i=0; i<num_reqs; i++) {
if (!tevent_req_is_in_progress(reqs[i])) {
return NT_STATUS_INTERNAL_ERROR;
}
state = tevent_req_data(reqs[i], struct smbXcli_req_state);
if (!smbXcli_conn_is_connected(state->conn)) {
return NT_STATUS_CONNECTION_DISCONNECTED;
}
if ((state->conn->protocol != PROTOCOL_NONE) &&
(state->conn->protocol < PROTOCOL_SMB2_02)) {
return NT_STATUS_REVISION_MISMATCH;
}
if (state->session == NULL) {
continue;
}
if (!state->smb2.should_encrypt) {
continue;
}
encryption_key = &state->session->smb2->encryption_key;
if (encryption_key->length == 0) {
return NT_STATUS_INVALID_PARAMETER_MIX;
}
encryption_session_id = state->session->smb2->session_id;
state->session->smb2->nonce_low += 1;
if (state->session->smb2->nonce_low == 0) {
state->session->smb2->nonce_high += 1;
state->session->smb2->nonce_low += 1;
}
/*
* CCM and GCM algorithms must never have their
* nonce wrap, or the security of the whole
* communication and the keys is destroyed.
* We must drop the connection once we have
* transfered too much data.
*
* NOTE: We assume nonces greater than 8 bytes.
*/
if (state->session->smb2->nonce_high >=
state->session->smb2->nonce_high_max)
{
return NT_STATUS_ENCRYPTION_FAILED;
}
nonce_high = state->session->smb2->nonce_high_random;
nonce_high += state->session->smb2->nonce_high;
nonce_low = state->session->smb2->nonce_low;
tf_iov = num_iov;
iov[num_iov].iov_base = state->smb2.transform;
iov[num_iov].iov_len = sizeof(state->smb2.transform);
num_iov += 1;
SBVAL(state->smb2.transform, SMB2_TF_PROTOCOL_ID, SMB2_TF_MAGIC);
SBVAL(state->smb2.transform, SMB2_TF_NONCE,
nonce_low);
SBVAL(state->smb2.transform, SMB2_TF_NONCE+8,
nonce_high);
SBVAL(state->smb2.transform, SMB2_TF_SESSION_ID,
encryption_session_id);
nbt_len += SMB2_TF_HDR_SIZE;
break;
}
for (i=0; i<num_reqs; i++) {
int hdr_iov;
size_t reqlen;
bool ret;
uint16_t opcode;
uint64_t avail;
uint16_t charge;
uint16_t credits;
uint64_t mid;
const DATA_BLOB *signing_key = NULL;
if (!tevent_req_is_in_progress(reqs[i])) {
return NT_STATUS_INTERNAL_ERROR;
}
state = tevent_req_data(reqs[i], struct smbXcli_req_state);
if (!smbXcli_conn_is_connected(state->conn)) {
return NT_STATUS_CONNECTION_DISCONNECTED;
}
if ((state->conn->protocol != PROTOCOL_NONE) &&
(state->conn->protocol < PROTOCOL_SMB2_02)) {
return NT_STATUS_REVISION_MISMATCH;
}
opcode = SVAL(state->smb2.hdr, SMB2_HDR_OPCODE);
if (opcode == SMB2_OP_CANCEL) {
goto skip_credits;
}
avail = UINT64_MAX - state->conn->smb2.mid;
if (avail < 1) {
return NT_STATUS_CONNECTION_ABORTED;
}
if (state->conn->smb2.server.capabilities & SMB2_CAP_LARGE_MTU) {
uint32_t max_dyn_len = 1;
max_dyn_len = MAX(max_dyn_len, state->smb2.dyn_len);
max_dyn_len = MAX(max_dyn_len, state->smb2.max_dyn_len);
charge = (max_dyn_len - 1)/ 65536 + 1;
} else {
charge = 1;
}
charge = MAX(state->smb2.credit_charge, charge);
avail = MIN(avail, state->conn->smb2.cur_credits);
if (avail < charge) {
return NT_STATUS_INTERNAL_ERROR;
}
credits = 0;
if (state->conn->smb2.max_credits > state->conn->smb2.cur_credits) {
credits = state->conn->smb2.max_credits -
state->conn->smb2.cur_credits;
}
if (state->conn->smb2.max_credits >= state->conn->smb2.cur_credits) {
credits += 1;
}
mid = state->conn->smb2.mid;
state->conn->smb2.mid += charge;
state->conn->smb2.cur_credits -= charge;
if (state->conn->smb2.server.capabilities & SMB2_CAP_LARGE_MTU) {
SSVAL(state->smb2.hdr, SMB2_HDR_CREDIT_CHARGE, charge);
}
SSVAL(state->smb2.hdr, SMB2_HDR_CREDIT, credits);
SBVAL(state->smb2.hdr, SMB2_HDR_MESSAGE_ID, mid);
state->smb2.cancel_flags = 0;
state->smb2.cancel_mid = mid;
state->smb2.cancel_aid = 0;
skip_credits:
if (state->session && encryption_key == NULL) {
/*
* We prefer the channel signing key if it is
* already there.
*/
if (state->smb2.should_sign) {
signing_key = &state->session->smb2_channel.signing_key;
}
/*
* If it is a channel binding, we already have the main
* signing key and try that one.
*/
if (signing_key && signing_key->length == 0) {
signing_key = &state->session->smb2->signing_key;
}
/*
* If we do not have any session key yet, we skip the
* signing of SMB2_OP_SESSSETUP requests.
*/
if (signing_key && signing_key->length == 0) {
signing_key = NULL;
}
}
hdr_iov = num_iov;
iov[num_iov].iov_base = state->smb2.hdr;
iov[num_iov].iov_len = sizeof(state->smb2.hdr);
num_iov += 1;
iov[num_iov].iov_base = discard_const(state->smb2.fixed);
iov[num_iov].iov_len = state->smb2.fixed_len;
num_iov += 1;
if (state->smb2.dyn != NULL) {
iov[num_iov].iov_base = discard_const(state->smb2.dyn);
iov[num_iov].iov_len = state->smb2.dyn_len;
num_iov += 1;
}
reqlen = sizeof(state->smb2.hdr);
reqlen += state->smb2.fixed_len;
reqlen += state->smb2.dyn_len;
if (i < num_reqs-1) {
if ((reqlen % 8) > 0) {
uint8_t pad = 8 - (reqlen % 8);
iov[num_iov].iov_base = state->smb2.pad;
iov[num_iov].iov_len = pad;
num_iov += 1;
reqlen += pad;
}
SIVAL(state->smb2.hdr, SMB2_HDR_NEXT_COMMAND, reqlen);
}
state->smb2.encryption_session_id = encryption_session_id;
if (signing_key != NULL) {
NTSTATUS status;
status = smb2_signing_sign_pdu(*signing_key,
state->session->conn->protocol,
&iov[hdr_iov], num_iov - hdr_iov);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
}
nbt_len += reqlen;
ret = smbXcli_req_set_pending(reqs[i]);
if (!ret) {
return NT_STATUS_NO_MEMORY;
}
}
state = tevent_req_data(reqs[0], struct smbXcli_req_state);
_smb_setlen_tcp(state->length_hdr, nbt_len);
iov[0].iov_base = state->length_hdr;
iov[0].iov_len = sizeof(state->length_hdr);
if (encryption_key != NULL) {
NTSTATUS status;
size_t buflen = nbt_len - SMB2_TF_HDR_SIZE;
uint8_t *buf;
int vi;
buf = talloc_array(iov, uint8_t, buflen);
if (buf == NULL) {
return NT_STATUS_NO_MEMORY;
}
/*
* We copy the buffers before encrypting them,
* this is at least currently needed for the
* to keep state->smb2.hdr.
*
* Also the callers may expect there buffers
* to be const.
*/
for (vi = tf_iov + 1; vi < num_iov; vi++) {
struct iovec *v = &iov[vi];
const uint8_t *o = (const uint8_t *)v->iov_base;
memcpy(buf, o, v->iov_len);
v->iov_base = (void *)buf;
buf += v->iov_len;
}
status = smb2_signing_encrypt_pdu(*encryption_key,
state->conn->smb2.server.cipher,
&iov[tf_iov], num_iov - tf_iov);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
}
if (state->conn->dispatch_incoming == NULL) {
state->conn->dispatch_incoming = smb2cli_conn_dispatch_incoming;
}
subreq = writev_send(state, state->ev, state->conn->outgoing,
state->conn->sock_fd, false, iov, num_iov);
if (subreq == NULL) {
return NT_STATUS_NO_MEMORY;
}
tevent_req_set_callback(subreq, smb2cli_req_writev_done, reqs[0]);
state->write_req = subreq;
return NT_STATUS_OK;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,942
|
struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint16_t cmd,
uint32_t additional_flags,
uint32_t clear_flags,
uint32_t timeout_msec,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
const uint8_t *fixed,
uint16_t fixed_len,
const uint8_t *dyn,
uint32_t dyn_len,
uint32_t max_dyn_len)
{
struct tevent_req *req;
struct smbXcli_req_state *state;
uint32_t flags = 0;
uint32_t tid = 0;
uint64_t uid = 0;
bool use_channel_sequence = false;
uint16_t channel_sequence = 0;
bool use_replay_flag = false;
req = tevent_req_create(mem_ctx, &state,
struct smbXcli_req_state);
if (req == NULL) {
return NULL;
}
state->ev = ev;
state->conn = conn;
state->session = session;
state->tcon = tcon;
if (conn->smb2.server.capabilities & SMB2_CAP_PERSISTENT_HANDLES) {
use_channel_sequence = true;
} else if (conn->smb2.server.capabilities & SMB2_CAP_MULTI_CHANNEL) {
use_channel_sequence = true;
}
if (smbXcli_conn_protocol(conn) >= PROTOCOL_SMB3_00) {
use_replay_flag = true;
}
if (smbXcli_conn_protocol(conn) >= PROTOCOL_SMB3_11) {
flags |= SMB2_PRIORITY_VALUE_TO_MASK(conn->smb2.io_priority);
}
if (session) {
uid = session->smb2->session_id;
if (use_channel_sequence) {
channel_sequence = session->smb2->channel_sequence;
}
if (use_replay_flag && session->smb2->replay_active) {
additional_flags |= SMB2_HDR_FLAG_REPLAY_OPERATION;
}
state->smb2.should_sign = session->smb2->should_sign;
state->smb2.should_encrypt = session->smb2->should_encrypt;
if (cmd == SMB2_OP_SESSSETUP &&
session->smb2_channel.signing_key.length == 0 &&
session->smb2->signing_key.length != 0)
{
/*
* a session bind needs to be signed
*/
state->smb2.should_sign = true;
}
if (cmd == SMB2_OP_SESSSETUP &&
session->smb2_channel.signing_key.length == 0) {
state->smb2.should_encrypt = false;
}
if (additional_flags & SMB2_HDR_FLAG_SIGNED) {
if (session->smb2_channel.signing_key.length == 0) {
tevent_req_nterror(req, NT_STATUS_NO_USER_SESSION_KEY);
return req;
}
additional_flags &= ~SMB2_HDR_FLAG_SIGNED;
state->smb2.should_sign = true;
}
}
if (tcon) {
tid = tcon->smb2.tcon_id;
if (tcon->smb2.should_sign) {
state->smb2.should_sign = true;
}
if (tcon->smb2.should_encrypt) {
state->smb2.should_encrypt = true;
}
}
if (state->smb2.should_encrypt) {
state->smb2.should_sign = false;
}
state->smb2.recv_iov = talloc_zero_array(state, struct iovec, 3);
if (state->smb2.recv_iov == NULL) {
TALLOC_FREE(req);
return NULL;
}
flags |= additional_flags;
flags &= ~clear_flags;
state->smb2.fixed = fixed;
state->smb2.fixed_len = fixed_len;
state->smb2.dyn = dyn;
state->smb2.dyn_len = dyn_len;
state->smb2.max_dyn_len = max_dyn_len;
if (state->smb2.should_encrypt) {
SIVAL(state->smb2.transform, SMB2_TF_PROTOCOL_ID, SMB2_TF_MAGIC);
SBVAL(state->smb2.transform, SMB2_TF_SESSION_ID, uid);
}
SIVAL(state->smb2.hdr, SMB2_HDR_PROTOCOL_ID, SMB2_MAGIC);
SSVAL(state->smb2.hdr, SMB2_HDR_LENGTH, SMB2_HDR_BODY);
SSVAL(state->smb2.hdr, SMB2_HDR_OPCODE, cmd);
SSVAL(state->smb2.hdr, SMB2_HDR_CHANNEL_SEQUENCE, channel_sequence);
SIVAL(state->smb2.hdr, SMB2_HDR_FLAGS, flags);
SIVAL(state->smb2.hdr, SMB2_HDR_PID, 0); /* reserved */
SIVAL(state->smb2.hdr, SMB2_HDR_TID, tid);
SBVAL(state->smb2.hdr, SMB2_HDR_SESSION_ID, uid);
switch (cmd) {
case SMB2_OP_CANCEL:
state->one_way = true;
break;
case SMB2_OP_BREAK:
/*
* If this is a dummy request, it will have
* UINT64_MAX as message id.
* If we send on break acknowledgement,
* this gets overwritten later.
*/
SBVAL(state->smb2.hdr, SMB2_HDR_MESSAGE_ID, UINT64_MAX);
break;
}
if (timeout_msec > 0) {
struct timeval endtime;
endtime = timeval_current_ofs_msec(timeout_msec);
if (!tevent_req_set_endtime(req, ev, endtime)) {
return req;
}
}
return req;
}
| null | 0
|
struct tevent_req *smb2cli_req_create(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint16_t cmd,
uint32_t additional_flags,
uint32_t clear_flags,
uint32_t timeout_msec,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
const uint8_t *fixed,
uint16_t fixed_len,
const uint8_t *dyn,
uint32_t dyn_len,
uint32_t max_dyn_len)
{
struct tevent_req *req;
struct smbXcli_req_state *state;
uint32_t flags = 0;
uint32_t tid = 0;
uint64_t uid = 0;
bool use_channel_sequence = false;
uint16_t channel_sequence = 0;
bool use_replay_flag = false;
req = tevent_req_create(mem_ctx, &state,
struct smbXcli_req_state);
if (req == NULL) {
return NULL;
}
state->ev = ev;
state->conn = conn;
state->session = session;
state->tcon = tcon;
if (conn->smb2.server.capabilities & SMB2_CAP_PERSISTENT_HANDLES) {
use_channel_sequence = true;
} else if (conn->smb2.server.capabilities & SMB2_CAP_MULTI_CHANNEL) {
use_channel_sequence = true;
}
if (smbXcli_conn_protocol(conn) >= PROTOCOL_SMB3_00) {
use_replay_flag = true;
}
if (smbXcli_conn_protocol(conn) >= PROTOCOL_SMB3_11) {
flags |= SMB2_PRIORITY_VALUE_TO_MASK(conn->smb2.io_priority);
}
if (session) {
uid = session->smb2->session_id;
if (use_channel_sequence) {
channel_sequence = session->smb2->channel_sequence;
}
if (use_replay_flag && session->smb2->replay_active) {
additional_flags |= SMB2_HDR_FLAG_REPLAY_OPERATION;
}
state->smb2.should_sign = session->smb2->should_sign;
state->smb2.should_encrypt = session->smb2->should_encrypt;
if (cmd == SMB2_OP_SESSSETUP &&
session->smb2_channel.signing_key.length == 0 &&
session->smb2->signing_key.length != 0)
{
/*
* a session bind needs to be signed
*/
state->smb2.should_sign = true;
}
if (cmd == SMB2_OP_SESSSETUP &&
session->smb2_channel.signing_key.length == 0) {
state->smb2.should_encrypt = false;
}
if (additional_flags & SMB2_HDR_FLAG_SIGNED) {
if (session->smb2_channel.signing_key.length == 0) {
tevent_req_nterror(req, NT_STATUS_NO_USER_SESSION_KEY);
return req;
}
additional_flags &= ~SMB2_HDR_FLAG_SIGNED;
state->smb2.should_sign = true;
}
}
if (tcon) {
tid = tcon->smb2.tcon_id;
if (tcon->smb2.should_sign) {
state->smb2.should_sign = true;
}
if (tcon->smb2.should_encrypt) {
state->smb2.should_encrypt = true;
}
}
if (state->smb2.should_encrypt) {
state->smb2.should_sign = false;
}
state->smb2.recv_iov = talloc_zero_array(state, struct iovec, 3);
if (state->smb2.recv_iov == NULL) {
TALLOC_FREE(req);
return NULL;
}
flags |= additional_flags;
flags &= ~clear_flags;
state->smb2.fixed = fixed;
state->smb2.fixed_len = fixed_len;
state->smb2.dyn = dyn;
state->smb2.dyn_len = dyn_len;
state->smb2.max_dyn_len = max_dyn_len;
if (state->smb2.should_encrypt) {
SIVAL(state->smb2.transform, SMB2_TF_PROTOCOL_ID, SMB2_TF_MAGIC);
SBVAL(state->smb2.transform, SMB2_TF_SESSION_ID, uid);
}
SIVAL(state->smb2.hdr, SMB2_HDR_PROTOCOL_ID, SMB2_MAGIC);
SSVAL(state->smb2.hdr, SMB2_HDR_LENGTH, SMB2_HDR_BODY);
SSVAL(state->smb2.hdr, SMB2_HDR_OPCODE, cmd);
SSVAL(state->smb2.hdr, SMB2_HDR_CHANNEL_SEQUENCE, channel_sequence);
SIVAL(state->smb2.hdr, SMB2_HDR_FLAGS, flags);
SIVAL(state->smb2.hdr, SMB2_HDR_PID, 0); /* reserved */
SIVAL(state->smb2.hdr, SMB2_HDR_TID, tid);
SBVAL(state->smb2.hdr, SMB2_HDR_SESSION_ID, uid);
switch (cmd) {
case SMB2_OP_CANCEL:
state->one_way = true;
break;
case SMB2_OP_BREAK:
/*
* If this is a dummy request, it will have
* UINT64_MAX as message id.
* If we send on break acknowledgement,
* this gets overwritten later.
*/
SBVAL(state->smb2.hdr, SMB2_HDR_MESSAGE_ID, UINT64_MAX);
break;
}
if (timeout_msec > 0) {
struct timeval endtime;
endtime = timeval_current_ofs_msec(timeout_msec);
if (!tevent_req_set_endtime(req, ev, endtime)) {
return req;
}
}
return req;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,943
|
NTSTATUS smb2cli_req_get_sent_iov(struct tevent_req *req,
struct iovec *sent_iov)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
if (tevent_req_is_in_progress(req)) {
return STATUS_PENDING;
}
sent_iov[0].iov_base = state->smb2.hdr;
sent_iov[0].iov_len = sizeof(state->smb2.hdr);
sent_iov[1].iov_base = discard_const(state->smb2.fixed);
sent_iov[1].iov_len = state->smb2.fixed_len;
if (state->smb2.dyn != NULL) {
sent_iov[2].iov_base = discard_const(state->smb2.dyn);
sent_iov[2].iov_len = state->smb2.dyn_len;
} else {
sent_iov[2].iov_base = NULL;
sent_iov[2].iov_len = 0;
}
return NT_STATUS_OK;
}
| null | 0
|
NTSTATUS smb2cli_req_get_sent_iov(struct tevent_req *req,
struct iovec *sent_iov)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
if (tevent_req_is_in_progress(req)) {
return STATUS_PENDING;
}
sent_iov[0].iov_base = state->smb2.hdr;
sent_iov[0].iov_len = sizeof(state->smb2.hdr);
sent_iov[1].iov_base = discard_const(state->smb2.fixed);
sent_iov[1].iov_len = state->smb2.fixed_len;
if (state->smb2.dyn != NULL) {
sent_iov[2].iov_base = discard_const(state->smb2.dyn);
sent_iov[2].iov_len = state->smb2.dyn_len;
} else {
sent_iov[2].iov_base = NULL;
sent_iov[2].iov_len = 0;
}
return NT_STATUS_OK;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,944
|
struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint16_t cmd,
uint32_t additional_flags,
uint32_t clear_flags,
uint32_t timeout_msec,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
const uint8_t *fixed,
uint16_t fixed_len,
const uint8_t *dyn,
uint32_t dyn_len,
uint32_t max_dyn_len)
{
struct tevent_req *req;
NTSTATUS status;
req = smb2cli_req_create(mem_ctx, ev, conn, cmd,
additional_flags, clear_flags,
timeout_msec,
tcon, session,
fixed, fixed_len,
dyn, dyn_len,
max_dyn_len);
if (req == NULL) {
return NULL;
}
if (!tevent_req_is_in_progress(req)) {
return tevent_req_post(req, ev);
}
status = smb2cli_req_compound_submit(&req, 1);
if (tevent_req_nterror(req, status)) {
return tevent_req_post(req, ev);
}
return req;
}
| null | 0
|
struct tevent_req *smb2cli_req_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXcli_conn *conn,
uint16_t cmd,
uint32_t additional_flags,
uint32_t clear_flags,
uint32_t timeout_msec,
struct smbXcli_tcon *tcon,
struct smbXcli_session *session,
const uint8_t *fixed,
uint16_t fixed_len,
const uint8_t *dyn,
uint32_t dyn_len,
uint32_t max_dyn_len)
{
struct tevent_req *req;
NTSTATUS status;
req = smb2cli_req_create(mem_ctx, ev, conn, cmd,
additional_flags, clear_flags,
timeout_msec,
tcon, session,
fixed, fixed_len,
dyn, dyn_len,
max_dyn_len);
if (req == NULL) {
return NULL;
}
if (!tevent_req_is_in_progress(req)) {
return tevent_req_post(req, ev);
}
status = smb2cli_req_compound_submit(&req, 1);
if (tevent_req_nterror(req, status)) {
return tevent_req_post(req, ev);
}
return req;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,945
|
void smb2cli_req_set_credit_charge(struct tevent_req *req, uint16_t charge)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
state->smb2.credit_charge = charge;
}
| null | 0
|
void smb2cli_req_set_credit_charge(struct tevent_req *req, uint16_t charge)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
state->smb2.credit_charge = charge;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,946
|
void smb2cli_req_set_notify_async(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
state->smb2.notify_async = true;
}
| null | 0
|
void smb2cli_req_set_notify_async(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
state->smb2.notify_async = true;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,947
|
static void smb2cli_req_writev_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
ssize_t nwritten;
int err;
state->write_req = NULL;
nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
if (nwritten == -1) {
/* here, we need to notify all pending requests */
NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
}
| null | 0
|
static void smb2cli_req_writev_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
ssize_t nwritten;
int err;
state->write_req = NULL;
nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
if (nwritten == -1) {
/* here, we need to notify all pending requests */
NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,948
|
static void smb2cli_validate_negotiate_info_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smb2cli_validate_negotiate_info_state *state =
tevent_req_data(req,
struct smb2cli_validate_negotiate_info_state);
NTSTATUS status;
const uint8_t *buf;
uint32_t capabilities;
DATA_BLOB guid_blob;
struct GUID server_guid;
uint16_t security_mode;
uint16_t dialect;
status = smb2cli_ioctl_recv(subreq, state,
&state->out_input_buffer,
&state->out_output_buffer);
TALLOC_FREE(subreq);
if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
/*
* The response was signed, but not supported
*
* Older Windows and Samba releases return
* NT_STATUS_FILE_CLOSED.
*/
tevent_req_done(req);
return;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_DEVICE_REQUEST)) {
/*
* The response was signed, but not supported
*
* This is returned by the NTVFS based Samba 4.x file server
* for file shares.
*/
tevent_req_done(req);
return;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_FS_DRIVER_REQUIRED)) {
/*
* The response was signed, but not supported
*
* This is returned by the NTVFS based Samba 4.x file server
* for ipc shares.
*/
tevent_req_done(req);
return;
}
if (tevent_req_nterror(req, status)) {
return;
}
if (state->out_output_buffer.length != 24) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
buf = state->out_output_buffer.data;
capabilities = IVAL(buf, 0);
guid_blob = data_blob_const(buf + 4, 16);
status = GUID_from_data_blob(&guid_blob, &server_guid);
if (tevent_req_nterror(req, status)) {
return;
}
security_mode = CVAL(buf, 20);
dialect = SVAL(buf, 22);
if (capabilities != state->conn->smb2.server.capabilities) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (!GUID_equal(&server_guid, &state->conn->smb2.server.guid)) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (security_mode != state->conn->smb2.server.security_mode) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (dialect != state->dialect) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
tevent_req_done(req);
}
| null | 0
|
static void smb2cli_validate_negotiate_info_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smb2cli_validate_negotiate_info_state *state =
tevent_req_data(req,
struct smb2cli_validate_negotiate_info_state);
NTSTATUS status;
const uint8_t *buf;
uint32_t capabilities;
DATA_BLOB guid_blob;
struct GUID server_guid;
uint16_t security_mode;
uint16_t dialect;
status = smb2cli_ioctl_recv(subreq, state,
&state->out_input_buffer,
&state->out_output_buffer);
TALLOC_FREE(subreq);
if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_CLOSED)) {
/*
* The response was signed, but not supported
*
* Older Windows and Samba releases return
* NT_STATUS_FILE_CLOSED.
*/
tevent_req_done(req);
return;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_DEVICE_REQUEST)) {
/*
* The response was signed, but not supported
*
* This is returned by the NTVFS based Samba 4.x file server
* for file shares.
*/
tevent_req_done(req);
return;
}
if (NT_STATUS_EQUAL(status, NT_STATUS_FS_DRIVER_REQUIRED)) {
/*
* The response was signed, but not supported
*
* This is returned by the NTVFS based Samba 4.x file server
* for ipc shares.
*/
tevent_req_done(req);
return;
}
if (tevent_req_nterror(req, status)) {
return;
}
if (state->out_output_buffer.length != 24) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
buf = state->out_output_buffer.data;
capabilities = IVAL(buf, 0);
guid_blob = data_blob_const(buf + 4, 16);
status = GUID_from_data_blob(&guid_blob, &server_guid);
if (tevent_req_nterror(req, status)) {
return;
}
security_mode = CVAL(buf, 20);
dialect = SVAL(buf, 22);
if (capabilities != state->conn->smb2.server.capabilities) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (!GUID_equal(&server_guid, &state->conn->smb2.server.guid)) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (security_mode != state->conn->smb2.server.security_mode) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (dialect != state->dialect) {
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
tevent_req_done(req);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,949
|
struct smbXcli_conn *smbXcli_conn_create(TALLOC_CTX *mem_ctx,
int fd,
const char *remote_name,
enum smb_signing_setting signing_state,
uint32_t smb1_capabilities,
struct GUID *client_guid,
uint32_t smb2_capabilities)
{
struct smbXcli_conn *conn = NULL;
void *ss = NULL;
struct sockaddr *sa = NULL;
socklen_t sa_length;
int ret;
conn = talloc_zero(mem_ctx, struct smbXcli_conn);
if (!conn) {
return NULL;
}
conn->sock_fd = fd;
conn->remote_name = talloc_strdup(conn, remote_name);
if (conn->remote_name == NULL) {
goto error;
}
ss = (void *)&conn->local_ss;
sa = (struct sockaddr *)ss;
sa_length = sizeof(conn->local_ss);
ret = getsockname(fd, sa, &sa_length);
if (ret == -1) {
goto error;
}
ss = (void *)&conn->remote_ss;
sa = (struct sockaddr *)ss;
sa_length = sizeof(conn->remote_ss);
ret = getpeername(fd, sa, &sa_length);
if (ret == -1) {
goto error;
}
conn->outgoing = tevent_queue_create(conn, "smbXcli_outgoing");
if (conn->outgoing == NULL) {
goto error;
}
conn->pending = NULL;
conn->min_protocol = PROTOCOL_NONE;
conn->max_protocol = PROTOCOL_NONE;
conn->protocol = PROTOCOL_NONE;
switch (signing_state) {
case SMB_SIGNING_OFF:
/* never */
conn->allow_signing = false;
conn->desire_signing = false;
conn->mandatory_signing = false;
break;
case SMB_SIGNING_DEFAULT:
case SMB_SIGNING_IF_REQUIRED:
/* if the server requires it */
conn->allow_signing = true;
conn->desire_signing = false;
conn->mandatory_signing = false;
break;
case SMB_SIGNING_DESIRED:
/* if the server desires it */
conn->allow_signing = true;
conn->desire_signing = true;
conn->mandatory_signing = false;
break;
case SMB_SIGNING_REQUIRED:
/* always */
conn->allow_signing = true;
conn->desire_signing = true;
conn->mandatory_signing = true;
break;
}
conn->smb1.client.capabilities = smb1_capabilities;
conn->smb1.client.max_xmit = UINT16_MAX;
conn->smb1.capabilities = conn->smb1.client.capabilities;
conn->smb1.max_xmit = 1024;
conn->smb1.mid = 1;
/* initialise signing */
conn->smb1.signing = smb_signing_init(conn,
conn->allow_signing,
conn->desire_signing,
conn->mandatory_signing);
if (!conn->smb1.signing) {
goto error;
}
conn->smb2.client.security_mode = SMB2_NEGOTIATE_SIGNING_ENABLED;
if (conn->mandatory_signing) {
conn->smb2.client.security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
if (client_guid) {
conn->smb2.client.guid = *client_guid;
}
conn->smb2.client.capabilities = smb2_capabilities;
conn->smb2.cur_credits = 1;
conn->smb2.max_credits = 0;
conn->smb2.io_priority = 1;
/*
* Samba and Windows servers accept a maximum of 16 MiB with a maximum
* chunk length of 1 MiB.
*/
conn->smb2.cc_chunk_len = 1024 * 1024;
conn->smb2.cc_max_chunks = 16;
talloc_set_destructor(conn, smbXcli_conn_destructor);
return conn;
error:
TALLOC_FREE(conn);
return NULL;
}
| null | 0
|
struct smbXcli_conn *smbXcli_conn_create(TALLOC_CTX *mem_ctx,
int fd,
const char *remote_name,
enum smb_signing_setting signing_state,
uint32_t smb1_capabilities,
struct GUID *client_guid,
uint32_t smb2_capabilities)
{
struct smbXcli_conn *conn = NULL;
void *ss = NULL;
struct sockaddr *sa = NULL;
socklen_t sa_length;
int ret;
conn = talloc_zero(mem_ctx, struct smbXcli_conn);
if (!conn) {
return NULL;
}
conn->sock_fd = fd;
conn->remote_name = talloc_strdup(conn, remote_name);
if (conn->remote_name == NULL) {
goto error;
}
ss = (void *)&conn->local_ss;
sa = (struct sockaddr *)ss;
sa_length = sizeof(conn->local_ss);
ret = getsockname(fd, sa, &sa_length);
if (ret == -1) {
goto error;
}
ss = (void *)&conn->remote_ss;
sa = (struct sockaddr *)ss;
sa_length = sizeof(conn->remote_ss);
ret = getpeername(fd, sa, &sa_length);
if (ret == -1) {
goto error;
}
conn->outgoing = tevent_queue_create(conn, "smbXcli_outgoing");
if (conn->outgoing == NULL) {
goto error;
}
conn->pending = NULL;
conn->min_protocol = PROTOCOL_NONE;
conn->max_protocol = PROTOCOL_NONE;
conn->protocol = PROTOCOL_NONE;
switch (signing_state) {
case SMB_SIGNING_OFF:
/* never */
conn->allow_signing = false;
conn->desire_signing = false;
conn->mandatory_signing = false;
break;
case SMB_SIGNING_DEFAULT:
case SMB_SIGNING_IF_REQUIRED:
/* if the server requires it */
conn->allow_signing = true;
conn->desire_signing = false;
conn->mandatory_signing = false;
break;
case SMB_SIGNING_DESIRED:
/* if the server desires it */
conn->allow_signing = true;
conn->desire_signing = true;
conn->mandatory_signing = false;
break;
case SMB_SIGNING_REQUIRED:
/* always */
conn->allow_signing = true;
conn->desire_signing = true;
conn->mandatory_signing = true;
break;
}
conn->smb1.client.capabilities = smb1_capabilities;
conn->smb1.client.max_xmit = UINT16_MAX;
conn->smb1.capabilities = conn->smb1.client.capabilities;
conn->smb1.max_xmit = 1024;
conn->smb1.mid = 1;
/* initialise signing */
conn->smb1.signing = smb_signing_init(conn,
conn->allow_signing,
conn->desire_signing,
conn->mandatory_signing);
if (!conn->smb1.signing) {
goto error;
}
conn->smb2.client.security_mode = SMB2_NEGOTIATE_SIGNING_ENABLED;
if (conn->mandatory_signing) {
conn->smb2.client.security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
if (client_guid) {
conn->smb2.client.guid = *client_guid;
}
conn->smb2.client.capabilities = smb2_capabilities;
conn->smb2.cur_credits = 1;
conn->smb2.max_credits = 0;
conn->smb2.io_priority = 1;
/*
* Samba and Windows servers accept a maximum of 16 MiB with a maximum
* chunk length of 1 MiB.
*/
conn->smb2.cc_chunk_len = 1024 * 1024;
conn->smb2.cc_max_chunks = 16;
talloc_set_destructor(conn, smbXcli_conn_destructor);
return conn;
error:
TALLOC_FREE(conn);
return NULL;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,950
|
static int smbXcli_conn_destructor(struct smbXcli_conn *conn)
{
/*
* NT_STATUS_OK, means we do not notify the callers
*/
smbXcli_conn_disconnect(conn, NT_STATUS_OK);
while (conn->sessions) {
conn->sessions->conn = NULL;
DLIST_REMOVE(conn->sessions, conn->sessions);
}
if (conn->smb1.trans_enc) {
TALLOC_FREE(conn->smb1.trans_enc);
}
return 0;
}
| null | 0
|
static int smbXcli_conn_destructor(struct smbXcli_conn *conn)
{
/*
* NT_STATUS_OK, means we do not notify the callers
*/
smbXcli_conn_disconnect(conn, NT_STATUS_OK);
while (conn->sessions) {
conn->sessions->conn = NULL;
DLIST_REMOVE(conn->sessions, conn->sessions);
}
if (conn->smb1.trans_enc) {
TALLOC_FREE(conn->smb1.trans_enc);
}
return 0;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,951
|
bool smbXcli_conn_dfs_supported(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return (smb2cli_conn_server_capabilities(conn) & SMB2_CAP_DFS);
}
return (smb1cli_conn_capabilities(conn) & CAP_DFS);
}
| null | 0
|
bool smbXcli_conn_dfs_supported(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return (smb2cli_conn_server_capabilities(conn) & SMB2_CAP_DFS);
}
return (smb1cli_conn_capabilities(conn) & CAP_DFS);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,952
|
bool smbXcli_conn_has_async_calls(struct smbXcli_conn *conn)
{
return ((tevent_queue_length(conn->outgoing) != 0)
|| (talloc_array_length(conn->pending) != 0));
}
| null | 0
|
bool smbXcli_conn_has_async_calls(struct smbXcli_conn *conn)
{
return ((tevent_queue_length(conn->outgoing) != 0)
|| (talloc_array_length(conn->pending) != 0));
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,953
|
uint16_t smbXcli_conn_max_requests(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
/*
* TODO...
*/
return 1;
}
return conn->smb1.server.max_mux;
}
| null | 0
|
uint16_t smbXcli_conn_max_requests(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
/*
* TODO...
*/
return 1;
}
return conn->smb1.server.max_mux;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,954
|
static bool smbXcli_conn_receive_next(struct smbXcli_conn *conn)
{
size_t num_pending = talloc_array_length(conn->pending);
struct tevent_req *req;
struct smbXcli_req_state *state;
if (conn->read_smb_req != NULL) {
return true;
}
if (num_pending == 0) {
if (conn->smb2.mid < UINT64_MAX) {
/* no more pending requests, so we are done for now */
return true;
}
/*
* If there are no more SMB2 requests possible,
* because we are out of message ids,
* we need to disconnect.
*/
smbXcli_conn_disconnect(conn, NT_STATUS_CONNECTION_ABORTED);
return true;
}
req = conn->pending[0];
state = tevent_req_data(req, struct smbXcli_req_state);
/*
* We're the first ones, add the read_smb request that waits for the
* answer from the server
*/
conn->read_smb_req = read_smb_send(conn->pending,
state->ev,
conn->sock_fd);
if (conn->read_smb_req == NULL) {
return false;
}
tevent_req_set_callback(conn->read_smb_req, smbXcli_conn_received, conn);
return true;
}
| null | 0
|
static bool smbXcli_conn_receive_next(struct smbXcli_conn *conn)
{
size_t num_pending = talloc_array_length(conn->pending);
struct tevent_req *req;
struct smbXcli_req_state *state;
if (conn->read_smb_req != NULL) {
return true;
}
if (num_pending == 0) {
if (conn->smb2.mid < UINT64_MAX) {
/* no more pending requests, so we are done for now */
return true;
}
/*
* If there are no more SMB2 requests possible,
* because we are out of message ids,
* we need to disconnect.
*/
smbXcli_conn_disconnect(conn, NT_STATUS_CONNECTION_ABORTED);
return true;
}
req = conn->pending[0];
state = tevent_req_data(req, struct smbXcli_req_state);
/*
* We're the first ones, add the read_smb request that waits for the
* answer from the server
*/
conn->read_smb_req = read_smb_send(conn->pending,
state->ev,
conn->sock_fd);
if (conn->read_smb_req == NULL) {
return false;
}
tevent_req_set_callback(conn->read_smb_req, smbXcli_conn_received, conn);
return true;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,955
|
static void smbXcli_conn_received(struct tevent_req *subreq)
{
struct smbXcli_conn *conn =
tevent_req_callback_data(subreq,
struct smbXcli_conn);
TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
uint8_t *inbuf;
ssize_t received;
int err;
if (subreq != conn->read_smb_req) {
DEBUG(1, ("Internal error: cli_smb_received called with "
"unexpected subreq\n"));
smbXcli_conn_disconnect(conn, NT_STATUS_INTERNAL_ERROR);
TALLOC_FREE(frame);
return;
}
conn->read_smb_req = NULL;
received = read_smb_recv(subreq, frame, &inbuf, &err);
TALLOC_FREE(subreq);
if (received == -1) {
status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(conn, status);
TALLOC_FREE(frame);
return;
}
status = conn->dispatch_incoming(conn, frame, inbuf);
TALLOC_FREE(frame);
if (NT_STATUS_IS_OK(status)) {
/*
* We should not do any more processing
* as the dispatch function called
* tevent_req_done().
*/
return;
}
if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
/*
* We got an error, so notify all pending requests
*/
smbXcli_conn_disconnect(conn, status);
return;
}
/*
* We got NT_STATUS_RETRY, so we may ask for a
* next incoming pdu.
*/
if (!smbXcli_conn_receive_next(conn)) {
smbXcli_conn_disconnect(conn, NT_STATUS_NO_MEMORY);
}
}
| null | 0
|
static void smbXcli_conn_received(struct tevent_req *subreq)
{
struct smbXcli_conn *conn =
tevent_req_callback_data(subreq,
struct smbXcli_conn);
TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
uint8_t *inbuf;
ssize_t received;
int err;
if (subreq != conn->read_smb_req) {
DEBUG(1, ("Internal error: cli_smb_received called with "
"unexpected subreq\n"));
smbXcli_conn_disconnect(conn, NT_STATUS_INTERNAL_ERROR);
TALLOC_FREE(frame);
return;
}
conn->read_smb_req = NULL;
received = read_smb_recv(subreq, frame, &inbuf, &err);
TALLOC_FREE(subreq);
if (received == -1) {
status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(conn, status);
TALLOC_FREE(frame);
return;
}
status = conn->dispatch_incoming(conn, frame, inbuf);
TALLOC_FREE(frame);
if (NT_STATUS_IS_OK(status)) {
/*
* We should not do any more processing
* as the dispatch function called
* tevent_req_done().
*/
return;
}
if (!NT_STATUS_EQUAL(status, NT_STATUS_RETRY)) {
/*
* We got an error, so notify all pending requests
*/
smbXcli_conn_disconnect(conn, status);
return;
}
/*
* We got NT_STATUS_RETRY, so we may ask for a
* next incoming pdu.
*/
if (!smbXcli_conn_receive_next(conn)) {
smbXcli_conn_disconnect(conn, NT_STATUS_NO_MEMORY);
}
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,956
|
const char *smbXcli_conn_remote_name(struct smbXcli_conn *conn)
{
return conn->remote_name;
}
| null | 0
|
const char *smbXcli_conn_remote_name(struct smbXcli_conn *conn)
{
return conn->remote_name;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,957
|
NTSTATUS smbXcli_conn_samba_suicide(struct smbXcli_conn *conn,
uint8_t exitcode)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
bool ok;
if (smbXcli_conn_has_async_calls(conn)) {
/*
* Can't use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER_MIX;
goto fail;
}
ev = samba_tevent_context_init(frame);
if (ev == NULL) {
goto fail;
}
req = smbXcli_conn_samba_suicide_send(frame, ev, conn, exitcode);
if (req == NULL) {
goto fail;
}
ok = tevent_req_poll_ntstatus(req, ev, &status);
if (!ok) {
goto fail;
}
status = smbXcli_conn_samba_suicide_recv(req);
fail:
TALLOC_FREE(frame);
return status;
}
| null | 0
|
NTSTATUS smbXcli_conn_samba_suicide(struct smbXcli_conn *conn,
uint8_t exitcode)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
bool ok;
if (smbXcli_conn_has_async_calls(conn)) {
/*
* Can't use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER_MIX;
goto fail;
}
ev = samba_tevent_context_init(frame);
if (ev == NULL) {
goto fail;
}
req = smbXcli_conn_samba_suicide_send(frame, ev, conn, exitcode);
if (req == NULL) {
goto fail;
}
ok = tevent_req_poll_ntstatus(req, ev, &status);
if (!ok) {
goto fail;
}
status = smbXcli_conn_samba_suicide_recv(req);
fail:
TALLOC_FREE(frame);
return status;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,958
|
static void smbXcli_conn_samba_suicide_cleanup(struct tevent_req *req,
enum tevent_req_state req_state)
{
struct smbXcli_conn_samba_suicide_state *state = tevent_req_data(
req, struct smbXcli_conn_samba_suicide_state);
TALLOC_FREE(state->write_req);
if (state->conn == NULL) {
return;
}
if (state->conn->suicide_req == req) {
state->conn->suicide_req = NULL;
}
state->conn = NULL;
}
| null | 0
|
static void smbXcli_conn_samba_suicide_cleanup(struct tevent_req *req,
enum tevent_req_state req_state)
{
struct smbXcli_conn_samba_suicide_state *state = tevent_req_data(
req, struct smbXcli_conn_samba_suicide_state);
TALLOC_FREE(state->write_req);
if (state->conn == NULL) {
return;
}
if (state->conn->suicide_req == req) {
state->conn->suicide_req = NULL;
}
state->conn = NULL;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,959
|
static void smbXcli_conn_samba_suicide_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct smbXcli_conn_samba_suicide_state *state = tevent_req_data(
req, struct smbXcli_conn_samba_suicide_state);
ssize_t nwritten;
int err;
state->write_req = NULL;
nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
if (nwritten == -1) {
/* here, we need to notify all pending requests */
NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
tevent_req_done(req);
}
| null | 0
|
static void smbXcli_conn_samba_suicide_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct smbXcli_conn_samba_suicide_state *state = tevent_req_data(
req, struct smbXcli_conn_samba_suicide_state);
ssize_t nwritten;
int err;
state->write_req = NULL;
nwritten = writev_recv(subreq, &err);
TALLOC_FREE(subreq);
if (nwritten == -1) {
/* here, we need to notify all pending requests */
NTSTATUS status = map_nt_error_from_unix_common(err);
smbXcli_conn_disconnect(state->conn, status);
return;
}
tevent_req_done(req);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,960
|
NTSTATUS smbXcli_conn_samba_suicide_recv(struct tevent_req *req)
{
return tevent_req_simple_recv_ntstatus(req);
}
| null | 0
|
NTSTATUS smbXcli_conn_samba_suicide_recv(struct tevent_req *req)
{
return tevent_req_simple_recv_ntstatus(req);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,961
|
const DATA_BLOB *smbXcli_conn_server_gss_blob(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return &conn->smb2.server.gss_blob;
}
return &conn->smb1.server.gss_blob;
}
| null | 0
|
const DATA_BLOB *smbXcli_conn_server_gss_blob(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return &conn->smb2.server.gss_blob;
}
return &conn->smb1.server.gss_blob;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,962
|
const struct GUID *smbXcli_conn_server_guid(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return &conn->smb2.server.guid;
}
return &conn->smb1.server.guid;
}
| null | 0
|
const struct GUID *smbXcli_conn_server_guid(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return &conn->smb2.server.guid;
}
return &conn->smb1.server.guid;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,963
|
void smbXcli_conn_set_sockopt(struct smbXcli_conn *conn, const char *options)
{
set_socket_options(conn->sock_fd, options);
}
| null | 0
|
void smbXcli_conn_set_sockopt(struct smbXcli_conn *conn, const char *options)
{
set_socket_options(conn->sock_fd, options);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,964
|
bool smbXcli_conn_use_unicode(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return true;
}
if (conn->smb1.capabilities & CAP_UNICODE) {
return true;
}
return false;
}
| null | 0
|
bool smbXcli_conn_use_unicode(struct smbXcli_conn *conn)
{
if (conn->protocol >= PROTOCOL_SMB2_02) {
return true;
}
if (conn->smb1.capabilities & CAP_UNICODE) {
return true;
}
return false;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,965
|
static uint8_t *smbXcli_iov_concat(TALLOC_CTX *mem_ctx,
const struct iovec *iov,
int count)
{
ssize_t buflen;
uint8_t *buf;
buflen = iov_buflen(iov, count);
if (buflen == -1) {
return NULL;
}
buf = talloc_array(mem_ctx, uint8_t, buflen);
if (buf == NULL) {
return NULL;
}
iov_buf(iov, count, buf, buflen);
return buf;
}
| null | 0
|
static uint8_t *smbXcli_iov_concat(TALLOC_CTX *mem_ctx,
const struct iovec *iov,
int count)
{
ssize_t buflen;
uint8_t *buf;
buflen = iov_buflen(iov, count);
if (buflen == -1) {
return NULL;
}
buf = talloc_array(mem_ctx, uint8_t, buflen);
if (buf == NULL) {
return NULL;
}
iov_buf(iov, count, buf, buflen);
return buf;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,966
|
static size_t smbXcli_iov_len(const struct iovec *iov, int count)
{
ssize_t ret = iov_buflen(iov, count);
/* Ignore the overflow case for now ... */
return ret;
}
| null | 0
|
static size_t smbXcli_iov_len(const struct iovec *iov, int count)
{
ssize_t ret = iov_buflen(iov, count);
/* Ignore the overflow case for now ... */
return ret;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,967
|
NTSTATUS smbXcli_negprot(struct smbXcli_conn *conn,
uint32_t timeout_msec,
enum protocol_types min_protocol,
enum protocol_types max_protocol)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
bool ok;
if (smbXcli_conn_has_async_calls(conn)) {
/*
* Can't use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER_MIX;
goto fail;
}
ev = samba_tevent_context_init(frame);
if (ev == NULL) {
goto fail;
}
req = smbXcli_negprot_send(frame, ev, conn, timeout_msec,
min_protocol, max_protocol);
if (req == NULL) {
goto fail;
}
ok = tevent_req_poll_ntstatus(req, ev, &status);
if (!ok) {
goto fail;
}
status = smbXcli_negprot_recv(req);
fail:
TALLOC_FREE(frame);
return status;
}
| null | 0
|
NTSTATUS smbXcli_negprot(struct smbXcli_conn *conn,
uint32_t timeout_msec,
enum protocol_types min_protocol,
enum protocol_types max_protocol)
{
TALLOC_CTX *frame = talloc_stackframe();
struct tevent_context *ev;
struct tevent_req *req;
NTSTATUS status = NT_STATUS_NO_MEMORY;
bool ok;
if (smbXcli_conn_has_async_calls(conn)) {
/*
* Can't use sync call while an async call is in flight
*/
status = NT_STATUS_INVALID_PARAMETER_MIX;
goto fail;
}
ev = samba_tevent_context_init(frame);
if (ev == NULL) {
goto fail;
}
req = smbXcli_negprot_send(frame, ev, conn, timeout_msec,
min_protocol, max_protocol);
if (req == NULL) {
goto fail;
}
ok = tevent_req_poll_ntstatus(req, ev, &status);
if (!ok) {
goto fail;
}
status = smbXcli_negprot_recv(req);
fail:
TALLOC_FREE(frame);
return status;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,968
|
static NTSTATUS smbXcli_negprot_dispatch_incoming(struct smbXcli_conn *conn,
TALLOC_CTX *tmp_mem,
uint8_t *inbuf)
{
size_t num_pending = talloc_array_length(conn->pending);
struct tevent_req *subreq;
struct smbXcli_req_state *substate;
struct tevent_req *req;
uint32_t protocol_magic;
size_t inbuf_len = smb_len_nbt(inbuf);
if (num_pending != 1) {
return NT_STATUS_INTERNAL_ERROR;
}
if (inbuf_len < 4) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
subreq = conn->pending[0];
substate = tevent_req_data(subreq, struct smbXcli_req_state);
req = tevent_req_callback_data(subreq, struct tevent_req);
protocol_magic = IVAL(inbuf, 4);
switch (protocol_magic) {
case SMB_MAGIC:
tevent_req_set_callback(subreq, smbXcli_negprot_smb1_done, req);
conn->dispatch_incoming = smb1cli_conn_dispatch_incoming;
return smb1cli_conn_dispatch_incoming(conn, tmp_mem, inbuf);
case SMB2_MAGIC:
if (substate->smb2.recv_iov == NULL) {
/*
* For the SMB1 negprot we have move it.
*/
substate->smb2.recv_iov = substate->smb1.recv_iov;
substate->smb1.recv_iov = NULL;
}
/*
* we got an SMB2 answer, which consumed sequence number 0
* so we need to use 1 as the next one.
*
* we also need to set the current credits to 0
* as we consumed the initial one. The SMB2 answer
* hopefully grant us a new credit.
*/
conn->smb2.mid = 1;
conn->smb2.cur_credits = 0;
tevent_req_set_callback(subreq, smbXcli_negprot_smb2_done, req);
conn->dispatch_incoming = smb2cli_conn_dispatch_incoming;
return smb2cli_conn_dispatch_incoming(conn, tmp_mem, inbuf);
}
DEBUG(10, ("Got non-SMB PDU\n"));
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
| null | 0
|
static NTSTATUS smbXcli_negprot_dispatch_incoming(struct smbXcli_conn *conn,
TALLOC_CTX *tmp_mem,
uint8_t *inbuf)
{
size_t num_pending = talloc_array_length(conn->pending);
struct tevent_req *subreq;
struct smbXcli_req_state *substate;
struct tevent_req *req;
uint32_t protocol_magic;
size_t inbuf_len = smb_len_nbt(inbuf);
if (num_pending != 1) {
return NT_STATUS_INTERNAL_ERROR;
}
if (inbuf_len < 4) {
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
subreq = conn->pending[0];
substate = tevent_req_data(subreq, struct smbXcli_req_state);
req = tevent_req_callback_data(subreq, struct tevent_req);
protocol_magic = IVAL(inbuf, 4);
switch (protocol_magic) {
case SMB_MAGIC:
tevent_req_set_callback(subreq, smbXcli_negprot_smb1_done, req);
conn->dispatch_incoming = smb1cli_conn_dispatch_incoming;
return smb1cli_conn_dispatch_incoming(conn, tmp_mem, inbuf);
case SMB2_MAGIC:
if (substate->smb2.recv_iov == NULL) {
/*
* For the SMB1 negprot we have move it.
*/
substate->smb2.recv_iov = substate->smb1.recv_iov;
substate->smb1.recv_iov = NULL;
}
/*
* we got an SMB2 answer, which consumed sequence number 0
* so we need to use 1 as the next one.
*
* we also need to set the current credits to 0
* as we consumed the initial one. The SMB2 answer
* hopefully grant us a new credit.
*/
conn->smb2.mid = 1;
conn->smb2.cur_credits = 0;
tevent_req_set_callback(subreq, smbXcli_negprot_smb2_done, req);
conn->dispatch_incoming = smb2cli_conn_dispatch_incoming;
return smb2cli_conn_dispatch_incoming(conn, tmp_mem, inbuf);
}
DEBUG(10, ("Got non-SMB PDU\n"));
return NT_STATUS_INVALID_NETWORK_RESPONSE;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,969
|
static void smbXcli_negprot_invalid_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
NTSTATUS status;
/*
* we just want the low level error
*/
status = tevent_req_simple_recv_ntstatus(subreq);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
/* this should never happen */
tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
}
| null | 0
|
static void smbXcli_negprot_invalid_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
NTSTATUS status;
/*
* we just want the low level error
*/
status = tevent_req_simple_recv_ntstatus(subreq);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
/* this should never happen */
tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,970
|
NTSTATUS smbXcli_negprot_recv(struct tevent_req *req)
{
return tevent_req_simple_recv_ntstatus(req);
}
| null | 0
|
NTSTATUS smbXcli_negprot_recv(struct tevent_req *req)
{
return tevent_req_simple_recv_ntstatus(req);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,971
|
static void smbXcli_negprot_smb1_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_negprot_state *state =
tevent_req_data(req,
struct smbXcli_negprot_state);
struct smbXcli_conn *conn = state->conn;
struct iovec *recv_iov = NULL;
uint8_t *inhdr;
uint8_t wct;
uint16_t *vwv;
uint32_t num_bytes;
uint8_t *bytes;
NTSTATUS status;
uint16_t protnum;
size_t i;
size_t num_prots = 0;
uint8_t flags;
uint32_t client_capabilities = conn->smb1.client.capabilities;
uint32_t both_capabilities;
uint32_t server_capabilities = 0;
uint32_t capabilities;
uint32_t client_max_xmit = conn->smb1.client.max_xmit;
uint32_t server_max_xmit = 0;
uint32_t max_xmit;
uint32_t server_max_mux = 0;
uint16_t server_security_mode = 0;
uint32_t server_session_key = 0;
bool server_readbraw = false;
bool server_writebraw = false;
bool server_lockread = false;
bool server_writeunlock = false;
struct GUID server_guid = GUID_zero();
DATA_BLOB server_gss_blob = data_blob_null;
uint8_t server_challenge[8];
char *server_workgroup = NULL;
char *server_name = NULL;
int server_time_zone = 0;
NTTIME server_system_time = 0;
static const struct smb1cli_req_expected_response expected[] = {
{
.status = NT_STATUS_OK,
.wct = 0x11, /* NT1 */
},
{
.status = NT_STATUS_OK,
.wct = 0x0D, /* LM */
},
{
.status = NT_STATUS_OK,
.wct = 0x01, /* CORE */
}
};
ZERO_STRUCT(server_challenge);
status = smb1cli_req_recv(subreq, state,
&recv_iov,
&inhdr,
&wct,
&vwv,
NULL, /* pvwv_offset */
&num_bytes,
&bytes,
NULL, /* pbytes_offset */
NULL, /* pinbuf */
expected, ARRAY_SIZE(expected));
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
flags = CVAL(inhdr, HDR_FLG);
protnum = SVAL(vwv, 0);
for (i=0; i < ARRAY_SIZE(smb1cli_prots); i++) {
if (smb1cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb1cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
if (protnum != num_prots) {
num_prots++;
continue;
}
conn->protocol = smb1cli_prots[i].proto;
break;
}
if (conn->protocol == PROTOCOL_NONE) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if ((conn->protocol < PROTOCOL_NT1) && conn->mandatory_signing) {
DEBUG(0,("smbXcli_negprot: SMB signing is mandatory "
"and the selected protocol level doesn't support it.\n"));
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (flags & FLAG_SUPPORT_LOCKREAD) {
server_lockread = true;
server_writeunlock = true;
}
if (conn->protocol >= PROTOCOL_NT1) {
const char *client_signing = NULL;
bool server_mandatory = false;
bool server_allowed = false;
const char *server_signing = NULL;
bool ok;
uint8_t key_len;
if (wct != 0x11) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
/* NT protocol */
server_security_mode = CVAL(vwv + 1, 0);
server_max_mux = SVAL(vwv + 1, 1);
server_max_xmit = IVAL(vwv + 3, 1);
server_session_key = IVAL(vwv + 7, 1);
server_time_zone = SVALS(vwv + 15, 1);
server_time_zone *= 60;
/* this time arrives in real GMT */
server_system_time = BVAL(vwv + 11, 1);
server_capabilities = IVAL(vwv + 9, 1);
key_len = CVAL(vwv + 16, 1);
if (server_capabilities & CAP_RAW_MODE) {
server_readbraw = true;
server_writebraw = true;
}
if (server_capabilities & CAP_LOCK_AND_READ) {
server_lockread = true;
}
if (server_capabilities & CAP_EXTENDED_SECURITY) {
DATA_BLOB blob1, blob2;
if (num_bytes < 16) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
blob1 = data_blob_const(bytes, 16);
status = GUID_from_data_blob(&blob1, &server_guid);
if (tevent_req_nterror(req, status)) {
return;
}
blob1 = data_blob_const(bytes+16, num_bytes-16);
blob2 = data_blob_dup_talloc(state, blob1);
if (blob1.length > 0 &&
tevent_req_nomem(blob2.data, req)) {
return;
}
server_gss_blob = blob2;
} else {
DATA_BLOB blob1, blob2;
if (num_bytes < key_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len != 0 && key_len != 8) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len == 8) {
memcpy(server_challenge, bytes, 8);
}
blob1 = data_blob_const(bytes+key_len, num_bytes-key_len);
blob2 = data_blob_const(bytes+key_len, num_bytes-key_len);
if (blob1.length > 0) {
size_t len;
len = utf16_len_n(blob1.data,
blob1.length);
blob1.length = len;
ok = convert_string_talloc(state,
CH_UTF16LE,
CH_UNIX,
blob1.data,
blob1.length,
&server_workgroup,
&len);
if (!ok) {
status = map_nt_error_from_unix_common(errno);
tevent_req_nterror(req, status);
return;
}
}
blob2.data += blob1.length;
blob2.length -= blob1.length;
if (blob2.length > 0) {
size_t len;
len = utf16_len_n(blob1.data,
blob1.length);
blob1.length = len;
ok = convert_string_talloc(state,
CH_UTF16LE,
CH_UNIX,
blob2.data,
blob2.length,
&server_name,
&len);
if (!ok) {
status = map_nt_error_from_unix_common(errno);
tevent_req_nterror(req, status);
return;
}
}
}
client_signing = "disabled";
if (conn->allow_signing) {
client_signing = "allowed";
}
if (conn->mandatory_signing) {
client_signing = "required";
}
server_signing = "not supported";
if (server_security_mode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED) {
server_signing = "supported";
server_allowed = true;
} else if (conn->mandatory_signing) {
/*
* We have mandatory signing as client
* lets assume the server will look at our
* FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED
* flag in the session setup
*/
server_signing = "not announced";
server_allowed = true;
}
if (server_security_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRED) {
server_signing = "required";
server_mandatory = true;
}
ok = smb_signing_set_negotiated(conn->smb1.signing,
server_allowed,
server_mandatory);
if (!ok) {
DEBUG(1,("cli_negprot: SMB signing is required, "
"but client[%s] and server[%s] mismatch\n",
client_signing, server_signing));
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
} else if (conn->protocol >= PROTOCOL_LANMAN1) {
DATA_BLOB blob1;
uint8_t key_len;
time_t t;
if (wct != 0x0D) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
server_security_mode = SVAL(vwv + 1, 0);
server_max_xmit = SVAL(vwv + 2, 0);
server_max_mux = SVAL(vwv + 3, 0);
server_readbraw = ((SVAL(vwv + 5, 0) & 0x1) != 0);
server_writebraw = ((SVAL(vwv + 5, 0) & 0x2) != 0);
server_session_key = IVAL(vwv + 6, 0);
server_time_zone = SVALS(vwv + 10, 0);
server_time_zone *= 60;
/* this time is converted to GMT by make_unix_date */
t = pull_dos_date((const uint8_t *)(vwv + 8), server_time_zone);
unix_to_nt_time(&server_system_time, t);
key_len = SVAL(vwv + 11, 0);
if (num_bytes < key_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len != 0 && key_len != 8) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len == 8) {
memcpy(server_challenge, bytes, 8);
}
blob1 = data_blob_const(bytes+key_len, num_bytes-key_len);
if (blob1.length > 0) {
size_t len;
bool ok;
len = utf16_len_n(blob1.data,
blob1.length);
blob1.length = len;
ok = convert_string_talloc(state,
CH_DOS,
CH_UNIX,
blob1.data,
blob1.length,
&server_workgroup,
&len);
if (!ok) {
status = map_nt_error_from_unix_common(errno);
tevent_req_nterror(req, status);
return;
}
}
} else {
/* the old core protocol */
server_time_zone = get_time_zone(time(NULL));
server_max_xmit = 1024;
server_max_mux = 1;
}
if (server_max_xmit < 1024) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (server_max_mux < 1) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
/*
* Now calculate the negotiated capabilities
* based on the mask for:
* - client only flags
* - flags used in both directions
* - server only flags
*/
both_capabilities = client_capabilities & server_capabilities;
capabilities = client_capabilities & SMB_CAP_CLIENT_MASK;
capabilities |= both_capabilities & SMB_CAP_BOTH_MASK;
capabilities |= server_capabilities & SMB_CAP_SERVER_MASK;
max_xmit = MIN(client_max_xmit, server_max_xmit);
conn->smb1.server.capabilities = server_capabilities;
conn->smb1.capabilities = capabilities;
conn->smb1.server.max_xmit = server_max_xmit;
conn->smb1.max_xmit = max_xmit;
conn->smb1.server.max_mux = server_max_mux;
conn->smb1.server.security_mode = server_security_mode;
conn->smb1.server.readbraw = server_readbraw;
conn->smb1.server.writebraw = server_writebraw;
conn->smb1.server.lockread = server_lockread;
conn->smb1.server.writeunlock = server_writeunlock;
conn->smb1.server.session_key = server_session_key;
talloc_steal(conn, server_gss_blob.data);
conn->smb1.server.gss_blob = server_gss_blob;
conn->smb1.server.guid = server_guid;
memcpy(conn->smb1.server.challenge, server_challenge, 8);
conn->smb1.server.workgroup = talloc_move(conn, &server_workgroup);
conn->smb1.server.name = talloc_move(conn, &server_name);
conn->smb1.server.time_zone = server_time_zone;
conn->smb1.server.system_time = server_system_time;
tevent_req_done(req);
}
| null | 0
|
static void smbXcli_negprot_smb1_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_negprot_state *state =
tevent_req_data(req,
struct smbXcli_negprot_state);
struct smbXcli_conn *conn = state->conn;
struct iovec *recv_iov = NULL;
uint8_t *inhdr;
uint8_t wct;
uint16_t *vwv;
uint32_t num_bytes;
uint8_t *bytes;
NTSTATUS status;
uint16_t protnum;
size_t i;
size_t num_prots = 0;
uint8_t flags;
uint32_t client_capabilities = conn->smb1.client.capabilities;
uint32_t both_capabilities;
uint32_t server_capabilities = 0;
uint32_t capabilities;
uint32_t client_max_xmit = conn->smb1.client.max_xmit;
uint32_t server_max_xmit = 0;
uint32_t max_xmit;
uint32_t server_max_mux = 0;
uint16_t server_security_mode = 0;
uint32_t server_session_key = 0;
bool server_readbraw = false;
bool server_writebraw = false;
bool server_lockread = false;
bool server_writeunlock = false;
struct GUID server_guid = GUID_zero();
DATA_BLOB server_gss_blob = data_blob_null;
uint8_t server_challenge[8];
char *server_workgroup = NULL;
char *server_name = NULL;
int server_time_zone = 0;
NTTIME server_system_time = 0;
static const struct smb1cli_req_expected_response expected[] = {
{
.status = NT_STATUS_OK,
.wct = 0x11, /* NT1 */
},
{
.status = NT_STATUS_OK,
.wct = 0x0D, /* LM */
},
{
.status = NT_STATUS_OK,
.wct = 0x01, /* CORE */
}
};
ZERO_STRUCT(server_challenge);
status = smb1cli_req_recv(subreq, state,
&recv_iov,
&inhdr,
&wct,
&vwv,
NULL, /* pvwv_offset */
&num_bytes,
&bytes,
NULL, /* pbytes_offset */
NULL, /* pinbuf */
expected, ARRAY_SIZE(expected));
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
flags = CVAL(inhdr, HDR_FLG);
protnum = SVAL(vwv, 0);
for (i=0; i < ARRAY_SIZE(smb1cli_prots); i++) {
if (smb1cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb1cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
if (protnum != num_prots) {
num_prots++;
continue;
}
conn->protocol = smb1cli_prots[i].proto;
break;
}
if (conn->protocol == PROTOCOL_NONE) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if ((conn->protocol < PROTOCOL_NT1) && conn->mandatory_signing) {
DEBUG(0,("smbXcli_negprot: SMB signing is mandatory "
"and the selected protocol level doesn't support it.\n"));
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
if (flags & FLAG_SUPPORT_LOCKREAD) {
server_lockread = true;
server_writeunlock = true;
}
if (conn->protocol >= PROTOCOL_NT1) {
const char *client_signing = NULL;
bool server_mandatory = false;
bool server_allowed = false;
const char *server_signing = NULL;
bool ok;
uint8_t key_len;
if (wct != 0x11) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
/* NT protocol */
server_security_mode = CVAL(vwv + 1, 0);
server_max_mux = SVAL(vwv + 1, 1);
server_max_xmit = IVAL(vwv + 3, 1);
server_session_key = IVAL(vwv + 7, 1);
server_time_zone = SVALS(vwv + 15, 1);
server_time_zone *= 60;
/* this time arrives in real GMT */
server_system_time = BVAL(vwv + 11, 1);
server_capabilities = IVAL(vwv + 9, 1);
key_len = CVAL(vwv + 16, 1);
if (server_capabilities & CAP_RAW_MODE) {
server_readbraw = true;
server_writebraw = true;
}
if (server_capabilities & CAP_LOCK_AND_READ) {
server_lockread = true;
}
if (server_capabilities & CAP_EXTENDED_SECURITY) {
DATA_BLOB blob1, blob2;
if (num_bytes < 16) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
blob1 = data_blob_const(bytes, 16);
status = GUID_from_data_blob(&blob1, &server_guid);
if (tevent_req_nterror(req, status)) {
return;
}
blob1 = data_blob_const(bytes+16, num_bytes-16);
blob2 = data_blob_dup_talloc(state, blob1);
if (blob1.length > 0 &&
tevent_req_nomem(blob2.data, req)) {
return;
}
server_gss_blob = blob2;
} else {
DATA_BLOB blob1, blob2;
if (num_bytes < key_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len != 0 && key_len != 8) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len == 8) {
memcpy(server_challenge, bytes, 8);
}
blob1 = data_blob_const(bytes+key_len, num_bytes-key_len);
blob2 = data_blob_const(bytes+key_len, num_bytes-key_len);
if (blob1.length > 0) {
size_t len;
len = utf16_len_n(blob1.data,
blob1.length);
blob1.length = len;
ok = convert_string_talloc(state,
CH_UTF16LE,
CH_UNIX,
blob1.data,
blob1.length,
&server_workgroup,
&len);
if (!ok) {
status = map_nt_error_from_unix_common(errno);
tevent_req_nterror(req, status);
return;
}
}
blob2.data += blob1.length;
blob2.length -= blob1.length;
if (blob2.length > 0) {
size_t len;
len = utf16_len_n(blob1.data,
blob1.length);
blob1.length = len;
ok = convert_string_talloc(state,
CH_UTF16LE,
CH_UNIX,
blob2.data,
blob2.length,
&server_name,
&len);
if (!ok) {
status = map_nt_error_from_unix_common(errno);
tevent_req_nterror(req, status);
return;
}
}
}
client_signing = "disabled";
if (conn->allow_signing) {
client_signing = "allowed";
}
if (conn->mandatory_signing) {
client_signing = "required";
}
server_signing = "not supported";
if (server_security_mode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED) {
server_signing = "supported";
server_allowed = true;
} else if (conn->mandatory_signing) {
/*
* We have mandatory signing as client
* lets assume the server will look at our
* FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED
* flag in the session setup
*/
server_signing = "not announced";
server_allowed = true;
}
if (server_security_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRED) {
server_signing = "required";
server_mandatory = true;
}
ok = smb_signing_set_negotiated(conn->smb1.signing,
server_allowed,
server_mandatory);
if (!ok) {
DEBUG(1,("cli_negprot: SMB signing is required, "
"but client[%s] and server[%s] mismatch\n",
client_signing, server_signing));
tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
return;
}
} else if (conn->protocol >= PROTOCOL_LANMAN1) {
DATA_BLOB blob1;
uint8_t key_len;
time_t t;
if (wct != 0x0D) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
server_security_mode = SVAL(vwv + 1, 0);
server_max_xmit = SVAL(vwv + 2, 0);
server_max_mux = SVAL(vwv + 3, 0);
server_readbraw = ((SVAL(vwv + 5, 0) & 0x1) != 0);
server_writebraw = ((SVAL(vwv + 5, 0) & 0x2) != 0);
server_session_key = IVAL(vwv + 6, 0);
server_time_zone = SVALS(vwv + 10, 0);
server_time_zone *= 60;
/* this time is converted to GMT by make_unix_date */
t = pull_dos_date((const uint8_t *)(vwv + 8), server_time_zone);
unix_to_nt_time(&server_system_time, t);
key_len = SVAL(vwv + 11, 0);
if (num_bytes < key_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len != 0 && key_len != 8) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (key_len == 8) {
memcpy(server_challenge, bytes, 8);
}
blob1 = data_blob_const(bytes+key_len, num_bytes-key_len);
if (blob1.length > 0) {
size_t len;
bool ok;
len = utf16_len_n(blob1.data,
blob1.length);
blob1.length = len;
ok = convert_string_talloc(state,
CH_DOS,
CH_UNIX,
blob1.data,
blob1.length,
&server_workgroup,
&len);
if (!ok) {
status = map_nt_error_from_unix_common(errno);
tevent_req_nterror(req, status);
return;
}
}
} else {
/* the old core protocol */
server_time_zone = get_time_zone(time(NULL));
server_max_xmit = 1024;
server_max_mux = 1;
}
if (server_max_xmit < 1024) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (server_max_mux < 1) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
/*
* Now calculate the negotiated capabilities
* based on the mask for:
* - client only flags
* - flags used in both directions
* - server only flags
*/
both_capabilities = client_capabilities & server_capabilities;
capabilities = client_capabilities & SMB_CAP_CLIENT_MASK;
capabilities |= both_capabilities & SMB_CAP_BOTH_MASK;
capabilities |= server_capabilities & SMB_CAP_SERVER_MASK;
max_xmit = MIN(client_max_xmit, server_max_xmit);
conn->smb1.server.capabilities = server_capabilities;
conn->smb1.capabilities = capabilities;
conn->smb1.server.max_xmit = server_max_xmit;
conn->smb1.max_xmit = max_xmit;
conn->smb1.server.max_mux = server_max_mux;
conn->smb1.server.security_mode = server_security_mode;
conn->smb1.server.readbraw = server_readbraw;
conn->smb1.server.writebraw = server_writebraw;
conn->smb1.server.lockread = server_lockread;
conn->smb1.server.writeunlock = server_writeunlock;
conn->smb1.server.session_key = server_session_key;
talloc_steal(conn, server_gss_blob.data);
conn->smb1.server.gss_blob = server_gss_blob;
conn->smb1.server.guid = server_guid;
memcpy(conn->smb1.server.challenge, server_challenge, 8);
conn->smb1.server.workgroup = talloc_move(conn, &server_workgroup);
conn->smb1.server.name = talloc_move(conn, &server_name);
conn->smb1.server.time_zone = server_time_zone;
conn->smb1.server.system_time = server_system_time;
tevent_req_done(req);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,972
|
static struct tevent_req *smbXcli_negprot_smb1_subreq(struct smbXcli_negprot_state *state)
{
size_t i;
DATA_BLOB bytes = data_blob_null;
uint8_t flags;
uint16_t flags2;
/* setup the protocol strings */
for (i=0; i < ARRAY_SIZE(smb1cli_prots); i++) {
uint8_t c = 2;
bool ok;
if (smb1cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb1cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
ok = data_blob_append(state, &bytes, &c, sizeof(c));
if (!ok) {
return NULL;
}
/*
* We now it is already ascii and
* we want NULL termination.
*/
ok = data_blob_append(state, &bytes,
smb1cli_prots[i].smb1_name,
strlen(smb1cli_prots[i].smb1_name)+1);
if (!ok) {
return NULL;
}
}
smb1cli_req_flags(state->conn->max_protocol,
state->conn->smb1.client.capabilities,
SMBnegprot,
0, 0, &flags,
0, 0, &flags2);
return smb1cli_req_send(state, state->ev, state->conn,
SMBnegprot,
flags, ~flags,
flags2, ~flags2,
state->timeout_msec,
0xFFFE, 0, NULL, /* pid, tid, session */
0, NULL, /* wct, vwv */
bytes.length, bytes.data);
}
| null | 0
|
static struct tevent_req *smbXcli_negprot_smb1_subreq(struct smbXcli_negprot_state *state)
{
size_t i;
DATA_BLOB bytes = data_blob_null;
uint8_t flags;
uint16_t flags2;
/* setup the protocol strings */
for (i=0; i < ARRAY_SIZE(smb1cli_prots); i++) {
uint8_t c = 2;
bool ok;
if (smb1cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb1cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
ok = data_blob_append(state, &bytes, &c, sizeof(c));
if (!ok) {
return NULL;
}
/*
* We now it is already ascii and
* we want NULL termination.
*/
ok = data_blob_append(state, &bytes,
smb1cli_prots[i].smb1_name,
strlen(smb1cli_prots[i].smb1_name)+1);
if (!ok) {
return NULL;
}
}
smb1cli_req_flags(state->conn->max_protocol,
state->conn->smb1.client.capabilities,
SMBnegprot,
0, 0, &flags,
0, 0, &flags2);
return smb1cli_req_send(state, state->ev, state->conn,
SMBnegprot,
flags, ~flags,
flags2, ~flags2,
state->timeout_msec,
0xFFFE, 0, NULL, /* pid, tid, session */
0, NULL, /* wct, vwv */
bytes.length, bytes.data);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,973
|
static void smbXcli_negprot_smb2_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_negprot_state *state =
tevent_req_data(req,
struct smbXcli_negprot_state);
struct smbXcli_conn *conn = state->conn;
size_t security_offset, security_length;
DATA_BLOB blob;
NTSTATUS status;
struct iovec *iov;
uint8_t *body;
size_t i;
uint16_t dialect_revision;
struct smb2_negotiate_contexts c = { .num_contexts = 0, };
uint32_t negotiate_context_offset = 0;
uint16_t negotiate_context_count = 0;
DATA_BLOB negotiate_context_blob = data_blob_null;
size_t avail;
size_t ctx_ofs;
size_t needed;
struct smb2_negotiate_context *preauth = NULL;
uint16_t hash_count;
uint16_t salt_length;
uint16_t hash_selected;
struct hc_sha512state sctx;
struct smb2_negotiate_context *cipher = NULL;
struct iovec sent_iov[3];
static const struct smb2cli_req_expected_response expected[] = {
{
.status = NT_STATUS_OK,
.body_size = 0x41
}
};
status = smb2cli_req_recv(subreq, state, &iov,
expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}
body = (uint8_t *)iov[1].iov_base;
dialect_revision = SVAL(body, 4);
for (i=0; i < ARRAY_SIZE(smb2cli_prots); i++) {
if (smb2cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb2cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
if (smb2cli_prots[i].smb2_dialect != dialect_revision) {
continue;
}
conn->protocol = smb2cli_prots[i].proto;
break;
}
if (conn->protocol == PROTOCOL_NONE) {
TALLOC_FREE(subreq);
if (state->conn->min_protocol >= PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (dialect_revision != SMB2_DIALECT_REVISION_2FF) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
/* make sure we do not loop forever */
state->conn->min_protocol = PROTOCOL_SMB2_02;
/*
* send a SMB2 negprot, in order to negotiate
* the SMB2 dialect.
*/
subreq = smbXcli_negprot_smb2_subreq(state);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, smbXcli_negprot_smb2_done, req);
return;
}
conn->smb2.server.security_mode = SVAL(body, 2);
if (conn->protocol >= PROTOCOL_SMB3_10) {
negotiate_context_count = SVAL(body, 6);
}
blob = data_blob_const(body + 8, 16);
status = GUID_from_data_blob(&blob, &conn->smb2.server.guid);
if (tevent_req_nterror(req, status)) {
return;
}
conn->smb2.server.capabilities = IVAL(body, 24);
conn->smb2.server.max_trans_size= IVAL(body, 28);
conn->smb2.server.max_read_size = IVAL(body, 32);
conn->smb2.server.max_write_size= IVAL(body, 36);
conn->smb2.server.system_time = BVAL(body, 40);
conn->smb2.server.start_time = BVAL(body, 48);
security_offset = SVAL(body, 56);
security_length = SVAL(body, 58);
if (security_offset != SMB2_HDR_BODY + iov[1].iov_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (security_length > iov[2].iov_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
conn->smb2.server.gss_blob = data_blob_talloc(conn,
iov[2].iov_base,
security_length);
if (tevent_req_nomem(conn->smb2.server.gss_blob.data, req)) {
return;
}
if (conn->protocol < PROTOCOL_SMB3_10) {
TALLOC_FREE(subreq);
if (conn->smb2.server.capabilities & SMB2_CAP_ENCRYPTION) {
conn->smb2.server.cipher = SMB2_ENCRYPTION_AES128_CCM;
}
tevent_req_done(req);
return;
}
if (conn->smb2.server.capabilities & SMB2_CAP_ENCRYPTION) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
negotiate_context_offset = IVAL(body, 60);
if (negotiate_context_offset < security_offset) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
ctx_ofs = negotiate_context_offset - security_offset;
if (ctx_ofs > iov[2].iov_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
avail = iov[2].iov_len - security_length;
needed = iov[2].iov_len - ctx_ofs;
if (needed > avail) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
negotiate_context_blob.data = (uint8_t *)iov[2].iov_base;
negotiate_context_blob.length = iov[2].iov_len;
negotiate_context_blob.data += ctx_ofs;
negotiate_context_blob.length -= ctx_ofs;
status = smb2_negotiate_context_parse(state, negotiate_context_blob, &c);
if (tevent_req_nterror(req, status)) {
return;
}
if (negotiate_context_count != c.num_contexts) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
preauth = smb2_negotiate_context_find(&c,
SMB2_PREAUTH_INTEGRITY_CAPABILITIES);
if (preauth == NULL) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (preauth->data.length < 6) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
hash_count = SVAL(preauth->data.data, 0);
salt_length = SVAL(preauth->data.data, 2);
hash_selected = SVAL(preauth->data.data, 4);
if (hash_count != 1) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (preauth->data.length != (6 + salt_length)) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (hash_selected != SMB2_PREAUTH_INTEGRITY_SHA512) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
cipher = smb2_negotiate_context_find(&c, SMB2_ENCRYPTION_CAPABILITIES);
if (cipher != NULL) {
uint16_t cipher_count;
if (cipher->data.length < 2) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
cipher_count = SVAL(cipher->data.data, 0);
if (cipher_count > 1) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (cipher->data.length != (2 + 2 * cipher_count)) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (cipher_count == 1) {
uint16_t cipher_selected;
cipher_selected = SVAL(cipher->data.data, 2);
switch (cipher_selected) {
case SMB2_ENCRYPTION_AES128_GCM:
case SMB2_ENCRYPTION_AES128_CCM:
conn->smb2.server.cipher = cipher_selected;
break;
}
}
}
/* First we hash the request */
smb2cli_req_get_sent_iov(subreq, sent_iov);
samba_SHA512_Init(&sctx);
samba_SHA512_Update(&sctx, conn->smb2.preauth_sha512,
sizeof(conn->smb2.preauth_sha512));
for (i = 0; i < 3; i++) {
samba_SHA512_Update(&sctx, sent_iov[i].iov_base, sent_iov[i].iov_len);
}
samba_SHA512_Final(conn->smb2.preauth_sha512, &sctx);
TALLOC_FREE(subreq);
/* And now we hash the response */
samba_SHA512_Init(&sctx);
samba_SHA512_Update(&sctx, conn->smb2.preauth_sha512,
sizeof(conn->smb2.preauth_sha512));
for (i = 0; i < 3; i++) {
samba_SHA512_Update(&sctx, iov[i].iov_base, iov[i].iov_len);
}
samba_SHA512_Final(conn->smb2.preauth_sha512, &sctx);
tevent_req_done(req);
}
| null | 0
|
static void smbXcli_negprot_smb2_done(struct tevent_req *subreq)
{
struct tevent_req *req =
tevent_req_callback_data(subreq,
struct tevent_req);
struct smbXcli_negprot_state *state =
tevent_req_data(req,
struct smbXcli_negprot_state);
struct smbXcli_conn *conn = state->conn;
size_t security_offset, security_length;
DATA_BLOB blob;
NTSTATUS status;
struct iovec *iov;
uint8_t *body;
size_t i;
uint16_t dialect_revision;
struct smb2_negotiate_contexts c = { .num_contexts = 0, };
uint32_t negotiate_context_offset = 0;
uint16_t negotiate_context_count = 0;
DATA_BLOB negotiate_context_blob = data_blob_null;
size_t avail;
size_t ctx_ofs;
size_t needed;
struct smb2_negotiate_context *preauth = NULL;
uint16_t hash_count;
uint16_t salt_length;
uint16_t hash_selected;
struct hc_sha512state sctx;
struct smb2_negotiate_context *cipher = NULL;
struct iovec sent_iov[3];
static const struct smb2cli_req_expected_response expected[] = {
{
.status = NT_STATUS_OK,
.body_size = 0x41
}
};
status = smb2cli_req_recv(subreq, state, &iov,
expected, ARRAY_SIZE(expected));
if (tevent_req_nterror(req, status)) {
return;
}
body = (uint8_t *)iov[1].iov_base;
dialect_revision = SVAL(body, 4);
for (i=0; i < ARRAY_SIZE(smb2cli_prots); i++) {
if (smb2cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb2cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
if (smb2cli_prots[i].smb2_dialect != dialect_revision) {
continue;
}
conn->protocol = smb2cli_prots[i].proto;
break;
}
if (conn->protocol == PROTOCOL_NONE) {
TALLOC_FREE(subreq);
if (state->conn->min_protocol >= PROTOCOL_SMB2_02) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (dialect_revision != SMB2_DIALECT_REVISION_2FF) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
/* make sure we do not loop forever */
state->conn->min_protocol = PROTOCOL_SMB2_02;
/*
* send a SMB2 negprot, in order to negotiate
* the SMB2 dialect.
*/
subreq = smbXcli_negprot_smb2_subreq(state);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, smbXcli_negprot_smb2_done, req);
return;
}
conn->smb2.server.security_mode = SVAL(body, 2);
if (conn->protocol >= PROTOCOL_SMB3_10) {
negotiate_context_count = SVAL(body, 6);
}
blob = data_blob_const(body + 8, 16);
status = GUID_from_data_blob(&blob, &conn->smb2.server.guid);
if (tevent_req_nterror(req, status)) {
return;
}
conn->smb2.server.capabilities = IVAL(body, 24);
conn->smb2.server.max_trans_size= IVAL(body, 28);
conn->smb2.server.max_read_size = IVAL(body, 32);
conn->smb2.server.max_write_size= IVAL(body, 36);
conn->smb2.server.system_time = BVAL(body, 40);
conn->smb2.server.start_time = BVAL(body, 48);
security_offset = SVAL(body, 56);
security_length = SVAL(body, 58);
if (security_offset != SMB2_HDR_BODY + iov[1].iov_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (security_length > iov[2].iov_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
conn->smb2.server.gss_blob = data_blob_talloc(conn,
iov[2].iov_base,
security_length);
if (tevent_req_nomem(conn->smb2.server.gss_blob.data, req)) {
return;
}
if (conn->protocol < PROTOCOL_SMB3_10) {
TALLOC_FREE(subreq);
if (conn->smb2.server.capabilities & SMB2_CAP_ENCRYPTION) {
conn->smb2.server.cipher = SMB2_ENCRYPTION_AES128_CCM;
}
tevent_req_done(req);
return;
}
if (conn->smb2.server.capabilities & SMB2_CAP_ENCRYPTION) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
negotiate_context_offset = IVAL(body, 60);
if (negotiate_context_offset < security_offset) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
ctx_ofs = negotiate_context_offset - security_offset;
if (ctx_ofs > iov[2].iov_len) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
avail = iov[2].iov_len - security_length;
needed = iov[2].iov_len - ctx_ofs;
if (needed > avail) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
negotiate_context_blob.data = (uint8_t *)iov[2].iov_base;
negotiate_context_blob.length = iov[2].iov_len;
negotiate_context_blob.data += ctx_ofs;
negotiate_context_blob.length -= ctx_ofs;
status = smb2_negotiate_context_parse(state, negotiate_context_blob, &c);
if (tevent_req_nterror(req, status)) {
return;
}
if (negotiate_context_count != c.num_contexts) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
preauth = smb2_negotiate_context_find(&c,
SMB2_PREAUTH_INTEGRITY_CAPABILITIES);
if (preauth == NULL) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (preauth->data.length < 6) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
hash_count = SVAL(preauth->data.data, 0);
salt_length = SVAL(preauth->data.data, 2);
hash_selected = SVAL(preauth->data.data, 4);
if (hash_count != 1) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (preauth->data.length != (6 + salt_length)) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (hash_selected != SMB2_PREAUTH_INTEGRITY_SHA512) {
tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
cipher = smb2_negotiate_context_find(&c, SMB2_ENCRYPTION_CAPABILITIES);
if (cipher != NULL) {
uint16_t cipher_count;
if (cipher->data.length < 2) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
cipher_count = SVAL(cipher->data.data, 0);
if (cipher_count > 1) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (cipher->data.length != (2 + 2 * cipher_count)) {
tevent_req_nterror(req,
NT_STATUS_INVALID_NETWORK_RESPONSE);
return;
}
if (cipher_count == 1) {
uint16_t cipher_selected;
cipher_selected = SVAL(cipher->data.data, 2);
switch (cipher_selected) {
case SMB2_ENCRYPTION_AES128_GCM:
case SMB2_ENCRYPTION_AES128_CCM:
conn->smb2.server.cipher = cipher_selected;
break;
}
}
}
/* First we hash the request */
smb2cli_req_get_sent_iov(subreq, sent_iov);
samba_SHA512_Init(&sctx);
samba_SHA512_Update(&sctx, conn->smb2.preauth_sha512,
sizeof(conn->smb2.preauth_sha512));
for (i = 0; i < 3; i++) {
samba_SHA512_Update(&sctx, sent_iov[i].iov_base, sent_iov[i].iov_len);
}
samba_SHA512_Final(conn->smb2.preauth_sha512, &sctx);
TALLOC_FREE(subreq);
/* And now we hash the response */
samba_SHA512_Init(&sctx);
samba_SHA512_Update(&sctx, conn->smb2.preauth_sha512,
sizeof(conn->smb2.preauth_sha512));
for (i = 0; i < 3; i++) {
samba_SHA512_Update(&sctx, iov[i].iov_base, iov[i].iov_len);
}
samba_SHA512_Final(conn->smb2.preauth_sha512, &sctx);
tevent_req_done(req);
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,974
|
static struct tevent_req *smbXcli_negprot_smb2_subreq(struct smbXcli_negprot_state *state)
{
size_t i;
uint8_t *buf;
uint16_t dialect_count = 0;
DATA_BLOB dyn = data_blob_null;
for (i=0; i < ARRAY_SIZE(smb2cli_prots); i++) {
bool ok;
uint8_t val[2];
if (smb2cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb2cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
SSVAL(val, 0, smb2cli_prots[i].smb2_dialect);
ok = data_blob_append(state, &dyn, val, sizeof(val));
if (!ok) {
return NULL;
}
dialect_count++;
}
buf = state->smb2.fixed;
SSVAL(buf, 0, 36);
SSVAL(buf, 2, dialect_count);
SSVAL(buf, 4, state->conn->smb2.client.security_mode);
SSVAL(buf, 6, 0); /* Reserved */
if (state->conn->max_protocol >= PROTOCOL_SMB2_22) {
SIVAL(buf, 8, state->conn->smb2.client.capabilities);
} else {
SIVAL(buf, 8, 0); /* Capabilities */
}
if (state->conn->max_protocol >= PROTOCOL_SMB2_10) {
NTSTATUS status;
DATA_BLOB blob;
status = GUID_to_ndr_blob(&state->conn->smb2.client.guid,
state, &blob);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
memcpy(buf+12, blob.data, 16); /* ClientGuid */
} else {
memset(buf+12, 0, 16); /* ClientGuid */
}
if (state->conn->max_protocol >= PROTOCOL_SMB3_10) {
NTSTATUS status;
struct smb2_negotiate_contexts c = { .num_contexts = 0, };
uint32_t offset;
DATA_BLOB b;
uint8_t p[38];
const uint8_t zeros[8] = {0, };
size_t pad;
bool ok;
SSVAL(p, 0, 1); /* HashAlgorithmCount */
SSVAL(p, 2, 32); /* SaltLength */
SSVAL(p, 4, SMB2_PREAUTH_INTEGRITY_SHA512);
generate_random_buffer(p + 6, 32);
b = data_blob_const(p, 38);
status = smb2_negotiate_context_add(state, &c,
SMB2_PREAUTH_INTEGRITY_CAPABILITIES, b);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
SSVAL(p, 0, 2); /* ChiperCount */
/*
* For now we preferr CCM because our implementation
* is faster than GCM, see bug #11451.
*/
SSVAL(p, 2, SMB2_ENCRYPTION_AES128_CCM);
SSVAL(p, 4, SMB2_ENCRYPTION_AES128_GCM);
b = data_blob_const(p, 6);
status = smb2_negotiate_context_add(state, &c,
SMB2_ENCRYPTION_CAPABILITIES, b);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
status = smb2_negotiate_context_push(state, &b, c);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
offset = SMB2_HDR_BODY + sizeof(state->smb2.fixed) + dyn.length;
pad = smbXcli_padding_helper(offset, 8);
ok = data_blob_append(state, &dyn, zeros, pad);
if (!ok) {
return NULL;
}
offset += pad;
ok = data_blob_append(state, &dyn, b.data, b.length);
if (!ok) {
return NULL;
}
SIVAL(buf, 28, offset); /* NegotiateContextOffset */
SSVAL(buf, 32, c.num_contexts); /* NegotiateContextCount */
SSVAL(buf, 34, 0); /* Reserved */
} else {
SBVAL(buf, 28, 0); /* Reserved/ClientStartTime */
}
return smb2cli_req_send(state, state->ev,
state->conn, SMB2_OP_NEGPROT,
0, 0, /* flags */
state->timeout_msec,
NULL, NULL, /* tcon, session */
state->smb2.fixed, sizeof(state->smb2.fixed),
dyn.data, dyn.length,
UINT16_MAX); /* max_dyn_len */
}
| null | 0
|
static struct tevent_req *smbXcli_negprot_smb2_subreq(struct smbXcli_negprot_state *state)
{
size_t i;
uint8_t *buf;
uint16_t dialect_count = 0;
DATA_BLOB dyn = data_blob_null;
for (i=0; i < ARRAY_SIZE(smb2cli_prots); i++) {
bool ok;
uint8_t val[2];
if (smb2cli_prots[i].proto < state->conn->min_protocol) {
continue;
}
if (smb2cli_prots[i].proto > state->conn->max_protocol) {
continue;
}
SSVAL(val, 0, smb2cli_prots[i].smb2_dialect);
ok = data_blob_append(state, &dyn, val, sizeof(val));
if (!ok) {
return NULL;
}
dialect_count++;
}
buf = state->smb2.fixed;
SSVAL(buf, 0, 36);
SSVAL(buf, 2, dialect_count);
SSVAL(buf, 4, state->conn->smb2.client.security_mode);
SSVAL(buf, 6, 0); /* Reserved */
if (state->conn->max_protocol >= PROTOCOL_SMB2_22) {
SIVAL(buf, 8, state->conn->smb2.client.capabilities);
} else {
SIVAL(buf, 8, 0); /* Capabilities */
}
if (state->conn->max_protocol >= PROTOCOL_SMB2_10) {
NTSTATUS status;
DATA_BLOB blob;
status = GUID_to_ndr_blob(&state->conn->smb2.client.guid,
state, &blob);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
memcpy(buf+12, blob.data, 16); /* ClientGuid */
} else {
memset(buf+12, 0, 16); /* ClientGuid */
}
if (state->conn->max_protocol >= PROTOCOL_SMB3_10) {
NTSTATUS status;
struct smb2_negotiate_contexts c = { .num_contexts = 0, };
uint32_t offset;
DATA_BLOB b;
uint8_t p[38];
const uint8_t zeros[8] = {0, };
size_t pad;
bool ok;
SSVAL(p, 0, 1); /* HashAlgorithmCount */
SSVAL(p, 2, 32); /* SaltLength */
SSVAL(p, 4, SMB2_PREAUTH_INTEGRITY_SHA512);
generate_random_buffer(p + 6, 32);
b = data_blob_const(p, 38);
status = smb2_negotiate_context_add(state, &c,
SMB2_PREAUTH_INTEGRITY_CAPABILITIES, b);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
SSVAL(p, 0, 2); /* ChiperCount */
/*
* For now we preferr CCM because our implementation
* is faster than GCM, see bug #11451.
*/
SSVAL(p, 2, SMB2_ENCRYPTION_AES128_CCM);
SSVAL(p, 4, SMB2_ENCRYPTION_AES128_GCM);
b = data_blob_const(p, 6);
status = smb2_negotiate_context_add(state, &c,
SMB2_ENCRYPTION_CAPABILITIES, b);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
status = smb2_negotiate_context_push(state, &b, c);
if (!NT_STATUS_IS_OK(status)) {
return NULL;
}
offset = SMB2_HDR_BODY + sizeof(state->smb2.fixed) + dyn.length;
pad = smbXcli_padding_helper(offset, 8);
ok = data_blob_append(state, &dyn, zeros, pad);
if (!ok) {
return NULL;
}
offset += pad;
ok = data_blob_append(state, &dyn, b.data, b.length);
if (!ok) {
return NULL;
}
SIVAL(buf, 28, offset); /* NegotiateContextOffset */
SSVAL(buf, 32, c.num_contexts); /* NegotiateContextCount */
SSVAL(buf, 34, 0); /* Reserved */
} else {
SBVAL(buf, 28, 0); /* Reserved/ClientStartTime */
}
return smb2cli_req_send(state, state->ev,
state->conn, SMB2_OP_NEGPROT,
0, 0, /* flags */
state->timeout_msec,
NULL, NULL, /* tcon, session */
state->smb2.fixed, sizeof(state->smb2.fixed),
dyn.data, dyn.length,
UINT16_MAX); /* max_dyn_len */
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,975
|
static void smbXcli_req_cleanup(struct tevent_req *req,
enum tevent_req_state req_state)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
TALLOC_FREE(state->write_req);
switch (req_state) {
case TEVENT_REQ_RECEIVED:
/*
* Make sure we really remove it from
* the pending array on destruction.
*/
state->smb1.mid = 0;
smbXcli_req_unset_pending(req);
return;
default:
return;
}
}
| null | 0
|
static void smbXcli_req_cleanup(struct tevent_req *req,
enum tevent_req_state req_state)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
TALLOC_FREE(state->write_req);
switch (req_state) {
case TEVENT_REQ_RECEIVED:
/*
* Make sure we really remove it from
* the pending array on destruction.
*/
state->smb1.mid = 0;
smbXcli_req_unset_pending(req);
return;
default:
return;
}
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,976
|
bool smbXcli_req_set_pending(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
struct smbXcli_conn *conn;
struct tevent_req **pending;
size_t num_pending;
conn = state->conn;
if (!smbXcli_conn_is_connected(conn)) {
return false;
}
num_pending = talloc_array_length(conn->pending);
pending = talloc_realloc(conn, conn->pending, struct tevent_req *,
num_pending+1);
if (pending == NULL) {
return false;
}
pending[num_pending] = req;
conn->pending = pending;
tevent_req_set_cleanup_fn(req, smbXcli_req_cleanup);
tevent_req_set_cancel_fn(req, smbXcli_req_cancel);
if (!smbXcli_conn_receive_next(conn)) {
/*
* the caller should notify the current request
*
* And all other pending requests get notified
* by smbXcli_conn_disconnect().
*/
smbXcli_req_unset_pending(req);
smbXcli_conn_disconnect(conn, NT_STATUS_NO_MEMORY);
return false;
}
return true;
}
| null | 0
|
bool smbXcli_req_set_pending(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
struct smbXcli_conn *conn;
struct tevent_req **pending;
size_t num_pending;
conn = state->conn;
if (!smbXcli_conn_is_connected(conn)) {
return false;
}
num_pending = talloc_array_length(conn->pending);
pending = talloc_realloc(conn, conn->pending, struct tevent_req *,
num_pending+1);
if (pending == NULL) {
return false;
}
pending[num_pending] = req;
conn->pending = pending;
tevent_req_set_cleanup_fn(req, smbXcli_req_cleanup);
tevent_req_set_cancel_fn(req, smbXcli_req_cancel);
if (!smbXcli_conn_receive_next(conn)) {
/*
* the caller should notify the current request
*
* And all other pending requests get notified
* by smbXcli_conn_disconnect().
*/
smbXcli_req_unset_pending(req);
smbXcli_conn_disconnect(conn, NT_STATUS_NO_MEMORY);
return false;
}
return true;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,977
|
void smbXcli_req_unset_pending(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
struct smbXcli_conn *conn = state->conn;
size_t num_pending = talloc_array_length(conn->pending);
size_t i;
TALLOC_FREE(state->write_req);
if (state->smb1.mid != 0) {
/*
* This is a [nt]trans[2] request which waits
* for more than one reply.
*/
return;
}
tevent_req_set_cleanup_fn(req, NULL);
if (num_pending == 1) {
/*
* The pending read_smb tevent_req is a child of
* conn->pending. So if nothing is pending anymore, we need to
* delete the socket read fde.
*/
TALLOC_FREE(conn->pending);
conn->read_smb_req = NULL;
return;
}
for (i=0; i<num_pending; i++) {
if (req == conn->pending[i]) {
break;
}
}
if (i == num_pending) {
/*
* Something's seriously broken. Just returning here is the
* right thing nevertheless, the point of this routine is to
* remove ourselves from conn->pending.
*/
return;
}
/*
* Remove ourselves from the conn->pending array
*/
for (; i < (num_pending - 1); i++) {
conn->pending[i] = conn->pending[i+1];
}
/*
* No NULL check here, we're shrinking by sizeof(void *), and
* talloc_realloc just adjusts the size for this.
*/
conn->pending = talloc_realloc(NULL, conn->pending, struct tevent_req *,
num_pending - 1);
return;
}
| null | 0
|
void smbXcli_req_unset_pending(struct tevent_req *req)
{
struct smbXcli_req_state *state =
tevent_req_data(req,
struct smbXcli_req_state);
struct smbXcli_conn *conn = state->conn;
size_t num_pending = talloc_array_length(conn->pending);
size_t i;
TALLOC_FREE(state->write_req);
if (state->smb1.mid != 0) {
/*
* This is a [nt]trans[2] request which waits
* for more than one reply.
*/
return;
}
tevent_req_set_cleanup_fn(req, NULL);
if (num_pending == 1) {
/*
* The pending read_smb tevent_req is a child of
* conn->pending. So if nothing is pending anymore, we need to
* delete the socket read fde.
*/
TALLOC_FREE(conn->pending);
conn->read_smb_req = NULL;
return;
}
for (i=0; i<num_pending; i++) {
if (req == conn->pending[i]) {
break;
}
}
if (i == num_pending) {
/*
* Something's seriously broken. Just returning here is the
* right thing nevertheless, the point of this routine is to
* remove ourselves from conn->pending.
*/
return;
}
/*
* Remove ourselves from the conn->pending array
*/
for (; i < (num_pending - 1); i++) {
conn->pending[i] = conn->pending[i+1];
}
/*
* No NULL check here, we're shrinking by sizeof(void *), and
* talloc_realloc just adjusts the size for this.
*/
conn->pending = talloc_realloc(NULL, conn->pending, struct tevent_req *,
num_pending - 1);
return;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,978
|
struct smbXcli_session *smbXcli_session_create(TALLOC_CTX *mem_ctx,
struct smbXcli_conn *conn)
{
struct smbXcli_session *session;
session = talloc_zero(mem_ctx, struct smbXcli_session);
if (session == NULL) {
return NULL;
}
session->smb2 = talloc_zero(session, struct smb2cli_session);
if (session->smb2 == NULL) {
talloc_free(session);
return NULL;
}
talloc_set_destructor(session, smbXcli_session_destructor);
DLIST_ADD_END(conn->sessions, session, struct smbXcli_session *);
session->conn = conn;
memcpy(session->smb2_channel.preauth_sha512,
conn->smb2.preauth_sha512,
sizeof(session->smb2_channel.preauth_sha512));
return session;
}
| null | 0
|
struct smbXcli_session *smbXcli_session_create(TALLOC_CTX *mem_ctx,
struct smbXcli_conn *conn)
{
struct smbXcli_session *session;
session = talloc_zero(mem_ctx, struct smbXcli_session);
if (session == NULL) {
return NULL;
}
session->smb2 = talloc_zero(session, struct smb2cli_session);
if (session->smb2 == NULL) {
talloc_free(session);
return NULL;
}
talloc_set_destructor(session, smbXcli_session_destructor);
DLIST_ADD_END(conn->sessions, session, struct smbXcli_session *);
session->conn = conn;
memcpy(session->smb2_channel.preauth_sha512,
conn->smb2.preauth_sha512,
sizeof(session->smb2_channel.preauth_sha512));
return session;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,979
|
static int smbXcli_session_destructor(struct smbXcli_session *session)
{
if (session->conn == NULL) {
return 0;
}
DLIST_REMOVE(session->conn->sessions, session);
return 0;
}
| null | 0
|
static int smbXcli_session_destructor(struct smbXcli_session *session)
{
if (session->conn == NULL) {
return 0;
}
DLIST_REMOVE(session->conn->sessions, session);
return 0;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,980
|
bool smbXcli_session_is_authenticated(struct smbXcli_session *session)
{
const DATA_BLOB *application_key;
if (session->conn == NULL) {
return false;
}
/*
* If we have an application key we had a session key negotiated
* at auth time.
*/
if (session->conn->protocol >= PROTOCOL_SMB2_02) {
application_key = &session->smb2->application_key;
} else {
application_key = &session->smb1.application_key;
}
if (application_key->length == 0) {
return false;
}
return true;
}
| null | 0
|
bool smbXcli_session_is_authenticated(struct smbXcli_session *session)
{
const DATA_BLOB *application_key;
if (session->conn == NULL) {
return false;
}
/*
* If we have an application key we had a session key negotiated
* at auth time.
*/
if (session->conn->protocol >= PROTOCOL_SMB2_02) {
application_key = &session->smb2->application_key;
} else {
application_key = &session->smb1.application_key;
}
if (application_key->length == 0) {
return false;
}
return true;
}
|
@@ -5446,6 +5446,9 @@ uint8_t smb2cli_session_security_mode(struct smbXcli_session *session)
if (conn->mandatory_signing) {
security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
}
+ if (session->smb2->should_sign) {
+ security_mode |= SMB2_NEGOTIATE_SIGNING_REQUIRED;
+ }
return security_mode;
}
@@ -5877,6 +5880,14 @@ NTSTATUS smb2cli_session_set_channel_key(struct smbXcli_session *session,
NTSTATUS smb2cli_session_encryption_on(struct smbXcli_session *session)
{
+ if (!session->smb2->should_sign) {
+ /*
+ * We need required signing on the session
+ * in order to prevent man in the middle attacks.
+ */
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+
if (session->smb2->should_encrypt) {
return NT_STATUS_OK;
}
|
CWE-20
| null | null |
1,981
|
static char *clean_path(TALLOC_CTX *ctx, const char *path)
{
size_t len;
char *p1, *p2, *p;
char *path_out;
/* No absolute paths. */
while (IS_DIRECTORY_SEP(*path)) {
path++;
}
path_out = talloc_strdup(ctx, path);
if (!path_out) {
return NULL;
}
p1 = strchr_m(path_out, '*');
p2 = strchr_m(path_out, '?');
if (p1 || p2) {
if (p1 && p2) {
p = MIN(p1,p2);
} else if (!p1) {
p = p2;
} else {
p = p1;
}
*p = '\0';
/* Now go back to the start of this component. */
p1 = strrchr_m(path_out, '/');
p2 = strrchr_m(path_out, '\\');
p = MAX(p1,p2);
if (p) {
*p = '\0';
}
}
/* Strip any trailing separator */
len = strlen(path_out);
if ( (len > 0) && IS_DIRECTORY_SEP(path_out[len-1])) {
path_out[len-1] = '\0';
}
return path_out;
}
| null | 0
|
static char *clean_path(TALLOC_CTX *ctx, const char *path)
{
size_t len;
char *p1, *p2, *p;
char *path_out;
/* No absolute paths. */
while (IS_DIRECTORY_SEP(*path)) {
path++;
}
path_out = talloc_strdup(ctx, path);
if (!path_out) {
return NULL;
}
p1 = strchr_m(path_out, '*');
p2 = strchr_m(path_out, '?');
if (p1 || p2) {
if (p1 && p2) {
p = MIN(p1,p2);
} else if (!p1) {
p = p2;
} else {
p = p1;
}
*p = '\0';
/* Now go back to the start of this component. */
p1 = strrchr_m(path_out, '/');
p2 = strrchr_m(path_out, '\\');
p = MAX(p1,p2);
if (p) {
*p = '\0';
}
}
/* Strip any trailing separator */
len = strlen(path_out);
if ( (len > 0) && IS_DIRECTORY_SEP(path_out[len-1])) {
path_out[len-1] = '\0';
}
return path_out;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,982
|
bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
struct cli_state *cli,
const char *sharename,
char **pp_newserver,
char **pp_newshare,
bool force_encrypt,
const char *username,
const char *password,
const char *domain)
{
struct client_dfs_referral *refs = NULL;
size_t num_refs = 0;
size_t consumed = 0;
char *fullpath = NULL;
bool res;
uint16_t cnum;
char *newextrapath = NULL;
NTSTATUS status;
const char *remote_name;
if (!cli || !sharename) {
return false;
}
remote_name = smbXcli_conn_remote_name(cli->conn);
cnum = cli_state_get_tid(cli);
/* special case. never check for a referral on the IPC$ share */
if (strequal(sharename, "IPC$")) {
return false;
}
/* send a trans2_query_path_info to check for a referral */
fullpath = talloc_asprintf(ctx, "\\%s\\%s", remote_name, sharename);
if (!fullpath) {
return false;
}
/* check for the referral */
if (!NT_STATUS_IS_OK(cli_tree_connect(cli, "IPC$", "IPC", NULL, 0))) {
return false;
}
if (force_encrypt) {
status = cli_cm_force_encryption(cli,
username,
password,
domain,
"IPC$");
if (!NT_STATUS_IS_OK(status)) {
return false;
}
}
status = cli_dfs_get_referral(ctx, cli, fullpath, &refs,
&num_refs, &consumed);
res = NT_STATUS_IS_OK(status);
status = cli_tdis(cli);
if (!NT_STATUS_IS_OK(status)) {
return false;
}
cli_state_set_tid(cli, cnum);
if (!res || !num_refs) {
return false;
}
if (!refs[0].dfspath) {
return false;
}
if (!split_dfs_path(ctx, refs[0].dfspath, pp_newserver,
pp_newshare, &newextrapath)) {
return false;
}
/* check that this is not a self-referral */
if (strequal(remote_name, *pp_newserver) &&
strequal(sharename, *pp_newshare)) {
return false;
}
return true;
}
| null | 0
|
bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
struct cli_state *cli,
const char *sharename,
char **pp_newserver,
char **pp_newshare,
bool force_encrypt,
const char *username,
const char *password,
const char *domain)
{
struct client_dfs_referral *refs = NULL;
size_t num_refs = 0;
size_t consumed = 0;
char *fullpath = NULL;
bool res;
uint16_t cnum;
char *newextrapath = NULL;
NTSTATUS status;
const char *remote_name;
if (!cli || !sharename) {
return false;
}
remote_name = smbXcli_conn_remote_name(cli->conn);
cnum = cli_state_get_tid(cli);
/* special case. never check for a referral on the IPC$ share */
if (strequal(sharename, "IPC$")) {
return false;
}
/* send a trans2_query_path_info to check for a referral */
fullpath = talloc_asprintf(ctx, "\\%s\\%s", remote_name, sharename);
if (!fullpath) {
return false;
}
/* check for the referral */
if (!NT_STATUS_IS_OK(cli_tree_connect(cli, "IPC$", "IPC", NULL, 0))) {
return false;
}
if (force_encrypt) {
status = cli_cm_force_encryption(cli,
username,
password,
domain,
"IPC$");
if (!NT_STATUS_IS_OK(status)) {
return false;
}
}
status = cli_dfs_get_referral(ctx, cli, fullpath, &refs,
&num_refs, &consumed);
res = NT_STATUS_IS_OK(status);
status = cli_tdis(cli);
if (!NT_STATUS_IS_OK(status)) {
return false;
}
cli_state_set_tid(cli, cnum);
if (!res || !num_refs) {
return false;
}
if (!refs[0].dfspath) {
return false;
}
if (!split_dfs_path(ctx, refs[0].dfspath, pp_newserver,
pp_newshare, &newextrapath)) {
return false;
}
/* check that this is not a self-referral */
if (strequal(remote_name, *pp_newserver) &&
strequal(sharename, *pp_newshare)) {
return false;
}
return true;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,983
|
static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
struct cli_state *referring_cli,
const char *server,
const char *share,
const struct user_auth_info *auth_info,
bool show_hdr,
bool force_encrypt,
int max_protocol,
int port,
int name_type,
struct cli_state **pcli)
{
struct cli_state *cli;
NTSTATUS status;
status = do_connect(ctx, server, share,
auth_info,
show_hdr, force_encrypt, max_protocol,
port, name_type, &cli);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
/* Enter into the list. */
if (referring_cli) {
DLIST_ADD_END(referring_cli, cli, struct cli_state *);
}
if (referring_cli && referring_cli->requested_posix_capabilities) {
uint16_t major, minor;
uint32_t caplow, caphigh;
status = cli_unix_extensions_version(cli, &major, &minor,
&caplow, &caphigh);
if (NT_STATUS_IS_OK(status)) {
cli_set_unix_extensions_capabilities(cli,
major, minor,
caplow, caphigh);
}
}
*pcli = cli;
return NT_STATUS_OK;
}
| null | 0
|
static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
struct cli_state *referring_cli,
const char *server,
const char *share,
const struct user_auth_info *auth_info,
bool show_hdr,
bool force_encrypt,
int max_protocol,
int port,
int name_type,
struct cli_state **pcli)
{
struct cli_state *cli;
NTSTATUS status;
status = do_connect(ctx, server, share,
auth_info,
show_hdr, force_encrypt, max_protocol,
port, name_type, &cli);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
/* Enter into the list. */
if (referring_cli) {
DLIST_ADD_END(referring_cli, cli, struct cli_state *);
}
if (referring_cli && referring_cli->requested_posix_capabilities) {
uint16_t major, minor;
uint32_t caplow, caphigh;
status = cli_unix_extensions_version(cli, &major, &minor,
&caplow, &caphigh);
if (NT_STATUS_IS_OK(status)) {
cli_set_unix_extensions_capabilities(cli,
major, minor,
caplow, caphigh);
}
}
*pcli = cli;
return NT_STATUS_OK;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,984
|
void cli_cm_display(struct cli_state *cli)
{
int i;
for (i=0; cli; cli = cli->next,i++ ) {
d_printf("%d:\tserver=%s, share=%s\n",
i, smbXcli_conn_remote_name(cli->conn), cli->share);
}
}
| null | 0
|
void cli_cm_display(struct cli_state *cli)
{
int i;
for (i=0; cli; cli = cli->next,i++ ) {
d_printf("%d:\tserver=%s, share=%s\n",
i, smbXcli_conn_remote_name(cli->conn), cli->share);
}
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,985
|
static struct cli_state *cli_cm_find(struct cli_state *cli,
const char *server,
const char *share)
{
struct cli_state *p;
if (cli == NULL) {
return NULL;
}
/* Search to the start of the list. */
for (p = cli; p; p = DLIST_PREV(p)) {
const char *remote_name =
smbXcli_conn_remote_name(p->conn);
if (strequal(server, remote_name) &&
strequal(share,p->share)) {
return p;
}
}
/* Search to the end of the list. */
for (p = cli->next; p; p = p->next) {
const char *remote_name =
smbXcli_conn_remote_name(p->conn);
if (strequal(server, remote_name) &&
strequal(share,p->share)) {
return p;
}
}
return NULL;
}
| null | 0
|
static struct cli_state *cli_cm_find(struct cli_state *cli,
const char *server,
const char *share)
{
struct cli_state *p;
if (cli == NULL) {
return NULL;
}
/* Search to the start of the list. */
for (p = cli; p; p = DLIST_PREV(p)) {
const char *remote_name =
smbXcli_conn_remote_name(p->conn);
if (strequal(server, remote_name) &&
strequal(share,p->share)) {
return p;
}
}
/* Search to the end of the list. */
for (p = cli->next; p; p = p->next) {
const char *remote_name =
smbXcli_conn_remote_name(p->conn);
if (strequal(server, remote_name) &&
strequal(share,p->share)) {
return p;
}
}
return NULL;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,986
|
NTSTATUS cli_cm_force_encryption(struct cli_state *c,
const char *username,
const char *password,
const char *domain,
const char *sharename)
{
NTSTATUS status;
if (smbXcli_conn_protocol(c->conn) >= PROTOCOL_SMB2_02) {
status = smb2cli_session_encryption_on(c->smb2.session);
if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED)) {
d_printf("Encryption required and "
"server doesn't support "
"SMB3 encryption - failing connect\n");
} else if (!NT_STATUS_IS_OK(status)) {
d_printf("Encryption required and "
"setup failed with error %s.\n",
nt_errstr(status));
}
return status;
}
status = cli_force_encryption(c,
username,
password,
domain);
if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED)) {
d_printf("Encryption required and "
"server that doesn't support "
"UNIX extensions - failing connect\n");
} else if (NT_STATUS_EQUAL(status,NT_STATUS_UNKNOWN_REVISION)) {
d_printf("Encryption required and "
"can't get UNIX CIFS extensions "
"version from server.\n");
} else if (NT_STATUS_EQUAL(status,NT_STATUS_UNSUPPORTED_COMPRESSION)) {
d_printf("Encryption required and "
"share %s doesn't support "
"encryption.\n", sharename);
} else if (!NT_STATUS_IS_OK(status)) {
d_printf("Encryption required and "
"setup failed with error %s.\n",
nt_errstr(status));
}
return status;
}
| null | 0
|
NTSTATUS cli_cm_force_encryption(struct cli_state *c,
const char *username,
const char *password,
const char *domain,
const char *sharename)
{
NTSTATUS status;
if (smbXcli_conn_protocol(c->conn) >= PROTOCOL_SMB2_02) {
status = smb2cli_session_encryption_on(c->smb2.session);
if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED)) {
d_printf("Encryption required and "
"server doesn't support "
"SMB3 encryption - failing connect\n");
} else if (!NT_STATUS_IS_OK(status)) {
d_printf("Encryption required and "
"setup failed with error %s.\n",
nt_errstr(status));
}
return status;
}
status = cli_force_encryption(c,
username,
password,
domain);
if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED)) {
d_printf("Encryption required and "
"server that doesn't support "
"UNIX extensions - failing connect\n");
} else if (NT_STATUS_EQUAL(status,NT_STATUS_UNKNOWN_REVISION)) {
d_printf("Encryption required and "
"can't get UNIX CIFS extensions "
"version from server.\n");
} else if (NT_STATUS_EQUAL(status,NT_STATUS_UNSUPPORTED_COMPRESSION)) {
d_printf("Encryption required and "
"share %s doesn't support "
"encryption.\n", sharename);
} else if (!NT_STATUS_IS_OK(status)) {
d_printf("Encryption required and "
"setup failed with error %s.\n",
nt_errstr(status));
}
return status;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,987
|
NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
struct cli_state *referring_cli,
const char *server,
const char *share,
const struct user_auth_info *auth_info,
bool show_hdr,
bool force_encrypt,
int max_protocol,
int port,
int name_type,
struct cli_state **pcli)
{
/* Try to reuse an existing connection in this list. */
struct cli_state *c = cli_cm_find(referring_cli, server, share);
NTSTATUS status;
if (c) {
*pcli = c;
return NT_STATUS_OK;
}
if (auth_info == NULL) {
/* Can't do a new connection
* without auth info. */
d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
"without auth info\n",
server, share );
return NT_STATUS_INVALID_PARAMETER;
}
status = cli_cm_connect(ctx,
referring_cli,
server,
share,
auth_info,
show_hdr,
force_encrypt,
max_protocol,
port,
name_type,
&c);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
*pcli = c;
return NT_STATUS_OK;
}
| null | 0
|
NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
struct cli_state *referring_cli,
const char *server,
const char *share,
const struct user_auth_info *auth_info,
bool show_hdr,
bool force_encrypt,
int max_protocol,
int port,
int name_type,
struct cli_state **pcli)
{
/* Try to reuse an existing connection in this list. */
struct cli_state *c = cli_cm_find(referring_cli, server, share);
NTSTATUS status;
if (c) {
*pcli = c;
return NT_STATUS_OK;
}
if (auth_info == NULL) {
/* Can't do a new connection
* without auth info. */
d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
"without auth info\n",
server, share );
return NT_STATUS_INVALID_PARAMETER;
}
status = cli_cm_connect(ctx,
referring_cli,
server,
share,
auth_info,
show_hdr,
force_encrypt,
max_protocol,
port,
name_type,
&c);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
*pcli = c;
return NT_STATUS_OK;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,988
|
static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected,
NTSTATUS status)
{
/* only deal with DS when we negotiated NT_STATUS codes and UNICODE */
if (!(smbXcli_conn_use_unicode(cli->conn))) {
return false;
}
if (!(smb1cli_conn_capabilities(cli->conn) & CAP_STATUS32)) {
return false;
}
if (NT_STATUS_EQUAL(status, expected)) {
return true;
}
return false;
}
| null | 0
|
static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected,
NTSTATUS status)
{
/* only deal with DS when we negotiated NT_STATUS codes and UNICODE */
if (!(smbXcli_conn_use_unicode(cli->conn))) {
return false;
}
if (!(smb1cli_conn_capabilities(cli->conn) & CAP_STATUS32)) {
return false;
}
if (NT_STATUS_EQUAL(status, expected)) {
return true;
}
return false;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,989
|
NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,
struct cli_state *cli,
const char *path,
struct client_dfs_referral **refs,
size_t *num_refs,
size_t *consumed)
{
unsigned int param_len = 0;
uint16_t recv_flags2;
uint8_t *param = NULL;
uint8_t *rdata = NULL;
char *p;
char *endp;
smb_ucs2_t *path_ucs;
char *consumed_path = NULL;
uint16_t consumed_ucs;
uint16_t num_referrals;
struct client_dfs_referral *referrals = NULL;
NTSTATUS status;
TALLOC_CTX *frame = talloc_stackframe();
*num_refs = 0;
*refs = NULL;
param = talloc_array(talloc_tos(), uint8_t, 2);
if (!param) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
SSVAL(param, 0, 0x03); /* max referral level */
param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
path, strlen(path)+1,
NULL);
if (!param) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
param_len = talloc_get_size(param);
path_ucs = (smb_ucs2_t *)¶m[2];
if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
DATA_BLOB in_input_buffer;
DATA_BLOB in_output_buffer = data_blob_null;
DATA_BLOB out_input_buffer = data_blob_null;
DATA_BLOB out_output_buffer = data_blob_null;
in_input_buffer.data = param;
in_input_buffer.length = param_len;
status = smb2cli_ioctl(cli->conn,
cli->timeout,
cli->smb2.session,
cli->smb2.tcon,
UINT64_MAX, /* in_fid_persistent */
UINT64_MAX, /* in_fid_volatile */
FSCTL_DFS_GET_REFERRALS,
0, /* in_max_input_length */
&in_input_buffer,
CLI_BUFFER_SIZE, /* in_max_output_length */
&in_output_buffer,
SMB2_IOCTL_FLAG_IS_FSCTL,
talloc_tos(),
&out_input_buffer,
&out_output_buffer);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
if (out_output_buffer.length < 4) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
recv_flags2 = FLAGS2_UNICODE_STRINGS;
rdata = out_output_buffer.data;
endp = (char *)rdata + out_output_buffer.length;
} else {
unsigned int data_len = 0;
uint16_t setup[1];
SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL);
status = cli_trans(talloc_tos(), cli, SMBtrans2,
NULL, 0xffff, 0, 0,
setup, 1, 0,
param, param_len, 2,
NULL, 0, CLI_BUFFER_SIZE,
&recv_flags2,
NULL, 0, NULL, /* rsetup */
NULL, 0, NULL,
&rdata, 4, &data_len);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
endp = (char *)rdata + data_len;
}
consumed_ucs = SVAL(rdata, 0);
num_referrals = SVAL(rdata, 2);
/* consumed_ucs is the number of bytes
* of the UCS2 path consumed not counting any
* terminating null. We need to convert
* back to unix charset and count again
* to get the number of bytes consumed from
* the incoming path. */
errno = 0;
if (pull_string_talloc(talloc_tos(),
NULL,
0,
&consumed_path,
path_ucs,
consumed_ucs,
STR_UNICODE) == 0) {
if (errno != 0) {
status = map_nt_error_from_unix(errno);
} else {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
}
goto out;
}
if (consumed_path == NULL) {
status = map_nt_error_from_unix(errno);
goto out;
}
*consumed = strlen(consumed_path);
if (num_referrals != 0) {
uint16_t ref_version;
uint16_t ref_size;
int i;
uint16_t node_offset;
referrals = talloc_array(ctx, struct client_dfs_referral,
num_referrals);
if (!referrals) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
/* start at the referrals array */
p = (char *)rdata+8;
for (i=0; i<num_referrals && p < endp; i++) {
if (p + 18 > endp) {
goto out;
}
ref_version = SVAL(p, 0);
ref_size = SVAL(p, 2);
node_offset = SVAL(p, 16);
if (ref_version != 3) {
p += ref_size;
continue;
}
referrals[i].proximity = SVAL(p, 8);
referrals[i].ttl = SVAL(p, 10);
if (p + node_offset > endp) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
clistr_pull_talloc(referrals,
(const char *)rdata,
recv_flags2,
&referrals[i].dfspath,
p+node_offset,
PTR_DIFF(endp, p+node_offset),
STR_TERMINATE|STR_UNICODE);
if (!referrals[i].dfspath) {
status = map_nt_error_from_unix(errno);
goto out;
}
p += ref_size;
}
if (i < num_referrals) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
}
*num_refs = num_referrals;
*refs = referrals;
out:
TALLOC_FREE(frame);
return status;
}
| null | 0
|
NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,
struct cli_state *cli,
const char *path,
struct client_dfs_referral **refs,
size_t *num_refs,
size_t *consumed)
{
unsigned int param_len = 0;
uint16_t recv_flags2;
uint8_t *param = NULL;
uint8_t *rdata = NULL;
char *p;
char *endp;
smb_ucs2_t *path_ucs;
char *consumed_path = NULL;
uint16_t consumed_ucs;
uint16_t num_referrals;
struct client_dfs_referral *referrals = NULL;
NTSTATUS status;
TALLOC_CTX *frame = talloc_stackframe();
*num_refs = 0;
*refs = NULL;
param = talloc_array(talloc_tos(), uint8_t, 2);
if (!param) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
SSVAL(param, 0, 0x03); /* max referral level */
param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
path, strlen(path)+1,
NULL);
if (!param) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
param_len = talloc_get_size(param);
path_ucs = (smb_ucs2_t *)¶m[2];
if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
DATA_BLOB in_input_buffer;
DATA_BLOB in_output_buffer = data_blob_null;
DATA_BLOB out_input_buffer = data_blob_null;
DATA_BLOB out_output_buffer = data_blob_null;
in_input_buffer.data = param;
in_input_buffer.length = param_len;
status = smb2cli_ioctl(cli->conn,
cli->timeout,
cli->smb2.session,
cli->smb2.tcon,
UINT64_MAX, /* in_fid_persistent */
UINT64_MAX, /* in_fid_volatile */
FSCTL_DFS_GET_REFERRALS,
0, /* in_max_input_length */
&in_input_buffer,
CLI_BUFFER_SIZE, /* in_max_output_length */
&in_output_buffer,
SMB2_IOCTL_FLAG_IS_FSCTL,
talloc_tos(),
&out_input_buffer,
&out_output_buffer);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
if (out_output_buffer.length < 4) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
recv_flags2 = FLAGS2_UNICODE_STRINGS;
rdata = out_output_buffer.data;
endp = (char *)rdata + out_output_buffer.length;
} else {
unsigned int data_len = 0;
uint16_t setup[1];
SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL);
status = cli_trans(talloc_tos(), cli, SMBtrans2,
NULL, 0xffff, 0, 0,
setup, 1, 0,
param, param_len, 2,
NULL, 0, CLI_BUFFER_SIZE,
&recv_flags2,
NULL, 0, NULL, /* rsetup */
NULL, 0, NULL,
&rdata, 4, &data_len);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
endp = (char *)rdata + data_len;
}
consumed_ucs = SVAL(rdata, 0);
num_referrals = SVAL(rdata, 2);
/* consumed_ucs is the number of bytes
* of the UCS2 path consumed not counting any
* terminating null. We need to convert
* back to unix charset and count again
* to get the number of bytes consumed from
* the incoming path. */
errno = 0;
if (pull_string_talloc(talloc_tos(),
NULL,
0,
&consumed_path,
path_ucs,
consumed_ucs,
STR_UNICODE) == 0) {
if (errno != 0) {
status = map_nt_error_from_unix(errno);
} else {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
}
goto out;
}
if (consumed_path == NULL) {
status = map_nt_error_from_unix(errno);
goto out;
}
*consumed = strlen(consumed_path);
if (num_referrals != 0) {
uint16_t ref_version;
uint16_t ref_size;
int i;
uint16_t node_offset;
referrals = talloc_array(ctx, struct client_dfs_referral,
num_referrals);
if (!referrals) {
status = NT_STATUS_NO_MEMORY;
goto out;
}
/* start at the referrals array */
p = (char *)rdata+8;
for (i=0; i<num_referrals && p < endp; i++) {
if (p + 18 > endp) {
goto out;
}
ref_version = SVAL(p, 0);
ref_size = SVAL(p, 2);
node_offset = SVAL(p, 16);
if (ref_version != 3) {
p += ref_size;
continue;
}
referrals[i].proximity = SVAL(p, 8);
referrals[i].ttl = SVAL(p, 10);
if (p + node_offset > endp) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
clistr_pull_talloc(referrals,
(const char *)rdata,
recv_flags2,
&referrals[i].dfspath,
p+node_offset,
PTR_DIFF(endp, p+node_offset),
STR_TERMINATE|STR_UNICODE);
if (!referrals[i].dfspath) {
status = map_nt_error_from_unix(errno);
goto out;
}
p += ref_size;
}
if (i < num_referrals) {
status = NT_STATUS_INVALID_NETWORK_RESPONSE;
goto out;
}
}
*num_refs = num_referrals;
*refs = referrals;
out:
TALLOC_FREE(frame);
return status;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,990
|
NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
const char *mountpt,
const struct user_auth_info *dfs_auth_info,
struct cli_state *rootcli,
const char *path,
struct cli_state **targetcli,
char **pp_targetpath)
{
struct client_dfs_referral *refs = NULL;
size_t num_refs = 0;
size_t consumed = 0;
struct cli_state *cli_ipc = NULL;
char *dfs_path = NULL;
char *cleanpath = NULL;
char *extrapath = NULL;
int pathlen;
struct cli_state *newcli = NULL;
struct cli_state *ccli = NULL;
int count = 0;
char *newpath = NULL;
char *newmount = NULL;
char *ppath = NULL;
SMB_STRUCT_STAT sbuf;
uint32_t attributes;
NTSTATUS status;
struct smbXcli_tcon *root_tcon = NULL;
struct smbXcli_tcon *target_tcon = NULL;
struct cli_dfs_path_split *dfs_refs = NULL;
if ( !rootcli || !path || !targetcli ) {
return NT_STATUS_INVALID_PARAMETER;
}
/* Don't do anything if this is not a DFS root. */
if (smbXcli_conn_protocol(rootcli->conn) >= PROTOCOL_SMB2_02) {
root_tcon = rootcli->smb2.tcon;
} else {
root_tcon = rootcli->smb1.tcon;
}
if (!smbXcli_tcon_is_dfs_share(root_tcon)) {
*targetcli = rootcli;
*pp_targetpath = talloc_strdup(ctx, path);
if (!*pp_targetpath) {
return NT_STATUS_NO_MEMORY;
}
return NT_STATUS_OK;
}
*targetcli = NULL;
/* Send a trans2_query_path_info to check for a referral. */
cleanpath = clean_path(ctx, path);
if (!cleanpath) {
return NT_STATUS_NO_MEMORY;
}
dfs_path = cli_dfs_make_full_path(ctx, rootcli, cleanpath);
if (!dfs_path) {
return NT_STATUS_NO_MEMORY;
}
status = cli_qpathinfo_basic( rootcli, dfs_path, &sbuf, &attributes);
if (NT_STATUS_IS_OK(status)) {
/* This is an ordinary path, just return it. */
*targetcli = rootcli;
*pp_targetpath = talloc_strdup(ctx, path);
if (!*pp_targetpath) {
return NT_STATUS_NO_MEMORY;
}
goto done;
}
/* Special case where client asked for a path that does not exist */
if (cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND,
status)) {
*targetcli = rootcli;
*pp_targetpath = talloc_strdup(ctx, path);
if (!*pp_targetpath) {
return NT_STATUS_NO_MEMORY;
}
goto done;
}
/* We got an error, check for DFS referral. */
if (!cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED,
status)) {
return status;
}
/* Check for the referral. */
status = cli_cm_open(ctx,
rootcli,
smbXcli_conn_remote_name(rootcli->conn),
"IPC$",
dfs_auth_info,
false,
smb1cli_conn_encryption_on(rootcli->conn),
smbXcli_conn_protocol(rootcli->conn),
0,
0x20,
&cli_ipc);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
status = cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs,
&num_refs, &consumed);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
if (!num_refs || !refs[0].dfspath) {
return NT_STATUS_NOT_FOUND;
}
/*
* Bug#10123 - DFS referal entries can be provided in a random order,
* so check the connection cache for each item to avoid unnecessary
* reconnections.
*/
dfs_refs = talloc_array(ctx, struct cli_dfs_path_split, num_refs);
if (dfs_refs == NULL) {
return NT_STATUS_NO_MEMORY;
}
for (count = 0; count < num_refs; count++) {
if (!split_dfs_path(dfs_refs, refs[count].dfspath,
&dfs_refs[count].server,
&dfs_refs[count].share,
&dfs_refs[count].extrapath)) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ccli = cli_cm_find(rootcli, dfs_refs[count].server,
dfs_refs[count].share);
if (ccli != NULL) {
extrapath = dfs_refs[count].extrapath;
*targetcli = ccli;
break;
}
}
/*
* If no cached connection was found, then connect to the first live
* referral server in the list.
*/
for (count = 0; (ccli == NULL) && (count < num_refs); count++) {
/* Connect to the target server & share */
status = cli_cm_connect(ctx, rootcli,
dfs_refs[count].server,
dfs_refs[count].share,
dfs_auth_info,
false,
smb1cli_conn_encryption_on(rootcli->conn),
smbXcli_conn_protocol(rootcli->conn),
0,
0x20,
targetcli);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
dfs_refs[count].server,
dfs_refs[count].share);
continue;
} else {
extrapath = dfs_refs[count].extrapath;
break;
}
}
/* No available referral server for the connection */
if (*targetcli == NULL) {
TALLOC_FREE(dfs_refs);
return status;
}
/* Make sure to recreate the original string including any wildcards. */
dfs_path = cli_dfs_make_full_path(ctx, rootcli, path);
if (!dfs_path) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
pathlen = strlen(dfs_path);
consumed = MIN(pathlen, consumed);
*pp_targetpath = talloc_strdup(ctx, &dfs_path[consumed]);
if (!*pp_targetpath) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
dfs_path[consumed] = '\0';
/*
* *pp_targetpath is now the unconsumed part of the path.
* dfs_path is now the consumed part of the path
* (in \server\share\path format).
*/
if (extrapath && strlen(extrapath) > 0) {
/* EMC Celerra NAS version 5.6.50 (at least) doesn't appear to */
/* put the trailing \ on the path, so to be save we put one in if needed */
if (extrapath[strlen(extrapath)-1] != '\\' && **pp_targetpath != '\\') {
*pp_targetpath = talloc_asprintf(ctx,
"%s\\%s",
extrapath,
*pp_targetpath);
} else {
*pp_targetpath = talloc_asprintf(ctx,
"%s%s",
extrapath,
*pp_targetpath);
}
if (!*pp_targetpath) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
}
/* parse out the consumed mount path */
/* trim off the \server\share\ */
ppath = dfs_path;
if (*ppath != '\\') {
d_printf("cli_resolve_path: "
"dfs_path (%s) not in correct format.\n",
dfs_path );
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ppath++; /* Now pointing at start of server name. */
if ((ppath = strchr_m( dfs_path, '\\' )) == NULL) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ppath++; /* Now pointing at start of share name. */
if ((ppath = strchr_m( ppath+1, '\\' )) == NULL) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ppath++; /* Now pointing at path component. */
newmount = talloc_asprintf(ctx, "%s\\%s", mountpt, ppath );
if (!newmount) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
cli_set_mntpoint(*targetcli, newmount);
/* Check for another dfs referral, note that we are not
checking for loops here. */
if (!strequal(*pp_targetpath, "\\") && !strequal(*pp_targetpath, "/")) {
status = cli_resolve_path(ctx,
newmount,
dfs_auth_info,
*targetcli,
*pp_targetpath,
&newcli,
&newpath);
if (NT_STATUS_IS_OK(status)) {
/*
* When cli_resolve_path returns true here it's always
* returning the complete path in newpath, so we're done
* here.
*/
*targetcli = newcli;
*pp_targetpath = newpath;
TALLOC_FREE(dfs_refs);
return status;
}
}
done:
if (smbXcli_conn_protocol((*targetcli)->conn) >= PROTOCOL_SMB2_02) {
target_tcon = (*targetcli)->smb2.tcon;
} else {
target_tcon = (*targetcli)->smb1.tcon;
}
/* If returning true ensure we return a dfs root full path. */
if (smbXcli_tcon_is_dfs_share(target_tcon)) {
dfs_path = talloc_strdup(ctx, *pp_targetpath);
if (!dfs_path) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
*pp_targetpath = cli_dfs_make_full_path(ctx, *targetcli, dfs_path);
if (*pp_targetpath == NULL) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
}
TALLOC_FREE(dfs_refs);
return NT_STATUS_OK;
}
| null | 0
|
NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
const char *mountpt,
const struct user_auth_info *dfs_auth_info,
struct cli_state *rootcli,
const char *path,
struct cli_state **targetcli,
char **pp_targetpath)
{
struct client_dfs_referral *refs = NULL;
size_t num_refs = 0;
size_t consumed = 0;
struct cli_state *cli_ipc = NULL;
char *dfs_path = NULL;
char *cleanpath = NULL;
char *extrapath = NULL;
int pathlen;
struct cli_state *newcli = NULL;
struct cli_state *ccli = NULL;
int count = 0;
char *newpath = NULL;
char *newmount = NULL;
char *ppath = NULL;
SMB_STRUCT_STAT sbuf;
uint32_t attributes;
NTSTATUS status;
struct smbXcli_tcon *root_tcon = NULL;
struct smbXcli_tcon *target_tcon = NULL;
struct cli_dfs_path_split *dfs_refs = NULL;
if ( !rootcli || !path || !targetcli ) {
return NT_STATUS_INVALID_PARAMETER;
}
/* Don't do anything if this is not a DFS root. */
if (smbXcli_conn_protocol(rootcli->conn) >= PROTOCOL_SMB2_02) {
root_tcon = rootcli->smb2.tcon;
} else {
root_tcon = rootcli->smb1.tcon;
}
if (!smbXcli_tcon_is_dfs_share(root_tcon)) {
*targetcli = rootcli;
*pp_targetpath = talloc_strdup(ctx, path);
if (!*pp_targetpath) {
return NT_STATUS_NO_MEMORY;
}
return NT_STATUS_OK;
}
*targetcli = NULL;
/* Send a trans2_query_path_info to check for a referral. */
cleanpath = clean_path(ctx, path);
if (!cleanpath) {
return NT_STATUS_NO_MEMORY;
}
dfs_path = cli_dfs_make_full_path(ctx, rootcli, cleanpath);
if (!dfs_path) {
return NT_STATUS_NO_MEMORY;
}
status = cli_qpathinfo_basic( rootcli, dfs_path, &sbuf, &attributes);
if (NT_STATUS_IS_OK(status)) {
/* This is an ordinary path, just return it. */
*targetcli = rootcli;
*pp_targetpath = talloc_strdup(ctx, path);
if (!*pp_targetpath) {
return NT_STATUS_NO_MEMORY;
}
goto done;
}
/* Special case where client asked for a path that does not exist */
if (cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND,
status)) {
*targetcli = rootcli;
*pp_targetpath = talloc_strdup(ctx, path);
if (!*pp_targetpath) {
return NT_STATUS_NO_MEMORY;
}
goto done;
}
/* We got an error, check for DFS referral. */
if (!cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED,
status)) {
return status;
}
/* Check for the referral. */
status = cli_cm_open(ctx,
rootcli,
smbXcli_conn_remote_name(rootcli->conn),
"IPC$",
dfs_auth_info,
false,
smb1cli_conn_encryption_on(rootcli->conn),
smbXcli_conn_protocol(rootcli->conn),
0,
0x20,
&cli_ipc);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
status = cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs,
&num_refs, &consumed);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
if (!num_refs || !refs[0].dfspath) {
return NT_STATUS_NOT_FOUND;
}
/*
* Bug#10123 - DFS referal entries can be provided in a random order,
* so check the connection cache for each item to avoid unnecessary
* reconnections.
*/
dfs_refs = talloc_array(ctx, struct cli_dfs_path_split, num_refs);
if (dfs_refs == NULL) {
return NT_STATUS_NO_MEMORY;
}
for (count = 0; count < num_refs; count++) {
if (!split_dfs_path(dfs_refs, refs[count].dfspath,
&dfs_refs[count].server,
&dfs_refs[count].share,
&dfs_refs[count].extrapath)) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ccli = cli_cm_find(rootcli, dfs_refs[count].server,
dfs_refs[count].share);
if (ccli != NULL) {
extrapath = dfs_refs[count].extrapath;
*targetcli = ccli;
break;
}
}
/*
* If no cached connection was found, then connect to the first live
* referral server in the list.
*/
for (count = 0; (ccli == NULL) && (count < num_refs); count++) {
/* Connect to the target server & share */
status = cli_cm_connect(ctx, rootcli,
dfs_refs[count].server,
dfs_refs[count].share,
dfs_auth_info,
false,
smb1cli_conn_encryption_on(rootcli->conn),
smbXcli_conn_protocol(rootcli->conn),
0,
0x20,
targetcli);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
dfs_refs[count].server,
dfs_refs[count].share);
continue;
} else {
extrapath = dfs_refs[count].extrapath;
break;
}
}
/* No available referral server for the connection */
if (*targetcli == NULL) {
TALLOC_FREE(dfs_refs);
return status;
}
/* Make sure to recreate the original string including any wildcards. */
dfs_path = cli_dfs_make_full_path(ctx, rootcli, path);
if (!dfs_path) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
pathlen = strlen(dfs_path);
consumed = MIN(pathlen, consumed);
*pp_targetpath = talloc_strdup(ctx, &dfs_path[consumed]);
if (!*pp_targetpath) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
dfs_path[consumed] = '\0';
/*
* *pp_targetpath is now the unconsumed part of the path.
* dfs_path is now the consumed part of the path
* (in \server\share\path format).
*/
if (extrapath && strlen(extrapath) > 0) {
/* EMC Celerra NAS version 5.6.50 (at least) doesn't appear to */
/* put the trailing \ on the path, so to be save we put one in if needed */
if (extrapath[strlen(extrapath)-1] != '\\' && **pp_targetpath != '\\') {
*pp_targetpath = talloc_asprintf(ctx,
"%s\\%s",
extrapath,
*pp_targetpath);
} else {
*pp_targetpath = talloc_asprintf(ctx,
"%s%s",
extrapath,
*pp_targetpath);
}
if (!*pp_targetpath) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
}
/* parse out the consumed mount path */
/* trim off the \server\share\ */
ppath = dfs_path;
if (*ppath != '\\') {
d_printf("cli_resolve_path: "
"dfs_path (%s) not in correct format.\n",
dfs_path );
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ppath++; /* Now pointing at start of server name. */
if ((ppath = strchr_m( dfs_path, '\\' )) == NULL) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ppath++; /* Now pointing at start of share name. */
if ((ppath = strchr_m( ppath+1, '\\' )) == NULL) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
ppath++; /* Now pointing at path component. */
newmount = talloc_asprintf(ctx, "%s\\%s", mountpt, ppath );
if (!newmount) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NOT_FOUND;
}
cli_set_mntpoint(*targetcli, newmount);
/* Check for another dfs referral, note that we are not
checking for loops here. */
if (!strequal(*pp_targetpath, "\\") && !strequal(*pp_targetpath, "/")) {
status = cli_resolve_path(ctx,
newmount,
dfs_auth_info,
*targetcli,
*pp_targetpath,
&newcli,
&newpath);
if (NT_STATUS_IS_OK(status)) {
/*
* When cli_resolve_path returns true here it's always
* returning the complete path in newpath, so we're done
* here.
*/
*targetcli = newcli;
*pp_targetpath = newpath;
TALLOC_FREE(dfs_refs);
return status;
}
}
done:
if (smbXcli_conn_protocol((*targetcli)->conn) >= PROTOCOL_SMB2_02) {
target_tcon = (*targetcli)->smb2.tcon;
} else {
target_tcon = (*targetcli)->smb1.tcon;
}
/* If returning true ensure we return a dfs root full path. */
if (smbXcli_tcon_is_dfs_share(target_tcon)) {
dfs_path = talloc_strdup(ctx, *pp_targetpath);
if (!dfs_path) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
*pp_targetpath = cli_dfs_make_full_path(ctx, *targetcli, dfs_path);
if (*pp_targetpath == NULL) {
TALLOC_FREE(dfs_refs);
return NT_STATUS_NO_MEMORY;
}
}
TALLOC_FREE(dfs_refs);
return NT_STATUS_OK;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,991
|
static void cli_set_mntpoint(struct cli_state *cli, const char *mnt)
{
TALLOC_CTX *frame = talloc_stackframe();
char *name = clean_name(frame, mnt);
if (!name) {
TALLOC_FREE(frame);
return;
}
TALLOC_FREE(cli->dfs_mountpoint);
cli->dfs_mountpoint = talloc_strdup(cli, name);
TALLOC_FREE(frame);
}
| null | 0
|
static void cli_set_mntpoint(struct cli_state *cli, const char *mnt)
{
TALLOC_CTX *frame = talloc_stackframe();
char *name = clean_name(frame, mnt);
if (!name) {
TALLOC_FREE(frame);
return;
}
TALLOC_FREE(cli->dfs_mountpoint);
cli->dfs_mountpoint = talloc_strdup(cli, name);
TALLOC_FREE(frame);
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,992
|
static bool split_dfs_path(TALLOC_CTX *ctx,
const char *nodepath,
char **pp_server,
char **pp_share,
char **pp_extrapath)
{
char *p, *q;
char *path;
*pp_server = NULL;
*pp_share = NULL;
*pp_extrapath = NULL;
path = talloc_strdup(ctx, nodepath);
if (!path) {
goto fail;
}
if ( path[0] != '\\' ) {
goto fail;
}
p = strchr_m( path + 1, '\\' );
if ( !p ) {
goto fail;
}
*p = '\0';
p++;
/* Look for any extra/deep path */
q = strchr_m(p, '\\');
if (q != NULL) {
*q = '\0';
q++;
*pp_extrapath = talloc_strdup(ctx, q);
} else {
*pp_extrapath = talloc_strdup(ctx, "");
}
if (*pp_extrapath == NULL) {
goto fail;
}
*pp_share = talloc_strdup(ctx, p);
if (*pp_share == NULL) {
goto fail;
}
*pp_server = talloc_strdup(ctx, &path[1]);
if (*pp_server == NULL) {
goto fail;
}
TALLOC_FREE(path);
return true;
fail:
TALLOC_FREE(*pp_share);
TALLOC_FREE(*pp_extrapath);
TALLOC_FREE(path);
return false;
}
| null | 0
|
static bool split_dfs_path(TALLOC_CTX *ctx,
const char *nodepath,
char **pp_server,
char **pp_share,
char **pp_extrapath)
{
char *p, *q;
char *path;
*pp_server = NULL;
*pp_share = NULL;
*pp_extrapath = NULL;
path = talloc_strdup(ctx, nodepath);
if (!path) {
goto fail;
}
if ( path[0] != '\\' ) {
goto fail;
}
p = strchr_m( path + 1, '\\' );
if ( !p ) {
goto fail;
}
*p = '\0';
p++;
/* Look for any extra/deep path */
q = strchr_m(p, '\\');
if (q != NULL) {
*q = '\0';
q++;
*pp_extrapath = talloc_strdup(ctx, q);
} else {
*pp_extrapath = talloc_strdup(ctx, "");
}
if (*pp_extrapath == NULL) {
goto fail;
}
*pp_share = talloc_strdup(ctx, p);
if (*pp_share == NULL) {
goto fail;
}
*pp_server = talloc_strdup(ctx, &path[1]);
if (*pp_server == NULL) {
goto fail;
}
TALLOC_FREE(path);
return true;
fail:
TALLOC_FREE(*pp_share);
TALLOC_FREE(*pp_extrapath);
TALLOC_FREE(path);
return false;
}
|
@@ -114,6 +114,11 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
const char *domain;
NTSTATUS status;
int flags = 0;
+ int signing_state = get_cmdline_auth_info_signing_state(auth_info);
+
+ if (force_encrypt) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
/* make a copy so we don't modify the global string 'service' */
servicename = talloc_strdup(ctx,share);
@@ -152,7 +157,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
status = cli_connect_nb(
server, NULL, port, name_type, NULL,
- get_cmdline_auth_info_signing_state(auth_info),
+ signing_state,
flags, &c);
if (!NT_STATUS_IS_OK(status)) {
|
CWE-20
| null | null |
1,993
|
SMBC_check_server(SMBCCTX * context,
SMBCSRV * server)
{
time_t now;
if (!cli_state_is_connected(server->cli)) {
return 1;
}
now = time_mono(NULL);
if (server->last_echo_time == (time_t)0 ||
now > server->last_echo_time +
(server->cli->timeout/1000)) {
unsigned char data[16] = {0};
NTSTATUS status = cli_echo(server->cli,
1,
data_blob_const(data, sizeof(data)));
if (!NT_STATUS_IS_OK(status)) {
return 1;
}
server->last_echo_time = now;
}
return 0;
}
| null | 0
|
SMBC_check_server(SMBCCTX * context,
SMBCSRV * server)
{
time_t now;
if (!cli_state_is_connected(server->cli)) {
return 1;
}
now = time_mono(NULL);
if (server->last_echo_time == (time_t)0 ||
now > server->last_echo_time +
(server->cli->timeout/1000)) {
unsigned char data[16] = {0};
NTSTATUS status = cli_echo(server->cli,
1,
data_blob_const(data, sizeof(data)));
if (!NT_STATUS_IS_OK(status)) {
return 1;
}
server->last_echo_time = now;
}
return 0;
}
|
@@ -273,6 +273,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
char *newserver, *newshare;
int flags = 0;
struct smbXcli_tcon *tcon = NULL;
+ int signing_state = SMB_SIGNING_DEFAULT;
ZERO_STRUCT(c);
*in_cache = false;
@@ -439,6 +440,10 @@ SMBC_server_internal(TALLOC_CTX *ctx,
flags |= CLI_FULL_CONNECTION_USE_NT_HASH;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
+
if (port == 0) {
if (share == NULL || *share == '\0' || is_ipc) {
/*
@@ -446,7 +451,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, NBT_SMB_PORT, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
}
@@ -456,7 +461,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, port, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
if (!NT_STATUS_IS_OK(status)) {
@@ -737,6 +742,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
ipc_srv = SMBC_find_server(ctx, context, server, "*IPC$",
pp_workgroup, pp_username, pp_password);
if (!ipc_srv) {
+ int signing_state = SMB_SIGNING_DEFAULT;
/* We didn't find a cached connection. Get the password */
if (!*pp_password || (*pp_password)[0] == '\0') {
@@ -758,6 +764,9 @@ SMBC_attr_server(TALLOC_CTX *ctx,
if (smbc_getOptionUseCCache(context)) {
flags |= CLI_FULL_CONNECTION_USE_CCACHE;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
nt_status = cli_full_connection(&ipc_cli,
lp_netbios_name(), server,
@@ -766,7 +775,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
*pp_workgroup,
*pp_password,
flags,
- SMB_SIGNING_DEFAULT);
+ signing_state);
if (! NT_STATUS_IS_OK(nt_status)) {
DEBUG(1,("cli_full_connection failed! (%s)\n",
nt_errstr(nt_status)));
|
CWE-20
| null | null |
1,994
|
SMBC_find_server(TALLOC_CTX *ctx,
SMBCCTX *context,
const char *server,
const char *share,
char **pp_workgroup,
char **pp_username,
char **pp_password)
{
SMBCSRV *srv;
int auth_called = 0;
if (!pp_workgroup || !pp_username || !pp_password) {
return NULL;
}
check_server_cache:
srv = smbc_getFunctionGetCachedServer(context)(context,
server, share,
*pp_workgroup,
*pp_username);
if (!auth_called && !srv && (!*pp_username || !(*pp_username)[0] ||
!*pp_password || !(*pp_password)[0])) {
SMBC_call_auth_fn(ctx, context, server, share,
pp_workgroup, pp_username, pp_password);
/*
* However, smbc_auth_fn may have picked up info relating to
* an existing connection, so try for an existing connection
* again ...
*/
auth_called = 1;
goto check_server_cache;
}
if (srv) {
if (smbc_getFunctionCheckServer(context)(context, srv)) {
/*
* This server is no good anymore
* Try to remove it and check for more possible
* servers in the cache
*/
if (smbc_getFunctionRemoveUnusedServer(context)(context,
srv)) {
/*
* We could not remove the server completely,
* remove it from the cache so we will not get
* it again. It will be removed when the last
* file/dir is closed.
*/
smbc_getFunctionRemoveCachedServer(context)(context,
srv);
}
/*
* Maybe there are more cached connections to this
* server
*/
goto check_server_cache;
}
return srv;
}
return NULL;
}
| null | 0
|
SMBC_find_server(TALLOC_CTX *ctx,
SMBCCTX *context,
const char *server,
const char *share,
char **pp_workgroup,
char **pp_username,
char **pp_password)
{
SMBCSRV *srv;
int auth_called = 0;
if (!pp_workgroup || !pp_username || !pp_password) {
return NULL;
}
check_server_cache:
srv = smbc_getFunctionGetCachedServer(context)(context,
server, share,
*pp_workgroup,
*pp_username);
if (!auth_called && !srv && (!*pp_username || !(*pp_username)[0] ||
!*pp_password || !(*pp_password)[0])) {
SMBC_call_auth_fn(ctx, context, server, share,
pp_workgroup, pp_username, pp_password);
/*
* However, smbc_auth_fn may have picked up info relating to
* an existing connection, so try for an existing connection
* again ...
*/
auth_called = 1;
goto check_server_cache;
}
if (srv) {
if (smbc_getFunctionCheckServer(context)(context, srv)) {
/*
* This server is no good anymore
* Try to remove it and check for more possible
* servers in the cache
*/
if (smbc_getFunctionRemoveUnusedServer(context)(context,
srv)) {
/*
* We could not remove the server completely,
* remove it from the cache so we will not get
* it again. It will be removed when the last
* file/dir is closed.
*/
smbc_getFunctionRemoveCachedServer(context)(context,
srv);
}
/*
* Maybe there are more cached connections to this
* server
*/
goto check_server_cache;
}
return srv;
}
return NULL;
}
|
@@ -273,6 +273,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
char *newserver, *newshare;
int flags = 0;
struct smbXcli_tcon *tcon = NULL;
+ int signing_state = SMB_SIGNING_DEFAULT;
ZERO_STRUCT(c);
*in_cache = false;
@@ -439,6 +440,10 @@ SMBC_server_internal(TALLOC_CTX *ctx,
flags |= CLI_FULL_CONNECTION_USE_NT_HASH;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
+
if (port == 0) {
if (share == NULL || *share == '\0' || is_ipc) {
/*
@@ -446,7 +451,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, NBT_SMB_PORT, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
}
@@ -456,7 +461,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, port, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
if (!NT_STATUS_IS_OK(status)) {
@@ -737,6 +742,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
ipc_srv = SMBC_find_server(ctx, context, server, "*IPC$",
pp_workgroup, pp_username, pp_password);
if (!ipc_srv) {
+ int signing_state = SMB_SIGNING_DEFAULT;
/* We didn't find a cached connection. Get the password */
if (!*pp_password || (*pp_password)[0] == '\0') {
@@ -758,6 +764,9 @@ SMBC_attr_server(TALLOC_CTX *ctx,
if (smbc_getOptionUseCCache(context)) {
flags |= CLI_FULL_CONNECTION_USE_CCACHE;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
nt_status = cli_full_connection(&ipc_cli,
lp_netbios_name(), server,
@@ -766,7 +775,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
*pp_workgroup,
*pp_password,
flags,
- SMB_SIGNING_DEFAULT);
+ signing_state);
if (! NT_STATUS_IS_OK(nt_status)) {
DEBUG(1,("cli_full_connection failed! (%s)\n",
nt_errstr(nt_status)));
|
CWE-20
| null | null |
1,995
|
SMBC_get_auth_data(const char *server, const char *share,
char *workgroup_buf, int workgroup_buf_len,
char *username_buf, int username_buf_len,
char *password_buf, int password_buf_len)
{
/* Default function just uses provided data. Nothing to do. */
}
| null | 0
|
SMBC_get_auth_data(const char *server, const char *share,
char *workgroup_buf, int workgroup_buf_len,
char *username_buf, int username_buf_len,
char *password_buf, int password_buf_len)
{
/* Default function just uses provided data. Nothing to do. */
}
|
@@ -273,6 +273,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
char *newserver, *newshare;
int flags = 0;
struct smbXcli_tcon *tcon = NULL;
+ int signing_state = SMB_SIGNING_DEFAULT;
ZERO_STRUCT(c);
*in_cache = false;
@@ -439,6 +440,10 @@ SMBC_server_internal(TALLOC_CTX *ctx,
flags |= CLI_FULL_CONNECTION_USE_NT_HASH;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
+
if (port == 0) {
if (share == NULL || *share == '\0' || is_ipc) {
/*
@@ -446,7 +451,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, NBT_SMB_PORT, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
}
@@ -456,7 +461,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, port, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
if (!NT_STATUS_IS_OK(status)) {
@@ -737,6 +742,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
ipc_srv = SMBC_find_server(ctx, context, server, "*IPC$",
pp_workgroup, pp_username, pp_password);
if (!ipc_srv) {
+ int signing_state = SMB_SIGNING_DEFAULT;
/* We didn't find a cached connection. Get the password */
if (!*pp_password || (*pp_password)[0] == '\0') {
@@ -758,6 +764,9 @@ SMBC_attr_server(TALLOC_CTX *ctx,
if (smbc_getOptionUseCCache(context)) {
flags |= CLI_FULL_CONNECTION_USE_CCACHE;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
nt_status = cli_full_connection(&ipc_cli,
lp_netbios_name(), server,
@@ -766,7 +775,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
*pp_workgroup,
*pp_password,
flags,
- SMB_SIGNING_DEFAULT);
+ signing_state);
if (! NT_STATUS_IS_OK(nt_status)) {
DEBUG(1,("cli_full_connection failed! (%s)\n",
nt_errstr(nt_status)));
|
CWE-20
| null | null |
1,996
|
SMBC_remove_unused_server(SMBCCTX * context,
SMBCSRV * srv)
{
SMBCFILE * file;
/* are we being fooled ? */
if (!context || !context->internal->initialized || !srv) {
return 1;
}
/* Check all open files/directories for a relation with this server */
for (file = context->internal->files; file; file = file->next) {
if (file->srv == srv) {
/* Still used */
DEBUG(3, ("smbc_remove_usused_server: "
"%p still used by %p.\n",
srv, file));
return 1;
}
}
DLIST_REMOVE(context->internal->servers, srv);
cli_shutdown(srv->cli);
srv->cli = NULL;
DEBUG(3, ("smbc_remove_usused_server: %p removed.\n", srv));
smbc_getFunctionRemoveCachedServer(context)(context, srv);
SAFE_FREE(srv);
return 0;
}
| null | 0
|
SMBC_remove_unused_server(SMBCCTX * context,
SMBCSRV * srv)
{
SMBCFILE * file;
/* are we being fooled ? */
if (!context || !context->internal->initialized || !srv) {
return 1;
}
/* Check all open files/directories for a relation with this server */
for (file = context->internal->files; file; file = file->next) {
if (file->srv == srv) {
/* Still used */
DEBUG(3, ("smbc_remove_usused_server: "
"%p still used by %p.\n",
srv, file));
return 1;
}
}
DLIST_REMOVE(context->internal->servers, srv);
cli_shutdown(srv->cli);
srv->cli = NULL;
DEBUG(3, ("smbc_remove_usused_server: %p removed.\n", srv));
smbc_getFunctionRemoveCachedServer(context)(context, srv);
SAFE_FREE(srv);
return 0;
}
|
@@ -273,6 +273,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
char *newserver, *newshare;
int flags = 0;
struct smbXcli_tcon *tcon = NULL;
+ int signing_state = SMB_SIGNING_DEFAULT;
ZERO_STRUCT(c);
*in_cache = false;
@@ -439,6 +440,10 @@ SMBC_server_internal(TALLOC_CTX *ctx,
flags |= CLI_FULL_CONNECTION_USE_NT_HASH;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
+
if (port == 0) {
if (share == NULL || *share == '\0' || is_ipc) {
/*
@@ -446,7 +451,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, NBT_SMB_PORT, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
}
@@ -456,7 +461,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
*/
status = cli_connect_nb(server_n, NULL, port, 0x20,
smbc_getNetbiosName(context),
- SMB_SIGNING_DEFAULT, flags, &c);
+ signing_state, flags, &c);
}
if (!NT_STATUS_IS_OK(status)) {
@@ -737,6 +742,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
ipc_srv = SMBC_find_server(ctx, context, server, "*IPC$",
pp_workgroup, pp_username, pp_password);
if (!ipc_srv) {
+ int signing_state = SMB_SIGNING_DEFAULT;
/* We didn't find a cached connection. Get the password */
if (!*pp_password || (*pp_password)[0] == '\0') {
@@ -758,6 +764,9 @@ SMBC_attr_server(TALLOC_CTX *ctx,
if (smbc_getOptionUseCCache(context)) {
flags |= CLI_FULL_CONNECTION_USE_CCACHE;
}
+ if (context->internal->smb_encryption_level != SMBC_ENCRYPTLEVEL_NONE) {
+ signing_state = SMB_SIGNING_REQUIRED;
+ }
nt_status = cli_full_connection(&ipc_cli,
lp_netbios_name(), server,
@@ -766,7 +775,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
*pp_workgroup,
*pp_password,
flags,
- SMB_SIGNING_DEFAULT);
+ signing_state);
if (! NT_STATUS_IS_OK(nt_status)) {
DEBUG(1,("cli_full_connection failed! (%s)\n",
nt_errstr(nt_status)));
|
CWE-20
| null | null |
1,997
|
IsValidJsonNumber(const char *str, int len)
{
bool numeric_error;
JsonLexContext dummy_lex;
/*
* json_lex_number expects a leading '-' to have been eaten already.
*
* having to cast away the constness of str is ugly, but there's not much
* easy alternative.
*/
if (*str == '-')
{
dummy_lex.input = (char *) str + 1;
dummy_lex.input_length = len - 1;
}
else
{
dummy_lex.input = (char *) str;
dummy_lex.input_length = len;
}
json_lex_number(&dummy_lex, dummy_lex.input, &numeric_error);
return !numeric_error;
}
|
DoS Overflow
| 0
|
IsValidJsonNumber(const char *str, int len)
{
bool numeric_error;
JsonLexContext dummy_lex;
/*
* json_lex_number expects a leading '-' to have been eaten already.
*
* having to cast away the constness of str is ugly, but there's not much
* easy alternative.
*/
if (*str == '-')
{
dummy_lex.input = (char *) str + 1;
dummy_lex.input_length = len - 1;
}
else
{
dummy_lex.input = (char *) str;
dummy_lex.input_length = len;
}
json_lex_number(&dummy_lex, dummy_lex.input, &numeric_error);
return !numeric_error;
}
|
@@ -490,6 +490,8 @@ parse_object(JsonLexContext *lex, JsonSemAction *sem)
json_struct_action oend = sem->object_end;
JsonTokenType tok;
+ check_stack_depth();
+
if (ostart != NULL)
(*ostart) (sem->semstate);
@@ -568,6 +570,8 @@ parse_array(JsonLexContext *lex, JsonSemAction *sem)
json_struct_action astart = sem->array_start;
json_struct_action aend = sem->array_end;
+ check_stack_depth();
+
if (astart != NULL)
(*astart) (sem->semstate);
@@ -1433,6 +1437,8 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
char *outputstr;
text *jsontext;
+ check_stack_depth();
+
/* callers are expected to ensure that null keys are not passed in */
Assert(!(key_scalar && is_null));
|
CWE-119
| null | null |
1,998
|
add_json(Datum val, bool is_null, StringInfo result,
Oid val_type, bool key_scalar)
{
JsonTypeCategory tcategory;
Oid outfuncoid;
if (val_type == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine input data type")));
if (is_null)
{
tcategory = JSONTYPE_NULL;
outfuncoid = InvalidOid;
}
else
json_categorize_type(val_type,
&tcategory, &outfuncoid);
datum_to_json(val, is_null, result, tcategory, outfuncoid, key_scalar);
}
|
DoS Overflow
| 0
|
add_json(Datum val, bool is_null, StringInfo result,
Oid val_type, bool key_scalar)
{
JsonTypeCategory tcategory;
Oid outfuncoid;
if (val_type == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not determine input data type")));
if (is_null)
{
tcategory = JSONTYPE_NULL;
outfuncoid = InvalidOid;
}
else
json_categorize_type(val_type,
&tcategory, &outfuncoid);
datum_to_json(val, is_null, result, tcategory, outfuncoid, key_scalar);
}
|
@@ -490,6 +490,8 @@ parse_object(JsonLexContext *lex, JsonSemAction *sem)
json_struct_action oend = sem->object_end;
JsonTokenType tok;
+ check_stack_depth();
+
if (ostart != NULL)
(*ostart) (sem->semstate);
@@ -568,6 +570,8 @@ parse_array(JsonLexContext *lex, JsonSemAction *sem)
json_struct_action astart = sem->array_start;
json_struct_action aend = sem->array_end;
+ check_stack_depth();
+
if (astart != NULL)
(*astart) (sem->semstate);
@@ -1433,6 +1437,8 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
char *outputstr;
text *jsontext;
+ check_stack_depth();
+
/* callers are expected to ensure that null keys are not passed in */
Assert(!(key_scalar && is_null));
|
CWE-119
| null | null |
1,999
|
array_dim_to_json(StringInfo result, int dim, int ndims, int *dims, Datum *vals,
bool *nulls, int *valcount, JsonTypeCategory tcategory,
Oid outfuncoid, bool use_line_feeds)
{
int i;
const char *sep;
Assert(dim < ndims);
sep = use_line_feeds ? ",\n " : ",";
appendStringInfoChar(result, '[');
for (i = 1; i <= dims[dim]; i++)
{
if (i > 1)
appendStringInfoString(result, sep);
if (dim + 1 == ndims)
{
datum_to_json(vals[*valcount], nulls[*valcount], result, tcategory,
outfuncoid, false);
(*valcount)++;
}
else
{
/*
* Do we want line feeds on inner dimensions of arrays? For now
* we'll say no.
*/
array_dim_to_json(result, dim + 1, ndims, dims, vals, nulls,
valcount, tcategory, outfuncoid, false);
}
}
appendStringInfoChar(result, ']');
}
|
DoS Overflow
| 0
|
array_dim_to_json(StringInfo result, int dim, int ndims, int *dims, Datum *vals,
bool *nulls, int *valcount, JsonTypeCategory tcategory,
Oid outfuncoid, bool use_line_feeds)
{
int i;
const char *sep;
Assert(dim < ndims);
sep = use_line_feeds ? ",\n " : ",";
appendStringInfoChar(result, '[');
for (i = 1; i <= dims[dim]; i++)
{
if (i > 1)
appendStringInfoString(result, sep);
if (dim + 1 == ndims)
{
datum_to_json(vals[*valcount], nulls[*valcount], result, tcategory,
outfuncoid, false);
(*valcount)++;
}
else
{
/*
* Do we want line feeds on inner dimensions of arrays? For now
* we'll say no.
*/
array_dim_to_json(result, dim + 1, ndims, dims, vals, nulls,
valcount, tcategory, outfuncoid, false);
}
}
appendStringInfoChar(result, ']');
}
|
@@ -490,6 +490,8 @@ parse_object(JsonLexContext *lex, JsonSemAction *sem)
json_struct_action oend = sem->object_end;
JsonTokenType tok;
+ check_stack_depth();
+
if (ostart != NULL)
(*ostart) (sem->semstate);
@@ -568,6 +570,8 @@ parse_array(JsonLexContext *lex, JsonSemAction *sem)
json_struct_action astart = sem->array_start;
json_struct_action aend = sem->array_end;
+ check_stack_depth();
+
if (astart != NULL)
(*astart) (sem->semstate);
@@ -1433,6 +1437,8 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
char *outputstr;
text *jsontext;
+ check_stack_depth();
+
/* callers are expected to ensure that null keys are not passed in */
Assert(!(key_scalar && is_null));
|
CWE-119
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.