]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/bind.c
3a9824729dda58ee2dcfaa5cbef591950c74e4a8
[openldap] / servers / slapd / back-shell / bind.c
1 /* bind.c - shell backend bind function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2017 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26 /* ACKNOWLEDGEMENTS:
27  * This work was originally developed by the University of Michigan
28  * (as part of U-MICH LDAP).
29  */
30
31 #include "portable.h"
32
33 #include <stdio.h>
34
35 #include <ac/socket.h>
36 #include <ac/string.h>
37
38 #include "slap.h"
39 #include "shell.h"
40
41 int
42 shell_back_bind(
43     Operation           *op,
44     SlapReply           *rs )
45 {
46         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
47         AttributeDescription *entry = slap_schema.si_ad_entry;
48         Entry e;
49         FILE                    *rfp, *wfp;
50         int                     rc;
51
52         /* allow rootdn as a means to auth without the need to actually
53          * contact the proxied DSA */
54         switch ( be_rootdn_bind( op, rs ) ) {
55         case SLAP_CB_CONTINUE:
56                 break;
57
58         default:
59                 return rs->sr_err;
60         }
61
62         if ( si->si_bind == NULL ) {
63                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
64                     "bind not implemented" );
65                 return( -1 );
66         }
67
68         e.e_id = NOID;
69         e.e_name = op->o_req_dn;
70         e.e_nname = op->o_req_ndn;
71         e.e_attrs = NULL;
72         e.e_ocflags = 0;
73         e.e_bv.bv_len = 0;
74         e.e_bv.bv_val = NULL;
75         e.e_private = NULL;
76
77         if ( ! access_allowed( op, &e,
78                 entry, NULL, ACL_AUTH, NULL ) )
79         {
80                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
81                 return -1;
82         }
83
84         if ( forkandexec( si->si_bind, &rfp, &wfp ) == (pid_t)-1 ) {
85                 send_ldap_error( op, rs, LDAP_OTHER,
86                     "could not fork/exec" );
87                 return( -1 );
88         }
89
90         /* write out the request to the bind process */
91         fprintf( wfp, "BIND\n" );
92         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
93         print_suffixes( wfp, op->o_bd );
94         fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
95         fprintf( wfp, "method: %d\n", op->oq_bind.rb_method );
96         fprintf( wfp, "credlen: %lu\n", op->oq_bind.rb_cred.bv_len );
97         fprintf( wfp, "cred: %s\n", op->oq_bind.rb_cred.bv_val ); /* XXX */
98         fclose( wfp );
99
100         /* read in the results and send them along */
101         rc = read_and_send_results( op, rs, rfp );
102         fclose( rfp );
103
104         return( rc );
105 }