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