]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/result.c
Don't reeval expression
[openldap] / servers / slapd / back-shell / result.c
1 /* result.c - shell backend result reading function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/errno.h>
13 #include <ac/string.h>
14 #include <ac/socket.h>
15 #include <ac/unistd.h>
16
17 #include "slap.h"
18 #include "shell.h"
19
20 int
21 read_and_send_results(
22     Backend     *be,
23     Connection  *conn,
24     Operation   *op,
25     FILE        *fp,
26     AttributeName *attrs,
27     int         attrsonly
28 )
29 {
30         int     bsize, len;
31         char    *buf, *bp;
32         char    line[BUFSIZ];
33         Entry   *e;
34         int     err;
35         char    *matched, *info;
36
37         /* read in the result and send it along */
38         buf = (char *) ch_malloc( BUFSIZ );
39         buf[0] = '\0';
40         bsize = BUFSIZ;
41         bp = buf;
42         while ( !feof(fp) ) {
43                 errno = 0;
44                 if ( fgets( line, sizeof(line), fp ) == NULL ) {
45                         if ( errno == EINTR ) continue;
46
47                         Debug( LDAP_DEBUG_ANY, "shell: fgets failed: %s (%d)\n",
48                                 strerror(errno), errno, 0 ); 
49                         break;
50                 }
51
52                 Debug( LDAP_DEBUG_SHELL, "shell search reading line (%s)\n",
53                     line, 0, 0 );
54
55                 /* ignore lines beginning with # (LDIFv1 comments) */
56                 if ( *line == '#' ) {
57                         continue;
58                 }
59
60                 /* ignore lines beginning with DEBUG: */
61                 if ( strncasecmp( line, "DEBUG:", 6 ) == 0 ) {
62                         continue;
63                 }
64
65                 len = strlen( line );
66                 while ( bp + len - buf > bsize ) {
67                         size_t offset = bp - buf;
68                         bsize += BUFSIZ;
69                         buf = (char *) ch_realloc( buf, bsize );
70                         bp = &buf[offset];
71                 }
72                 strcpy( bp, line );
73                 bp += len;
74
75                 /* line marked the end of an entry or result */
76                 if ( *line == '\n' ) {
77                         if ( strncasecmp( buf, "RESULT", 6 ) == 0 ) {
78                                 break;
79                         }
80
81                         if ( (e = str2entry( buf )) == NULL ) {
82                                 Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n",
83                                     buf, 0, 0 );
84                         } else {
85                                 send_search_entry( be, conn, op, e,
86                                         attrs, attrsonly, NULL );
87                                 entry_free( e );
88                         }
89
90                         bp = buf;
91                 }
92         }
93         (void) str2result( buf, &err, &matched, &info );
94
95         /* otherwise, front end will send this result */
96         if ( err != 0 || op->o_tag != LDAP_REQ_BIND ) {
97                 send_ldap_result( conn, op, err, matched, info, NULL, NULL );
98         }
99
100         free( buf );
101
102         return( err );
103 }
104
105 void
106 print_suffixes(
107     FILE        *fp,
108     Backend     *be
109 )
110 {
111         int     i;
112
113         for ( i = 0; be->be_suffix[i].bv_val != NULL; i++ ) {
114                 fprintf( fp, "suffix: %s\n", be->be_suffix[i].bv_val );
115         }
116 }