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