]> git.sur5r.net Git - openldap/blob - libraries/libldap/init.c
ITS#5369 SASL/GSSAPi refactoring from Stefan Metzmacher <metze@samba.org>
[openldap] / libraries / libldap / init.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2008 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19 #include <ac/stdlib.h>
20
21 #include <ac/socket.h>
22 #include <ac/string.h>
23 #include <ac/ctype.h>
24 #include <ac/time.h>
25
26 #ifdef HAVE_LIMITS_H
27 #include <limits.h>
28 #endif
29
30 #include "ldap-int.h"
31 #include "ldap_defaults.h"
32 #include "lutil.h"
33
34 struct ldapoptions ldap_int_global_options =
35         { LDAP_UNINITIALIZED, LDAP_DEBUG_NONE };  
36
37 #define ATTR_NONE       0
38 #define ATTR_BOOL       1
39 #define ATTR_INT        2
40 #define ATTR_KV         3
41 #define ATTR_STRING     4
42 #define ATTR_OPTION     5
43
44 #define ATTR_SASL       6
45 #define ATTR_TLS        7
46
47 #define ATTR_OPT_TV     8
48 #define ATTR_OPT_INT    9
49
50 #define ATTR_GSSAPI     10
51
52 struct ol_keyvalue {
53         const char *            key;
54         int                     value;
55 };
56
57 static const struct ol_keyvalue deref_kv[] = {
58         {"never", LDAP_DEREF_NEVER},
59         {"searching", LDAP_DEREF_SEARCHING},
60         {"finding", LDAP_DEREF_FINDING},
61         {"always", LDAP_DEREF_ALWAYS},
62         {NULL, 0}
63 };
64
65 static const struct ol_attribute {
66         int                     useronly;
67         int                     type;
68         const char *    name;
69         const void *    data;
70         size_t          offset;
71 } attrs[] = {
72         {0, ATTR_OPT_TV,        "TIMEOUT",              NULL,   LDAP_OPT_TIMEOUT},
73         {0, ATTR_OPT_TV,        "NETWORK_TIMEOUT",      NULL,   LDAP_OPT_NETWORK_TIMEOUT},
74         {0, ATTR_OPT_INT,       "VERSION",              NULL,   LDAP_OPT_PROTOCOL_VERSION},
75         {0, ATTR_KV,            "DEREF",        deref_kv, /* or &deref_kv[0] */
76                 offsetof(struct ldapoptions, ldo_deref)},
77         {0, ATTR_INT,           "SIZELIMIT",    NULL,
78                 offsetof(struct ldapoptions, ldo_sizelimit)},
79         {0, ATTR_INT,           "TIMELIMIT",    NULL,
80                 offsetof(struct ldapoptions, ldo_timelimit)},
81         {1, ATTR_STRING,        "BINDDN",               NULL,
82                 offsetof(struct ldapoptions, ldo_defbinddn)},
83         {0, ATTR_STRING,        "BASE",                 NULL,
84                 offsetof(struct ldapoptions, ldo_defbase)},
85         {0, ATTR_INT,           "PORT",                 NULL,           /* deprecated */
86                 offsetof(struct ldapoptions, ldo_defport)},
87         {0, ATTR_OPTION,        "HOST",                 NULL,   LDAP_OPT_HOST_NAME}, /* deprecated */
88         {0, ATTR_OPTION,        "URI",                  NULL,   LDAP_OPT_URI}, /* replaces HOST/PORT */
89         {0, ATTR_BOOL,          "REFERRALS",    NULL,   LDAP_BOOL_REFERRALS},
90 #if 0
91         /* This should only be allowed via ldap_set_option(3) */
92         {0, ATTR_BOOL,          "RESTART",              NULL,   LDAP_BOOL_RESTART},
93 #endif
94
95 #ifdef HAVE_CYRUS_SASL
96         {0, ATTR_STRING,        "SASL_MECH",            NULL,
97                 offsetof(struct ldapoptions, ldo_def_sasl_mech)},
98         {0, ATTR_STRING,        "SASL_REALM",           NULL,
99                 offsetof(struct ldapoptions, ldo_def_sasl_realm)},
100         {1, ATTR_STRING,        "SASL_AUTHCID",         NULL,
101                 offsetof(struct ldapoptions, ldo_def_sasl_authcid)},
102         {1, ATTR_STRING,        "SASL_AUTHZID",         NULL,
103                 offsetof(struct ldapoptions, ldo_def_sasl_authzid)},
104         {0, ATTR_SASL,          "SASL_SECPROPS",        NULL,   LDAP_OPT_X_SASL_SECPROPS},
105 #endif
106
107 #ifdef HAVE_GSSAPI
108         {0, ATTR_GSSAPI,"GSSAPI_SIGN",                  NULL,   LDAP_OPT_SIGN},
109         {0, ATTR_GSSAPI,"GSSAPI_ENCRYPT",               NULL,   LDAP_OPT_ENCRYPT},
110         {0, ATTR_GSSAPI,"GSSAPI_ALLOW_REMOTE_PRINCIPAL",NULL,   LDAP_OPT_X_GSSAPI_ALLOW_REMOTE_PRINCIPAL},
111 #endif
112
113 #ifdef HAVE_TLS
114         {1, ATTR_TLS,   "TLS_CERT",                     NULL,   LDAP_OPT_X_TLS_CERTFILE},
115         {1, ATTR_TLS,   "TLS_KEY",                      NULL,   LDAP_OPT_X_TLS_KEYFILE},
116         {0, ATTR_TLS,   "TLS_CACERT",           NULL,   LDAP_OPT_X_TLS_CACERTFILE},
117         {0, ATTR_TLS,   "TLS_CACERTDIR",        NULL,   LDAP_OPT_X_TLS_CACERTDIR},
118         {0, ATTR_TLS,   "TLS_REQCERT",          NULL,   LDAP_OPT_X_TLS_REQUIRE_CERT},
119         {0, ATTR_TLS,   "TLS_RANDFILE",         NULL,   LDAP_OPT_X_TLS_RANDOM_FILE},
120         {0, ATTR_TLS,   "TLS_CIPHER_SUITE",     NULL,   LDAP_OPT_X_TLS_CIPHER_SUITE},
121
122 #ifdef HAVE_OPENSSL_CRL
123         {0, ATTR_TLS,   "TLS_CRLCHECK",         NULL,   LDAP_OPT_X_TLS_CRLCHECK},
124 #endif
125 #ifdef HAVE_GNUTLS
126         {0, ATTR_TLS,   "TLS_CRLFILE",                  NULL,   LDAP_OPT_X_TLS_CRLFILE},
127 #endif
128         
129 #endif
130
131         {0, ATTR_NONE,          NULL,           NULL,   0}
132 };
133
134 #define MAX_LDAP_ATTR_LEN  sizeof("GSSAPI_ALLOW_REMOTE_PRINCIPAL")
135 #define MAX_LDAP_ENV_PREFIX_LEN 8
136
137 static void openldap_ldap_init_w_conf(
138         const char *file, int userconf )
139 {
140         char linebuf[ AC_LINE_MAX ];
141         FILE *fp;
142         int i;
143         char *cmd, *opt;
144         char *start, *end;
145         struct ldapoptions *gopts;
146
147         if ((gopts = LDAP_INT_GLOBAL_OPT()) == NULL) {
148                 return;                 /* Could not allocate mem for global options */
149         }
150
151         if (file == NULL) {
152                 /* no file name */
153                 return;
154         }
155
156         Debug(LDAP_DEBUG_TRACE, "ldap_init: trying %s\n", file, 0, 0);
157
158         fp = fopen(file, "r");
159         if(fp == NULL) {
160                 /* could not open file */
161                 return;
162         }
163
164         Debug(LDAP_DEBUG_TRACE, "ldap_init: using %s\n", file, 0, 0);
165
166         while((start = fgets(linebuf, sizeof(linebuf), fp)) != NULL) {
167                 /* skip lines starting with '#' */
168                 if(*start == '#') continue;
169
170                 /* trim leading white space */
171                 while((*start != '\0') && isspace((unsigned char) *start))
172                         start++;
173
174                 /* anything left? */
175                 if(*start == '\0') continue;
176
177                 /* trim trailing white space */
178                 end = &start[strlen(start)-1];
179                 while(isspace((unsigned char)*end)) end--;
180                 end[1] = '\0';
181
182                 /* anything left? */
183                 if(*start == '\0') continue;
184                 
185
186                 /* parse the command */
187                 cmd=start;
188                 while((*start != '\0') && !isspace((unsigned char)*start)) {
189                         start++;
190                 }
191                 if(*start == '\0') {
192                         /* command has no argument */
193                         continue;
194                 } 
195
196                 *start++ = '\0';
197
198                 /* we must have some whitespace to skip */
199                 while(isspace((unsigned char)*start)) start++;
200                 opt = start;
201
202                 for(i=0; attrs[i].type != ATTR_NONE; i++) {
203                         void *p;
204
205                         if( !userconf && attrs[i].useronly ) {
206                                 continue;
207                         }
208
209                         if(strcasecmp(cmd, attrs[i].name) != 0) {
210                                 continue;
211                         }
212
213                         switch(attrs[i].type) {
214                         case ATTR_BOOL:
215                                 if((strcasecmp(opt, "on") == 0) 
216                                         || (strcasecmp(opt, "yes") == 0)
217                                         || (strcasecmp(opt, "true") == 0))
218                                 {
219                                         LDAP_BOOL_SET(gopts, attrs[i].offset);
220
221                                 } else {
222                                         LDAP_BOOL_CLR(gopts, attrs[i].offset);
223                                 }
224
225                                 break;
226
227                         case ATTR_INT: {
228                                 char *next;
229                                 long l;
230                                 p = &((char *) gopts)[attrs[i].offset];
231                                 l = strtol( opt, &next, 10 );
232                                 if ( next != opt && next[ 0 ] == '\0' ) {
233                                         * (int*) p = l;
234                                 }
235                                 } break;
236
237                         case ATTR_KV: {
238                                         const struct ol_keyvalue *kv;
239
240                                         for(kv = attrs[i].data;
241                                                 kv->key != NULL;
242                                                 kv++) {
243
244                                                 if(strcasecmp(opt, kv->key) == 0) {
245                                                         p = &((char *) gopts)[attrs[i].offset];
246                                                         * (int*) p = kv->value;
247                                                         break;
248                                                 }
249                                         }
250                                 } break;
251
252                         case ATTR_STRING:
253                                 p = &((char *) gopts)[attrs[i].offset];
254                                 if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
255                                 * (char**) p = LDAP_STRDUP(opt);
256                                 break;
257                         case ATTR_OPTION:
258                                 ldap_set_option( NULL, attrs[i].offset, opt );
259                                 break;
260                         case ATTR_SASL:
261 #ifdef HAVE_CYRUS_SASL
262                                 ldap_int_sasl_config( gopts, attrs[i].offset, opt );
263 #endif
264                                 break;
265                         case ATTR_GSSAPI:
266 #ifdef HAVE_GSSAPI
267                                 ldap_int_gssapi_config( gopts, attrs[i].offset, opt );
268 #endif
269                                 break;
270                         case ATTR_TLS:
271 #ifdef HAVE_TLS
272                                 ldap_int_tls_config( NULL, attrs[i].offset, opt );
273 #endif
274                                 break;
275                         case ATTR_OPT_TV: {
276                                 struct timeval tv;
277                                 char *next;
278                                 tv.tv_usec = 0;
279                                 tv.tv_sec = strtol( opt, &next, 10 );
280                                 if ( next != opt && next[ 0 ] == '\0' && tv.tv_sec > 0 ) {
281                                         (void)ldap_set_option( NULL, attrs[i].offset, (const void *)&tv );
282                                 }
283                                 } break;
284                         case ATTR_OPT_INT: {
285                                 long l;
286                                 char *next;
287                                 l = strtol( opt, &next, 10 );
288                                 if ( next != opt && next[ 0 ] == '\0' && l > 0 && (long)((int)l) == l ) {
289                                         int v = (int)l;
290                                         (void)ldap_set_option( NULL, attrs[i].offset, (const void *)&v );
291                                 }
292                                 } break;
293                         }
294
295                         break;
296                 }
297         }
298
299         fclose(fp);
300 }
301
302 static void openldap_ldap_init_w_sysconf(const char *file)
303 {
304         openldap_ldap_init_w_conf( file, 0 );
305 }
306
307 static void openldap_ldap_init_w_userconf(const char *file)
308 {
309         char *home;
310         char *path = NULL;
311
312         if (file == NULL) {
313                 /* no file name */
314                 return;
315         }
316
317         home = getenv("HOME");
318
319         if (home != NULL) {
320                 Debug(LDAP_DEBUG_TRACE, "ldap_init: HOME env is %s\n",
321                       home, 0, 0);
322                 path = LDAP_MALLOC(strlen(home) + strlen(file) + sizeof( LDAP_DIRSEP "."));
323         } else {
324                 Debug(LDAP_DEBUG_TRACE, "ldap_init: HOME env is NULL\n",
325                       0, 0, 0);
326         }
327
328         if(home != NULL && path != NULL) {
329                 /* we assume UNIX path syntax is used... */
330
331                 /* try ~/file */
332                 sprintf(path, "%s" LDAP_DIRSEP "%s", home, file);
333                 openldap_ldap_init_w_conf(path, 1);
334
335                 /* try ~/.file */
336                 sprintf(path, "%s" LDAP_DIRSEP ".%s", home, file);
337                 openldap_ldap_init_w_conf(path, 1);
338         }
339
340         if(path != NULL) {
341                 LDAP_FREE(path);
342         }
343
344         /* try file */
345         openldap_ldap_init_w_conf(file, 1);
346 }
347
348 static void openldap_ldap_init_w_env(
349                 struct ldapoptions *gopts,
350                 const char *prefix)
351 {
352         char buf[MAX_LDAP_ATTR_LEN+MAX_LDAP_ENV_PREFIX_LEN];
353         int len;
354         int i;
355         void *p;
356         char *value;
357
358         if (prefix == NULL) {
359                 prefix = LDAP_ENV_PREFIX;
360         }
361
362         strncpy(buf, prefix, MAX_LDAP_ENV_PREFIX_LEN);
363         buf[MAX_LDAP_ENV_PREFIX_LEN] = '\0';
364         len = strlen(buf);
365
366         for(i=0; attrs[i].type != ATTR_NONE; i++) {
367                 strcpy(&buf[len], attrs[i].name);
368                 value = getenv(buf);
369
370                 if(value == NULL) {
371                         continue;
372                 }
373
374                 switch(attrs[i].type) {
375                 case ATTR_BOOL:
376                         if((strcasecmp(value, "on") == 0) 
377                                 || (strcasecmp(value, "yes") == 0)
378                                 || (strcasecmp(value, "true") == 0))
379                         {
380                                 LDAP_BOOL_SET(gopts, attrs[i].offset);
381
382                         } else {
383                                 LDAP_BOOL_CLR(gopts, attrs[i].offset);
384                         }
385                         break;
386
387                 case ATTR_INT:
388                         p = &((char *) gopts)[attrs[i].offset];
389                         * (int*) p = atoi(value);
390                         break;
391
392                 case ATTR_KV: {
393                                 const struct ol_keyvalue *kv;
394
395                                 for(kv = attrs[i].data;
396                                         kv->key != NULL;
397                                         kv++) {
398
399                                         if(strcasecmp(value, kv->key) == 0) {
400                                                 p = &((char *) gopts)[attrs[i].offset];
401                                                 * (int*) p = kv->value;
402                                                 break;
403                                         }
404                                 }
405                         } break;
406
407                 case ATTR_STRING:
408                         p = &((char *) gopts)[attrs[i].offset];
409                         if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
410                         if (*value == '\0') {
411                                 * (char**) p = NULL;
412                         } else {
413                                 * (char**) p = LDAP_STRDUP(value);
414                         }
415                         break;
416                 case ATTR_OPTION:
417                         ldap_set_option( NULL, attrs[i].offset, value );
418                         break;
419                 case ATTR_SASL:
420 #ifdef HAVE_CYRUS_SASL
421                         ldap_int_sasl_config( gopts, attrs[i].offset, value );
422 #endif                          
423                         break;
424                 case ATTR_TLS:
425 #ifdef HAVE_TLS
426                         ldap_int_tls_config( NULL, attrs[i].offset, value );
427 #endif                          
428                         break;
429                 }
430         }
431 }
432
433 #if defined(__GNUC__)
434 /* Declare this function as a destructor so that it will automatically be
435  * invoked either at program exit (if libldap is a static library) or
436  * at unload time (if libldap is a dynamic library).
437  *
438  * Sorry, don't know how to handle this for non-GCC environments.
439  */
440 static void ldap_int_destroy_global_options(void)
441         __attribute__ ((destructor));
442 #endif
443
444 static void
445 ldap_int_destroy_global_options(void)
446 {
447         struct ldapoptions *gopts = LDAP_INT_GLOBAL_OPT();
448
449         if ( gopts == NULL )
450                 return;
451
452         gopts->ldo_valid = LDAP_UNINITIALIZED;
453
454         if ( gopts->ldo_defludp ) {
455                 ldap_free_urllist( gopts->ldo_defludp );
456                 gopts->ldo_defludp = NULL;
457         }
458 #if defined(HAVE_WINSOCK) || defined(HAVE_WINSOCK2)
459         WSACleanup( );
460 #endif
461
462 #if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
463         if ( ldap_int_hostname ) {
464                 LDAP_FREE( ldap_int_hostname );
465                 ldap_int_hostname = NULL;
466         }
467 #endif
468 #ifdef HAVE_CYRUS_SASL
469         if ( gopts->ldo_def_sasl_authcid ) {
470                 LDAP_FREE( gopts->ldo_def_sasl_authcid );
471                 gopts->ldo_def_sasl_authcid = NULL;
472         }
473 #endif
474 #ifdef HAVE_TLS
475         ldap_int_tls_destroy( gopts );
476 #endif
477 }
478
479 /* 
480  * Initialize the global options structure with default values.
481  */
482 void ldap_int_initialize_global_options( struct ldapoptions *gopts, int *dbglvl )
483 {
484         if (dbglvl)
485             gopts->ldo_debug = *dbglvl;
486         else
487                 gopts->ldo_debug = 0;
488
489         gopts->ldo_version   = LDAP_VERSION2;
490         gopts->ldo_deref     = LDAP_DEREF_NEVER;
491         gopts->ldo_timelimit = LDAP_NO_LIMIT;
492         gopts->ldo_sizelimit = LDAP_NO_LIMIT;
493
494         gopts->ldo_tm_api.tv_sec = -1;
495         gopts->ldo_tm_net.tv_sec = -1;
496
497         /* ldo_defludp will be freed by the termination handler
498          */
499         ldap_url_parselist(&gopts->ldo_defludp, "ldap://localhost/");
500         gopts->ldo_defport = LDAP_PORT;
501 #if !defined(__GNUC__) && !defined(PIC)
502         /* Do this only for a static library, and only if we can't
503          * arrange for it to be executed as a library destructor
504          */
505         atexit(ldap_int_destroy_global_options);
506 #endif
507
508         gopts->ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
509         gopts->ldo_rebind_proc = NULL;
510         gopts->ldo_rebind_params = NULL;
511
512         LDAP_BOOL_ZERO(gopts);
513
514         LDAP_BOOL_SET(gopts, LDAP_BOOL_REFERRALS);
515
516 #ifdef LDAP_CONNECTIONLESS
517         gopts->ldo_peer = NULL;
518         gopts->ldo_cldapdn = NULL;
519         gopts->ldo_is_udp = 0;
520 #endif
521
522 #ifdef HAVE_CYRUS_SASL
523         gopts->ldo_def_sasl_mech = NULL;
524         gopts->ldo_def_sasl_realm = NULL;
525         gopts->ldo_def_sasl_authcid = NULL;
526         gopts->ldo_def_sasl_authzid = NULL;
527
528         memset( &gopts->ldo_sasl_secprops,
529                 '\0', sizeof(gopts->ldo_sasl_secprops) );
530
531         gopts->ldo_sasl_secprops.max_ssf = INT_MAX;
532         gopts->ldo_sasl_secprops.maxbufsize = SASL_MAX_BUFF_SIZE;
533         gopts->ldo_sasl_secprops.security_flags =
534                 SASL_SEC_NOPLAINTEXT | SASL_SEC_NOANONYMOUS;
535 #endif
536
537 #ifdef HAVE_TLS
538         gopts->ldo_tls_connect_cb = NULL;
539         gopts->ldo_tls_connect_arg = NULL;
540         gopts->ldo_tls_require_cert = LDAP_OPT_X_TLS_DEMAND;
541 #endif
542
543         gopts->ldo_valid = LDAP_INITIALIZED;
544         return;
545 }
546
547 #if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
548 char * ldap_int_hostname = NULL;
549 #endif
550
551 void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
552 {
553         if ( gopts->ldo_valid == LDAP_INITIALIZED ) {
554                 return;
555         }
556
557         ldap_int_error_init();
558
559         ldap_int_utils_init();
560
561 #ifdef HAVE_WINSOCK2
562 {       WORD wVersionRequested;
563         WSADATA wsaData;
564  
565         wVersionRequested = MAKEWORD( 2, 0 );
566         if ( WSAStartup( wVersionRequested, &wsaData ) != 0 ) {
567                 /* Tell the user that we couldn't find a usable */
568                 /* WinSock DLL.                                  */
569                 return;
570         }
571  
572         /* Confirm that the WinSock DLL supports 2.0.*/
573         /* Note that if the DLL supports versions greater    */
574         /* than 2.0 in addition to 2.0, it will still return */
575         /* 2.0 in wVersion since that is the version we      */
576         /* requested.                                        */
577  
578         if ( LOBYTE( wsaData.wVersion ) != 2 ||
579                 HIBYTE( wsaData.wVersion ) != 0 )
580         {
581             /* Tell the user that we couldn't find a usable */
582             /* WinSock DLL.                                  */
583             WSACleanup( );
584             return; 
585         }
586 }       /* The WinSock DLL is acceptable. Proceed. */
587 #elif HAVE_WINSOCK
588 {       WSADATA wsaData;
589         if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
590             return;
591         }
592 }
593 #endif
594
595 #if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
596         {
597                 char    *name = ldap_int_hostname;
598
599                 ldap_int_hostname = ldap_pvt_get_fqdn( name );
600
601                 if ( name != NULL && name != ldap_int_hostname ) {
602                         LDAP_FREE( name );
603                 }
604         }
605 #endif
606
607 #ifndef HAVE_POLL
608         if ( ldap_int_tblsize == 0 ) ldap_int_ip_init();
609 #endif
610
611         ldap_int_initialize_global_options(gopts, NULL);
612
613         if( getenv("LDAPNOINIT") != NULL ) {
614                 return;
615         }
616
617 #ifdef HAVE_CYRUS_SASL
618         {
619                 /* set authentication identity to current user name */
620                 char *user = getenv("USER");
621
622                 if( user == NULL ) user = getenv("USERNAME");
623                 if( user == NULL ) user = getenv("LOGNAME");
624
625                 if( user != NULL ) {
626                         gopts->ldo_def_sasl_authcid = LDAP_STRDUP( user );
627                 }
628     }
629 #endif
630
631         openldap_ldap_init_w_sysconf(LDAP_CONF_FILE);
632         openldap_ldap_init_w_userconf(LDAP_USERRC_FILE);
633
634         {
635                 char *altfile = getenv(LDAP_ENV_PREFIX "CONF");
636
637                 if( altfile != NULL ) {
638                         Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is %s\n",
639                               LDAP_ENV_PREFIX "CONF", altfile, 0);
640                         openldap_ldap_init_w_sysconf( altfile );
641                 }
642                 else
643                         Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is NULL\n",
644                               LDAP_ENV_PREFIX "CONF", 0, 0);
645         }
646
647         {
648                 char *altfile = getenv(LDAP_ENV_PREFIX "RC");
649
650                 if( altfile != NULL ) {
651                         Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is %s\n",
652                               LDAP_ENV_PREFIX "RC", altfile, 0);
653                         openldap_ldap_init_w_userconf( altfile );
654                 }
655                 else
656                         Debug(LDAP_DEBUG_TRACE, "ldap_init: %s env is NULL\n",
657                               LDAP_ENV_PREFIX "RC", 0, 0);
658         }
659
660         openldap_ldap_init_w_env(gopts, NULL);
661 }