Esempio n. 1
0
        public void receive(NbtSession nbt)
        {
            nbt.DoRecieve(this);

            if (Debug.DebugOn)
            {
                dumpPacket("Recieve SMB buffer");
            }
        }
Esempio n. 2
0
        public void send(NbtSession nbt)
        {
            if (Debug.DebugOn)
            {
                dumpPacket("Send SMB buffer");
            }


            nbt.DoSend(this);
        }
Esempio n. 3
0
        /// <summary>
        ///   Connect to Remote Admin Protocol
        /// </summary>
        /// <param name = "sessionname">local alias name for this connection</param>
        /// <param name = "host">host name</param>
        /// <param name = "login">authentication data</param>
        public static ICifsRemoteAdmin ConnectRemoteAdmin(string sessionname, string host, CifsLogin login)
        {
            // check if the admname connection is already open
            ICifsSession session = LookupSession(sessionname);

            if (session != null)
            {
                throw new CifsIoException("SS1", sessionname);
            }

            if (login == null)
            {
                login = fDefaultLogin;
            }

            var share = new Share(login);

            share.SetInfo(Share.IPC, host, "IPC$");

            var        nbt = new NbtSession();
            SmbMessage smb = CifsSession.AllocateSmbMessage();

            int             protocol;
            CifsRemoteAdmin admin = null;

            try
            {
                protocol = CifsSession.Negotiate(nbt, share.HostName, smb);
                admin    = new CifsRemoteAdmin(sessionname, protocol, share, nbt, smb);
                admin.Connect();
            }
            catch (IOException e)
            {
                //nbt.doHangup();
                if (admin != null)
                {
                    admin.Dispose();
                }
                else
                {
                    nbt.DoHangup();
                }


                throw;
            }

            return(admin);
        }
Esempio n. 4
0
        public void SendAndRecieve(NbtSession nbt, SmbMessage reply)
        {
            nbt.DoSend(this);

            if (Debug.DebugOn)
            {
                dumpPacket("Send SMB buffer");
            }


            nbt.DoRecieve(reply);

            if (Debug.DebugOn)
            {
                dumpPacket("Recieve SMB buffer");
            }
        }
Esempio n. 5
0
 internal CifsRemoteAdmin(string sessionname, int prot, Share share, NbtSession nbt, SmbMessage packet)
     : base(sessionname, prot, share, nbt, packet)
 {
 }
Esempio n. 6
0
 /// <summary>
 ///   Disconnect the connection
 /// </summary>
 public void Disconnect()
 {
     DoTreeDisconnect();
     //logoff();
     if (fNBTSession != null)
         fNBTSession.DoHangup();
     fNBTSession = null;
     fMsg = null;
     RemoveSession(fSessionName);
 }
Esempio n. 7
0
        /// <summary>
        ///   Negotiates protocol (we only support NT_LM_0_12). Calls NetBIOS
        /// </summary>
        /// <param name = "nbt">NetBIOS session</param>
        /// <param name = "nbtname">NetBIOS name</param>
        /// <param name = "msg">SMB Message</param>
        /// <returns>Negotiated protocol</returns>
        internal static int Negotiate(NbtSession nbt, string nbtname, SmbMessage msg)
        {
            if (Debug.DebugOn)
                Debug.WriteLine(Debug.Info, "SMB_COM_NEGOTIATE");

            nbt.DoCall(nbtname);

            msg.setCommand(SmbMessage.SMB_COM_NEGOTIATE);
            msg.setPID(fPID);

            /**
             * struct {
             *			UCHAR BufferFormat;	 // DT_DIALECT
             *			UCHAR DialectName[]; // Null-terminated
             * } Dialects[];
             */

            var buf = new StringBuilder();
            for (int i = 0; i < SUPPORTED_DIALECTS.Length; i++)
            {
                buf.Append((char) SmbMessage.DT_DIALECT);
                buf.Append(SUPPORTED_DIALECTS[i]);
                buf.Append('\0');
            }

            msg.setContent(Encoding.UTF8.GetBytes(buf.ToString()));


            if (Debug.DebugOn && Debug.DebugLevel >= Debug.Buffer)
            {
                Debug.WriteLine(Debug.Buffer, "Supported Dialects:");
                Debug.WriteLine(Debug.Buffer, msg.getMessageBuffer(), 0, msg.getMessageSize());
            }


            msg.SendAndRecieve(nbt, msg);

            if (Debug.DebugOn && Debug.DebugLevel >= Debug.Buffer)
            {
                Debug.WriteLine(Debug.Buffer, "Dialects Response:");
                Debug.WriteLine(Debug.Buffer, msg.getMessageBuffer(), 0, msg.getMessageSize());
            }

            int protocol = msg.getParameter(0);

            if (protocol == -1)
                throw new CifsIoException("PE1");

            if (protocol != NT_LM_0_12)
                throw new CifsIoException("PE2", SUPPORTED_DIALECTS[protocol]);

            if (msg.getWordCount() != 17)
                throw new CifsIoException("PE2", SUPPORTED_DIALECTS[protocol]);

            if (Debug.DebugOn && Debug.DebugLevel >= Debug.Info)
                Debug.WriteLine(Debug.Info, "Negotiated protocol: " + SUPPORTED_DIALECTS[protocol]);

            return protocol;
        }
Esempio n. 8
0
        /// <summary>
        ///   Reconnects server if disconnected
        /// </summary>
        public void Reconnect()
        {
            lock (this)
            {
                if (IsConnected)
                    return;

                if (Debug.DebugOn)
                    Debug.WriteLine(Debug.Info, "Reconnect session");

                if (fMsg == null)
                    fMsg = AllocateSmbMessage();

                if (fNBTSession == null)
                    fNBTSession = new NbtSession();

                fConnectionLost = false;

                try
                {
                    fProtocol = Negotiate(fNBTSession, fShare.HostName, fMsg);
                    SetNegotiatedData(fMsg);
                    Connect();
                }
                catch (IOException e)
                {
                    fNBTSession.DoHangup();
                    fNBTSession = null;

                    throw e;
                }
            } // lock
        }
Esempio n. 9
0
 /// <summary>
 ///   Constructor
 /// </summary>
 /// <param name = "sessionname">String identfying the session</param>
 /// <param name = "protocol"></param>
 /// <param name = "share">Share object</param>
 /// <param name = "nbt">NetBIOS session</param>
 /// <param name = "msg">Message containing negotiated data</param>
 internal CifsSession(string sessionname, int protocol, Share share, NbtSession nbt, SmbMessage msg)
 {
     fShare = share;
     fNBTSession = nbt;
     fMsg = msg;
     fProtocol = protocol;
     SetNegotiatedData(msg);
     if (sessionname == null)
         fSessionName = "Session" + fSessionNameCounter++;
     else
         fSessionName = sessionname;
 }
Esempio n. 10
0
        public void SendAndRecieve(NbtSession nbt, SmbMessage reply)
        {
            nbt.DoSend(this);

            if(Debug.DebugOn)
                dumpPacket("Send SMB buffer");
            

            nbt.DoRecieve(reply);

            if(Debug.DebugOn)
                dumpPacket("Recieve SMB buffer");
            
        }
Esempio n. 11
0
 public void receive(NbtSession nbt)
 {
     nbt.DoRecieve(this);
     
     if(Debug.DebugOn)
         dumpPacket("Recieve SMB buffer");
     
 }
Esempio n. 12
0
        public void send(NbtSession nbt)
        {
            if(Debug.DebugOn)
                dumpPacket("Send SMB buffer"); 
            

            nbt.DoSend(this);
        }