diff --git a/.classpath b/.classpath index c0c1ca3..11bdcff 100644 --- a/.classpath +++ b/.classpath @@ -4,9 +4,10 @@ - + + diff --git a/.gitignore b/.gitignore index 77e7411..ae3c172 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ /bin/ -.classpath -.project diff --git a/jars/WrapperForSlf4j-1.0.2.jar b/jars/WrapperForSlf4j-1.0.2.jar deleted file mode 100644 index 187bc26..0000000 Binary files a/jars/WrapperForSlf4j-1.0.2.jar and /dev/null differ diff --git a/jars/WrapperForSlf4j-1.7.36.jar b/jars/WrapperForSlf4j-1.7.36.jar new file mode 100644 index 0000000..1a5750a Binary files /dev/null and b/jars/WrapperForSlf4j-1.7.36.jar differ diff --git a/jars/jcifs-1.3.17_patch.jar b/jars/jcifs-1.3.17_patch.jar index 882adad..99f74af 100644 Binary files a/jars/jcifs-1.3.17_patch.jar and b/jars/jcifs-1.3.17_patch.jar differ diff --git a/jars/jcifsngLatest.jar b/jars/jcifsngLatest.jar new file mode 100644 index 0000000..df6be65 Binary files /dev/null and b/jars/jcifsngLatest.jar differ diff --git a/src/com/sentaroh/jcifs/JcifsAuth.java b/src/com/sentaroh/jcifs/JcifsAuth.java index ff6fc4f..20c4af7 100644 --- a/src/com/sentaroh/jcifs/JcifsAuth.java +++ b/src/com/sentaroh/jcifs/JcifsAuth.java @@ -31,11 +31,13 @@ public class JcifsAuth { final static public int JCIFS_FILE_SMB211 = 3; final static public int JCIFS_FILE_SMB212 = 4; final static public int JCIFS_FILE_SMB214 = 5; - private jcifs.smb.NtlmPasswordAuthentication mSmb1Auth = null; + final static public int JCIFS_FILE_SMB_LATEST = 6; + private jcifs13.smb.NtlmPasswordAuthentication mSmb1Auth = null; private jcifsng.CIFSContext mSmb201Auth = null; private jcifsng211.CIFSContext mSmb211Auth = null; private jcifsng212.CIFSContext mSmb212Auth = null; private jcifsng214.CIFSContext mSmb214Auth = null; + private jcifs.CIFSContext mSmbLatestAuth = null; private int mSmbLevel = JCIFS_FILE_SMB1; private String mDomain = null, mUserName = null, mUserPass = null; @@ -56,7 +58,7 @@ public JcifsAuth(int smb_level, String domain, String user, String pass) { mUserName = user; mUserPass = pass; if (mSmbLevel==JCIFS_FILE_SMB1) { - mSmb1Auth = new jcifs.smb.NtlmPasswordAuthentication(domain, user, pass); + mSmb1Auth = new jcifs13.smb.NtlmPasswordAuthentication(domain, user, pass); } else if (mSmbLevel==JCIFS_FILE_SMB201) { try { Properties prop = new Properties(); @@ -101,6 +103,17 @@ public JcifsAuth(int smb_level, String domain, String user, String pass) { } catch (jcifsng214.CIFSException e) { e.printStackTrace(); } + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + try { + Properties prop = new Properties(); + prop.setProperty("jcifs.smb.client.minVersion", "SMB202"); + prop.setProperty("jcifs.smb.client.maxVersion", "SMB311"); + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(prop)); + jcifs.smb.NtlmPasswordAuthentication creds = new jcifs.smb.NtlmPasswordAuthentication(bc, domain, user, pass); + mSmbLatestAuth = bc.withCredentials(creds); + } catch (jcifs.CIFSException e) { + e.printStackTrace(); + } } } @@ -178,6 +191,21 @@ public JcifsAuth(int smb_level, String domain, String user, String pass, boolean } catch (jcifsng214.CIFSException e) { e.printStackTrace(); } + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + try { + Properties prop = new Properties(); + if (ipc_signing_enforced) prop.setProperty("jcifs.smb.client.ipcSigningEnforced", "true"); + else prop.setProperty("jcifs.smb.client.ipcSigningEnforced", "false"); + + prop.setProperty("jcifs.smb.client.minVersion", "SMB202"); + prop.setProperty("jcifs.smb.client.maxVersion", "SMB311"); + + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(prop)); + jcifs.smb.NtlmPasswordAuthentication creds = new jcifs.smb.NtlmPasswordAuthentication(bc, domain, user, pass); + mSmbLatestAuth = bc.withCredentials(creds); + } catch (jcifs.CIFSException e) { + e.printStackTrace(); + } } } @@ -262,6 +290,24 @@ public JcifsAuth(int smb_level, String domain, String user, String pass, boolean } catch (jcifsng214.CIFSException e) { e.printStackTrace(); } + } if (isSmbLatest()) { + try { + Properties prop = new Properties(); + if (ipc_signing_enforced) prop.setProperty("jcifs.smb.client.ipcSigningEnforced", "true"); + else prop.setProperty("jcifs.smb.client.ipcSigningEnforced", "false"); + + if (use_smb2_nego) prop.setProperty("jcifs.smb.client.useSMB2Negotiation", "true"); + else prop.setProperty("jcifs.smb.client.useSMB2Negotiation", "false"); + + prop.setProperty("jcifs.smb.client.minVersion", "SMB202"); + prop.setProperty("jcifs.smb.client.maxVersion", "SMB311"); + + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(prop)); + jcifs.smb.NtlmPasswordAuthentication creds = new jcifs.smb.NtlmPasswordAuthentication(bc, domain, user, pass); + mSmbLatestAuth = bc.withCredentials(creds); + } catch (jcifs.CIFSException e) { + e.printStackTrace(); + } } } @@ -345,6 +391,23 @@ public JcifsAuth(int smb_level, String domain, String user, String pass, boolean } catch (jcifsng214.CIFSException e) { e.printStackTrace(); } + } if (isSmbLatest()) { + try { + if (ipc_signing_enforced) prop_new.setProperty("jcifs.smb.client.ipcSigningEnforced", "true"); + else prop_new.setProperty("jcifs.smb.client.ipcSigningEnforced", "false"); + + if (use_smb2_nego) prop_new.setProperty("jcifs.smb.client.useSMB2Negotiation", "true"); + else prop_new.setProperty("jcifs.smb.client.useSMB2Negotiation", "false"); + + prop_new.setProperty("jcifs.smb.client.minVersion", "SMB202"); + prop_new.setProperty("jcifs.smb.client.maxVersion", "SMB311"); + + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(prop_new)); + jcifs.smb.NtlmPasswordAuthentication creds = new jcifs.smb.NtlmPasswordAuthentication(bc, domain, user, pass); + mSmbLatestAuth = bc.withCredentials(creds); + } catch (jcifs.CIFSException e) { + e.printStackTrace(); + } } } @@ -428,6 +491,22 @@ public JcifsAuth(int smb_level, String domain, String user, String pass, boolean } catch (jcifsng214.CIFSException e) { e.printStackTrace(); } + } else if (isSmbLatest()) { + try { + Properties prop = new Properties(); + if (ipc_signing_enforced) + prop.setProperty("jcifs.smb.client.ipcSigningEnforced", "true"); + else prop.setProperty("jcifs.smb.client.ipcSigningEnforced", "false"); + prop.setProperty("jcifs.smb.client.useSMB2Negotiation", "true"); + prop.setProperty("jcifs.smb.client.minVersion", min_version); + prop.setProperty("jcifs.smb.client.maxVersion", max_version); + + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(prop)); + jcifs.smb.NtlmPasswordAuthentication creds = new jcifs.smb.NtlmPasswordAuthentication(bc, domain, user, pass); + mSmbLatestAuth = bc.withCredentials(creds); + } catch (jcifs.CIFSException e) { + e.printStackTrace(); + } } } @@ -455,7 +534,11 @@ public boolean isSmb214() { return mSmbLevel==JCIFS_FILE_SMB214; } - public jcifs.smb.NtlmPasswordAuthentication getSmb1Auth() { + public boolean isSmbLatest() { + return mSmbLevel==JCIFS_FILE_SMB_LATEST; + } + + public jcifs13.smb.NtlmPasswordAuthentication getSmb1Auth() { return mSmb1Auth; } @@ -475,6 +558,10 @@ public jcifsng214.CIFSContext getSmb214Auth() { return mSmb214Auth; } + public jcifs.CIFSContext getSmbLatestAuth() { + return mSmbLatestAuth; + } + public String getDomain() { return mDomain; } diff --git a/src/com/sentaroh/jcifs/JcifsFile.java b/src/com/sentaroh/jcifs/JcifsFile.java index 8949a29..c1ff485 100644 --- a/src/com/sentaroh/jcifs/JcifsFile.java +++ b/src/com/sentaroh/jcifs/JcifsFile.java @@ -36,6 +36,7 @@ public class JcifsFile { final static public int JCIFS_FILE_SMB211 = JcifsAuth.JCIFS_FILE_SMB211; final static public int JCIFS_FILE_SMB212 = JcifsAuth.JCIFS_FILE_SMB212; final static public int JCIFS_FILE_SMB214 = JcifsAuth.JCIFS_FILE_SMB214; + final static public int JCIFS_FILE_SMB_LATEST = JcifsAuth.JCIFS_FILE_SMB_LATEST; private int mSmbLevel = JCIFS_FILE_SMB1; @@ -45,7 +46,8 @@ public class JcifsFile { private jcifsng211.smb.SmbFile mSmb211File = null; private jcifsng212.smb.SmbFile mSmb212File = null; private jcifsng214.smb.SmbFile mSmb214File = null; - private jcifs.smb.SmbFile mSmb1File = null; + private jcifs.smb.SmbFile mSmbLatestFile = null; + private jcifs13.smb.SmbFile mSmb1File = null; public JcifsFile(String url, JcifsAuth auth) throws MalformedURLException, JcifsException { if (auth==null) { @@ -55,7 +57,7 @@ public JcifsFile(String url, JcifsAuth auth) throws MalformedURLException, Jcifs mAuth = auth; if (mSmbLevel==JCIFS_FILE_SMB1) { - mSmb1File = new jcifs.smb.SmbFile(url, auth.getSmb1Auth()); + mSmb1File = new jcifs13.smb.SmbFile(url, auth.getSmb1Auth()); } else if (mSmbLevel==JCIFS_FILE_SMB201) { mSmb201File = new jcifsng.smb.SmbFile(url, auth.getSmb201Auth()); } else if (mSmbLevel==JCIFS_FILE_SMB211) { @@ -64,10 +66,12 @@ public JcifsFile(String url, JcifsAuth auth) throws MalformedURLException, Jcifs mSmb212File = new jcifsng212.smb.SmbFile(url, auth.getSmb212Auth()); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File = new jcifsng214.smb.SmbFile(url, auth.getSmb214Auth()); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile = new jcifs.smb.SmbFile(url, auth.getSmbLatestAuth()); } } - private JcifsFile(jcifs.smb.SmbFile smb1File, JcifsAuth auth) throws JcifsException { + private JcifsFile(jcifs13.smb.SmbFile smb1File, JcifsAuth auth) throws JcifsException { mSmbLevel = JCIFS_FILE_SMB1; if (auth==null || !auth.isSmb1()) { throw new JcifsException("JcifsAuth is null or SMB2."); @@ -112,6 +116,15 @@ private JcifsFile(jcifsng214.smb.SmbFile smb214File, JcifsAuth auth) throws Jcif mSmb214File = smb214File; } + private JcifsFile(jcifs.smb.SmbFile smbLatestFile, JcifsAuth auth) throws JcifsException { + mSmbLevel = JCIFS_FILE_SMB_LATEST; + if (auth==null || auth.isSmb1()) { + throw new JcifsException("JcifsAuth is null or SMB1."); + } + mAuth = auth; + mSmbLatestFile = smbLatestFile; + } + public boolean isSmb1File() { return mSmbLevel==JCIFS_FILE_SMB1; } @@ -132,7 +145,11 @@ public boolean isSmb214File() { return mSmbLevel==JCIFS_FILE_SMB214; } - public jcifs.smb.SmbFile getSmb1File() { + public boolean isSmbLatestFile() { + return mSmbLevel==JCIFS_FILE_SMB_LATEST; + } + + public jcifs13.smb.SmbFile getSmb1File() { return mSmb1File; } @@ -152,6 +169,10 @@ public jcifsng214.smb.SmbFile getSmb214File() { return mSmb214File; } + public jcifs.smb.SmbFile getSmbLatestFile() { + return mSmbLatestFile; + } + public boolean exists() throws JcifsException { try { if (mSmbLevel==JCIFS_FILE_SMB1) { @@ -164,6 +185,8 @@ public boolean exists() throws JcifsException { return mSmb212File.exists(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.exists(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.exists(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -176,6 +199,8 @@ public boolean exists() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -192,6 +217,8 @@ public void delete() throws JcifsException { mSmb212File.delete(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File.delete(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile.delete(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -204,6 +231,8 @@ public void delete() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -220,6 +249,8 @@ public void mkdir() throws JcifsException { mSmb212File.mkdir(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File.mkdir(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile.mkdir(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -232,6 +263,8 @@ public void mkdir() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -247,6 +280,8 @@ public void mkdirs() throws JcifsException { mSmb212File.mkdirs(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File.mkdirs(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile.mkdirs(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -259,6 +294,8 @@ public void mkdirs() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -274,6 +311,8 @@ public int getAttributes() throws JcifsException { return mSmb212File.getAttributes(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getAttributes(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getAttributes(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -286,6 +325,8 @@ public int getAttributes() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -301,6 +342,8 @@ public InputStream getInputStream() throws JcifsException { return mSmb212File.getInputStream(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getInputStream(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getInputStream(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -313,6 +356,8 @@ public InputStream getInputStream() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (IOException e) { throw (new JcifsException(e, 0, e.getCause())); } @@ -331,6 +376,8 @@ public OutputStream getOutputStream() throws JcifsException { return mSmb212File.getOutputStream(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getOutputStream(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getOutputStream(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -343,6 +390,8 @@ public OutputStream getOutputStream() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (IOException e) { throw (new JcifsException(e, 0, e.getCause())); } @@ -360,6 +409,8 @@ public void close() throws JcifsException { mSmb212File.close(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File.close(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile.close(); } else throw (new JcifsException("Unknown SMB Level")); } @@ -376,6 +427,8 @@ public void connect() throws JcifsException { mSmb212File.connect(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File.connect(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile.connect(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -388,6 +441,8 @@ public void connect() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (IOException e) { throw (new JcifsException(e, 0, e.getCause())); } @@ -405,6 +460,8 @@ public void createNew() throws JcifsException { mSmb212File.createNewFile(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File.createNewFile(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile.createNewFile(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -417,6 +474,8 @@ public void createNew() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -431,6 +490,8 @@ public String getName() { return mSmb212File.getName(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getName(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getName(); } return null; } @@ -446,6 +507,8 @@ public String getPath() { return mSmb212File.getPath(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getPath(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getPath(); } return null; } @@ -461,6 +524,8 @@ public String getCanonicalPath() { return mSmb212File.getCanonicalPath(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getCanonicalPath(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getCanonicalPath(); } return null; } @@ -476,6 +541,8 @@ public String getShare() { return mSmb212File.getShare(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getShare(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getShare(); } return null; } @@ -492,6 +559,8 @@ public int getType() throws JcifsException { return mSmb212File.getType(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getType(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getType(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -504,6 +573,8 @@ public int getType() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -518,6 +589,8 @@ public String getUncPath() { return mSmb212File.getUncPath(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getUncPath(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getUncPath(); } return null; } @@ -533,6 +606,8 @@ public String getParent() { return mSmb212File.getParent(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.getParent(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.getParent(); } return null; } @@ -549,6 +624,8 @@ public boolean canRead() throws JcifsException { return mSmb212File.canRead(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.canRead(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.canRead(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -561,6 +638,8 @@ public boolean canRead() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -576,6 +655,8 @@ public boolean canWrite() throws JcifsException { return mSmb212File.canWrite(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.canWrite(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.canWrite(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -588,6 +669,8 @@ public boolean canWrite() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -603,6 +686,8 @@ public boolean isDirectory() throws JcifsException { return mSmb212File.isDirectory(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.isDirectory(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.isDirectory(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -615,6 +700,8 @@ public boolean isDirectory() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -630,6 +717,8 @@ public boolean isFile() throws JcifsException { return mSmb212File.isFile(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.isFile(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.isFile(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -642,6 +731,8 @@ public boolean isFile() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -657,6 +748,8 @@ public boolean isHidden() throws JcifsException { return mSmb212File.isHidden(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.isHidden(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.isHidden(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -669,6 +762,8 @@ public boolean isHidden() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -684,6 +779,8 @@ public long length() throws JcifsException { return mSmb212File.length(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.length(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.length(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -696,6 +793,8 @@ public long length() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -711,6 +810,8 @@ public String[] list() throws JcifsException { return mSmb212File.list(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.list(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.list(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -723,13 +824,15 @@ public String[] list() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } public JcifsFile[] listFiles() throws JcifsException { try { if (mSmbLevel==JCIFS_FILE_SMB1) { - jcifs.smb.SmbFile[] smb1Files = mSmb1File.listFiles(); + jcifs13.smb.SmbFile[] smb1Files = mSmb1File.listFiles(); if (smb1Files == null) return null; JcifsFile[] result = new JcifsFile[smb1Files.length]; for (int i = 0; i < smb1Files.length; i++) @@ -763,6 +866,13 @@ public JcifsFile[] listFiles() throws JcifsException { for (int i = 0; i < smb214Files.length; i++) result[i] = new JcifsFile(smb214Files[i], mAuth); return result; + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + jcifs.smb.SmbFile[] smbLatestFiles = mSmbLatestFile.listFiles(); + if (smbLatestFiles == null) return null; + JcifsFile[] result = new JcifsFile[smbLatestFiles.length]; + for (int i = 0; i < smbLatestFiles.length; i++) + result[i] = new JcifsFile(smbLatestFiles[i], mAuth); + return result; } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -775,6 +885,8 @@ public JcifsFile[] listFiles() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -800,6 +912,10 @@ public void renameTo(JcifsFile d) throws JcifsException { if (d.getSmb214File() == null) throw new JcifsException("Null SMB214 file specified."); else mSmb214File.renameTo(d.getSmb214File()); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + if (d.getSmbLatestFile() == null) + throw new JcifsException("Null SMBLatest file specified."); + else mSmbLatestFile.renameTo(d.getSmbLatestFile()); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -812,6 +928,8 @@ public void renameTo(JcifsFile d) throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -832,6 +950,8 @@ public void setLastModified(long lm) throws JcifsException { mSmb212File.setLastModified(lm); } else if (mSmbLevel==JCIFS_FILE_SMB214) { mSmb214File.setLastModified(lm); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + mSmbLatestFile.setLastModified(lm); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -844,6 +964,8 @@ public void setLastModified(long lm) throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } @@ -859,6 +981,8 @@ public long getLastModified() throws JcifsException { return mSmb212File.lastModified(); } else if (mSmbLevel==JCIFS_FILE_SMB214) { return mSmb214File.lastModified(); + } else if (mSmbLevel==JCIFS_FILE_SMB_LATEST) { + return mSmbLatestFile.lastModified(); } else throw (new JcifsException("Unknown SMB Level")); } catch (jcifsng.smb.SmbException e) { @@ -871,6 +995,8 @@ public long getLastModified() throws JcifsException { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } catch (jcifs.smb.SmbException e) { throw (new JcifsException(e, e.getNtStatus(), e.getCause())); + } catch (jcifs13.smb.SmbException e) { + throw (new JcifsException(e, e.getNtStatus(), e.getCause())); } } diff --git a/src/com/sentaroh/jcifs/JcifsUtil.java b/src/com/sentaroh/jcifs/JcifsUtil.java index 2ad9f01..5567e24 100644 --- a/src/com/sentaroh/jcifs/JcifsUtil.java +++ b/src/com/sentaroh/jcifs/JcifsUtil.java @@ -78,6 +78,8 @@ final static public String getSmbHostIpAddressByHostName(int smb_level, String h return getSmbHostIpAddressFromNameSmb212(hn); } else if (smb_level==JcifsAuth.JCIFS_FILE_SMB214) { return getSmbHostIpAddressFromNameSmb214(hn); + } else if (smb_level==JcifsAuth.JCIFS_FILE_SMB_LATEST) { + return getSmbHostIpAddressFromNameSmbLatest(hn); } return null; } @@ -85,7 +87,7 @@ final static public String getSmbHostIpAddressByHostName(int smb_level, String h final static private String getSmbHostIpAddressFromNameSmb1(String hn) { String ipAddress = null; try { - jcifs.netbios.NbtAddress nbtAddress = jcifs.netbios.NbtAddress.getByName(hn); + jcifs13.netbios.NbtAddress nbtAddress = jcifs13.netbios.NbtAddress.getByName(hn); InetAddress address = nbtAddress.getInetAddress(); ipAddress = address.getHostAddress(); } catch (UnknownHostException e) { @@ -156,6 +158,21 @@ final static private String getSmbHostIpAddressFromNameSmb214(String hn) { return ipAddress; } + final static private String getSmbHostIpAddressFromNameSmbLatest(String hn) { + String ipAddress = null; + try { + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(System.getProperties())); + ipAddress = bc.getNameServiceClient().getByName(hn).getHostAddress(); + } catch (UnknownHostException e) { + log.error("getSmbHostIpAddressFromNameSmb2 UnknownHostException", e); + } catch (jcifs.CIFSException e) { + log.error("getSmbHostIpAddressFromNameSmb2 CIFSException", e); + } catch (Exception e) { + log.error("getSmbHostIpAddressFromNameSmb2 Exception", e); + } + return ipAddress; + } + final static public boolean isIpAddressAndPortConnected(String address, int port, int timeout) { boolean reachable = false; Socket socket = new Socket(); @@ -183,6 +200,8 @@ final static public String getSmbHostNameByAddress(int smb_level, String address return getSmbHostNameFromAddressSmb212(address); } else if (smb_level==JcifsAuth.JCIFS_FILE_SMB214) { return getSmbHostNameFromAddressSmb214(address); + } else if (smb_level==JcifsAuth.JCIFS_FILE_SMB_LATEST) { + return getSmbHostNameFromAddressSmbLatest(address); } return null; } @@ -190,10 +209,10 @@ final static public String getSmbHostNameByAddress(int smb_level, String address final static private String getSmbHostNameFromAddressSmb1(String address) { String srv_name = ""; try { - jcifs.netbios.NbtAddress[] uax = jcifs.netbios.NbtAddress.getAllByAddress(address); + jcifs13.netbios.NbtAddress[] uax = jcifs13.netbios.NbtAddress.getAllByAddress(address); if (uax != null) { for (int i = 0; i < uax.length; i++) { - jcifs.netbios.NbtAddress ua = uax[i]; + jcifs13.netbios.NbtAddress ua = uax[i]; String hn; hn = ua.firstCalledName(); if (ua.getNameType() == 32) { @@ -314,6 +333,32 @@ final static private String getSmbHostNameFromAddressSmb214(String address) { return srv_name; } + final static private String getSmbHostNameFromAddressSmbLatest(String address) { + String srv_name = ""; + try { + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(System.getProperties())); + jcifs.NetbiosAddress[] uax = bc.getNameServiceClient().getNbtAllByAddress(address); + if (uax != null) { + for (int i = 0; i < uax.length; i++) { + jcifs.NetbiosAddress ua = uax[i]; + String hn; + hn = ua.firstCalledName(); + if (ua.getNameType() == 32) { + srv_name = hn; + break; + } + } + } + } catch (UnknownHostException e) { + log.error("getSmbHostNameFromAddressSmb2 UnknownHostException", e); + } catch (jcifs.CIFSException e) { + log.error("getSmbHostNameFromAddressSmb2 CIFSException", e); + } catch (Exception e) { + log.error("getSmbHostNameFromAddressSmb2 Exception", e); + } + return srv_name; + } + final static public boolean isNetbiosAddress(int smb_level, String address) { if (smb_level==JcifsAuth.JCIFS_FILE_SMB1) { return isNbtAddressActiveSmb1(address); @@ -325,6 +370,8 @@ final static public boolean isNetbiosAddress(int smb_level, String address) { return isNbtAddressActiveSmb212(address); } else if (smb_level==JcifsAuth.JCIFS_FILE_SMB214) { return isNbtAddressActiveSmb214(address); + } else if (smb_level==JcifsAuth.JCIFS_FILE_SMB_LATEST) { + return isNbtAddressActiveSmbLatest(address); } return false; } @@ -332,7 +379,7 @@ final static public boolean isNetbiosAddress(int smb_level, String address) { final static private boolean isNbtAddressActiveSmb1(String address) { boolean result = false; try { - jcifs.netbios.NbtAddress na = jcifs.netbios.NbtAddress.getByName(address); + jcifs13.netbios.NbtAddress na = jcifs13.netbios.NbtAddress.getByName(address); result = na.isActive(); } catch (UnknownHostException e) { log.error("isNbtAddressActiveSmb1 UnknownHostException", e); @@ -406,6 +453,22 @@ final static private boolean isNbtAddressActiveSmb214(String address) { return result; } + final static private boolean isNbtAddressActiveSmbLatest(String address) { + boolean result = false; + try { + jcifs.context.BaseContext bc = new jcifs.context.BaseContext(new jcifs.config.PropertyConfiguration(System.getProperties())); + jcifs.NetbiosAddress na = bc.getNameServiceClient().getNbtByName(address); + result = na.isActive(bc); + } catch (UnknownHostException e) { + log.error("isNbtAddressActiveSmb2 UnknownHostException", e); + } catch (jcifs.CIFSException e) { + log.error("isNbtAddressActiveSmb2 CIFSException", e); + } catch (Exception e) { + log.error("isNbtAddressActiveSmb2 Exception", e); + } + return result; + } + final static public String[] analyzeNtStatusCode(JcifsException e, String url, String user) { String[] result = new String[4];