hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
707 stars 180 forks source link

Simply read File #166

Closed sshklianko closed 7 years ago

sshklianko commented 7 years ago

Hi, @hierynomus . Is there a possibility in your lib to read/download a file without affecting its attributes? Each call to DiskShare.openFile/getEntry results in file's change/write time attributes being set to current time

Thanks.

hierynomus commented 7 years ago

Can you send a code sample of how you're calling the API's? And a full trace log

Sent from my Samsung SM-G950F using FastHub

sshklianko commented 7 years ago

This is how I get the file

public File getFile(String path) throws Exception {
        Set<SMB2ShareAccess> s = new HashSet<>();
        s.add(SMB2ShareAccess.ALL.iterator().next()); // this is to get READ only
        return this.getShare().openFile(path, EnumSet.of(AccessMask.GENERIC_READ), null, s, null, null);
    }
private DiskShare getShare() throws Exception {
        if (this.share != null && this.share.isConnected()) {
            return this.share;
        }

        this.share = (DiskShare) this.getSession().connectShare(this.shareName);
        return this.share;
    }

and then I print file info:

File f = smbjConnector.getFile("MyTests\\text1.txt");
        System.out.println("Change time: " + f.getFileInformation().getBasicInformation().getChangeTime().toDate());
        System.out.println("Access time: " + f.getFileInformation().getBasicInformation().getLastAccessTime().toDate());
        System.out.println("Write time: " + f.getFileInformation().getBasicInformation().getLastWriteTime().toDate());
        smbjConnector.close();

Log trace is pretty short: 2017-08-24 10:43:30 INFO Connection:108 - Successfully connected to: xxxxxxx 2017-08-24 10:43:31 INFO Connection:173 - Successfully authenticated aaa on xxxxxxx, session is 48514675507212 2017-08-24 10:43:31 INFO Session:105 - Connecting to \xxxxxx\MyTests on session 48514675507212 Change time: Thu Aug 24 10:43:30 MSK 2017 Access time: Wed Apr 19 14:35:07 MSK 2017 Write time: Thu Aug 24 10:43:30 MSK 2017 2017-08-24 10:43:32 INFO Session:154 - Logging off session 48514675507212 from host xxxxxx

hierynomus commented 7 years ago

Can you up the log level to trace so we can see which packets traverse the line?

sshklianko commented 7 years ago

There you go:

2017-08-24 15:45:25 DEBUG ProxySocketFactory:86 - Connecting to / 2017-08-24 15:45:25 DEBUG PacketReader:83 - Starting PacketReader on thread: Packet Reader for xx.x.x.xx 2017-08-24 15:45:25 DEBUG Connection:270 - Negotiating dialects [SMB_2_0_2, SMB_2_1] with server xx.x.x.xx 2017-08-24 15:45:25 DEBUG Connection:235 - Granted 1 (out of 1) credits to SMB2_NEGOTIATE with message id << 0 >> 2017-08-24 15:45:25 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_NEGOTIATE with message id << 0 >> >> 2017-08-24 15:45:25 DEBUG DirectTcpTransport:65 - Writing packet SMB2_NEGOTIATE with message id << 0 >> 2017-08-24 15:45:25 TRACE DirectTcpTransport:75 - Packet SMB2_NEGOTIATE with message id << 0 >> sent, lock released. 2017-08-24 15:45:25 DEBUG Promise:163 - Awaiting << 0 >> 2017-08-24 15:45:25 DEBUG PacketReader:70 - Received packet SMB2_NEGOTIATE with message id << 0 >> 2017-08-24 15:45:25 DEBUG Connection:347 - Server granted us 1 credits for SMB2_NEGOTIATE with message id << 0 >>, now available: 1 credits 2017-08-24 15:45:25 TRACE Connection:350 - Send/Recv of packet SMB2_NEGOTIATE with message id << 0 >> took << 72 ms >> 2017-08-24 15:45:25 DEBUG Promise:78 - Setting << 0 >> to SMB2_NEGOTIATE with message id << 0 >> 2017-08-24 15:45:25 DEBUG Connection:285 - Negotiated the following connection settings: ConnectionInfo{ serverGuid=ad5c1001-d3f0-47cd-8f1a-74687ecf342b, serverName='xx.x.x.xx', negotiatedProtocol=NegotiatedProtocol{dialect=SMB_2_1, maxTransactSize=8388608, maxReadSize=8388608, maxWriteSize=8388608}, clientGuid=58f6cb21-1e35-4eb0-a853-bffc1b17d9b6, clientCapabilities=[SMB2_GLOBAL_CAP_DFS], serverCapabilities=[SMB2_GLOBAL_CAP_DFS, SMB2_GLOBAL_CAP_LEASING, SMB2_GLOBAL_CAP_LARGE_MTU], clientSecurityMode=0, serverSecurityMode=3, server='null' } 2017-08-24 15:45:25 INFO Connection:108 - Successfully connected to: xx.x.x.xx 2017-08-24 15:45:26 DEBUG NtlmAuthenticator:72 - Initialized Authentication of test1 using NTLM 2017-08-24 15:45:26 DEBUG Connection:235 - Granted 1 (out of 1) credits to SMB2_SESSION_SETUP with message id << 1 >> 2017-08-24 15:45:26 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_SESSION_SETUP with message id << 1 >> >> 2017-08-24 15:45:26 DEBUG DirectTcpTransport:65 - Writing packet SMB2_SESSION_SETUP with message id << 1 >> 2017-08-24 15:45:26 TRACE DirectTcpTransport:75 - Packet SMB2_SESSION_SETUP with message id << 1 >> sent, lock released. 2017-08-24 15:45:26 DEBUG Promise:163 - Awaiting << 1 >> 2017-08-24 15:45:26 DEBUG PacketReader:70 - Received packet SMB2_SESSION_SETUP with message id << 1 >> 2017-08-24 15:45:26 DEBUG Connection:347 - Server granted us 1 credits for SMB2_SESSION_SETUP with message id << 1 >>, now available: 1 credits 2017-08-24 15:45:26 TRACE Connection:350 - Send/Recv of packet SMB2_SESSION_SETUP with message id << 1 >> took << 51 ms >> 2017-08-24 15:45:26 DEBUG Promise:78 - Setting << 1 >> to SMB2_SESSION_SETUP with message id << 1 >> 2017-08-24 15:45:26 DEBUG Connection:161 - More processing required for authentication of test1 using com.hierynomus.smbj.auth.NtlmAuthenticator@d0c94c0 2017-08-24 15:45:26 DEBUG NtlmAuthenticator:77 - Received token: a1 81 fc 30 81 f9 a0 03 0a 01 01 a1 0c 06 0a 2b 06 01 04 01 82 37 02 02 0a a2 81 e3 04 81 e0 4e 54 4c 4d 53 53 50 00 02 00 00 00 0a 00 0a 00 38 00 00 00 15 82 89 e2 53 2a 82 0e 17 c0 d1 d0 00 00 00 00 00 00 00 00 9e 00 9e 00 42 00 00 00 0a 00 39 38 00 00 00 0f 42 00 49 00 47 00 49 00 44 00 02 00 0a 00 42 00 49 00 47 00 49 00 44 00 01 00 1c 00 57 00 49 00 4e 00 44 00 4f 00 57 00 53 00 2d 00 53 00 45 00 52 00 56 00 45 00 52 00 04 00 12 00 62 00 69 00 67 00 69 00 64 00 2e 00 63 00 6f 00 6d 00 03 00 30 00 77 00 69 00 6e 00 64 00 6f 00 77 00 73 00 2d 00 73 00 65 00 72 00 76 00 65 00 72 00 2e 00 62 00 69 00 67 00 69 00 64 00 2e 00 63 00 6f 00 6d 00 05 00 12 00 62 00 69 00 67 00 69 00 64 00 2e 00 63 00 6f 00 6d 00 07 00 08 00 aa 4a 00 dc d6 1c d3 01 00 00 00 00 2017-08-24 15:45:26 DEBUG NtlmChallenge:114 - Windows version = WindowsVersion[WINDOWS_MAJOR_VERSION_10, WINDOWS_MINOR_VERSION_0, 14393, NTLMSSP_REVISION_W2K3] 2017-08-24 15:45:26 TRACE NtlmChallenge:71 - NTLM channel contains MsvAvNdDomainName(2) TargetInfo 2017-08-24 15:45:26 TRACE NtlmChallenge:71 - NTLM channel contains MsvAvNbComputerName(1) TargetInfo 2017-08-24 15:45:26 TRACE NtlmChallenge:71 - NTLM channel contains MsvAvDnsDomainName(4) TargetInfo 2017-08-24 15:45:26 TRACE NtlmChallenge:71 - NTLM channel contains MsvAvDnsComputerName(3) TargetInfo 2017-08-24 15:45:26 TRACE NtlmChallenge:71 - NTLM channel contains MsvAvDnsTreeName(5) TargetInfo 2017-08-24 15:45:26 TRACE NtlmChallenge:71 - NTLM channel contains MsvAvTimestamp(7) TargetInfo 2017-08-24 15:45:26 TRACE NtlmChallenge:71 - NTLM channel contains MsvAvEOL(0) TargetInfo 2017-08-24 15:45:26 DEBUG NtlmAuthenticator:87 - Received NTLM challenge from: BIGID 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 1) credits to SMB2_SESSION_SETUP with message id << 2 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_SESSION_SETUP with message id << 2 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_SESSION_SETUP with message id << 2 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_SESSION_SETUP with message id << 2 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 2 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_SESSION_SETUP with message id << 2 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 511 credits for SMB2_SESSION_SETUP with message id << 2 >>, now available: 511 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_SESSION_SETUP with message id << 2 >> took << 48 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 2 >> to SMB2_SESSION_SETUP with message id << 2 >> 2017-08-24 15:45:27 INFO Connection:173 - Successfully authenticated test1 on xx.x.x.xx, session is 48514876833861 2017-08-24 15:45:27 INFO Session:105 - Connecting to \xx.x.x.xx\SamplingTests on session 48514876833861 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 511) credits to SMB2_TREE_CONNECT with message id << 3 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_TREE_CONNECT with message id << 3 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_TREE_CONNECT with message id << 3 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_TREE_CONNECT with message id << 3 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 3 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_TREE_CONNECT with message id << 3 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 2 credits for SMB2_TREE_CONNECT with message id << 3 >>, now available: 512 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_TREE_CONNECT with message id << 3 >> took << 53 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 3 >> to SMB2_TREE_CONNECT with message id << 3 >> 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 512) credits to SMB2_CREATE with message id << 4 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_CREATE with message id << 4 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_CREATE with message id << 4 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_CREATE with message id << 4 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 4 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_CREATE with message id << 4 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 2 credits for SMB2_CREATE with message id << 4 >>, now available: 513 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_CREATE with message id << 4 >> took << 59 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 4 >> to SMB2_CREATE with message id << 4 >> 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 513) credits to SMB2_QUERY_INFO with message id << 5 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_QUERY_INFO with message id << 5 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_QUERY_INFO with message id << 5 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_QUERY_INFO with message id << 5 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 5 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_QUERY_INFO with message id << 5 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 2 credits for SMB2_QUERY_INFO with message id << 5 >>, now available: 514 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_QUERY_INFO with message id << 5 >> took << 44 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 5 >> to SMB2_QUERY_INFO with message id << 5 >> Change time: Thu Aug 24 15:45:27 MSK 2017 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 514) credits to SMB2_QUERY_INFO with message id << 6 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_QUERY_INFO with message id << 6 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_QUERY_INFO with message id << 6 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_QUERY_INFO with message id << 6 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 6 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_QUERY_INFO with message id << 6 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 2 credits for SMB2_QUERY_INFO with message id << 6 >>, now available: 515 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_QUERY_INFO with message id << 6 >> took << 48 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 6 >> to SMB2_QUERY_INFO with message id << 6 >> Access time: Wed Apr 19 14:35:07 MSK 2017 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 515) credits to SMB2_QUERY_INFO with message id << 7 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_QUERY_INFO with message id << 7 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_QUERY_INFO with message id << 7 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_QUERY_INFO with message id << 7 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 7 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_QUERY_INFO with message id << 7 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 2 credits for SMB2_QUERY_INFO with message id << 7 >>, now available: 516 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_QUERY_INFO with message id << 7 >> took << 44 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 7 >> to SMB2_QUERY_INFO with message id << 7 >> Write time: Thu Aug 24 15:45:27 MSK 2017 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 516) credits to SMB2_TREE_DISCONNECT with message id << 8 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_TREE_DISCONNECT with message id << 8 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_TREE_DISCONNECT with message id << 8 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_TREE_DISCONNECT with message id << 8 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 8 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_TREE_DISCONNECT with message id << 8 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 2 credits for SMB2_TREE_DISCONNECT with message id << 8 >>, now available: 517 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_TREE_DISCONNECT with message id << 8 >> took << 42 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 8 >> to SMB2_TREE_DISCONNECT with message id << 8 >> 2017-08-24 15:45:27 DEBUG Session:147 - Notified of TreeDisconnected <<1>> 2017-08-24 15:45:27 INFO Session:154 - Logging off session 48514876833861 from host xx.x.x.xx 2017-08-24 15:45:27 DEBUG Connection:235 - Granted 1 (out of 517) credits to SMB2_LOGOFF with message id << 9 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:61 - Acquiring write lock to send packet << SMB2_LOGOFF with message id << 9 >> >> 2017-08-24 15:45:27 DEBUG DirectTcpTransport:65 - Writing packet SMB2_LOGOFF with message id << 9 >> 2017-08-24 15:45:27 TRACE DirectTcpTransport:75 - Packet SMB2_LOGOFF with message id << 9 >> sent, lock released. 2017-08-24 15:45:27 DEBUG Promise:163 - Awaiting << 9 >> 2017-08-24 15:45:27 DEBUG PacketReader:70 - Received packet SMB2_LOGOFF with message id << 9 >> 2017-08-24 15:45:27 DEBUG Connection:347 - Server granted us 2 credits for SMB2_LOGOFF with message id << 9 >>, now available: 518 credits 2017-08-24 15:45:27 TRACE Connection:350 - Send/Recv of packet SMB2_LOGOFF with message id << 9 >> took << 44 ms >> 2017-08-24 15:45:27 DEBUG Promise:78 - Setting << 9 >> to SMB2_LOGOFF with message id << 9 >> 2017-08-24 15:45:27 DEBUG Connection:423 - Session << 48514876833861 >> logged off

hierynomus commented 7 years ago

I have no idea why the dates are getting changed. As you can see in the logging we only send SMB2_QUERY_INFO packets, no SMB2_SET_INFO which would normally alter file attributes.

It could be that we're reading the file dates in the wrong order, because I am pretty sure that when you open the file you change the last access time, which is the one that does not seem to be touched. But for that I would have to look into the specifications.

sshklianko commented 7 years ago

Maybe somehow during that query file actually gets into 'Open' state...

Do you have ideas how to overcome that problem? How about your File.getInputStream() method. Maybe If it was possible to instantiate FIle instance having SMB2FileId value - it would be possible to perform a simple read? - Is it possible to have File's constructor public and get File's SMB2FileId by some means?

pepijnve commented 7 years ago

@hierynomus what triggers that query_info in the code? Afaict DiskShare#openFile shouldn't be doing that.

@sshklianko from an SMB2 client perspective you're already doing just about everything you can: you're not sending any write requests at all and you're opening the file for read only usage. What you could try doing is sending a set info request with FileBasicInformation where you set the timestamp fields to the special FileBasicInformation#DONT_UPDATE values. That shouldn't even be necessary, but it might help.

What type of server are you communicating with? Updating the last write/access/change time is a server side operation that you can't really control from the client side except with those special DONT_UPDATE(-1) and DONT_SET(0) values. If the server decides to still update the timestamps regardless of that there's not much you can do about it I'm afraid.

hierynomus commented 7 years ago

The query_info is triggered by the fetch of File.getfileinformation(). But that is also just a read op.

Op 24 aug. 2017 19:40 schreef "Pepijn Van Eeckhoudt" < notifications@github.com>:

@hierynomus https://github.com/hierynomus what triggers that query_info in the code? Afaict DiskShare#openFile shouldn't be doing that.

@sshklianko https://github.com/sshklianko from an SMB2 client perspective you're already doing just about everything you can: you're not sending any write requests at all and you're opening the file for read only usage. What you could try doing is sending a set info request with FileBasicInformation where you set the timestamp fields to the special FileBasicInformation#DONT_UPDATE values. That shouldn't even be necessary, but it might help.

What type of server are you communicating with? Updating the last write/access/change time is a server side operation that you can't really control from the client side except with those special DONT_UPDATE(-1) and DONT_SET(0) values. If the server decides to still update the timestamps regardless of that there's not much you can do about it I'm afraid.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hierynomus/smbj/issues/166#issuecomment-324705685, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHLo96IWJ-EQKsuF-JQuyEb2cKPmq_Hks5sbbWFgaJpZM4PAqL9 .

sshklianko commented 7 years ago

Thank you guys for your responses.

@pepijnve Im using MS Server 2016. My intention is to be able to read the file and it's metadata, this is why it is important for me to not modify any file attributes, so I could use them. I will try the approach you propose.

@hierynomus it should not be the server issue - when I use SMB1 protocol for the same purpose, file attributes are not modified. What is that packet SMB2_CREATE in the log?

hierynomus commented 7 years ago

What you could check is which of the calls updates the timestamps. Is the time updated on the server if the SMB2_CREATE is executed, or when the SMB2_QUERY_INFO is executed.

But do that by checking on the server itself that you're connecting to.

sshklianko commented 7 years ago

@hierynomus I've got an access to server and here is what I found:

when I call DiskShare.openFile() - file gets completely erased. I believe it has to do with the fact it is really a file OPEN command - which prepares file for writing. So there is no problem with reading attributes - it just opens file as before write operation. Also, if you go to SMB2CreateRequest you'll see the SMB2MessageCommandCode.SMB2_CREATE message type being set.

If I use DiskShare.list() operation - it gets me a correct file attributes, but I still need a way to do a simple file read. Can u advice on this?

hierynomus commented 7 years ago

Hi stepan,

If that happens you're specifying the wrong create mode.

Op 25 aug. 2017 7:52 p.m. schreef "Stepan Shklianko" < notifications@github.com>:

@hierynomus https://github.com/hierynomus I've got an access to server and here is what I found:

when I call DiskShare.openFile() - file gets completely erased. I believe it has to do with the fact it is really a file OPEN command - which prepares file for writing. So there is no problem with reading attributes - it just opens file as before write operation. Also, if you go to SMB2CreateRequest you'll see the SMB2MessageCommandCode.SMB2_CREATE dialect being set.

If I use DiskShare.list() operation - it gets me a correct file attributes, but I still need a way to do a simple file read. Can u advice on this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hierynomus/smbj/issues/166#issuecomment-324992644, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHLo0Rky1894IuE77yaAIduefOeuGXJks5sbwnvgaJpZM4PAqL9 .

sshklianko commented 7 years ago

Is there supposed to be any "create" mode for read operation?

hierynomus commented 7 years ago

Smb2CreateDisposition.open will open the file without doing anything to it.

Sent from my Samsung SM-G950F using FastHub

sshklianko commented 7 years ago

That did the trick - I was able to read the file using Smb2CreateDisposition.open. Thanks @hierynomus

One more question: is there a way to get a file size and file owner somehow from file attributes?

hierynomus commented 7 years ago

The file size is in FileBasicInformation.getEndOfFile(). The file owner I'm not completely sure about, @pepijnve do you know how to obtain that?

pepijnve commented 7 years ago

That's in the security descriptor which you can get using DiskEntry#getSecurityInformation. Note that you'll only get the SID value for the owner. Resolving that to a name can be done using the lsarpc interface (LsarLookupSids and LsarLookupNames), but that hasn't been implemented yet as far as I know.

sshklianko commented 7 years ago

Ok, Thank you guys. I believe this ussue may be closed now.

vicnumberone commented 5 years ago

hi guys, can you tell me are you fixed problem with getting owner? Now I can get only SID but not String value of that. Thank!

pepijnve commented 5 years ago

If you want the SID literal (e.g., S-1-5-32-544), just call toString() on the SID object. If you need the name of the user or group, see my answer above. https://github.com/rapid7/smbj-rpc provides the components you need to do the necessary RPC calls.

DanskerDave commented 1 year ago

Regarding... https://github.com/hierynomus/smbj/issues/166#issuecomment-325377426

The file size is in FileBasicInformation.getEndOfFile().

...I could not find the size there. Found it here instead:: FileStandardInformation.getEndOfFile().