Back to index

openldap  2.4.31
apitest.c
Go to the documentation of this file.
00001 /* apitest.c -- OpenLDAP API Test Program */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This program was orignally developed by Kurt D. Zeilenga for inclusion in
00019  * OpenLDAP Software.
00020  */
00021 #include "portable.h"
00022 
00023 #include <ac/stdlib.h>
00024 
00025 #include <stdio.h>
00026 
00027 #include <ldap.h>
00028 
00029 int
00030 main(int argc, char **argv)
00031 {
00032        LDAPAPIInfo api;
00033        int ival;
00034        char *sval;
00035 
00036        printf("Compile time API Information\n");
00037 
00038 #ifdef LDAP_API_INFO_VERSION
00039        api.ldapai_info_version = LDAP_API_INFO_VERSION;
00040        printf("  API Info version:  %d\n", (int) api.ldapai_info_version);
00041 #else
00042        api.ldapai_info_version = 1;
00043        printf("  API Info version:  unknown\n");
00044 #endif
00045 
00046 #ifdef LDAP_FEATURE_INFO_VERSION
00047        printf("  Feature Info version:  %d\n", (int) LDAP_FEATURE_INFO_VERSION);
00048 #else
00049        printf("  Feature Info version:  unknown\n");
00050        api.ldapai_info_version = 1;
00051 #endif
00052 
00053 #ifdef LDAP_API_VERSION
00054        printf("  API version:       %d\n", (int) LDAP_API_VERSION);
00055 #else
00056        printf("  API version:       unknown\n");
00057 #endif
00058 
00059 #ifdef LDAP_VERSION
00060        printf("  Protocol Version:  %d\n", (int) LDAP_VERSION);
00061 #else
00062        printf("  Protocol Version:  unknown\n");
00063 #endif
00064 #ifdef LDAP_VERSION_MIN
00065        printf("  Protocol Min:      %d\n", (int) LDAP_VERSION_MIN);
00066 #else
00067        printf("  Protocol Min:      unknown\n");
00068 #endif
00069 #ifdef LDAP_VERSION_MAX
00070        printf("  Protocol Max:      %d\n", (int) LDAP_VERSION_MAX);
00071 #else
00072        printf("  Protocol Max:      unknown\n");
00073 #endif
00074 #ifdef LDAP_VENDOR_NAME
00075        printf("  Vendor Name:       %s\n", LDAP_VENDOR_NAME);
00076 #else
00077        printf("  Vendor Name:       unknown\n");
00078 #endif
00079 #ifdef LDAP_VENDOR_VERSION
00080        printf("  Vendor Version:    %d\n", (int) LDAP_VENDOR_VERSION);
00081 #else
00082        printf("  Vendor Version:    unknown\n");
00083 #endif
00084 
00085        if(ldap_get_option(NULL, LDAP_OPT_API_INFO, &api) != LDAP_SUCCESS) {
00086               fprintf(stderr, "%s: ldap_get_option(API_INFO) failed\n", argv[0]);
00087               return EXIT_FAILURE;
00088        }
00089 
00090        printf("\nExecution time API Information\n");
00091        printf("  API Info version:  %d\n", api.ldapai_info_version);
00092 
00093        if (api.ldapai_info_version != LDAP_API_INFO_VERSION) {
00094               printf(" API INFO version mismatch: got %d, expected %d\n",
00095                      api.ldapai_info_version, LDAP_API_INFO_VERSION);
00096               return EXIT_FAILURE;
00097        }
00098 
00099        printf("  API Version:       %d\n", api.ldapai_api_version);
00100        printf("  Protocol Max:      %d\n", api.ldapai_protocol_version);
00101 
00102        if(api.ldapai_extensions == NULL) {
00103               printf("  Extensions:        none\n");
00104 
00105        } else {
00106               int i;
00107               for(i=0; api.ldapai_extensions[i] != NULL; i++) /* empty */;
00108               printf("  Extensions:        %d\n", i);
00109               for(i=0; api.ldapai_extensions[i] != NULL; i++) {
00110 #ifdef LDAP_OPT_API_FEATURE_INFO
00111                      LDAPAPIFeatureInfo fi;
00112                      fi.ldapaif_info_version = LDAP_FEATURE_INFO_VERSION;
00113                      fi.ldapaif_name = api.ldapai_extensions[i];
00114                      fi.ldapaif_version = 0;
00115 
00116                      if( ldap_get_option(NULL, LDAP_OPT_API_FEATURE_INFO, &fi) == LDAP_SUCCESS ) {
00117                             if(fi.ldapaif_info_version != LDAP_FEATURE_INFO_VERSION) {
00118                                    printf("                     %s feature info mismatch: got %d, expected %d\n",
00119                                           api.ldapai_extensions[i],
00120                                           LDAP_FEATURE_INFO_VERSION,
00121                                           fi.ldapaif_info_version);
00122 
00123                             } else {
00124                                    printf("                     %s: version %d\n",
00125                                           fi.ldapaif_name,
00126                                           fi.ldapaif_version);
00127                             }
00128 
00129                      } else {
00130                             printf("                     %s (NO FEATURE INFO)\n",
00131                                    api.ldapai_extensions[i]);
00132                      }
00133 
00134 #else
00135                      printf("                     %s\n",
00136                             api.ldapai_extensions[i]);
00137 #endif
00138 
00139                      ldap_memfree(api.ldapai_extensions[i]);
00140               }
00141               ldap_memfree(api.ldapai_extensions);
00142        }
00143 
00144        printf("  Vendor Name:       %s\n", api.ldapai_vendor_name);
00145        ldap_memfree(api.ldapai_vendor_name);
00146 
00147        printf("  Vendor Version:    %d\n", api.ldapai_vendor_version);
00148 
00149        printf("\nExecution time Default Options\n");
00150 
00151        if(ldap_get_option(NULL, LDAP_OPT_DEREF, &ival) != LDAP_SUCCESS) {
00152               fprintf(stderr, "%s: ldap_get_option(api) failed\n", argv[0]);
00153               return EXIT_FAILURE;
00154        }
00155        printf("  DEREF:             %d\n", ival);
00156 
00157        if(ldap_get_option(NULL, LDAP_OPT_SIZELIMIT, &ival) != LDAP_SUCCESS) {
00158               fprintf(stderr, "%s: ldap_get_option(sizelimit) failed\n", argv[0]);
00159               return EXIT_FAILURE;
00160        }
00161        printf("  SIZELIMIT:         %d\n", ival);
00162 
00163        if(ldap_get_option(NULL, LDAP_OPT_TIMELIMIT, &ival) != LDAP_SUCCESS) {
00164               fprintf(stderr, "%s: ldap_get_option(timelimit) failed\n", argv[0]);
00165               return EXIT_FAILURE;
00166        }
00167        printf("  TIMELIMIT:         %d\n", ival);
00168 
00169        if(ldap_get_option(NULL, LDAP_OPT_REFERRALS, &ival) != LDAP_SUCCESS) {
00170               fprintf(stderr, "%s: ldap_get_option(referrals) failed\n", argv[0]);
00171               return EXIT_FAILURE;
00172        }
00173        printf("  REFERRALS:         %s\n", ival ? "on" : "off");
00174 
00175        if(ldap_get_option(NULL, LDAP_OPT_RESTART, &ival) != LDAP_SUCCESS) {
00176               fprintf(stderr, "%s: ldap_get_option(restart) failed\n", argv[0]);
00177               return EXIT_FAILURE;
00178        }
00179        printf("  RESTART:           %s\n", ival ? "on" : "off");
00180 
00181        if(ldap_get_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ival) != LDAP_SUCCESS) {
00182               fprintf(stderr, "%s: ldap_get_option(protocol version) failed\n", argv[0]);
00183               return EXIT_FAILURE;
00184        }
00185        printf("  PROTOCOL VERSION:  %d\n", ival);
00186 
00187        if(ldap_get_option(NULL, LDAP_OPT_HOST_NAME, &sval) != LDAP_SUCCESS) {
00188               fprintf(stderr, "%s: ldap_get_option(host name) failed\n", argv[0]);
00189               return EXIT_FAILURE;
00190        }
00191        if( sval != NULL ) {
00192               printf("  HOST NAME:         %s\n", sval);
00193               ldap_memfree(sval);
00194        } else {
00195               puts("  HOST NAME:         <not set>");
00196        }
00197 
00198 #if 0
00199        /* API tests */
00200        {      /* bindless unbind */
00201               LDAP *ld;
00202               int rc;
00203 
00204               ld = ldap_init( "localhost", 389 );
00205               if( ld == NULL ) {
00206                      perror("ldap_init");
00207                      return EXIT_FAILURE;
00208               }
00209 
00210               rc = ldap_unbind( ld );
00211               if( rc != LDAP_SUCCESS ) {
00212                      perror("ldap_unbind");
00213                      return EXIT_FAILURE;
00214               }
00215        }
00216        {      /* bindless unbind */
00217               LDAP *ld;
00218               int rc;
00219 
00220               ld = ldap_init( "localhost", 389 );
00221               if( ld == NULL ) {
00222                      perror("ldap_init");
00223                      return EXIT_FAILURE;
00224               }
00225 
00226               rc = ldap_abandon_ext( ld, 0, NULL, NULL );
00227               if( rc != LDAP_SERVER_DOWN ) {
00228                      ldap_perror( ld, "ldap_abandon");
00229                      return EXIT_FAILURE;
00230               }
00231 
00232               rc = ldap_unbind( ld );
00233               if( rc != LDAP_SUCCESS ) {
00234                      perror("ldap_unbind");
00235                      return EXIT_FAILURE;
00236               }
00237        }
00238 #endif
00239 
00240        return EXIT_SUCCESS;
00241 }