]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/bind.c
Update forkandexec() prototype.
[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     struct berval       *cred,
21         char            **edn
22 )
23 {
24         struct shellinfo        *si = (struct shellinfo *) be->be_private;
25         FILE                    *rfp, *wfp;
26         int                     rc;
27
28         *edn = NULL;
29
30         if ( si->si_bind == NULL ) {
31                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
32                     "bind not implemented" );
33                 return( -1 );
34         }
35
36         if ( (op->o_private = (void *) forkandexec( si->si_bind, &rfp, &wfp ))
37             == (void *) -1 ) {
38                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
39                     "could not fork/exec" );
40                 return( -1 );
41         }
42
43         /* write out the request to the bind process */
44         fprintf( wfp, "BIND\n" );
45         fprintf( wfp, "msgid: %ld\n", op->o_msgid );
46         print_suffixes( wfp, be );
47         fprintf( wfp, "dn: %s\n", dn );
48         fprintf( wfp, "method: %d\n", method );
49         fprintf( wfp, "credlen: %lu\n", cred->bv_len );
50         fprintf( wfp, "cred: %s\n", cred->bv_val ); /* XXX */
51         fclose( wfp );
52
53         /* read in the results and send them along */
54         rc = read_and_send_results( be, conn, op, rfp, NULL, 0 );
55         fclose( rfp );
56
57         return( rc );
58 }