1 /* result.c - shell backend result reading function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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.
27 * This work was originally developed by the University of Michigan
28 * (as part of U-MICH LDAP).
36 #include <ac/string.h>
37 #include <ac/socket.h>
38 #include <ac/unistd.h>
44 read_and_send_results(
53 /* read in the result and send it along */
54 buf = (char *) ch_malloc( BUFSIZ );
60 if ( fgets( line, sizeof(line), fp ) == NULL ) {
61 if ( errno == EINTR ) continue;
63 Debug( LDAP_DEBUG_ANY, "shell: fgets failed: %s (%d)\n",
64 strerror(errno), errno, 0 );
68 Debug( LDAP_DEBUG_SHELL, "shell search reading line (%s)\n",
71 /* ignore lines beginning with # (LDIFv1 comments) */
76 /* ignore lines beginning with DEBUG: */
77 if ( strncasecmp( line, "DEBUG:", 6 ) == 0 ) {
82 while ( bp + len - buf > bsize ) {
83 size_t offset = bp - buf;
85 buf = (char *) ch_realloc( buf, bsize );
91 /* line marked the end of an entry or result */
92 if ( *line == '\n' ) {
93 if ( strncasecmp( buf, "RESULT", 6 ) == 0 ) {
97 if ( (rs->sr_entry = str2entry( buf )) == NULL ) {
98 Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n",
101 rs->sr_attrs = op->oq_search.rs_attrs;
102 send_search_entry( op, rs );
103 entry_free( rs->sr_entry );
109 (void) str2result( buf, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text );
111 /* otherwise, front end will send this result */
112 if ( rs->sr_err != 0 || op->o_tag != LDAP_REQ_BIND ) {
113 send_ldap_result( op, rs );
118 return( rs->sr_err );
129 for ( i = 0; be->be_suffix[i].bv_val != NULL; i++ ) {
130 fprintf( fp, "suffix: %s\n", be->be_suffix[i].bv_val );