Beispiel #1
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));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            string path;

            if (string.Compare(this.Domain, this.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.Domain = string.Empty;
            }

            if (string.IsNullOrEmpty(this.Domain))
            {
                // Connect to a computer
                path           = "WinNT://" + this.MachineName + ",computer";
                this.groupType = ADGroupType.Local;
                this.target    = this.MachineName;
            }
            else
            {
                // connect to a domain
                path = "WinNT://" + this.Domain + ",domain";
                if (this.GroupType == "0")
                {
                    this.groupType = ADGroupType.Global;
                }

                this.target = this.domain;
            }

            using (this.activeDirEntry = new DirectoryEntry(path))
            {
                switch (this.TaskAction)
                {
                case AddGroupToGroupTaskAction:
                case RemoveGroupFromGroupTaskAction:
                    this.GroupGroup();
                    break;

                case AddUserTaskAction:
                    this.AddUser();
                    break;

                case DeleteUserTaskAction:
                    this.DeleteEntity("User", this.User);
                    break;

                case AddGroupTaskAction:
                    this.AddGroup();
                    break;

                case DeleteGroupTaskAction:
                    this.DeleteEntity("Group", this.Group);
                    break;

                case AddUserToGroupTaskAction:
                    this.AddUserToGroup();
                    break;

                case DeleteUserFromGroupTaskAction:
                    this.DeleteUserFromGroup();
                    break;

                case CheckUserExistsTaskAction:
                    this.CheckExistsForUser(this.User[0].ItemSpec);
                    break;

                case CheckUserPasswordTaskAction:
                    this.CheckUserPassword();
                    break;

                case GetUserPasswordTaskAction:
                    this.GetUserPassword();
                    break;

                case CheckGroupExistsTaskAction:
                    this.CheckExists("group", this.Group[0].ItemSpec);
                    break;

                case GrantPrivilegeTaskAction:
                    this.GrantUserPrivilege();
                    break;

                case RemovePrivilegeTaskAction:
                    // Not implemented this.RemoveUserPrivilege();
                    break;

                case GetGroupMembersTaskAction:
                    this.GetGroupMembers();
                    break;

                default:
                    this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
                    return;
                }
            }
        }
        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            string path;
            if (string.Compare(this.Domain, this.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.Domain = string.Empty;
            }

            if (string.IsNullOrEmpty(this.Domain))
            {
                // Connect to a computer
                path = "WinNT://" + this.MachineName + ",computer";
                this.groupType = ADGroupType.Local;
                this.target = this.MachineName;
            }
            else
            {
                // connect to a domain
                path = "WinNT://" + this.Domain + ",domain";
                if (this.GroupType == "0")
                {
                    this.groupType = ADGroupType.Global;
                }

                this.target = this.domain;
            }

            using (this.activeDirEntry = new DirectoryEntry(path))
            {
                switch (this.TaskAction)
                {
                    case AddGroupToGroupTaskAction:
                    case RemoveGroupFromGroupTaskAction:
                        this.GroupGroup();
                        break;
                    case AddUserTaskAction:
                        this.AddUser();
                        break;
                    case DeleteUserTaskAction:
                        this.DeleteEntity("User", this.User);
                        break;
                    case AddGroupTaskAction:
                        this.AddGroup();
                        break;
                    case DeleteGroupTaskAction:
                        this.DeleteEntity("Group", this.Group);
                        break;
                    case AddUserToGroupTaskAction:
                        this.AddUserToGroup();
                        break;
                    case DeleteUserFromGroupTaskAction:
                        this.DeleteUserFromGroup();
                        break;
                    case CheckUserExistsTaskAction:
                        this.CheckExistsForUser(this.User[0].ItemSpec);
                        break;
                    case CheckUserPasswordTaskAction:
                        this.CheckUserPassword();
                        break;
                    case GetUserPasswordTaskAction:
                        this.GetUserPassword();
                        break;
                    case CheckGroupExistsTaskAction:
                        this.CheckExists("group", this.Group[0].ItemSpec);
                        break;
                    case GrantPrivilegeTaskAction:
                        this.GrantUserPrivilege();
                        break;
                    case RemovePrivilegeTaskAction:
                        // Not implemented this.RemoveUserPrivilege();
                        break;
                    case GetGroupMembersTaskAction:
                        this.GetGroupMembers();
                        break;
                    default:
                        this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
                        return;
                }
            }
        }