Beispiel #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">
        /// Specify the UNC path or zero length string to be resolved.
        /// This parameter should not be null-terminated. This packet api adds null character automatically.
        /// </param>
        /// <exception cref="ArgumentException">fileName is not a valid string for DFS referral</exception>
        public DfscReferralRequestPacket CreateDfscReferralRequestPacket(ushort maxReferralLevel, string fileName)
        {
            /* 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';


            //Create REQ_GET_DFS_REFERRAL structure and packet
            REQ_GET_DFS_REFERRAL referralRequest = new REQ_GET_DFS_REFERRAL();

            referralRequest.MaxReferralLevel = maxReferralLevel;
            referralRequest.RequestFileName  = Encoding.Unicode.GetBytes(fileName);

            DfscReferralRequestPacket packet = new DfscReferralRequestPacket();

            packet.ReferralRequest = referralRequest;

            return(packet);
        }
Beispiel #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);
     }
 }
Beispiel #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));
        }