Doxygen docs, first tools for automatically populate rosters, LDAP Leak test.
[vcard2ldap.git] / tools / ldap_leak.c
blob56040355958976e656408f1b60502449fc455b53
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <ldap.h>
6 void usage (const char *argv0);
7 void leak_loop (const char *host, int port, const char *binddn,
8 const char *passwd);
10 int
11 main (int argc, char **argv)
13 char *host = "localhost";
14 int port = LDAP_PORT;
16 char *binddn = NULL;
17 char *passwd = NULL;
19 int c;
21 opterr = 0;
25 c = getopt (argc, argv, "h:p:b:x:");
27 switch (c)
29 case 'h':
30 host = optarg;
31 break;
32 case 'p':
33 port = atoi (optarg);
34 break;
35 case 'b':
36 binddn = optarg;
37 break;
38 case 'x':
39 passwd = optarg;
40 break;
41 case '?':
42 usage (argv[0]);
43 return 1;
44 default:
45 break;
47 } while (c != -1);
49 if (!binddn || !passwd || port <= 0 || port >= 1 << 16)
50 usage (argv[0]);
52 leak_loop (host, port, binddn, passwd);
54 return 0;
57 void
58 usage (const char *argv0)
60 fprintf (stderr, "Usage: %s -b binndn -x passwd [-h host] [-p port]\n",
61 argv0);
62 exit (1);
65 void
66 leak_loop (const char *host, int port, const char *binddn,
67 const char *passwd)
69 LDAP *ld;
70 int version;
71 int rc, i;
73 for (i = 0; i < 1 << 12; i++)
75 ld = ldap_init (host, port);
77 version = LDAP_VERSION3;
78 ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION, &version);
80 rc = ldap_simple_bind_s (ld, binddn, passwd);
82 if (rc != LDAP_SUCCESS)
84 fprintf (stderr, "LDAP Error: %s\n", ldap_err2string (rc));
85 exit (1);
88 ldap_unbind_s (ld);
89 #ifdef NOLEAK
90 sasl_done ();
91 #endif