+Mon Jul 16 13:26:26 EDT 2007
+jcifs-1.2.15 released
+
+This release includes some significant changes. Most of these changes
+are related to NetApp compatibility. The changes in this release are:
+
+An SMB signing failure related to DFS has been fixed.
+
+The DCERPC bind did not exactly mimic Windows which uses
+SMB_COM_{WRITE,READ}_ANDX. We were using TransactNmPipe throughout which
+could result in an 'Incorrect function' error when querying the LSA on
+a NetApp server. JCIFS now implements the bind exactly like Windows to
+help ensure compatibility with other servers.
+
+Other changes related to NetApp compatibility include falling back to
+SamrConnect2 if an DCERPC_FAULT_OP_RNG_ERROR error occurs, more closely
+mimicing the SMB_COM_NT_CREATE_ANDX "extended" response, adjusting various
+RPC handle operation access masks, uncommenting some padding code that
+was commented out for what appeared to be a NetWare problem, disabling
+some logic to used port 139 if the jcifs.netbios.hostname was set and
+finally adding code to include LsarQosInfo structures in the MSRPC bind.
+
+Some new error code information has been added.
+
+Constants for common SIDs have been added to the SID class.
+
+The SID.getGroupMemberSids() method will now return an empty SID array
+if the SID is not of type SID_TYPE_DOM_GRP or SID_TYPE_ALIAS.
+
+A minor performance flaw in the DCERPC code was found and fixed.
+
Wed Jun 20 13:09:10 EDT 2007
jcifs-1.2.14 released
<project name="jcifs" default="usage" basedir=".">
- <property name="version" value="1.2.14"/>
- <property name="reldate" value="Jun 20, 2007"/>
+ <property name="version" value="1.2.16"/>
+ <property name="reldate" value="Aug 2, 2007"/>
<target name="usage">
<echo>
--- /dev/null
+C:\tmp>ktpass /princ HTTP/www.foo.net@WIN.NET /ptype KRB5_NT_PRINCIPAL /desonly /pass asj7j112233hh4455 /mapuser test2\r
+Targeting domain controller: ts0.win.net\r
+Using legacy password setting method\r
+Successfully mapped HTTP/www.foo.net to test2.\r
+Key created.\r
+Account test2 has been set for DES-only encryption.
\ No newline at end of file
+++ /dev/null
-import java.util.Date;
-import java.util.TimeZone;
-
-public class CifsTime {
-
- // Observed dates reporting ServerTimeZone=240
- // file last modified date = { low, high };
-
- // Mon Mar 26 23:14:42 EST 2001 (no DST)
- static final int[] D = { 0x10BE3D00, 0x01C0B66C };
-
- // Mon Apr 30 03:17:14 EST 2001 (in DST)
- //static final int[] D = { 0x9474B900, 0x01C0D145 };
-
- static final long MILLISECONDS_BETWEEN_1970_AND_1601 = 11644473600000L;
-
- static long calcDate() {
- int lo, hi;
- long t;
-
- t = ((long)D[1] << 32 ) | ( (long)D[0] & 0xFFFFFFFFL );
- t = ( t / 10000L - MILLISECONDS_BETWEEN_1970_AND_1601 );
-
- if( TimeZone.getDefault().inDaylightTime( new Date() )) {
- // in dst
-
- if( TimeZone.getDefault().inDaylightTime( new Date( t ))) {
- // t was also generated in dst too so no correction
- return t;
- }
- // t was not generated during dst so add 1 hour
- return t + 3600000L;
- } else {
- // not in dst
-
- if( TimeZone.getDefault().inDaylightTime( new Date( t ))) {
- // t was generated in dst so subtract 1 hour
- return t - 3600000L;
- }
- // t was also not generated in dst so no correction
- return t;
- }
- }
- public static void main( String[] argv ) throws Exception {
- System.out.println( new Date( calcDate() ));
- }
-}
--- /dev/null
+import java.util.*;
+import jcifs.smb.*;
+
+public class GetGroupMemberSidsFromURL {
+
+ public static void main( String[] argv ) throws Exception {
+ if (argv.length < 1) {
+ System.err.println("usage: GetGroupMemberSidsFromURL <smburl>");
+ System.exit(1);
+ }
+
+ SmbFile file = new SmbFile(argv[0]);
+ String server = file.getServer();
+ NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)file.getPrincipal();
+ ACE[] security = file.getSecurity(true);
+
+ for (int ai = 0; ai < security.length; ai++) {
+ ACE ace = security[ai];
+ SID sid = ace.getSID();
+ if (sid.equals(SID.EVERYONE) ||
+ sid.equals(SID.CREATOR_OWNER) ||
+ sid.equals(SID.SYSTEM))
+ continue;
+
+ System.out.println(sid.toString() + " (" + sid.toDisplayString() + ") members:");
+
+ SID[] mems = sid.getGroupMemberSids(server, auth, SID.SID_FLAG_RESOLVE_SIDS);
+ for (int mi = 0; mi < mems.length; mi++) {
+ SID mem = mems[mi];
+ System.out.println(" " + mem.getType() + " " + mem.toDisplayString());
+ }
+ }
+ }
+}
System.out.println( acl[i] );
SID sid = acl[i].getSID();
System.out.println(" toString: " + sid.toString());
- System.out.println(" toSidString: " + sid.toSidString());
+ System.out.println(" toSidString: " + sid.toDisplayString());
System.out.println(" getType: " + sid.getType());
System.out.println(" getTypeText: " + sid.getTypeText());
System.out.println(" getDomainName: " + sid.getDomainName());
.SUFFIXES: .java .class
-CLASSFILES=SidCacheTest.class GetSecurity.class SidCrawler.class InterruptTest.class AllocInfo.class Append.class AuthListFiles.class CallNamedPipe.class CopyTo.class CreateFile.class Delete.class Equals.class Exists.class FileInfo.class FileOps.class FilterFiles.class Format.class GetDate.class GetDfsPath.class Get.class GetType.class GetURL.class GrowWrite.class HttpURL.class Interleave.class IsDir.class Length.class ListFiles.class List.class ListTypes.class Mkdir.class NodeStatus.class OpenExclusive.class PeekNamedPipe.class PipeTalk.class Put.class Query.class RenameTo.class SetAttrs.class SetTime.class SlowRead.class SlowWrite.class SmbCrawler.class SmbShell.class SmbTableFile.class SmbTableFileRecord.class T2Crawler.class TestRandomAccess.class TestSmbURL.class TestUnicode.class ThreadedNbtQuery.class ThreadedSmbCrawler.class ThreadedUniQuery.class Torture1.class Torture2.class TortureTest5.class TransactNamedPipe.class URLTest.class VerifyGuest.class VerifyIO.class VerifyReads.class
+CLASSFILES=GetGroupMemberSidsFromURL.class ListACL.class LargeListFiles.class GetShareSecurity.class CountPerms.class AclCrawler.class SidCacheTest.class GetSecurity.class SidCrawler.class InterruptTest.class AllocInfo.class Append.class AuthListFiles.class CallNamedPipe.class CopyTo.class CreateFile.class Delete.class Equals.class Exists.class FileInfo.class FileOps.class FilterFiles.class Format.class GetDate.class GetDfsPath.class Get.class GetType.class GetURL.class GrowWrite.class HttpURL.class Interleave.class IsDir.class Length.class ListFiles.class List.class ListTypes.class Mkdir.class NodeStatus.class OpenExclusive.class PeekNamedPipe.class PipeTalk.class Put.class Query.class RenameTo.class SetAttrs.class SetTime.class SlowRead.class SlowWrite.class SmbCrawler.class SmbShell.class SmbTableFile.class SmbTableFileRecord.class T2Crawler.class TestRandomAccess.class TestSmbURL.class TestUnicode.class ThreadedNbtQuery.class ThreadedSmbCrawler.class ThreadedUniQuery.class Torture1.class Torture2.class TortureTest5.class TransactNamedPipe.class URLTest.class VerifyGuest.class VerifyIO.class VerifyReads.class
all: ${CLASSFILES}
SID sid = new SID(argv[0]);
sid.resolve("ts0", null);
System.out.println(" toString: " + sid.toString());
- System.out.println(" toSidString: " + sid.toSidString());
+ System.out.println(" toSidString: " + sid.toDisplayString());
System.out.println(" getType: " + sid.getType());
System.out.println(" getTypeText: " + sid.getTypeText());
System.out.println(" getDomainName: " + sid.getDomainName());
JAVA_HOME=/usr/local/java
CLASSPATH=../build:.
-PROPERTIES=../../miallen.prp
+PROPERTIES=../../user10.prp
RUN="${JAVA_HOME}/bin/java -cp ${CLASSPATH} -Djcifs.properties=${PROPERTIES}"
-SERVER=ts0
+SERVER=dc1.w.net
SHARE=tmp
WRITE_DIR=test/
SRC_DIR=test/Junk
FILE1=test/Junk/10883563.doc
-URL_SHARE=smb://${SERVER}/${SHARE}/
+URL_SERVER=smb://${SERVER}/
+URL_SHARE=${URL_SERVER}${SHARE}/
URL_WRITE_DIR=${URL_SHARE}${WRITE_DIR}
+[ "$1" = "ListACL" ] && $RUN ListACL ${URL_WRITE_DIR}
+[ "$1" = "LargeListFiles" ] && $RUN LargeListFiles ${URL_WRITE_DIR}
+[ "$1" = "CountPerms" ] && $RUN CountPerms ${URL_WRITE_DIR} 100
+[ "$1" = "AclCrawler" ] && $RUN AclCrawler ${URL_WRITE_DIR} 100
[ "$1" = "SidCacheTest" ] && $RUN SidCacheTest ${URL_WRITE_DIR}
[ "$1" = "GetSecurity" ] && $RUN GetSecurity ${URL_WRITE_DIR}
+[ "$1" = "GetSecurityS" ] && $RUN GetSecurity ${URL_SHARE}
+[ "$1" = "GetShareSecurity" ] && $RUN GetShareSecurity ${URL_WRITE_DIR}
[ "$1" = "SidCrawler" ] && $RUN SidCrawler ${URL_WRITE_DIR} 5
+[ "$1" = "GetGroupMemberSidsFromURL" ] && $RUN GetGroupMemberSidsFromURL ${URL_WRITE_DIR}
[ "$1" = "InterruptTest" ] && $RUN InterruptTest ${URL_WRITE_DIR}Append.txt
[ "$1" = "AllocInfo" ] && $RUN AllocInfo ${URL_SHARE}
[ "$1" = "Append" ] && $RUN Append ${URL_WRITE_DIR}Append.txt
[ "$1" = "IsDir" ] && $RUN IsDir ${URL_SHARE}${SRC_DIR}/
[ "$1" = "Length" ] && $RUN Length ${URL_SHARE}${FILE1}
[ "$1" = "ListFiles" ] && $RUN ListFiles ${URL_WRITE_DIR}
+[ "$1" = "ListShares" ] && $RUN ListFiles ${URL_SERVER}
[ "$1" = "List" ] && $RUN List ${URL_WRITE_DIR}
[ "$1" = "ListTypes" ] && $RUN ListTypes ${URL_WRITE_DIR}
[ "$1" = "Mkdir" ] && $RUN Mkdir ${URL_WRITE_DIR}Mkdir
JAVA_HOME=/usr/local/java
CLASSPATH=../build:.
-PROPERTIES=../../miallen.prp
+PROPERTIES=../../user10.prp
RUN="${JAVA_HOME}/bin/java -cp ${CLASSPATH} -Djcifs.properties=${PROPERTIES}"
-SERVER=ts0
+SERVER=dc1.w.net
SHARE=tmp
WRITE_DIR=test/
SRC_DIR=test/Junk
FILE1=test/Junk/10883563.doc
-URL_SHARE=smb://${SERVER}/${SHARE}/
+URL_SERVER=smb://${SERVER}/
+URL_SHARE=${URL_SERVER}${SHARE}/
URL_WRITE_DIR=${URL_SHARE}${WRITE_DIR}
set -x
+$RUN ListACL ${URL_WRITE_DIR}
+$RUN LargeListFiles ${URL_WRITE_DIR}
+$RUN CountPerms ${URL_WRITE_DIR} 100
+$RUN AclCrawler ${URL_WRITE_DIR} 100
$RUN SidCacheTest ${URL_WRITE_DIR}
$RUN GetSecurity ${URL_WRITE_DIR}
+$RUN GetSecurity ${URL_SHARE}
+$RUN GetShareSecurity ${URL_WRITE_DIR}
$RUN SidCrawler ${URL_WRITE_DIR} 5
+$RUN GetGroupMemberSidsFromURL ${URL_WRITE_DIR}
$RUN InterruptTest ${URL_WRITE_DIR}Append.txt
$RUN AllocInfo ${URL_SHARE}
$RUN Append ${URL_WRITE_DIR}Append.txt
$RUN IsDir ${URL_SHARE}${SRC_DIR}/
$RUN Length ${URL_SHARE}${FILE1}
$RUN ListFiles ${URL_WRITE_DIR}
+$RUN ListFiles ${URL_SERVER}
$RUN List ${URL_WRITE_DIR}
$RUN ListTypes ${URL_WRITE_DIR}
$RUN Mkdir ${URL_WRITE_DIR}Mkdir
public static UniAddress getByName( String hostname,
boolean possibleNTDomainOrWorkgroup )
throws UnknownHostException {
+ UniAddress[] addrs = UniAddress.getAllByName(hostname, possibleNTDomainOrWorkgroup);
+ return addrs[0];
+ }
+ public static UniAddress[] getAllByName( String hostname,
+ boolean possibleNTDomainOrWorkgroup )
+ throws UnknownHostException {
Object addr;
int i;
}
if( isDotQuadIP( hostname )) {
- return new UniAddress( NbtAddress.getByName( hostname ));
+ UniAddress[] addrs = new UniAddress[1];
+ addrs[0] = new UniAddress( NbtAddress.getByName( hostname ));
+ return addrs;
}
for( i = 0; i < resolveOrder.length; i++ ) {
if( isAllDigits( hostname )) {
throw new UnknownHostException( hostname );
}
- addr = InetAddress.getByName( hostname );
- break;
+ InetAddress[] iaddrs = InetAddress.getAllByName( hostname );
+ UniAddress[] addrs = new UniAddress[iaddrs.length];
+ for (int ii = 0; ii < iaddrs.length; ii++) {
+ addrs[ii] = new UniAddress(iaddrs[ii]);
+ }
+ return addrs; // Success
default:
throw new UnknownHostException( hostname );
}
- return new UniAddress( addr ); // Success
+ UniAddress[] addrs = new UniAddress[1];
+ addrs[0] = new UniAddress( addr );
+ return addrs; // Success
} catch( IOException ioe ) {
// Failure
}
protected int max_xmit = 4280;
protected int max_recv = max_xmit;
protected int state = 0;
- private static int call_id = 0;
+ private static int call_id = 1;
public static DcerpcHandle getHandle(String url,
NtlmPasswordAuthentication auth)
public void sendrecv(DcerpcMessage msg) throws DcerpcException, IOException {
byte[] stub, frag;
NdrBuffer buf, fbuf;
- boolean isLast;
+ boolean isLast, isDirect;
DcerpcException de;
if (state == 0) {
sendrecv(bind);
}
+ isDirect = msg instanceof DcerpcBind;
+
stub = jcifs.smb.BufferCache.getBuffer();
try {
int off, tot, n;
n = tot - off;
}
- doSendFragment(stub, off, n);
+ doSendFragment(stub, off, n, isDirect);
off += n;
}
- doReceiveFragment(stub);
+ doReceiveFragment(stub, isDirect);
buf.reset();
msg.decode_header(buf);
fbuf = new NdrBuffer(frag, 0);
}
- doReceiveFragment(frag);
+ doReceiveFragment(frag, isDirect);
fbuf.reset();
msg.decode_header(fbuf);
stub_frag_len = msg.length - 24;
return binding.toString();
}
- protected abstract void doSendFragment(byte[] buf, int off, int length) throws IOException;
- protected abstract void doReceiveFragment(byte[] buf) throws IOException;
+ protected abstract void doSendFragment(byte[] buf,
+ int off,
+ int length,
+ boolean isDirect) throws IOException;
+ protected abstract void doReceiveFragment(byte[] buf, boolean isDirect) throws IOException;
public abstract void close() throws IOException;
}
public class DcerpcPipeHandle extends DcerpcHandle {
SmbNamedPipe pipe;
- SmbFileInputStream in;
- OutputStream out = null;
+ SmbFileInputStream in = null;
+ SmbFileOutputStream out = null;
boolean isStart = true;
public DcerpcPipeHandle(String url,
auth);
}
- protected void doSendFragment(byte[] buf, int off, int length) throws IOException {
- in = (SmbFileInputStream)pipe.getNamedPipeInputStream();
- out = pipe.getNamedPipeOutputStream();
+ protected void doSendFragment(byte[] buf,
+ int off,
+ int length,
+ boolean isDirect) throws IOException {
+ if (in == null)
+ in = (SmbFileInputStream)pipe.getNamedPipeInputStream();
+ if (out == null)
+ out = (SmbFileOutputStream)pipe.getNamedPipeOutputStream();
+ if (isDirect) {
+ out.writeDirect( buf, off, length, 1 );
+ return;
+ }
out.write(buf, off, length);
}
- protected void doReceiveFragment(byte[] buf) throws IOException {
+ protected void doReceiveFragment(byte[] buf, boolean isDirect) throws IOException {
int off, flags, length;
if (buf.length < max_recv)
throw new IllegalArgumentException("buffer too small");
- if (isStart) { // start of new frag, do trans
+ if (isStart && !isDirect) { // start of new frag, do trans
off = in.read(buf, 0, 1024);
} else {
off = in.readDirect(buf, 0, buf.length);
public MsrpcLsarOpenPolicy2(String server, int access, LsaPolicyHandle policyHandle) {
super(server, new lsarpc.LsarObjectAttributes(), access, policyHandle);
object_attributes.length = 24;
+lsarpc.LsarQosInfo qos = new lsarpc.LsarQosInfo();
+qos.length = 12;
+qos.impersonation_level = 2;
+qos.context_mode = 1;
+qos.effective_only = 0;
+object_attributes.security_quality_of_service = qos;
ptype = 0;
flags = DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG;
}
--- /dev/null
+/* jcifs msrpc client library in Java
+ * Copyright (C) 2007 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package jcifs.dcerpc.msrpc;
+
+public class MsrpcSamrConnect2 extends samr.SamrConnect2 {
+
+ public MsrpcSamrConnect2(String server, int access, SamrPolicyHandle policyHandle) {
+ super(server, access, policyHandle);
+ ptype = 0;
+ flags = DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG;
+ }
+}
public class MsrpcShareEnum extends srvsvc.ShareEnumAll {
- class MsrpcShareInfo1 implements FileEntry {
-
- String netname;
- int type;
- String remark;
+ class MsrpcShareInfo1 extends SmbShareInfo {
MsrpcShareInfo1(srvsvc.ShareInfo1 info1) {
- this.netname = info1.netname;
+ this.netName = info1.netname;
this.type = info1.type;
this.remark = info1.remark;
}
-
- public String getName() {
- return netname;
- }
- public int getType() {
- /* 0x80000000 means hidden but SmbFile.isHidden() checks for $ at end
- */
- switch(type & 0xFFFF) {
- case 1:
- return SmbFile.TYPE_PRINTER;
- case 3:
- return SmbFile.TYPE_NAMED_PIPE;
- }
- return SmbFile.TYPE_SHARE;
- }
- public int getAttributes() {
- return SmbFile.ATTR_READONLY | SmbFile.ATTR_DIRECTORY;
- }
- public long createTime() {
- return 0L;
- }
- public long lastModified() {
- return 0L;
- }
- public long length() {
- return 0L;
- }
-
- public String toString() {
- return new String( "MsrpcShareInfo1[" +
- "netName=" + netname +
- ",type=0x" + Hexdump.toHexString( type, 8 ) +
- ",remark=" + remark + "]" );
- }
}
public MsrpcShareEnum(String server) {
if (server == null)
server = "\\\\";
MsrpcSamrConnect4 rpc = new MsrpcSamrConnect4(server, access, this);
- handle.sendrecv(rpc);
+ try {
+ handle.sendrecv(rpc);
+ } catch (DcerpcException de) {
+ if (de.getErrorCode() != DcerpcError.DCERPC_FAULT_OP_RNG_ERROR)
+ throw de;
+
+ MsrpcSamrConnect2 rpc2 = new MsrpcSamrConnect2(server, access, this);
+ handle.sendrecv(rpc2);
+ }
}
public void close() throws IOException {
[op(0x01)]
int SamrCloseHandle([in] policy_handle *handle);
+ [op(0x39)]
+ int SamrConnect2([in,string,unique] wchar_t *system_name,
+ [in] uint32_t access_mask,
+ [out] policy_handle *handle);
+
[op(0x3e)]
int SamrConnect4([in,string,unique] wchar_t *system_name,
[in] uint32_t unknown,
retval = (int)_src.dec_ndr_long();
}
}
+ public static class SamrConnect2 extends DcerpcMessage {
+
+ public int getOpnum() { return 0x39; }
+
+ public int retval;
+ public String system_name;
+ public int access_mask;
+ public rpc.policy_handle handle;
+
+ public SamrConnect2(String system_name, int access_mask, rpc.policy_handle handle) {
+ this.system_name = system_name;
+ this.access_mask = access_mask;
+ this.handle = handle;
+ }
+
+ public void encode_in(NdrBuffer _dst) throws NdrException {
+ _dst.enc_ndr_referent(system_name, 1);
+ if (system_name != null) {
+ _dst.enc_ndr_string(system_name);
+
+ }
+ _dst.enc_ndr_long(access_mask);
+ }
+ public void decode_out(NdrBuffer _src) throws NdrException {
+ handle.decode(_src);
+ retval = (int)_src.dec_ndr_long();
+ }
+ }
public static class SamrConnect4 extends DcerpcMessage {
public int getOpnum() { return 0x3e; }
dst[start + ANDX_COMMAND_OFFSET] = (byte)0xFF;
dst[start + ANDX_RESERVED_OFFSET] = (byte)0x00;
- dst[start + ANDX_OFFSET_OFFSET] = (byte)0x00;
- dst[start + ANDX_OFFSET_OFFSET + 1] = (byte)0x00;
+// dst[start + ANDX_OFFSET_OFFSET] = (byte)0x00;
+// dst[start + ANDX_OFFSET_OFFSET + 1] = (byte)0x00;
+ dst[start + ANDX_OFFSET_OFFSET] = (byte)0xde;
+ dst[start + ANDX_OFFSET_OFFSET + 1] = (byte)0xde;
// andx not used; return
return dstIndex - start;
int start = bufferIndex;
wordCount = buffer[bufferIndex++];
+if (command == SMB_COM_NT_CREATE_ANDX)
+ wordCount = 42;
if( wordCount != 0 ) {
/*
if( wordCount > 2 ) {
bufferIndex += readParameterWordsWireFormat( buffer, bufferIndex );
+/* required for signing verification
+ */
+if (command == SMB_COM_NT_CREATE_ANDX) {
+ if (((SmbComNTCreateAndXResponse)this).isExtended)
+ bufferIndex += 32;
+}
}
}
class NetShareEnumResponse extends SmbComTransactionResponse {
- class ShareInfo1 implements FileEntry {
- String netName;
- int type;
- String remark;
-
- public String getName() {
- return netName;
- }
- public int getType() {
- switch( type ) {
- case 1:
- return SmbFile.TYPE_PRINTER;
- case 3:
- return SmbFile.TYPE_NAMED_PIPE;
- }
- return SmbFile.TYPE_SHARE;
- }
- public int getAttributes() {
- return SmbFile.ATTR_READONLY | SmbFile.ATTR_DIRECTORY;
- }
- public long createTime() {
- return 0L;
- }
- public long lastModified() {
- return 0L;
- }
- public long length() {
- return 0L;
- }
-
- public String toString() {
- return new String( "ShareInfo1[" +
- "netName=" + netName +
- ",type=0x" + Hexdump.toHexString( type, 4 ) +
- ",remark=" + remark + "]" );
- }
- }
-
private int converter, totalAvailableEntries;
NetShareEnumResponse() {
}
int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
int start = bufferIndex;
- ShareInfo1 e;
+ SmbShareInfo e;
useUnicode = false;
- results = new ShareInfo1[numEntries];
+ results = new SmbShareInfo[numEntries];
for( int i = 0; i < numEntries; i++ ) {
- results[i] = e = new ShareInfo1();
+ results[i] = e = new SmbShareInfo();
e.netName = readString( buffer, bufferIndex, 13, false );
bufferIndex += 14;
e.type = readInt2( buffer, bufferIndex );
public static final int NT_STATUS_INVALID_PARAMETER = 0xC000000d;
public static final int NT_STATUS_NO_SUCH_DEVICE = 0xC000000e;
public static final int NT_STATUS_NO_SUCH_FILE = 0xC000000f;
+ public static final int NT_STATUS_MORE_PROCESSING_REQUIRED = 0xC0000016;
public static final int NT_STATUS_ACCESS_DENIED = 0xC0000022;
public static final int NT_STATUS_BUFFER_TOO_SMALL = 0xC0000023;
public static final int NT_STATUS_OBJECT_NAME_INVALID = 0xC0000033;
public static final int NT_STATUS_OBJECT_NAME_NOT_FOUND = 0xC0000034;
public static final int NT_STATUS_OBJECT_NAME_COLLISION = 0xC0000035;
public static final int NT_STATUS_PORT_DISCONNECTED = 0xC0000037;
+ public static final int NT_STATUS_OBJECT_PATH_INVALID = 0xC0000039;
public static final int NT_STATUS_OBJECT_PATH_NOT_FOUND = 0xC000003a;
public static final int NT_STATUS_OBJECT_PATH_SYNTAX_BAD = 0xC000003b;
public static final int NT_STATUS_SHARING_VIOLATION = 0xC0000043;
public static final int NT_STATUS_DELETE_PENDING = 0xC0000056;
public static final int NT_STATUS_NO_LOGON_SERVERS = 0xC000005e;
+ public static final int NT_STATUS_USER_EXISTS = 0xC0000063;
public static final int NT_STATUS_NO_SUCH_USER = 0xC0000064;
public static final int NT_STATUS_WRONG_PASSWORD = 0xC000006a;
public static final int NT_STATUS_LOGON_FAILURE = 0xC000006d;
public static final int NT_STATUS_NOT_A_DIRECTORY = 0xC0000103;
public static final int NT_STATUS_CANNOT_DELETE = 0xC0000121;
public static final int NT_STATUS_PIPE_BROKEN = 0xC000014b;
+ public static final int NT_STATUS_NO_SUCH_ALIAS = 0xC0000151;
public static final int NT_STATUS_LOGON_TYPE_NOT_GRANTED = 0xC000015b;
public static final int NT_STATUS_TRUSTED_DOMAIN_FAILURE = 0xC000018c;
public static final int NT_STATUS_PASSWORD_MUST_CHANGE = 0xC0000224;
NT_STATUS_INVALID_PARAMETER,
NT_STATUS_NO_SUCH_DEVICE,
NT_STATUS_NO_SUCH_FILE,
+ NT_STATUS_MORE_PROCESSING_REQUIRED,
NT_STATUS_ACCESS_DENIED,
NT_STATUS_BUFFER_TOO_SMALL,
NT_STATUS_OBJECT_NAME_INVALID,
NT_STATUS_OBJECT_NAME_NOT_FOUND,
NT_STATUS_OBJECT_NAME_COLLISION,
NT_STATUS_PORT_DISCONNECTED,
+ NT_STATUS_OBJECT_PATH_INVALID,
NT_STATUS_OBJECT_PATH_NOT_FOUND,
NT_STATUS_OBJECT_PATH_SYNTAX_BAD,
NT_STATUS_SHARING_VIOLATION,
NT_STATUS_DELETE_PENDING,
NT_STATUS_NO_LOGON_SERVERS,
+ NT_STATUS_USER_EXISTS,
NT_STATUS_NO_SUCH_USER,
NT_STATUS_WRONG_PASSWORD,
NT_STATUS_LOGON_FAILURE,
NT_STATUS_NOT_A_DIRECTORY,
NT_STATUS_CANNOT_DELETE,
NT_STATUS_PIPE_BROKEN,
+ NT_STATUS_NO_SUCH_ALIAS,
NT_STATUS_LOGON_TYPE_NOT_GRANTED,
NT_STATUS_TRUSTED_DOMAIN_FAILURE,
NT_STATUS_PASSWORD_MUST_CHANGE,
"The parameter is incorrect.",
"The system cannot find the file specified.",
"The system cannot find the file specified.",
+ "More data is available.",
"Access is denied.",
"The data area passed to a system call is too small.",
"The filename, directory name, or volume label syntax is incorrect.",
"The system cannot find the file specified.",
"Cannot create a file when that file already exists.",
"The handle is invalid.",
+ "The specified path is invalid.",
"The system cannot find the path specified.",
"The specified path is invalid.",
"The process cannot access the file because it is being used by another process.",
"Access is denied.",
"There are currently no logon servers available to service the logon request.",
+ "The specified user already exists.",
"The specified user does not exist.",
"The specified network password is not correct.",
"Logon failure: unknown user name or bad password.",
"The directory name is invalid.",
"Access is denied.",
"The pipe has been ended.",
+ "The specified local group does not exist.",
"Logon failure: the user has not been granted the requested logon type at this computer.",
"The trust relationship between the primary domain and the trusted domain failed.",
"The user must change his password before he logs on the first time.",
import java.util.Random;
import java.util.Arrays;
import jcifs.Config;
-import jcifs.util.LogStream;
-import jcifs.util.DES;
-import jcifs.util.MD4;
-import jcifs.util.HMACT64;
+import jcifs.util.*;
/**
* This class stores and encrypts NTLM user credentials. The default
public static final int SID_FLAG_RESOLVE_SIDS = 0x0001;
+ public static SID EVERYONE = null;
+ public static SID CREATOR_OWNER = null;
+ public static SID SYSTEM = null;
+
+ static {
+ try {
+ EVERYONE = new SID("S-1-1-0");
+ CREATOR_OWNER = new SID("S-1-3-0");
+ SYSTEM = new SID("S-1-5-18");
+ } catch (SmbException se) {
+ }
+ }
+
static Map sid_cache = Collections.synchronizedMap(new HashMap());
static void resolveSids(DcerpcHandle handle,
try {
handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName +
"[\\PIPE\\lsarpc]", auth);
- policyHandle = new LsaPolicyHandle(handle, null, 0x00000800);
+ String server = authorityServerName;
+ int dot = server.indexOf('.');
+ if (dot > 0 && Character.isDigit(server.charAt(0)) == false)
+ server = server.substring(0, dot);
+ policyHandle = new LsaPolicyHandle(handle, "\\\\" + server, 0x00000800);
SID.resolveSids(handle, policyHandle, sids);
} finally {
if (handle != null) {
MsrpcGetMembersInAlias rpc = null;
try {
- aliasHandle = new SamrAliasHandle(handle, domainHandle, 0x02000000, rid);
+ aliasHandle = new SamrAliasHandle(handle, domainHandle, 0x0002000c, rid);
rpc = new MsrpcGetMembersInAlias(aliasHandle, sidarray);
handle.sendrecv(rpc);
if (rpc.retval != 0)
public SID[] getGroupMemberSids(String authorityServerName,
NtlmPasswordAuthentication auth,
int flags) throws IOException {
+ if (type != SID_TYPE_DOM_GRP && type != SID_TYPE_ALIAS)
+ return new SID[0];
+
DcerpcHandle handle = null;
SamrPolicyHandle policyHandle = null;
SamrDomainHandle domainHandle = null;
try {
handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName +
"[\\PIPE\\samr]", auth);
- policyHandle = new SamrPolicyHandle(handle, authorityServerName, 0x02000000);
- domainHandle = new SamrDomainHandle(handle, policyHandle, 0x02000000, domsid);
+ policyHandle = new SamrPolicyHandle(handle, authorityServerName, 0x00000030);
+ domainHandle = new SamrDomainHandle(handle, policyHandle, 0x00000200, domsid);
return SID.getGroupMemberSids0(handle,
domainHandle,
domsid,
flags2 = 0;
errorCode = 0;
received = false;
+ digest = null;
}
int writeString( String str, byte[] dst, int dstIndex ) {
return writeString( str, dst, dstIndex, useUnicode );
} catch( Exception ex ) {
throw new SmbException( "", ex );
}
- if( log.level >= 4 ) {
+ if( log.level >= 5 ) {
log.println( "LM_COMPATIBILITY=" + LM_COMPATIBILITY );
Hexdump.hexdump( log, macSigningKey, 0, macSigningKey.length );
}
}
public void update( byte[] input, int offset, int len ) {
- if( log.level >= 4 ) {
+ if( log.level >= 5 ) {
log.println( "update: " + updates + " " + offset + ":" + len );
Hexdump.hexdump( log, input, offset, Math.min( len, 256 ));
log.flush();
b = digest.digest();
- if( log.level >= 4 ) {
+ if( log.level >= 5 ) {
log.println( "digest: " );
Hexdump.hexdump( log, b, 0, b.length );
log.flush();
return response.verifyFailed = false;
}
+ public String toString() {
+ return "LM_COMPATIBILITY=" + LM_COMPATIBILITY + " MacSigningKey=" + Hexdump.toHexString(macSigningKey, 0, macSigningKey.length);
+ }
}
static final int SECURITY_CONTEXT_TRACKING = 0x01;
static final int SECURITY_EFFECTIVE_ONLY = 0x02;
- private int flags,
- rootDirectoryFid,
- desiredAccess,
+ private int rootDirectoryFid,
extFileAttributes,
shareAccess,
createDisposition,
private byte securityFlags;
private int namelen_index;
+int flags0, desiredAccess;
+
SmbComNTCreateAndX( String name, int flags,
int access,
int shareAccess,
// name length without counting null termination
namelen_index = dstIndex;
dstIndex += 2;
- writeInt4( flags, dst, dstIndex );
+ writeInt4( flags0, dst, dstIndex );
dstIndex += 4;
writeInt4( rootDirectoryFid, dst, dstIndex );
dstIndex += 4;
public String toString() {
return new String( "SmbComNTCreateAndX[" +
super.toString() +
- ",flags=0x" + Hexdump.toHexString( flags, 2 ) +
+ ",flags=0x" + Hexdump.toHexString( flags0, 2 ) +
",rootDirectoryFid=" + rootDirectoryFid +
",desiredAccess=0x" + Hexdump.toHexString( desiredAccess, 4 ) +
",allocationSize=" + allocationSize +
allocationSize,
endOfFile;
boolean directory;
+boolean isExtended;
SmbComNTCreateAndXResponse() {
}
private long offset;
private int fid,
- maxCount,
- minCount,
- openTimeout,
- remaining;
+ openTimeout;
+int maxCount, minCount, remaining;
SmbComReadAndX() {
super( null );
}
writeInt2( parameterCount, dst, dstIndex );
dstIndex += 2;
- writeInt2(( parameterCount == 0 ? 0 : parameterOffset ), dst, dstIndex );
+// writeInt2(( parameterCount == 0 ? 0 : parameterOffset ), dst, dstIndex );
+ writeInt2(parameterOffset, dst, dstIndex );
dstIndex += 2;
if( command == SMB_COM_TRANSACTION_SECONDARY ) {
writeInt2( parameterDisplacement, dst, dstIndex );
package jcifs.smb;
import jcifs.Config;
+import jcifs.util.*;
class SmbComWriteAndX extends AndXServerMessageBlock {
Config.getInt( "jcifs.smb.client.WriteAndX.Close", 1 );
private int fid,
- writeMode,
remaining,
dataLength,
dataOffset,
private byte[] b;
private long offset;
+private int pad;
+
+ int writeMode;
+
SmbComWriteAndX() {
super( null );
command = SMB_COM_WRITE_ANDX;
int start = dstIndex;
dataOffset = (dstIndex - headerStart) + 26; // 26 = off from here to pad
-/*
- * pad = ( dataOffset - headerStart ) % 4;
- * pad = pad == 0 ? 0 : 4 - pad;
- * dataOffset += pad;
- */
+
+pad = ( dataOffset - headerStart ) % 4;
+pad = pad == 0 ? 0 : 4 - pad;
+dataOffset += pad;
writeInt2( fid, dst, dstIndex );
dstIndex += 2;
writeInt4( offset, dst, dstIndex );
dstIndex += 4;
for( int i = 0; i < 4; i++ ) {
- dst[dstIndex++] = (byte)0x00;
+ dst[dstIndex++] = (byte)0xFF;
}
writeInt2( writeMode, dst, dstIndex );
dstIndex += 2;
int writeBytesWireFormat( byte[] dst, int dstIndex ) {
int start = dstIndex;
-/* Netware doesn't like this
- * while( pad-- > 0 ) {
- * dst[dstIndex++] = (byte)0x00;
- * }
- */
+while( pad-- > 0 ) {
+ dst[dstIndex++] = (byte)0xEE;
+}
System.arraycopy( b, off, dst, dstIndex, dataLength );
dstIndex += dataLength;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.security.Principal;
import jcifs.Config;
import jcifs.util.LogStream;
return null;
}
+UniAddress[] addresses;
+int addressIndex;
+
UniAddress getAddress() throws UnknownHostException {
+ if (addressIndex == 0)
+ return getFirstAddress();
+ return addresses[addressIndex - 1];
+ }
+ UniAddress getFirstAddress() throws UnknownHostException {
+ addressIndex = 0;
+
String host = url.getHost();
String path = url.getPath();
String query = url.getQuery();
if( query != null ) {
String server = queryLookup( query, "server" );
if( server != null && server.length() > 0 ) {
- return UniAddress.getByName( server );
+ addresses = new UniAddress[1];
+ addresses[0] = UniAddress.getByName( server );
+ return getNextAddress();
}
}
- if( host.length() == 0 ) {
+ if (host.length() == 0) {
try {
NbtAddress addr = NbtAddress.getByName(
NbtAddress.MASTER_BROWSER_NAME, 0x01, null);
- return UniAddress.getByName( addr.getHostAddress() );
+ addresses = new UniAddress[1];
+ addresses[0] = UniAddress.getByName( addr.getHostAddress() );
} catch( UnknownHostException uhe ) {
NtlmPasswordAuthentication.initDefaults();
if( NtlmPasswordAuthentication.DEFAULT_DOMAIN.equals( "?" )) {
throw uhe;
}
- return UniAddress.getByName( NtlmPasswordAuthentication.DEFAULT_DOMAIN, true );
+ addresses = UniAddress.getAllByName( NtlmPasswordAuthentication.DEFAULT_DOMAIN, true );
}
} else if( path.length() == 0 || path.equals( "/" )) {
- return UniAddress.getByName( host, true );
+ addresses = UniAddress.getAllByName( host, true );
} else {
- return UniAddress.getByName( host );
+ addresses = UniAddress.getAllByName(host, false);
}
+
+ return getNextAddress();
+ }
+ UniAddress getNextAddress() {
+ UniAddress addr = null;
+ if (addressIndex < addresses.length)
+ addr = addresses[addressIndex++];
+ return addr;
+ }
+ boolean hasNextAddress() {
+ return addressIndex < addresses.length;
}
void connect0() throws SmbException {
try {
throw new SmbException( "Failed to connect to server", ioe );
}
}
+ void doConnect() throws IOException {
+ SmbTransport trans;
+ SmbSession ssn;
+ UniAddress addr;
+
+ addr = getAddress();
+ trans = SmbTransport.getSmbTransport(addr, url.getPort());
+ ssn = trans.getSmbSession(auth);
+ tree = ssn.getSmbTree(share, null);
+
+ try {
+ if( log.level >= 3 )
+ log.println( "doConnect: " + addr );
+
+ tree.treeConnect(null, null);
+ } catch (SmbAuthException sae) {
+ NtlmPasswordAuthentication a;
+
+ if (share == null) { // IPC$ - try "anonymous" credentials
+ ssn = trans.getSmbSession(NtlmPasswordAuthentication.NULL);
+ tree = ssn.getSmbTree(null, null);
+ tree.treeConnect(null, null);
+ } else if ((a = NtlmAuthenticator.requestNtlmPasswordAuthentication(
+ url.toString(), sae)) != null) {
+ auth = a;
+ ssn = trans.getSmbSession(auth);
+ tree = ssn.getSmbTree(share, null);
+ tree.treeConnect(null, null);
+ } else {
+ if (log.level >= 1 && hasNextAddress())
+ sae.printStackTrace(log);
+ throw sae;
+ }
+ }
+ }
/**
* It is not necessary to call this method directly. This is the
* <tt>URLConnection</tt> implementation of <tt>connect()</tt>.
}
getUncPath0();
- addr = getAddress();
-
- trans = SmbTransport.getSmbTransport( addr, url.getPort() );
- ssn = trans.getSmbSession( auth );
- tree = ssn.getSmbTree( share, null );
-
- try {
- tree.treeConnect( null, null );
- } catch( SmbAuthException sae ) {
- NtlmPasswordAuthentication a;
-
- if( share == null ) { // IPC$ - try "anonymous" credentials
- ssn = trans.getSmbSession( NtlmPasswordAuthentication.NULL );
- tree = ssn.getSmbTree( null, null );
- tree.treeConnect( null, null );
- } else if(( a = NtlmAuthenticator.requestNtlmPasswordAuthentication(
- url.toString(), sae )) != null ) {
- auth = a;
- ssn = trans.getSmbSession( auth );
- tree = ssn.getSmbTree( share, null );
- tree.treeConnect( null, null );
- } else {
- throw sae;
+ getFirstAddress();
+ for ( ;; ) {
+ try {
+ doConnect();
+ return;
+ } catch(SmbException se) {
+ if (getNextAddress() == null)
+ throw se;
+ if (log.level >= 3)
+ se.printStackTrace(log);
}
}
}
boolean isConnected() {
- return (connected = tree != null && tree.treeConnected);
+ return tree != null && tree.treeConnected;
}
int open0( int flags, int access, int attrs, int options ) throws SmbException {
int f;
if( tree.session.transport.hasCapability( ServerMessageBlock.CAP_NT_SMBS )) {
SmbComNTCreateAndXResponse response = new SmbComNTCreateAndXResponse();
- send( new SmbComNTCreateAndX( unc, flags, access, shareAccess,
- attrs, options, null ), response );
+SmbComNTCreateAndX request = new SmbComNTCreateAndX( unc, flags, access, shareAccess, attrs, options, null );
+if (this instanceof SmbNamedPipe) {
+ request.flags0 |= 0x16;
+ request.desiredAccess |= 0x20000;
+ response.isExtended = true;
+}
+try {
+ send( request, response );
+} catch( Exception e) {
+ e.printStackTrace();
+}
f = response.fid;
attributes = response.extFileAttributes & ATTR_GET_MASK;
attrExpiration = System.currentTimeMillis() + attrExpirationPeriod;
tree_num = tree.tree_num;
}
boolean isOpen() {
- return opened && isConnected() && tree_num == tree.tree_num;
+ boolean ans = opened && isConnected() && tree_num == tree.tree_num;
+ return ans;
}
void close( int f, long lastWriteTime ) throws SmbException {
} else {
type = TYPE_SHARE;
}
- } else if( url.getAuthority().length() == 0 ) {
+ } else if( url.getAuthority() == null || url.getAuthority().length() == 0 ) {
type = TYPE_WORKGROUP;
} else {
UniAddress addr;
String[] list( String wildcard, int searchAttributes,
SmbFilenameFilter fnf, SmbFileFilter ff ) throws SmbException {
ArrayList list = new ArrayList();
-
- try {
- int hostlen = url.getHost().length();
- if( hostlen == 0 || share == null ) {
- boolean done = false;
- if (hostlen != 0 && getType() == TYPE_SERVER) {
- try {
- doMsrpcEnum(list, false, wildcard, searchAttributes, fnf, ff);
- done = true;
- } catch(IOException ioe) {
- if (log.level >= 3)
- ioe.printStackTrace(log);
- }
- }
- if (!done)
- doNetEnum( list, false, wildcard, searchAttributes, fnf, ff );
- } else {
- doFindFirstNext( list, false, wildcard, searchAttributes, fnf, ff );
- }
- } catch( UnknownHostException uhe ) {
- throw new SmbException( url.toString(), uhe );
- } catch( MalformedURLException mue ) {
- throw new SmbException( url.toString(), mue );
- }
-
+ doEnum(list, false, wildcard, searchAttributes, fnf, ff);
return (String[])list.toArray(new String[list.size()]);
}
SmbFile[] listFiles( String wildcard, int searchAttributes,
SmbFilenameFilter fnf, SmbFileFilter ff ) throws SmbException {
ArrayList list = new ArrayList();
-
- if( ff != null && ff instanceof DosFileFilter ) {
+ doEnum(list, true, wildcard, searchAttributes, fnf, ff);
+ return (SmbFile[])list.toArray(new SmbFile[list.size()]);
+ }
+ void doEnum(ArrayList list,
+ boolean files,
+ String wildcard,
+ int searchAttributes,
+ SmbFilenameFilter fnf,
+ SmbFileFilter ff) throws SmbException {
+ if (ff != null && ff instanceof DosFileFilter) {
DosFileFilter dff = (DosFileFilter)ff;
- if( dff.wildcard != null ) {
+ if (dff.wildcard != null)
wildcard = dff.wildcard;
- }
searchAttributes = dff.attributes;
}
try {
int hostlen = url.getHost().length();
- if( hostlen == 0 || share == null ) {
- boolean done = false;
- if (hostlen != 0 && getType() == TYPE_SERVER) {
- try {
- doMsrpcEnum(list, true, wildcard, searchAttributes, fnf, ff);
- done = true;
- } catch(IOException ioe) {
- if (log.level >= 3)
- ioe.printStackTrace(log);
- }
- }
- if (!done)
- doNetEnum( list, true, wildcard, searchAttributes, fnf, ff );
+ if (hostlen == 0 || getType() == TYPE_WORKGROUP) {
+ doNetServerEnum(list, files, wildcard, searchAttributes, fnf, ff);
+ } else if (share == null) {
+ doShareEnum(list, files, wildcard, searchAttributes, fnf, ff);
} else {
- doFindFirstNext( list, true, wildcard, searchAttributes, fnf, ff );
+ doFindFirstNext(list, files, wildcard, searchAttributes, fnf, ff);
}
- } catch( UnknownHostException uhe ) {
- throw new SmbException( url.toString(), uhe );
- } catch( MalformedURLException mue ) {
- throw new SmbException( url.toString(), mue );
+ } catch (UnknownHostException uhe) {
+ throw new SmbException(url.toString(), uhe);
+ } catch (MalformedURLException mue) {
+ throw new SmbException(url.toString(), mue);
}
-
- return (SmbFile[])list.toArray(new SmbFile[list.size()]);
}
- void doMsrpcEnum( ArrayList list,
+ void doShareEnum(ArrayList list,
boolean files,
String wildcard,
int searchAttributes,
SmbFilenameFilter fnf,
- SmbFileFilter ff ) throws IOException,
- UnknownHostException,
- MalformedURLException {
+ SmbFileFilter ff) throws SmbException,
+ UnknownHostException,
+ MalformedURLException {
String p = url.getPath();
- MsrpcShareEnum rpc;
- DcerpcHandle handle;
+ IOException last = null;
+ FileEntry[] entries;
+ UniAddress addr;
+ FileEntry e;
+ HashMap map;
- if( p.lastIndexOf( '/' ) != ( p.length() - 1 )) {
- throw new SmbException( url.toString() + " directory must end with '/'" );
- }
+ if (p.lastIndexOf('/') != (p.length() - 1))
+ throw new SmbException(url.toString() + " directory must end with '/'");
if (getType() != TYPE_SERVER)
- throw new SmbException( "The requested list operations is invalid: " + url.toString() );
+ throw new SmbException("The requested list operations is invalid: " + url.toString());
+
+ map = new HashMap();
+
+ addr = getFirstAddress();
+ while (addr != null) {
+ try {
+ doConnect();
+ try {
+ entries = doMsrpcShareEnum();
+ } catch(IOException ioe) {
+ if (log.level >= 3)
+ ioe.printStackTrace(log);
+ entries = doNetShareEnum();
+ }
+ for (int ei = 0; ei < entries.length; ei++) {
+ e = entries[ei];
+ if (map.containsKey(e) == false)
+ map.put(e, e);
+ }
+ } catch(IOException ioe) {
+ if (log.level >= 3)
+ ioe.printStackTrace(log);
+ last = ioe;
+ }
+ addr = getNextAddress();
+ }
+
+ if (last != null && map.isEmpty()) {
+ if (last instanceof SmbException == false)
+ throw new SmbException(url.toString(), last);
+ throw (SmbException)last;
+ }
+
+ Iterator iter = map.keySet().iterator();
+ while (iter.hasNext()) {
+ e = (FileEntry)iter.next();
+ String name = e.getName();
+ if (fnf != null && fnf.accept(this, name) == false)
+ continue;
+ if (name.length() > 0) {
+ // if !files we don't need to create SmbFiles here
+ SmbFile f = new SmbFile(this, name, e.getType(),
+ ATTR_READONLY | ATTR_DIRECTORY, 0L, 0L, 0L );
+ if (ff != null && ff.accept(f) == false)
+ continue;
+ if (files) {
+ list.add(f);
+ } else {
+ list.add(name);
+ }
+ }
+ }
+ }
+ FileEntry[] doMsrpcShareEnum() throws IOException {
+ MsrpcShareEnum rpc;
+ DcerpcHandle handle;
rpc = new MsrpcShareEnum(url.getHost());
- handle = DcerpcHandle.getHandle("ncacn_np:" + url.getHost() + "[\\PIPE\\srvsvc]", auth);
+
+ /* JCIFS will build a composite list of shares if the target host has
+ * multiple IP addresses such as when domain-based DFS is in play. Because
+ * of this, to ensure that we query each IP individually without re-resolving
+ * the hostname and getting a different IP, we must use the current addresses
+ * IP rather than just url.getHost() like we were using prior to 1.2.16.
+ */
+
+ handle = DcerpcHandle.getHandle("ncacn_np:" +
+ getAddress().getHostAddress() +
+ "[\\PIPE\\srvsvc]", auth);
try {
handle.sendrecv(rpc);
if (rpc.retval != 0)
throw new SmbException(rpc.retval, true);
- FileEntry[] entries = rpc.getEntries();
- for( int i = 0; i < entries.length; i++ ) {
- FileEntry e = entries[i];
+ return rpc.getEntries();
+ } finally {
+ try {
+ handle.close();
+ } catch(IOException ioe) {
+ if (log.level >= 4)
+ ioe.printStackTrace(log);
+ }
+ }
+ }
+ FileEntry[] doNetShareEnum() throws SmbException {
+ SmbComTransaction req = new NetShareEnum();
+ SmbComTransactionResponse resp = new NetShareEnumResponse();
+
+ send(req, resp);
+
+ if (resp.status != SmbException.ERROR_SUCCESS)
+ throw new SmbException(resp.status, true);
+
+ return resp.results;
+ }
+ void doNetServerEnum(ArrayList list,
+ boolean files,
+ String wildcard,
+ int searchAttributes,
+ SmbFilenameFilter fnf,
+ SmbFileFilter ff) throws SmbException,
+ UnknownHostException,
+ MalformedURLException {
+ int listType = url.getHost().length() == 0 ? 0 : getType();
+ SmbComTransaction req;
+ SmbComTransactionResponse resp;
+
+ if (listType == 0) {
+ connect0();
+ req = new NetServerEnum2(tree.session.transport.server.oemDomainName,
+ NetServerEnum2.SV_TYPE_DOMAIN_ENUM );
+ resp = new NetServerEnum2Response();
+ } else if (listType == TYPE_WORKGROUP) {
+ req = new NetServerEnum2(url.getHost(), NetServerEnum2.SV_TYPE_ALL);
+ resp = new NetServerEnum2Response();
+ } else {
+ throw new SmbException( "The requested list operations is invalid: " + url.toString() );
+ }
+
+ boolean more;
+ do {
+ int n;
+
+ send(req, resp);
+
+ if (resp.status != SmbException.ERROR_SUCCESS &&
+ resp.status != SmbException.ERROR_MORE_DATA) {
+ throw new SmbException( resp.status, true );
+ }
+ more = resp.status == SmbException.ERROR_MORE_DATA;
+
+ n = more ? resp.numEntries - 1 : resp.numEntries;
+ for (int i = 0; i < n; i++) {
+ FileEntry e = resp.results[i];
String name = e.getName();
- if( fnf != null && fnf.accept( this, name ) == false ) {
+ if (fnf != null && fnf.accept(this, name) == false)
continue;
- }
- if( name.length() > 0 ) {
- SmbFile f = new SmbFile( this, name,
- e.getType(),
+ if (name.length() > 0) {
+ // if !files we don't need to create SmbFiles here
+ SmbFile f = new SmbFile(this, name, e.getType(),
ATTR_READONLY | ATTR_DIRECTORY, 0L, 0L, 0L );
- if( ff != null && ff.accept( f ) == false ) {
+ if (ff != null && ff.accept(f) == false)
continue;
- }
- if( files ) {
- list.add( f );
+ if (files) {
+ list.add(f);
} else {
- list.add( name );
+ list.add(name);
}
}
}
- } finally {
- try {
- handle.close();
- } catch(IOException ioe) {
- if (log.level >= 4)
- ioe.printStackTrace(log);
+ if (getType() != TYPE_WORKGROUP) {
+ break;
}
- }
+ req.subCommand = (byte)SmbComTransaction.NET_SERVER_ENUM3;
+ req.reset(0, ((NetServerEnum2Response)resp).lastName);
+ resp.reset();
+ } while(more);
}
- void doNetEnum( ArrayList list,
+ void doNetEnumX( ArrayList list,
boolean files,
String wildcard,
int searchAttributes,
file.log.println( "read: len=" + len + ",r=" + r + ",fp=" + fp );
try {
- file.send( new SmbComReadAndX( file.fid, fp, r, null ), response );
+SmbComReadAndX request = new SmbComReadAndX( file.fid, fp, r, null );
+if( file.type == SmbFile.TYPE_NAMED_PIPE ) {
+ request.minCount = request.maxCount = request.remaining = 1024;
+}
+ file.send( request, response );
} catch( SmbException se ) {
if( file.type == SmbFile.TYPE_NAMED_PIPE &&
se.getNtStatus() == NtStatus.NT_STATUS_PIPE_BROKEN ) {
write( b, 0, b.length );
}
+ void ensureOpen() throws IOException {
+ // ensure file is open
+ if( file.isOpen() == false ) {
+ file.open( openFlags, access | SmbConstants.FILE_WRITE_DATA, SmbFile.ATTR_NORMAL, 0 );
+ if( append ) {
+ fp = file.length();
+ }
+ }
+ }
/**
* Writes len bytes from the specified byte array starting at
* offset off to this file output stream.
*/
public void write( byte[] b, int off, int len ) throws IOException {
+ if( file.isOpen() == false && file instanceof SmbNamedPipe ) {
+ file.send( new TransWaitNamedPipe( "\\pipe" + file.unc ),
+ new TransWaitNamedPipeResponse() );
+ }
+ writeDirect( b, off, len, 0 );
+ }
+/**
+ * Just bypasses TransWaitNamedPipe - used by DCERPC bind.
+ */
+ public void writeDirect( byte[] b, int off, int len, int flags ) throws IOException {
if( len <= 0 ) {
return;
}
if( tmp == null ) {
throw new IOException( "Bad file descriptor" );
}
- // ensure file is open
- if( file.isOpen() == false ) {
- if( file instanceof SmbNamedPipe ) {
- file.send( new TransWaitNamedPipe( "\\pipe" + file.unc ),
- new TransWaitNamedPipeResponse() );
- }
- file.open( openFlags, access | SmbConstants.FILE_WRITE_DATA, SmbFile.ATTR_NORMAL, 0 );
- if( append ) {
- fp = file.length();
- }
- }
+ ensureOpen();
if( file.log.level >= 4 )
file.log.println( "write: fid=" + file.fid + ",off=" + off + ",len=" + len );
w = len > writeSize ? writeSize : len;
if( useNTSmbs ) {
reqx.setParam( file.fid, fp, len - w, b, off, w );
+if ((flags & 1) != 0) {
+ reqx.setParam( file.fid, fp, len, b, off, w );
+ reqx.writeMode = 0x8;
+} else {
+ reqx.writeMode = 0;
+}
file.send( reqx, rspx );
fp += rspx.count;
len -= rspx.count;
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2007 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package jcifs.smb;
+
+import jcifs.util.Hexdump;
+
+public class SmbShareInfo implements FileEntry {
+
+ protected String netName;
+ protected int type;
+ protected String remark;
+
+ public String getName() {
+ return netName;
+ }
+ public int getType() {
+ /* 0x80000000 means hidden but SmbFile.isHidden() checks for $ at end
+ */
+ switch (type & 0xFFFF) {
+ case 1:
+ return SmbFile.TYPE_PRINTER;
+ case 3:
+ return SmbFile.TYPE_NAMED_PIPE;
+ }
+ return SmbFile.TYPE_SHARE;
+ }
+ public int getAttributes() {
+ return SmbFile.ATTR_READONLY | SmbFile.ATTR_DIRECTORY;
+ }
+ public long createTime() {
+ return 0L;
+ }
+ public long lastModified() {
+ return 0L;
+ }
+ public long length() {
+ return 0L;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof SmbShareInfo) {
+ SmbShareInfo si = (SmbShareInfo)obj;
+ return netName.equals(si.netName);
+ }
+ return false;
+ }
+ public int hashCode() {
+ int hashCode = netName.hashCode();
+ return hashCode;
+ }
+
+ public String toString() {
+ return new String( "SmbShareInfo[" +
+ "netName=" + netName +
+ ",type=0x" + Hexdump.toHexString( type, 8 ) +
+ ",remark=" + remark + "]" );
+ }
+}
* is a policy regarding which hosts a user can connect from. This
* requires communicating over port 139 rather than 445.
*/
- if (NETBIOS_HOSTNAME != null && NETBIOS_HOSTNAME.equals( "" ) == false) {
+ if (false && NETBIOS_HOSTNAME != null && NETBIOS_HOSTNAME.equals( "" ) == false) {
port = 139;
}
if (port == 139) {
}
}
request.tid = tid;
- if( inDfs && request.path != null && request.path.length() > 0 ) {
+ if( inDfs && !service.equals("IPC") && request.path != null && request.path.length() > 0 ) {
/* When DFS is in action all request paths are
* full UNC paths minus the first backslash like
* \server\share\path\to\file
import java.io.OutputStream;
import java.io.IOException;
-class TransactNamedPipeOutputStream extends OutputStream {
+class TransactNamedPipeOutputStream extends SmbFileOutputStream {
private String path;
private SmbNamedPipe pipe;
private boolean dcePipe;
TransactNamedPipeOutputStream( SmbNamedPipe pipe ) throws IOException {
+ super(pipe, false, (pipe.pipeType & 0xFFFF00FF) | SmbFile.O_EXCL);
this.pipe = pipe;
this.dcePipe = ( pipe.pipeType & SmbNamedPipe.PIPE_TYPE_DCE_TRANSACT ) == SmbNamedPipe.PIPE_TYPE_DCE_TRANSACT;
path = pipe.unc;
new TransCallNamedPipeResponse( pipe ));
} else if(( pipe.pipeType & SmbNamedPipe.PIPE_TYPE_TRANSACT ) ==
SmbNamedPipe.PIPE_TYPE_TRANSACT ) {
- pipe.open((pipe.pipeType & 0xFF) | SmbFile.O_EXCL,
- pipe.pipeType >>> 16,
- SmbFile.ATTR_NORMAL,
- 0);
+ ensureOpen();
TransTransactNamedPipe req = new TransTransactNamedPipe( pipe.fid, b, off, len );
if (dcePipe) {
req.maxDataCount = 1024;