1 /* result.c - shell backend result reading function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2012 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(
54 /* read in the result and send it along */
55 buf = (char *) ch_malloc( BUFSIZ );
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 );
69 Debug( LDAP_DEBUG_SHELL, "shell search reading line (%s)\n",
72 /* ignore lines beginning with # (LDIFv1 comments) */
77 /* ignore lines beginning with DEBUG: */
78 if ( strncasecmp( line, "DEBUG:", 6 ) == 0 ) {
83 while ( bp + len + 1 - buf > bsize ) {
84 size_t offset = bp - buf;
86 buf = (char *) ch_realloc( buf, bsize );
92 /* line marked the end of an entry or result */
93 if ( *line == '\n' ) {
94 if ( strncasecmp( buf, "RESULT", 6 ) == 0 ) {
98 if ( (rs->sr_entry = str2entry( buf )) == NULL ) {
99 Debug( LDAP_DEBUG_ANY, "str2entry(%s) failed\n",
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 );
112 (void) str2result( buf, &rs->sr_err, (char **)&rs->sr_matched, (char **)&rs->sr_text );
114 /* otherwise, front end will send this result */
115 if ( rs->sr_err != 0 || op->o_tag != LDAP_REQ_BIND ) {
116 send_ldap_result( op, rs );
121 return( rs->sr_err );
132 for ( i = 0; be->be_suffix[i].bv_val != NULL; i++ ) {
133 fprintf( fp, "suffix: %s\n", be->be_suffix[i].bv_val );