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