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