2004-10-08 12:26:14 +00:00
/*
Unix SMB / CIFS implementation .
LDAP server
Copyright ( C ) Stefan Metzmacher 2004
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-02 06:52:59 +00:00
# include "ldap_server/ldap_server.h"
2004-11-02 06:42:15 +00:00
# include "dlinklist.h"
2004-10-08 12:26:14 +00:00
2005-02-10 07:08:40 +00:00
struct ldapsrv_reply * ldapsrv_init_reply ( struct ldapsrv_call * call , uint8_t type )
2004-10-08 12:26:14 +00:00
{
struct ldapsrv_reply * reply ;
2005-01-27 07:08:20 +00:00
reply = talloc ( call , struct ldapsrv_reply ) ;
2004-10-08 12:26:14 +00:00
if ( ! reply ) {
return NULL ;
}
2005-06-15 00:27:51 +00:00
reply - > msg = talloc ( reply , struct ldap_message ) ;
if ( reply - > msg = = NULL ) {
talloc_free ( reply ) ;
return NULL ;
}
2004-10-08 12:26:14 +00:00
2005-06-15 00:27:51 +00:00
reply - > msg - > messageid = call - > request - > messageid ;
reply - > msg - > type = type ;
2004-10-08 12:26:14 +00:00
return reply ;
}
2005-06-19 09:31:34 +00:00
void ldapsrv_queue_reply ( struct ldapsrv_call * call , struct ldapsrv_reply * reply )
2004-10-08 12:26:14 +00:00
{
DLIST_ADD_END ( call - > replies , reply , struct ldapsrv_reply * ) ;
}
2005-02-10 07:08:40 +00:00
struct ldapsrv_partition * ldapsrv_get_partition ( struct ldapsrv_connection * conn , const char * dn , uint8_t scope )
2004-10-08 12:26:14 +00:00
{
2005-10-07 11:31:45 +00:00
return conn - > default_partition ;
2004-10-08 12:26:14 +00:00
}
NTSTATUS ldapsrv_unwilling ( struct ldapsrv_call * call , int error )
{
struct ldapsrv_reply * reply ;
struct ldap_ExtendedResponse * r ;
2005-06-15 00:27:51 +00:00
DEBUG ( 10 , ( " Unwilling type[%d] id[%d] \n " , call - > request - > type , call - > request - > messageid ) ) ;
2004-10-08 12:26:14 +00:00
reply = ldapsrv_init_reply ( call , LDAP_TAG_ExtendedResponse ) ;
if ( ! reply ) {
return NT_STATUS_NO_MEMORY ;
}
2005-06-15 00:27:51 +00:00
r = & reply - > msg - > r . ExtendedResponse ;
2004-10-08 12:26:14 +00:00
r - > response . resultcode = error ;
r - > response . dn = NULL ;
r - > response . errormessage = NULL ;
r - > response . referral = NULL ;
r - > name = NULL ;
r - > value . data = NULL ;
r - > value . length = 0 ;
2005-06-19 09:31:34 +00:00
ldapsrv_queue_reply ( call , reply ) ;
return NT_STATUS_OK ;
2004-10-08 12:26:14 +00:00
}
static NTSTATUS ldapsrv_SearchRequest ( struct ldapsrv_call * call )
{
2005-06-15 00:27:51 +00:00
struct ldap_SearchRequest * req = & call - > request - > r . SearchRequest ;
2004-10-08 12:26:14 +00:00
struct ldapsrv_partition * part ;
DEBUG ( 10 , ( " SearchRequest " ) ) ;
DEBUGADD ( 10 , ( " basedn: %s " , req - > basedn ) ) ;
2005-06-13 09:10:17 +00:00
DEBUGADD ( 10 , ( " filter: %s \n " , ldb_filter_from_tree ( call , req - > tree ) ) ) ;
2004-10-08 12:26:14 +00:00
2004-10-10 02:24:42 +00:00
part = ldapsrv_get_partition ( call - > conn , req - > basedn , req - > scope ) ;
2004-10-08 12:26:14 +00:00
if ( ! part - > ops - > Search ) {
struct ldap_Result * done ;
struct ldapsrv_reply * done_r ;
done_r = ldapsrv_init_reply ( call , LDAP_TAG_SearchResultDone ) ;
if ( ! done_r ) {
return NT_STATUS_NO_MEMORY ;
}
2005-06-15 00:27:51 +00:00
done = & done_r - > msg - > r . SearchResultDone ;
2004-10-08 12:26:14 +00:00
done - > resultcode = 53 ;
done - > dn = NULL ;
done - > errormessage = NULL ;
done - > referral = NULL ;
2005-06-19 09:31:34 +00:00
ldapsrv_queue_reply ( call , done_r ) ;
return NT_STATUS_OK ;
2004-10-08 12:26:14 +00:00
}
return part - > ops - > Search ( part , call , req ) ;
}
static NTSTATUS ldapsrv_ModifyRequest ( struct ldapsrv_call * call )
{
2005-06-15 00:27:51 +00:00
struct ldap_ModifyRequest * req = & call - > request - > r . ModifyRequest ;
2004-10-08 12:26:14 +00:00
struct ldapsrv_partition * part ;
DEBUG ( 10 , ( " ModifyRequest " ) ) ;
DEBUGADD ( 10 , ( " dn: %s " , req - > dn ) ) ;
2004-10-10 02:24:42 +00:00
part = ldapsrv_get_partition ( call - > conn , req - > dn , LDAP_SEARCH_SCOPE_SUB ) ;
2004-10-08 12:26:14 +00:00
if ( ! part - > ops - > Modify ) {
return ldapsrv_unwilling ( call , 53 ) ;
}
return part - > ops - > Modify ( part , call , req ) ;
}
static NTSTATUS ldapsrv_AddRequest ( struct ldapsrv_call * call )
{
2005-06-15 00:27:51 +00:00
struct ldap_AddRequest * req = & call - > request - > r . AddRequest ;
2004-10-08 12:26:14 +00:00
struct ldapsrv_partition * part ;
DEBUG ( 10 , ( " AddRequest " ) ) ;
DEBUGADD ( 10 , ( " dn: %s " , req - > dn ) ) ;
2004-10-10 02:24:42 +00:00
part = ldapsrv_get_partition ( call - > conn , req - > dn , LDAP_SEARCH_SCOPE_SUB ) ;
2004-10-08 12:26:14 +00:00
if ( ! part - > ops - > Add ) {
return ldapsrv_unwilling ( call , 53 ) ;
}
return part - > ops - > Add ( part , call , req ) ;
}
static NTSTATUS ldapsrv_DelRequest ( struct ldapsrv_call * call )
{
2005-06-15 00:27:51 +00:00
struct ldap_DelRequest * req = & call - > request - > r . DelRequest ;
2004-10-08 12:26:14 +00:00
struct ldapsrv_partition * part ;
DEBUG ( 10 , ( " DelRequest " ) ) ;
DEBUGADD ( 10 , ( " dn: %s " , req - > dn ) ) ;
2004-10-10 02:24:42 +00:00
part = ldapsrv_get_partition ( call - > conn , req - > dn , LDAP_SEARCH_SCOPE_SUB ) ;
2004-10-08 12:26:14 +00:00
if ( ! part - > ops - > Del ) {
return ldapsrv_unwilling ( call , 53 ) ;
}
return part - > ops - > Del ( part , call , req ) ;
}
static NTSTATUS ldapsrv_ModifyDNRequest ( struct ldapsrv_call * call )
{
2005-06-15 00:27:51 +00:00
struct ldap_ModifyDNRequest * req = & call - > request - > r . ModifyDNRequest ;
2004-10-08 12:26:14 +00:00
struct ldapsrv_partition * part ;
DEBUG ( 10 , ( " ModifyDNRequrest " ) ) ;
DEBUGADD ( 10 , ( " dn: %s " , req - > dn ) ) ;
DEBUGADD ( 10 , ( " newrdn: %s " , req - > newrdn ) ) ;
2004-10-10 02:24:42 +00:00
part = ldapsrv_get_partition ( call - > conn , req - > dn , LDAP_SEARCH_SCOPE_SUB ) ;
2004-10-08 12:26:14 +00:00
if ( ! part - > ops - > ModifyDN ) {
return ldapsrv_unwilling ( call , 53 ) ;
}
return part - > ops - > ModifyDN ( part , call , req ) ;
}
static NTSTATUS ldapsrv_CompareRequest ( struct ldapsrv_call * call )
{
2005-06-15 00:27:51 +00:00
struct ldap_CompareRequest * req = & call - > request - > r . CompareRequest ;
2004-10-08 12:26:14 +00:00
struct ldapsrv_partition * part ;
DEBUG ( 10 , ( " CompareRequest " ) ) ;
DEBUGADD ( 10 , ( " dn: %s " , req - > dn ) ) ;
2004-10-10 02:24:42 +00:00
part = ldapsrv_get_partition ( call - > conn , req - > dn , LDAP_SEARCH_SCOPE_SUB ) ;
2004-10-08 12:26:14 +00:00
if ( ! part - > ops - > Compare ) {
return ldapsrv_unwilling ( call , 53 ) ;
}
return part - > ops - > Compare ( part , call , req ) ;
}
static NTSTATUS ldapsrv_AbandonRequest ( struct ldapsrv_call * call )
{
/* struct ldap_AbandonRequest *req = &call->request.r.AbandonRequest;*/
DEBUG ( 10 , ( " AbandonRequest \n " ) ) ;
return NT_STATUS_OK ;
}
static NTSTATUS ldapsrv_ExtendedRequest ( struct ldapsrv_call * call )
{
/* struct ldap_ExtendedRequest *req = &call->request.r.ExtendedRequest;*/
struct ldapsrv_reply * reply ;
DEBUG ( 10 , ( " Extended \n " ) ) ;
reply = ldapsrv_init_reply ( call , LDAP_TAG_ExtendedResponse ) ;
if ( ! reply ) {
return NT_STATUS_NO_MEMORY ;
}
2005-06-15 00:27:51 +00:00
ZERO_STRUCT ( reply - > msg - > r ) ;
2004-10-08 12:26:14 +00:00
2005-06-19 09:31:34 +00:00
ldapsrv_queue_reply ( call , reply ) ;
return NT_STATUS_OK ;
2004-10-08 12:26:14 +00:00
}
NTSTATUS ldapsrv_do_call ( struct ldapsrv_call * call )
{
2005-06-15 00:27:51 +00:00
switch ( call - > request - > type ) {
2004-10-08 12:26:14 +00:00
case LDAP_TAG_BindRequest :
return ldapsrv_BindRequest ( call ) ;
case LDAP_TAG_UnbindRequest :
return ldapsrv_UnbindRequest ( call ) ;
case LDAP_TAG_SearchRequest :
return ldapsrv_SearchRequest ( call ) ;
case LDAP_TAG_ModifyRequest :
return ldapsrv_ModifyRequest ( call ) ;
case LDAP_TAG_AddRequest :
return ldapsrv_AddRequest ( call ) ;
case LDAP_TAG_DelRequest :
return ldapsrv_DelRequest ( call ) ;
case LDAP_TAG_ModifyDNRequest :
return ldapsrv_ModifyDNRequest ( call ) ;
case LDAP_TAG_CompareRequest :
return ldapsrv_CompareRequest ( call ) ;
case LDAP_TAG_AbandonRequest :
return ldapsrv_AbandonRequest ( call ) ;
case LDAP_TAG_ExtendedRequest :
return ldapsrv_ExtendedRequest ( call ) ;
default :
return ldapsrv_unwilling ( call , 2 ) ;
}
}
2005-06-20 04:59:10 +00:00