Class DFSPathResolver

java.lang.Object
com.hierynomus.smbj.paths.DFSPathResolver
All Implemented Interfaces:
PathResolver

public class DFSPathResolver extends Object implements PathResolver
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
    • FSCTL_DFS_GET_REFERRALS

      private static final long FSCTL_DFS_GET_REFERRALS
      See Also:
    • FSCTL_DFS_GET_REFERRALS_EX

      private static final long FSCTL_DFS_GET_REFERRALS_EX
      See Also:
    • statusHandler

      private final StatusHandler statusHandler
    • wrapped

      private final PathResolver wrapped
    • referralCache

      private ReferralCache referralCache
    • domainCache

      private DomainCache domainCache
    • transactTimeout

      private long transactTimeout
  • Constructor Details

    • DFSPathResolver

      public DFSPathResolver(PathResolver wrapped, long transactTimeout)
  • Method Details

    • resolve

      public <T> T resolve(Session session, SMB2Packet responsePacket, SmbPath smbPath, PathResolver.ResolveAction<T> action) throws PathResolveException
      Description copied from interface: PathResolver
      Reactive path resolution based on response packet
      Specified by:
      resolve in interface PathResolver
      Parameters:
      session -
      responsePacket -
      smbPath -
      Returns:
      Throws:
      PathResolveException
    • statusHandler

      public StatusHandler statusHandler()
      Specified by:
      statusHandler in interface PathResolver
    • resolve

      public <T> T resolve(Session session, SmbPath smbPath, PathResolver.ResolveAction<T> action) throws PathResolveException
      Description copied from interface: PathResolver
      Proactive path resolution based on response packet
      Specified by:
      resolve in interface PathResolver
      Parameters:
      session -
      smbPath -
      Returns:
      Throws:
      PathResolveException
    • start

      private <T> T start(Session session, SmbPath uncPath, PathResolver.ResolveAction<T> action) throws PathResolveException
      Throws:
      PathResolveException
    • step1

      private <T> T step1(Session session, DFSPathResolver.ResolveState<T> state) throws DFSException
      Step 1: If the path has only one path component (for example, \abc), go to step 12; otherwise, go to step 2.
      Throws:
      DFSException
    • step2

      private <T> T step2(Session session, DFSPathResolver.ResolveState<T> state) throws DFSException
      Step 2: Look up the path in ReferralCache if a cache is being maintained. If no cache is being maintained, go to step 5. 1. If no matching entry is found in ReferralCache, go to step 5. 2. If an entry's TTL has expired: - If RootOrLink indicates DFS root targets, goto step 5. - If RootOrLink indicates DFS link targets, goto step 9. 3. If an entry contains DFS link targets as indicated by RootOrLink, go to step 4; otherwise, go to step 3.
      Throws:
      DFSException
    • step3

      private <T> T step3(Session session, DFSPathResolver.ResolveState<T> state, ReferralCache.ReferralCacheEntry lookup)
      Step 3: [ReferralCache hit, unexpired TTL] Replace the portion of the path that matches DFSPathPrefix of the ReferralCache entry with the DFS target path of TargetHint of the ReferralCache entry. For example, if the path is \MyDomain\MyDfs\MyDir and the ReferralCache entry contains \MyDomain\MyDfs with a DFS target path of \someserver\someshare\somepath, the effective path becomes \someserver\someshare\somepath\MyDir. Go to step 8.
    • step4

      private <T> T step4(Session session, DFSPathResolver.ResolveState<T> state, ReferralCache.ReferralCacheEntry lookup) throws DFSException
      Step 4: [ReferralCache hit, unexpired TTL, RootOrLink=link] 1. If the second component of the path is "SYSVOL" or "NETLOGON" go to step 3. 2. Check the Interlink element of the ReferralCache entry. - If Interlink is set in the ReferralCache entry,then the TargetHint is in another DFS namespace. Go to step 11. - If Interlink is not set in the ReferralCache entry then the TargetHint is not in another DFS namespace. Go to step 3.
      Throws:
      DFSException
    • step5

      private <T> T step5(Session session, DFSPathResolver.ResolveState<T> state) throws DFSException
      Step 5: [ReferralCache miss] [ReferralCache hit, expired TTL, RootOrLink=root] Look up the first path component in DomainCache. 1. If no matching DomainCache entry is found, use the first path component as the host name for DFS root referral request purposes. Go to step 6. 2. If a matching DomainCache entry is found: 1. If DCHint is not valid, send DC referral request, as specified in section 3.1.4.2, providing "DC", BootstrapDC, UserCredentials, MaxOutputSizeff, and Path as parameters. The processing of the referral response is specified in section 3.1.5.4.2. If the referral request fails, go to step 13. 2. If the second path component is "SYSVOL" or "NETLOGON", go to step 10. 3. Use DCHint as host name for DFS root referral request purposes. Go to step 6.
      Throws:
      DFSException
    • step6

      private <T> T step6(Session session, DFSPathResolver.ResolveState<T> state) throws DFSException
      [DFS Root referral request] Issue a DFS root referral request, as specified in section 3.1.4.2, providing "ROOT", the first path component, UserCredentials, MaxOutputSize, and Path as parameters. The processing of the referral response and/or error is as specified in section 3.1.5.4.3, which will update the ReferralCache on success. On DFS root referral request success, go to step 7. On DFS root referral request failure: 1. If the immediately preceding processing step was step 5.2.3, this is a domain name or path. Go to step 13. 2. If processing of this I/O request encountered a ReferralCache hit, or one of its DFS referral requests succeeded (as would have occurred in the case of a previous Interlink - see step 11 - or a domain root referral, when entering from step 5), the path is in a DFS namespace. Go to step 14. 3. The path is not a DFS path and no further processing is required. Go to step 12.
      Throws:
      DFSException
    • step7

      private <T> T step7(Session session, DFSPathResolver.ResolveState<T> state, ReferralCache.ReferralCacheEntry lookup) throws DFSException
      [DFS root referral success] If the current ReferralCache entry's RootOrLink indicates root targets, go to step 3; otherwise, go to step 4.
      Throws:
      DFSException
    • step8

      private <T> T step8(Session session, DFSPathResolver.ResolveState<T> state, ReferralCache.ReferralCacheEntry lookup)
      Step 8: [I/O request, path fully resolved] Issue I/O operation to TargetHint of ReferralCache entry. 1. If the I/O operation fails with STATUS_PATH_NOT_COVERED. - If the RootOrLink of ReferralCache entry indicates link targets, set the failure status to the last error that occurred and go to step 14. - If the RootOrLink of ReferralCache entry indicates root targets, the process is as specified in section 3.1.5.1. If this processing does not successfully determine a ReferralCache entry to traverse the link, set the failure status to the last error that occurred and go to step 14. - ReferralCache entry for the link determined successfully. Go to step 4. 2. If the I/O operation fails with an error other than STATUS_PATH_NOT_COVERED, then the process is as specified in section 3.1.5.2. If the processing of that section specifies a new TargetHint, repeat step 8. Otherwise, set the failure status to the last error that occurred and go to step 14. 3. If the I/O operation is successful, the process is as specified in section 3.1.5.3. Complete the I/O operation and user/application-initiated I/O request with success.
    • step9

      private <T> T step9(Session session, DFSPathResolver.ResolveState<T> state, ReferralCache.ReferralCacheEntry lookup) throws DFSException
      Step 9: [ReferralCache hit, expired TTL, RootOrLink=link] The link referral request is issued to a DFS root target of the namespace. Find the root ReferralCache entry corresponding to the first two path components, noting that this will already be in the cache due to processing that resulted in acquiring the expired link ReferralCache entry. Issue a DFS link referral request, as specified in section 3.1.4.2, providing "LINK", TargetHint of the root ReferralCache entry, UserCredentials, MaxOutputSize, and Path as parameters, and process the DFS referral response and/or error as specified in section 3.1.5.4.3, which will update the ReferralCache on success.

      If the DFS Link referral request fails, set the failure status to the last error that occurred and go to step 14. Otherwise: 1. If the RootOrLink of the refreshed ReferralCache entry indicates DFS root targets, go to step 3. 2. If the RootOrLink of the refreshed ReferralCache entry indicates DFS link targets, go to step 4.

      Throws:
      DFSException
    • step10

      private <T> T step10(Session session, DFSPathResolver.ResolveState<T> state, DomainCache.DomainCacheEntry domainCacheEntry) throws DFSException
      Step 10: [sysvol referral request] Issue a sysvol referral request, as specified in section 3.1.4.2, providing 'SYSVOL', the DCHint DC of the DomainCache entry that corresponds to the domain name in the first path component, UserCredentials, MaxOutputSize, and Path as parameters. The processing of the referral response and/or error is as specified in section 3.1.5.4.4, which will update the ReferralCache on success. If the referral request is successful, go to step 3; otherwise, go to step 13.
      Throws:
      DFSException
    • step11

      private <T> T step11(Session session, DFSPathResolver.ResolveState<T> state, ReferralCache.ReferralCacheEntry lookup) throws DFSException
      Step 11: [interlink] Replace the portion of the path that matches the DFSPathPrefix of the ReferralCache entry with TargetHint. For example, if the path is \MyDomain\MyDfs\MyLink\MyDir and the referral entry contains \MyDomain\MyDfs\MyLink with a DFS target path of \someserver\someshare\somepath, the effective path becomes \someserver\someshare\somepath\MyDir. Go to step 2.
      Throws:
      DFSException
    • step12

      private <T> T step12(DFSPathResolver.ResolveState<T> state)
      Step 12: [not DFS] The path does not correspond to a DFS namespace or a SYSVOL/NETLOGON share. Do not change the path, and return an implementation-defined error. The user/application initiated I/O request is handled by the local operating system.
    • step13

      private <T> T step13(Session session, DFSPathResolver.ResolveState<T> state, DFSPathResolver.ReferralResult result) throws DFSException
      Step 13: [Cannot get DC for domain] The first path component is a domain name. Fail the I/O operation and user/application-initiated I/O request with the last error code that occurred before the jump to this step.
      Throws:
      DFSException
    • step14

      private <T> T step14(Session session, DFSPathResolver.ResolveState<T> state, DFSPathResolver.ReferralResult result) throws DFSException
      Step 14: [DFS path] The path is known to be in a DFS namespace, but the DFS root referral request or DFS Link referral request has failed. Complete the user/application-initiated I/O request with the error code that occurred before the jump to this step.
      Throws:
      DFSException
    • sendDfsReferralRequest

      private DFSPathResolver.ReferralResult sendDfsReferralRequest(DFSPathResolver.DfsRequestType type, String hostName, Session session, DFSPath path) throws DFSException
      Throws:
      DFSException
    • getReferral

      Throws:
      TransportException
      Buffer.BufferException
    • handleReferralResponse

      private DFSPathResolver.ReferralResult handleReferralResponse(DFSPathResolver.DfsRequestType type, SMB2IoctlResponse response, DFSPath originalPath) throws Buffer.BufferException
      Throws:
      Buffer.BufferException
    • handleRootOrLinkReferralResponse

      private void handleRootOrLinkReferralResponse(DFSPathResolver.ReferralResult result, SMB2GetDFSReferralResponse response)
    • handleDCReferralResponse

      private void handleDCReferralResponse(DFSPathResolver.ReferralResult result, SMB2GetDFSReferralResponse response)