Example #1
0
        private static IPAddress ResolveInWins(string netbios)
        {
            if (fWins == null)
            {
                // Add external configuration....
                string wins = "wins2.cwru.edu";  // CWRU's wins server (129.22.4.11)

                if (wins == null)
                {
                    return(null);
                }
                if (Debug.DebugOn && Debug.DebugLevel >= Debug.Info)
                {
                    Debug.WriteLine(Debug.Info, "Check name in WINS");
                }


                try
                {
                    fWinsAddr = Dns.Resolve(wins).AddressList[0];
                    fWins     = new NBTNameService();
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            return(fWins.lookup(fWinsAddr, netbios));
        }
Example #2
0
        /// <summary>
        /// Creates the session request packet
        /// </summary>
        /// <remarks>
        /// <pre>
        ///         SESSION REQUEST PACKET:
        ///
        ///                            1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
        ///        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        ///        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        ///        |      TYPE     |     FLAGS     |            LENGTH             |
        ///        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        ///        |                                                               |
        ///        /                          CALLED NAME                          /
        ///        |                                                               |
        ///        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        ///        |                                                               |
        ///        /                          CALLING NAME                         /
        ///        |                                                               |
        ///        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        ///        </pre></remarks>
        /// <param name="callname"> </param>
        private byte[] MakeRequestPacket(string callname)
        {
            // build called and calling names
            byte[] calledname = NBTNameService.buildSecondLevelEncodedName(callname); // NetBIOS.SMBSERVER_NAME

            byte[] callingname = NBTNameService.buildSecondLevelEncodedName(fCallingName);

            int packetsize = HDR_SIZE + calledname.Length + callingname.Length;

            byte[] packet = new byte[packetsize];

            // set packet header
            packet[HDR_TYPE_1]  = SPT_REQUEST;
            packet[HDR_FLAGS_1] = 0;
            SetShortAt(HDR_LENGTH_2, packet, (short)(packetsize - HDR_SIZE));

            int pos = RQ_CALLED_NAME_32;

            for (int i = 0; i < calledname.Length; i++)
            {
                packet[pos++] = calledname[i];
            }

            for (int i = 0; i < callingname.Length; i++)
            {
                packet[pos++] = callingname[i];
            }

            return(packet);
        }
Example #3
0
        public void DoCall(string netbiosname)
        {
            lock(this)	// This entire method needs to be synchronized
         {
            // int retry_count = 0;  
             int port = SSN_SRVC_TCP_PORT;
             
             InetAddress = NbtNameResolver.Resolve(netbiosname);
             
             // Get the real NetBIOS name & Workgroup from an IP
             NBTNameService ns = new NBTNameService();
             NbInfo info = ns.queryStatus(InetAddress);
             NetBiosName = info.Name;
             WorkgroupName = info.Workgroup;

             // If we couldn't resolve the name, then the host either doesn't
             // exist or does not support CIFS.
             if(NetBiosName == null)
                throw new CifsIoException("CM2", InetAddress.ToString());


             DoConnect(InetAddress, port);
             byte[] packet = MakeRequestPacket(NetBiosName);
            
             if(Debug.DebugOn && Debug.DebugLevel >= Debug.Info)
             {
                Debug.WriteLine(Debug.Info, "NetBIOS: doCall");
                Debug.WriteLine(Debug.Info, "Called name=" + NetBiosName);
                Debug.WriteLine(Debug.Info, "Calling name=" + fCallingName);
                Debug.WriteLine(Debug.Info, "Called addr=" + InetAddress.ToString());
                
                if(Debug.DebugLevel >= Debug.Buffer)
                {
                    Debug.WriteLine(Debug.Buffer, "Packet to send:");
                    Debug.WriteLine(Debug.Buffer, packet, 0, packet.Length);
                }
             }

             try
             {
                 fOutput.Write(packet, 0, packet.Length);
                 fOutput.Flush();
             }
             catch(IOException e)
             {
                 DoHangup();
                 throw new CifsIoException("NB500").setDetail(e);
             }

             // read header
             try
             {
                 int count = Read(packet, 0, HDR_SIZE);

                 
                 if(Debug.DebugOn && Debug.DebugLevel >= Debug.Buffer)
                 {				 
                     Debug.WriteLine(Debug.Buffer, "Recieved packet:");
                     Debug.WriteLine(Debug.Buffer, packet, 0, packet.Length);
                 }
                 


                 if(count < HDR_SIZE)
                 {
                     DoHangup();
                     throw new CifsIoException("NB501");
                 }

                 byte type = packet[HDR_TYPE_1];

                 switch(type)
                 {
                     case SPT_POS_RESPONSE:
                    /*
                        POSITIVE SESSION RESPONSE PACKET

                                            1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                        |      TYPE     |     FLAGS     |            LENGTH             |
                        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                    */						 
                         break;

                     case SPT_NEG_RESPONSE:
                    /*
                        NEGATIVE SESSION RESPONSE PACKET

                                            1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                        |      TYPE     |     FLAGS     |            LENGTH             |
                        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                        |   ERROR_CODE  |
                        +-+-+-+-+-+-+-+-+
                     */
                         
                         int rc = fInput.ReadByte();
                         Debug.WriteLine(Debug.Error, "NetBIOS: Negative response: " + rc);

                         DoHangup();
                         throw CifsIoException.getNBException(rc & 0xff);				

                     case SPT_RTG_RESPONSE:
                    /*
                       SESSION RETARGET RESPONSE PACKET

                           1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                       |      TYPE     |     FLAGS     |            LENGTH             |
                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                       |                      RETARGET_IP_ADDRESS                      |
                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                       |           PORT                |
                       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                     */						 
                         count = Read(packet, 0, RT_SIZE);
                         DoHangup();
                         throw new CifsIoException("NB502");
                         
                     default:
                         DoHangup();
                         throw new CifsRuntimeException("NB503", (Int32)type  );
                        
                 }
             }
             catch(IOException e)
             {
                 DoHangup();
                 throw new CifsIoException("NB501").setDetail(e);
             }

         }
        }
Example #4
0
        public void DoCall(string netbiosname)
        {
            lock (this)  // This entire method needs to be synchronized
            {
                // int retry_count = 0;
                int port = SSN_SRVC_TCP_PORT;

                InetAddress = NbtNameResolver.Resolve(netbiosname);

                // Get the real NetBIOS name & Workgroup from an IP
                NBTNameService ns   = new NBTNameService();
                NbInfo         info = ns.queryStatus(InetAddress);
                NetBiosName   = info.Name;
                WorkgroupName = info.Workgroup;

                // If we couldn't resolve the name, then the host either doesn't
                // exist or does not support CIFS.
                if (NetBiosName == null)
                {
                    throw new CifsIoException("CM2", InetAddress.ToString());
                }


                DoConnect(InetAddress, port);
                byte[] packet = MakeRequestPacket(NetBiosName);

                if (Debug.DebugOn && Debug.DebugLevel >= Debug.Info)
                {
                    Debug.WriteLine(Debug.Info, "NetBIOS: doCall");
                    Debug.WriteLine(Debug.Info, "Called name=" + NetBiosName);
                    Debug.WriteLine(Debug.Info, "Calling name=" + fCallingName);
                    Debug.WriteLine(Debug.Info, "Called addr=" + InetAddress.ToString());

                    if (Debug.DebugLevel >= Debug.Buffer)
                    {
                        Debug.WriteLine(Debug.Buffer, "Packet to send:");
                        Debug.WriteLine(Debug.Buffer, packet, 0, packet.Length);
                    }
                }

                try
                {
                    fOutput.Write(packet, 0, packet.Length);
                    fOutput.Flush();
                }
                catch (IOException e)
                {
                    DoHangup();
                    throw new CifsIoException("NB500").setDetail(e);
                }

                // read header
                try
                {
                    int count = Read(packet, 0, HDR_SIZE);


                    if (Debug.DebugOn && Debug.DebugLevel >= Debug.Buffer)
                    {
                        Debug.WriteLine(Debug.Buffer, "Recieved packet:");
                        Debug.WriteLine(Debug.Buffer, packet, 0, packet.Length);
                    }



                    if (count < HDR_SIZE)
                    {
                        DoHangup();
                        throw new CifsIoException("NB501");
                    }

                    byte type = packet[HDR_TYPE_1];

                    switch (type)
                    {
                    case SPT_POS_RESPONSE:
                        /*
                         *  POSITIVE SESSION RESPONSE PACKET
                         *
                         *                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                         *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |      TYPE     |     FLAGS     |            LENGTH             |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         */
                        break;

                    case SPT_NEG_RESPONSE:
                        /*
                         *  NEGATIVE SESSION RESPONSE PACKET
                         *
                         *                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                         *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |      TYPE     |     FLAGS     |            LENGTH             |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |   ERROR_CODE  |
                         +-+-+-+-+-+-+-+-+
                         */

                        int rc = fInput.ReadByte();
                        Debug.WriteLine(Debug.Error, "NetBIOS: Negative response: " + rc);

                        DoHangup();
                        throw CifsIoException.getNBException(rc & 0xff);

                    case SPT_RTG_RESPONSE:
                        /*
                         * SESSION RETARGET RESPONSE PACKET
                         *
                         *     1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
                         * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |      TYPE     |     FLAGS     |            LENGTH             |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |                      RETARGET_IP_ADDRESS                      |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         |           PORT                |
                         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                         */
                        count = Read(packet, 0, RT_SIZE);
                        DoHangup();
                        throw new CifsIoException("NB502");

                    default:
                        DoHangup();
                        throw new CifsRuntimeException("NB503", (Int32)type);
                    }
                }
                catch (IOException e)
                {
                    DoHangup();
                    throw new CifsIoException("NB501").setDetail(e);
                }
            }
        }
Example #5
0
        private static IPAddress ResolveInWins(string netbios)
        {
            if(fWins == null)
            {
                // Add external configuration....
                string wins = "wins2.cwru.edu";  // CWRU's wins server (129.22.4.11)

                if(wins == null)
                    return null;
                if(Debug.DebugOn && Debug.DebugLevel >= Debug.Info)
                    Debug.WriteLine(Debug.Info, "Check name in WINS");
                

                try
                {
                    fWinsAddr = Dns.Resolve(wins).AddressList[0];
                    fWins     = new NBTNameService();
                }
                catch(Exception)
                {
                    return null;
                }
            }
            return fWins.lookup(fWinsAddr, netbios);
        }