1 /* apitest.c -- OpenLDAP API Test Program */
2 /* $OpenLDAP: pkg/ldap/libraries/libldap/apitest.c,v 1.25.2.3 2008/02/11 23:26:41 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This program was orignally developed by Kurt D. Zeilenga for inclusion in
23 #include <ac/stdlib.h>
30 main(int argc
, char **argv
)
36 printf("Compile time API Information\n");
38 #ifdef LDAP_API_INFO_VERSION
39 api
.ldapai_info_version
= LDAP_API_INFO_VERSION
;
40 printf(" API Info version: %d\n", (int) api
.ldapai_info_version
);
42 api
.ldapai_info_version
= 1;
43 printf(" API Info version: unknown\n");
46 #ifdef LDAP_FEATURE_INFO_VERSION
47 printf(" Feature Info version: %d\n", (int) LDAP_FEATURE_INFO_VERSION
);
49 printf(" Feature Info version: unknown\n");
50 api
.ldapai_info_version
= 1;
53 #ifdef LDAP_API_VERSION
54 printf(" API version: %d\n", (int) LDAP_API_VERSION
);
56 printf(" API version: unknown\n");
60 printf(" Protocol Version: %d\n", (int) LDAP_VERSION
);
62 printf(" Protocol Version: unknown\n");
64 #ifdef LDAP_VERSION_MIN
65 printf(" Protocol Min: %d\n", (int) LDAP_VERSION_MIN
);
67 printf(" Protocol Min: unknown\n");
69 #ifdef LDAP_VERSION_MAX
70 printf(" Protocol Max: %d\n", (int) LDAP_VERSION_MAX
);
72 printf(" Protocol Max: unknown\n");
74 #ifdef LDAP_VENDOR_NAME
75 printf(" Vendor Name: %s\n", LDAP_VENDOR_NAME
);
77 printf(" Vendor Name: unknown\n");
79 #ifdef LDAP_VENDOR_VERSION
80 printf(" Vendor Version: %d\n", (int) LDAP_VENDOR_VERSION
);
82 printf(" Vendor Version: unknown\n");
85 if(ldap_get_option(NULL
, LDAP_OPT_API_INFO
, &api
) != LDAP_SUCCESS
) {
86 fprintf(stderr
, "%s: ldap_get_option(API_INFO) failed\n", argv
[0]);
90 printf("\nExecution time API Information\n");
91 printf(" API Info version: %d\n", api
.ldapai_info_version
);
93 if (api
.ldapai_info_version
!= LDAP_API_INFO_VERSION
) {
94 printf(" API INFO version mismatch: got %d, expected %d\n",
95 api
.ldapai_info_version
, LDAP_API_INFO_VERSION
);
99 printf(" API Version: %d\n", api
.ldapai_api_version
);
100 printf(" Protocol Max: %d\n", api
.ldapai_protocol_version
);
102 if(api
.ldapai_extensions
== NULL
) {
103 printf(" Extensions: none\n");
107 for(i
=0; api
.ldapai_extensions
[i
] != NULL
; i
++) /* empty */;
108 printf(" Extensions: %d\n", i
);
109 for(i
=0; api
.ldapai_extensions
[i
] != NULL
; i
++) {
110 #ifdef LDAP_OPT_API_FEATURE_INFO
111 LDAPAPIFeatureInfo fi
;
112 fi
.ldapaif_info_version
= LDAP_FEATURE_INFO_VERSION
;
113 fi
.ldapaif_name
= api
.ldapai_extensions
[i
];
114 fi
.ldapaif_version
= 0;
116 if( ldap_get_option(NULL
, LDAP_OPT_API_FEATURE_INFO
, &fi
) == LDAP_SUCCESS
) {
117 if(fi
.ldapaif_info_version
!= LDAP_FEATURE_INFO_VERSION
) {
118 printf(" %s feature info mismatch: got %d, expected %d\n",
119 api
.ldapai_extensions
[i
],
120 LDAP_FEATURE_INFO_VERSION
,
121 fi
.ldapaif_info_version
);
124 printf(" %s: version %d\n",
130 printf(" %s (NO FEATURE INFO)\n",
131 api
.ldapai_extensions
[i
]);
136 api
.ldapai_extensions
[i
]);
139 ldap_memfree(api
.ldapai_extensions
[i
]);
141 ldap_memfree(api
.ldapai_extensions
);
144 printf(" Vendor Name: %s\n", api
.ldapai_vendor_name
);
145 ldap_memfree(api
.ldapai_vendor_name
);
147 printf(" Vendor Version: %d\n", api
.ldapai_vendor_version
);
149 printf("\nExecution time Default Options\n");
151 if(ldap_get_option(NULL
, LDAP_OPT_DEREF
, &ival
) != LDAP_SUCCESS
) {
152 fprintf(stderr
, "%s: ldap_get_option(api) failed\n", argv
[0]);
155 printf(" DEREF: %d\n", ival
);
157 if(ldap_get_option(NULL
, LDAP_OPT_SIZELIMIT
, &ival
) != LDAP_SUCCESS
) {
158 fprintf(stderr
, "%s: ldap_get_option(sizelimit) failed\n", argv
[0]);
161 printf(" SIZELIMIT: %d\n", ival
);
163 if(ldap_get_option(NULL
, LDAP_OPT_TIMELIMIT
, &ival
) != LDAP_SUCCESS
) {
164 fprintf(stderr
, "%s: ldap_get_option(timelimit) failed\n", argv
[0]);
167 printf(" TIMELIMIT: %d\n", ival
);
169 if(ldap_get_option(NULL
, LDAP_OPT_REFERRALS
, &ival
) != LDAP_SUCCESS
) {
170 fprintf(stderr
, "%s: ldap_get_option(referrals) failed\n", argv
[0]);
173 printf(" REFERRALS: %s\n", ival
? "on" : "off");
175 if(ldap_get_option(NULL
, LDAP_OPT_RESTART
, &ival
) != LDAP_SUCCESS
) {
176 fprintf(stderr
, "%s: ldap_get_option(restart) failed\n", argv
[0]);
179 printf(" RESTART: %s\n", ival
? "on" : "off");
181 if(ldap_get_option(NULL
, LDAP_OPT_PROTOCOL_VERSION
, &ival
) != LDAP_SUCCESS
) {
182 fprintf(stderr
, "%s: ldap_get_option(protocol version) failed\n", argv
[0]);
185 printf(" PROTOCOL VERSION: %d\n", ival
);
187 if(ldap_get_option(NULL
, LDAP_OPT_HOST_NAME
, &sval
) != LDAP_SUCCESS
) {
188 fprintf(stderr
, "%s: ldap_get_option(host name) failed\n", argv
[0]);
192 printf(" HOST NAME: %s\n", sval
);
195 puts(" HOST NAME: <not set>");
200 { /* bindless unbind */
204 ld
= ldap_init( "localhost", 389 );
210 rc
= ldap_unbind( ld
);
211 if( rc
!= LDAP_SUCCESS
) {
212 perror("ldap_unbind");
216 { /* bindless unbind */
220 ld
= ldap_init( "localhost", 389 );
226 rc
= ldap_abandon_ext( ld
, 0, NULL
, NULL
);
227 if( rc
!= LDAP_SERVER_DOWN
) {
228 ldap_perror( ld
, "ldap_abandon");
232 rc
= ldap_unbind( ld
);
233 if( rc
!= LDAP_SUCCESS
) {
234 perror("ldap_unbind");