public Modify ( System dn, LdapModification mod, LdapResponseQueue queue ) : LdapResponseQueue | ||
dn | System | Distinguished name of the entry to modify. /// /// |
mod | LdapModification | A single change to be made to the entry. /// /// |
queue | LdapResponseQueue | Handler for messages returned from a server in /// response to this request. If it is null, a /// queue object is created internally. /// /// |
return | LdapResponseQueue |
public static void doCleanup(LdapConnection conn, System.String userdn, System.String groupdn) { // since we have modified the user's attributes and failed to // modify the group's attribute, we need to delete the modified // user's attribute values. // modifications for user LdapModification[] modUser = new LdapModification[2]; // Delete the groupdn from the user's attributes LdapAttribute membership = new LdapAttribute("groupMembership", groupdn); modUser[0] = new LdapModification(LdapModification.DELETE, membership); LdapAttribute security = new LdapAttribute("securityEquals", groupdn); modUser[1] = new LdapModification(LdapModification.DELETE, security); try { // Modify the user's attributes conn.Modify(userdn, modUser); System.Console.Out.WriteLine("Deleted the modified user's attribute values."); } catch (LdapException e) { System.Console.Out.WriteLine("Could not delete modified user's attributes: " + e.LdapErrorMessage); } catch(Exception e) { Console.WriteLine("Error:" + e.Message); return; } return ; }
static void Main(string[] args) { if ( args.Length != 5) { Console.WriteLine("Usage: mono ModifyEntry <host name> <ldap port> <login dn>" + " <password> <Modify dn>"); Console.WriteLine("Example: mono ModifyEntry Acme.com 389" + " \"cn=admin,o=Acme\"" + " secret \"cn=ksmith,o=Acme\""); return; } string ldapHost = args[0]; int ldapPort = System.Convert.ToInt32(args[1]); String loginDN = args[2]; String password = args[3]; String dn = args[4]; try { Console.WriteLine("Connecting to:" + ldapHost); LdapConnection conn= new LdapConnection(); ArrayList modList = new ArrayList(); String desc = "This object belongs to test user"; // Add a new value to the description attribute LdapAttribute attribute = new LdapAttribute( "description", desc); modList.Add( new LdapModification(LdapModification.ADD, attribute)); String email = "*****@*****.**"; attribute = new LdapAttribute( "mail", email); modList.Add( new LdapModification(LdapModification.REPLACE, attribute)); LdapModification[] mods = new LdapModification[modList.Count]; mods = (LdapModification[])modList.ToArray(typeof(LdapModification)); conn.Connect(ldapHost,ldapPort); conn.Bind(loginDN,password); conn.Modify(dn,mods); Console.WriteLine(" Entry: " + dn + "Modified Successfully"); conn.Disconnect(); } catch(LdapException e) { Console.WriteLine("Error:" + e.LdapErrorMessage); return; } catch(Exception e) { Console.WriteLine("Error:" + e.Message); return; } }
static void Main(string[] args) { if ( args.Length != 5) { Console.WriteLine("Usage: mono ModifyPass <host name> <ldap port> <login dn>" + " <old password> <new password>"); Console.WriteLine("Example: mono ModifyPass Acme.com 389" + " \"cn=tjhon,o=Acme\"" + " secret \"newpass\""); return; } string ldapHost = args[0]; int ldapPort = System.Convert.ToInt32(args[1]); String loginDN = args[2]; String opassword = args[3]; String npassword = args[4]; try { LdapConnection conn= new LdapConnection(); Console.WriteLine("Connecting to:" + ldapHost); conn.Connect(ldapHost,ldapPort); conn.Bind(loginDN,opassword); LdapModification[] modifications = new LdapModification[2]; LdapAttribute deletePassword = new LdapAttribute("userPassword", opassword); modifications[0] = new LdapModification(LdapModification.DELETE, deletePassword); LdapAttribute addPassword = new LdapAttribute("userPassword", npassword); modifications[1] = new LdapModification(LdapModification.ADD, addPassword); conn.Modify(loginDN, modifications); System.Console.Out.WriteLine("Your password has been modified."); conn.Disconnect(); } catch(LdapException e) { Console.WriteLine("Error:" + e.LdapErrorMessage); return; } catch(Exception e) { Console.WriteLine("Error:" + e.Message); return; } }
public static void Main( String[] args ) { if (args.Length != 6) { Console.Error.WriteLine( "Usage: mono ModifyACL <host name> <port number> <login dn>" + " <password> \n <entry dn> <trustee dn>"); Console.Error.WriteLine( "Example: mono ModifyACL Acme.com 389 \"cn=Admin,o=Acme\"" + " secret \n \"cn=test,ou=Sales,o=Acme\" " + "\"cn=trustee,o=Acme\""); Environment.Exit(1); } int privileges = 0; int ldapVersion = LdapConnection.Ldap_V3; int ldapPort = System.Convert.ToInt32(args[1]); String ldapHost = args[0]; String loginDN = args[2]; String password = args[3]; String entryDN = args[4]; String trusteeDN = args[5]; LdapConnection lc = new LdapConnection(); // encode ACL value privileges |= System.Convert.ToInt32(LdapDSConstants.LDAP_DS_ENTRY_BROWSE); privileges |= System.Convert.ToInt32(LdapDSConstants.LDAP_DS_ENTRY_ADD); privileges |= System.Convert.ToInt32(LdapDSConstants.LDAP_DS_ENTRY_DELETE); String aclValue = System.Convert.ToString(privileges)+ "#" + "entry" + "#" + trusteeDN + "#" + "[Entry Rights]"; try { // connect to the server lc.Connect( ldapHost, ldapPort ); // bind to the server lc.Bind(ldapVersion, loginDN, password); // modify entryDN's ACL attribute Console.WriteLine( " Entry DN: " + entryDN ); Console.WriteLine( " Trustee DN: " + trusteeDN ); Console.WriteLine( " Modifying entryDN's ACL value..."); LdapAttribute acl = new LdapAttribute( "acl", aclValue); lc.Modify( entryDN, new LdapModification(LdapModification.ADD, acl)); Console.WriteLine(" Modified ACL values to grant trusteeDN the" + "\n 'read', 'write', and 'delete' entry rights.\n"); // display entryDN's ACL values findACLValues(lc, entryDN); // remove the Modified entryDN's ACL value Console.WriteLine( "\n Removing the modified ACL value..." ); lc.Modify( entryDN, new LdapModification(LdapModification.DELETE,acl)); Console.WriteLine( " Removed modified ACL value." ); lc.Disconnect(); } catch( LdapException e ) { if ( e.ResultCode == LdapException.NO_SUCH_OBJECT ) Console.Error.WriteLine( "Error: ModifyACL.java, No such entry" ); else if ( e.ResultCode == LdapException.INSUFFICIENT_ACCESS_RIGHTS ) Console.Error.WriteLine("Error: ModifyACL.java, Insufficient rights"); else if ( e.ResultCode == LdapException.ATTRIBUTE_OR_VALUE_EXISTS ) Console.Error.WriteLine("Error: ModifyACL.java, Attribute or value " + "exists"); else { Console.WriteLine( "Error: ModifyACL.java, " + e.ToString() ); } Environment.Exit(1); } catch( Exception e ) { Console.WriteLine( "Error: " + e.ToString() ); } Environment.Exit(0); }
public static bool _AddUserToGroup(LdapConnection conn, System.String userdn, System.String groupdn) { // modifications for group and user LdapModification[] modGroup = new LdapModification[2]; LdapModification[] modUser = new LdapModification[2]; // Add modifications to modUser LdapAttribute membership = new LdapAttribute("groupMembership", groupdn); modUser[0] = new LdapModification(LdapModification.ADD, membership); LdapAttribute security = new LdapAttribute("securityEquals", groupdn); modUser[1] = new LdapModification(LdapModification.ADD, security); // Add modifications to modGroup LdapAttribute member = new LdapAttribute("uniqueMember", userdn); modGroup[0] = new LdapModification(LdapModification.ADD, member); LdapAttribute equivalent = new LdapAttribute("equivalentToMe", userdn); modGroup[1] = new LdapModification(LdapModification.ADD, equivalent); try { // Modify the user's attributes conn.Modify(userdn, modUser); System.Console.Out.WriteLine("Modified the user's attribute."); } catch (LdapException e) { System.Console.Out.WriteLine("Failed to modify user's attributes: " + e.LdapErrorMessage); return false; } try { // Modify the group's attributes conn.Modify(groupdn, modGroup); System.Console.Out.WriteLine("Modified the group's attribute."); } catch (LdapException e) { System.Console.Out.WriteLine("Failed to modify group's attributes: " + e.LdapErrorMessage); doCleanup(conn, userdn, groupdn); return false; } catch(Exception e) { Console.WriteLine("Error:" + e.Message); return false; } return true; }
public static void Main( String[] args ) { if (args.Length != 5) { Console.Error.WriteLine("Usage: mono SetPassword <host name> " + "<login dn> <password>\n" + " <modify dn> <new password>"); Console.Error.WriteLine("Example: mono SetPassword Acme.com " + "\"cn=Admin,o=Acme secret\"\n" + " \"cn=JSmith,ou=Sales,o=Acme\"" + " newPassword"); Environment.Exit(1); } int ldapPort = LdapConnection.DEFAULT_PORT; int ldapVersion = LdapConnection.Ldap_V3; String ldapHost = args[0]; String loginDN = args[1]; String password = args[2]; String modifyDN = args[3]; String newPassword = args[4]; LdapConnection lc = new LdapConnection(); /* To set a user's password, * -- User should have administrator privileges * -- Specify the new password value to be set * -- Specify the modify type (replace for this operation) * -- Add the new value and type to the modification set * -- Call LdapConnection modify method to set the password */ try { // connect to the server lc.Connect( ldapHost, ldapPort ); // authenticate to the server lc.Bind( ldapVersion, loginDN, password ); LdapAttribute attributePassword = new LdapAttribute( "userPassword", newPassword); lc.Modify( modifyDN, new LdapModification( LdapModification.REPLACE, attributePassword) ); Console.WriteLine( "Successfully set the user's password" ); // disconnect with the server lc.Disconnect(); } catch( LdapException e ) { if ( e.ResultCode == LdapException.NO_SUCH_OBJECT ) { Console.Error.WriteLine( "Error: No such entry" ); } else if ( e.ResultCode == LdapException.INSUFFICIENT_ACCESS_RIGHTS ) { Console.Error.WriteLine( "Error: Insufficient rights" ); } else { Console.Error.WriteLine( "Error: " + e.ToString() ); } } catch( Exception e ) { Console.WriteLine( "Error: " + e.ToString() ); } Environment.Exit(0); }
public static void Main( String[] args ) { if (args.Length != 6) { Console.Error.WriteLine("Usage: mono SimplePassword <host Name> " + "<port number> <login dn> <password> <user dn>" + " <new user password>"); Console.Error.WriteLine("\n Example: mono SimplePassword Acme.com 389" + " \"cn=Admin,o=Acme\" secret\n" + " \"cn=JSmith,ou=sales,o=Acme\" userPWD"); Environment.Exit(1); } int ldapVersion = LdapConnection.Ldap_V3; String ldapHost = args[0]; int ldapPort = int.Parse(args[1]); String loginDN = args[2]; String password = args[3]; String userDN = args[4]; String userPWD = args[5]; /* Simple Password control. There is no value associated with this control, * just an OID and criticality. Setting the criticality to TRUE means the * server will return an error if it does not recognize or is unable to * perform the control. */ LdapControl cont = new LdapControl(simplePassOID, true, null); LdapConstraints lcons = new LdapConstraints(); lcons.setControls(cont); LdapConnection lc = new LdapConnection(); try { // connect to the server lc.Connect( ldapHost, ldapPort ); // bind to the server lc.Bind( ldapVersion, loginDN, password ); // Modify the 'userpassword' attribute, with the Simple // Password control. LdapModification[] modifications = new LdapModification[1]; LdapAttribute sPassword = new LdapAttribute( "userPassword",userPWD); modifications[0] = new LdapModification( LdapModification.REPLACE, sPassword); lc.Modify( userDN, modifications,lcons); Console.WriteLine("Your Simple password has been modified."); lc.Disconnect(); } catch( LdapException e ) { Console.Error.WriteLine("SimplePassword example failed"); Console.Error.WriteLine( "Error: " + e.ToString() ); Environment.Exit(1); } catch( Exception e ) { Console.WriteLine( "Error: " + e.ToString() ); } Environment.Exit(0); }
public ActionResult ChangeUserPass(string UserName, string PassWord, string RPassWord, string OldPassword) { string userName = UserName.ToString(); string newPassword = PassWord.ToString(); string OldPass = OldPassword.ToString(); string RPass = RPassWord.ToString(); TempData["msg"] = ""; if (newPassword == RPass) { // Creating an LdapConnection instance Novell.Directory.Ldap.LdapConnection ldapConn = new Novell.Directory.Ldap.LdapConnection(); string dn = "uid=" + userName + ",ou=users,dc=example,dc=com"; // Check if User Exists in LDAP if (CheckUser(userName, OldPass) == true) { try { //Connect function will create a socket connection to the server ldapConn.Connect(ldapHost, ldapPort); //Bind function will Bind the user object Credentials to the Server ldapConn.Bind(adminUname, adminPword); ArrayList modList = new ArrayList(); //Replace the existing email with the new email value LdapAttribute attributes = new LdapAttribute("userPassword", newPassword); modList.Add(new LdapModification(LdapModification.REPLACE, attributes)); LdapModification[] mods = new LdapModification[modList.Count]; Type mtype = Type.GetType("Novell.Directory.LdapModification"); mods = (LdapModification[])modList.ToArray(typeof(LdapModification)); //Modify the entry in the directory ldapConn.Modify(dn, mods); } catch (Novell.Directory.Ldap.LdapException e) { string error = "Error: " + e; TempData["msg"] = "<script>alert('" + error + "');</script>"; Thread.Sleep(2000); return(View("Index")); } finally { // Disconnect from LDAP ldapConn.Disconnect(); } TempData["msg"] = "<script>alert('Password Changed Successfully!');</script>"; Thread.Sleep(2000); return(View("Index")); } else { TempData["msg"] = "<script>alert('Could not authenticate user!');</script>"; Thread.Sleep(2000); return(View("Index")); } } else { TempData["msg"] = "<script>alert('New passwords do not match!');</script>"; Thread.Sleep(2000); return(View("Index")); } }