SharpCifs.Smb.SmbFile.ResolveDfs C# (CSharp) Method

ResolveDfs() private method

private ResolveDfs ( ServerMessageBlock request ) : void
request ServerMessageBlock
return void
        internal virtual void ResolveDfs(ServerMessageBlock request)
        {
            if (!_enableDfs)
            {
                Connect0();
                return;
            }

            if (request is SmbComClose)
            {
                return;
            }
            Connect0();
            DfsReferral dr = Dfs.Resolve(Tree.Session.transport.TconHostName, Tree.Share, Unc
                , Auth);
            if (dr != null)
            {
                string service = null;
                if (request != null)
                {
                    switch (request.Command)
                    {
                        case ServerMessageBlock.SmbComTransaction:
                        case ServerMessageBlock.SmbComTransaction2:
                            {
                                switch (((SmbComTransaction)request).SubCommand & 0xFF)
                                {
                                    case SmbComTransaction.Trans2GetDfsReferral:
                                        {
                                            break;
                                        }

                                    default:
                                        {
                                            service = "A:";
                                            break;
                                        }
                                }
                                break;
                            }

                        default:
                            {
                                service = "A:";
                                break;
                            }
                    }
                }
                DfsReferral start = dr;
                SmbException se = null;
                do
                {
                    try
                    {
                        if (Log.Level >= 2)
                        {
                            Log.WriteLine("DFS redirect: " + dr);
                        }
                        UniAddress addr = UniAddress.GetByName(dr.Server);
                        SmbTransport trans = SmbTransport.GetSmbTransport(addr, Url.Port);
                        trans.Connect();
                        Tree = trans.GetSmbSession(Auth).GetSmbTree(dr.Share, service);
                        if (dr != start && dr.Key != null)
                        {
                            dr.Map.Put(dr.Key, dr);
                        }
                        se = null;
                        break;
                    }
                    catch (IOException ioe)
                    {
                        if (ioe is SmbException)
                        {
                            se = (SmbException)ioe;
                        }
                        else
                        {
                            se = new SmbException(dr.Server, ioe);
                        }
                    }
                    dr = dr.Next;
                }
                while (dr != start);
                if (se != null)
                {
                    throw se;
                }
                if (Log.Level >= 3)
                {
                    Log.WriteLine(dr);
                }
                _dfsReferral = dr;
                if (dr.PathConsumed < 0)
                {
                    dr.PathConsumed = 0;
                }
                else
                {
                    if (dr.PathConsumed > Unc.Length)
                    {
                        dr.PathConsumed = Unc.Length;
                    }
                }
                string dunc = Runtime.Substring(Unc, dr.PathConsumed);
                if (dunc.Equals(string.Empty))
                {
                    dunc = "\\";
                }
                if (!dr.Path.Equals(string.Empty))
                {
                    dunc = "\\" + dr.Path + dunc;
                }
                Unc = dunc;
                if (request != null && request.Path != null && request.Path.EndsWith("\\") && dunc
                    .EndsWith("\\") == false)
                {
                    dunc += "\\";
                }
                if (request != null)
                {
                    request.Path = dunc;
                    request.Flags2 |= SmbConstants.Flags2ResolvePathsInDfs;
                }
            }
            else
            {
                if (Tree.InDomainDfs && !(request is NtTransQuerySecurityDesc) && !(request is SmbComClose
                    ) && !(request is SmbComFindClose2))
                {
                    throw new SmbException(NtStatus.NtStatusNotFound, false);
                }
                if (request != null)
                {
                    request.Flags2 &= ~SmbConstants.Flags2ResolvePathsInDfs;
                }
            }
        }

Usage Example

Example #1
0
 /// <summary>
 /// Changes the name of the file this <code>SmbFile</code> represents to the name
 /// designated by the <code>SmbFile</code> argument.
 /// </summary>
 /// <remarks>
 /// Changes the name of the file this <code>SmbFile</code> represents to the name
 /// designated by the <code>SmbFile</code> argument.
 /// <p/>
 /// <i>Remember: <code>SmbFile</code>s are immutible and therefore
 /// the path associated with this <code>SmbFile</code> object will not
 /// change). To access the renamed file it is necessary to construct a
 /// new <tt>SmbFile</tt></i>.
 /// </remarks>
 /// <param name="dest">An <code>SmbFile</code> that represents the new pathname</param>
 /// <exception cref="System.ArgumentNullException">If the <code>dest</code> argument is <code>null</code>
 /// 	</exception>
 /// <exception cref="SharpCifs.Smb.SmbException"></exception>
 public virtual void RenameTo(SmbFile dest)
 {
     if (GetUncPath0().Length == 1 || dest.GetUncPath0().Length == 1)
     {
         throw new SmbException("Invalid operation for workgroups, servers, or shares");
     }
     ResolveDfs(null);
     dest.ResolveDfs(null);
     if (!Tree.Equals(dest.Tree))
     {
         throw new SmbException("Invalid operation for workgroups, servers, or shares");
     }
     if (Log.Level >= 3)
     {
         Log.WriteLine("renameTo: " + Unc + " -> " + dest.Unc);
     }
     _attrExpiration = _sizeExpiration = 0;
     dest._attrExpiration = 0;
     Send(new SmbComRename(Unc, dest.Unc), Blank_resp());
 }