At first i apoligize for my poor english. i'm not an English
guy.
I wrote two source files with policy.c and
common.c
What the built application do just is bind to my own ldap
server.
When i make the source files, I got the
following warnings not errors.
fortunately the target application , 'policy' was made
successfully.
anyway Why the errors happened ?
[root@wisep source]# make
cc -g -O2 -o policy policy.o common.o ldsversion.o -L/usr/local/BerkeleyDB.4.2/lib liblutil.a libldif.a libldap.a liblber.a /usr/local/lib/libsasl2.so -lssl -lcrypto -lresolv -ldl -Wl,--rpath -Wl,/usr/local/lib -Wl,--rpath -Wl,/usr/local/lib libldap.a(os-ip.o)(.text+0x241): In function `ldap_pvt_is_socket_ready': /root/software/openldap-2.1.25/libraries/libldap/os-ip.c:191: `sys_errlist' is deprecated; use `strerror' or `strerror_r' instead libldap.a(os-ip.o)(.text+0x238):/root/software/openldap-2.1.25/libraries/libldap/os-ip.c:191: `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead [root@wisep source]# The sources below are policy.c and common.c and
policy.h and common.h , and Makefile
///////////////////////////////////////////////////////////////
// policy.c
///////////////////////////////////////////////////////////////
#include <stdio.h>
#include <ldap.h> #include "common.h"
#define MAX_LINE 256
#define OP_QUIT "quit"
#define OP_SEARCH "search" #define OP_ADD "add" #define OP_DELETE "delete" #define OP_MODIFY "modify" //
// LDAP connection handle // int protocol = LDAP_VERSION3; // LDAP
version
int authmethod = LDAP_AUTH_SIMPLE; char* binddn = "pr=ccc, dc=plantynet, dc=com"; struct berval passwd = { 0, NULL }; LDAP* ldconn = NULL; char* ldapuri = NULL; char* filter = "(objectclass=*)"; void doexit(int code)
{ //free( passwd.bv_val ); //
// unbind LDAP connection // unbind_ldap( ldconn );
exit( code );
} static void
private_setup_ldap( LDAP* ld ) { } int main(int argc, char**
argv)
{ char line[MAX_LINE]; int done =
0;
int opcode; char* cmdargs; char command[32]; int not = 0; //
// setup ldap configuration // setup_ldap(not, NULL);
//
// bind ldap connection // bind_ldap( ldconn );
while(
!done)
{ // // 명령어를 읽는다. // if( fgets( line, sizeof(line), stdin) == NULL
)
{ continue; } cmdargs = strchr( line, ' ');
if( cmdargs == NULL
)
{ cmdargs = line + strlen(line); } memset( command, 0, sizeof(command)
);
memcpy( command, line, cmdargs - line); if( command[ strlen(command) -1 ] == '\n' ) { command[ strlen(command) -1 ] = 0; } if( !strncasecmp( command, OP_SEARCH )
)
{ //dosearch( cmdargs, ldconn ); printf("search\n"); } else if( !strncasecmp(command, OP_ADD) ) { printf("add\n"); } else if( !strncasecmp(command, OP_DELETE) ) { printf("del\n"); } else if( !strncasecmp(command, OP_MODIFY) ) { printf("modify\n"); } else if( !strncasecmp(command, OP_QUIT) ) { printf("quit\n"); done = 1; } } doexit( 0 );
} ///////////////////////////////////////////////////////////////
// policy.h
///////////////////////////////////////////////////////////////
#ifndef __POLICY_H__
#define __POLICY_H__ extern void doexit( int code );
#endif
///////////////////////////////////////////////////////////////
// common.c
///////////////////////////////////////////////////////////////
#include <stdio.h>
#include <ldap.h> #include <signal.h> #include "policy.h"
extern char* ldapuri;
extern int protocol; extern char* binddn; extern struct berval passwd; extern int authmethod; //
// Setup ldap configuration // LDAP* setup_ldap(int not, void (*private_setup)( LDAP * ) ) { LDAP* ld = NULL; (void) signal( SIGPIPE, SIG_IGN );
int rc;
rc = ldap_initialize( &ld, ldapuri );
if( rc != LDAP_SUCCESS )
{ fprintf( stderr, "Could not create LDAP session handle (%d): %s\n", rc, ldap_err2string(rc) ); doexit( -1 ); } if( private_setup )
{ private_setup( ld ); } if( ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &protocol
)
!= LDAP_OPT_SUCCESS ) { fprintf(stderr, "Could not set LDAP_OPT_PROTOCOL_VERSION %d\n", protocol ); doexit( -1 ); } } void
bind_ldap( LDAP* ld ) { if( authmethod == LDAP_AUTH_SASL )
{ // // add code here !! // } else { // // LDAP_AUTH_SIMPLE // if( ldap_bind_s( ld, binddn, passwd.bv_val,
authmethod)
!= LDAP_SUCCESS ) { ldap_perror( ld, "ldap_bind" ); doexit( -1 ); } } } //
// unbind LDAP connection // void unbind_ldap( LDAP* ld ) { ldap_unbind( ld ); } ///////////////////////////////////////////////////////////////
// common.h
///////////////////////////////////////////////////////////////
#include <ldap.h>
#ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0 # define EXIT_FAILURE 1 #endif extern void setup_ldap( int not, void (*private_setup)( LDAP* )
);
extern void bind_ldap( LDAP* );
extern void unbind_ldap( LDAP *);
///////////////////////////////////////////////////////////////
// Makefile
///////////////////////////////////////////////////////////////
INCDIR=-I include -I .
LIBS=liblutil.a libldif.a -lldap OBJS=policy.o common.o ldsversion.o PROG=policy
all: $(PROG)
$(PROG): $(OBJS)
cc -g -O2 -o $(PROG) policy.o common.o ldsversion.o -L/usr/local/BerkeleyDB.4.2/lib liblutil.a libldif.a libldap.a liblber.a /usr/local/lib/libsasl2.so -lssl -lcrypto -lresolv -ldl -Wl,--rpath -Wl,/usr/local/lib -Wl,--rpath -Wl,/usr/local/lib %.o: %.c
gcc -c -o $@ $< $(INCDIR) clean:
rm -f $(PROG) $(OBJS) policy Good luck everyone !! |