Ejemplo n.º 1
0
        public void Ldap_Add_Object_SASL_Success()
        {
            ILdapConnection ldapConnection = LdapConnection.LdapInit(hostName, portNumber);

            Assert.IsNotNull(ldapConnection);

            ldapConnection.VmDirSafeLDAPBind(hostName, upn, password);

            string basedn = "cn=ExampleAddSasl,cn=Users,dc=vsphere,dc=local";

            LdapMod[] lMods = new LdapMod[3];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "cn", new string[] { "ExampleAddSasl", null });

            lMods[1] = new LdapMod(0, "objectClass", new string[] { "person", null });

            lMods[2] = new LdapMod(0, "sn", new string[] { "Allen", null });

            try
            {
                ldapConnection.AddObject(basedn, lMods);
            }
            catch
            {
                Assert.Fail();
            }
        }
 public void OnClickOKButton(object sender, EventArgs e)
 {
     try {
         DoValidate();
         if (_properties.Count > 0 && ds.PendingMod.Count > 0)
         {
             LdapMod[] user = new LdapMod[ds.PendingMod.Count];
             int       i    = 0;
             foreach (var entry in ds.PendingMod)
             {
                 string[] entries = entry.Value.Split(',');
                 string[] values  = new string[entries.Length + 1];
                 entries.CopyTo(values, 0);
                 values [entries.Length] = null;
                 user [i] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, entry.Key, values);
                 i++;
             }
             serverDTO.Connection.ModifyObject(itemName, user);
         }
     } catch (Exception ex) {
         UIErrorHelper.ShowAlert("", ex.Message);
     } finally {
         this.Close();
         NSApplication.SharedApplication.StopModalWithCode(1);
     }
 }
Ejemplo n.º 3
0
        public void AddGroup()
        {
            GroupDTO dto = new GroupDTO();
            var      frm = new AddGroup(dto);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                MiscUtilsService.CheckedExec(delegate()
                {
                    LdapMod[] user = new LdapMod[4];
                    user[0]        = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_CN, new string[] {
                        dto.cn,
                        null
                    });
                    user[1] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_GROUPTYPE, new string[] {
                        dto.groupType.ToString(),
                        null
                    });
                    user[2] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SAM_ACCOUNT_NAME, new string[] {
                        dto.sAMAccountName,
                        null
                    });
                    user[3] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_OBJECT_CLASS, new string[] {
                        dto.objectClass,
                        null
                    });
                    string dn = string.Format("cn={0},{1}", dto.cn, Dn);
                    ServerDTO.Connection.AddObject(dn, user);
                    ClearDummyNode();
                    var oc = VMDirUtil.Utilities.GetObjectClassList(ServerDTO, dn, LdapScope.SCOPE_BASE);
                    this.Nodes.Insert(0, new DirectoryExpandableNode(dn, oc, ServerDTO, PropertiesCtl));
                    MMCDlgHelper.ShowInformation(VMDirConstants.STAT_GRP_ADD_SUCC);
                });
            }
        }
Ejemplo n.º 4
0
        public void LdapModify_AddAttribute_Failure()
        {
            ILdapConnection ldapConnection = LdapConnection.LdapInit(hostName, portNumber);

            Assert.IsNotNull(ldapConnection);

            ldapConnection.LdapSimpleBindS(myDN, password);

            string basedn = "cn=lModAdd,cn=Users,dc=vsphere,dc=local";

            LdapMod[] lMods = new LdapMod[1];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "cn", new string[] { "Allen", null });


            try
            {
                ldapConnection.ModifyObject(basedn, lMods);
                Assert.Fail();
            }
            catch
            {
                //Expected Exception
            }
        }
Ejemplo n.º 5
0
        public static void LdapModify_ReplaceAttribute_Success(ILdapConnection ldapConnection, LdapUser user)
        {
            LdapMod[] lMods = new LdapMod[1];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, "sn", new string[] { "Barry" });

            try
            {
                ldapConnection.ModifyObject(user.DN, lMods);
            }
            catch
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 6
0
        public static void LdapModify_AddAttribute_Failure(ILdapConnection ldapConnection, LdapUser user)
        {
            LdapMod[] lMods = new LdapMod[1];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "cn", new string[] { "Allen" });

            try
            {
                ldapConnection.ModifyObject(user.DN, lMods);
                Assert.Fail();
            }
            catch
            {
                //Expected Exception
            }
        }
Ejemplo n.º 7
0
        public void ShowAddUser()
        {
            UserDTO userDTO          = new UserDTO();
            AddNewUserController awc = new AddNewUserController(userDTO);
            nint res = NSApplication.SharedApplication.RunModalForWindow(awc.Window);

            if (res == (nint)VMIdentityConstants.DIALOGOK)
            {
                UIErrorHelper.CheckedExec(delegate()
                {
                    LdapMod[] user = new LdapMod[6];
                    user[0]        = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_GIVEN_NAME, new string[] {
                        userDTO.FirstName,
                        null
                    });
                    user[1] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SN, new string[] {
                        userDTO.LastName,
                        null
                    });
                    user[2] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_CN, new string[] {
                        userDTO.Cn,
                        null
                    });
                    user[3] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_KRB_UPN, new string[] {
                        userDTO.UPN,
                        null
                    });
                    user[4] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SAM_ACCOUNT_NAME, new string[] {
                        userDTO.SAMAccountName,
                        null
                    });
                    user[5] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_OBJECT_CLASS, new string[] {
                        VMDirConstants.USER_OC,
                        null
                    });
                    string dn = string.Format("cn={0},{1}", userDTO.Cn, Dn);
                    ServerDTO.Connection.AddObject(dn, user);
                    UIErrorHelper.ShowInformation(VMDirConstants.STAT_USR_ADD_SUCC);
                    var oc = Utilities.GetObjectClassList(ServerDTO, dn, LdapScope.SCOPE_BASE);
                    this.Children.Insert(0, new DirectoryNode(dn, oc, ServerDTO, this));
                    //ReloadChildren();
                    RefreshProperties();
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadOutlineView", this);
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this);
                });
            }
        }
Ejemplo n.º 8
0
        private LdapUser(ILdapConnection ldapConnection, string UserName)
        {
            this.UserName = UserName;
            this.DN       = String.Format("cn={0},cn=Users,dc=vsphere,dc=local", UserName);

            LdapMod[] lMods = new LdapMod[7];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "cn", new string[] { UserName });
            lMods[1] = new LdapMod(0, "objectClass", new string[] { "person", "top", "organizationalPerson", "user" });
            lMods[2] = new LdapMod(0, "givenName", new string[] { "Laddy McLdap" });
            lMods[3] = new LdapMod(0, "userPrincipalName", new string[] { String.Format("{0}@vsphere.local", UserName) });
            lMods[4] = new LdapMod(0, "sAMAccountName", new string[] { UserName });
            lMods[5] = new LdapMod(0, "vmwPasswordNeverExpires", new string[] { "TRUE" });
            lMods[6] = new LdapMod(0, "userpassword", new string[] { "Admin!23" });

            ldapConnection.AddObject(DN, lMods);
        }
Ejemplo n.º 9
0
 public void ResetPassword()
 {
     MiscUtilsService.CheckedExec(delegate
     {
         var frm = new ResetUserPwdForm(Dn);
         if (frm.ShowDialog() == DialogResult.OK)
         {
             LdapMod[] mod = new LdapMod[1];
             mod[0]        = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, VMDirConstants.ATTR_USER_PASSWORD, new string[] {
                 frm.Password,
                 null
             });
             ServerDTO.Connection.ModifyObject(frm.Dn, mod);
             MMCDlgHelper.ShowInformation(VMDirConstants.STAT_PWD_RESET_SUCC);
         }
     });
 }
Ejemplo n.º 10
0
        void _parent_Apply(object sender, CancelEventArgs e)
        {
            try
            {
                if (_properties.Count > 0 && _pendingMods.Count > 0)
                {
                    var finalMods = new Dictionary <string, List <string> >();

                    foreach (var kv in _kvData)
                    {
                        if (_pendingMods.Contains(kv.Key))
                        {
                            if (finalMods.ContainsKey(kv.Key))
                            {
                                finalMods[kv.Key].Add(kv.Value);
                            }
                            else
                            {
                                finalMods.Add(kv.Key, new List <string>()
                                {
                                    kv.Value
                                });
                            }
                        }
                    }
                    LdapMod[] user = new LdapMod[finalMods.Count];
                    int       i    = 0;
                    foreach (var m in finalMods)
                    {
                        var values = m.Value.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
                        Array.Resize(ref values, values.Count() + 1);
                        user[i] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, m.Key, values);
                        i++;
                    }
                    ServerDTO.Connection.ModifyObject(_dn, user);
                    _pendingMods.Clear();
                    Bind();
                }
            }
            catch (Exception exp)
            {
                MiscUtilsService.ShowError(exp);
                e.Cancel = true;
            }
        }
Ejemplo n.º 11
0
        public void ShowAddUser()
        {
            AddNewUserDTO        userDTO = new AddNewUserDTO();
            AddNewUserController awc     = new AddNewUserController(userDTO);
            nint res = NSApplication.SharedApplication.RunModalForWindow(awc.Window);

            if (res == (nint)VMIdentityConstants.DIALOGOK)
            {
                UIErrorHelper.CheckedExec(delegate() {
                    LdapMod[] user = new LdapMod[6];
                    user [0]       = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_GIVEN_NAME, new string[] {
                        userDTO.FirstName,
                        null
                    });
                    user [1] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SN, new string[] {
                        userDTO.LastName,
                        null
                    });
                    user [2] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_CN, new string[] {
                        userDTO.Cn,
                        null
                    });
                    user [3] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_KRB_UPN, new string[] {
                        userDTO.UPN,
                        null
                    });
                    user [4] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SAM_ACCOUNT_NAME, new string[] {
                        userDTO.SAMAccountName,
                        null
                    });
                    user [5] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_OBJECT_CLASS, new string[] {
                        "user",
                        null
                    });
                    string dn = string.Format("cn={0},{1}", userDTO.Cn, Name);
                    ServerDTO.Connection.AddObject(dn, user);
                    UIErrorHelper.ShowAlert("", "Successfully added object");
                    ReloadChildren();
                    RefreshProperties();
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadOutlineView", this);
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this);
                });
            }
        }
Ejemplo n.º 12
0
        public void AddUser()
        {
            UserDTO userDTO = new UserDTO();
            var     frm     = new AddUser(userDTO);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                MiscUtilsService.CheckedExec(delegate()
                {
                    LdapMod[] user = new LdapMod[6];
                    user[0]        = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_GIVEN_NAME, new string[] {
                        userDTO.FirstName,
                        null
                    });
                    user[1] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SN, new string[] {
                        userDTO.LastName,
                        null
                    });
                    user[2] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_CN, new string[] {
                        userDTO.Cn,
                        null
                    });
                    user[3] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_KRB_UPN, new string[] {
                        userDTO.UPN,
                        null
                    });
                    user[4] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SAM_ACCOUNT_NAME, new string[] {
                        userDTO.SAMAccountName,
                        null
                    });
                    user[5] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_OBJECT_CLASS, new string[] {
                        VMDirConstants.USER_OC,
                        null
                    });
                    string dn = string.Format("cn={0},{1}", userDTO.Cn, Dn);
                    ServerDTO.Connection.AddObject(dn, user);
                    ClearDummyNode();
                    var oc = VMDirUtil.Utilities.GetObjectClassList(ServerDTO, dn, LdapScope.SCOPE_BASE);
                    this.Nodes.Insert(0, new DirectoryExpandableNode(dn, oc, ServerDTO, PropertiesCtl));
                    MMCDlgHelper.ShowInformation(VMDirConstants.STAT_USR_ADD_SUCC);
                });
            }
        }
Ejemplo n.º 13
0
        public void AddUserToGroup()
        {
            var frm = new AddToGroup(ServerDTO);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                MiscUtilsService.CheckedExec(delegate()
                {
                    string[] values   = new string[2];
                    values[1]         = null;
                    values[0]         = Dn;
                    LdapMod[] ldapVal = new LdapMod[1];
                    ldapVal[0]        = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_MEMBER, values);
                    ServerDTO.Connection.ModifyObject(frm.DNText, ldapVal);
                    MMCDlgHelper.ShowInformation(VMDirConstants.STAT_MEMBER_ADD_SUCC);
                    RefreshProperties();
                });
            }
        }
Ejemplo n.º 14
0
        public void ShowAddWindow()
        {
            SelectObjectClassWindowController swc = new SelectObjectClassWindowController(ServerDTO.Connection.SchemaManager);
            nint result = NSApplication.SharedApplication.RunModalForWindow(swc.Window);

            if (result == (nint)VMIdentityConstants.DIALOGOK)
            {
                CreateObjectWindowController cwc = new CreateObjectWindowController(swc.SelectedObject, ServerDTO);
                nint res = NSApplication.SharedApplication.RunModalForWindow(cwc.Window);
                if (res == (nint)VMIdentityConstants.DIALOGOK)
                {
                    UIErrorHelper.CheckedExec(delegate() {
                        if (cwc._properties.Count > 0)
                        {
                            LdapMod[] user = new LdapMod[cwc._properties.Count];
                            int count      = 0;
                            foreach (var entry in cwc._properties)
                            {
                                string[] values = new string[2];
                                values [0]      = Utilities.LdapValueToString(entry.Value.Value);
                                if (string.IsNullOrEmpty(values [0]))
                                {
                                    continue;
                                }
                                values [1]   = null;
                                user [count] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, entry.Key, values);
                                count++;
                            }
                            string dn = string.Format("cn={0},{1}", Utilities.LdapValueToString(cwc._properties.First(x => x.Key == "cn").Value.Value), Name);
                            ServerDTO.Connection.AddObject(dn, user);
                            UIErrorHelper.ShowAlert("", "Successfully Added object");
                            ReloadChildren();
                            RefreshProperties();
                            NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadOutlineView", this);
                            NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this);
                        }
                    });
                }
                VMDirSnapInEnvironment.Instance.MainWindow.EndSheet(cwc.Window);
                swc.Dispose();
            }
        }
Ejemplo n.º 15
0
        public void RestUserPassword(object sender, EventArgs e)
        {
            ResetPasswordWindowController cwc = new ResetPasswordWindowController();
            nint result = NSApplication.SharedApplication.RunModalForWindow(cwc.Window);

            if (result == (nint)VMIdentityConstants.DIALOGOK)
            {
                UIErrorHelper.CheckedExec(delegate() {
                    LdapMod[] mod = new LdapMod[1];
                    mod [0]       = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, VMDirConstants.ATTR_USER_PASSWORD, new string[] {
                        cwc.Password,
                        null
                    });
                    ServerDTO.Connection.ModifyObject(Name, mod);
                    UIErrorHelper.ShowAlert("Successfully reset password for the object", "Info");
                    ReloadChildren();
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this);
                });
            }
        }
Ejemplo n.º 16
0
        //Launch Dialogs
        public void AddUserToGroup(object sender, EventArgs e)
        {
            AddGroupByCNWindowController gwc = new AddGroupByCNWindowController(ServerDTO);
            nint result = NSApplication.SharedApplication.RunModalForWindow(gwc.Window);

            if (result == (nint)VMIdentityConstants.DIALOGOK)
            {
                UIErrorHelper.CheckedExec(delegate() {
                    string[] values   = new string[2];
                    values [1]        = null;
                    values [0]        = Name;
                    LdapMod[] ldapVal = new LdapMod[1];
                    ldapVal [0]       = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "member", values);
                    ServerDTO.Connection.ModifyObject(gwc.DNText, ldapVal);
                    UIErrorHelper.ShowAlert("", "Successfully Added Member");
                    ReloadChildren();
                    RefreshProperties();
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this);
                });
            }
        }
Ejemplo n.º 17
0
        public static void Ldap_Add_Object_SASL_Success(ILdapConnection ldapConnection, string UserName)
        {
            string DN = String.Format("cn={0},cn=Users,dc=vsphere,dc=local", UserName);

            LdapMod[] lMods = new LdapMod[3];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "cn", new string[] { UserName });

            lMods[1] = new LdapMod(0, "objectClass", new string[] { "person" });

            lMods[2] = new LdapMod(0, "sn", new string[] { "Allen" });

            try
            {
                ldapConnection.AddObject(DN, lMods);
            }
            catch
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 18
0
        public static void Ldap_Add_Object_SASL_Failure(ILdapConnection ldapConnection, string UserName)
        {
            string DN = String.Format("cn={0},cn=Users,dc=vsphere,dc=local", UserName);

            LdapMod[] lMods = new LdapMod[3];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "cn", new string[] { "Cap2" });

            lMods[1] = new LdapMod(0, "objectClass", new string[] { "person" });

            lMods[2] = new LdapMod(0, "sn", new string[] { "Allen" });

            try
            {
                ldapConnection.AddObject(DN, lMods);
                Assert.Fail();
            }
            catch
            {
                // Expected Exception Due to Invalid bind.
            }
        }
Ejemplo n.º 19
0
        public override void AddUserToGroup(object sender, EventArgs e)
        {
            AddGroupByCNWindowController gwc = new AddGroupByCNWindowController(ServerDTO);
            nint result = NSApplication.SharedApplication.RunModalForWindow(gwc.Window);

            if (result == (nint)VMIdentityConstants.DIALOGOK)
            {
                UIErrorHelper.CheckedExec(delegate()
                {
                    string[] values   = new string[2];
                    values[1]         = null;
                    values[0]         = Dn;
                    LdapMod[] ldapVal = new LdapMod[1];
                    ldapVal[0]        = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_MEMBER, values);
                    ServerDTO.Connection.ModifyObject(gwc.DNText, ldapVal);
                    UIErrorHelper.ShowInformation(VMDirConstants.STAT_MEMBER_ADD_SUCC);
                    ReloadChildren();
                    RefreshProperties();
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadResultTableView", this);
                });
            }
        }
Ejemplo n.º 20
0
        public void ShowAddGroup()
        {
            GroupDTO dto = new GroupDTO();
            AddNewGroupController agc = new AddNewGroupController(dto);
            nint res = NSApplication.SharedApplication.RunModalForWindow(agc.Window);

            if (res == (nint)VMIdentityConstants.DIALOGOK)
            {
                UIErrorHelper.CheckedExec(delegate()
                {
                    LdapMod[] user = new LdapMod[4];
                    user[0]        = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_CN, new string[] {
                        dto.cn,
                        null
                    });
                    user[1] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_GROUPTYPE, new string[] {
                        dto.groupType.ToString(),
                        null
                    });
                    user[2] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SAM_ACCOUNT_NAME, new string[] {
                        dto.sAMAccountName,
                        null
                    });
                    user[3] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_OBJECT_CLASS, new string[] {
                        dto.objectClass,
                        null
                    });
                    string dn = string.Format("cn={0},{1}", dto.cn, Dn);
                    ServerDTO.Connection.AddObject(dn, user);
                    UIErrorHelper.ShowInformation(VMDirConstants.STAT_GRP_ADD_SUCC);
                    var oc = Utilities.GetObjectClassList(ServerDTO, dn, LdapScope.SCOPE_BASE);
                    this.Children.Insert(0, new DirectoryNode(dn, oc, ServerDTO, this));
                    //ReloadChildren();
                    RefreshProperties();
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadOutlineView", this);
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this);
                });
            }
        }
Ejemplo n.º 21
0
        public void LdapModify_ReplaceAttribute_Success()
        {
            ILdapConnection ldapConnection = LdapConnection.LdapInit(hostName, portNumber);

            Assert.IsNotNull(ldapConnection);

            ldapConnection.LdapSimpleBindS(myDN, password);

            string basedn = "cn=lModReplace,cn=Users,dc=vsphere,dc=local";

            LdapMod[] lMods = new LdapMod[1];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, "sn", new string[] { "Barry", null });

            try
            {
                ldapConnection.ModifyObject(basedn, lMods);
            }
            catch
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 22
0
        public void ShowAddGroup()
        {
            GroupDTO dto = new GroupDTO();
            AddNewGroupController agc = new AddNewGroupController(dto);
            nint res = NSApplication.SharedApplication.RunModalForWindow(agc.Window);

            if (res == (nint)VMIdentityConstants.DIALOGOK)
            {
                UIErrorHelper.CheckedExec(delegate() {
                    LdapMod[] user = new LdapMod[4];
                    user [0]       = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_CN, new string[] {
                        dto.cn,
                        null
                    });
                    user [1] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_GROUPTYPE, new string[] {
                        dto.groupType.ToString(),
                        null
                    });
                    user [2] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_SAM_ACCOUNT_NAME, new string[] {
                        dto.sAMAccountName,
                        null
                    });
                    user [3] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, VMDirConstants.ATTR_OBJECT_CLASS, new string[] {
                        dto.objectClass,
                        null
                    });
                    string dn = string.Format("cn={0},{1}", dto.cn, Name);
                    ServerDTO.Connection.AddObject(dn, user);
                    UIErrorHelper.ShowAlert("", "Successfully added object");
                    ReloadChildren();
                    RefreshProperties();
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadOutlineView", this);
                    NSNotificationCenter.DefaultCenter.PostNotificationName("ReloadTableView", this);
                });
            }
        }
Ejemplo n.º 23
0
        public void Ldap_Add_Object_SASL_Failure()
        {
            ILdapConnection ldapConnection = LdapConnection.LdapInit(hostName, portNumber);

            Assert.IsNotNull(ldapConnection);

            try
            {
                ldapConnection.VmDirSafeLDAPBind(hostName, upn, password_F);
                Assert.Fail();
            }
            catch
            {
                //Expected Exception
            }

            string basedn = "cn=Cap2,cn=Users,dc=vsphere,dc=local";

            LdapMod[] lMods = new LdapMod[3];

            lMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_ADD, "cn", new string[] { "Cap2", null });

            lMods[1] = new LdapMod(0, "objectClass", new string[] { "person", null });

            lMods[2] = new LdapMod(0, "sn", new string[] { "Allen", null });

            try
            {
                ldapConnection.AddObject(basedn, lMods);
                Assert.Fail();
            }
            catch
            {
                // Expected Exception Due to Invalid bind.
            }
        }
Ejemplo n.º 24
0
        partial void PropApplyClick(NSObject sender)
        {
            UIErrorHelper.CheckedExec(delegate
            {
                if (ds != null && ds.modData.Count > 0)
                {
                    var finalMods = new Dictionary <string, List <string> >();
                    foreach (var item in ds.displayAttrDTOList)
                    {
                        var key = item.Name;
                        var val = item.Value;
                        if (ds.modData.Contains(key))
                        {
                            if (finalMods.ContainsKey(key))
                            {
                                finalMods[key].Add(val);
                            }
                            else
                            {
                                finalMods.Add(key, new List <string>()
                                {
                                    val
                                });
                            }
                        }
                    }

                    ModSubmitConfirmController mscwc = new ModSubmitConfirmController(finalMods);
                    nint result = NSApplication.SharedApplication.RunModalForWindow(mscwc.Window);
                    if (result != (nint)VMIdentityConstants.DIALOGOK)
                    {
                        return;
                    }

                    List <AttributeModStatus> modificationStatus = new List <AttributeModStatus>();
                    int i = 0;
                    foreach (var m in finalMods)
                    {
                        LdapMod[] attrMods = new LdapMod[1];
                        var values         = m.Value.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
                        Array.Resize(ref values, values.Count() + 1);
                        attrMods[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, m.Key, values);
                        try
                        {
                            ds.serverDTO.Connection.ModifyObject(ds.dn, attrMods);
                            modificationStatus.Add(new AttributeModStatus(m.Key, true, "Success"));
                        }
                        catch (Exception exp)
                        {
                            modificationStatus.Add(new AttributeModStatus(m.Key, false, exp.Message));
                        }
                        i++;
                    }
                    ModSubmitStatusController msswc = new ModSubmitStatusController(modificationStatus);
                    NSApplication.SharedApplication.RunModalForWindow(msswc.Window);
                    ds.modData.Clear();
                    ds.ReloadData();
                    ReloadTable();
                    SetEditVisibility(false);
                }
            });
        }
Ejemplo n.º 25
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            if (_serverDTO == null || _serverDTO.Connection == null)
            {
                MMCDlgHelper.ShowWarning(VMDirConstants.WRN_RELOGIN);
                return;
            }
            MiscUtilsService.CheckedExec(delegate
            {
                if (_modData.Count > 0)
                {
                    var finalMods = new Dictionary <string, List <string> >();
                    foreach (ListViewItem item in listViewProp.Items)
                    {
                        var key = item.SubItems[0].Text;
                        var val = item.SubItems[1].Text;
                        if (_modData.Contains(key))
                        {
                            if (finalMods.ContainsKey(key))
                            {
                                finalMods[key].Add(val);
                            }
                            else
                            {
                                finalMods.Add(key, new List <string>()
                                {
                                    val
                                });
                            }
                        }
                    }
                    var frm = new SubmitModConfirm(finalMods);
                    if (frm.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    //LdapMod[] attrMods = new LdapMod[finalMods.Count];
                    List <AttributeModStatus> modificationStatus = new List <AttributeModStatus>();
                    int i = 0;
                    foreach (var m in finalMods)
                    {
                        LdapMod[] ldapVal = new LdapMod[1];
                        var values        = m.Value.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
                        Array.Resize(ref values, values.Count() + 1);
                        ldapVal[0] = new LdapMod((int)LdapMod.mod_ops.LDAP_MOD_REPLACE, m.Key, values);
                        try
                        {
                            _serverDTO.Connection.ModifyObject(_dn, ldapVal);
                            modificationStatus.Add(new AttributeModStatus(m.Key, true, "Success"));
                        }
                        catch (Exception exp) {
                            modificationStatus.Add(new AttributeModStatus(m.Key, false, exp.Message));
                        }
                        i++;
                    }
                    var frm2 = new SubmitModStatus(modificationStatus);
                    frm2.ShowDialog();
                    RefreshPropertiesView();
                }
            });
        }