Skip to content

Commit

Permalink
Merge branch 'jcifs-ng'
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Oct 8, 2018
2 parents b6daa36 + 3292a1f commit 10eaef0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/main/java/jcifs/internal/smb1/net/SmbShareInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ public boolean equals ( Object obj ) {

@Override
public int hashCode () {
int hashCode = this.netName.hashCode();
return hashCode;
return this.netName != null ? this.netName.hashCode() : 0;
}


Expand Down
21 changes: 20 additions & 1 deletion src/main/java/jcifs/internal/smb2/ServerMessageBlock2.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public abstract class ServerMessageBlock2 implements CommonServerMessageBlock {
private int status;
private int credit;
private int nextCommand;
private int readSize;
private boolean async;
private int treeId;
private long mid, asyncId, sessionId;
Expand Down Expand Up @@ -164,6 +165,15 @@ public final int getNextCommandOffset () {
}


/**
* @param readSize
* the readSize to set
*/
public void setReadSize ( int readSize ) {
this.readSize = readSize;
}


/**
* @return the async
*/
Expand Down Expand Up @@ -560,10 +570,19 @@ public int decode ( byte[] buffer, int bufferIndex, boolean compound ) throws SM
this.length = bufferIndex - start;
int len = this.length;

if ( compound || this.nextCommand != 0 ) {
if ( this.nextCommand != 0 ) {
// padding becomes part of signature if this is _PART_ of a compound chain
len += pad8(bufferIndex);
}
else if ( compound && this.nextCommand == 0 && this.readSize > 0 ) {
// TODO: only apply this for actual compound chains, or is this correct for single responses, too?
// 3.2.5.1.9 Handling Compounded Responses
// The final response in the compounded response chain will have NextCommand equal to 0,
// and it MUST be processed as an individual message of a size equal to the number of bytes
// remaining in this receive.
int rem = this.readSize - this.length;
len += rem;
}

haveResponse(buffer, start, len);

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/jcifs/smb/NtStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public interface NtStatus {
public static final int NT_STATUS_CONNECTION_REFUSED = 0xC0000236;
public static final int NT_STATUS_PATH_NOT_COVERED = 0xC0000257;
public static final int NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED = 0xC0000279;
public static final int NT_STATUS_NO_MORE_FILES = 0x80000006;

static final int[] NT_STATUS_CODES = {
NT_STATUS_OK, NT_STATUS_PENDING, NT_STATUS_NOTIFY_ENUM_DIR, NT_STATUS_BUFFER_OVERFLOW, NT_STATUS_UNSUCCESSFUL,
Expand All @@ -113,7 +114,7 @@ public interface NtStatus {
NT_STATUS_CANNOT_DELETE, NT_STATUS_INVALID_COMPUTER_NAME, NT_STATUS_PIPE_BROKEN, NT_STATUS_NO_SUCH_ALIAS, NT_STATUS_LOGON_TYPE_NOT_GRANTED,
NT_STATUS_NO_TRUST_SAM_ACCOUNT, NT_STATUS_TRUSTED_DOMAIN_FAILURE, NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE,
NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT, NT_STATUS_PASSWORD_MUST_CHANGE, NT_STATUS_NOT_FOUND, NT_STATUS_ACCOUNT_LOCKED_OUT,
NT_STATUS_CONNECTION_REFUSED, NT_STATUS_PATH_NOT_COVERED, NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED,
NT_STATUS_CONNECTION_REFUSED, NT_STATUS_PATH_NOT_COVERED, NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED, NT_STATUS_NO_MORE_FILES,
};

static final String[] NT_STATUS_MESSAGES = {
Expand Down Expand Up @@ -146,5 +147,6 @@ public interface NtStatus {
"The user must change his password before he logs on the first time.", "The object was not found.",
"The referenced account is currently locked out and may not be logged on to.", "Connection refused",
"The remote system is not reachable by the transport.", "The layered file system driver for this I/O tag did not handle it when needed.",
"No more files were found that match the file specification.",
};
}
2 changes: 1 addition & 1 deletion src/main/java/jcifs/smb/SmbFileOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected final void init ( SmbTreeHandleImpl th ) throws CIFSException {
// there seems to be a bug with some servers that causes corruption if using signatures +
// CAP_LARGE_WRITE
if ( th.hasCapability(SmbConstants.CAP_LARGE_WRITEX) && !th.areSignaturesActive() ) {
this.writeSizeFile = Math.min(sendBufferSize - 70, 0xFFFF - 70);
this.writeSizeFile = Math.min(th.getConfig().getSendBufferSize() - 70, 0xFFFF - 70);
}
else {
log.debug("No support or SMB signing is enabled, not enabling large writes");
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/jcifs/smb/SmbTransportImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ private SmbNegotiation negotiate ( int prt ) throws IOException {
this.in = this.socket.getInputStream();
}

if ( this.credits.drainPermits() == 0 ) {
log.debug("It appears we previously lost some credits");
}

if ( this.smb2 || this.getContext().getConfig().isUseSMB2OnlyNegotiation() ) {
log.debug("Using SMB2 only negotiation");
return negotiate2(null);
Expand Down Expand Up @@ -528,7 +532,7 @@ private SmbNegotiation negotiate ( int prt ) throws IOException {
return negotiate2(r);
}

int permits = resp.getInitialCredits() - 1;
int permits = resp.getInitialCredits();
if ( permits > 0 ) {
this.credits.release(permits);
}
Expand Down Expand Up @@ -607,10 +611,6 @@ private SmbNegotiation negotiate2 ( Smb2NegotiateResponse first ) throws IOExcep

// further negotiation needed
Smb2NegotiateRequest smb2neg = new Smb2NegotiateRequest(getContext().getConfig(), securityMode);

if ( this.credits.drainPermits() == 0 ) {
throw new IOException("No credits for negotiate");
}
Smb2NegotiateResponse r = null;
byte[] negoReqBuffer = null;
byte[] negoRespBuffer = null;
Expand Down Expand Up @@ -1174,6 +1174,7 @@ private void doRecvSMB2 ( CommonServerMessageBlock response ) throws IOException
System.arraycopy(this.sbuf, 4, buffer, 0, Smb2Constants.SMB2_HEADER_LENGTH);
readn(this.in, buffer, Smb2Constants.SMB2_HEADER_LENGTH, rl - Smb2Constants.SMB2_HEADER_LENGTH);

cur.setReadSize(rl);
int len = cur.decode(buffer, 0);

if ( len > rl ) {
Expand Down Expand Up @@ -1207,6 +1208,7 @@ else if ( nextCommand != 0 && len > nextCommand ) {
log.debug(String.format("Compound next command %d read size %d remain %d", nextCommand, rl, size));
}

cur.setReadSize(rl);
readn(this.in, buffer, Smb2Constants.SMB2_HEADER_LENGTH, rl - Smb2Constants.SMB2_HEADER_LENGTH);

len = cur.decode(buffer, 0, true);
Expand Down Expand Up @@ -1388,6 +1390,7 @@ boolean checkStatus2 ( ServerMessageBlock2 req, Response resp ) throws SmbExcept
boolean cont = false;
switch ( resp.getErrorCode() ) {
case NtStatus.NT_STATUS_OK:
case NtStatus.NT_STATUS_NO_MORE_FILES:
cont = true;
break;
case NtStatus.NT_STATUS_PENDING:
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/jcifs/tests/SessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -134,12 +133,12 @@ public void logonUserNoDomain () throws IOException {


@Test
@Ignore
public void transportReconnects () throws IOException {
try ( SmbFile f = getDefaultShareRoot() ) {
// transport disconnects can happen pretty much any time
assertNotNull(f);
f.connect();
f.exists();
assertNotNull(f);
try ( SmbTreeHandleInternal treeHandle = (SmbTreeHandleInternal) f.getTreeHandle();
SmbSessionInternal session = treeHandle.getSession().unwrap(SmbSessionInternal.class) ) {
Expand All @@ -149,6 +148,7 @@ public void transportReconnects () throws IOException {
transport.disconnect(true, true);
assertNotNull(f);
checkConnection(f);
f.exists();
}
}
}
Expand All @@ -160,7 +160,6 @@ public void transportReconnects () throws IOException {


@Test
@Ignore
public void transportReuseSimple () throws CIFSException {
CIFSContext ctx = withTestNTLMCredentials(getContext());
String loc = getTestShareURL();
Expand All @@ -175,7 +174,6 @@ public void transportReuseSimple () throws CIFSException {


@Test
@Ignore
public void transportReuseAnon () throws CIFSException {
CIFSContext ctx1 = withTestNTLMCredentials(getContext());
CIFSContext ctx2 = withAnonymousCredentials();
Expand All @@ -191,7 +189,6 @@ public void transportReuseAnon () throws CIFSException {


@Test
@Ignore
// BUG #14
public void testNoLeakRequest () throws CIFSException, MalformedURLException {
try ( SmbFile f = getDefaultShareRoot() ) {
Expand All @@ -208,7 +205,6 @@ public void testNoLeakRequest () throws CIFSException, MalformedURLException {


@Test
@Ignore
// BUG #14
public void testNoLeakRequestError () throws IOException {
try ( SmbResource f = getDefaultShareRoot().resolve("doesnotexist") ) {
Expand Down

0 comments on commit 10eaef0

Please sign in to comment.