xref: /netbsd-src/external/bsd/openldap/dist/servers/slapd/back-sock/bind.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: bind.c,v 1.1.1.4 2014/05/28 09:58:51 tron Exp $	*/
2 
3 /* bind.c - sock backend bind function */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6  *
7  * Copyright 2007-2014 The OpenLDAP Foundation.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by Brian Candler for inclusion
20  * in OpenLDAP Software.
21  */
22 
23 #include "portable.h"
24 
25 #include <stdio.h>
26 
27 #include <ac/socket.h>
28 #include <ac/string.h>
29 
30 #include "slap.h"
31 #include "back-sock.h"
32 
33 int
34 sock_back_bind(
35     Operation		*op,
36     SlapReply		*rs )
37 {
38 	struct sockinfo	*si = (struct sockinfo *) op->o_bd->be_private;
39 	AttributeDescription *entry = slap_schema.si_ad_entry;
40 	Entry e;
41 	FILE			*fp;
42 	int			rc;
43 
44 	e.e_id = NOID;
45 	e.e_name = op->o_req_dn;
46 	e.e_nname = op->o_req_ndn;
47 	e.e_attrs = NULL;
48 	e.e_ocflags = 0;
49 	e.e_bv.bv_len = 0;
50 	e.e_bv.bv_val = NULL;
51 	e.e_private = NULL;
52 
53 	if ( ! access_allowed( op, &e,
54 		entry, NULL, ACL_AUTH, NULL ) )
55 	{
56 		send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
57 		return -1;
58 	}
59 
60 	if ( (fp = opensock( si->si_sockpath )) == NULL ) {
61 		send_ldap_error( op, rs, LDAP_OTHER,
62 		    "could not open socket" );
63 		return( -1 );
64 	}
65 
66 	/* write out the request to the bind process */
67 	fprintf( fp, "BIND\n" );
68 	fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
69 	sock_print_conn( fp, op->o_conn, si );
70 	sock_print_suffixes( fp, op->o_bd );
71 	fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
72 	fprintf( fp, "method: %d\n", op->oq_bind.rb_method );
73 	fprintf( fp, "credlen: %lu\n", op->oq_bind.rb_cred.bv_len );
74 	fprintf( fp, "cred: %s\n", op->oq_bind.rb_cred.bv_val ); /* XXX */
75 	fprintf( fp, "\n" );
76 
77 	/* read in the results and send them along */
78 	rc = sock_read_and_send_results( op, rs, fp );
79 	fclose( fp );
80 
81 	return( rc );
82 }
83