class='cKeyword'>#if defined(WIN32)
class='cKeyword'>#include<windows.h>
class='cKeyword'>#elif defined(N_PLAT_NLM)
class='cKeyword'>#include <nwthread.h>
class='cKeyword'>#include <string.h>
class='cKeyword'>#define printf ConsolePrintf
class='cKeyword'>#elif defined(UNIX)
class='cKeyword'>#include <ldap.h>
class='cKeyword'>#include <lber.h>
class='cKeyword'>#endif
class='cKeyword'>#include <stdio.h>
class='cKeyword'>#include <ntypes.h>
class='cKeyword'>#include <nmaserr.h>
class='cKeyword'>#include <nmasext.h>
class='cKeyword'>#include <ldap_ssl.h>
class='cKeyword'>#define MAX_DN_CHARS 256
class='cKeyword'>#define MAX_TREE_NAME_CHARS 32
void findAnObject(LDAP *ld, class='cKeyword'>char *queryID)
{
const class='cKeyword'>char *apszAttributes[] =
{
"mail",
"cn",
NULL
};
int err;
class='cKeyword'>char searchBase[] = "";
struct timeval timeOut;
LDAPMessage *searchResult;
timeOut.tv_sec = 10L;
timeOut.tv_usec = 0L;
err = ldap_search_ext_s(
ld,
searchBase,
LDAP_SCOPE_SUBTREE,
queryID,
apszAttributes,
0,
NULL,
NULL,
&timeOut,
LDAP_NO_LIMIT,
&searchResult );
ldap_msgfree( searchResult );
}
main(int argc, class='cKeyword'>char **argv)
{
int err = 0;
LDAP *ld = NULL;
int LDAPVersion = LDAP_VERSION3;
int resetCur = 0;
class='cKeyword'>char polcDN[MAX_DN_CHARS +1];
size_t polcDNLen = sizeof(polcDN);
class='cKeyword'>char subjName[MAX_DN_CHARS +1];
class='cKeyword'>char subjPwd[512];
class='cKeyword'>char userName[MAX_DN_CHARS +1];
class='cKeyword'>char userPwd[512];
class='cKeyword'>char chgPwd[]="This is the changed password";
class='cKeyword'>char newPwd[] ="THE NEW PASSWORD";
class='cKeyword'>char curPwd[512];
class='cKeyword'>char getPwd[512];
size_t getPwdLen = sizeof(getPwd);
nuint32 mid = 0;
nuint32 midLen = sizeof(mid);
class='cKeyword'>char tag[] = "BIG BUFFER";
class='cKeyword'>char bigBuf[60000];
class='cKeyword'>char getBigBuf[60000];
size_t bigBufLen = sizeof(bigBuf);
size_t getBigBufLen = sizeof(getBigBuf);
class='cKeyword'>char *ipAddr, *derFile;
if(argc < 7 )
{
printf("sample usage: <ldap ip addr> <der file> <subjDN> <subjPwd> <objDN> <objPwd>\n");
return -1;
}
ipAddr = argv[1];
derFile = argv[2];
strcpy( subjName, argv[3]);
strcpy( subjPwd, argv[4]);
strcpy( userName, argv[5]);
strcpy( userPwd, argv[6]);
ldap_set_option( NULL, LDAP_OPT_PROTOCOL_VERSION, &LDAPVersion);
err = ldapssl_client_init(derFile, NULL );
if (err != LDAP_SUCCESS)
{
printf ("ldapssl_client_init failed %d\n", err);
return err;
}
if (( ld = ldapssl_init( ipAddr, 636, 1 )) == NULL)
{
err = NMAS_E_SERVER_NOT_FOUND;
printf ("(LSMLDAP)- ldapssl_init failed\n");
}
if (!err)
{
err = nmasldap_change_password( ld, userName, userPwd, chgPwd);
printf("ERROR %d nmasldap_change_password\n", err);
polcDNLen = sizeof(polcDN);
err = nmasldap_get_password_policy_dn(ld, userName, &polcDNLen, polcDN);
if (!err)
{
printf("PUBLIC nmasldap_get_password_policy_dn %s\n", polcDN);
}
else
{
printf("ERROR %d PUBLIC nmasldap_get_password_policy_dn\n", err);
}
err = ldap_simple_bind_s( ld, subjName, subjPwd );
if (err != LDAP_SUCCESS)
{
printf("ERROR %d ldap_simple_bind_s\n", err);
}
else
{
nuint32 pwdStatus=0xffffffff;
nuint32 simplePwdStatus=0xffffffff;
err = nmasldap_get_password_status(ld, userName, &pwdStatus, &simplePwdStatus);
if (!err)
{
printf("Universal Password status: 0x%x\n", pwdStatus);
printf("Simple Password status: 0x%x\n", simplePwdStatus);
}
else
{
printf("ERROR %d nmasldap_get_password_status\n", err);
}
polcDNLen = sizeof(polcDN);
err = nmasldap_get_password_policy_dn(ld, userName, &polcDNLen, polcDN);
if (!err)
{
printf("nmasldap_get_password_policy_dn %s\n", polcDN);
}
else
{
printf("ERROR %d nmasldap_get_password_policy_dn\n", err);
}
getPwdLen = sizeof(getPwd);
err = nmasldap_get_password( ld, userName, &getPwdLen, getPwd);
printf("ERROR %d nmasldap_get_password\n", err);
if (!err)
{
resetCur = 1;
if (strcmp(chgPwd, getPwd) == 0)
{
printf("change and get passwords are the same\n");
}
else
{
printf("change and get passwords are NOT the same\n");
}
}
err = nmasldap_policy_check_current_password(ld, userName);
printf("ERROR %d nmasldap_policy_check_password\n", err);
err = nmasldap_policy_check_password(ld, userName, newPwd);
printf("ERROR %d nmasldap_policy_check_password\n", err);
err = nmasldap_change_password( ld, userName, getPwd, chgPwd);
printf("ERROR %d nmasldap_change_password\n", err);
getPwdLen = sizeof(getPwd);
err = nmasldap_get_password( ld, userName, &getPwdLen, getPwd);
printf("ERROR %d nmasldap_get_password\n", err);
if (!err)
{
if (strcmp(chgPwd, getPwd) == 0)
{
printf("change and get passwords are the same\n");
}
else
{
printf("change and get passwords are NOT the same\n");
}
}
err = nmasldap_set_password( ld, userName, newPwd);
printf("ERROR %d nmasldap_set_password\n", err);
getPwdLen = sizeof(getPwd);
err = nmasldap_get_password( ld, userName, &getPwdLen, getPwd);
printf("ERROR %d nmasldap_get_password\n", err);
if (!err)
{
if (strcmp(newPwd, getPwd) == 0)
{
printf("set and get passwords are the same\n");
}
else
{
printf("set and get passwords are NOT the same\n");
}
}
err = nmasldap_delete_password( ld, userName);
printf("ERROR %d nmasldap_delete_password\n", err);
err = nmasldap_set_password( ld, userName, "a");
printf("ERROR %d nmasldap_set_password(a)\n", err);
err = nmasldap_set_password( ld, userName, "novell");
printf("ERROR %d nmasldap_set_password(novell)\n", err);
err = nmasldap_set_password( ld, userName, "5novell");
printf("ERROR %d nmasldap_set_password(5novell)\n", err);
err = nmasldap_set_password( ld, userName, "novell5");
printf("ERROR %d nmasldap_set_password(novell5)\n", err);
if (resetCur)
{
err = nmasldap_set_password( ld, userName, userPwd);
printf("ERROR %d nmasldap_set_password\n", err);
}
else
{
err = nmasldap_set_password( ld, userName, newPwd);
printf("ERROR %d nmasldap_set_password\n", err);
}
getPwdLen = sizeof(curPwd);
err = nmasldap_get_simple_pwd( ld, userName, getPwdLen, curPwd);
printf("ERROR %d nmasldap_get_simple_pwd\n", err);
err = nmasldap_put_simple_pwd( ld, userName, newPwd);
printf("ERROR %d nmasldap_put_simple_pwd\n", err);
getPwdLen = sizeof(getPwd);
err = nmasldap_get_simple_pwd( ld, userName, getPwdLen, getPwd);
printf("ERROR %d nmasldap_get_simple_pwd\n", err);
if (!err)
{
if (strcmp(newPwd, getPwd) == 0)
{
printf("set and get simple passwords are the same\n");
}
else
{
printf("set and get simple passwords are NOT the same\n");
}
}
err = nmasldap_delete_simple_pwd( ld, userName);
printf("ERROR %d nmasldap_delete_simple_pwd\n", err);
memset (bigBuf, '$', bigBufLen);
err = nmasldap_put_login_config( ld, userName, midLen, &mid, tag, bigBufLen, bigBuf);
printf("ERROR %d nmasldap_put_login_config (bigBuf)\n", err);
err = nmasldap_get_login_config( ld, userName, midLen, &mid, tag, &getBigBufLen, getBigBuf);
printf("ERROR %d nmasldap_get_login_config (getBigBuf)\n", err);
if (!err)
{
if (bigBufLen != getBigBufLen)
{
printf("put %d and get %d length are different \n", bigBufLen, getBigBufLen);
}
else if (memcmp(bigBuf, getBigBuf, bigBufLen) != 0)
{
printf("put and get data are different \n");
}
else
{
printf("put and get data are the same \n");
}
}
err = nmasldap_delete_login_config( ld, userName, midLen, &mid, tag);
printf("ERROR %d nmasldap_delete_login_config\n", err);
err = nmasldap_put_login_secret( ld, userName, midLen, &mid, tag, bigBufLen, bigBuf);
printf("ERROR %d nmasldap_put_login_secret\n", err);
err = nmasldap_delete_login_secret( ld, userName, midLen, &mid, tag);
printf("ERROR %d nmasldap_delete_login_secret\n", err);
}
ldap_unbind_s( ld );
ldapssl_client_deinit();
}
return err;
}