Sponsored Content
Full Discussion: LDAPSEARCH in C
Top Forums Programming LDAPSEARCH in C Post 302433950 by tailangong on Thursday 1st of July 2010 02:57:48 AM
Old 07-01-2010
LDAPSEARCH in C

Hi all,

I've been searching for ldapsearch function these few days. Still I couldn't found the solution.

I would like to translate this query

Code:
ldapsearch -x -LLL -h new_IP -p new_Port -D "cn=jw" -w "dummy" -b
"id=2311,o=WC,c=jp" -s sub

to ldap_search_ext_s() function in C program.

Any idea how to do it?

Below is my attempt but to no avail:

Code:
char		*attrs[] = {"Name", NULL};
tmax.tv_sec = 10;
tmax.tv_usec = 0;
LDAPMessage     *res = NULL
rc = ldap_search_ext_s(ld, "o=WC,c=jp", LDAP_SCOPE_SUBTREE, "(objectclass=*)", attrs, 0, NULL, NULL, &tmax, 1, &res);

PS: I am newbie in LDAP. Hope you guys could help and intro some good source for me to read more about LDAP for beginner. Thanks
 

10 More Discussions You Might Find Interesting

1. Red Hat

ldapsearch doesnt work.

Hii All, I am using openldap v2.3 on redhat El-4. When i run ldapsearch it returns all the entries. The command runs successfully. But when I run the ldapsearch with following filter option it doesnt work and immediately returns to the shell. ldapsearch uidNumber>=2000 I've started slapd... (0 Replies)
Discussion started by: shamik
0 Replies

2. IP Networking

Help Needed regarding Ldapsearch script

Hi guys, I very appreciate for answering to my previous query. I have encountered another problem.I have a perl script to display required networking information like DNS,gateway,etc. to be changed in a remote computer which is to be added to a computing cluster. I need a script which... (0 Replies)
Discussion started by: pranav.mehta3
0 Replies

3. UNIX for Advanced & Expert Users

ldapsearch and XML

Hello all I would like to know if it's possible to extract users from Active Directory and parse the output to obtain a XML file with specific format. So the AD is a windows machine, and I would like to extract from a red hat linux serveur. I try ldapsearch command and ok I'm abble to extract... (5 Replies)
Discussion started by: ldiaz2106
5 Replies

4. AIX

ldapsearch to find DN for a user

How can I do a ldapsearch to find a DN for a user when I know the exact cn for that user out of active directory. I have tried several different commands (hundreds) but need the -b with the full dn to perform the search using ldapsearch from AIX. I am trying to find the OU for a user and the... (3 Replies)
Discussion started by: cchart3
3 Replies

5. Red Hat

ldapsearch bash script help

Hi there everyone. I'm trying to make a bash script that accepts some arguments ans give's back some info about LDAP users and servers. I have this function : has_group_access(){ result=$(ldapsearch -LLL "cn=${GROUP_NAME}" cn member | cut -d"," -f1 | cut -d":" -f2 | cut -d"=" -f2 | grep... (1 Reply)
Discussion started by: theboogymaster
1 Replies

6. UNIX for Dummies Questions & Answers

Need assistance on using ldapsearch

Never knew of this command ldapsearch, but I would like to use it to lookup a single user and return where their office is. Is this possible? I'm totally starting from scratch. I already saw some of the gurus say read the man page, which is pretty greek when you don't know the details of... (1 Reply)
Discussion started by: srhadden
1 Replies

7. Red Hat

Ldapsearch problem

Hi I'm not familiar with ldap and I hope someone to help me. I need to get some attribute value from ldap DB. When i run the following command is OK: ldapsearch -h localhost -p 16611 -x -D cn=user -w passwd -b msisdn=359502479649,dc=MSISDN,DC=C-NTDB "(objectClass=SUBINNSS)" refinmocNAME the... (0 Replies)
Discussion started by: vasil
0 Replies

8. Solaris

Ldapsearch command not exiting

All, New to this forum and unix here so please forgive any silly questions. I am on a Solaris 10 machine and need a script to query our Windows Domain controller to determine if a user is active or not. Man files were helpful enough and it worked. The Challenge is the program doesn't exit... (1 Reply)
Discussion started by: daniel333
1 Replies

9. UNIX for Beginners Questions & Answers

Help with output from ldapsearch command

Using ldapsearch, I've built the following command to get what I need. ldapsearch -x -LLL -E pr=200/noprompt -h abc-loc.somecompany.com -D "account@somecompany.com" -w password -b "ou=End Users,ou=Accounts,dc=abc,dc=somecompany,dc=com" -s sub '(distinguishedName=CN=Bob\\, Billy J,OU=End... (8 Replies)
Discussion started by: who10
8 Replies

10. UNIX for Beginners Questions & Answers

Ldapsearch using variable will not work

When I execute the code below with cn set to the $adgroup variable, I get the following error: Invalid DN syntax (34) Additional information: 0000208F: NameErr: DSID-031001F7, problem 2006 (BAD_NAME), data 8349, best match of: ,ou=Resource,ou=groups,dc=abc,dc=somecompany,dc=com' If I set cn... (6 Replies)
Discussion started by: who10
6 Replies
LDAP_SEARCH(3)						     Library Functions Manual						    LDAP_SEARCH(3)

NAME
ldap_search, ldap_search_s, ldap_search_st, ldap_search_ext, ldap_search_ext_s - Perform an LDAP search operation LIBRARY
OpenLDAP LDAP (libldap, -lldap) SYNOPSIS
#include <sys/types.h> #include <ldap.h> int ldap_search_ext( LDAP *ld, char *base, int scope, char *filter, char *attrs[], int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeout, int sizelimit, int *msgidp ); int ldap_search_ext_s( LDAP *ld, char *base, int scope, char *filter, char *attrs[], int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeout, int sizelimit, LDAPMessage **res ); DESCRIPTION
These routines are used to perform LDAP search operations. The ldap_search_ext_s() routine does the search synchronously (i.e., not returning until the operation completes), providing a pointer to the resulting LDAP messages at the location pointed to by the res parame- ter. The ldap_search_ext() routine is the asynchronous version, initiating the search and returning the message id of the operation it initiated in the integer pointed to by the msgidp parameter. The base parameter is the DN of the entry at which to start the search. The scope parameter is the scope of the search and should be one of LDAP_SCOPE_BASE, to search the object itself, LDAP_SCOPE_ONELEVEL, to search the object's immediate children, LDAP_SCOPE_SUBTREE, to search the object and all its descendants, or LDAP_SCOPE_CHILDREN, to search all of the descendants. Note that the latter requires the server support the LDAP Subordinates Search Scope extension. The filter is a string representation of the filter to apply in the search. The string should conform to the format specified in RFC 4515 as extended by RFC 4526. For instance, "(cn=Jane Doe)". Note that use of the extension requires the server to support the LDAP Absolute True/False Filter extension. NULL may be specified to indicate the library should send the filter (objectClass=*). The attrs parameter is a null-terminated array of attribute descriptions to return from matching entries. If NULL is specified, the return of all user attributes is requested. The description "*" (LDAP_ALL_USER_ATTRIBUTES) may be used to request all user attributes to be returned. The description "+"(LDAP_ALL_OPERATIONAL_ATTRIBUTES) may be used to request all operational attributes to be returned. Note that this requires the server to support the LDAP All Operational Attribute extension. To request no attributes, the description "1.1" (LDAP_NO_ATTRS) should be listed by itself. The attrsonly parameter should be set to a non-zero value if only attribute descriptions are wanted. It should be set to zero (0) if both attributes descriptions and attribute values are wanted. The serverctrls and clientctrls parameters may be used to specify server and client controls, respectively. The ldap_search_ext_s() routine is the synchronous version of ldap_search_ext(). It also returns a code indicating success or, in the case of failure, indicating the nature of the failure of the operation. See ldap_error(3) for details. NOTES
Note that both read and list functionality are subsumed by these routines, by using a filter like "(objectclass=*)" and a scope of LDAP_SCOPE_BASE (to emulate read) or LDAP_SCOPE_ONELEVEL (to emulate list). These routines may dynamically allocate memory. The caller is responsible for freeing such memory using supplied deallocation routines. Return values are contained in <ldap.h>. Note that res parameter of ldap_search_ext_s() and ldap_search_s() should be freed with ldap_msgfree() regardless of return value of these functions. DEPRECATED INTERFACES
The ldap_search() routine is deprecated in favor of the ldap_search_ext() routine. The ldap_search_s() and ldap_search_st() routines are deprecated in favor of the ldap_search_ext_s() routine. Deprecated interfaces generally remain in the library. The macro LDAP_DEPRECATED can be defined to a non-zero value (e.g., -DLDAP_DEPRE- CATED=1) when compiling program designed to use deprecated interfaces. It is recommended that developers writing new programs, or updating old programs, avoid use of deprecated interfaces. Over time, it is expected that documentation (and, eventually, support) for deprecated interfaces to be eliminated. SEE ALSO
ldap(3), ldap_result(3), ldap_error(3) ACKNOWLEDGEMENTS
OpenLDAP Software is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release. OpenLDAP 2017/06/01 LDAP_SEARCH(3)
All times are GMT -4. The time now is 10:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy