#include <stdio.h>
#include <stdlib.h>
#include <ldap.h>
#if defined(N_PLAT_NLM) && defined(LIBC)
#include <screen.h>
#endif
static char usage[] =
"\n Usage: modattrs <host name> <port number> <login dn> <password>"
"\n\t <modify dn> \n"
"\n Example: modattrs acme.com 389 cn=admin,o=acme secret"
"\n\t cn=james,ou=sales,o=acme\n";
int main( int argc, char **argv)
{
int version, ldapPort, rc;
char *ldapHost, *loginDN, *password, *modifyDN;
char *mailValues[2], *phoneValues1[2], *phoneValues2[2] ;
LDAP *ld;
LDAPMod modMail, modPhone1, modPhone2, *modify[4];
struct timeval timeOut = {10,0};
#if defined(N_PLAT_NLM) && defined(LIBC)
setscreenmode(SCR_NO_MODE);
#endif
if (argc != 6)
{
printf("%s", usage);
return(1);
}
ldapHost = argv[1];
ldapPort = atoi(argv[2]);
loginDN = argv[3];
password = argv[4];
modifyDN = argv[5];
version = LDAP_VERSION3;
ldap_set_option( NULL, LDAP_OPT_PROTOCOL_VERSION, &version);
ldap_set_option( NULL, LDAP_OPT_NETWORK_TIMEOUT, &timeOut);
if (( ld = ldap_init( ldapHost, ldapPort )) == NULL)
{
printf ( "\n\tLDAP session initialization failed\n");
return( 1 );
}
printf ( "\n\tLDAP session initialized\n");
rc = ldap_simple_bind_s( ld, loginDN, password );
if (rc != LDAP_SUCCESS )
{
printf("ldap_simple_bind_s: %s\n", ldap_err2string( rc ));
ldap_unbind_s ( ld );
return( 1 );
}
printf("\n\tBind successful\n");
modMail.mod_op = LDAP_MOD_REPLACE;
modMail.mod_type = "mail";
mailValues[0] = "jimmy@acme.com";
mailValues[1] = NULL;
modMail.mod_values = mailValues;
modPhone1.mod_op = LDAP_MOD_ADD;
modPhone1.mod_type = "telephoneNumber";
phoneValues1[0] = "1 234 567 8910";
phoneValues1[1] = NULL;
modPhone1.mod_values = phoneValues1;
modPhone2.mod_op = LDAP_MOD_DELETE;
modPhone2.mod_type = "telephoneNumber";
phoneValues2[0] = "1 234 567 8910";
phoneValues2[1] = NULL;
modPhone2.mod_values = phoneValues2;
modify[0] = &modMail;
modify[1] = &modPhone1;
modify[2] = &modPhone2;
modify[3] = NULL;
rc= ldap_modify_ext_s( ld,
modifyDN,
modify,
NULL,
NULL);
if ( rc != LDAP_SUCCESS )
{
printf("ldap_modify_ext_s: %s\n", ldap_err2string( rc ));
ldap_unbind_s( ld );
return(1);
}
printf("\n\t%s modified successfully.\n", modifyDN );
ldap_unbind_s( ld );
return( 0 );
}