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;
}
}