diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /ldapaddressbook/ldapsearch.c | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'ldapaddressbook/ldapsearch.c')
| -rw-r--r-- | ldapaddressbook/ldapsearch.c | 62 | 
1 files changed, 62 insertions, 0 deletions
| diff --git a/ldapaddressbook/ldapsearch.c b/ldapaddressbook/ldapsearch.c new file mode 100644 index 0000000..d0deec6 --- /dev/null +++ b/ldapaddressbook/ldapsearch.c @@ -0,0 +1,62 @@ +/* +** Copyright 2006, Double Precision Inc. +** +** See COPYING for distribution information. +*/ + +#include "libldapsearch.h" +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> + +static int cb(const char *utf8_name, +	      const char *address, +	      void *callback_arg) +{ +	if (strchr(utf8_name, '\n') == NULL && +	    strchr(address, '\n') == NULL) +		/* filter out if it looks funny */ + +		printf("%s\n%s\n", utf8_name, address); +	return 0; +} + +int main(int argc, char **argv) +{ +	const char *host, *port, *suffix, *search; +	int port_n; +	struct ldapsearch *s; + +	if (argc < 5) +	{ +		fprintf(stderr, "INTERNAL ERROR: Invalid # of parameters to ldapsearch\n"); +		exit(1); +	} + +	host=argv[1]; +	port=argv[2]; +	suffix=argv[3]; +	search=argv[4]; + +	port_n=atoi(port); + +	if (port_n <= 0) +		port_n=LDAP_PORT; + +	s=l_search_alloc(host, port_n, argc > 5 ? argv[5]:NULL, +			 argc > 6 ?argv[6]:NULL, suffix); + +	if (!s) +	{ +		perror("l_search_alloc"); +		exit(1); +	} + +	if (l_search_do(s, search, cb, NULL)) +	{ +		perror("l_search_do"); +		exit(1); +	} +	l_search_free(s); +	exit(0); +} | 
