]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/bind.c
0acca761ce517394b3ad9b655d8a3c311c03129f
[openldap] / servers / slapd / back-shell / bind.c
1 /* bind.c - shell backend bind function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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     Operation           *op,
21     SlapReply           *rs )
22 {
23         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
24         AttributeDescription *entry = slap_schema.si_ad_entry;
25         Entry e;
26         FILE                    *rfp, *wfp;
27         int                     rc;
28
29         if ( si->si_bind == NULL ) {
30                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
31                     "bind not implemented" );
32                 return( -1 );
33         }
34
35         e.e_id = NOID;
36         e.e_name = op->o_req_dn;
37         e.e_nname = op->o_req_ndn;
38         e.e_attrs = NULL;
39         e.e_ocflags = 0;
40         e.e_bv.bv_len = 0;
41         e.e_bv.bv_val = NULL;
42         e.e_private = NULL;
43
44         if ( ! access_allowed( op, &e,
45                 entry, NULL, ACL_AUTH, NULL ) )
46         {
47                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
48                 return -1;
49         }
50
51         if ( (op->o_private = (void *) forkandexec( si->si_bind, &rfp, &wfp ))
52             == (void *) -1 ) {
53                 send_ldap_error( op, rs, LDAP_OTHER,
54                     "could not fork/exec" );
55                 return( -1 );
56         }
57
58         /* write out the request to the bind process */
59         fprintf( wfp, "BIND\n" );
60         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
61         print_suffixes( wfp, op->o_bd );
62         fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
63         fprintf( wfp, "method: %d\n", op->oq_bind.rb_method );
64         fprintf( wfp, "credlen: %lu\n", op->oq_bind.rb_cred.bv_len );
65         fprintf( wfp, "cred: %s\n", op->oq_bind.rb_cred.bv_val ); /* XXX */
66         fclose( wfp );
67
68         /* read in the results and send them along */
69         rc = read_and_send_results( op, rs, rfp );
70         fclose( rfp );
71
72         return( rc );
73 }