jCIFS似乎无法进行身份验证

时间:2014-11-07 00:26:02

标签: java cifs jcifs

我开始通过使用jCIFS来衡量我们失去的性能,而不是要求我们的用户自己手动映射驱动器,但后来我发现我甚至无法通过第一次基本的阅读测试使用jCIFS从文件中获取数据。

我将问题归结为测试问题:

import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.google.common.io.ByteStreams;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;

public class TestCifs
{
    public static void main(String[] args) throws Exception
    {
        OutputStream output = ByteStreams.nullOutputStream();

        String domain = ""; // have tried the actual name too
        String user = "<your_user_here>";
        String pass = "<your_pass_here>";

        String relativePath = "path/to/100MiB";

        // Read via UNC path (Windows doing the SMB work.)
        Path uncFile = Paths.get("\\\\192.168.1.66\\Shared", relativePath);
        Files.copy(uncFile, output);

        // Read via jCIFS
        //TODO: Figure out if this is a real URL in which case we'd have to escape stuff.
        SmbFile smbFile = new SmbFile("smb://192.168.1.66/Shared/" + relativePath,
                                      new NtlmPasswordAuthentication(domain, user, pass));
        ByteStreams.copy(smbFile.getInputStream(), output);
    }
}

如果我运行它,它会运行直接拷贝,然后jCIFS拷贝失败并显示:

Exception in thread "main" jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.
    at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:546)
    at jcifs.smb.SmbTransport.send(SmbTransport.java:663)
    at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:390)
    at jcifs.smb.SmbSession.send(SmbSession.java:218)
    at jcifs.smb.SmbTree.treeConnect(SmbTree.java:176)
    at jcifs.smb.SmbFile.doConnect(SmbFile.java:911)
    at jcifs.smb.SmbFile.connect(SmbFile.java:954)
    at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
    at jcifs.smb.SmbFile.open0(SmbFile.java:972)
    at jcifs.smb.SmbFile.open(SmbFile.java:1006)
    at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
    at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
    at jcifs.smb.SmbFile.getInputStream(SmbFile.java:2844)
    at TestCifs.main(TestCifs.java:33)

我在user / pass中提供的用户名和密码与我在服务器上通过Windows安装其目录进行身份验证时使用的用户名和密码相同。我也尝试使用服务器的名称作为域无效。我真的对此感到茫然,我正要看看像Wireshark这样的东西来弄清楚实际上出了什么问题,但也许我做了一些明显错误的事情,而且有人可以指出这一点。

这可能是jCIFS&#39;的相关内容。自己的登录失败诊断:

treeConnect: unc=\\192.168.1.66\SHARED,service=?????
sessionSetup: accountName=TESTER,primaryDomain=
NtlmContext[auth=TESTER,ntlmsspFlags=0x20080004,workstation=JCIFS1_183_42,isEstablished=false,state=1,serverChallenge=null,signingKey=null]
Type1Message[suppliedDomain=,suppliedWorkstation=JCIFS1_183_42,flags=0x20080205]
00000: 4E 54 4C 4D 53 53 50 00 01 00 00 00 05 22 08 20  |NTLMSSP......". |
00010: 00 00 00 00 00 00 00 00 0D 00 0D 00 20 00 00 00  |............ ...|
00020: 4A 43 49 46 53 31 5F 31 38 33 5F 34 32           |JCIFS1_183_42   |

SmbComSessionSetupAndX[command=SMB_COM_SESSION_SETUP_ANDX,received=false,errorCode=0,flags=0x0018,flags2=0xC803,signSeq=0,tid=0,pid=21886,uid=0,mid=2,wordCount=12,byteCount=77,andxCommand=0xFF,andxOffset=0,snd_buf_size=16644,maxMpxCount=10,VC_NUMBER=1,sessionKey=0,lmHash.length=0,ntHash.length=0,capabilities=-2147483564,accountName=null,primaryDomain=null,NATIVE_OS=Windows 8,NATIVE_LANMAN=jCIFS]
00000: FF 53 4D 42 73 00 00 00 00 18 03 C8 00 00 00 00  |ÿSMBs......È....|
00010: 00 00 00 00 00 00 00 00 00 00 7E 55 00 00 02 00  |..........~U....|
00020: 0C FF 00 DE DE 04 41 0A 00 01 00 00 00 00 00 2D  |.ÿ.ÞÞ.A........-|
00030: 00 00 00 00 00 54 00 00 80 4D 00 4E 54 4C 4D 53  |.....T...M.NTLMS|
00040: 53 50 00 01 00 00 00 05 22 08 20 00 00 00 00 00  |SP......". .....|
00050: 00 00 00 0D 00 0D 00 20 00 00 00 4A 43 49 46 53  |....... ...JCIFS|
00060: 31 5F 31 38 33 5F 34 32 57 00 69 00 6E 00 64 00  |1_183_42W.i.n.d.|
00070: 6F 00 77 00 73 00 20 00 38 00 00 00 6A 00 43 00  |o.w.s. .8...j.C.|
00080: 49 00 46 00 53 00 00 00                          |I.F.S...        |

New data read: Transport1[0.0.0.0<00>/192.168.1.66:445]
00000: FF 53 4D 42 73 6D 00 00 C0 80 41 C8 00 00 00 00  |ÿSMBsm..À.AÈ....|
00010: 00 00 00 00 00 00 00 00 00 00 7E 55 00 00 02 00  |..........~U....|

SmbComSessionSetupAndXResponse[command=SMB_COM_SESSION_SETUP_ANDX,received=false,errorCode=Logon failure: unknown user name or bad password.,flags=0x0080,flags2=0xC841,signSeq=0,tid=0,pid=21886,uid=0,mid=2,wordCount=0,byteCount=0,andxCommand=0xFF,andxOffset=0,isLoggedInAsGuest=false,nativeOs=,nativeLanMan=,primaryDomain=]
00000: FF 53 4D 42 73 6D 00 00 C0 80 41 C8 00 00 00 00  |ÿSMBsm..À.AÈ....|
00010: 00 00 00 00 00 00 00 00 00 00 7E 55 00 00 02 00  |..........~U....|
00020: 00 00 00                                         |...             |

似乎根本没有将用户名放入邮件中,所以也许我正在查看错误,但如果它真的这样做,肯定会被注意到之前是别人...

已尝试的解决方法:

  • 将身份验证信息放入网址而不是auth对象。
  • 在尝试访问SmbFile之前调用SmbSession.logon。在这种情况下,您只需从登录中获取错误。
  • 使用NtlmAuthenticator.setDefault()设置默认验证器。在这种情况下,您会看到它调用身份验证器来获取身份验证详细信息,但然后似乎丢弃了信息并在没有用户名的情况下发出请求。

0 个答案:

没有答案