Back to index

openldap  2.4.31
bind.c
Go to the documentation of this file.
00001 /* bind.c - sock backend bind function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2007-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS:
00017  * This work was initially developed by Brian Candler for inclusion
00018  * in OpenLDAP Software.
00019  */
00020 
00021 #include "portable.h"
00022 
00023 #include <stdio.h>
00024 
00025 #include <ac/socket.h>
00026 #include <ac/string.h>
00027 
00028 #include "slap.h"
00029 #include "back-sock.h"
00030 
00031 int
00032 sock_back_bind(
00033     Operation        *op,
00034     SlapReply        *rs )
00035 {
00036        struct sockinfo      *si = (struct sockinfo *) op->o_bd->be_private;
00037        AttributeDescription *entry = slap_schema.si_ad_entry;
00038        Entry e;
00039        FILE                 *fp;
00040        int                  rc;
00041 
00042        e.e_id = NOID;
00043        e.e_name = op->o_req_dn;
00044        e.e_nname = op->o_req_ndn;
00045        e.e_attrs = NULL;
00046        e.e_ocflags = 0;
00047        e.e_bv.bv_len = 0;
00048        e.e_bv.bv_val = NULL;
00049        e.e_private = NULL;
00050 
00051        if ( ! access_allowed( op, &e,
00052               entry, NULL, ACL_AUTH, NULL ) )
00053        {
00054               send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
00055               return -1;
00056        }
00057 
00058        if ( (fp = opensock( si->si_sockpath )) == NULL ) {
00059               send_ldap_error( op, rs, LDAP_OTHER,
00060                   "could not open socket" );
00061               return( -1 );
00062        }
00063 
00064        /* write out the request to the bind process */
00065        fprintf( fp, "BIND\n" );
00066        fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
00067        sock_print_conn( fp, op->o_conn, si );
00068        sock_print_suffixes( fp, op->o_bd );
00069        fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
00070        fprintf( fp, "method: %d\n", op->oq_bind.rb_method );
00071        fprintf( fp, "credlen: %lu\n", op->oq_bind.rb_cred.bv_len );
00072        fprintf( fp, "cred: %s\n", op->oq_bind.rb_cred.bv_val ); /* XXX */
00073        fprintf( fp, "\n" );
00074 
00075        /* read in the results and send them along */
00076        rc = sock_read_and_send_results( op, rs, fp );
00077        fclose( fp );
00078 
00079        return( rc );
00080 }