s4:acl LDB module - define the delete passwords special case a bit better
[samba.git] / source4 / dsdb / samdb / ldb_modules / acl.c
1 /*
2   ldb database library
3
4   Copyright (C) Simo Sorce 2006-2008
5   Copyright (C) Nadezhda Ivanova 2009
6   Copyright (C) Anatoliy Atanasov  2009
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 3 of the License, or
11   (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 /*
23  *  Name: ldb
24  *
25  *  Component: ldb ACL module
26  *
27  *  Description: Module that performs authorisation access checks based on the
28  *               account's security context and the DACL of the object being polled.
29  *               Only DACL checks implemented at this point
30  *
31  *  Authors: Nadezhda Ivanova, Anatoliy Atanasov
32  */
33
34 #include "includes.h"
35 #include "ldb_module.h"
36 #include "auth/auth.h"
37 #include "libcli/security/security.h"
38 #include "dsdb/samdb/samdb.h"
39 #include "librpc/gen_ndr/ndr_security.h"
40 #include "param/param.h"
41 #include "dsdb/samdb/ldb_modules/util.h"
42 #include "dsdb/samdb/ldb_modules/schema.h"
43 #include "lib/util/tsort.h"
44
45 struct extended_access_check_attribute {
46         const char *oa_name;
47         const uint32_t requires_rights;
48 };
49
50 struct acl_private {
51         bool acl_perform;
52         const char **password_attrs;
53 };
54
55 struct acl_context {
56         struct ldb_module *module;
57         struct ldb_request *req;
58         bool am_system;
59         bool allowedAttributes;
60         bool allowedAttributesEffective;
61         bool allowedChildClasses;
62         bool allowedChildClassesEffective;
63         bool sDRightsEffective;
64         const char * const *attrs;
65         struct dsdb_schema *schema;
66 };
67
68 static int acl_module_init(struct ldb_module *module)
69 {
70         struct ldb_context *ldb;
71         struct acl_private *data;
72         int ret, i;
73         TALLOC_CTX *mem_ctx;
74         static const char *attrs[] = { "passwordAttribute", NULL };
75         struct ldb_result *res;
76         struct ldb_message *msg;
77         struct ldb_message_element *password_attributes;
78
79         ldb = ldb_module_get_ctx(module);
80
81         ret = ldb_mod_register_control(module, LDB_CONTROL_SD_FLAGS_OID);
82         if (ret != LDB_SUCCESS) {
83                 ldb_debug(ldb, LDB_DEBUG_ERROR,
84                           "acl_module_init: Unable to register control with rootdse!\n");
85                 return ldb_operr(ldb);
86         }
87
88         data = talloc(module, struct acl_private);
89         if (data == NULL) {
90                 return ldb_oom(ldb);
91         }
92
93         data->password_attrs = NULL;
94         data->acl_perform = lpcfg_parm_bool(ldb_get_opaque(ldb, "loadparm"),
95                                          NULL, "acl", "perform", false);
96         ldb_module_set_private(module, data);
97
98         mem_ctx = talloc_new(module);
99         if (!mem_ctx) {
100                 return ldb_oom(ldb);
101         }
102
103         ret = dsdb_module_search_dn(module, mem_ctx, &res,
104                                     ldb_dn_new(mem_ctx, ldb, "@KLUDGEACL"),
105                                     attrs,
106                                     DSDB_FLAG_NEXT_MODULE);
107         if (ret != LDB_SUCCESS) {
108                 goto done;
109         }
110         if (res->count == 0) {
111                 goto done;
112         }
113
114         if (res->count > 1) {
115                 talloc_free(mem_ctx);
116                 return LDB_ERR_CONSTRAINT_VIOLATION;
117         }
118
119         msg = res->msgs[0];
120
121         password_attributes = ldb_msg_find_element(msg, "passwordAttribute");
122         if (!password_attributes) {
123                 goto done;
124         }
125         data->password_attrs = talloc_array(data, const char *, password_attributes->num_values + 1);
126         if (!data->password_attrs) {
127                 talloc_free(mem_ctx);
128                 return ldb_oom(ldb);
129         }
130         for (i=0; i < password_attributes->num_values; i++) {
131                 data->password_attrs[i] = (const char *)password_attributes->values[i].data;
132                 talloc_steal(data->password_attrs, password_attributes->values[i].data);
133         }
134         data->password_attrs[i] = NULL;
135
136 done:
137         talloc_free(mem_ctx);
138         return ldb_next_init(module);
139 }
140
141 static int acl_allowedAttributes(struct ldb_module *module,
142                                  const struct dsdb_schema *schema,
143                                  struct ldb_message *sd_msg,
144                                  struct ldb_message *msg,
145                                  struct acl_context *ac)
146 {
147         struct ldb_message_element *oc_el;
148         struct ldb_context *ldb = ldb_module_get_ctx(module);
149         TALLOC_CTX *mem_ctx;
150         const char **attr_list;
151         int i, ret;
152
153         /* If we don't have a schema yet, we can't do anything... */
154         if (schema == NULL) {
155                 ldb_asprintf_errstring(ldb, "cannot add allowedAttributes to %s because no schema is loaded", ldb_dn_get_linearized(msg->dn));
156                 return LDB_ERR_OPERATIONS_ERROR;
157         }
158
159         /* Must remove any existing attribute */
160         if (ac->allowedAttributes) {
161                 ldb_msg_remove_attr(msg, "allowedAttributes");
162         }
163
164         mem_ctx = talloc_new(msg);
165         if (!mem_ctx) {
166                 return ldb_oom(ldb);
167         }
168
169         oc_el = ldb_msg_find_element(sd_msg, "objectClass");
170         attr_list = dsdb_full_attribute_list(mem_ctx, schema, oc_el, DSDB_SCHEMA_ALL);
171         if (!attr_list) {
172                 ldb_asprintf_errstring(ldb, "acl: Failed to get list of attributes");
173                 talloc_free(mem_ctx);
174                 return LDB_ERR_OPERATIONS_ERROR;
175         }
176         if (ac->allowedAttributes) {
177                 for (i=0; attr_list && attr_list[i]; i++) {
178                         ldb_msg_add_string(msg, "allowedAttributes", attr_list[i]);
179                 }
180         }
181         if (ac->allowedAttributesEffective) {
182                 struct security_descriptor *sd;
183                 struct dom_sid *sid = NULL;
184                 struct ldb_control *as_system = ldb_request_get_control(ac->req,
185                                                                         LDB_CONTROL_AS_SYSTEM_OID);
186
187                 if (as_system != NULL) {
188                         as_system->critical = 0;
189                 }
190
191                 ldb_msg_remove_attr(msg, "allowedAttributesEffective");
192                 if (ac->am_system || as_system) {
193                         for (i=0; attr_list && attr_list[i]; i++) {
194                                 ldb_msg_add_string(msg, "allowedAttributesEffective", attr_list[i]);
195                         }
196                         return LDB_SUCCESS;
197                 }
198
199                 ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(module), mem_ctx, sd_msg, &sd);
200
201                 if (ret != LDB_SUCCESS) {
202                         return ret;
203                 }
204
205                 sid = samdb_result_dom_sid(mem_ctx, sd_msg, "objectSid");
206                 for (i=0; attr_list && attr_list[i]; i++) {
207                         const struct dsdb_attribute *attr = dsdb_attribute_by_lDAPDisplayName(schema,
208                                                                                         attr_list[i]);
209                         if (!attr) {
210                                 return ldb_operr(ldb);
211                         }
212                         /* remove constructed attributes */
213                         if (attr->systemFlags & DS_FLAG_ATTR_IS_CONSTRUCTED
214                             || attr->systemOnly
215                             || (attr->linkID != 0 && attr->linkID % 2 != 0 )) {
216                                 continue;
217                         }
218                         ret = acl_check_access_on_attribute(module,
219                                                             msg,
220                                                             sd,
221                                                             sid,
222                                                             SEC_ADS_WRITE_PROP,
223                                                             attr);
224                         if (ret == LDB_SUCCESS) {
225                                 ldb_msg_add_string(msg, "allowedAttributesEffective", attr_list[i]);
226                         }
227                 }
228         }
229         return LDB_SUCCESS;
230 }
231
232 static int acl_childClasses(struct ldb_module *module,
233                             const struct dsdb_schema *schema,
234                             struct ldb_message *sd_msg,
235                             struct ldb_message *msg,
236                             const char *attrName)
237 {
238         struct ldb_message_element *oc_el;
239         struct ldb_message_element *allowedClasses;
240         const struct dsdb_class *sclass;
241         unsigned int i, j;
242         int ret;
243
244         /* If we don't have a schema yet, we can't do anything... */
245         if (schema == NULL) {
246                 ldb_asprintf_errstring(ldb_module_get_ctx(module), "cannot add childClassesEffective to %s because no schema is loaded", ldb_dn_get_linearized(msg->dn));
247                 return LDB_ERR_OPERATIONS_ERROR;
248         }
249
250         /* Must remove any existing attribute, or else confusion reins */
251         ldb_msg_remove_attr(msg, attrName);
252         ret = ldb_msg_add_empty(msg, attrName, 0, &allowedClasses);
253         if (ret != LDB_SUCCESS) {
254                 return ret;
255         }
256
257         oc_el = ldb_msg_find_element(sd_msg, "objectClass");
258
259         for (i=0; oc_el && i < oc_el->num_values; i++) {
260                 sclass = dsdb_class_by_lDAPDisplayName_ldb_val(schema, &oc_el->values[i]);
261                 if (!sclass) {
262                         /* We don't know this class?  what is going on? */
263                         continue;
264                 }
265
266                 for (j=0; sclass->possibleInferiors && sclass->possibleInferiors[j]; j++) {
267                         ldb_msg_add_string(msg, attrName, sclass->possibleInferiors[j]);
268                 }
269         }
270         if (allowedClasses->num_values > 1) {
271                 TYPESAFE_QSORT(allowedClasses->values, allowedClasses->num_values, data_blob_cmp);
272                 for (i=1 ; i < allowedClasses->num_values; i++) {
273                         struct ldb_val *val1 = &allowedClasses->values[i-1];
274                         struct ldb_val *val2 = &allowedClasses->values[i];
275                         if (data_blob_cmp(val1, val2) == 0) {
276                                 memmove(val1, val2, (allowedClasses->num_values - i) * sizeof(struct ldb_val));
277                                 allowedClasses->num_values--;
278                                 i--;
279                         }
280                 }
281         }
282
283         return LDB_SUCCESS;
284 }
285
286 static int acl_childClassesEffective(struct ldb_module *module,
287                                      const struct dsdb_schema *schema,
288                                      struct ldb_message *sd_msg,
289                                      struct ldb_message *msg,
290                                      struct acl_context *ac)
291 {
292         struct ldb_message_element *oc_el;
293         struct ldb_message_element *allowedClasses = NULL;
294         const struct dsdb_class *sclass;
295         struct security_descriptor *sd;
296         struct ldb_control *as_system = ldb_request_get_control(ac->req,
297                                                                 LDB_CONTROL_AS_SYSTEM_OID);
298         struct dom_sid *sid = NULL;
299         unsigned int i, j;
300         int ret;
301
302         if (as_system != NULL) {
303                 as_system->critical = 0;
304         }
305
306         if (ac->am_system || as_system) {
307                 return acl_childClasses(module, schema, sd_msg, msg, "allowedChildClassesEffective");
308         }
309
310         /* If we don't have a schema yet, we can't do anything... */
311         if (schema == NULL) {
312                 ldb_asprintf_errstring(ldb_module_get_ctx(module), "cannot add allowedChildClassesEffective to %s because no schema is loaded", ldb_dn_get_linearized(msg->dn));
313                 return LDB_ERR_OPERATIONS_ERROR;
314         }
315
316         /* Must remove any existing attribute, or else confusion reins */
317         ldb_msg_remove_attr(msg, "allowedChildClassesEffective");
318
319         oc_el = ldb_msg_find_element(sd_msg, "objectClass");
320         ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(module), msg, sd_msg, &sd);
321         if (ret != LDB_SUCCESS) {
322                 return ret;
323         }
324
325         sid = samdb_result_dom_sid(msg, sd_msg, "objectSid");
326         for (i=0; oc_el && i < oc_el->num_values; i++) {
327                 sclass = dsdb_class_by_lDAPDisplayName_ldb_val(schema, &oc_el->values[i]);
328                 if (!sclass) {
329                         /* We don't know this class?  what is going on? */
330                         continue;
331                 }
332
333                 for (j=0; sclass->possibleInferiors && sclass->possibleInferiors[j]; j++) {
334                         ret = acl_check_access_on_class(module,
335                                                         schema,
336                                                         msg,
337                                                         sd,
338                                                         sid,
339                                                         SEC_ADS_CREATE_CHILD,
340                                                         sclass->possibleInferiors[j]);
341                         if (ret == LDB_SUCCESS) {
342                                 ldb_msg_add_string(msg, "allowedChildClassesEffective",
343                                                    sclass->possibleInferiors[j]);
344                         }
345                 }
346         }
347         allowedClasses = ldb_msg_find_element(msg, "allowedChildClassesEffective");
348         if (!allowedClasses) {
349                 return LDB_SUCCESS;
350         }
351
352         if (allowedClasses->num_values > 1) {
353                 TYPESAFE_QSORT(allowedClasses->values, allowedClasses->num_values, data_blob_cmp);
354                 for (i=1 ; i < allowedClasses->num_values; i++) {
355                         struct ldb_val *val1 = &allowedClasses->values[i-1];
356                         struct ldb_val *val2 = &allowedClasses->values[i];
357                         if (data_blob_cmp(val1, val2) == 0) {
358                                 memmove(val1, val2, (allowedClasses->num_values - i) * sizeof( struct ldb_val));
359                                 allowedClasses->num_values--;
360                                 i--;
361                         }
362                 }
363         }
364         return LDB_SUCCESS;
365 }
366
367 static int acl_sDRightsEffective(struct ldb_module *module,
368                                  struct ldb_message *sd_msg,
369                                  struct ldb_message *msg,
370                                  struct acl_context *ac)
371 {
372         struct ldb_message_element *rightsEffective;
373         int ret;
374         struct security_descriptor *sd;
375         struct ldb_control *as_system = ldb_request_get_control(ac->req,
376                                                                 LDB_CONTROL_AS_SYSTEM_OID);
377         struct dom_sid *sid = NULL;
378         uint32_t flags = 0;
379
380         if (as_system != NULL) {
381                 as_system->critical = 0;
382         }
383
384         /* Must remove any existing attribute, or else confusion reins */
385         ldb_msg_remove_attr(msg, "sDRightsEffective");
386         ret = ldb_msg_add_empty(msg, "sDRightsEffective", 0, &rightsEffective);
387         if (ret != LDB_SUCCESS) {
388                 return ret;
389         }
390         if (ac->am_system || as_system) {
391                 flags = SECINFO_OWNER | SECINFO_GROUP |  SECINFO_SACL |  SECINFO_DACL;
392         }
393         else {
394                 /* Get the security descriptor from the message */
395                 ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(module), msg, sd_msg, &sd);
396                 if (ret != LDB_SUCCESS) {
397                         return ret;
398                 }
399                 sid = samdb_result_dom_sid(msg, sd_msg, "objectSid");
400                 ret = acl_check_access_on_attribute(module,
401                                                     msg,
402                                                     sd,
403                                                     sid,
404                                                     SEC_STD_WRITE_OWNER,
405                                                     NULL);
406                 if (ret == LDB_SUCCESS) {
407                         flags |= SECINFO_OWNER | SECINFO_GROUP;
408                 }
409                 ret = acl_check_access_on_attribute(module,
410                                                     msg,
411                                                     sd,
412                                                     sid,
413                                                     SEC_STD_WRITE_DAC,
414                                                     NULL);
415                 if (ret == LDB_SUCCESS) {
416                         flags |= SECINFO_DACL;
417                 }
418                 ret = acl_check_access_on_attribute(module,
419                                                     msg,
420                                                     sd,
421                                                     sid,
422                                                     SEC_FLAG_SYSTEM_SECURITY,
423                                                     NULL);
424                 if (ret == LDB_SUCCESS) {
425                         flags |= SECINFO_SACL;
426                 }
427         }
428         return samdb_msg_add_uint(ldb_module_get_ctx(module), msg, msg,
429                                   "sDRightsEffective", flags);
430 }
431
432 static int acl_add(struct ldb_module *module, struct ldb_request *req)
433 {
434         int ret;
435         struct ldb_dn *parent = ldb_dn_get_parent(req, req->op.add.message->dn);
436         struct ldb_context *ldb;
437         const struct dsdb_schema *schema;
438         struct ldb_message_element *oc_el;
439         const struct GUID *guid;
440         struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
441
442         if (as_system != NULL) {
443                 as_system->critical = 0;
444         }
445
446         if (dsdb_module_am_system(module) || as_system) {
447                 return ldb_next_request(module, req);
448         }
449
450         if (ldb_dn_is_special(req->op.add.message->dn)) {
451                 return ldb_next_request(module, req);
452         }
453         ldb = ldb_module_get_ctx(module);
454         /* Creating an NC. There is probably something we should do here,
455          * but we will establish that later */
456         /* FIXME: this has to be made dynamic at some point */
457         if ((ldb_dn_compare(req->op.add.message->dn, (ldb_get_schema_basedn(ldb))) == 0) ||
458             (ldb_dn_compare(req->op.add.message->dn, (ldb_get_config_basedn(ldb))) == 0) ||
459             (ldb_dn_compare(req->op.add.message->dn, (ldb_get_default_basedn(ldb))) == 0)) {
460                 return ldb_next_request(module, req);
461         }
462
463         schema = dsdb_get_schema(ldb, req);
464         if (!schema) {
465                 return ldb_operr(ldb);
466         }
467
468         oc_el = ldb_msg_find_element(req->op.add.message, "objectClass");
469         if (!oc_el || oc_el->num_values == 0) {
470                 DEBUG(10,("acl:operation error %s\n", ldb_dn_get_linearized(req->op.add.message->dn)));
471                 return ldb_module_done(req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
472         }
473
474         guid = class_schemaid_guid_by_lDAPDisplayName(schema,
475                                                       (char *)oc_el->values[oc_el->num_values-1].data);
476         ret = dsdb_module_check_access_on_dn(module, req, parent, SEC_ADS_CREATE_CHILD, guid);
477         if (ret != LDB_SUCCESS) {
478                 return ret;
479         }
480         return ldb_next_request(module, req);
481 }
482
483 /* ckecks if modifications are allowed on "Member" attribute */
484 static int acl_check_self_membership(TALLOC_CTX *mem_ctx,
485                                      struct ldb_module *module,
486                                      struct ldb_request *req,
487                                      struct security_descriptor *sd,
488                                      struct dom_sid *sid,
489                                      const struct GUID *oc_guid,
490                                      const struct dsdb_attribute *attr)
491 {
492         int ret;
493         unsigned int i;
494         struct ldb_context *ldb = ldb_module_get_ctx(module);
495         struct ldb_dn *user_dn;
496         struct ldb_message_element *member_el;
497         /* if we have wp, we can do whatever we like */
498         if (acl_check_access_on_attribute(module,
499                                           mem_ctx,
500                                           sd,
501                                           sid,
502                                           SEC_ADS_WRITE_PROP,
503                                           attr) == LDB_SUCCESS) {
504                 return LDB_SUCCESS;
505         }
506         /* if we are adding/deleting ourselves, check for self membership */
507         ret = dsdb_find_dn_by_sid(ldb, mem_ctx, 
508                                   &acl_user_token(module)->sids[PRIMARY_USER_SID_INDEX], 
509                                   &user_dn);
510         if (ret != LDB_SUCCESS) {
511                 return ret;
512         }
513         member_el = ldb_msg_find_element(req->op.mod.message, "member");
514         if (!member_el) {
515                 return ldb_operr(ldb);
516         }
517         /* user can only remove oneself */
518         if (member_el->num_values == 0) {
519                 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
520         }
521         for (i = 0; i < member_el->num_values; i++) {
522                 if (strcasecmp((const char *)member_el->values[i].data,
523                                ldb_dn_get_extended_linearized(mem_ctx, user_dn, 1)) != 0) {
524                         return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
525                 }
526         }
527         ret = acl_check_extended_right(mem_ctx, sd, acl_user_token(module),
528                                        GUID_DRS_SELF_MEMBERSHIP,
529                                        SEC_ADS_SELF_WRITE,
530                                        sid);
531         if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
532                 dsdb_acl_debug(sd, acl_user_token(module),
533                                req->op.mod.message->dn,
534                                true,
535                                10);
536         }
537         return ret;
538 }
539
540 static int acl_check_password_rights(TALLOC_CTX *mem_ctx,
541                                      struct ldb_module *module,
542                                      struct ldb_request *req,
543                                      struct security_descriptor *sd,
544                                      struct dom_sid *sid,
545                                      const struct GUID *oc_guid)
546 {
547         int ret = LDB_SUCCESS;
548         unsigned int del_attr_cnt = 0, add_attr_cnt = 0, rep_attr_cnt = 0;
549         struct ldb_message_element *el;
550         struct ldb_message *msg;
551         const char *passwordAttrs[] = { "userPassword", "clearTextPassword",
552                                         "unicodePwd", "dBCSPwd", NULL }, **l;
553         TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
554
555         msg = ldb_msg_copy_shallow(tmp_ctx, req->op.mod.message);
556         if (msg == NULL) {
557                 return ldb_module_oom(module);
558         }
559         for (l = passwordAttrs; *l != NULL; l++) {
560                 while ((el = ldb_msg_find_element(msg, *l)) != NULL) {
561                         if (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE) {
562                                 ++del_attr_cnt;
563                         }
564                         if (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_ADD) {
565                                 ++add_attr_cnt;
566                         }
567                         if (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) {
568                                 ++rep_attr_cnt;
569                         }
570                         ldb_msg_remove_element(msg, el);
571                 }
572         }
573
574         /* single deletes will be handled by the "password_hash" LDB module
575          * later in the stack, so we let it though here */
576         if ((del_attr_cnt > 0) && (add_attr_cnt == 0) && (rep_attr_cnt == 0)) {
577                 talloc_free(tmp_ctx);
578                 return LDB_SUCCESS;
579         }
580
581         if (ldb_request_get_control(req,
582                                     DSDB_CONTROL_PASSWORD_CHANGE_OID) != NULL) {
583                 /* The "DSDB_CONTROL_PASSWORD_CHANGE_OID" control means that we
584                  * have a user password change and not a set as the message
585                  * looks like. In it's value blob it contains the NT and/or LM
586                  * hash of the old password specified by the user.
587                  * This control is used by the SAMR and "kpasswd" password
588                  * change mechanisms. */
589                 ret = acl_check_extended_right(tmp_ctx, sd, acl_user_token(module),
590                                                GUID_DRS_USER_CHANGE_PASSWORD,
591                                                SEC_ADS_CONTROL_ACCESS,
592                                                sid);
593         }
594         else if (rep_attr_cnt > 0 || (add_attr_cnt != del_attr_cnt)) {
595                 ret = acl_check_extended_right(tmp_ctx, sd, acl_user_token(module),
596                                                GUID_DRS_FORCE_CHANGE_PASSWORD,
597                                                SEC_ADS_CONTROL_ACCESS,
598                                                sid);
599         }
600         else if (add_attr_cnt == 1 && del_attr_cnt == 1) {
601                 ret = acl_check_extended_right(tmp_ctx, sd, acl_user_token(module),
602                                                GUID_DRS_USER_CHANGE_PASSWORD,
603                                                SEC_ADS_CONTROL_ACCESS,
604                                                sid);
605                 /* Very strange, but we get constraint violation in this case */
606                 if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
607                         ret = LDB_ERR_CONSTRAINT_VIOLATION;
608                 }
609         }
610         if (ret != LDB_SUCCESS) {
611                 dsdb_acl_debug(sd, acl_user_token(module),
612                                req->op.mod.message->dn,
613                                true,
614                                10);
615         }
616         talloc_free(tmp_ctx);
617         return ret;
618 }
619
620 static int acl_modify(struct ldb_module *module, struct ldb_request *req)
621 {
622         int ret;
623         struct ldb_context *ldb = ldb_module_get_ctx(module);
624         const struct dsdb_schema *schema;
625         unsigned int i;
626         const struct GUID *guid;
627         uint32_t access_granted;
628         struct object_tree *root = NULL;
629         struct object_tree *new_node = NULL;
630         NTSTATUS status;
631         struct ldb_result *acl_res;
632         struct security_descriptor *sd;
633         struct dom_sid *sid = NULL;
634         struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
635         TALLOC_CTX *tmp_ctx = talloc_new(req);
636         static const char *acl_attrs[] = {
637                 "nTSecurityDescriptor",
638                 "objectClass",
639                 "objectSid",
640                 NULL
641         };
642
643         if (as_system != NULL) {
644                 as_system->critical = 0;
645         }
646
647         /* Don't print this debug statement if elements[0].name is going to be NULL */
648         if(req->op.mod.message->num_elements > 0)
649         {
650                 DEBUG(10, ("ldb:acl_modify: %s\n", req->op.mod.message->elements[0].name));
651         }
652         if (dsdb_module_am_system(module) || as_system) {
653                 return ldb_next_request(module, req);
654         }
655         if (ldb_dn_is_special(req->op.mod.message->dn)) {
656                 return ldb_next_request(module, req);
657         }
658         ret = dsdb_module_search_dn(module, tmp_ctx, &acl_res, req->op.mod.message->dn,
659                                     acl_attrs,
660                                     DSDB_FLAG_NEXT_MODULE);
661
662         if (ret != LDB_SUCCESS) {
663                 goto fail;
664         }
665
666         schema = dsdb_get_schema(ldb, tmp_ctx);
667         if (!schema) {
668                 ret = LDB_ERR_OPERATIONS_ERROR;
669                 goto fail;
670         }
671
672         ret = dsdb_get_sd_from_ldb_message(ldb, tmp_ctx, acl_res->msgs[0], &sd);
673         if (ret != LDB_SUCCESS) {
674                 DEBUG(10, ("acl_modify: cannot get descriptor\n"));
675                 goto fail;
676         }
677         /* Theoretically we pass the check if the object has no sd */
678         if (!sd) {
679                 goto success;
680         }
681
682         guid = get_oc_guid_from_message(module, schema, acl_res->msgs[0]);
683         if (!guid) {
684                 DEBUG(10, ("acl_modify: cannot get guid\n"));
685                 goto fail;
686         }
687         sid = samdb_result_dom_sid(req, acl_res->msgs[0], "objectSid");
688         if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
689                                    &root, &new_node)) {
690                 DEBUG(10, ("acl_modify: cannot add to object tree\n"));
691                 goto fail;
692         }
693         for (i=0; i < req->op.mod.message->num_elements; i++){
694                 const struct dsdb_attribute *attr;
695                 attr = dsdb_attribute_by_lDAPDisplayName(schema,
696                                                                  req->op.mod.message->elements[i].name);
697
698                 if (ldb_attr_cmp("nTSecurityDescriptor", req->op.mod.message->elements[i].name) == 0) {
699                         status = sec_access_check_ds(sd, acl_user_token(module),
700                                              SEC_STD_WRITE_DAC,
701                                              &access_granted,
702                                              NULL,
703                                              sid);
704
705                         if (!NT_STATUS_IS_OK(status)) {
706                                 DEBUG(10, ("Object %s has no write dacl access\n",
707                                            ldb_dn_get_linearized(req->op.mod.message->dn)));
708                                 dsdb_acl_debug(sd,
709                                                acl_user_token(module),
710                                                req->op.mod.message->dn,
711                                                true,
712                                                10);
713                                 ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
714                                 goto fail;
715                         }
716                 }
717                 else if (ldb_attr_cmp("member", req->op.mod.message->elements[i].name) == 0) {
718                         ret = acl_check_self_membership(tmp_ctx,
719                                                         module,
720                                                         req,
721                                                         sd,
722                                                         sid,
723                                                         guid,
724                                                         attr);
725                         if (ret != LDB_SUCCESS) {
726                                 goto fail;
727                         }
728                 }
729                 else if (ldb_attr_cmp("dBCSPwd", req->op.mod.message->elements[i].name) == 0) {
730                         /* this one is not affected by any rights, we should let it through
731                            so that passwords_hash returns the correct error */
732                         continue;
733                 }
734                 else if (ldb_attr_cmp("unicodePwd", req->op.mod.message->elements[i].name) == 0 ||
735                          ldb_attr_cmp("userPassword", req->op.mod.message->elements[i].name) == 0 ||
736                          ldb_attr_cmp("clearTextPassword", req->op.mod.message->elements[i].name) == 0) {
737                         ret = acl_check_password_rights(tmp_ctx,
738                                                         module,
739                                                         req,
740                                                         sd,
741                                                         sid,
742                                                         guid);
743                         if (ret != LDB_SUCCESS) {
744                                 goto fail;
745                         }
746                 } else {
747
748                 /* This basic attribute existence check with the right errorcode
749                  * is needed since this module is the first one which requests
750                  * schema attribute informations.
751                  * The complete attribute checking is done in the
752                  * "objectclass_attrs" module behind this one.
753                  */
754                         if (!attr) {
755                                 ldb_asprintf_errstring(ldb, "acl_modify: attribute '%s' on entry '%s' was not found in the schema!",
756                                                        req->op.mod.message->elements[i].name,
757                                                ldb_dn_get_linearized(req->op.mod.message->dn));
758                                 ret =  LDB_ERR_NO_SUCH_ATTRIBUTE;
759                                 goto fail;
760                         }
761                         if (!insert_in_object_tree(tmp_ctx,
762                                                    &attr->attributeSecurityGUID, SEC_ADS_WRITE_PROP,
763                                                    &new_node, &new_node)) {
764                                 DEBUG(10, ("acl_modify: cannot add to object tree securityGUID\n"));
765                                 ret = LDB_ERR_OPERATIONS_ERROR;
766                                 goto fail;
767                         }
768
769                         if (!insert_in_object_tree(tmp_ctx,
770                                                    &attr->schemaIDGUID, SEC_ADS_WRITE_PROP, &new_node, &new_node)) {
771                                 DEBUG(10, ("acl_modify: cannot add to object tree attributeGUID\n"));
772                                 ret = LDB_ERR_OPERATIONS_ERROR;
773                                 goto fail;
774                         }
775                 }
776         }
777
778         if (root->num_of_children > 0) {
779                 status = sec_access_check_ds(sd, acl_user_token(module),
780                                              SEC_ADS_WRITE_PROP,
781                                              &access_granted,
782                                              root,
783                                              sid);
784
785                 if (!NT_STATUS_IS_OK(status)) {
786                         DEBUG(10, ("Object %s has no write property access\n",
787                                    ldb_dn_get_linearized(req->op.mod.message->dn)));
788                         dsdb_acl_debug(sd,
789                                   acl_user_token(module),
790                                   req->op.mod.message->dn,
791                                   true,
792                                   10);
793                         ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
794                         goto fail;
795                 }
796         }
797
798 success:
799         talloc_free(tmp_ctx);
800         return ldb_next_request(module, req);
801 fail:
802         talloc_free(tmp_ctx);
803         return ret;
804 }
805
806 /* similar to the modify for the time being.
807  * We need to concider the special delete tree case, though - TODO */
808 static int acl_delete(struct ldb_module *module, struct ldb_request *req)
809 {
810         int ret;
811         struct ldb_dn *parent = ldb_dn_get_parent(req, req->op.del.dn);
812         struct ldb_context *ldb;
813         struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
814
815         if (as_system != NULL) {
816                 as_system->critical = 0;
817         }
818
819         DEBUG(10, ("ldb:acl_delete: %s\n", ldb_dn_get_linearized(req->op.del.dn)));
820         if (dsdb_module_am_system(module) || as_system) {
821                 return ldb_next_request(module, req);
822         }
823
824         if (ldb_dn_is_special(req->op.del.dn)) {
825                 return ldb_next_request(module, req);
826         }
827         ldb = ldb_module_get_ctx(module);
828         /* first check if we have delete object right */
829         ret = dsdb_module_check_access_on_dn(module, req, req->op.del.dn, SEC_STD_DELETE, NULL);
830         if (ret == LDB_SUCCESS) {
831                 return ldb_next_request(module, req);
832         }
833
834         /* Nope, we don't have delete object. Lets check if we have delete child on the parent */
835         /* No parent, so check fails */
836         /* FIXME: this has to be made dynamic at some point */
837         if ((ldb_dn_compare(req->op.del.dn, (ldb_get_schema_basedn(ldb))) == 0) ||
838             (ldb_dn_compare(req->op.del.dn, (ldb_get_config_basedn(ldb))) == 0) ||
839             (ldb_dn_compare(req->op.del.dn, (ldb_get_default_basedn(ldb))) == 0)) {
840                 DEBUG(10,("acl:deleting an NC\n"));
841                 return ldb_module_done(req, NULL, NULL, LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS);
842         }
843
844         ret = dsdb_module_check_access_on_dn(module, req, parent, SEC_ADS_DELETE_CHILD, NULL);
845         if (ret != LDB_SUCCESS) {
846                 return ret;
847         }
848         return ldb_next_request(module, req);
849 }
850
851 static int acl_rename(struct ldb_module *module, struct ldb_request *req)
852 {
853         int ret;
854         struct ldb_dn *oldparent = ldb_dn_get_parent(req, req->op.rename.olddn);
855         struct ldb_dn *newparent = ldb_dn_get_parent(req, req->op.rename.newdn);
856         const struct dsdb_schema *schema;
857         struct ldb_context *ldb;
858         struct security_descriptor *sd = NULL;
859         struct dom_sid *sid = NULL;
860         struct ldb_result *acl_res;
861         const struct GUID *guid;
862         struct object_tree *root = NULL;
863         struct object_tree *new_node = NULL;
864         struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
865         TALLOC_CTX *tmp_ctx = talloc_new(req);
866         NTSTATUS status;
867         uint32_t access_granted;
868         const char *rdn_name;
869         static const char *acl_attrs[] = {
870                 "nTSecurityDescriptor",
871                 "objectClass",
872                 "objectSid",
873                 NULL
874         };
875
876         if (as_system != NULL) {
877                 as_system->critical = 0;
878         }
879
880         DEBUG(10, ("ldb:acl_rename: %s\n", ldb_dn_get_linearized(req->op.rename.olddn)));
881         if (dsdb_module_am_system(module) || as_system) {
882                 return ldb_next_request(module, req);
883         }
884         if (ldb_dn_is_special(req->op.rename.olddn)) {
885                 return ldb_next_request(module, req);
886         }
887         ldb = ldb_module_get_ctx(module);
888
889         ret = dsdb_module_search_dn(module, req, &acl_res, req->op.rename.olddn,
890                                     acl_attrs,
891                                     DSDB_FLAG_NEXT_MODULE |
892                                     DSDB_SEARCH_SHOW_RECYCLED);
893         /* we sould be able to find the parent */
894         if (ret != LDB_SUCCESS) {
895                 DEBUG(10,("acl: failed to find object %s\n",
896                           ldb_dn_get_linearized(req->op.rename.olddn)));
897                 return ret;
898         }
899
900         schema = dsdb_get_schema(ldb, acl_res);
901         if (!schema) {
902                 talloc_free(acl_res);
903                 return ldb_operr(ldb);
904         }
905
906         guid = get_oc_guid_from_message(module, schema, acl_res->msgs[0]);
907         if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
908                                    &root, &new_node)) {
909                 return ldb_operr(ldb);
910         };
911
912         guid = attribute_schemaid_guid_by_lDAPDisplayName(schema,
913                                                           "name");
914         if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
915                                    &new_node, &new_node)) {
916                 return ldb_operr(ldb);
917         };
918
919         rdn_name = ldb_dn_get_rdn_name(req->op.rename.olddn);
920         if (rdn_name == NULL) {
921                 return ldb_operr(ldb);
922         }
923         guid = attribute_schemaid_guid_by_lDAPDisplayName(schema,
924                                                           rdn_name);
925         if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
926                                    &new_node, &new_node)) {
927                 return ldb_operr(ldb);
928         };
929
930         ret = dsdb_get_sd_from_ldb_message(ldb, req, acl_res->msgs[0], &sd);
931
932         if (ret != LDB_SUCCESS) {
933                 return ldb_operr(ldb);
934         }
935         /* Theoretically we pass the check if the object has no sd */
936         if (!sd) {
937                 return LDB_SUCCESS;
938         }
939         sid = samdb_result_dom_sid(req, acl_res->msgs[0], "objectSid");
940         status = sec_access_check_ds(sd, acl_user_token(module),
941                                      SEC_ADS_WRITE_PROP,
942                                      &access_granted,
943                                      root,
944                                      sid);
945
946         if (!NT_STATUS_IS_OK(status)) {
947                 DEBUG(10, ("Object %s has no wp on name\n",
948                            ldb_dn_get_linearized(req->op.rename.olddn)));
949                 dsdb_acl_debug(sd,
950                           acl_user_token(module),
951                           req->op.rename.olddn,
952                           true,
953                           10);
954                 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
955         }
956
957         if (ldb_dn_compare(oldparent, newparent) == 0) {
958                 /* regular rename, not move, nothing more to do */
959                 return ldb_next_request(module, req);
960         }
961
962         /* What exactly to do in this case? It would fail anyway.. */
963         /* FIXME: this has to be made dynamic at some point */
964         if ((ldb_dn_compare(req->op.rename.newdn, (ldb_get_schema_basedn(ldb))) == 0) ||
965             (ldb_dn_compare(req->op.rename.newdn, (ldb_get_config_basedn(ldb))) == 0) ||
966             (ldb_dn_compare(req->op.rename.newdn, (ldb_get_default_basedn(ldb))) == 0)) {
967                 DEBUG(10,("acl:moving as an NC\n"));
968                 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
969         }
970         /* new parent should have create child */
971         talloc_free(tmp_ctx);
972         tmp_ctx = talloc_new(req);
973         root = NULL;
974         new_node = NULL;
975         guid = get_oc_guid_from_message(module, schema, acl_res->msgs[0]);
976         if (!guid) {
977                 DEBUG(10,("acl:renamed object has no object class\n"));
978                 return ldb_module_done(req, NULL, NULL,  LDB_ERR_OPERATIONS_ERROR);
979         }
980
981         ret = dsdb_module_check_access_on_dn(module, req, newparent, SEC_ADS_CREATE_CHILD, guid);
982         if (ret != LDB_SUCCESS) {
983                 DEBUG(10,("acl:access_denied renaming %s", ldb_dn_get_linearized(req->op.rename.olddn)));
984                 return ret;
985         }
986         /* do we have delete object on the object? */
987
988         status = sec_access_check_ds(sd, acl_user_token(module),
989                                      SEC_STD_DELETE,
990                                      &access_granted,
991                                      NULL,
992                                      sid);
993
994         if (NT_STATUS_IS_OK(status)) {
995                 return ldb_next_request(module, req);
996         }
997         /* what about delete child on the current parent */
998         ret = dsdb_module_check_access_on_dn(module, req, oldparent, SEC_ADS_DELETE_CHILD, NULL);
999         if (ret != LDB_SUCCESS) {
1000                 DEBUG(10,("acl:access_denied renaming %s", ldb_dn_get_linearized(req->op.rename.olddn)));
1001                 return ldb_module_done(req, NULL, NULL, ret);
1002         }
1003         return ldb_next_request(module, req);
1004 }
1005
1006 static int acl_search_callback(struct ldb_request *req, struct ldb_reply *ares)
1007 {
1008         struct ldb_context *ldb;
1009         struct acl_context *ac;
1010         struct acl_private *data;
1011         struct ldb_result *acl_res;
1012         static const char *acl_attrs[] = {
1013                 "objectClass",
1014                 "nTSecurityDescriptor",
1015                 "objectSid",
1016                 NULL
1017         };
1018         int ret, i;
1019
1020         ac = talloc_get_type(req->context, struct acl_context);
1021         data = talloc_get_type(ldb_module_get_private(ac->module), struct acl_private);
1022         ldb = ldb_module_get_ctx(ac->module);
1023
1024         if (!ares) {
1025                 return ldb_module_done(ac->req, NULL, NULL,
1026                                        LDB_ERR_OPERATIONS_ERROR);
1027         }
1028         if (ares->error != LDB_SUCCESS) {
1029                 return ldb_module_done(ac->req, ares->controls,
1030                                        ares->response, ares->error);
1031         }
1032
1033         switch (ares->type) {
1034         case LDB_REPLY_ENTRY:
1035                 if (ac->allowedAttributes 
1036                     || ac->allowedChildClasses
1037                     || ac->allowedChildClassesEffective
1038                     || ac->allowedAttributesEffective
1039                     || ac->sDRightsEffective) {
1040                         ret = dsdb_module_search_dn(ac->module, ac, &acl_res, ares->message->dn, 
1041                                                     acl_attrs,
1042                                                     DSDB_FLAG_NEXT_MODULE);
1043                         if (ret != LDB_SUCCESS) {
1044                                 return ldb_module_done(ac->req, NULL, NULL, ret);
1045                         }
1046                         if (ac->allowedAttributes || ac->allowedAttributesEffective) {
1047                                 ret = acl_allowedAttributes(ac->module, ac->schema, acl_res->msgs[0], ares->message, ac);
1048                                 if (ret != LDB_SUCCESS) {
1049                                         return ldb_module_done(ac->req, NULL, NULL, ret);
1050                                 }
1051                         }
1052                         if (ac->allowedChildClasses) {
1053                                 ret = acl_childClasses(ac->module, ac->schema, acl_res->msgs[0],
1054                                                        ares->message, "allowedChildClasses");
1055                                 if (ret != LDB_SUCCESS) {
1056                                         return ldb_module_done(ac->req, NULL, NULL, ret);
1057                                 }
1058                         }
1059                         if (ac->allowedChildClassesEffective) {
1060                                 ret = acl_childClassesEffective(ac->module, ac->schema,
1061                                                                 acl_res->msgs[0], ares->message, ac);
1062                                 if (ret != LDB_SUCCESS) {
1063                                         return ldb_module_done(ac->req, NULL, NULL, ret);
1064                                 }
1065                         }
1066                         if (ac->sDRightsEffective) {
1067                                 ret = acl_sDRightsEffective(ac->module, 
1068                                                             acl_res->msgs[0], ares->message, ac);
1069                                 if (ret != LDB_SUCCESS) {
1070                                         return ldb_module_done(ac->req, NULL, NULL, ret);
1071                                 }
1072                         }
1073                 }
1074                 if (data && data->password_attrs) {
1075                         if (!ac->am_system) {
1076                                 for (i = 0; data->password_attrs[i]; i++) {
1077                                         ldb_msg_remove_attr(ares->message, data->password_attrs[i]);
1078                                 }
1079                         }
1080                 }
1081                 return ldb_module_send_entry(ac->req, ares->message, ares->controls);
1082
1083         case LDB_REPLY_REFERRAL:
1084                 return ldb_module_send_referral(ac->req, ares->referral);
1085
1086         case LDB_REPLY_DONE:
1087                 return ldb_module_done(ac->req, ares->controls,
1088                                        ares->response, LDB_SUCCESS);
1089
1090         }
1091         return LDB_SUCCESS;
1092 }
1093
1094 static int acl_search(struct ldb_module *module, struct ldb_request *req)
1095 {
1096         struct ldb_context *ldb;
1097         struct acl_context *ac;
1098         struct ldb_request *down_req;
1099         struct acl_private *data;
1100         int ret, i;
1101
1102         ldb = ldb_module_get_ctx(module);
1103
1104         ac = talloc_zero(req, struct acl_context);
1105         if (ac == NULL) {
1106                 return ldb_oom(ldb);
1107         }
1108         data = talloc_get_type(ldb_module_get_private(module), struct acl_private);
1109
1110         ac->module = module;
1111         ac->req = req;
1112         ac->am_system = dsdb_module_am_system(module);
1113         ac->allowedAttributes = ldb_attr_in_list(req->op.search.attrs, "allowedAttributes");
1114         ac->allowedAttributesEffective = ldb_attr_in_list(req->op.search.attrs, "allowedAttributesEffective");
1115         ac->allowedChildClasses = ldb_attr_in_list(req->op.search.attrs, "allowedChildClasses");
1116         ac->allowedChildClassesEffective = ldb_attr_in_list(req->op.search.attrs, "allowedChildClassesEffective");
1117         ac->sDRightsEffective = ldb_attr_in_list(req->op.search.attrs, "sDRightsEffective");
1118         ac->schema = dsdb_get_schema(ldb, ac);
1119
1120         /* replace any attributes in the parse tree that are private,
1121            so we don't allow a search for 'userPassword=penguin',
1122            just as we would not allow that attribute to be returned */
1123         if (ac->am_system) {
1124                 /* FIXME: We should copy the tree and keep the original unmodified. */
1125                 /* remove password attributes */
1126                 if (data && data->password_attrs) {
1127                         for (i = 0; data->password_attrs[i]; i++) {
1128                                 ldb_parse_tree_attr_replace(req->op.search.tree,
1129                                                             data->password_attrs[i],
1130                                                             "kludgeACLredactedattribute");
1131                         }
1132                 }
1133         }
1134         ret = ldb_build_search_req_ex(&down_req,
1135                                       ldb, ac,
1136                                       req->op.search.base,
1137                                       req->op.search.scope,
1138                                       req->op.search.tree,
1139                                       req->op.search.attrs,
1140                                       req->controls,
1141                                       ac, acl_search_callback,
1142                                       req);
1143         LDB_REQ_SET_LOCATION(down_req);
1144         if (ret != LDB_SUCCESS) {
1145                 return ret;
1146         }
1147         /* perform the search */
1148         return ldb_next_request(module, down_req);
1149 }
1150
1151 static int acl_extended(struct ldb_module *module, struct ldb_request *req)
1152 {
1153         struct ldb_context *ldb = ldb_module_get_ctx(module);
1154         struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
1155
1156         /* allow everybody to read the sequence number */
1157         if (strcmp(req->op.extended.oid,
1158                    LDB_EXTENDED_SEQUENCE_NUMBER) == 0) {
1159                 return ldb_next_request(module, req);
1160         }
1161
1162         if (dsdb_module_am_system(module) ||
1163             dsdb_module_am_administrator(module) || as_system) {
1164                 return ldb_next_request(module, req);
1165         } else {
1166                 ldb_asprintf_errstring(ldb,
1167                                        "acl_extended: "
1168                                        "attempted database modify not permitted. "
1169                                        "User %s is not SYSTEM or an administrator",
1170                                        acl_user_name(req, module));
1171                 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
1172         }
1173 }
1174
1175 static const struct ldb_module_ops ldb_acl_module_ops = {
1176         .name              = "acl",
1177         .search            = acl_search,
1178         .add               = acl_add,
1179         .modify            = acl_modify,
1180         .del               = acl_delete,
1181         .rename            = acl_rename,
1182         .extended          = acl_extended,
1183         .init_context      = acl_module_init
1184 };
1185
1186 int ldb_acl_module_init(const char *version)
1187 {
1188         LDB_MODULE_CHECK_VERSION(version);
1189         return ldb_register_module(&ldb_acl_module_ops);
1190 }