Back to index

courier  0.68.2
ldapsearch.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2006, Double Precision Inc.
00003 **
00004 ** See COPYING for distribution information.
00005 */
00006 
00007 #include "libldapsearch.h"
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <errno.h>
00011 
00012 static int cb(const char *utf8_name,
00013              const char *address,
00014              void *callback_arg)
00015 {
00016        if (strchr(utf8_name, '\n') == NULL &&
00017            strchr(address, '\n') == NULL)
00018               /* filter out if it looks funny */
00019 
00020               printf("%s\n%s\n", utf8_name, address);
00021        return 0;
00022 }
00023 
00024 int main(int argc, char **argv)
00025 {
00026        const char *host, *port, *suffix, *search;
00027        int port_n;
00028        struct ldapsearch *s;
00029 
00030        if (argc < 5)
00031        {
00032               fprintf(stderr, "INTERNAL ERROR: Invalid # of parameters to ldapsearch\n");
00033               exit(1);
00034        }
00035 
00036        host=argv[1];
00037        port=argv[2];
00038        suffix=argv[3];
00039        search=argv[4];
00040 
00041        port_n=atoi(port);
00042 
00043        if (port_n <= 0)
00044               port_n=LDAP_PORT;
00045 
00046        s=l_search_alloc(host, port_n, argc > 5 ? argv[5]:NULL,
00047                       argc > 6 ?argv[6]:NULL, suffix);
00048 
00049        if (!s)
00050        {
00051               perror("l_search_alloc");
00052               exit(1);
00053        }
00054 
00055        if (l_search_do(s, search, cb, NULL))
00056        {
00057               perror("l_search_do");
00058               exit(1);
00059        }
00060        l_search_free(s);
00061        exit(0);
00062 }