Пример #1
0
        /// <summary>
        /// Create DfsReferralRequest packet
        /// </summary>
        /// <param name="maxReferralLevel">
        /// A 16-bit integer that indicates the highest DFS referral version understood by the client.
        /// </param>
        /// <param name="fileName">
        /// Specifies the UNC path or zero length string to be resolved.
        /// This parameter should not be null-terminated. parameter length precedes parameter in structure to indicate bounds.
        ///
        /// </param>
        /// <param name="flag">
        /// A 16 bit integer which indicates if client site name has been provided.
        /// "0x1": Site name included, "0x0": Site name is not included.
        /// </param>
        /// <param name="siteName">
        /// A string which specifies the client computer's Active Directory Domain Service site name.
        /// This parameter should not be null-terminated. parameter length precedes parameter in structure to indicate bounds.
        /// </param>
        /// <exception cref="ArgumentException">fileName is not a valid string for DFS referral</exception>
        ///
        public DfscReferralRequestEXPacket CreateDfscReferralRequestPacketEX(ushort maxReferralLevel, string fileName,
                                                                             REQ_GET_DFS_REFERRAL_RequestFlags flag, string siteName = null)
        {
            /* Remove first backslash from fileName
             * To create valid string for the RequestFileName field of the REQ_DFS_REFERRAL_EX structure
             * Example:
             * "\\contoso.com\share\filepath" becomes "\contoso.com\share\filepath"
             */
            if (fileName.Length > 0 && fileName.StartsWith(@"\\"))
            {
                fileName = fileName.Substring(1);
            }

            fileName += '\0';

            //Build REQ_DFS_REFERRAL_EX structure
            REQ_GET_DFS_REFERRAL_EX DFSRequestEX = new REQ_GET_DFS_REFERRAL_EX();

            DFSRequestEX.MaxReferralLevel = maxReferralLevel;
            DFSRequestEX.RequestFlags     = flag;

            REQ_GET_DFS_REFERRAL_RequestData requestData = new REQ_GET_DFS_REFERRAL_RequestData();

            requestData.RequestFileName       = Encoding.Unicode.GetBytes(fileName);
            requestData.RequestFileNameLength = (ushort)requestData.RequestFileName.Length;

            DFSRequestEX.RequestDataLength = (uint)(requestData.RequestFileNameLength + 2);

            if (DFSRequestEX.RequestFlags == REQ_GET_DFS_REFERRAL_RequestFlags.SiteName)
            {
                if (siteName == null)
                {
                    throw new ArgumentNullException("siteName is null when flag is set");
                }

                requestData.SiteName            = Encoding.Unicode.GetBytes(siteName);
                requestData.SiteNameLength      = (ushort)requestData.SiteName.Length;
                DFSRequestEX.RequestDataLength += (uint)(requestData.SiteNameLength + 2);
            }

            DFSRequestEX.RequestData = requestData;

            //Build REQ_GET_DFS_REFERRAL_EX packet
            DfscReferralRequestEXPacket packet = new DfscReferralRequestEXPacket();

            packet.ReferralRequest = DFSRequestEX;

            return(packet);
        }
Пример #2
0
 /// <summary>
 /// Encode the packet to the specified transport protocol's payload. Then Send the request to server.
 /// </summary>
 /// <param name="packet">
 /// The REQ_GET_DFS_REFERRAL packet to be sent.
 /// </param>
 /// <param name="EXpacket">
 /// The REQ_GET_DFS_REFERRAL_EX packet to be sent.
 /// MUST be null if transport is not SMB2 or SMB3
 /// </param>
 /// <exception cref="System.ArgumentNullException">The packet to be sent is null.</exception>
 /// <exception cref="System.InvalidOperationException">The transport is not connected.</exception>
 public void SendPacket(DfscReferralRequestEXPacket EXpacket = null, DfscReferralRequestPacket packet = null)
 {
     if (packet == null && EXpacket == null)
     {
         throw new ArgumentNullException("packet is null");
     }
     else if (packet == null)
     {
         this.transport.SendDfscPayload(EXpacket.ToBytes(), true);
     }
     else
     {
         this.transport.SendDfscPayload(packet.ToBytes(), false);
     }
 }
Пример #3
0
        /// <summary>
        /// Sends a REQ_GET_DFS_REFERRAL or REQ_GET_DFS_REFERRAL_EX to the server and captures the RESP_GET_DFS_REFERRAL response.
        /// </summary>
        /// <param name="packetEX">Optional REQ_GET_DFS_REFERRAL_EX packet to be sent to the server</param>
        /// <param name="packet">Optional REQ_GET_DFS_REFERRAL packet to be sent to the server</param>
        /// <exception cref="ArgumentNullException">There must be one non null request packet.</exception>
        /// <returns></returns>
        public DfscReferralResponsePacket SendAndRecieveDFSCReferralMessages(out uint status, TimeSpan timeout, DfscReferralRequestEXPacket packetEX = null, DfscReferralRequestPacket packet = null)
        {
            SendPacket(packetEX, packet);

            return(ExpectPacket(timeout, out status));
        }