#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ldap.h>
#include <ldapx.h>
#if defined(N_PLAT_NLM) && defined(LIBC)
#include <screen.h>
#endif
static char usage[] =
"\n Usage: getrinfo <host name> <port number> <login dn> <password> "
"\n\t <partition dn> <serverDN>\n"
"\n Example: getrinfo acme.com 389 cn=admin,o=acme secret ou=sales,o=acme"
"\n\t cn=myServer,o=acme\n";
int main(int argc, char **argv)
{
int rc, version, ldapPort;
char *ldapHost;
char *loginDN;
char *password;
char *partitionDN;
char *serverDN;
char *msg;
LDAPReplicaInfo replicaInfo;
LDAP *ld;
struct timeval timeOut = {10,0};
#if defined(N_PLAT_NLM) && defined(LIBC)
setscreenmode(SCR_NO_MODE);
#endif
if ( argc != 7 )
{
printf("%s", usage);
return (1);
}
ldapHost = argv[1];
ldapPort = atoi(argv[2]);
loginDN = argv[3];
password = argv[4];
partitionDN = argv[5];
serverDN = argv[6];
version = LDAP_VERSION3;
ldap_set_option( NULL, LDAP_OPT_PROTOCOL_VERSION, &version);
ldap_set_option( NULL, LDAP_OPT_NETWORK_TIMEOUT, &timeOut);
printf( " Getting the handle to the LDAP connection...\n" );
if ( (ld = ldap_init( ldapHost, ldapPort )) == NULL )
{
perror( "ldap_init" );
return ( 1 );
}
printf( " Binding to the directory...\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( " Calling ldap_get_replica_info...\n" );
rc = ldap_get_replica_info(
ld,
partitionDN,
serverDN,
&replicaInfo);
if ( rc != LDAP_SUCCESS )
{
if(ldap_get_option (ld, LDAP_OPT_ERROR_STRING, &msg ) ==
LDAP_OPT_SUCCESS ) {
if ( (msg != NULL) ) {
printf("\n LDAP server message: ");
if ( strlen(msg) != 0 )
printf("%s\n", msg);
else
printf("none\n");
ldap_memfree( msg );
}
}
printf(" LDAP error message: ldap_get_replica_info:"
" %s (%d)\n", ldap_err2string( rc ), rc);
printf("\n ldap_get_replica_info failed\n\n");
ldap_unbind_s( ld );
return( 1 );
}
printf("\n ldap_get_replica_info succeeded\n\n");
printf("\n Replica info: ");
printf("\n Partition root ID: %d", replicaInfo.rootID);
printf("\n Replica state: %d", replicaInfo.state);
printf("\n Modification time: %d", replicaInfo.modificationTime);
printf("\n Purge time: %d", replicaInfo.purgeTime);
printf("\n Local replica ID: %d", replicaInfo.localReplicaID);
printf("\n Replica type: %d", replicaInfo.replicaType);
printf("\n partition DN: %s", replicaInfo.namingContextDN);
printf("\n Flag: %d", replicaInfo.flags);
printf("\n\n");
ldap_unbind_s( ld );
return 0;
}