2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2004
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 struct ldapsrv_reply *ldapsrv_init_reply(struct ldapsrv_call *call, enum ldap_request_tag type)
26 struct ldapsrv_reply *reply;
28 reply = talloc_p(call, struct ldapsrv_reply);
33 reply->prev = reply->next = NULL;
34 reply->state = LDAPSRV_REPLY_STATE_NEW;
35 reply->msg.messageid = call->request.messageid;
36 reply->msg.type = type;
37 reply->msg.mem_ctx = reply;
42 NTSTATUS ldapsrv_queue_reply(struct ldapsrv_call *call, struct ldapsrv_reply *reply)
44 DLIST_ADD_END(call->replies, reply, struct ldapsrv_reply *);
48 struct ldapsrv_partition *ldapsrv_get_partition(struct ldapsrv_connection *conn, const char *dn)
50 if (strcasecmp("", dn) == 0) {
51 return conn->service->rootDSE;
54 return conn->service->default_partition;
57 NTSTATUS ldapsrv_unwilling(struct ldapsrv_call *call, int error)
59 struct ldapsrv_reply *reply;
60 struct ldap_ExtendedResponse *r;
62 DEBUG(10,("Unwilling type[%d] id[%d]\n", call->request.type, call->request.messageid));
64 reply = ldapsrv_init_reply(call, LDAP_TAG_ExtendedResponse);
66 return NT_STATUS_NO_MEMORY;
69 r = &reply->msg.r.ExtendedResponse;
70 r->response.resultcode = error;
71 r->response.dn = NULL;
72 r->response.errormessage = NULL;
73 r->response.referral = NULL;
78 return ldapsrv_queue_reply(call, reply);
81 static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
83 struct ldap_SearchRequest *req = &call->request.r.SearchRequest;
84 struct ldapsrv_partition *part;
86 DEBUG(10, ("SearchRequest"));
87 DEBUGADD(10, (" basedn: %s", req->basedn));
88 DEBUGADD(10, (" filter: %s\n", req->filter));
90 part = ldapsrv_get_partition(call->conn, req->basedn);
92 if (!part->ops->Search) {
93 struct ldap_Result *done;
94 struct ldapsrv_reply *done_r;
96 done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
98 return NT_STATUS_NO_MEMORY;
101 done = &done_r->msg.r.SearchResultDone;
102 done->resultcode = 53;
104 done->errormessage = NULL;
105 done->referral = NULL;
107 return ldapsrv_queue_reply(call, done_r);
110 return part->ops->Search(part, call, req);
113 static NTSTATUS ldapsrv_ModifyRequest(struct ldapsrv_call *call)
115 struct ldap_ModifyRequest *req = &call->request.r.ModifyRequest;
116 struct ldapsrv_partition *part;
118 DEBUG(10, ("ModifyRequest"));
119 DEBUGADD(10, (" dn: %s", req->dn));
121 part = ldapsrv_get_partition(call->conn, req->dn);
123 if (!part->ops->Modify) {
124 return ldapsrv_unwilling(call, 53);
127 return part->ops->Modify(part, call, req);
130 static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call)
132 struct ldap_AddRequest *req = &call->request.r.AddRequest;
133 struct ldapsrv_partition *part;
135 DEBUG(10, ("AddRequest"));
136 DEBUGADD(10, (" dn: %s", req->dn));
138 part = ldapsrv_get_partition(call->conn, req->dn);
140 if (!part->ops->Add) {
141 return ldapsrv_unwilling(call, 53);
144 return part->ops->Add(part, call, req);
147 static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call)
149 struct ldap_DelRequest *req = &call->request.r.DelRequest;
150 struct ldapsrv_partition *part;
152 DEBUG(10, ("DelRequest"));
153 DEBUGADD(10, (" dn: %s", req->dn));
155 part = ldapsrv_get_partition(call->conn, req->dn);
157 if (!part->ops->Del) {
158 return ldapsrv_unwilling(call, 53);
161 return part->ops->Del(part, call, req);
164 static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call)
166 struct ldap_ModifyDNRequest *req = &call->request.r.ModifyDNRequest;
167 struct ldapsrv_partition *part;
169 DEBUG(10, ("ModifyDNRequrest"));
170 DEBUGADD(10, (" dn: %s", req->dn));
171 DEBUGADD(10, (" newrdn: %s", req->newrdn));
173 part = ldapsrv_get_partition(call->conn, req->dn);
175 if (!part->ops->ModifyDN) {
176 return ldapsrv_unwilling(call, 53);
179 return part->ops->ModifyDN(part, call, req);
182 static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call)
184 struct ldap_CompareRequest *req = &call->request.r.CompareRequest;
185 struct ldapsrv_partition *part;
187 DEBUG(10, ("CompareRequest"));
188 DEBUGADD(10, (" dn: %s", req->dn));
190 part = ldapsrv_get_partition(call->conn, req->dn);
192 if (!part->ops->Compare) {
193 return ldapsrv_unwilling(call, 53);
196 return part->ops->Compare(part, call, req);
199 static NTSTATUS ldapsrv_AbandonRequest(struct ldapsrv_call *call)
201 /* struct ldap_AbandonRequest *req = &call->request.r.AbandonRequest;*/
202 DEBUG(10, ("AbandonRequest\n"));
206 static NTSTATUS ldapsrv_ExtendedRequest(struct ldapsrv_call *call)
208 /* struct ldap_ExtendedRequest *req = &call->request.r.ExtendedRequest;*/
209 struct ldapsrv_reply *reply;
211 DEBUG(10, ("Extended\n"));
213 reply = ldapsrv_init_reply(call, LDAP_TAG_ExtendedResponse);
215 return NT_STATUS_NO_MEMORY;
218 ZERO_STRUCT(reply->msg.r);
220 return ldapsrv_queue_reply(call, reply);
223 NTSTATUS ldapsrv_do_call(struct ldapsrv_call *call)
225 switch(call->request.type) {
226 case LDAP_TAG_BindRequest:
227 return ldapsrv_BindRequest(call);
228 case LDAP_TAG_UnbindRequest:
229 return ldapsrv_UnbindRequest(call);
230 case LDAP_TAG_SearchRequest:
231 return ldapsrv_SearchRequest(call);
232 case LDAP_TAG_ModifyRequest:
233 return ldapsrv_ModifyRequest(call);
234 case LDAP_TAG_AddRequest:
235 return ldapsrv_AddRequest(call);
236 case LDAP_TAG_DelRequest:
237 return ldapsrv_DelRequest(call);
238 case LDAP_TAG_ModifyDNRequest:
239 return ldapsrv_ModifyDNRequest(call);
240 case LDAP_TAG_CompareRequest:
241 return ldapsrv_CompareRequest(call);
242 case LDAP_TAG_AbandonRequest:
243 return ldapsrv_AbandonRequest(call);
244 case LDAP_TAG_ExtendedRequest:
245 return ldapsrv_ExtendedRequest(call);
247 return ldapsrv_unwilling(call, 2);