4 Copyright (C) Simo Sorce 2006-2008
5 Copyright (C) Nadezhda Ivanova 2009
6 Copyright (C) Anatoliy Atanasov 2009
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.
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.
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/>.
25 * Component: ldb ACL module
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
31 * Authors: Nadezhda Ivanova, Anatoliy Atanasov
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 #include "system/kerberos.h"
45 #include "auth/kerberos/kerberos.h"
47 struct extended_access_check_attribute {
49 const uint32_t requires_rights;
54 const char **password_attrs;
58 struct ldb_module *module;
59 struct ldb_request *req;
61 bool allowedAttributes;
62 bool allowedAttributesEffective;
63 bool allowedChildClasses;
64 bool allowedChildClassesEffective;
65 bool sDRightsEffective;
67 const char * const *attrs;
68 struct dsdb_schema *schema;
71 static int acl_module_init(struct ldb_module *module)
73 struct ldb_context *ldb;
74 struct acl_private *data;
78 static const char *attrs[] = { "passwordAttribute", NULL };
79 struct ldb_result *res;
80 struct ldb_message *msg;
81 struct ldb_message_element *password_attributes;
83 ldb = ldb_module_get_ctx(module);
85 ret = ldb_mod_register_control(module, LDB_CONTROL_SD_FLAGS_OID);
86 if (ret != LDB_SUCCESS) {
87 ldb_debug(ldb, LDB_DEBUG_ERROR,
88 "acl_module_init: Unable to register control with rootdse!\n");
89 return ldb_operr(ldb);
92 data = talloc(module, struct acl_private);
97 data->password_attrs = NULL;
98 data->acl_perform = lpcfg_parm_bool(ldb_get_opaque(ldb, "loadparm"),
99 NULL, "acl", "perform", false);
100 ldb_module_set_private(module, data);
102 mem_ctx = talloc_new(module);
107 ret = dsdb_module_search_dn(module, mem_ctx, &res,
108 ldb_dn_new(mem_ctx, ldb, "@KLUDGEACL"),
110 DSDB_FLAG_NEXT_MODULE, NULL);
111 if (ret != LDB_SUCCESS) {
114 if (res->count == 0) {
118 if (res->count > 1) {
119 talloc_free(mem_ctx);
120 return LDB_ERR_CONSTRAINT_VIOLATION;
125 password_attributes = ldb_msg_find_element(msg, "passwordAttribute");
126 if (!password_attributes) {
129 data->password_attrs = talloc_array(data, const char *, password_attributes->num_values + 1);
130 if (!data->password_attrs) {
131 talloc_free(mem_ctx);
134 for (i=0; i < password_attributes->num_values; i++) {
135 data->password_attrs[i] = (const char *)password_attributes->values[i].data;
136 talloc_steal(data->password_attrs, password_attributes->values[i].data);
138 data->password_attrs[i] = NULL;
141 talloc_free(mem_ctx);
142 return ldb_next_init(module);
145 static int acl_allowedAttributes(struct ldb_module *module,
146 const struct dsdb_schema *schema,
147 struct ldb_message *sd_msg,
148 struct ldb_message *msg,
149 struct acl_context *ac)
151 struct ldb_message_element *oc_el;
152 struct ldb_context *ldb = ldb_module_get_ctx(module);
154 const char **attr_list;
157 /* If we don't have a schema yet, we can't do anything... */
158 if (schema == NULL) {
159 ldb_asprintf_errstring(ldb, "cannot add allowedAttributes to %s because no schema is loaded", ldb_dn_get_linearized(msg->dn));
160 return LDB_ERR_OPERATIONS_ERROR;
163 /* Must remove any existing attribute */
164 if (ac->allowedAttributes) {
165 ldb_msg_remove_attr(msg, "allowedAttributes");
168 mem_ctx = talloc_new(msg);
173 oc_el = ldb_msg_find_element(sd_msg, "objectClass");
174 attr_list = dsdb_full_attribute_list(mem_ctx, schema, oc_el, DSDB_SCHEMA_ALL);
176 ldb_asprintf_errstring(ldb, "acl: Failed to get list of attributes");
177 talloc_free(mem_ctx);
178 return LDB_ERR_OPERATIONS_ERROR;
180 if (ac->allowedAttributes) {
181 for (i=0; attr_list && attr_list[i]; i++) {
182 ldb_msg_add_string(msg, "allowedAttributes", attr_list[i]);
185 if (ac->allowedAttributesEffective) {
186 struct security_descriptor *sd;
187 struct dom_sid *sid = NULL;
188 struct ldb_control *as_system = ldb_request_get_control(ac->req,
189 LDB_CONTROL_AS_SYSTEM_OID);
191 if (as_system != NULL) {
192 as_system->critical = 0;
195 ldb_msg_remove_attr(msg, "allowedAttributesEffective");
196 if (ac->am_system || as_system) {
197 for (i=0; attr_list && attr_list[i]; i++) {
198 ldb_msg_add_string(msg, "allowedAttributesEffective", attr_list[i]);
203 ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(module), mem_ctx, sd_msg, &sd);
205 if (ret != LDB_SUCCESS) {
209 sid = samdb_result_dom_sid(mem_ctx, sd_msg, "objectSid");
210 for (i=0; attr_list && attr_list[i]; i++) {
211 const struct dsdb_attribute *attr = dsdb_attribute_by_lDAPDisplayName(schema,
214 return ldb_operr(ldb);
216 /* remove constructed attributes */
217 if (attr->systemFlags & DS_FLAG_ATTR_IS_CONSTRUCTED
219 || (attr->linkID != 0 && attr->linkID % 2 != 0 )) {
222 ret = acl_check_access_on_attribute(module,
228 if (ret == LDB_SUCCESS) {
229 ldb_msg_add_string(msg, "allowedAttributesEffective", attr_list[i]);
236 static int acl_childClasses(struct ldb_module *module,
237 const struct dsdb_schema *schema,
238 struct ldb_message *sd_msg,
239 struct ldb_message *msg,
240 const char *attrName)
242 struct ldb_message_element *oc_el;
243 struct ldb_message_element *allowedClasses;
244 const struct dsdb_class *sclass;
248 /* If we don't have a schema yet, we can't do anything... */
249 if (schema == NULL) {
250 ldb_asprintf_errstring(ldb_module_get_ctx(module), "cannot add childClassesEffective to %s because no schema is loaded", ldb_dn_get_linearized(msg->dn));
251 return LDB_ERR_OPERATIONS_ERROR;
254 /* Must remove any existing attribute, or else confusion reins */
255 ldb_msg_remove_attr(msg, attrName);
256 ret = ldb_msg_add_empty(msg, attrName, 0, &allowedClasses);
257 if (ret != LDB_SUCCESS) {
261 oc_el = ldb_msg_find_element(sd_msg, "objectClass");
263 for (i=0; oc_el && i < oc_el->num_values; i++) {
264 sclass = dsdb_class_by_lDAPDisplayName_ldb_val(schema, &oc_el->values[i]);
266 /* We don't know this class? what is going on? */
270 for (j=0; sclass->possibleInferiors && sclass->possibleInferiors[j]; j++) {
271 ldb_msg_add_string(msg, attrName, sclass->possibleInferiors[j]);
274 if (allowedClasses->num_values > 1) {
275 TYPESAFE_QSORT(allowedClasses->values, allowedClasses->num_values, data_blob_cmp);
276 for (i=1 ; i < allowedClasses->num_values; i++) {
277 struct ldb_val *val1 = &allowedClasses->values[i-1];
278 struct ldb_val *val2 = &allowedClasses->values[i];
279 if (data_blob_cmp(val1, val2) == 0) {
280 memmove(val1, val2, (allowedClasses->num_values - i) * sizeof(struct ldb_val));
281 allowedClasses->num_values--;
290 static int acl_check_access_on_class(struct ldb_module *module,
291 const struct dsdb_schema *schema,
293 struct security_descriptor *sd,
294 struct security_token *token,
295 struct dom_sid *rp_sid,
296 uint32_t access_mask,
297 const char *class_name)
301 uint32_t access_granted;
302 struct object_tree *root = NULL;
303 struct object_tree *new_node = NULL;
304 const struct GUID *guid;
306 if (class_name != NULL) {
307 guid = class_schemaid_guid_by_lDAPDisplayName(schema, class_name);
309 DEBUG(10, ("acl_search: cannot find class %s\n",
313 if (!insert_in_object_tree(mem_ctx,
316 DEBUG(10, ("acl_search: cannot add to object tree guid\n"));
321 status = sec_access_check_ds(sd, token,
326 if (!NT_STATUS_IS_OK(status)) {
327 ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
333 return ldb_operr(ldb_module_get_ctx(module));
336 static int acl_childClassesEffective(struct ldb_module *module,
337 const struct dsdb_schema *schema,
338 struct ldb_message *sd_msg,
339 struct ldb_message *msg,
340 struct acl_context *ac)
342 struct ldb_message_element *oc_el;
343 struct ldb_message_element *allowedClasses = NULL;
344 const struct dsdb_class *sclass;
345 struct security_descriptor *sd;
346 struct ldb_control *as_system = ldb_request_get_control(ac->req,
347 LDB_CONTROL_AS_SYSTEM_OID);
348 struct dom_sid *sid = NULL;
352 if (as_system != NULL) {
353 as_system->critical = 0;
356 if (ac->am_system || as_system) {
357 return acl_childClasses(module, schema, sd_msg, msg, "allowedChildClassesEffective");
360 /* If we don't have a schema yet, we can't do anything... */
361 if (schema == NULL) {
362 ldb_asprintf_errstring(ldb_module_get_ctx(module), "cannot add allowedChildClassesEffective to %s because no schema is loaded", ldb_dn_get_linearized(msg->dn));
363 return LDB_ERR_OPERATIONS_ERROR;
366 /* Must remove any existing attribute, or else confusion reins */
367 ldb_msg_remove_attr(msg, "allowedChildClassesEffective");
369 oc_el = ldb_msg_find_element(sd_msg, "objectClass");
370 ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(module), msg, sd_msg, &sd);
371 if (ret != LDB_SUCCESS) {
375 sid = samdb_result_dom_sid(msg, sd_msg, "objectSid");
376 for (i=0; oc_el && i < oc_el->num_values; i++) {
377 sclass = dsdb_class_by_lDAPDisplayName_ldb_val(schema, &oc_el->values[i]);
379 /* We don't know this class? what is going on? */
383 for (j=0; sclass->possibleInferiors && sclass->possibleInferiors[j]; j++) {
384 ret = acl_check_access_on_class(module,
388 acl_user_token(module),
390 SEC_ADS_CREATE_CHILD,
391 sclass->possibleInferiors[j]);
392 if (ret == LDB_SUCCESS) {
393 ldb_msg_add_string(msg, "allowedChildClassesEffective",
394 sclass->possibleInferiors[j]);
398 allowedClasses = ldb_msg_find_element(msg, "allowedChildClassesEffective");
399 if (!allowedClasses) {
403 if (allowedClasses->num_values > 1) {
404 TYPESAFE_QSORT(allowedClasses->values, allowedClasses->num_values, data_blob_cmp);
405 for (i=1 ; i < allowedClasses->num_values; i++) {
406 struct ldb_val *val1 = &allowedClasses->values[i-1];
407 struct ldb_val *val2 = &allowedClasses->values[i];
408 if (data_blob_cmp(val1, val2) == 0) {
409 memmove(val1, val2, (allowedClasses->num_values - i) * sizeof( struct ldb_val));
410 allowedClasses->num_values--;
418 static int acl_sDRightsEffective(struct ldb_module *module,
419 struct ldb_message *sd_msg,
420 struct ldb_message *msg,
421 struct acl_context *ac)
423 struct ldb_message_element *rightsEffective;
425 struct security_descriptor *sd;
426 struct ldb_control *as_system = ldb_request_get_control(ac->req,
427 LDB_CONTROL_AS_SYSTEM_OID);
428 struct dom_sid *sid = NULL;
431 if (as_system != NULL) {
432 as_system->critical = 0;
435 /* Must remove any existing attribute, or else confusion reins */
436 ldb_msg_remove_attr(msg, "sDRightsEffective");
437 ret = ldb_msg_add_empty(msg, "sDRightsEffective", 0, &rightsEffective);
438 if (ret != LDB_SUCCESS) {
441 if (ac->am_system || as_system) {
442 flags = SECINFO_OWNER | SECINFO_GROUP | SECINFO_SACL | SECINFO_DACL;
445 /* Get the security descriptor from the message */
446 ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(module), msg, sd_msg, &sd);
447 if (ret != LDB_SUCCESS) {
450 sid = samdb_result_dom_sid(msg, sd_msg, "objectSid");
451 ret = acl_check_access_on_attribute(module,
457 if (ret == LDB_SUCCESS) {
458 flags |= SECINFO_OWNER | SECINFO_GROUP;
460 ret = acl_check_access_on_attribute(module,
466 if (ret == LDB_SUCCESS) {
467 flags |= SECINFO_DACL;
469 ret = acl_check_access_on_attribute(module,
473 SEC_FLAG_SYSTEM_SECURITY,
475 if (ret == LDB_SUCCESS) {
476 flags |= SECINFO_SACL;
479 return samdb_msg_add_uint(ldb_module_get_ctx(module), msg, msg,
480 "sDRightsEffective", flags);
483 static int acl_validate_spn_value(TALLOC_CTX *mem_ctx,
484 struct ldb_context *ldb,
485 const char *spn_value,
486 uint32_t userAccountControl,
487 const char *samAccountName,
488 const char *dnsHostName,
489 const char *netbios_name,
490 const char *ntds_guid)
493 krb5_context krb_ctx;
494 krb5_error_code kerr;
495 krb5_principal principal;
499 const char *forest_name = samdb_forest_name(ldb, mem_ctx);
500 const char *base_domain = samdb_default_domain_name(ldb, mem_ctx);
501 struct loadparm_context *lp_ctx = talloc_get_type(ldb_get_opaque(ldb, "loadparm"),
502 struct loadparm_context);
503 bool is_dc = (userAccountControl & UF_SERVER_TRUST_ACCOUNT) ||
504 (userAccountControl & UF_PARTIAL_SECRETS_ACCOUNT);
506 if (strcasecmp_m(spn_value, samAccountName) == 0) {
507 /* MacOS X sets this value, and setting an SPN of your
508 * own samAccountName is both pointless and safe */
512 kerr = smb_krb5_init_context_basic(mem_ctx,
516 return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR,
517 "Could not initialize kerberos context.");
520 ret = krb5_parse_name(krb_ctx, spn_value, &principal);
522 krb5_free_context(krb_ctx);
523 return LDB_ERR_CONSTRAINT_VIOLATION;
526 if (principal->name.name_string.len < 2) {
530 instanceName = principal->name.name_string.val[1];
531 serviceType = principal->name.name_string.val[0];
532 if (principal->name.name_string.len == 3) {
533 serviceName = principal->name.name_string.val[2];
542 if (strcasecmp(serviceType, "ldap") == 0) {
543 if (strcasecmp(serviceName, netbios_name) != 0 &&
544 strcasecmp(serviceName, forest_name) != 0) {
548 } else if (strcasecmp(serviceType, "gc") == 0) {
549 if (strcasecmp(serviceName, forest_name) != 0) {
553 if (strcasecmp(serviceName, base_domain) != 0 &&
554 strcasecmp(serviceName, netbios_name) != 0) {
559 /* instanceName can be samAccountName without $ or dnsHostName
560 * or "ntds_guid._msdcs.forest_domain for DC objects */
561 if (strlen(instanceName) == (strlen(samAccountName) - 1)
562 && strncasecmp(instanceName, samAccountName, strlen(samAccountName) - 1) == 0) {
564 } else if (dnsHostName != NULL && strcasecmp(instanceName, dnsHostName) == 0) {
567 const char *guid_str;
568 guid_str = talloc_asprintf(mem_ctx,"%s._msdcs.%s",
571 if (strcasecmp(instanceName, guid_str) == 0) {
577 krb5_free_principal(krb_ctx, principal);
578 krb5_free_context(krb_ctx);
579 return LDB_ERR_CONSTRAINT_VIOLATION;
582 krb5_free_principal(krb_ctx, principal);
583 krb5_free_context(krb_ctx);
587 static int acl_check_spn(TALLOC_CTX *mem_ctx,
588 struct ldb_module *module,
589 struct ldb_request *req,
590 struct security_descriptor *sd,
592 const struct GUID *oc_guid,
593 const struct dsdb_attribute *attr)
597 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
598 struct ldb_context *ldb = ldb_module_get_ctx(module);
599 struct ldb_result *acl_res;
600 struct ldb_result *netbios_res;
601 struct ldb_message_element *el;
602 struct ldb_dn *partitions_dn = samdb_partitions_dn(ldb, tmp_ctx);
603 uint32_t userAccountControl;
604 const char *samAccountName;
605 const char *dnsHostName;
606 const char *netbios_name;
608 char *ntds_guid = NULL;
610 static const char *acl_attrs[] = {
613 "userAccountControl",
616 static const char *netbios_attrs[] = {
621 /* if we have wp, we can do whatever we like */
622 if (acl_check_access_on_attribute(module,
627 attr) == LDB_SUCCESS) {
628 talloc_free(tmp_ctx);
632 ret = acl_check_extended_right(tmp_ctx, sd, acl_user_token(module),
633 GUID_DRS_VALIDATE_SPN,
637 if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
638 dsdb_acl_debug(sd, acl_user_token(module),
639 req->op.mod.message->dn,
642 talloc_free(tmp_ctx);
646 ret = dsdb_module_search_dn(module, tmp_ctx,
647 &acl_res, req->op.mod.message->dn,
649 DSDB_FLAG_NEXT_MODULE |
650 DSDB_SEARCH_SHOW_DELETED, req);
651 if (ret != LDB_SUCCESS) {
652 talloc_free(tmp_ctx);
656 userAccountControl = ldb_msg_find_attr_as_uint(acl_res->msgs[0], "userAccountControl", 0);
657 dnsHostName = ldb_msg_find_attr_as_string(acl_res->msgs[0], "dnsHostName", NULL);
658 samAccountName = ldb_msg_find_attr_as_string(acl_res->msgs[0], "samAccountName", NULL);
660 ret = dsdb_module_search(module, tmp_ctx,
661 &netbios_res, partitions_dn,
664 DSDB_FLAG_NEXT_MODULE,
667 ldb_dn_get_linearized(ldb_get_default_basedn(ldb)));
669 netbios_name = ldb_msg_find_attr_as_string(netbios_res->msgs[0], "nETBIOSName", NULL);
671 el = ldb_msg_find_element(req->op.mod.message, "servicePrincipalName");
673 talloc_free(tmp_ctx);
674 return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR,
675 "Error finding element for servicePrincipalName.");
678 /* NTDSDSA objectGuid of object we are checking SPN for */
679 if (userAccountControl & (UF_SERVER_TRUST_ACCOUNT | UF_PARTIAL_SECRETS_ACCOUNT)) {
680 ret = dsdb_module_find_ntdsguid_for_computer(module, tmp_ctx,
681 req->op.mod.message->dn, &ntds, req);
682 if (ret != LDB_SUCCESS) {
683 ldb_asprintf_errstring(ldb, "Failed to find NTDSDSA objectGuid for %s: %s",
684 ldb_dn_get_linearized(req->op.mod.message->dn),
686 talloc_free(tmp_ctx);
687 return LDB_ERR_OPERATIONS_ERROR;
689 ntds_guid = GUID_string(tmp_ctx, &ntds);
692 for (i=0; i < el->num_values; i++) {
693 ret = acl_validate_spn_value(tmp_ctx,
695 (char *)el->values[i].data,
701 if (ret != LDB_SUCCESS) {
702 talloc_free(tmp_ctx);
706 talloc_free(tmp_ctx);
710 static int acl_add(struct ldb_module *module, struct ldb_request *req)
713 struct ldb_dn *parent = ldb_dn_get_parent(req, req->op.add.message->dn);
714 struct ldb_context *ldb;
715 const struct dsdb_schema *schema;
716 struct ldb_message_element *oc_el;
717 const struct GUID *guid;
718 struct ldb_dn *nc_root;
719 struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
721 if (as_system != NULL) {
722 as_system->critical = 0;
725 if (dsdb_module_am_system(module) || as_system) {
726 return ldb_next_request(module, req);
728 if (ldb_dn_is_special(req->op.add.message->dn)) {
729 return ldb_next_request(module, req);
732 ldb = ldb_module_get_ctx(module);
734 /* Creating an NC. There is probably something we should do here,
735 * but we will establish that later */
737 ret = dsdb_find_nc_root(ldb, req, req->op.add.message->dn, &nc_root);
738 if (ret != LDB_SUCCESS) {
741 if (ldb_dn_compare(nc_root, req->op.add.message->dn) == 0) {
742 talloc_free(nc_root);
743 return ldb_next_request(module, req);
745 talloc_free(nc_root);
747 schema = dsdb_get_schema(ldb, req);
749 return ldb_operr(ldb);
752 oc_el = ldb_msg_find_element(req->op.add.message, "objectClass");
753 if (!oc_el || oc_el->num_values == 0) {
754 ldb_asprintf_errstring(ldb_module_get_ctx(module),
755 "acl: unable to find objectClass on %s\n",
756 ldb_dn_get_linearized(req->op.add.message->dn));
757 return ldb_module_done(req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
760 guid = class_schemaid_guid_by_lDAPDisplayName(schema,
761 (char *)oc_el->values[oc_el->num_values-1].data);
762 ret = dsdb_module_check_access_on_dn(module, req, parent, SEC_ADS_CREATE_CHILD, guid, req);
763 if (ret != LDB_SUCCESS) {
766 return ldb_next_request(module, req);
769 /* ckecks if modifications are allowed on "Member" attribute */
770 static int acl_check_self_membership(TALLOC_CTX *mem_ctx,
771 struct ldb_module *module,
772 struct ldb_request *req,
773 struct security_descriptor *sd,
775 const struct GUID *oc_guid,
776 const struct dsdb_attribute *attr)
780 struct ldb_context *ldb = ldb_module_get_ctx(module);
781 struct ldb_dn *user_dn;
782 struct ldb_message_element *member_el;
783 /* if we have wp, we can do whatever we like */
784 if (acl_check_access_on_attribute(module,
789 attr) == LDB_SUCCESS) {
792 /* if we are adding/deleting ourselves, check for self membership */
793 ret = dsdb_find_dn_by_sid(ldb, mem_ctx,
794 &acl_user_token(module)->sids[PRIMARY_USER_SID_INDEX],
796 if (ret != LDB_SUCCESS) {
799 member_el = ldb_msg_find_element(req->op.mod.message, "member");
801 return ldb_operr(ldb);
803 /* user can only remove oneself */
804 if (member_el->num_values == 0) {
805 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
807 for (i = 0; i < member_el->num_values; i++) {
808 if (strcasecmp((const char *)member_el->values[i].data,
809 ldb_dn_get_extended_linearized(mem_ctx, user_dn, 1)) != 0) {
810 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
813 ret = acl_check_extended_right(mem_ctx, sd, acl_user_token(module),
814 GUID_DRS_SELF_MEMBERSHIP,
817 if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
818 dsdb_acl_debug(sd, acl_user_token(module),
819 req->op.mod.message->dn,
826 static int acl_check_password_rights(TALLOC_CTX *mem_ctx,
827 struct ldb_module *module,
828 struct ldb_request *req,
829 struct security_descriptor *sd,
831 const struct GUID *oc_guid,
834 int ret = LDB_SUCCESS;
835 unsigned int del_attr_cnt = 0, add_attr_cnt = 0, rep_attr_cnt = 0;
836 struct ldb_message_element *el;
837 struct ldb_message *msg;
838 const char *passwordAttrs[] = { "userPassword", "clearTextPassword",
839 "unicodePwd", "dBCSPwd", NULL }, **l;
840 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
842 msg = ldb_msg_copy_shallow(tmp_ctx, req->op.mod.message);
844 return ldb_module_oom(module);
846 for (l = passwordAttrs; *l != NULL; l++) {
847 if ((!userPassword) && (ldb_attr_cmp(*l, "userPassword") == 0)) {
851 while ((el = ldb_msg_find_element(msg, *l)) != NULL) {
852 if (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE) {
855 if (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_ADD) {
858 if (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) {
861 ldb_msg_remove_element(msg, el);
865 /* single deletes will be handled by the "password_hash" LDB module
866 * later in the stack, so we let it though here */
867 if ((del_attr_cnt > 0) && (add_attr_cnt == 0) && (rep_attr_cnt == 0)) {
868 talloc_free(tmp_ctx);
872 if (ldb_request_get_control(req,
873 DSDB_CONTROL_PASSWORD_CHANGE_OID) != NULL) {
874 /* The "DSDB_CONTROL_PASSWORD_CHANGE_OID" control means that we
875 * have a user password change and not a set as the message
876 * looks like. In it's value blob it contains the NT and/or LM
877 * hash of the old password specified by the user.
878 * This control is used by the SAMR and "kpasswd" password
879 * change mechanisms. */
880 ret = acl_check_extended_right(tmp_ctx, sd, acl_user_token(module),
881 GUID_DRS_USER_CHANGE_PASSWORD,
882 SEC_ADS_CONTROL_ACCESS,
885 else if (rep_attr_cnt > 0 || (add_attr_cnt != del_attr_cnt)) {
886 ret = acl_check_extended_right(tmp_ctx, sd, acl_user_token(module),
887 GUID_DRS_FORCE_CHANGE_PASSWORD,
888 SEC_ADS_CONTROL_ACCESS,
891 else if (add_attr_cnt == 1 && del_attr_cnt == 1) {
892 ret = acl_check_extended_right(tmp_ctx, sd, acl_user_token(module),
893 GUID_DRS_USER_CHANGE_PASSWORD,
894 SEC_ADS_CONTROL_ACCESS,
896 /* Very strange, but we get constraint violation in this case */
897 if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
898 ret = LDB_ERR_CONSTRAINT_VIOLATION;
901 if (ret != LDB_SUCCESS) {
902 dsdb_acl_debug(sd, acl_user_token(module),
903 req->op.mod.message->dn,
907 talloc_free(tmp_ctx);
911 static int acl_modify(struct ldb_module *module, struct ldb_request *req)
914 struct ldb_context *ldb = ldb_module_get_ctx(module);
915 const struct dsdb_schema *schema;
917 const struct GUID *guid;
918 uint32_t access_granted;
919 struct object_tree *root = NULL;
920 struct object_tree *new_node = NULL;
922 struct ldb_result *acl_res;
923 struct security_descriptor *sd;
924 struct dom_sid *sid = NULL;
925 struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
926 bool userPassword = dsdb_user_password_support(module, req, req);
927 TALLOC_CTX *tmp_ctx = talloc_new(req);
928 static const char *acl_attrs[] = {
929 "nTSecurityDescriptor",
935 if (as_system != NULL) {
936 as_system->critical = 0;
939 /* Don't print this debug statement if elements[0].name is going to be NULL */
940 if(req->op.mod.message->num_elements > 0)
942 DEBUG(10, ("ldb:acl_modify: %s\n", req->op.mod.message->elements[0].name));
944 if (dsdb_module_am_system(module) || as_system) {
945 return ldb_next_request(module, req);
947 if (ldb_dn_is_special(req->op.mod.message->dn)) {
948 return ldb_next_request(module, req);
950 ret = dsdb_module_search_dn(module, tmp_ctx, &acl_res, req->op.mod.message->dn,
952 DSDB_FLAG_NEXT_MODULE | DSDB_SEARCH_SHOW_DELETED,
955 if (ret != LDB_SUCCESS) {
959 schema = dsdb_get_schema(ldb, tmp_ctx);
961 ret = LDB_ERR_OPERATIONS_ERROR;
965 ret = dsdb_get_sd_from_ldb_message(ldb, tmp_ctx, acl_res->msgs[0], &sd);
966 if (ret != LDB_SUCCESS) {
967 talloc_free(tmp_ctx);
968 return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR,
969 "acl_modify: Error retrieving security descriptor.");
971 /* Theoretically we pass the check if the object has no sd */
976 guid = get_oc_guid_from_message(module, schema, acl_res->msgs[0]);
978 talloc_free(tmp_ctx);
979 return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR,
980 "acl_modify: Error retrieving object class GUID.");
982 sid = samdb_result_dom_sid(req, acl_res->msgs[0], "objectSid");
983 if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
985 talloc_free(tmp_ctx);
986 return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR,
987 "acl_modify: Error adding new node in object tree.");
989 for (i=0; i < req->op.mod.message->num_elements; i++){
990 const struct dsdb_attribute *attr;
991 attr = dsdb_attribute_by_lDAPDisplayName(schema,
992 req->op.mod.message->elements[i].name);
994 if (ldb_attr_cmp("nTSecurityDescriptor", req->op.mod.message->elements[i].name) == 0) {
995 status = sec_access_check_ds(sd, acl_user_token(module),
1001 if (!NT_STATUS_IS_OK(status)) {
1002 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1003 "Object %s has no write dacl access\n",
1004 ldb_dn_get_linearized(req->op.mod.message->dn));
1006 acl_user_token(module),
1007 req->op.mod.message->dn,
1010 ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
1014 else if (ldb_attr_cmp("member", req->op.mod.message->elements[i].name) == 0) {
1015 ret = acl_check_self_membership(tmp_ctx,
1022 if (ret != LDB_SUCCESS) {
1026 else if (ldb_attr_cmp("dBCSPwd", req->op.mod.message->elements[i].name) == 0) {
1027 /* this one is not affected by any rights, we should let it through
1028 so that passwords_hash returns the correct error */
1031 else if (ldb_attr_cmp("unicodePwd", req->op.mod.message->elements[i].name) == 0 ||
1032 (userPassword && ldb_attr_cmp("userPassword", req->op.mod.message->elements[i].name) == 0) ||
1033 ldb_attr_cmp("clearTextPassword", req->op.mod.message->elements[i].name) == 0) {
1034 ret = acl_check_password_rights(tmp_ctx,
1041 if (ret != LDB_SUCCESS) {
1044 } else if (ldb_attr_cmp("servicePrincipalName", req->op.mod.message->elements[i].name) == 0) {
1045 ret = acl_check_spn(tmp_ctx,
1052 if (ret != LDB_SUCCESS) {
1057 /* This basic attribute existence check with the right errorcode
1058 * is needed since this module is the first one which requests
1059 * schema attribute information.
1060 * The complete attribute checking is done in the
1061 * "objectclass_attrs" module behind this one.
1064 ldb_asprintf_errstring(ldb, "acl_modify: attribute '%s' on entry '%s' was not found in the schema!",
1065 req->op.mod.message->elements[i].name,
1066 ldb_dn_get_linearized(req->op.mod.message->dn));
1067 ret = LDB_ERR_NO_SUCH_ATTRIBUTE;
1070 if (!insert_in_object_tree(tmp_ctx,
1071 &attr->attributeSecurityGUID, SEC_ADS_WRITE_PROP,
1072 &new_node, &new_node)) {
1073 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1074 "acl_modify: cannot add to object tree securityGUID\n");
1075 ret = LDB_ERR_OPERATIONS_ERROR;
1079 if (!insert_in_object_tree(tmp_ctx,
1080 &attr->schemaIDGUID, SEC_ADS_WRITE_PROP, &new_node, &new_node)) {
1081 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1082 "acl_modify: cannot add to object tree attributeGUID\n");
1083 ret = LDB_ERR_OPERATIONS_ERROR;
1089 if (root->num_of_children > 0) {
1090 status = sec_access_check_ds(sd, acl_user_token(module),
1096 if (!NT_STATUS_IS_OK(status)) {
1097 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1098 "Object %s has no write property access\n",
1099 ldb_dn_get_linearized(req->op.mod.message->dn));
1101 acl_user_token(module),
1102 req->op.mod.message->dn,
1105 ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
1111 talloc_free(tmp_ctx);
1112 return ldb_next_request(module, req);
1114 talloc_free(tmp_ctx);
1118 /* similar to the modify for the time being.
1119 * We need to consider the special delete tree case, though - TODO */
1120 static int acl_delete(struct ldb_module *module, struct ldb_request *req)
1123 struct ldb_dn *parent = ldb_dn_get_parent(req, req->op.del.dn);
1124 struct ldb_context *ldb;
1125 struct ldb_dn *nc_root;
1126 struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
1128 if (as_system != NULL) {
1129 as_system->critical = 0;
1132 DEBUG(10, ("ldb:acl_delete: %s\n", ldb_dn_get_linearized(req->op.del.dn)));
1133 if (dsdb_module_am_system(module) || as_system) {
1134 return ldb_next_request(module, req);
1136 if (ldb_dn_is_special(req->op.del.dn)) {
1137 return ldb_next_request(module, req);
1140 ldb = ldb_module_get_ctx(module);
1142 /* Make sure we aren't deleting a NC */
1144 ret = dsdb_find_nc_root(ldb, req, req->op.del.dn, &nc_root);
1145 if (ret != LDB_SUCCESS) {
1148 if (ldb_dn_compare(nc_root, req->op.del.dn) == 0) {
1149 talloc_free(nc_root);
1150 DEBUG(10,("acl:deleting a NC\n"));
1151 /* Windows returns "ERR_UNWILLING_TO_PERFORM */
1152 return ldb_module_done(req, NULL, NULL,
1153 LDB_ERR_UNWILLING_TO_PERFORM);
1155 talloc_free(nc_root);
1157 /* First check if we have delete object right */
1158 ret = dsdb_module_check_access_on_dn(module, req, req->op.del.dn,
1159 SEC_STD_DELETE, NULL, req);
1160 if (ret == LDB_SUCCESS) {
1161 return ldb_next_request(module, req);
1164 /* Nope, we don't have delete object. Lets check if we have delete
1165 * child on the parent */
1166 ret = dsdb_module_check_access_on_dn(module, req, parent,
1167 SEC_ADS_DELETE_CHILD, NULL, req);
1168 if (ret != LDB_SUCCESS) {
1172 return ldb_next_request(module, req);
1175 static int acl_rename(struct ldb_module *module, struct ldb_request *req)
1178 struct ldb_dn *oldparent = ldb_dn_get_parent(req, req->op.rename.olddn);
1179 struct ldb_dn *newparent = ldb_dn_get_parent(req, req->op.rename.newdn);
1180 const struct dsdb_schema *schema;
1181 struct ldb_context *ldb;
1182 struct security_descriptor *sd = NULL;
1183 struct dom_sid *sid = NULL;
1184 struct ldb_result *acl_res;
1185 const struct GUID *guid;
1186 struct ldb_dn *nc_root;
1187 struct object_tree *root = NULL;
1188 struct object_tree *new_node = NULL;
1189 struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
1190 TALLOC_CTX *tmp_ctx = talloc_new(req);
1192 uint32_t access_granted;
1193 const char *rdn_name;
1194 static const char *acl_attrs[] = {
1195 "nTSecurityDescriptor",
1201 if (as_system != NULL) {
1202 as_system->critical = 0;
1205 DEBUG(10, ("ldb:acl_rename: %s\n", ldb_dn_get_linearized(req->op.rename.olddn)));
1206 if (dsdb_module_am_system(module) || as_system) {
1207 return ldb_next_request(module, req);
1209 if (ldb_dn_is_special(req->op.rename.olddn)) {
1210 return ldb_next_request(module, req);
1213 ldb = ldb_module_get_ctx(module);
1215 /* Make sure we aren't renaming/moving a NC */
1217 ret = dsdb_find_nc_root(ldb, req, req->op.rename.olddn, &nc_root);
1218 if (ret != LDB_SUCCESS) {
1221 if (ldb_dn_compare(nc_root, req->op.rename.olddn) == 0) {
1222 talloc_free(nc_root);
1223 DEBUG(10,("acl:renaming/moving a NC\n"));
1224 /* Windows returns "ERR_UNWILLING_TO_PERFORM */
1225 return ldb_module_done(req, NULL, NULL,
1226 LDB_ERR_UNWILLING_TO_PERFORM);
1228 talloc_free(nc_root);
1230 /* Look for the parent */
1232 ret = dsdb_module_search_dn(module, tmp_ctx, &acl_res,
1233 req->op.rename.olddn, acl_attrs,
1234 DSDB_FLAG_NEXT_MODULE |
1235 DSDB_SEARCH_SHOW_RECYCLED, req);
1236 /* we sould be able to find the parent */
1237 if (ret != LDB_SUCCESS) {
1238 DEBUG(10,("acl: failed to find object %s\n",
1239 ldb_dn_get_linearized(req->op.rename.olddn)));
1240 talloc_free(tmp_ctx);
1244 schema = dsdb_get_schema(ldb, acl_res);
1246 talloc_free(tmp_ctx);
1247 return ldb_operr(ldb);
1250 guid = get_oc_guid_from_message(module, schema, acl_res->msgs[0]);
1251 if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
1252 &root, &new_node)) {
1253 talloc_free(tmp_ctx);
1254 return ldb_operr(ldb);
1257 guid = attribute_schemaid_guid_by_lDAPDisplayName(schema,
1259 if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
1260 &new_node, &new_node)) {
1261 talloc_free(tmp_ctx);
1262 return ldb_operr(ldb);
1265 rdn_name = ldb_dn_get_rdn_name(req->op.rename.olddn);
1266 if (rdn_name == NULL) {
1267 talloc_free(tmp_ctx);
1268 return ldb_operr(ldb);
1270 guid = attribute_schemaid_guid_by_lDAPDisplayName(schema,
1272 if (!insert_in_object_tree(tmp_ctx, guid, SEC_ADS_WRITE_PROP,
1273 &new_node, &new_node)) {
1274 talloc_free(tmp_ctx);
1275 return ldb_operr(ldb);
1278 ret = dsdb_get_sd_from_ldb_message(ldb, req, acl_res->msgs[0], &sd);
1280 if (ret != LDB_SUCCESS) {
1281 talloc_free(tmp_ctx);
1282 return ldb_operr(ldb);
1284 /* Theoretically we pass the check if the object has no sd */
1286 talloc_free(tmp_ctx);
1289 sid = samdb_result_dom_sid(req, acl_res->msgs[0], "objectSid");
1290 status = sec_access_check_ds(sd, acl_user_token(module),
1296 if (!NT_STATUS_IS_OK(status)) {
1297 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1298 "Object %s has no wp on name\n",
1299 ldb_dn_get_linearized(req->op.rename.olddn));
1301 acl_user_token(module),
1302 req->op.rename.olddn,
1305 talloc_free(tmp_ctx);
1306 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
1309 if (ldb_dn_compare(oldparent, newparent) == 0) {
1310 /* regular rename, not move, nothing more to do */
1311 talloc_free(tmp_ctx);
1312 return ldb_next_request(module, req);
1315 /* new parent should have create child */
1318 guid = get_oc_guid_from_message(module, schema, acl_res->msgs[0]);
1320 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1321 "acl:renamed object has no object class\n");
1322 talloc_free(tmp_ctx);
1323 return ldb_module_done(req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
1326 ret = dsdb_module_check_access_on_dn(module, req, newparent, SEC_ADS_CREATE_CHILD, guid, req);
1327 if (ret != LDB_SUCCESS) {
1328 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1329 "acl:access_denied renaming %s",
1330 ldb_dn_get_linearized(req->op.rename.olddn));
1331 talloc_free(tmp_ctx);
1334 /* do we have delete object on the object? */
1336 status = sec_access_check_ds(sd, acl_user_token(module),
1342 if (NT_STATUS_IS_OK(status)) {
1343 talloc_free(tmp_ctx);
1344 return ldb_next_request(module, req);
1346 /* what about delete child on the current parent */
1347 ret = dsdb_module_check_access_on_dn(module, req, oldparent, SEC_ADS_DELETE_CHILD, NULL, req);
1348 if (ret != LDB_SUCCESS) {
1349 ldb_asprintf_errstring(ldb_module_get_ctx(module),
1350 "acl:access_denied renaming %s", ldb_dn_get_linearized(req->op.rename.olddn));
1351 talloc_free(tmp_ctx);
1352 return ldb_module_done(req, NULL, NULL, ret);
1355 talloc_free(tmp_ctx);
1357 return ldb_next_request(module, req);
1360 static int acl_search_callback(struct ldb_request *req, struct ldb_reply *ares)
1362 struct acl_context *ac;
1363 struct acl_private *data;
1364 struct ldb_result *acl_res;
1365 static const char *acl_attrs[] = {
1367 "nTSecurityDescriptor",
1374 ac = talloc_get_type(req->context, struct acl_context);
1375 data = talloc_get_type(ldb_module_get_private(ac->module), struct acl_private);
1377 return ldb_module_done(ac->req, NULL, NULL,
1378 LDB_ERR_OPERATIONS_ERROR);
1380 if (ares->error != LDB_SUCCESS) {
1381 return ldb_module_done(ac->req, ares->controls,
1382 ares->response, ares->error);
1385 switch (ares->type) {
1386 case LDB_REPLY_ENTRY:
1387 if (ac->allowedAttributes
1388 || ac->allowedChildClasses
1389 || ac->allowedChildClassesEffective
1390 || ac->allowedAttributesEffective
1391 || ac->sDRightsEffective) {
1392 ret = dsdb_module_search_dn(ac->module, ac, &acl_res, ares->message->dn,
1394 DSDB_FLAG_NEXT_MODULE |
1395 DSDB_SEARCH_SHOW_DELETED, req);
1396 if (ret != LDB_SUCCESS) {
1397 return ldb_module_done(ac->req, NULL, NULL, ret);
1399 if (ac->allowedAttributes || ac->allowedAttributesEffective) {
1400 ret = acl_allowedAttributes(ac->module, ac->schema, acl_res->msgs[0], ares->message, ac);
1401 if (ret != LDB_SUCCESS) {
1402 return ldb_module_done(ac->req, NULL, NULL, ret);
1405 if (ac->allowedChildClasses) {
1406 ret = acl_childClasses(ac->module, ac->schema, acl_res->msgs[0],
1407 ares->message, "allowedChildClasses");
1408 if (ret != LDB_SUCCESS) {
1409 return ldb_module_done(ac->req, NULL, NULL, ret);
1412 if (ac->allowedChildClassesEffective) {
1413 ret = acl_childClassesEffective(ac->module, ac->schema,
1414 acl_res->msgs[0], ares->message, ac);
1415 if (ret != LDB_SUCCESS) {
1416 return ldb_module_done(ac->req, NULL, NULL, ret);
1419 if (ac->sDRightsEffective) {
1420 ret = acl_sDRightsEffective(ac->module,
1421 acl_res->msgs[0], ares->message, ac);
1422 if (ret != LDB_SUCCESS) {
1423 return ldb_module_done(ac->req, NULL, NULL, ret);
1427 if (data && data->password_attrs) {
1428 if (!ac->am_system) {
1429 for (i = 0; data->password_attrs[i]; i++) {
1430 if ((!ac->userPassword) &&
1431 (ldb_attr_cmp(data->password_attrs[i],
1432 "userPassword") == 0))
1435 ldb_msg_remove_attr(ares->message, data->password_attrs[i]);
1439 return ldb_module_send_entry(ac->req, ares->message, ares->controls);
1441 case LDB_REPLY_REFERRAL:
1442 return ldb_module_send_referral(ac->req, ares->referral);
1444 case LDB_REPLY_DONE:
1445 return ldb_module_done(ac->req, ares->controls,
1446 ares->response, LDB_SUCCESS);
1452 static int acl_search(struct ldb_module *module, struct ldb_request *req)
1454 struct ldb_context *ldb;
1455 struct acl_context *ac;
1456 struct ldb_request *down_req;
1457 struct acl_private *data;
1461 ldb = ldb_module_get_ctx(module);
1463 ac = talloc_zero(req, struct acl_context);
1465 return ldb_oom(ldb);
1467 data = talloc_get_type(ldb_module_get_private(module), struct acl_private);
1469 ac->module = module;
1471 ac->am_system = dsdb_module_am_system(module);
1472 ac->allowedAttributes = ldb_attr_in_list(req->op.search.attrs, "allowedAttributes");
1473 ac->allowedAttributesEffective = ldb_attr_in_list(req->op.search.attrs, "allowedAttributesEffective");
1474 ac->allowedChildClasses = ldb_attr_in_list(req->op.search.attrs, "allowedChildClasses");
1475 ac->allowedChildClassesEffective = ldb_attr_in_list(req->op.search.attrs, "allowedChildClassesEffective");
1476 ac->sDRightsEffective = ldb_attr_in_list(req->op.search.attrs, "sDRightsEffective");
1477 ac->userPassword = dsdb_user_password_support(module, ac, req);
1478 ac->schema = dsdb_get_schema(ldb, ac);
1480 /* replace any attributes in the parse tree that are private,
1481 so we don't allow a search for 'userPassword=penguin',
1482 just as we would not allow that attribute to be returned */
1483 if (ac->am_system) {
1484 /* FIXME: We should copy the tree and keep the original unmodified. */
1485 /* remove password attributes */
1486 if (data && data->password_attrs) {
1487 for (i = 0; data->password_attrs[i]; i++) {
1488 if ((!ac->userPassword) &&
1489 (ldb_attr_cmp(data->password_attrs[i],
1490 "userPassword") == 0))
1493 ldb_parse_tree_attr_replace(req->op.search.tree,
1494 data->password_attrs[i],
1495 "kludgeACLredactedattribute");
1499 ret = ldb_build_search_req_ex(&down_req,
1501 req->op.search.base,
1502 req->op.search.scope,
1503 req->op.search.tree,
1504 req->op.search.attrs,
1506 ac, acl_search_callback,
1508 LDB_REQ_SET_LOCATION(down_req);
1509 if (ret != LDB_SUCCESS) {
1512 /* perform the search */
1513 return ldb_next_request(module, down_req);
1516 static int acl_extended(struct ldb_module *module, struct ldb_request *req)
1518 struct ldb_context *ldb = ldb_module_get_ctx(module);
1519 struct ldb_control *as_system = ldb_request_get_control(req, LDB_CONTROL_AS_SYSTEM_OID);
1521 /* allow everybody to read the sequence number */
1522 if (strcmp(req->op.extended.oid,
1523 LDB_EXTENDED_SEQUENCE_NUMBER) == 0) {
1524 return ldb_next_request(module, req);
1527 if (dsdb_module_am_system(module) ||
1528 dsdb_module_am_administrator(module) || as_system) {
1529 return ldb_next_request(module, req);
1531 ldb_asprintf_errstring(ldb,
1533 "attempted database modify not permitted. "
1534 "User %s is not SYSTEM or an administrator",
1535 acl_user_name(req, module));
1536 return LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
1540 static const struct ldb_module_ops ldb_acl_module_ops = {
1542 .search = acl_search,
1544 .modify = acl_modify,
1546 .rename = acl_rename,
1547 .extended = acl_extended,
1548 .init_context = acl_module_init
1551 int ldb_acl_module_init(const char *version)
1553 LDB_MODULE_CHECK_VERSION(version);
1554 return ldb_register_module(&ldb_acl_module_ops);