Пример #1
0
 public void SaveUser(PermissionUserInfo user)
 {
     // 增加时,设置密码
     if (user.Id.HasNotValue())
     {
         user.Pwd = user.Pwd.HasValue() ? _permission.HashPwd(user.Pwd) : _permission.HashPwd("123456");
     }
     else
     {
         // 修改时,如果密码不为空,则更新密码
         if (user.Id.HasValue() && user.Pwd.HasValue())
         {
             user.Pwd = _permission.HashPwd(user.Pwd);
         }
     }
     _permissionStore.SaveUser(user);
     _permissionStore.ReloadPemissionDatas();
 }
        /// <summary>
        /// Parse the values from server 
        /// </summary>
        /// <param name="permissionUserList">Permission user list</param>
        /// <param name="rawData">The values from server</param>
        /// <returns>If the returnValue is not 0x0000000, return false, else return true.</returns>
        private bool ParseUserListFromRawData(out List<PermissionUserInfo> permissionUserList, ref byte[] rawData)
        {
            permissionUserList = new List<PermissionUserInfo>();

            // Don't need to get the RopId(1byte) InputHandleIndex(1byte).
            int index = 0x0c;

            // Get the ReturnValue, ReturnValue 4 byte.     
            uint returnValue = (uint)BitConverter.ToInt32(rawData, index);
            if (returnValue != UINT32SUCCESS)
            {
                return false;
            }

            // Ignore Origin(1 byte)
            index += 5;

            // RowCout 
            int rowCount = BitConverter.ToInt16(rawData, index);
            index += 2;
            while (rowCount > 0)
            {
                // Flag 1 byte
                ++index;
                PermissionUserInfo permissionUserInfo = new PermissionUserInfo
                {
                    PidTagMemberId = (ulong)BitConverter.ToInt64(rawData, index)
                };

                // PT_I8  PidTagMemberId               
                index += 8;

                // PT_UNICODE  PidTagMemberName
                int countString = index;
                for (; countString < rawData.Length;)
                {
                    if (rawData[countString] == 0x00 && rawData[countString + 1] == 0x00)
                    {
                        break;
                    }

                    countString += 2;
                }

                byte[] byteTemp = new byte[countString - index];
                Array.Copy(rawData, index, byteTemp, 0x00, countString - index);
                string strTemp = Encoding.Unicode.GetString(byteTemp);
                permissionUserInfo.PidTagMemberName = strTemp; // BitConverter.(rawData, nIndex, nCountString - nIndex+1);
                index = countString + 2;

                // PT_LONG  PidTagMemberRights
                byte[] nrights = new byte[4];
                Array.Copy(rawData, index, nrights, 0x00, 0x0004);
                permissionUserInfo.PidTagMemberRights = this.GetRightsByByteArray(ref nrights);
                index += 4;

                // PT_BINARY PidTagEntryId               
                int ncount = 0x02; // COUNT: 16 bits wide
                byte[] countValue = new byte[0x02];
                Array.Copy(rawData, index, countValue, 0x00, ncount);
                int nwide = BitConverter.ToInt16(countValue, 0x0000);
                byte[] nvalue = new byte[nwide];
                index += 2;
                if (nwide > 0)
                {
                    Array.Copy(rawData, index, nvalue, 0x00, nwide - 1);
                }

                index += nwide;
                permissionUserInfo.PidTagEntryId = nvalue;
                permissionUserList.Add(permissionUserInfo);
                --rowCount;
            }

            return true;
        }
Пример #3
0
        /// <summary>
        /// Verify properties' value
        /// </summary>
        /// <param name="succeedToParse">Specify whether the data can parse successfully or not. True indicate success, else false</param>
        /// <param name="permissionUserList">The permission list of all users</param>
        private void VerifyProperties(bool succeedToParse, List <PermissionUserInfo> permissionUserList)
        {
            Site.Assert.IsTrue(succeedToParse, "True indicates the permissions list is parsed successfully.");
            if (permissionUserList == null || permissionUserList.Count == 0)
            {
                Site.Log.Add(LogEntryKind.Comment, "The permissions list is empty. The data related to the permission can't be verified here.");
                return;
            }

            // Verify MS-OXCPERM requirement: MS-OXCPERM_R1068
            // If the returned data can be parsed successfully, the format is following the defined structure.
            bool isVerifyR1068 = succeedToParse;

            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPERM_R1068: The data is{0} same as defined.", isVerifyR1068 ? string.Empty : " not");
            Site.CaptureRequirementIfIsTrue(
                isVerifyR1068,
                1068,
                @"[In PidTagEntryId Property] The first two bytes of this property specify the number of bytes that follow.");

            // Verify MS-OXCPERM requirement: MS-OXCPERM_R1069
            bool isVerifyR1069 = succeedToParse;

            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPERM_R1069: The data is{0} same as defined.", isVerifyR1069 ? string.Empty : " not");
            Site.CaptureRequirementIfIsTrue(
                isVerifyR1069,
                1069,
                @"[In PidTagEntryId Property] [The first two bytes of this property specify the number of bytes that follow.] The remaining bytes constitute the PermanentEntryID structure ([MS-OXNSPI] section 2.3.8.3).");

            bool memberIdIsUnique = true;

            for (int i = 0; i < permissionUserList.Count; i++)
            {
                PermissionUserInfo permissionInfo = permissionUserList[i];
                string             memberName     = permissionInfo.PidTagMemberName;
                if (memberName == this.defaultUser || memberName == this.anonymousUser)
                {
                    // Verify MS-OXCPERM requirement: MS-OXCPERM_R1070
                    Site.CaptureRequirementIfAreEqual <int>(
                        0,
                        permissionInfo.PidTagEntryId.Length,
                        1070,
                        @"[In PidTagEntryId Property] If the PidTagMemberId property (section 2.2.5) is set to one of the two reserved values, the first two bytes of this property MUST be 0x0000, indicating that zero bytes follow (that is, no PermanentEntryID structure follows the first two bytes).");
                }

                if (permissionInfo.PidTagMemberId == 0xFFFFFFFFFFFFFFFF)
                {
                    // Verify MS-OXCPERM requirement: MS-OXCPERM_R1079
                    // That PidTagMemberId is 0xFFFFFFFFFFFFFFFF and the name is "Anonymous" must be matched.
                    bool isVerifyR1079 = permissionInfo.PidTagMemberId == 0xFFFFFFFFFFFFFFFF &&
                                         permissionInfo.PidTagMemberName == this.anonymousUser;
                    Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPERM_R1079: the PidTagMemberId:{0:X} and PidTagMemberName:{1} are{2} matched.", permissionInfo.PidTagMemberId, permissionInfo.PidTagMemberName, isVerifyR1079 ? string.Empty : " not");
                    Site.CaptureRequirementIfIsTrue(
                        isVerifyR1079,
                        1079,
                        @"[In PidTagMemberName Property] Anonymous user: Value of the PidTagMemberId is 0xFFFFFFFFFFFFFFFF and the name is ""Anonymous"".");
                }

                if (permissionInfo.PidTagMemberId == 0x0000000000000000)
                {
                    // Verify MS-OXCPERM requirement: MS-OXCPERM_R1080
                    // That PidTagMemberId is 0x0000000000000000 and name is "" (empty string) must be matched.
                    bool isVerifyR1080 = permissionInfo.PidTagMemberId == 0x0000000000000000 &&
                                         permissionInfo.PidTagMemberName == this.defaultUser;
                    Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPERM_R1080: the PidTagMemberId:{0:X} and PidTagMemberName:{1} are{2} matched.", permissionInfo.PidTagMemberId, permissionInfo.PidTagMemberName, isVerifyR1080 ? string.Empty : " not");
                    Site.CaptureRequirementIfIsTrue(
                        isVerifyR1080,
                        1080,
                        @"[In PidTagMemberName Property] Default user: Value of the PidTagMemberId is 0x0000000000000000 and name is """" (empty string).");
                }

                for (int j = i + 1; j < permissionUserList.Count; j++)
                {
                    if (permissionInfo.PidTagMemberId == permissionUserList[j].PidTagMemberId)
                    {
                        memberIdIsUnique = false;
                    }
                }
            }

            // Verify MS-OXCPERM requirement: MS-OXCPERM_R74
            bool isVerifyR74 = memberIdIsUnique;

            Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCPERM_R74: the all PidTagMemberId are{0} unique.", isVerifyR74 ? string.Empty : " not");
            Site.CaptureRequirementIfIsTrue(
                isVerifyR74,
                74,
                @"[In PidTagMemberId Property] The PidTagMemberId property ([MS-OXPROPS] section 2.771) specifies the unique identifier that the server generates for each user.");

            // The PidTagMemberName is parsed as string, this requirement can be captured directly.
            Site.CaptureRequirement(
                1081,
                @"[In PidTagMemberName Property] The server provides the user-readable name for all entries in the permissions list.");

            // The parser has ensured the field satisfies the format, otherwise can't get the response.
            Site.CaptureRequirement(
                154,
                @"[In Retrieving Folder Permissions] If all three of the ROP requests [RopGetPermissionsTable, RopSetColumns, RopQueryRows] succeed, the permissions list is returned in the RowData field of the RopQueryRows ROP response buffer.");

            // The parser has ensured the field satisfies the format, otherwise can't get the response.
            Site.CaptureRequirement(
                155,
                @"[In Retrieving Folder Permissions] The RowData field contains one PropertyRow structure ([MS-OXCDATA] section 2.8.1) for each entry in the permissions list.");

            // The parser has ensured the field satisfies the format, otherwise can't get the response.
            Site.CaptureRequirement(
                1164,
                @"[In Processing a RopGetPermissionsTable ROP Request] The server responds with a RopGetPermissionsTable ROP response buffer.");

            // The parser has ensured the field satisfies the format, otherwise can't get the response.
            Site.CaptureRequirement(
                179,
                @"[In Processing a RopGetPermissionsTable ROP Request] If the user does have permission to view the folder, the server MUST return a Server object handle to a Table object, which can be used to retrieve the permissions list of the folder, as specified in section 3.1.4.1.");

            if (this.CheckUserPermissionContained(this.anonymousUser, permissionUserList))
            {
                // Verify MS-OXCPERM requirement: MS-OXCPERM_R189
                ulong anonymousMemberID = this.GetMemberIdByName(this.anonymousUser, permissionUserList);
                Site.CaptureRequirementIfAreEqual <ulong>(
                    0xFFFFFFFFFFFFFFFF,
                    anonymousMemberID,
                    189,
                    @"[In PidTagMemberId Property] 0xFFFFFFFFFFFFFFFF: Identifier for the anonymous user entry in the permissions list.");
            }

            if (this.CheckUserPermissionContained(this.defaultUser, permissionUserList))
            {
                // Verify MS-OXCPERM requirement: MS-OXCPERM_R190
                ulong defaultUserMemberID = this.GetMemberIdByName(this.defaultUser, permissionUserList);
                Site.CaptureRequirementIfAreEqual <ulong>(
                    0x0000000000000000,
                    defaultUserMemberID,
                    190,
                    @"[In PidTagMemberId Property] 0x0000000000000000: Identifier for the default user entry in the permissions list.");
            }
        }