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