Ejemplo n.º 1
0
 /// <summary>
 ///   Initializes SMB message for SMB_COM_TRANSACTION_SECONDARY
 /// </summary>
 /// <param name = "msg">SMB message</param>
 /// <param name = "cmd">Command</param>
 internal void SetupSmbMessageSecondary(SmbMessage msg, byte cmd) // should be protected
 {
     msg.setCommand(cmd);
     msg.setUID(fUID);
     msg.setTID(fTID);
     msg.setPID(fPID);
     msg.setMID(fMID);
     msg.setCanHandleLongNames();
     msg.setExtededAttributes();
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Initializes the SMB message
        /// </summary>
        /// <param name = "msg">SMB message</param>
        /// <param name = "cmd">Command</param>
        internal void SetupSmbMessage(SmbMessage msg, byte cmd) // should be protected
        {
            msg.setCommand(cmd);
            msg.setUID(fUID);
            msg.setTID(fTID);
            msg.setPID(fPID);
            msg.setMID(nextMID());
            msg.setCanHandleLongNames();
            msg.setExtededAttributes();

            if (cmd == SmbMessage.SMB_COM_TREE_CONNECT_ANDX ||
                cmd == SmbMessage.SMB_COM_TREE_DISCONNECT ||
                cmd == SmbMessage.SMB_COM_SESSION_SETUP_ANDX ||
                cmd == SmbMessage.SMB_COM_LOGOFF_ANDX)
                return;

            CheckConnection();
        }