hierynomus / smbj

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

SMBApiException: STATUS_PRIVILEGE_NOT_HELD #623

Closed cliviu closed 3 years ago

cliviu commented 3 years ago

Hi,

 I try to overwrite a file opened like this : 

File toFile = rootShare.openFile(destinationPath, new HashSet<>(Arrays.asList(AccessMask.MAXIMUM_ALLOWED)), null, SMB2ShareAccess.ALL, overwrite ? SMB2CreateDisposition.FILE_OVERWRITE_IF : SMB2CreateDisposition.FILE_CREATE, null);

I got the following Exception:

com.hierynomus.mssmb2.SMBApiException: STATUS_PRIVILEGE_NOT_HELD (0xc0000061): Create failed for \\file02\smb_test\archive\Test.txt
    at com.hierynomus.smbj.share.Share.receive(Share.java:371)
    at com.hierynomus.smbj.share.Share.sendReceive(Share.java:351)
    at com.hierynomus.smbj.share.Share.createFile(Share.java:159)
    at com.hierynomus.smbj.share.DiskShare.createFileAndResolve(DiskShare.java:97)
    at com.hierynomus.smbj.share.DiskShare.resolveAndCreateFile(DiskShare.java:79)
    at com.hierynomus.smbj.share.DiskShare.open(DiskShare.java:66)
    at com.hierynomus.smbj.share.DiskShare.openFile(DiskShare.java:148)

It looks like the Exception comes only when the negotiated Protocol is SMB 2_1, with SMB 2_0 works.

Any ideas ?

hierynomus commented 3 years ago

Hi Liviu,

There's some explanation here: https://github.com/hierynomus/smbj/issues/357 by @pepijnve.

I'm not sure why this only happens with SMB2.1 and not with 2.02, would need to look into that.

cliviu commented 3 years ago

thank you @hierynomus . Still I'm not sure how to interpret this .. Basically the way how I'm opening the file for owerwrite should be ok, right ?

hierynomus commented 3 years ago

You might want to try with a lesser AccessMask than the MAXIMUM_ALLOWED one. I've seen bugs in the past with that AccessMask. Just try to request the needed access.

cliviu commented 3 years ago

ok, I will try with GENERIC_WRITE . I was inspired by this thread : https://github.com/hierynomus/smbj/issues/355 when setting MAXIMUM_ALLOWED.

cliviu commented 3 years ago

Thank you, big time, GENERIC_WRITE instead of MAXIMUM_ALLOWED fixed the problem for me.