/** * @return the transportContext */ @Deprecated public CIFSContext getTransportContext () { return this.getContext(); }
/** * @return the transportContext */ @Deprecated public CIFSContext getTransportContext () { return this.getContext(); }
private void processAces ( ACE[] aces, boolean resolveSids ) throws IOException { String server = this.fileLocator.getServerWithDfs(); int ai; if ( resolveSids ) { SID[] sids = new SID[aces.length]; for ( ai = 0; ai < aces.length; ai++ ) { sids[ ai ] = aces[ ai ].getSID(); } for ( int off = 0; off < sids.length; off += 64 ) { int len = sids.length - off; if ( len > 64 ) len = 64; getContext().getSIDResolver().resolveSids(getContext(), server, sids, off, len); } } else { for ( ai = 0; ai < aces.length; ai++ ) { aces[ ai ].getSID().initContext(server, getContext()); } } }
private void processAces ( ACE[] aces, boolean resolveSids ) throws IOException { String server = this.fileLocator.getServerWithDfs(); int ai; if ( resolveSids ) { SID[] sids = new SID[aces.length]; for ( ai = 0; ai < aces.length; ai++ ) { sids[ ai ] = aces[ ai ].getSID(); } for ( int off = 0; off < sids.length; off += 64 ) { int len = sids.length - off; if ( len > 64 ) len = 64; getContext().getSIDResolver().resolveSids(getContext(), server, sids, off, len); } } else { for ( ai = 0; ai < aces.length; ai++ ) { aces[ ai ].getSID().initContext(server, getContext()); } } }
protected void processAllowedSIDs(final SmbFile file, final SID sid, final Set<SID> sidSet) { if (logger.isDebugEnabled()) { logger.debug("SID:" + sid); } final int type = sid.getType(); sidSet.add(sid); if (type == SID.SID_TYPE_DOM_GRP || type == SID.SID_TYPE_ALIAS) { try { CIFSContext context = file.getContext(); final SID[] children = context.getSIDResolver().getGroupMemberSids(context, file.getServer(), sid.getDomainSid(), sid.getRid(), jcifs.smb.SID.SID_FLAG_RESOLVE_SIDS); for (SID child : children) { if (!sidSet.contains(child)) { processAllowedSIDs(file, child, sidSet); } } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Exception on SID processing.", e); } } } }
@Override public SID getOwnerUser ( boolean resolve ) throws IOException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { SecurityDescriptor desc = querySecurity(th, SecurityInfo.OWNER_SECURITY_INFO); SID ownerUser = desc.getOwnerUserSid(); if ( ownerUser == null ) { return null; } String server = this.fileLocator.getServerWithDfs(); if ( resolve ) { ownerUser.resolve(server, getContext()); } else { ownerUser.initContext(server, getContext()); } return ownerUser; } }
@Override public SID getOwnerGroup ( boolean resolve ) throws IOException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { SecurityDescriptor desc = querySecurity(th, SecurityInfo.GROUP_SECURITY_INFO); SID ownerGroup = desc.getOwnerGroupSid(); if ( ownerGroup == null ) { return null; } String server = this.fileLocator.getServerWithDfs(); if ( resolve ) { ownerGroup.resolve(server, getContext()); } else { ownerGroup.initContext(server, getContext()); } return ownerGroup; } }
@Override public SID getOwnerUser ( boolean resolve ) throws IOException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { SecurityDescriptor desc = querySecurity(th, SecurityInfo.OWNER_SECURITY_INFO); SID ownerUser = desc.getOwnerUserSid(); if ( ownerUser == null ) { return null; } String server = this.fileLocator.getServerWithDfs(); if ( resolve ) { ownerUser.resolve(server, getContext()); } else { ownerUser.initContext(server, getContext()); } return ownerUser; } }
@Override public SID getOwnerGroup ( boolean resolve ) throws IOException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { SecurityDescriptor desc = querySecurity(th, SecurityInfo.GROUP_SECURITY_INFO); SID ownerGroup = desc.getOwnerGroupSid(); if ( ownerGroup == null ) { return null; } String server = this.fileLocator.getServerWithDfs(); if ( resolve ) { ownerGroup.resolve(server, getContext()); } else { ownerGroup.initContext(server, getContext()); } return ownerGroup; } }
String p = this.fileLocator.getParent(); try ( SmbTreeHandle th = ensureTreeConnected(); SmbFile parent = new SmbFile(p, getContext()) ) { try { if ( !parent.exists() ) {
@Override public long getDiskFreeSpace () throws SmbException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { int t = getType(); if ( t == TYPE_SHARE || t == TYPE_FILESYSTEM ) { AllocInfo allocInfo = fetchAllocationInfo(th); this.size = allocInfo.getCapacity(); this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); return allocInfo.getFree(); } return 0L; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public long getDiskFreeSpace () throws SmbException { try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { int t = getType(); if ( t == TYPE_SHARE || t == TYPE_FILESYSTEM ) { AllocInfo allocInfo = fetchAllocationInfo(th); this.size = allocInfo.getCapacity(); this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); return allocInfo.getFree(); } return 0L; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
SmbFile ( SmbResource context, String name, boolean loadedAttributes, int type, int attributes, long createTime, long lastModified, long lastAccess, long size ) throws MalformedURLException { this( isWorkgroup(context) ? new URL(null, "smb://" + checkName(name) + "/", Handler.SMB_HANDLER) : new URL(context.getLocator().getURL(), checkName(name) + ( ( attributes & ATTR_DIRECTORY ) > 0 ? "/" : "" )), context.getContext()); if ( !isWorkgroup(context) ) { setContext(context, name + ( ( attributes & ATTR_DIRECTORY ) > 0 ? "/" : "" )); } /* * why? am I going around in circles? * this.type = type == TYPE_WORKGROUP ? 0 : type; */ this.fileLocator.updateType(type); this.attributes = attributes; this.createTime = createTime; this.lastModified = lastModified; this.lastAccess = lastAccess; this.size = size; this.isExists = true; if ( loadedAttributes ) { this.attrExpiration = this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); } }
SmbFile ( SmbResource context, String name, boolean loadedAttributes, int type, int attributes, long createTime, long lastModified, long lastAccess, long size ) throws MalformedURLException { this( isWorkgroup(context) ? new URL(null, "smb://" + checkName(name) + "/", Handler.SMB_HANDLER) : new URL(context.getLocator().getURL(), checkName(name) + ( ( attributes & ATTR_DIRECTORY ) > 0 ? "/" : "" )), context.getContext()); if ( !isWorkgroup(context) ) { setContext(context, name + ( ( attributes & ATTR_DIRECTORY ) > 0 ? "/" : "" )); } /* * why? am I going around in circles? * this.type = type == TYPE_WORKGROUP ? 0 : type; */ this.fileLocator.updateType(type); this.attributes = attributes; this.createTime = createTime; this.lastModified = lastModified; this.lastAccess = lastAccess; this.size = size; this.isExists = true; if ( loadedAttributes ) { this.attrExpiration = this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); } }
@Override public long length () throws SmbException { if ( this.sizeExpiration > System.currentTimeMillis() ) { return this.size; } try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { int t = getType(); if ( t == TYPE_SHARE ) { this.size = fetchAllocationInfo(th).getCapacity(); } else if ( !this.fileLocator.isRoot() && t != TYPE_NAMED_PIPE ) { queryPath(th, this.fileLocator.getUNCPath(), FileInformation.FILE_STANDARD_INFO); } else { this.size = 0L; } this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); return this.size; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public long length () throws SmbException { if ( this.sizeExpiration > System.currentTimeMillis() ) { return this.size; } try ( SmbTreeHandleImpl th = ensureTreeConnected() ) { int t = getType(); if ( t == TYPE_SHARE ) { this.size = fetchAllocationInfo(th).getCapacity(); } else if ( !this.fileLocator.isRoot() && t != TYPE_NAMED_PIPE ) { queryPath(th, this.fileLocator.getUNCPath(), FileInformation.FILE_STANDARD_INFO); } else { this.size = 0L; } this.sizeExpiration = System.currentTimeMillis() + getContext().getConfig().getAttributeCacheTimeout(); return this.size; } catch ( CIFSException e ) { throw SmbException.wrap(e); } }
@Override public ACE[] getShareSecurity ( boolean resolveSids ) throws IOException { try ( SmbTreeHandleInternal th = ensureTreeConnected() ) { String server = this.fileLocator.getServerWithDfs(); ACE[] aces; MsrpcShareGetInfo rpc = new MsrpcShareGetInfo(server, th.getConnectedShare()); try ( DcerpcHandle handle = DcerpcHandle.getHandle("ncacn_np:" + server + "[\\PIPE\\srvsvc]", getContext()) ) { handle.sendrecv(rpc); if ( rpc.retval != 0 ) { throw new SmbException(rpc.retval, true); } aces = rpc.getSecurity(); if ( aces != null ) { processAces(aces, resolveSids); } } return aces; } }
SecurityDescriptor querySecurity ( SmbTreeHandleImpl th, int types ) throws CIFSException { if ( th.isSMB2() ) { Smb2QueryInfoRequest req = new Smb2QueryInfoRequest(th.getConfig()); req.setInfoType(Smb2Constants.SMB2_0_INFO_SECURITY); req.setAdditionalInformation(types); Smb2QueryInfoResponse resp = withOpen(th, req); return resp.getInfo(SecurityDescriptor.class); } if ( !th.hasCapability(SmbConstants.CAP_NT_SMBS) ) { throw new SmbUnsupportedOperationException("Not supported without CAP_NT_SMBS/SMB2"); } NtTransQuerySecurityDescResponse response = new NtTransQuerySecurityDescResponse(getContext().getConfig()); try ( SmbFileHandleImpl f = openUnshared(O_RDONLY, READ_CONTROL, DEFAULT_SHARING, 0, isDirectory() ? 1 : 0) ) { /* * NtTrans Query Security Desc Request / Response */ NtTransQuerySecurityDesc request = new NtTransQuerySecurityDesc(getContext().getConfig(), f.getFid(), types); response = th.send(request, response, RequestParam.NO_RETRY); return response.getSecurityDescriptor(); } }
SecurityDescriptor querySecurity ( SmbTreeHandleImpl th, int types ) throws CIFSException { if ( th.isSMB2() ) { Smb2QueryInfoRequest req = new Smb2QueryInfoRequest(th.getConfig()); req.setInfoType(Smb2Constants.SMB2_0_INFO_SECURITY); req.setAdditionalInformation(types); Smb2QueryInfoResponse resp = withOpen(th, req); return resp.getInfo(SecurityDescriptor.class); } if ( !th.hasCapability(SmbConstants.CAP_NT_SMBS) ) { throw new SmbUnsupportedOperationException("Not supported without CAP_NT_SMBS/SMB2"); } NtTransQuerySecurityDescResponse response = new NtTransQuerySecurityDescResponse(getContext().getConfig()); try ( SmbFileHandleImpl f = openUnshared(O_RDONLY, READ_CONTROL, DEFAULT_SHARING, 0, isDirectory() ? 1 : 0) ) { /* * NtTrans Query Security Desc Request / Response */ NtTransQuerySecurityDesc request = new NtTransQuerySecurityDesc(getContext().getConfig(), f.getFid(), types); response = th.send(request, response, RequestParam.NO_RETRY); return response.getSecurityDescriptor(); } }
@Override public ACE[] getShareSecurity ( boolean resolveSids ) throws IOException { try ( SmbTreeHandleInternal th = ensureTreeConnected() ) { String server = this.fileLocator.getServerWithDfs(); ACE[] aces; MsrpcShareGetInfo rpc = new MsrpcShareGetInfo(server, th.getConnectedShare()); try ( DcerpcHandle handle = DcerpcHandle.getHandle("ncacn_np:" + server + "[\\PIPE\\srvsvc]", getContext()) ) { handle.sendrecv(rpc); if ( rpc.retval != 0 ) { throw new SmbException(rpc.retval, true); } aces = rpc.getSecurity(); if ( aces != null ) { processAces(aces, resolveSids); } } return aces; } }