示例#1
0
        internal static CifsIoException getNBException(int code)
        {
            CifsIoException e = new CifsIoException();

            try
            {
                e.fMessage = CifsRuntimeException.GetMessage("NB" + code);
            }
            catch (Exception)
            {
                e.fMessage = CifsRuntimeException.GetMessage("NB999", code);
            }
            return(e);
        }
示例#2
0
        /// <summary>
        ///   Changes password on the server
        /// </summary>
        /// <param name = "user">user name</param>
        /// <param name = "oldpwd">old password</param>
        /// <param name = "newpwd">new password</param>
        public void ChangePassword(string user, string oldpwd, string newpwd)
        {
            lock (this)
            {
                if (Debug.DebugOn)
                {
                    Debug.WriteLine(Debug.Info, "SamOEMChangePassword");
                }

                var param = new MarshalBuffer(100);

                int pos = 0;
                pos += param.SetShortAt(pos, SamOEMChangePassword);
                // parameter descriptor string
                pos += param.SetZtAsciiStringAt(pos, "zsT");

                // the data descriptor string for the (returned) data which = null string
                pos += param.SetZtAsciiStringAt(pos, "B516B16");

                // user
                pos += param.SetZtAsciiStringAt(pos, user);

                // data size
                pos += param.SetShortAt(pos, 532);

                param.Size = pos;

                byte[] data = CifsLogin.GetChangePasswordData(oldpwd, newpwd);


                SendTransaction(null, "\\PIPE\\LANMAN", param, data, data.Length);

                var rdata = new MarshalBuffer(100);

                receiveTransaction(param, rdata);

                pos = 0;

                int error = param.GetShortAt(pos);

                // ignore more data
                if (error != 0 && error != 234)
                {
                    throw CifsIoException.getLMException(error);
                }
            } // lock
        }
示例#3
0
        internal static CifsIoException getLMException(int code)
        {
            CifsIoException e = new CifsIoException();

            try
            {
                e.fMessage = CifsRuntimeException.GetMessage("LM" + code);
            }
            catch (Exception)
            {
                e.fMessage = CifsRuntimeException.GetMessage("LMERROR", code);
                if (Debug.DebugOn)
                {
                    Debug.WriteLine(Debug.Warning, "LM Error: " + code + " not defined.");
                }
            }
            return(e);
        }
示例#4
0
        private void DoNetServerEnum2(string domain, uint types, int level,
                                      MarshalBuffer param, MarshalBuffer data)
        {
            int pos = 0;

            pos += param.SetShortAt(pos, NetShareEnum2);
            // parameter descriptor string
            pos += param.SetZtAsciiStringAt(pos, "WrLehDz");

            // the data descriptor string for the (returned) data
            switch (level)
            {
            case 0:
                pos += param.SetZtAsciiStringAt(pos, "B16");
                break;

            case 1:
                pos += param.SetZtAsciiStringAt(pos, "B16BBDz");
                break;

            default:
                Debug.WriteLine(Debug.Error, "Invalid NetServerEnum2 level");
                throw new ApplicationException("doNetServerEnum2");
            }


            // corresponding to the "W": Level 1
            pos += param.SetShortAt(pos, level);

            // buffer size
            pos += param.SetShortAt(pos, fReturnBufferSize);

            if (domain == null)
            {
                types |= CifsServerInfo.SV_TYPE_DOMAIN_ENUM;
            }

            // select types
            pos += param.SetIntAt(pos, (Int32)types);


            // domain
            if (domain != null)
            {
                pos += param.SetZtAsciiStringAt(pos, domain);
            }
            else
            {
                pos += param.SetByteAt(pos, 0);
            }

            param.Size = pos;


            SendTransaction(null, "\\PIPE\\LANMAN", param, null, 0);
            receiveTransaction(param, data);


            int error = param.GetShortAt(0);

            // ignore more data
            if (error != 0 && error != 234)
            {
                throw CifsIoException.getLMException(error);
            }
        }
示例#5
0
        /// <summary>
        ///   Returns detailed information about a particular user
        /// </summary>
        /// <param name = "user">User Name</param>
        /// <returns>user information</returns>
        public CifsUserInfo GetUserInfo(string user)
        {
            if (Debug.DebugOn)
            {
                Debug.WriteLine(Debug.Info, "IPC:NetUserGetInfo");
            }

            var param = new MarshalBuffer(100);
            int pos   = 0;

            pos += param.SetShortAt(pos, NetUserGetInfo);
            // parameter descriptor string
            pos += param.SetZtAsciiStringAt(pos, "zWrLh");

            // he data descriptor string for the (returned) data which is "B21BzzzWDDzzDDWWzWzDWb21W"
            pos += param.SetZtAsciiStringAt(pos, "B21BzzzWDDzzDDWWzWzDWb21W");

            // user
            pos += param.SetZtAsciiStringAt(pos, user);

            // corresponding to the "W"
            pos += param.SetShortAt(pos, 11);

            // buffer size
            pos += param.SetShortAt(pos, fReturnBufferSize);

            param.Size = pos;

            SendTransaction(null, "\\PIPE\\LANMAN", param, null, 0);

            var data = new MarshalBuffer(1000);

            receiveTransaction(param, data);

            pos = 0;

            int error = param.GetShortAt(pos);

            // ignore more data
            if (error != 0 && error != 234)
            {
                throw CifsIoException.getLMException(error);
            }

            pos += 2;

            // converter
            int converter = param.GetShortAt(pos);

            pos += 2;

            /* A 16 bit number representing the total number of available bytes.
             *  This has meaning only if the return status is NERR_Success or
             *  ERROR_MORE_DATA. Upon success, this number indicates the number of
             *  useful bytes available. Upon failure, this indicates how big the
             *  receive buffer needs to be.
             */
            int bytes = param.GetShortAt(pos);

            pos += 2;


            /*
             * struct user_info_11 {
             * char                usri11_name[21];
             * char                usri11_pad;
             * char                *usri11_comment;
             * char            *usri11_usr_comment;
             * char                *usri11_full_name;
             * unsigned short      usri11_priv;
             * unsigned long       usri11_auth_flags;
             * long                usri11_password_age;
             * char                *usri11_homedir;
             * char            *usri11_parms;
             * long                usri11_last_logon;
             * long                usri11_last_logoff;
             * unsigned short      usri11_bad_pw_count;
             * unsigned short      usri11_num_logons;
             * char                *usri11_logon_server;
             * unsigned short      usri11_country_code;
             * char            *usri11_workstations;
             * unsigned long       usri11_max_storage;
             * unsigned short      usri11_units_per_week;
             * unsigned char       *usri11_logon_hours;
             * unsigned short      usri11_code_page;
             *
             * };
             */

            if (Debug.DebugOn)
            {
                data.debug("NetUserGetInfo data");
            }

            var info = new CifsUserInfo();

            pos = 0;

            // user name for which information is retireved

            info.UserName = data.GetZtAsciiStringAt(pos, 21);
            pos          += 21;

            // pad
            pos++;

            //comment
            int ptr = data.GetIntAt(pos) & 0xffff;

            pos         += 4;
            info.Comment = data.GetZtAsciiStringAt(ptr - converter, bytes);
            // comment about user
            ptr  = data.GetIntAt(pos) & 0xffff;
            pos += 4;
            info.UserComment = data.GetZtAsciiStringAt(ptr - converter, bytes);

            // full name  of the user
            ptr  = data.GetIntAt(pos) & 0xffff;
            pos += 4;
            info.FullUserName = data.GetZtAsciiStringAt(ptr - converter, bytes);

            // level of the privilege assigned to the user
            info.UserPrivilege = data.GetShortAt(pos);
            pos += 2;

            // account operator privileges.
            info.OperatorPrivileges = data.GetIntAt(pos);
            pos += 4;

            // how many seconds have elapsed since the password was last changed.
            info.PasswordAge = data.GetIntAt(pos) & 0xffffffff;
            pos += 4;

            // path name of the user's home directory.
            ptr          = data.GetIntAt(pos) & 0xffff;
            pos         += 4;
            info.HomeDir = data.GetZtAsciiStringAt(ptr - converter, bytes);

            // skip usri11_parms
            pos += 4;

            // last logon
            info.fLastLogon = data.GetIntAt(pos) & 0xffffffff;
            pos            += 4;

            // last logon
            info.fLastLogoff = data.GetIntAt(pos) & 0xffffffff;
            pos += 4;

            // bad logons
            info.BadLogons = data.GetShortAt(pos);
            pos           += 2;

            // num logons
            info.Logons = data.GetShortAt(pos);
            pos        += 2;

            // logon server
            ptr  = data.GetIntAt(pos) & 0xffff;
            pos += 4;
            info.LogonServer = data.GetZtAsciiStringAt(ptr - converter, bytes);

            return(info);
        }
示例#6
0
        /// <summary>
        ///   Returns the list of shares on the computer
        /// </summary>
        /// <param name = "sort">if true, the names are sorted</param>
        /// <returns>list of <code>CifsShareInfo</code> objects</returns>
        public CifsShareInfo[] ListSharesInfo(bool sort)
        {
            lock (this)
            {
                if (Debug.DebugOn)
                {
                    Debug.WriteLine(Debug.Info, "IPC:NetShareEnum");
                }

                var param = new MarshalBuffer(100);

                int pos = 0;
                pos += param.SetShortAt(pos, NetShareEnum);
                // parameter descriptor string
                pos += param.SetZtAsciiStringAt(pos, "WrLeh");

                // The data descriptor string for the (returned) data which is "B13BWz"
                pos += param.SetZtAsciiStringAt(pos, "B13BWz");

                // corresponding to the "W"
                pos += param.SetShortAt(pos, 1);

                // buffer size
                pos += param.SetShortAt(pos, fReturnBufferSize);

                param.Size = pos;

                SendTransaction(null, "\\PIPE\\LANMAN", param, null, 0);

                var data = new MarshalBuffer(1000);

                receiveTransaction(param, data);

                pos = 0;

                int error = param.GetShortAt(pos);

                // ignore more data
                if (error != 0 && error != 234)
                {
                    throw CifsIoException.getLMException(error);
                }

                pos += 2;

                // converter
                int converter = param.GetShortAt(pos);
                pos += 2;

                // number of entries
                int counter = param.GetShortAt(pos);
                pos += 2;

                // number max of entries
                int maxcounter = param.GetShortAt(pos);


                /*
                 * The SHARE_INFO_1 structure is defined as:
                 *
                 * struct SHARE_INFO_1 {
                 *     char                shi1_netname[13]
                 *     char                shi1_pad;
                 *     unsigned short  shi1_type
                 *     char            *shi1_remark;
                 * }
                 *
                 * where:
                 *
                 * shi1_netname contains a null terminated ASCII string that
                 *             specifies the share name of the resource.
                 *
                 * shi1_pad aligns the next data strructure element to a word
                 *         boundary.
                 *
                 * shi1_type contains an integer that specifies the type of the
                 *         shared resource.
                 *
                 *
                 * shi1_remark points to a null terminated ASCII string that contains
                 *     a comment abthe shared resource. The value for shi1_remark is null
                 *     for ADMIN$ and IPC$ share names.  The shi1_remark pointer is a 32
                 *     bit pointer. The higher 16 bits need to be ignored. The converter
                 *     word returned in the parameters section needs to be subtracted
                 *     from the lower 16 bits to calculate an offset into the return
                 *     buffer where this ASCII string resides.
                 *
                 *     In case there are multiple SHARE_INFO_1 data structures to return,
                 *     the server may put all these fixed length structures in the return
                 *     buffer, leave some space and then put all the variable length data
                 *     (the actual value of the shi1_remark strings) at the end of the
                 * buffer.
                 */

                if (Debug.DebugOn)
                {
                    data.debug("NetShareEnum data");
                }

                var           result = new CifsShareInfo[counter];
                CifsShareInfo info;
                pos = 0;

                for (int i = 0; i < counter; i++)
                {
                    info = new CifsShareInfo(fShare.HostName);

                    // shil_netname[13]
                    info.ShareName = data.GetZtAsciiStringAt(pos, 13);
                    pos           += 13;

                    pos += 1; // pad

                    // shil_type
                    info.ShareType = data.GetShortAt(pos);

                    pos += 2;

                    // shil_remark
                    int rptr = (data.GetIntAt(pos) & 0xffff);
                    pos += 4;

                    info.Remark = data.GetZtAsciiStringAt(rptr - converter, 255);

                    result[i] = info;
                }

                if (sort)
                {
                    Util.Util.Sort(result, GetShareInfoComparator());
                }

                return(result);
            } // lock
        }
示例#7
0
 internal static CifsIoException getLMException(int code)
 {
     CifsIoException e = new CifsIoException();
     try
     {
         e.fMessage = CifsRuntimeException.GetMessage("LM" + code);
     }
     catch(Exception)
     {
         e.fMessage = CifsRuntimeException.GetMessage("LMERROR", code);
         if(Debug.DebugOn)
             Debug.WriteLine(Debug.Warning,"LM Error: " + code + " not defined.");
     }
     return e;
     
 }
示例#8
0
 internal static CifsIoException getNBException(int code)
 {
     CifsIoException e = new CifsIoException();
     
     try
     {
         e.fMessage = CifsRuntimeException.GetMessage("NB" + code);
     }
     catch(Exception)
     {
         e.fMessage = CifsRuntimeException.GetMessage("NB999", code);
     }
     return e;
 }
示例#9
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);
                }
            }
        }