need help -- not able to include <ldap.h> in my C program
807578Nov 27 2009 — edited Dec 10 2009good evening every-one,
Actually I don't have that much hands on experience in C programming [though I am very through in java/j2ee] but I have a task with me to be done in C language [i know some basics which i learnt years ago].
I have a C utility which performs certain tasks. I have to incorporate a check that only valid users can run that utility. This I have to do by authenticating their user names and pwds in LDAP.
Now, now I decided that I would break my problem in simple manageable tasks....
step (1) => I decided to write a sample C program which connects to our ldap server and performs the validation
step (2) => try include the above program in my utility.
And I am at present on step1.
I am using sunstudio 12 for this purpose running it on solaris 10.
I searched on net and learnt that i need a header file ldap.h along with its depencies. I downloaded those files.
The I made a new project in sunstudio 12 and and then made a c file and ran a sample to program to print a text to ensure that C is running and it was running fine.
Then i included <ldap.h> in my programe [see below] and then compiled again.
{ // main method starts here
// Get hold of a LDAP connection.
if ((ld = ldap_init("my_ldap_server_name", my_port_number)) == NULL ) {
printf("couldn't open connection to the ldap server...");
exit( 1 );
}
else
{
printf("connection to ldap server is open...");
}
// Bind to the server. when we specify null, its an annonymous login
ret_val = ldap_simple_bind_s( ld, NULL, NULL );
if ( ret_val != LDAP_SUCCESS ) {
printf("now we are bind, with annonymous log-in.....");
}
//now search/validate in the ldap / authenticate for the passwd.
/*
* yet to figure out methods that need to be used to do this.
* probably using these two functions below
* ldap_search_ext()
* ldap_search_ext_s()
*/
//need to free the ldap-handle
ldap_unbind_s(ld);
printf("finally exiting....");
} //end of main method
first I placed all the header files in 'header files' directory of the project [when it didn't work I placed them with-in the same directory of source file] and when I build it again it didn't recognize the functions that i invoked.
Undefined first referenced
symbol in file
ldap_unbind_s build/Debug
ldap_init build/Debug
ldap_simple_bind_s build
see some more logs in the output window
mkdir -p build/Debug/Sun12-Solaris-Sparc
cc -c -g -o build/Debug/Sun12-Solaris-Sparc/file1.o file1.c
(/home/XXXXX/SunStudioProjects/project1)file1.c:
"file1.c", line 55: warning: newline not last character in file
I have tried a lot of things but all in-vain.
Any help is much appreciated.
Best Regards,
Vinay