public void Ldap_Add_Object_Success() { ILdapConnection ldapConnection = LdapConnection.LdapInit(hostName, portNumber); Assert.IsNotNull(ldapConnection); ldapConnection.LdapSimpleBindS(myDN, password); string basedn = "cn=ExampleAdd,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[] { "ExampleAdd", 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 LdapModify_AddAttribute_Success() { 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, "sn", new string[] { "Allen", null }); try { ldapConnection.ModifyObject(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); } }
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); }); } }
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); }); } }
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); }); } }
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 (); } }
//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); }); } }
public void AddObject(string dn, LdapMod[] attrs) { IntPtr basednPtr = IntPtr.Zero; basednPtr = Marshal.StringToHGlobalAnsi(dn); IntPtr[] umattrs = new IntPtr[attrs.Length + 1]; for (int i = 0; i < attrs.Length; i++) { umattrs[i] = attrs[i].convertToUnmanaged(); } umattrs[attrs.Length] = IntPtr.Zero; /* NULL Termination */ var returnError = LdapClientLibrary.ldap_add_ext_s(this._connection, basednPtr, umattrs, null, null); for (int i = 0; i < attrs.Length; i++) { attrs[i].Free(); Marshal.FreeHGlobal(umattrs[i]); } Marshal.FreeHGlobal(basednPtr); ErrorCheckerHelper.Validate((int)returnError); return; }
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. } }
public void ModifyObject (string dn, LdapMod[] attrs) { MaintainSession (() => ldConn.ModifyObject (dn, attrs)); }