Exemplo n.º 1
0
        public static void ToDirectoryGroupScope(string extendedAttribute, string[] directoryAttributes, ADPropertyValueCollection extendedData, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
        {
            ADGroupScope aDGroupScope = ADGroupScope.DomainLocal;

            if (extendedData != null)
            {
                if (extendedData.Value != null)
                {
                    ADGroupScope value = (ADGroupScope)extendedData.Value;
                    int          directoryGroupTypeValue = GroupTypeUtils.GetDirectoryGroupTypeValue(value);
                    if (!directoryObj.Contains(directoryAttributes[0]))
                    {
                        directoryObj.Add(directoryAttributes[0], directoryGroupTypeValue);
                    }
                    else
                    {
                        int num = (int)directoryObj[directoryAttributes[0]].Value;
                        if (GroupTypeUtils.TryGetExtendedGroupScopeValue(num, out aDGroupScope))
                        {
                            int directoryGroupTypeValue1 = GroupTypeUtils.GetDirectoryGroupTypeValue(aDGroupScope);
                            num = num & ~directoryGroupTypeValue1;
                        }
                        directoryObj[directoryAttributes[0]].Value = num + directoryGroupTypeValue;
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
Exemplo n.º 2
0
 public static bool TryGetExtendedGroupScopeValue(int ldapgroupTypeValue, out ADGroupScope groupScope)
 {
     if ((ldapgroupTypeValue & 4) != 4)
     {
         if ((ldapgroupTypeValue & 2) != 2)
         {
             if ((ldapgroupTypeValue & 8) != 8)
             {
                 groupScope = ADGroupScope.DomainLocal;
                 return(false);
             }
             else
             {
                 groupScope = ADGroupScope.Universal;
                 return(true);
             }
         }
         else
         {
             groupScope = ADGroupScope.Global;
             return(true);
         }
     }
     else
     {
         groupScope = ADGroupScope.DomainLocal;
         return(true);
     }
 }
Exemplo n.º 3
0
        public static IADOPathNode ToSearchGroupScope(string extendedAttributeName, string[] directoryAttributes, IADOPathNode filterClause, CmdletSessionInfo cmdletSessionInfo)
        {
            ADGroupScope      aDGroupScope      = ADGroupScope.DomainLocal;
            BinaryADOPathNode binaryADOPathNode = filterClause as BinaryADOPathNode;

            if (binaryADOPathNode == null)
            {
                throw new ArgumentException(StringResources.SearchConverterNotBinaryNode);
            }
            else
            {
                if (binaryADOPathNode.Operator == ADOperator.Eq || binaryADOPathNode.Operator == ADOperator.Ne)
                {
                    IDataNode rightNode = binaryADOPathNode.RightNode as IDataNode;
                    if (rightNode == null)
                    {
                        throw new ArgumentException(StringResources.SearchConverterRHSNotDataNode);
                    }
                    else
                    {
                        if (!Utils.TryParseEnum <ADGroupScope>(rightNode.DataObject.ToString(), out aDGroupScope))
                        {
                            object[] str = new object[2];
                            str[0] = rightNode.DataObject.ToString();
                            str[1] = extendedAttributeName;
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterInvalidValue, str));
                        }
                        else
                        {
                            PropertyADOPathNode propertyADOPathNode = new PropertyADOPathNode(directoryAttributes[0]);
                            ObjectADOPathNode   objectADOPathNode   = new ObjectADOPathNode((object)GroupTypeUtils.GetDirectoryGroupTypeValue(aDGroupScope));
                            IADOPathNode        aDOPathNode         = new BinaryADOPathNode(ADOperator.Band, propertyADOPathNode, objectADOPathNode);
                            if (binaryADOPathNode.Operator != ADOperator.Eq)
                            {
                                return(ADOPathUtil.CreateNotClause(aDOPathNode));
                            }
                            else
                            {
                                return(aDOPathNode);
                            }
                        }
                    }
                }
                else
                {
                    object[]     objArray        = new object[2];
                    ADOperator[] aDOperatorArray = new ADOperator[2];
                    aDOperatorArray[1] = ADOperator.Ne;
                    objArray[0]        = SearchConverters.ConvertOperatorListToString(aDOperatorArray);
                    objArray[1]        = extendedAttributeName;
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.SearchConverterSupportedOperatorListErrorMessage, objArray));
                }
            }
        }
Exemplo n.º 4
0
		public static int GetDirectoryGroupTypeValue(ADGroupScope groupScope)
		{
			ADGroupScope aDGroupScope = groupScope;
			switch (aDGroupScope)
			{
				case ADGroupScope.DomainLocal:
				{
					return 4;
				}
				case ADGroupScope.Global:
				{
					return 2;
				}
				case ADGroupScope.Universal:
				{
					return 8;
				}
			}
			return 0;
		}
Exemplo n.º 5
0
        public static int GetDirectoryGroupTypeValue(ADGroupScope groupScope)
        {
            ADGroupScope aDGroupScope = groupScope;

            switch (aDGroupScope)
            {
            case ADGroupScope.DomainLocal:
            {
                return(4);
            }

            case ADGroupScope.Global:
            {
                return(2);
            }

            case ADGroupScope.Universal:
            {
                return(8);
            }
            }
            return(0);
        }
Exemplo n.º 6
0
		public static bool TryGetExtendedGroupScopeValue(int ldapgroupTypeValue, out ADGroupScope groupScope)
		{
			if ((ldapgroupTypeValue & 4) != 4)
			{
				if ((ldapgroupTypeValue & 2) != 2)
				{
					if ((ldapgroupTypeValue & 8) != 8)
					{
						groupScope = ADGroupScope.DomainLocal;
						return false;
					}
					else
					{
						groupScope = ADGroupScope.Universal;
						return true;
					}
				}
				else
				{
					groupScope = ADGroupScope.Global;
					return true;
				}
			}
			else
			{
				groupScope = ADGroupScope.DomainLocal;
				return true;
			}
		}
Exemplo n.º 7
0
        public void AddGroup(string parentGUID, string groupName, ADGroupType groupType, ADGroupScope groupScope)
        {
            DirectoryEntry de;
            DirectoryEntry deGroup;

            if (IsValidGroupName(groupName) == true)
            {
                if (!string.IsNullOrEmpty(parentGUID))
                {
                    de = GetDirectoryEntry(parentGUID);
                }
                else
                {
                    de = GetDirectoryEntry();
                }

                if (de is object)
                {
                    deGroup = de.Children.Add("CN=" + EscapeInvalidLDAPCharacters(groupName), SCHEMA_CLASS_GROUP);
                    deGroup.Properties["sAMAccountName"].Value = groupName;
                    deGroup.Properties["groupType"].Value      = (int)groupType | (int)groupScope;
                    deGroup.CommitChanges();
                }
            }
            else
            {
                throw new ArgumentException(string.Format("Group name contains one or more invalid characters. Invalid characters in a group name are {0}", INVALID_GROUPNAME_CHRS));
            }
        }