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