2 * Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
4 * Redistribution and use in source and binary forms are permitted only
5 * as authorized by the OpenLDAP Public License. A copy of this
6 * license is available at http://www.OpenLDAP.org/license.html or
7 * in file LICENSE in the top-level directory of the distribution.
15 #include <sys/types.h>
22 int backsql_bind(BackendDB *be,Connection *conn,Operation *op,
23 struct berval *dn,struct berval *ndn,int method,struct berval *cred,struct berval *edn)
25 backsql_info *bi=(backsql_info*)be->be_private;
26 backsql_entryID user_id,*res;
28 AttributeDescription *password = slap_schema.si_ad_userPassword;
31 backsql_srch_info bsi;
33 Debug(LDAP_DEBUG_TRACE,"==>backsql_bind()\n",0,0,0);
35 if ( be_isroot_pw( be, conn, ndn, cred ) )
37 ber_dupbv(edn, be_root_dn(be));
38 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind() root bind\n",0,0,0);
44 if (method == LDAP_AUTH_SIMPLE)
46 dbh=backsql_get_db_conn(be,conn);
50 Debug(LDAP_DEBUG_TRACE,"backsql_bind(): could not get connection handle - exiting\n",0,0,0);
51 send_ldap_result(conn,op,LDAP_OTHER,"","SQL-backend error",NULL,NULL);
55 res=backsql_dn2id(bi,&user_id,dbh,ndn->bv_val);
58 Debug(LDAP_DEBUG_TRACE,"backsql_bind(): could not retrieve bind dn id - no such entry\n",0,0,0);
59 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,NULL, NULL, NULL, NULL );
63 backsql_init_search(&bsi,bi,(char*)ndn->bv_val,LDAP_SCOPE_BASE,-1,-1,-1,NULL,dbh,
65 e=backsql_id2entry(&bsi,&user_entry,&user_id);
68 Debug(LDAP_DEBUG_TRACE,"backsql_bind(): error in backsql_id2entry() - auth failed\n",0,0,0);
69 send_ldap_result( conn, op, LDAP_OTHER,NULL, NULL, NULL, NULL );
73 if ( ! access_allowed( be, conn, op, e,password, NULL, ACL_AUTH ) )
75 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, NULL, NULL, NULL, NULL );
79 if ( (a = attr_find( e->e_attrs, password )) == NULL )
81 send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH, NULL, NULL, NULL, NULL );
85 if ( slap_passwd_check( conn, a, cred ) != 0 )
87 send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,NULL, NULL, NULL, NULL );
91 else /*method != SIMPLE */
93 send_ldap_result( conn, op, LDAP_STRONG_AUTH_NOT_SUPPORTED,
94 NULL, "authentication method not supported", NULL, NULL );
97 Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
101 int backsql_unbind(BackendDB *be,Connection *conn,Operation *op)
103 Debug(LDAP_DEBUG_TRACE,"==>backsql_unbind()\n",0,0,0);
104 send_ldap_result(conn,op,LDAP_SUCCESS,NULL,NULL,NULL,0);
105 Debug(LDAP_DEBUG_TRACE,"<==backsql_unbind()\n",0,0,0);
109 #endif /* SLAPD_SQL */