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