private void ShowDsPickerDialog(object ADObjects)
        {
            string distinguishedName = string.Empty;
            string domainName        = _securityDescriptor.GetDCInfo(null);

            distinguishedName = System.DirectoryServices.SDSUtils.DomainNameToDN(domainName);

            // show picker
            string sLdapPath = string.Format("LDAP://{0}/{1}", domainName, distinguishedName);
            string sProtocol;
            string sServer;
            string sCNs;
            string sDCs;

            System.DirectoryServices.SDSUtils.CrackPath(sLdapPath, out sProtocol, out sServer, out sCNs, out sDCs);
            System.DirectoryServices.Misc.DsPicker dsPickerDlg = new System.DirectoryServices.Misc.DsPicker();
            dsPickerDlg.SetData(System.DirectoryServices.Misc.DsPicker.DialogType.SELECT_USERS_OR_GROUPS,
                                sProtocol,
                                sServer,
                                sDCs,
                                true);
            if (dsPickerDlg.waitForm != null && dsPickerDlg.waitForm.bIsInterrupted)
            {
                return;
            }

            if (dsPickerDlg.ShowDialog(this) == DialogResult.OK)
            {
                if (dsPickerDlg.ADobjectsArray != null && dsPickerDlg.ADobjectsArray.Length != 0)
                {
                    ADObjects = dsPickerDlg.ADobjectsArray;
                }
            }
        }
Beispiel #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //AdvancedPermissionsControlDlg advancedPermissionsControlDlg = new AdvancedPermissionsControlDlg(_securityDescriptor, _ObjectPath);
            //advancedPermissionsControlDlg.ShowDialog(this);
            //return;

            string distinguishedName = string.Empty;
            string domainName        = _securityDescriptor.GetDCInfo(null);

            distinguishedName = System.DirectoryServices.SDSUtils.DomainNameToDN(domainName);

            // show picker
            string sLdapPath = string.Format("LDAP://{0}/{1}", domainName, distinguishedName);
            string sProtocol;
            string sServer;
            string sCNs;
            string sDCs;

            System.DirectoryServices.SDSUtils.CrackPath(sLdapPath, out sProtocol, out sServer, out sCNs, out sDCs);
            System.DirectoryServices.Misc.DsPicker dsPickerDlg = new System.DirectoryServices.Misc.DsPicker();
            dsPickerDlg.SetData(System.DirectoryServices.Misc.DsPicker.DialogType.SELECT_USERS_OR_GROUPS,
                                sProtocol,
                                sServer,
                                sDCs,
                                true);
            if (dsPickerDlg.waitForm != null && dsPickerDlg.waitForm.bIsInterrupted)
            {
                return;
            }

            if (dsPickerDlg.ShowDialog(this) == DialogResult.OK)
            {
                if (dsPickerDlg.ADobjectsArray != null && dsPickerDlg.ADobjectsArray.Length != 0)
                {
                    foreach (System.DirectoryServices.Misc.ADObject ado in dsPickerDlg.ADobjectsArray)
                    {
                        byte[] sObjectSid     = ado.de.Properties["objectSid"].Value as byte[];
                        string sAMAccountName = ado.de.Properties["sAMAccountName"].Value as string;

                        string sSID = _securityDescriptor.ConvetByteSidToStringSid(sObjectSid);

                        //Need to set the permission check list in the permission set
                        LwAccessControlEntry Ace = new LwAccessControlEntry();
                        Ace.SID        = sSID;
                        Ace.Username   = sAMAccountName;
                        Ace.AceType    = 0;
                        Ace.AceFlags   = 0;
                        Ace.AccessMask = Convert.ToInt64(LwAccessMask.ACCESS_MASK.Special_Permissions).ToString();

                        bool bIsEntryFound = false;
                        List <LwAccessControlEntry> acelist = null;

                        foreach (ListViewItem item in lvGroupOrUserNames.Items)
                        {
                            if (item.Text.Contains(sAMAccountName))
                            {
                                acelist = item.Tag as List <LwAccessControlEntry>;
                                foreach (LwAccessControlEntry aceEntry in acelist)
                                {
                                    if (aceEntry.AceType == 0)
                                    {
                                        aceEntry.AccessMask = Ace.AccessMask;
                                        item.Tag            = acelist;
                                        item.Selected       = true;
                                    }
                                }
                            }
                        }
                        if (!bIsEntryFound)
                        {
                            ListViewItem lvItem = new ListViewItem(sAMAccountName);
                            acelist = new List <LwAccessControlEntry>();
                            acelist.Add(Ace);
                            lvItem.Tag = acelist; //Need to initialize the DaclInfo for the object
                            lvGroupOrUserNames.Items.Add(lvItem);

                            lvGroupOrUserNames.Items[lvGroupOrUserNames.Items.Count - 1].Selected = true;
                        }
                        _addedObjects.Add(sAMAccountName, acelist);
                    }
                }
            }
        }