Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-shell / result.c
blobd5cb12292a6161d2e72a9a0b09fef7091f9d54a7
1 /* result.c - shell backend result reading function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-shell/result.c,v 1.23.2.4 2008/07/08 21:06:12 quanah Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
26 /* ACKNOWLEDGEMENTS:
27 * This work was originally developed by the University of Michigan
28 * (as part of U-MICH LDAP).
31 #include "portable.h"
33 #include <stdio.h>
35 #include <ac/errno.h>
36 #include <ac/string.h>
37 #include <ac/socket.h>
38 #include <ac/unistd.h>
40 #include "slap.h"
41 #include "shell.h"
43 int
44 read_and_send_results(
45 Operation *op,
46 SlapReply *rs,
47 FILE *fp )
49 int bsize, len;
50 char *buf, *bp;
51 char line[BUFSIZ];
52 char ebuf[128];
54 /* read in the result and send it along */
55 buf = (char *) ch_malloc( BUFSIZ );
56 buf[0] = '\0';
57 bsize = BUFSIZ;
58 bp = buf;
59 while ( !feof(fp) ) {
60 errno = 0;
61 if ( fgets( line, sizeof(line), fp ) == NULL ) {
62 if ( errno == EINTR ) continue;
64 Debug( LDAP_DEBUG_ANY, "shell: fgets failed: %s (%d)\n",
65 AC_STRERROR_R(errno, ebuf, sizeof ebuf), errno, 0 );
66 break;
69 Debug( LDAP_DEBUG_SHELL, "shell search reading line (%s)\n",
70 line, 0, 0 );
72 /* ignore lines beginning with # (LDIFv1 comments) */
73 if ( *line == '#' ) {
74 continue;
77 /* ignore lines beginning with DEBUG: */
78 if ( strncasecmp( line, "DEBUG:", 6 ) == 0 ) {
79 continue;
82 len = strlen( line );
83 while ( bp + len + 1 - buf > bsize ) {
84 size_t offset = bp - buf;
85 bsize += BUFSIZ;
86 buf = (char *) ch_realloc( buf, bsize );
87 bp = &buf[offset];
89 strcpy( bp, line );
90 bp += len;
92 /* line marked the end of an entry or result */
93 if ( *line == '\n' ) {
94 if ( strncasecmp( buf, "RESULT", 6 ) == 0 ) {
95 break;
98 if ( (rs->sr_entry = str2entry( buf )) == NULL ) {
99 Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n",
100 buf, 0, 0 );
101 } else {
102 rs->sr_attrs = op->oq_search.rs_attrs;
103 rs->sr_flags = REP_ENTRY_MODIFIABLE;
104 send_search_entry( op, rs );
105 entry_free( rs->sr_entry );
108 bp = buf;
111 (void) str2result( buf, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text );
113 /* otherwise, front end will send this result */
114 if ( rs->sr_err != 0 || op->o_tag != LDAP_REQ_BIND ) {
115 send_ldap_result( op, rs );
118 free( buf );
120 return( rs->sr_err );
123 void
124 print_suffixes(
125 FILE *fp,
126 Backend *be
129 int i;
131 for ( i = 0; be->be_suffix[i].bv_val != NULL; i++ ) {
132 fprintf( fp, "suffix: %s\n", be->be_suffix[i].bv_val );