public Add ( |
||
entry | LdapEntry object specifying the distinguished /// name and attributes of the new entry. /// /// | |
queue | Handler for messages returned from a server in /// response to this request. If it is null, a /// queue object is created internally. /// /// | |
return |
static void Main(string[] args) { if ( args.Length != 5) { Console.WriteLine("Usage: mono AddEntry <host name> <ldap port> <login dn>" + " <password> <container>"); Console.WriteLine("Example: mono AddEntry Acme.com 389" + " \"cn=admin,o=Acme\"" + " secret \"ou=sales,o=Acme\""); return; } string ldapHost = args[0]; int ldapPort = System.Convert.ToInt32(args[1]); String loginDN = args[2]; String password = args[3]; String containerName = args[4]; try { LdapAttributeSet attributeSet = new LdapAttributeSet(); attributeSet.Add( new LdapAttribute( "objectclass", "inetOrgPerson")); attributeSet.Add( new LdapAttribute("cn", new string[]{"James Smith", "Jim Smith", "Jimmy Smith"})); attributeSet.Add( new LdapAttribute("givenname", "James")); attributeSet.Add( new LdapAttribute("sn", "Smith")); attributeSet.Add( new LdapAttribute("telephonenumber","1 801 555 1212")); attributeSet.Add( new LdapAttribute("mail", "*****@*****.**")); attributeSet.Add( new LdapAttribute("userpassword","newpassword")); string dn = "cn=KSmith," + containerName; LdapEntry newEntry = new LdapEntry( dn, attributeSet ); LdapConnection conn= new LdapConnection(); Console.WriteLine("Connecting to:" + ldapHost); conn.Connect(ldapHost,ldapPort); conn.Bind(loginDN,password); conn.Add( newEntry ); Console.WriteLine("Entry:" + dn + " Added Successfully"); conn.Disconnect(); } catch(LdapException e) { Console.WriteLine("Error:" + e.LdapErrorMessage); return; } catch(Exception e) { Console.WriteLine("Error:" + e.Message); return; } }
// add dynamic group entry public static bool addDynamicGroupEntry( LdapConnection lc, String loginDN, String entryDN, String queryURL) { bool status = true; LdapAttributeSet attributeSet = new LdapAttributeSet(); //The objectclass "dynamicGroup is used to create dynamic group entries attributeSet.Add( new LdapAttribute( "objectclass", "dynamicGroup" )); /* The memberQueryURL attribute describes the membership of the list * using an LdapURL, which is defined in RFC2255 */ attributeSet.Add( new LdapAttribute( "memberQueryURL", queryURL ) ); /* Set the identity to use for the implied search. loginDN is used * as the dgIdentity in this sample. */ attributeSet.Add( new LdapAttribute( "dgIdentity", loginDN ) ); LdapEntry newEntry = new LdapEntry( entryDN, attributeSet ); try { lc.Add( newEntry ); Console.WriteLine("\tEntry: " + entryDN + " added successfully." ); } catch( LdapException e ) { Console.WriteLine( "\t\tFailed to add dynamic group entry " + entryDN); Console.WriteLine( "Error: " + e.ToString() ); status = false; } return status; }