2003-11-26 15:16:36 +08:00
|
|
|
/* apitest.c -- OpenLDAP API Test Program */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1998-2004 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +08:00
|
|
|
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
|
|
|
|
* All rights reserved.
|
1998-11-05 10:48:41 +08:00
|
|
|
*
|
2003-11-26 15:16:36 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
1998-12-23 02:27:14 +08:00
|
|
|
*
|
2003-11-26 15:16:36 +08:00
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
|
|
|
|
* OpenLDAP Software.
|
1998-11-05 10:48:41 +08:00
|
|
|
*/
|
1998-11-05 04:09:07 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1998-11-05 04:09:07 +08:00
|
|
|
|
1999-08-04 02:14:24 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ldap.h>
|
1998-11-05 04:09:07 +08:00
|
|
|
|
1998-11-11 04:27:47 +08:00
|
|
|
int
|
1998-11-05 04:09:07 +08:00
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
LDAPAPIInfo api;
|
|
|
|
int ival;
|
1998-11-11 04:27:47 +08:00
|
|
|
char *sval;
|
1998-11-05 04:09:07 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
printf("Compile time API Information\n");
|
|
|
|
|
1998-11-05 04:09:07 +08:00
|
|
|
#ifdef LDAP_API_INFO_VERSION
|
|
|
|
api.ldapai_info_version = LDAP_API_INFO_VERSION;
|
1999-05-19 09:12:33 +08:00
|
|
|
printf(" API Info version: %d\n", (int) api.ldapai_info_version);
|
1998-11-05 04:09:07 +08:00
|
|
|
#else
|
|
|
|
api.ldapai_info_version = 1;
|
1999-05-19 09:12:33 +08:00
|
|
|
printf(" API Info version: unknown\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LDAP_FEATURE_INFO_VERSION
|
|
|
|
printf(" Feature Info version: %d\n", (int) LDAP_FEATURE_INFO_VERSION);
|
|
|
|
#else
|
|
|
|
printf(" Feature Info version: unknown\n");
|
|
|
|
api.ldapai_info_version = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LDAP_API_VERSION
|
|
|
|
printf(" API version: %d\n", (int) LDAP_API_VERSION);
|
|
|
|
#else
|
|
|
|
printf(" API version: unknown\n");
|
1998-11-05 04:09:07 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LDAP_VERSION
|
1999-05-19 09:12:33 +08:00
|
|
|
printf(" Protocol Version: %d\n", (int) LDAP_VERSION);
|
1998-11-05 04:09:07 +08:00
|
|
|
#else
|
|
|
|
printf(" Protocol Version: unknown\n");
|
|
|
|
#endif
|
|
|
|
#ifdef LDAP_VERSION_MIN
|
1999-05-19 09:12:33 +08:00
|
|
|
printf(" Protocol Min: %d\n", (int) LDAP_VERSION_MIN);
|
1998-11-05 04:09:07 +08:00
|
|
|
#else
|
|
|
|
printf(" Protocol Min: unknown\n");
|
|
|
|
#endif
|
|
|
|
#ifdef LDAP_VERSION_MAX
|
1999-05-19 09:12:33 +08:00
|
|
|
printf(" Protocol Max: %d\n", (int) LDAP_VERSION_MAX);
|
1998-11-05 04:09:07 +08:00
|
|
|
#else
|
|
|
|
printf(" Protocol Max: unknown\n");
|
|
|
|
#endif
|
|
|
|
#ifdef LDAP_VENDOR_NAME
|
1999-05-31 13:34:49 +08:00
|
|
|
printf(" Vendor Name: %s\n", LDAP_VENDOR_NAME);
|
1998-11-05 04:09:07 +08:00
|
|
|
#else
|
|
|
|
printf(" Vendor Name: unknown\n");
|
|
|
|
#endif
|
|
|
|
#ifdef LDAP_VENDOR_VERSION
|
1999-05-19 09:12:33 +08:00
|
|
|
printf(" Vendor Version: %d\n", (int) LDAP_VENDOR_VERSION);
|
1998-11-05 04:09:07 +08:00
|
|
|
#else
|
|
|
|
printf(" Vendor Version: unknown\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) != LDAP_SUCCESS) {
|
1999-05-31 13:34:49 +08:00
|
|
|
fprintf(stderr, "%s: ldap_get_option(API_INFO) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nExecution time API Information\n");
|
|
|
|
printf(" API Info version: %d\n", api.ldapai_info_version);
|
|
|
|
|
|
|
|
if (api.ldapai_info_version != LDAP_API_INFO_VERSION) {
|
1999-05-19 09:12:33 +08:00
|
|
|
printf(" API INFO version mismatch: got %d, expected %d\n",
|
|
|
|
api.ldapai_info_version, LDAP_API_INFO_VERSION);
|
|
|
|
return EXIT_FAILURE;
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
printf(" API Version: %d\n", api.ldapai_api_version);
|
|
|
|
printf(" Protocol Max: %d\n", api.ldapai_protocol_version);
|
1998-11-05 14:16:11 +08:00
|
|
|
|
1998-11-05 04:09:07 +08:00
|
|
|
if(api.ldapai_extensions == NULL) {
|
|
|
|
printf(" Extensions: none\n");
|
1998-11-05 14:16:11 +08:00
|
|
|
|
1998-11-05 04:09:07 +08:00
|
|
|
} else {
|
|
|
|
int i;
|
1998-11-11 04:27:47 +08:00
|
|
|
for(i=0; api.ldapai_extensions[i] != NULL; i++) /* empty */;
|
|
|
|
printf(" Extensions: %d\n", i);
|
1998-11-05 04:09:07 +08:00
|
|
|
for(i=0; api.ldapai_extensions[i] != NULL; i++) {
|
1999-05-19 09:12:33 +08:00
|
|
|
#ifdef LDAP_OPT_API_FEATURE_INFO
|
1998-12-22 11:17:25 +08:00
|
|
|
LDAPAPIFeatureInfo fi;
|
1999-05-19 09:12:33 +08:00
|
|
|
fi.ldapaif_info_version = LDAP_FEATURE_INFO_VERSION;
|
1998-12-22 11:17:25 +08:00
|
|
|
fi.ldapaif_name = api.ldapai_extensions[i];
|
|
|
|
fi.ldapaif_version = 0;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
if( ldap_get_option(NULL, LDAP_OPT_API_FEATURE_INFO, &fi) == LDAP_SUCCESS ) {
|
|
|
|
if(fi.ldapaif_info_version != LDAP_FEATURE_INFO_VERSION) {
|
|
|
|
printf(" %s feature info mismatch: got %d, expected %d\n",
|
|
|
|
api.ldapai_extensions[i],
|
|
|
|
LDAP_FEATURE_INFO_VERSION,
|
|
|
|
fi.ldapaif_info_version);
|
1998-12-22 11:17:25 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
} else {
|
|
|
|
printf(" %s: version %d\n",
|
|
|
|
fi.ldapaif_name,
|
|
|
|
fi.ldapaif_version);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
printf(" %s (NO FEATURE INFO)\n",
|
|
|
|
api.ldapai_extensions[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
printf(" %s\n",
|
|
|
|
api.ldapai_extensions[i]);
|
1998-12-22 11:17:25 +08:00
|
|
|
#endif
|
1999-06-02 03:08:27 +08:00
|
|
|
|
1999-05-31 13:34:49 +08:00
|
|
|
ldap_memfree(api.ldapai_extensions[i]);
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|
1999-05-31 13:34:49 +08:00
|
|
|
ldap_memfree(api.ldapai_extensions);
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|
1998-11-05 14:16:11 +08:00
|
|
|
|
1998-11-05 04:09:07 +08:00
|
|
|
printf(" Vendor Name: %s\n", api.ldapai_vendor_name);
|
1999-05-31 13:34:49 +08:00
|
|
|
ldap_memfree(api.ldapai_vendor_name);
|
|
|
|
|
1998-11-05 04:09:07 +08:00
|
|
|
printf(" Vendor Version: %d\n", api.ldapai_vendor_version);
|
|
|
|
|
|
|
|
printf("\nExecution time Default Options\n");
|
|
|
|
|
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_DEREF, &ival) != LDAP_SUCCESS) {
|
1998-11-11 04:27:47 +08:00
|
|
|
fprintf(stderr, "%s: ldap_get_option(api) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|
|
|
|
printf(" DEREF: %d\n", ival);
|
|
|
|
|
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_SIZELIMIT, &ival) != LDAP_SUCCESS) {
|
1998-11-11 04:27:47 +08:00
|
|
|
fprintf(stderr, "%s: ldap_get_option(sizelimit) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|
|
|
|
printf(" SIZELIMIT: %d\n", ival);
|
|
|
|
|
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_TIMELIMIT, &ival) != LDAP_SUCCESS) {
|
1998-11-11 04:27:47 +08:00
|
|
|
fprintf(stderr, "%s: ldap_get_option(timelimit) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|
|
|
|
printf(" TIMELIMIT: %d\n", ival);
|
1998-11-05 14:18:06 +08:00
|
|
|
|
1998-11-11 04:27:47 +08:00
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_REFERRALS, &ival) != LDAP_SUCCESS) {
|
|
|
|
fprintf(stderr, "%s: ldap_get_option(referrals) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-11 04:27:47 +08:00
|
|
|
}
|
1999-06-01 01:30:22 +08:00
|
|
|
printf(" REFERRALS: %s\n", ival ? "on" : "off");
|
1998-11-11 04:27:47 +08:00
|
|
|
|
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_RESTART, &ival) != LDAP_SUCCESS) {
|
|
|
|
fprintf(stderr, "%s: ldap_get_option(restart) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-11 04:27:47 +08:00
|
|
|
}
|
1999-06-01 01:30:22 +08:00
|
|
|
printf(" RESTART: %s\n", ival ? "on" : "off");
|
1998-11-11 04:27:47 +08:00
|
|
|
|
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ival) != LDAP_SUCCESS) {
|
|
|
|
fprintf(stderr, "%s: ldap_get_option(protocol version) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-11 04:27:47 +08:00
|
|
|
}
|
|
|
|
printf(" PROTOCOL VERSION: %d\n", ival);
|
|
|
|
|
|
|
|
if(ldap_get_option(NULL, LDAP_OPT_HOST_NAME, &sval) != LDAP_SUCCESS) {
|
|
|
|
fprintf(stderr, "%s: ldap_get_option(host name) failed\n", argv[0]);
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_FAILURE;
|
1998-11-11 04:27:47 +08:00
|
|
|
}
|
1999-05-31 13:34:49 +08:00
|
|
|
if( sval != NULL ) {
|
|
|
|
printf(" HOST NAME: %s\n", sval);
|
|
|
|
ldap_memfree(sval);
|
|
|
|
} else {
|
1999-08-18 05:14:03 +08:00
|
|
|
puts(" HOST NAME: <not set>");
|
1999-05-31 13:34:49 +08:00
|
|
|
}
|
1998-11-11 04:27:47 +08:00
|
|
|
|
2000-10-17 07:11:41 +08:00
|
|
|
#if 0
|
|
|
|
/* API tests */
|
|
|
|
{ /* bindless unbind */
|
|
|
|
LDAP *ld;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
ld = ldap_init( "localhost", 389 );
|
|
|
|
if( ld == NULL ) {
|
|
|
|
perror("ldap_init");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ldap_unbind( ld );
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
perror("ldap_unbind");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{ /* bindless unbind */
|
|
|
|
LDAP *ld;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
ld = ldap_init( "localhost", 389 );
|
|
|
|
if( ld == NULL ) {
|
|
|
|
perror("ldap_init");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ldap_abandon_ext( ld, 0, NULL, NULL );
|
|
|
|
if( rc != LDAP_SERVER_DOWN ) {
|
|
|
|
ldap_perror( ld, "ldap_abandon");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ldap_unbind( ld );
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
perror("ldap_unbind");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
return EXIT_SUCCESS;
|
1998-11-05 04:09:07 +08:00
|
|
|
}
|