]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/bind.c
include portable.h
[openldap] / servers / slapd / back-shell / bind.c
1 /* bind.c - shell backend bind function */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include "slap.h"
10 #include "shell.h"
11
12 int
13 shell_back_bind(
14     Backend             *be,
15     Connection          *conn,
16     Operation           *op,
17     char                *dn,
18     int                 method,
19     struct berval       *cred
20 )
21 {
22         struct shellinfo        *si = (struct shellinfo *) be->be_private;
23         FILE                    *rfp, *wfp;
24         int                     rc;
25
26         if ( si->si_bind == NULL ) {
27                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
28                     "bind not implemented" );
29                 return;
30         }
31
32         if ( (op->o_private = forkandexec( si->si_bind, &rfp, &wfp ))
33             == -1 ) {
34                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
35                     "could not fork/exec" );
36                 return;
37         }
38
39         /* write out the request to the bind process */
40         fprintf( wfp, "BIND\n" );
41         fprintf( wfp, "msgid: %d\n", op->o_msgid );
42         print_suffixes( wfp, be );
43         fprintf( wfp, "dn: %s\n", dn );
44         fprintf( wfp, "method: %d\n", method );
45         fprintf( wfp, "credlen: %d\n", cred->bv_len );
46         fprintf( wfp, "cred: %s\n", cred->bv_val ); /* XXX */
47         fclose( wfp );
48
49         /* read in the results and send them along */
50         rc = read_and_send_results( be, conn, op, rfp, NULL, 0 );
51         fclose( rfp );
52
53         return( rc );
54 }