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