1 /* result.c - sock backend result reading function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-sock/result.c,v 1.3.2.2 2008/07/08 21:05:03 quanah Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2007-2008 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>.
17 * This work was initially developed by Brian Candler for inclusion
18 * in OpenLDAP Software.
26 #include <ac/string.h>
27 #include <ac/socket.h>
28 #include <ac/unistd.h>
31 #include "back-sock.h"
34 * FIXME: make a RESULT section compulsory from the socket response.
35 * Otherwise, a partial/aborted response is treated as 'success'.
36 * This is a divergence from the back-shell protocol, but makes things
41 sock_read_and_send_results(
51 /* read in the result and send it along */
52 buf
= (char *) ch_malloc( BUFSIZ
);
58 if ( fgets( line
, sizeof(line
), fp
) == NULL
) {
59 if ( errno
== EINTR
) continue;
61 Debug( LDAP_DEBUG_ANY
, "sock: fgets failed: %s (%d)\n",
62 AC_STRERROR_R(errno
, ebuf
, sizeof ebuf
), errno
, 0 );
66 Debug( LDAP_DEBUG_SHELL
, "sock search reading line (%s)\n",
69 /* ignore lines beginning with # (LDIFv1 comments) */
74 /* ignore lines beginning with DEBUG: */
75 if ( strncasecmp( line
, "DEBUG:", 6 ) == 0 ) {
80 while ( bp
+ len
+ 1 - buf
> bsize
) {
81 size_t offset
= bp
- buf
;
83 buf
= (char *) ch_realloc( buf
, bsize
);
89 /* line marked the end of an entry or result */
90 if ( *line
== '\n' ) {
91 if ( strncasecmp( buf
, "RESULT", 6 ) == 0 ) {
95 if ( (rs
->sr_entry
= str2entry( buf
)) == NULL
) {
96 Debug( LDAP_DEBUG_ANY
, "str2entry(%s) failed\n",
99 rs
->sr_attrs
= op
->oq_search
.rs_attrs
;
100 rs
->sr_flags
= REP_ENTRY_MODIFIABLE
;
101 send_search_entry( op
, rs
);
102 entry_free( rs
->sr_entry
);
108 (void) str2result( buf
, &rs
->sr_err
, (char **)&rs
->sr_matched
, (char **)&rs
->sr_text
);
110 /* otherwise, front end will send this result */
111 if ( rs
->sr_err
!= 0 || op
->o_tag
!= LDAP_REQ_BIND
) {
112 send_ldap_result( op
, rs
);
117 return( rs
->sr_err
);
128 for ( i
= 0; be
->be_suffix
[i
].bv_val
!= NULL
; i
++ ) {
129 fprintf( fp
, "suffix: %s\n", be
->be_suffix
[i
].bv_val
);
140 if ( conn
== NULL
) return;
142 if( si
->si_extensions
& SOCK_EXT_BINDDN
) {
143 fprintf( fp
, "binddn: %s\n",
144 conn
->c_dn
.bv_len
? conn
->c_dn
.bv_val
: "" );
146 if( si
->si_extensions
& SOCK_EXT_PEERNAME
) {
147 fprintf( fp
, "peername: %s\n",
148 conn
->c_peer_name
.bv_len
? conn
->c_peer_name
.bv_val
: "" );
150 if( si
->si_extensions
& SOCK_EXT_SSF
) {
151 fprintf( fp
, "ssf: %d\n", conn
->c_ssf
);