]> git.sur5r.net Git - openldap/blob - clients/ud/main.c
Modified UD as necessary to compile and link under NT.
[openldap] / clients / ud / main.c
1 /*
2  * Copyright (c) 1991, 1992, 1993 
3  * Regents of the University of Michigan.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  *
12  * The University of Michigan would like to thank the following people for
13  * their contributions to this piece of software:
14  *
15  *      Robert Urquhart    <robert@sfu.ca>
16  *      Simon Fraser University, Academic Computing Services
17  */
18
19 #include "portable.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <setjmp.h>
24
25 #ifdef HAVE_PWD_H
26 #include <pwd.h>
27 #endif
28
29 #include <ac/signal.h>
30 #include <ac/string.h>
31 #include <ac/termios.h>
32 #include <ac/time.h>
33 #include <ac/unistd.h>
34
35 #ifdef HAVE_SYS_FILE_H
36 #include <sys/file.h>
37 #endif
38
39 #include <lber.h>
40 #include <ldap.h>
41
42 #include <ldapconfig.h>
43 #include "ud.h"
44
45 #ifndef lint
46 char copyright[] =
47 "@(#) Copyright (c) 1991, 1992, 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
48 #endif
49
50 /*
51  *  Used with change_base() to indicate which base we are changing.
52  */
53 #define BASE_SEARCH     0
54 #define BASE_GROUPS     1
55
56 #define iscom(x)        (!strncasecmp(x, cmd, strlen(cmd)))
57
58 static char *server = NULL;
59 static char *config_file = UD_CONFIG_FILE;
60 static char *filter_file = FILTERFILE;
61 static int ldap_port = LDAP_PORT;
62 static int dereference = TRUE;
63
64 char *default_bind_object = NULL;
65
66 char *bound_dn;                 /* bound user's Distinguished Name */
67 char *group_base;               /* place in LDAP tree where groups are */
68 char *search_base;              /* place in LDAP tree where searches start */
69
70 static jmp_buf env;             /* spot to jump to on an interrupt */
71
72 int lpp;                        /* lines per page */
73 int verbose;                    /* 1 if verbose mode on */
74 int col_size;                   /* characters across on the screen */
75 int bind_status;                /* user's bind status */
76
77 LDAP *ld;                       /* LDAP descriptor */
78 LDAPFiltDesc *lfdp;             /* LDAP filter descriptor */
79
80 #ifdef DEBUG
81 int debug;                      /* debug flag */
82 #endif
83
84 extern void initialize_client();
85 extern void initialize_attribute_strings();
86
87 main(argc, argv)
88 int argc;
89 char *argv[];
90 {
91         extern char Version[];                  /* version number */
92         extern char *optarg;                    /* for parsing argv */
93         register int c;                         /* for parsing argv */
94         register char *cp;                      /* for parsing Version */
95
96         verbose = 1;
97
98         /*  handle argument list */
99         while ((c = getopt(argc, argv, "c:d:Df:l:p:s:u:vV")) != -1) {
100                 switch (c) {
101                 case 'l' :
102 #ifdef LDAP_DEBUG
103                         ldap_debug = (int) strtol(optarg, (char **) NULL, 0);
104                         lber_debug = ldap_debug;
105 #endif
106                         break;
107                 case 'd' :
108 #ifdef DEBUG
109                         debug = (int) strtol(optarg, (char **) NULL, 0);
110 #endif
111                         break;
112                 case 's' :
113                         server = strdup(optarg);
114                         break;
115                 case 'c' :
116                         filter_file = strdup(optarg);
117                         break;
118                 case 'f' :
119                         config_file = optarg;
120                         break;
121                 case 'p' :
122                         ldap_port = atoi(optarg);
123                         break;
124                 case 'u' :
125                         default_bind_object = strdup(optarg);
126                         break;
127                 case 'v' :
128                         verbose = 1;    /* this is the default anyways... */
129                         break;
130                 case 'V' :
131                         verbose = 0;
132                         break;
133                 case 'D' :
134                         printf("\n\n  Debug flag values\n\n");
135                         printf("    1  function trace\n");
136                         printf("    2  find() information\n");
137                         printf("    4  group information\n");
138                         printf("    8  mod() information\n");
139                         printf("   16  parsing information\n");
140                         printf("   32  output information\n");
141                         printf("   64  authentication information\n");
142                         printf("  128  initialization information\n\n");
143                         format("These are masks, and may be added to form multiple debug levels.  For example, '-d 35' would perform a function trace, print out information about the find() function, and would print out information about the output routines too.", 75, 2);
144                         exit(0);
145                 default:
146                         fprintf(stderr, "Usage: %s [-c filter-config-file] [-d debug-level] [-l ldap-debug-level] [-s server] [-p port] [-V]\n", argv[0]);
147                         exit(-1);
148                         /* NOTREACHED */
149                 }
150         }
151
152         /* just print the first line of Version[] */
153         cp = strchr(Version, '\t');
154         if (cp != NULL)
155                 *cp = '\0';
156         printf(Version);
157         fflush( stdout );
158
159         initialize_client();
160         initialize_attribute_strings();
161
162         /* now tackle the user's commands */
163         do_commands();
164         /* NOTREACHED */
165 }
166
167 do_commands()
168 {
169         LDAPMessage *mp;                        /* returned by find() */
170         register char *cp;                      /* misc char pointer */
171         register char *ap;                      /* misc char pointer */
172         static char buf[MED_BUF_SIZE];          /* for prompting */
173         static char cmd[MED_BUF_SIZE];          /* holds the command */
174         static char input[MED_BUF_SIZE];        /* buffer for input */
175         extern LDAPMessage *find();
176         extern void purge_group(), add_group(), remove_group(), x_group(),
177                 tidy_up(), list_groups(), list_memberships(), edit();
178         extern char *nextstr();
179
180 #ifdef DEBUG
181         if (debug & D_TRACE)
182                 printf("->do_commands()\n");
183 #endif
184         if (verbose) 
185                 printf("\n  Enter a command.  If you need help, type 'h' or '?' and hit RETURN.\n\n");
186         /* jump here on an interrupt */
187         (void) setjmp(env);
188         for (;;) {
189                 printf("* ");
190                 fflush(stdout);
191                 cp = input;
192 /* Temporary kludge - if cp is null, dumps core under Solaris */
193                 if (cp == NULL)
194                         break;
195                 fetch_buffer(input, sizeof(input), stdin);
196                 if (*input == '\0') {
197                         putchar('\n');
198                         continue;
199                 }
200                 while (isspace(*cp))
201                         cp++;   
202                 ap = cmd;
203                 if (memset(cmd, '\0', sizeof(cmd)) == NULL)
204                         fatal("memset");
205                 while (!isspace(*cp) && (*cp != '\0'))
206                         *ap++ = *cp++;
207                 if (iscom("status"))
208                         status();
209                 else if (iscom("stop") || iscom("quit"))
210                         break;
211                 else if (iscom("cb") || iscom("cd") || iscom("moveto")) {
212                         while (isspace(*cp) && (*cp != '\0')) 
213                                 cp++;
214                         if (!strncasecmp(cp, "base", 4))
215                                 cp += 4;
216                         change_base(BASE_SEARCH, &search_base, nextstr(cp));
217                 }
218                 else if (iscom("memberships"))
219                         (void) list_memberships(nextstr(cp));
220                 else if (iscom("list"))
221                         (void) list_groups(nextstr(cp));
222                 else if (iscom("groupbase"))
223                         change_base(BASE_GROUPS, &group_base, nextstr(cp));
224                 else if (iscom("find") || iscom("display") || iscom("show")) {
225                         cp = nextstr(cp);
226                         if ((mp = find(cp, FALSE)) != NULL) {
227                                 parse_answer(mp);
228                                 print_an_entry();
229                                 ldap_msgfree(mp);
230                         }
231                         else
232                                 printf(" Could not find \"%s\".\n", cp);
233                 }
234 #ifdef UOFM
235                 else if (iscom("vedit") && isatty( 1 )) {
236 #else
237                 else if (iscom("vedit")) {
238 #endif
239                         (void) edit(nextstr(cp));
240                 }
241                 else if (iscom("modify") || iscom("change") || iscom("alter"))
242                         (void) modify(nextstr(cp));
243                 else if (iscom("bind") || iscom("iam"))
244                         (void) auth(nextstr(cp), 0);
245                 else if ((cmd[0] == '?') || iscom("help"))
246                         print_help(nextstr(cp));
247                 else if (iscom("join") || iscom("subscribe")) 
248                         (void) x_group(G_JOIN, nextstr(cp));
249                 else if (iscom("resign") || iscom("unsubscribe"))
250                         (void) x_group(G_RESIGN, nextstr(cp));
251                 else if (!strncasecmp("create", cmd, strlen(cmd)))
252                         add_group(nextstr(cp));
253                 else if (!strncasecmp("remove", cmd, strlen(cmd)))
254                         remove_group(nextstr(cp));
255                 else if (!strncasecmp("purge", cmd, strlen(cmd)))
256                         purge_group(nextstr(cp));
257                 else if (!strncasecmp("verbose", cmd, strlen(cmd))) {
258                         verbose = 1 - verbose;
259                         if (verbose)
260                                 printf("  Verbose mode has been turned on.\n");
261                 }
262                 else if (!strncasecmp("dereference", cmd, strlen(cmd))) {
263                         int deref;
264                         dereference = 1 - dereference;
265                         if (dereference == 1) {
266                                 deref = LDAP_DEREF_ALWAYS;
267                         } else {
268                                 deref = LDAP_DEREF_NEVER;
269                         }
270                         ldap_set_option(ld, LDAP_OPT_DEREF, (void *) &deref);
271                 }
272                 else if (!strncasecmp("tidy", cmd, strlen(cmd)))
273                         tidy_up();
274                 else if (cmd[0] == '\0')
275                         putchar('\n');
276                 else
277                         printf("  Invalid command.  Type \"help commands.\"\n");
278         }
279         printf(" Thank you!\n");
280         
281         ldap_unbind(ld);
282 #ifdef HAVE_KERBEROS
283         destroy_tickets();
284 #endif
285         exit(0);
286         /* NOTREACHED */
287 }
288
289 status()
290 {
291         void printbase();
292         register char **rdns;
293         char *host;
294
295 #ifdef DEBUG
296         if (debug & D_TRACE)
297                 printf("->status()\n");
298 #endif
299         printf("  Current server is %s", server);
300         if ( ld != NULL ) {
301                 char *host = NULL;
302                 
303                 ldap_get_option(ld, LDAP_OPT_HOST_NAME, &host);
304
305                 if (( host != NULL ) && (strcasecmp( host, server ) != 0 )) {
306                         printf( " (%s)", host );
307                 }
308         }
309         putchar( '\n' );
310         printbase("  Search base is ", search_base);
311         printbase("  Group  base is ", group_base);
312         if ( bound_dn != NULL ) {
313                 rdns = ldap_explode_dn(bound_dn, TRUE);
314                 printf("  Bound as \"%s\"\n", *rdns);
315                 ldap_value_free(rdns);
316         } else {
317                 printf("  Bound as Nobody\n" );
318         }
319         printf( "  Verbose mode is %sabled\n", ( verbose ? "en" : "dis" ));
320         if ( ld != NULL ) {
321                 int deref = LDAP_DEREF_NEVER;
322                 ldap_get_option(ld, LDAP_OPT_DEREF, &deref);
323                 printf( "  Aliases are %sbeing dereferenced\n",
324                         ( deref == LDAP_DEREF_ALWAYS ) ? "" : "not" );
325         }
326 }
327
328 change_base(type, base, s)
329 int type;
330 char **base, *s;
331 {
332         register char *cp;                      /* utility pointers */
333         char **rdns;                            /* for parsing */
334         char *output_string;                    /* for nice output */
335         int num_picked;                         /* # of selected base */
336         int j;                                  /* used with num_picked */
337         int i = 1;                              /* index into choices array */
338         int matches;                            /* # of matches found */
339         int rest = 1;                           /* # left to display */
340         char tmp[MED_BUF_SIZE];                 /* temporary buffer */
341         static char *choices[MED_BUF_SIZE];     /* bases from which to choose */
342         static char resp[SMALL_BUF_SIZE];       /* for prompting user */
343         static char buf[MED_BUF_SIZE];
344         void printbase();
345         static char *attrs[] = { "objectClass", NULL };
346         LDAPMessage *mp;                        /* results from a search */
347         LDAPMessage *ep;                        /* for going thru bases */
348         extern char * friendly_name();
349         extern void StrFreeDup();
350         extern void Free();
351
352 #ifdef DEBUG
353         if (debug & D_TRACE)
354                 printf("->change_base(%s, %s)\n", s, s);
355 #endif
356         /*
357          *  If s is NULL we need to prompt the user for an argument.
358          */
359         while (s == NULL) {
360                 if (verbose) {
361                         printf("  You need to specify how the base is to be changed.  Valid choices are:\n");
362                         printf("     ?       - list the choices immediately below this level\n");
363                         printf("     ..      - move up one level in the Directory tree\n");
364                         printf("     root    - move to the root of the Directory tree\n");
365                         printf("     default - move to the default level built into this program\n");
366                         printf("     <entry> - move to the entry specified\n");
367                 }
368                 printf("  Change base to? ");
369                 fflush(stdout);
370                 fetch_buffer(buf, sizeof(buf), stdin);
371                 if ((buf != NULL) && (buf[0] != '\0'))
372                         s = buf;
373         }
374
375         /* set the output string */
376         if (type == BASE_SEARCH)
377                 output_string = "  Search base is now ";
378         else if (type == BASE_GROUPS)
379                 output_string = "  Group base is now ";
380
381         if (!strcasecmp(s, "root")) {
382                 StrFreeDup(base, NULL);
383                 printbase("  Search base is ", *base);
384                 return;
385         }
386
387         /*
388          *  User wants to ascend one level in the LDAP tree.
389          *  Easy:  Just strip off the first element of the
390          *  current search base, unless it's the root, in
391          *  which case we just do nothing.
392          */
393         if (!strcasecmp(s, "..")) {
394                 if (*base == NULL) {
395                         printf("  You are already at the root\n");
396                         return;
397                 }
398                 cp = strchr(*base, '=');
399                 cp++;
400                 /*
401                  *  If there isn't a second "=" in the base, then this was
402                  *  a one element base, and so now it should be NULL.
403                  */
404                 if ((cp = strchr(cp, '=')) == NULL)
405                         StrFreeDup(base, NULL);
406                 else {
407                         /*
408                          *  Back up to the start of this
409                          *
410                          *      attr=value
411                          *
412                          *  sequence now that 'cp' is pointing to the '='.
413                          */
414                         while(!isspace(*cp))
415                                 cp--;
416                         cp++;
417                         /*
418                          *  Goofy, but need to do it this way since both *base
419                          *  and cp point into the same chunk of memory, and
420                          *  we want to free *base, but keep part of it around.
421                          */
422                         cp = strdup(cp);
423                         StrFreeDup(base, cp);
424                         Free(cp);
425                 }
426                 printbase(output_string, *base);
427                 return;
428         }
429
430         /* user wants to see what is directly below this level */
431         if (*s == '?') {
432                 /*
433                  *  Fetch the list of entries directly below this level.
434                  *  Once we have the list, we will print it for the user, one
435                  *  screenful at a time.  At the end of each screen, we ask
436                  *  the user if they want to see more.  They can also just
437                  *  type a number at that point too.
438                  */
439                 if (ldap_search_s(ld, *base, LDAP_SCOPE_ONELEVEL, "(|(objectClass=quipuNonLeafObject)(objectClass=externalNonLeafObject))", attrs, FALSE, &mp) != LDAP_SUCCESS) {
440                         int ld_errno = 0;
441                         ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
442                         if ((ld_errno == LDAP_TIMELIMIT_EXCEEDED) ||
443                             (ld_errno == LDAP_SIZELIMIT_EXCEEDED)) {
444                                 if (verbose) {
445                                         printf("  Your query was too general and a limit was exceeded.  The results listed\n");
446                                         printf("  are not complete.  You may want to try again with a more refined query.\n\n");
447                                 }
448                                 else
449                                         printf("  Time or size limit exceeded.  Partial results follow.\n\n");
450                         } else {
451                                 ldap_perror(ld, "ldap_search_s");
452                                 return;
453                         }
454                 }
455                 if ((matches = ldap_count_entries(ld, mp)) < 1) {
456                         printf("  There is nothing below this level.\n");
457                         (void) ldap_msgfree(mp);
458                         return;
459                 }
460                 num_picked = 0;
461                 printf(" There are %d choices:\n", matches);
462                 for (ep = ldap_first_entry(ld, mp); ep != NULL; ep = ldap_next_entry(ld, ep)) {
463                         /*
464                          *  Put the last component of the DN into 'lastDN'.
465                          *  If we are at the root level, convert any country
466                          *  codes to recognizable names for printing.
467                          */
468                         choices[i] = ldap_get_dn(ld, ep);
469                         rdns = ldap_explode_dn(choices[i], TRUE);
470                         printf(" %2d. %s\n", i, friendly_name(*rdns));
471                         (void) ldap_value_free(rdns);
472                         i++;
473                         if ((rest++ > (lpp - 3)) && (i < matches)) {
474                                 printf("More? ");
475                                 fflush(stdout);
476                                 fetch_buffer(resp, sizeof(resp), stdin);
477                                 if ((resp[0] == 'n') || (resp[0] == 'N'))
478                                         break;
479                                 else if (((num_picked = atoi(resp)) != 0) && (num_picked < i))
480                                         break;
481                                 rest = 1;
482                         }
483                 }
484                 for (;;) {
485                         if (num_picked != 0) {
486                                 j = num_picked;
487                                 num_picked = 0;
488                         }
489                         else {
490                                 printf(" Which number? ");
491                                 fflush(stdout);
492                                 fetch_buffer(resp, sizeof(resp), stdin);
493                                 j = atoi(resp);
494                         }
495                         if (j == 0) {
496                                 (void) ldap_msgfree(mp);
497                                 for (i = 0; i < matches; i++)
498                                         Free(choices[i]);
499                                 return;
500                         }
501                         if ((j < 1) || (j >= i))
502                                 printf(" Invalid number\n");
503                         else {
504                                 StrFreeDup(base, choices[j]);
505                                 printbase(output_string, *base);
506                                 (void) ldap_msgfree(mp);
507                                 for (i = 0; choices[i] != NULL; i++)
508                                         Free(choices[i]);
509                                 return;
510                         }
511                 }
512         }
513         /* set the search base back to the original default value */
514         else if (!strcasecmp(s, "default")) {
515                 if (type == BASE_SEARCH)
516                         StrFreeDup(base, NULL);
517                 else if (type == BASE_GROUPS)
518                         StrFreeDup(base, UD_WHERE_GROUPS_ARE_CREATED);
519                 printbase(output_string, *base);
520         }
521         /* they typed in something -- see if it is legit */
522         else {
523                 /* user cannot do something like 'cb 33' */
524                 if (atoi(s) != 0) {
525                         printf("  \"%s\" is not a valid search base\n", s);
526                         printf("  Base unchanged.\n");
527                         printf("  Try using 'cb ?'\n");
528                         return;
529                 }
530                 /* was it a fully-specified DN? */
531                 if (vrfy(s)) {
532                         StrFreeDup(base, s);
533                         printbase(output_string, *base);
534                         return;
535                 }
536                 /* was it a RDN relative to the current base? */
537                 sprintf(tmp, "ou=%s, %s", s, *base);
538                 if (vrfy(tmp)) {
539                         StrFreeDup(base, tmp);
540                         printbase(output_string, *base);
541                         return;
542                 }
543                 printf("  \"%s\" is not a valid base\n  Base unchanged.\n", s);
544         }
545 }
546
547 void initialize_client()
548 {
549         FILE *fp;                               /* for config file */
550         static char buffer[MED_BUF_SIZE];       /* for input */
551         struct passwd *pw;                      /* for getting the home dir */
552         register char *cp;                      /* for fiddling with buffer */
553         char *term;                             /* for tty set-up */
554         char *config;                           /* config file to use */
555         static char bp[1024];                   /* for tty set-up */
556         extern RETSIGTYPE attn();                       /* ^C signal handler */
557         extern char *getenv();
558         extern void Free();
559
560 #ifdef DEBUG
561         if (debug & D_TRACE)
562                 printf("->initialize_client()\n");
563 #endif
564         /*
565          *  A per-user config file has precedence over any system-wide
566          *  config file, if one exists.
567          */
568 #ifdef HAVE_GETPWUID_H
569         if ((pw = getpwuid((uid_t) geteuid())) == (struct passwd *) NULL)
570                 config = config_file;
571         else {
572                 if (pw->pw_dir == NULL)
573                         config = config_file;
574                 else {
575                         sprintf(buffer, "%s/%s", pw->pw_dir,
576                             UD_USER_CONFIG_FILE);
577                         if (access(buffer, R_OK) == 0)
578                                 config = buffer;
579                         else
580                                 config = config_file;
581                 }
582         }
583 #endif /* getpwduid() */
584 #ifdef DEBUG
585         if (debug & D_INITIALIZE)
586                 printf("Using config file %s\n", config);
587 #endif
588
589         /*
590          *  If there is a config file, read it.
591          *
592          *  Could have lines that look like this:
593          *
594          *      server <ip-address or domain-name>
595          *      base   <default search base>
596          *      groupbase <default place where groups are created>
597          *
598          */
599         if ((fp = fopen(config, "r")) != NULL) {
600                 while (fgets(buffer, sizeof(buffer), fp) != NULL) {
601                         buffer[strlen(buffer) - 1] = '\0';
602                         if (!strncasecmp(buffer, "server", 6)) {
603                                 if (server != NULL)
604                                         continue;
605                                 cp = buffer + 6;
606                                 while (isspace(*cp))
607                                         cp++;
608                                 if ((*cp == '\0') || (*cp == '\n'))
609                                         continue;
610                                 server = strdup(cp);
611                         } 
612                         else if (!strncasecmp(buffer, "host", 4)) {
613                                 if (server != NULL)
614                                         continue;
615                                 cp = buffer + 4;
616                                 while (isspace(*cp))
617                                         cp++;
618                                 if ((*cp == '\0') || (*cp == '\n'))
619                                         continue;
620                                 server = strdup(cp);
621                         }
622                         else if (!strncasecmp(buffer, "base", 4)) {
623                                 cp = buffer + 4;
624                                 while (isspace(*cp))
625                                         cp++;
626                                 if ((*cp == '\0') || (*cp == '\n'))
627                                         continue;
628                                 search_base = strdup(cp);
629                         }
630                         else if (!strncasecmp(buffer, "groupbase", 9)) {
631                                 cp = buffer + 9;
632                                 while (isspace(*cp))
633                                         cp++;
634                                 if ((*cp == '\0') || (*cp == '\n'))
635                                         continue;
636                                 group_base = strdup(cp);
637                         }
638                         else
639                                 fprintf(stderr, "?? -> %s\n", buffer);
640                 }
641         }
642         if (group_base == NULL)
643                 group_base = strdup(UD_WHERE_GROUPS_ARE_CREATED);
644
645         /*
646          *  Set up our LDAP connection.  The values of retry and timeout
647          *  are meaningless since we will immediately be doing a null bind
648          *  because we want to be sure to use TCP, not UDP.
649          */
650         if ((ld = ldap_open(server, ldap_port)) == NULL) {
651                 fprintf(stderr, "  The LDAP Directory is temporarily unavailable.  Please try again later.\n");
652                 exit(0);
653                 /* NOTREACHED */
654         }
655         if (ldap_bind_s(ld, (char *) default_bind_object, NULL,
656             LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) {
657                 int ld_errno = 0;
658                 ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ld_errno);
659
660                 fprintf(stderr, "  The LDAP Directory is temporarily unavailable.  Please try again later.\n");
661                 if (ld_errno != LDAP_UNAVAILABLE)
662                         ldap_perror(ld, "  ldap_bind_s");
663                 exit(0);
664                 /* NOTREACHED */
665         }
666         {
667                 int deref = LDAP_DEREF_ALWAYS;
668                 ldap_set_option(ld, LDAP_OPT_DEREF, (void *) &deref);
669         }
670         bind_status = UD_NOT_BOUND;
671         if ( default_bind_object != NULL ) {
672                 bound_dn = strdup(default_bind_object);
673         } else {
674                 bound_dn = NULL;
675         }
676
677         /* enabled local caching of ldap results, 15 minute lifetime */
678 #ifdef DOS
679         ldap_enable_cache( ld, 60 * 15, 100 * 1024 );   /* 100k max memory */
680 #else /* DOS */
681         ldap_enable_cache( ld, 60 * 15, 0 );            /* no memory limit */
682 #endif /* DOS */
683
684         /* initialize the search filters */
685         if ((lfdp = ldap_init_getfilter(filter_file)) == NULL) {
686                 fprintf(stderr, "  Problem with ldap_init_getfilter\n");
687                 fatal(filter_file);
688                 /*NOTREACHED*/
689         }
690
691         /* terminal initialization stuff goes here */
692         lpp = DEFAULT_TTY_HEIGHT;
693         col_size = DEFAULT_TTY_WIDTH;
694
695         (void) SIGNAL (SIGINT, attn);
696
697 #ifndef NO_TERMCAP
698         {
699         struct winsize win;                     /* for tty set-up */
700         extern RETSIGTYPE chwinsz();            /* WINSZ signal handler */
701
702         if (((term = getenv("TERM")) == NULL) || (tgetent(bp, term) <= 0))
703                 return;
704         else {
705 #ifdef TIOCGWINSZ
706                 if (ioctl(fileno(stdout), TIOCGWINSZ, &win) < 0) {
707                         lpp = tgetnum("li");
708                         col_size = tgetnum("co");
709                 } else
710 #endif
711                 {
712                         if ((lpp = win.ws_row) == 0)
713                                 lpp = tgetnum("li");
714                         if ((col_size = win.ws_col) == 0)
715                                 col_size = tgetnum("co");
716                         if ((lpp <= 0) || tgetflag("hc"))
717                                 lpp = DEFAULT_TTY_HEIGHT;
718                         if ((col_size <= 0) || tgetflag("hc"))
719                                 col_size = DEFAULT_TTY_WIDTH;
720                 }
721         }
722         (void) SIGNAL (SIGWINCH, chwinsz);
723
724         }
725 #endif
726 }
727
728 RETSIGTYPE attn()
729 {
730         fflush(stderr);
731         fflush(stdout);
732         printf("\n\n  INTERRUPTED!\n");
733
734         (void) SIGNAL (SIGINT, attn);
735
736         longjmp(env, 1);
737 }
738
739 #ifndef NO_TERMCAP
740 RETSIGTYPE chwinsz() 
741 {
742         struct winsize win;
743
744         (void) SIGNAL (SIGWINCH, SIG_IGN);
745         if (ioctl(fileno(stdout), TIOCGWINSZ, &win) != -1) {
746                 if (win.ws_row != 0)
747                         lpp = win.ws_row;
748                 if (win.ws_col != 0)
749                         col_size = win.ws_col;
750         }
751
752         (void) SIGNAL (SIGWINCH, chwinsz);
753 }
754 #endif