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