/// <summary>
 /// Adds all the "user"/"group" objects to the tree
 /// </summary>
 /// <param name="container"></param>
 /// <param name="parentPage"></param>
 /// <param name="plugin"></param>
 /// <param name="PageType"></param>
 public AddUsertoGroup(IPlugInContainer container, MPPage parentPage, ADUCPlugin plugin, int PageType)
 : this()
 {
     this.IPlugInContainer = container;
     _addplugin = plugin;
     _aducRootnode = _addplugin.GetPlugInNode();
     _PageType = PageType;
     
     if (_aducRootnode.Nodes.Count > 0)
     {
         ADUCDirectoryNode rootNode =
         ADUCDirectoryNode.GetDirectoryRoot(_addplugin.GetpluginContext(),            
         _addplugin.GetRootDN(),
         Resources.ADUC, typeof (ADUCPage), _addplugin);
         
         if (rootNode != null)
         {
             treeView1.Nodes.Add(rootNode);
             rootNode.Refresh();
             treeView1.ExpandAll();
         }
     }
     else
     {
         Logger.Log("The LWTreeView control does not have any nodes.");
     }
 }
    public static bool OnApply_helper(List<string> MemofDnList, List<string> AddedGroups, List<string> RemovedGroups, ADUCDirectoryNode _dirnode, MPPage page)
    {
        bool retVal = true;

        if (MemofDnList != null && MemofDnList.Count > 0)
        {
            retVal = OnApply_inner(AddedGroups, _dirnode, page, ADDING);
            if (!retVal)
            {
                return retVal;
            }
            retVal = OnApply_inner(RemovedGroups, _dirnode, page, REMOVING);
            if (AddedGroups != null && AddedGroups.Count > 0)
            {
                AddedGroups.Clear();
            }
            if (RemovedGroups != null && RemovedGroups.Count > 0)
            {
                RemovedGroups.Clear();
            }
        }
        return retVal;
    }
    /// <summary>
    /// Modifies the "member" attribute for the selected "user" or "group" in AD schema template
    /// </summary>
    /// <param name="changedGroups"></param>
    /// <param name="_dirnode"></param>
    /// <param name="page"></param>
    /// <param name="operation"></param>
    /// <returns></returns>
    private static bool OnApply_inner(List<string> changedGroups, ADUCDirectoryNode _dirnode, MPPage page, int operation)
    {
        bool retVal = true;
        int ret = -1;
        string AdminGroupDN = string.Concat("CN=Administrators,CN=Builtin,", _dirnode.LdapContext.RootDN);

        if (changedGroups != null && changedGroups.Count > 0)
        {
            foreach (string newGroupname in changedGroups)
            {
                List<string> members = new List<string>();
                members = GetMemberAttrofGroup(newGroupname.Trim(), _dirnode);

                bool existingMember = false;

                //if we want to add, we need check whether it is already a member of the group
                if (operation == ADDING)
                {
                    foreach (string str in members)
                    {
                        if (str.Equals(_dirnode.DistinguishedName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            existingMember = true;
                            break;
                        }
                    }
                }

                if (!existingMember)
                {
                    if (operation == ADDING)
                    {
                        members.Add(_dirnode.DistinguishedName);
                    }
                    if (operation == REMOVING)
                    {
                        members.Remove(_dirnode.DistinguishedName);
                    }

                    if (newGroupname.Trim().ToLower().Equals(AdminGroupDN.Trim().ToLower()))
                    {
                        string userlogonName = OnApply_GetObjectRealmName(_dirnode);
                        LUGAPI.NetAddGroupMember(_dirnode.LdapContext.DomainControllerName, "Administrators", userlogonName);
                    }
                    else
                    {
                        string[] members_values = new string[members.Count + 1];
                        members.CopyTo(members_values);
                        members_values[members.Count] = null;

                        LDAPMod memberattr_Info =
                        new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "member",
                        members_values);

                        LDAPMod[] attrinfo = new LDAPMod[] { memberattr_Info };

                        if (_dirnode != null)
                        {
                            ret = _dirnode.LdapContext.ModifySynchronous(newGroupname.Trim(), attrinfo);

                            if (ret == 0)
                            {
                                retVal = true;
                            }
                            else
                            {
                                string sMsg = ErrorCodes.LDAPString(ret);
                                MessageBox.Show(page, sMsg, "Likewise Management Console",
                                MessageBoxButtons.OK);
                                retVal = false;
                            }
                        }
                    }
                }
            }
            if (ret == 0)
            {
                if (operation == ADDING)
                {
                    MessageBox.Show(
                    page,
                    "User/Computer/Group list is added to new groups!",
                    CommonResources.GetString("Caption_Console"),
                    MessageBoxButtons.OK);
                }
                if (operation == REMOVING)
                {
                    MessageBox.Show(
                    page,
                    "User/Computer/Group list is removed from chose groups!",
                    CommonResources.GetString("Caption_Console"),
                    MessageBoxButtons.OK);
                }
            }
        }
        return retVal;
    }
Exemple #4
0
        /// <summary>
        /// Adds a new page to the container.
        /// </summary>
        /// <param name="page">The page </param>
        /// <param name="menuItem"></param>
        /// <param name="position">zero based position of the page</param>
        public void AddPage(MPPage page, MPMenuItem menuItem, int position)
        {
            htPages.Add(menuItem.pageID, page);

            if (page.Size.Width > largestPageSize.Width)
            {
                largestPageSize.Width = page.Size.Width;
            }
            if (page.Size.Height > largestPageSize.Height)
            {
                largestPageSize.Height = page.Size.Height;
            }

            TabPage tabPage = new TabPage(menuItem.menuText);

            tabPage.Name = page.PageID;
            tabPage.UseVisualStyleBackColor = true;
            tabPage.Size = page.Size;
            if (bPagesSizable)
            {
                page.Dock = DockStyle.Fill;
            }
            tabPage.Controls.Add(page);
            if (tabControl.ImageList != null)
            {
                tabPage.ImageIndex =
                    tabControl.ImageList.Images.IndexOfKey(page.PageID);
            }
            page.ParentContainer  = this;
            page.IPlugInContainer = container;
            page.position         = position;

            // Menu positioning:
            // The assumption is that the caller will either care about
            // positioning and give each page a unique position or
            // that he will use POSITION_END or POSITION_BEGINING for all pages.

            if (page.position == MPMenu.POSITION_END || tabControl.TabPages.Count == 0)
            {
                tabControl.TabPages.Add(tabPage);
            }
            else
            {
                TabPage[] arrPages = new TabPage[tabControl.TabPages.Count + 1];
                int       i;
                int       j = 0;
                for (i = 0; i < tabControl.TabPages.Count; i++)
                {
                    MPPage curPage = GetPage(tabControl.TabPages[i].Name);
                    if (i == j && page.position < curPage.position)
                    {
                        arrPages[j++] = tabPage;
                    }
                    arrPages[j++] = tabControl.TabPages[i];
                }

                // insert at the end
                if (i == j)
                {
                    arrPages[j++] = tabPage;
                }

                // the tabControl.TabPages.Insert( int index, TabPage page ) does not work for some reason
                tabControl.TabPages.Clear();
                tabControl.TabPages.AddRange(arrPages);
            }

            // we need to remember the index of the tab page so we can get it
            // later by page ID
            htTabPages.Add(page.PageID, tabPage);
        }
 public ObjectPropertyInfo(CredentialEntry ce,
                           string server,
                           string name,
                           ADUCDirectoryNode node,
                           MPPage pp
                           )
 {
     this.ce = ce;
     servername = server;
     objectName = name;
     dirnode = node;
     page = pp;
 }
        /// <summary>
        /// Adds a new page to the container.
        /// </summary>
        /// <param name="page">The page </param>
        /// <param name="menuItem"></param>
        /// <param name="position">zero based position of the page</param>
        public void AddPage(MPPage page, MPMenuItem menuItem, int position)
        {
            htPages.Add(menuItem.pageID, page);

            if (page.Size.Width > largestPageSize.Width)
                largestPageSize.Width = page.Size.Width;
            if (page.Size.Height > largestPageSize.Height)
                largestPageSize.Height = page.Size.Height;

            TabPage tabPage = new TabPage(menuItem.menuText);
            tabPage.Name = page.PageID;
            tabPage.UseVisualStyleBackColor = true;
            tabPage.Size = page.Size;
            if (bPagesSizable)
                page.Dock = DockStyle.Fill;
            tabPage.Controls.Add(page);
            if (tabControl.ImageList != null)
            {
                tabPage.ImageIndex =
                    tabControl.ImageList.Images.IndexOfKey(page.PageID);
            }
            page.ParentContainer = this;
            page.IPlugInContainer = container;
            page.position = position;

            // Menu positioning:
            // The assumption is that the caller will either care about
            // positioning and give each page a unique position or
            // that he will use POSITION_END or POSITION_BEGINING for all pages.

            if (page.position == MPMenu.POSITION_END || tabControl.TabPages.Count == 0)
            {
                tabControl.TabPages.Add(tabPage);
            }
            else
            {
                TabPage[] arrPages = new TabPage[tabControl.TabPages.Count + 1];
                int i;
                int j = 0;
                for (i = 0; i < tabControl.TabPages.Count; i++)
                {
                    MPPage curPage = GetPage(tabControl.TabPages[i].Name);
                    if (i == j && page.position < curPage.position)
                        arrPages[j++] = tabPage;
                    arrPages[j++] = tabControl.TabPages[i];
                }

                // insert at the end
                if (i == j)
                    arrPages[j++] = tabPage;

                // the tabControl.TabPages.Insert( int index, TabPage page ) does not work for some reason
                tabControl.TabPages.Clear();
                tabControl.TabPages.AddRange(arrPages);
            }

            // we need to remember the index of the tab page so we can get it
            // later by page ID
            htTabPages.Add(page.PageID, tabPage);
        }