示例#1
0
			/// <summary>
			/// Add to the cache.
			/// </summary>
			/// <param name="item">The item.</param>
			public void Add(
				ADGroupInfo item )
			{
				cachedItems.Add( item );
			}
示例#2
0
		// ------------------------------------------------------------------
		#endregion

		#region Private methods and properties.
		// ------------------------------------------------------------------

		/// <summary>
		/// Gets the group info.
		/// </summary>
		/// <param name="searcher">The searcher.</param>
		/// <returns></returns>
		private ADGroupInfo GetGroupInfo(
			DirectorySearcher searcher )
		{
			searcher.SizeLimit = adSizeReturn;

			searcher.PropertiesToLoad.Add( @"objectGUID" );
			searcher.PropertiesToLoad.Add( @"sAMAccountName" );
			searcher.PropertiesToLoad.Add( @"cn" );
			searcher.PropertiesToLoad.Add( @"name" );

			searcher.PropertiesToLoad.Add( @"mail" );
			searcher.PropertiesToLoad.Add( @"groupScope" );
			searcher.PropertiesToLoad.Add( @"groupType" );
			searcher.PropertiesToLoad.Add( @"description" );

			// --

			SearchResult result = searcher.FindOne();
			if ( result == null )
			{
				return null;
			}
			else
			{
				ADGroupInfo info = new ADGroupInfo( this );

				// Add relative DN.
				string dn = result.Path;
				string basePath =
					string.Format( @"LDAP://{0}",
					configuration.LdapServer );
				if ( dn.StartsWith( basePath, StringComparison.InvariantCultureIgnoreCase ) )
				{
					dn = dn.Substring( basePath.Length ).Trim( '/' );
				}
				info.DN = dn;

				byte[] guidBytes = (byte[])result.Properties[@"objectGUID"][0];

				info.Guid = new Guid( guidBytes );
				info.SamName = ReadFieldString( GetRP( result.Properties[@"sAMAccountName"] ) );
				info.CN = ReadFieldString( GetRP( result.Properties[@"cn"] ) );
				info.Name = ReadFieldString( GetRP( result.Properties[@"name"] ) );

				info.EMail = ReadFieldString( GetRP( result.Properties[@"mail"] ) );
				info.Scope = ReadFieldString( GetRP( result.Properties[@"groupScope"] ) );
				info.Type = ReadFieldInteger( GetRP( result.Properties[@"groupType"] ) );
				info.Description = ReadFieldString( GetRP( result.Properties[@"description"] ) );

				return info;
			}
		}
示例#3
0
		/// <summary>
		/// Gets the group child users.
		/// </summary>
		/// <param name="parentGroup">The parent group.</param>
		/// <returns></returns>
		public ADUserInfo[] GetGroupChildUsers(
			ADGroupInfo parentGroup )
		{
			List<ADUserInfo> list = new List<ADUserInfo>();

			// --

			// Loop to get past the 1000 items limit.
			for ( int i = 0; i < SliceLoopLimit; ++i )
			{
				string searchFilter = GetSliceLoopFilter( i );

				// --

				DirectoryEntry entry = GetDirectoryEntry( LdapBaseString );

				DirectorySearcher searcher = new DirectorySearcher( entry );
				searcher.Filter = string.Format(
					@"(&(objectCategory=person){0}(memberOf={1}))",
					searchFilter,
					parentGroup.DN );

				LogCentral.Current.LogDebug(
					string.Format(
					@"Searching with search filter '{0}' and size limit {1}.",
					searcher.Filter,
					adSizeReturn ) );

				searcher.PropertiesToLoad.Add( @"objectGUID" );
				searcher.SizeLimit = adSizeReturn;

				SearchResultCollection results = searcher.FindAll();

				LogCentral.Current.LogDebug(
					string.Format(
					@"Searching returned {0} items.",
					results.Count ) );

				// --

				foreach ( SearchResult result in results )
				{
					Guid guid = new Guid(
						(byte[])result.Properties[@"objectGUID"][0] );
					list.Add( GetUserInfoByGuid( guid ) );
				}
			}

			// --

			if ( list.Count <= 0 )
			{
				return null;
			}
			else
			{
				return list.ToArray();
			}
		}
示例#4
0
		/// <summary>
		/// Get a list of all groups of a certain group.
		/// </summary>
		/// <param name="adInfo">The group to query the groups from.</param>
		/// <returns>
		/// Returns an array of all groups the given group
		/// is member of.
		/// </returns>
		public ADGroupInfo[] GetGroupParentGroups(
			ADGroupInfo adInfo )
		{
			byte[] guidBytes = adInfo.Guid.ToByteArray();
			string guidString = HexEscape( guidBytes );

			DirectoryEntry entry = GetDirectoryEntry( LdapBaseString );

			DirectorySearcher searcher = new DirectorySearcher( entry );
			searcher.Filter =
				string.Format(
				@"(&(objectCategory=group)(objectGUID={0}))",
				guidString );

			searcher.PropertiesToLoad.Add( @"memberOf" );
			searcher.SizeLimit = adSizeReturn;

			SearchResult result = searcher.FindOne();
			if ( result == null )
			{
				LogCentral.Current.LogDebug(
					string.Format(
					@"GetGroupGroups(): (B) searcher.FindOne() returned NULL, exiting with return value NULL."
					) );

				return null;
			}
			else if ( result.Properties[@"memberOf"] == null )
			{
				return null;
			}
			else
			{
				List<ADGroupInfo> list = new List<ADGroupInfo>();

				foreach ( object val in result.Properties[@"memberOf"] )
				{
					ADGroupInfo info = GetGroupInfoByDN(
						Convert.ToString( val ) );
					if ( info != null )
					{
						list.Add( info );
					}
				}

				return list.ToArray();
			}
		}
示例#5
0
		// ------------------------------------------------------------------
		#endregion

		#region Private methods.
		// ------------------------------------------------------------------

		/// <summary>
		/// Helper.
		/// </summary>
		/// <param name="group">The group.</param>
		/// <param name="groupName">Name of the group.</param>
		/// <param name="checkedGroupSamNames">The checked group sam names.</param>
		/// <returns></returns>
		private bool DoCheckIsMemberOfGroup(
			ADGroupInfo group,
			string groupName,
			Set<string> checkedGroupSamNames )
		{
			if ( group == null )
			{
				return false;
			}
			else
			{
				// Only process once.
				if ( !checkedGroupSamNames.Contains( group.SamName ) )
				{
					checkedGroupSamNames.Add( group.SamName );

					LogCentral.Current.LogInfo(
						string.Format(
						@"[AD] About to check whether group with SAM name '{0}' equals group name '{1}'.",
						group.SamName,
						groupName
						) );

					if ( group.SamName.ToLower() == groupName.ToLower() )
					{
						return true;
					}

					// --
					// Recurse to parents.

					ADGroupInfo[] pgroups = group.ParentGroups;

					if ( pgroups != null )
					{
						foreach ( ADGroupInfo pgroup in pgroups )
						{
							if ( DoCheckIsMemberOfGroup(
								pgroup,
								groupName,
								checkedGroupSamNames ) )
							{
								return true;
							}
						}
					}
				}

				return false;
			}
		}