4 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
5 Copyright (C) Simo Sorce 2004-2008
6 Copyright (C) Matthias Dieter Wallnöfer 2009-2010
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 samldb module
27 * Description: various internal DSDB triggers - most for SAM specific objects
33 #include "libcli/ldap/ldap_ndr.h"
34 #include "ldb_module.h"
35 #include "dsdb/samdb/samdb.h"
36 #include "dsdb/samdb/ldb_modules/util.h"
37 #include "dsdb/samdb/ldb_modules/ridalloc.h"
38 #include "libcli/security/security.h"
39 #include "librpc/gen_ndr/ndr_security.h"
40 #include "../lib/util/util_ldb.h"
42 #include "param/param.h"
46 typedef int (*samldb_step_fn_t)(struct samldb_ctx *);
49 struct samldb_step *next;
54 struct ldb_module *module;
55 struct ldb_request *req;
57 /* used for add operations */
60 /* the resulting message */
61 struct ldb_message *msg;
63 /* used in "samldb_find_for_defaultObjectCategory" */
64 struct ldb_dn *dn, *res_dn;
66 /* all the async steps necessary to complete the operation */
67 struct samldb_step *steps;
68 struct samldb_step *curstep;
70 /* If someone set an ares to forward controls and response back to the caller */
71 struct ldb_reply *ares;
74 static struct samldb_ctx *samldb_ctx_init(struct ldb_module *module,
75 struct ldb_request *req)
77 struct ldb_context *ldb;
78 struct samldb_ctx *ac;
80 ldb = ldb_module_get_ctx(module);
82 ac = talloc_zero(req, struct samldb_ctx);
94 static int samldb_add_step(struct samldb_ctx *ac, samldb_step_fn_t fn)
96 struct samldb_step *step, *stepper;
98 step = talloc_zero(ac, struct samldb_step);
100 return ldb_oom(ldb_module_get_ctx(ac->module));
105 if (ac->steps == NULL) {
109 if (ac->curstep == NULL)
110 return ldb_operr(ldb_module_get_ctx(ac->module));
111 for (stepper = ac->curstep; stepper->next != NULL;
112 stepper = stepper->next);
113 stepper->next = step;
119 static int samldb_first_step(struct samldb_ctx *ac)
121 if (ac->steps == NULL) {
122 return ldb_operr(ldb_module_get_ctx(ac->module));
125 ac->curstep = ac->steps;
126 return ac->curstep->fn(ac);
129 static int samldb_next_step(struct samldb_ctx *ac)
131 if (ac->curstep->next) {
132 ac->curstep = ac->curstep->next;
133 return ac->curstep->fn(ac);
136 /* we exit the samldb module here */
137 /* If someone set an ares to forward controls and response back to the caller, use them */
139 return ldb_module_done(ac->req, ac->ares->controls,
140 ac->ares->response, LDB_SUCCESS);
142 return ldb_module_done(ac->req, NULL, NULL, LDB_SUCCESS);
147 /* sAMAccountName handling */
149 static int samldb_generate_sAMAccountName(struct ldb_context *ldb, struct ldb_message *msg)
153 /* Format: $000000-000000000000 */
155 name = talloc_asprintf(msg, "$%.6X-%.6X%.6X",
156 (unsigned int)generate_random(),
157 (unsigned int)generate_random(),
158 (unsigned int)generate_random());
162 return ldb_msg_add_steal_string(msg, "sAMAccountName", name);
165 static int samldb_check_sAMAccountName(struct samldb_ctx *ac)
167 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
171 if (ldb_msg_find_element(ac->msg, "sAMAccountName") == NULL) {
172 ret = samldb_generate_sAMAccountName(ldb, ac->msg);
173 if (ret != LDB_SUCCESS) {
178 name = ldb_msg_find_attr_as_string(ac->msg, "sAMAccountName", NULL);
180 return ldb_operr(ldb);
183 ret = samdb_search_count(ldb, NULL, "(sAMAccountName=%s)",
184 ldb_binary_encode_string(ac, name));
185 if ((ret < 0) || (ret > 1)) {
186 return ldb_operr(ldb);
189 return LDB_ERR_ENTRY_ALREADY_EXISTS;
192 return samldb_next_step(ac);
196 static bool samldb_msg_add_sid(struct ldb_message *msg,
198 const struct dom_sid *sid)
201 enum ndr_err_code ndr_err;
203 ndr_err = ndr_push_struct_blob(&v, msg, sid,
204 (ndr_push_flags_fn_t)ndr_push_dom_sid);
205 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
208 return (ldb_msg_add_value(msg, name, &v, NULL) == 0);
212 /* allocate a SID using our RID Set */
213 static int samldb_allocate_sid(struct samldb_ctx *ac)
217 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
220 ret = ridalloc_allocate_rid(ac->module, &rid);
221 if (ret != LDB_SUCCESS) {
225 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
227 return ldb_module_oom(ac->module);
230 if ( ! samldb_msg_add_sid(ac->msg, "objectSid", sid)) {
231 return ldb_operr(ldb);
234 return samldb_next_step(ac);
238 see if a krbtgt_number is available
240 static bool samldb_krbtgtnumber_available(struct samldb_ctx *ac, unsigned krbtgt_number)
242 TALLOC_CTX *tmp_ctx = talloc_new(ac);
243 struct ldb_result *res;
244 const char *attrs[] = { NULL };
247 ret = dsdb_module_search(ac->module, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
248 attrs, DSDB_FLAG_NEXT_MODULE,
249 "msDC-SecondaryKrbTgtNumber=%u", krbtgt_number);
250 if (ret == LDB_SUCCESS && res->count == 0) {
251 talloc_free(tmp_ctx);
254 talloc_free(tmp_ctx);
258 /* special handling for add in RODC join */
259 static int samldb_rodc_add(struct samldb_ctx *ac)
261 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
262 unsigned krbtgt_number, i_start, i;
266 /* find a unused msDC-SecondaryKrbTgtNumber */
267 i_start = generate_random() & 0xFFFF;
272 for (i=i_start; i<=0xFFFF; i++) {
273 if (samldb_krbtgtnumber_available(ac, i)) {
278 for (i=1; i<i_start; i++) {
279 if (samldb_krbtgtnumber_available(ac, i)) {
285 ldb_asprintf_errstring(ldb,
286 "%08X: Unable to find available msDS-SecondaryKrbTgtNumber",
287 W_ERROR_V(WERR_NO_SYSTEM_RESOURCES));
288 return LDB_ERR_OTHER;
291 ret = ldb_msg_add_empty(ac->msg, "msDS-SecondaryKrbTgtNumber", LDB_FLAG_INTERNAL_DISABLE_VALIDATION, NULL);
292 if (ret != LDB_SUCCESS) {
293 return ldb_operr(ldb);
296 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
297 "msDS-SecondaryKrbTgtNumber", krbtgt_number);
298 if (ret != LDB_SUCCESS) {
299 return ldb_operr(ldb);
302 ret = ldb_msg_add_fmt(ac->msg, "sAMAccountName", "krbtgt_%u", krbtgt_number);
303 if (ret != LDB_SUCCESS) {
304 return ldb_operr(ldb);
307 newpass = generate_random_password(ac, 128, 255);
308 if (newpass == NULL) {
309 return ldb_operr(ldb);
312 ret = ldb_msg_add_steal_string(ac->msg, "clearTextPassword", newpass);
313 if (ret != LDB_SUCCESS) {
314 return ldb_operr(ldb);
317 return samldb_next_step(ac);
320 static int samldb_find_for_defaultObjectCategory(struct samldb_ctx *ac)
322 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
323 struct ldb_result *res;
324 const char *no_attrs[] = { NULL };
329 ret = dsdb_module_search(ac->module, ac, &res,
330 ac->dn, LDB_SCOPE_BASE, no_attrs,
331 DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT | DSDB_FLAG_NEXT_MODULE,
332 "(objectClass=classSchema)");
333 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
334 /* Don't be pricky when the DN doesn't exist if we have the */
335 /* RELAX control specified */
336 if (ldb_request_get_control(ac->req,
337 LDB_CONTROL_RELAX_OID) == NULL) {
338 ldb_set_errstring(ldb,
339 "samldb_find_defaultObjectCategory: "
340 "Invalid DN for 'defaultObjectCategory'!");
341 return LDB_ERR_CONSTRAINT_VIOLATION;
344 if ((ret != LDB_ERR_NO_SUCH_OBJECT) && (ret != LDB_SUCCESS)) {
350 return samldb_next_step(ac);
354 * msDS-IntId attributeSchema attribute handling
355 * during LDB_ADD request processing
357 static int samldb_add_handle_msDS_IntId(struct samldb_ctx *ac)
362 uint32_t system_flags;
363 struct ldb_context *ldb;
364 struct ldb_result *ldb_res;
365 struct ldb_dn *schema_dn;
367 ldb = ldb_module_get_ctx(ac->module);
368 schema_dn = ldb_get_schema_basedn(ldb);
370 /* replicated update should always go through */
371 if (ldb_request_get_control(ac->req, DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
375 /* msDS-IntId is handled by system and should never be
376 * passed by clients */
377 if (ldb_msg_find_element(ac->msg, "msDS-IntId")) {
378 return LDB_ERR_UNWILLING_TO_PERFORM;
381 /* do not generate msDS-IntId if Relax control is passed */
382 if (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
386 /* check Functional Level */
387 if (dsdb_functional_level(ldb) < DS_DOMAIN_FUNCTION_2003) {
391 /* check systemFlags for SCHEMA_BASE_OBJECT flag */
392 system_flags = ldb_msg_find_attr_as_uint(ac->msg, "systemFlags", 0);
393 if (system_flags & SYSTEM_FLAG_SCHEMA_BASE_OBJECT) {
397 /* Generate new value for msDs-IntId
398 * Value should be in 0x80000000..0xBFFFFFFF range */
399 msds_intid = generate_random() % 0X3FFFFFFF;
400 msds_intid += 0x80000000;
402 /* probe id values until unique one is found */
405 if (msds_intid > 0xBFFFFFFF) {
406 msds_intid = 0x80000001;
409 ret = dsdb_module_search(ac->module, ac,
411 schema_dn, LDB_SCOPE_ONELEVEL, NULL,
412 DSDB_FLAG_NEXT_MODULE,
413 "(msDS-IntId=%d)", msds_intid);
414 if (ret != LDB_SUCCESS) {
415 ldb_debug_set(ldb, LDB_DEBUG_ERROR,
416 __location__": Searching for msDS-IntId=%d failed - %s\n",
419 return ldb_operr(ldb);
421 id_exists = (ldb_res->count > 0);
423 talloc_free(ldb_res);
426 return ldb_msg_add_fmt(ac->msg, "msDS-IntId", "%d", msds_intid);
431 * samldb_add_entry (async)
434 static int samldb_add_entry_callback(struct ldb_request *req,
435 struct ldb_reply *ares)
437 struct ldb_context *ldb;
438 struct samldb_ctx *ac;
441 ac = talloc_get_type(req->context, struct samldb_ctx);
442 ldb = ldb_module_get_ctx(ac->module);
445 return ldb_module_done(ac->req, NULL, NULL,
446 LDB_ERR_OPERATIONS_ERROR);
449 if (ares->type == LDB_REPLY_REFERRAL) {
450 return ldb_module_send_referral(ac->req, ares->referral);
453 if (ares->error != LDB_SUCCESS) {
454 return ldb_module_done(ac->req, ares->controls,
455 ares->response, ares->error);
457 if (ares->type != LDB_REPLY_DONE) {
458 ldb_set_errstring(ldb,
459 "Invalid reply type!\n");
460 return ldb_module_done(ac->req, NULL, NULL,
461 LDB_ERR_OPERATIONS_ERROR);
464 /* The caller may wish to get controls back from the add */
465 ac->ares = talloc_steal(ac, ares);
467 ret = samldb_next_step(ac);
468 if (ret != LDB_SUCCESS) {
469 return ldb_module_done(ac->req, NULL, NULL, ret);
474 static int samldb_add_entry(struct samldb_ctx *ac)
476 struct ldb_context *ldb;
477 struct ldb_request *req;
480 ldb = ldb_module_get_ctx(ac->module);
482 ret = ldb_build_add_req(&req, ldb, ac,
485 ac, samldb_add_entry_callback,
487 LDB_REQ_SET_LOCATION(req);
488 if (ret != LDB_SUCCESS) {
492 return ldb_next_request(ac->module, req);
496 * return true if msg carries an attributeSchema that is intended to be RODC
497 * filtered but is also a system-critical attribute.
499 static bool check_rodc_critical_attribute(struct ldb_message *msg)
501 uint32_t schemaFlagsEx, searchFlags, rodc_filtered_flags;
503 schemaFlagsEx = ldb_msg_find_attr_as_uint(msg, "schemaFlagsEx", 0);
504 searchFlags = ldb_msg_find_attr_as_uint(msg, "searchFlags", 0);
505 rodc_filtered_flags = (SEARCH_FLAG_RODC_ATTRIBUTE | SEARCH_FLAG_CONFIDENTIAL);
507 if ((schemaFlagsEx & SCHEMA_FLAG_ATTR_IS_CRITICAL) &&
508 ((searchFlags & rodc_filtered_flags) == rodc_filtered_flags)) {
516 static int samldb_fill_object(struct samldb_ctx *ac)
518 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
521 /* Add informations for the different account types */
522 if (strcmp(ac->type, "user") == 0) {
523 struct ldb_control *rodc_control = ldb_request_get_control(ac->req,
524 LDB_CONTROL_RODC_DCPROMO_OID);
525 if (rodc_control != NULL) {
526 /* see [MS-ADTS] 3.1.1.3.4.1.23 LDAP_SERVER_RODC_DCPROMO_OID */
527 rodc_control->critical = false;
528 ret = samldb_add_step(ac, samldb_rodc_add);
529 if (ret != LDB_SUCCESS) return ret;
532 /* check if we have a valid sAMAccountName */
533 ret = samldb_add_step(ac, samldb_check_sAMAccountName);
534 if (ret != LDB_SUCCESS) return ret;
536 ret = samldb_add_step(ac, samldb_add_entry);
537 if (ret != LDB_SUCCESS) return ret;
539 } else if (strcmp(ac->type, "group") == 0) {
540 /* check if we have a valid sAMAccountName */
541 ret = samldb_add_step(ac, samldb_check_sAMAccountName);
542 if (ret != LDB_SUCCESS) return ret;
544 ret = samldb_add_step(ac, samldb_add_entry);
545 if (ret != LDB_SUCCESS) return ret;
547 } else if (strcmp(ac->type, "classSchema") == 0) {
548 const struct ldb_val *rdn_value, *def_obj_cat_val;
550 ret = samdb_find_or_add_attribute(ldb, ac->msg,
552 if (ret != LDB_SUCCESS) return ret;
554 /* do not allow to mark an attributeSchema as RODC filtered if it
555 * is system-critical */
556 if (check_rodc_critical_attribute(ac->msg)) {
557 ldb_asprintf_errstring(ldb, "Refusing schema add of %s - cannot combine critical class with RODC filtering",
558 ldb_dn_get_linearized(ac->msg->dn));
559 return LDB_ERR_UNWILLING_TO_PERFORM;
562 rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
563 if (!ldb_msg_find_element(ac->msg, "lDAPDisplayName")) {
564 /* the RDN has prefix "CN" */
565 ret = ldb_msg_add_string(ac->msg, "lDAPDisplayName",
566 samdb_cn_to_lDAPDisplayName(ac,
567 (const char *) rdn_value->data));
568 if (ret != LDB_SUCCESS) {
574 if (!ldb_msg_find_element(ac->msg, "schemaIDGUID")) {
577 guid = GUID_random();
578 ret = dsdb_msg_add_guid(ac->msg, &guid, "schemaIDGUID");
579 if (ret != LDB_SUCCESS) {
585 def_obj_cat_val = ldb_msg_find_ldb_val(ac->msg,
586 "defaultObjectCategory");
587 if (def_obj_cat_val != NULL) {
588 /* "defaultObjectCategory" has been set by the caller.
589 * Do some checks for consistency.
590 * NOTE: The real constraint check (that
591 * 'defaultObjectCategory' is the DN of the new
592 * objectclass or any parent of it) is still incomplete.
593 * For now we say that 'defaultObjectCategory' is valid
594 * if it exists and it is of objectclass "classSchema".
596 ac->dn = ldb_dn_from_ldb_val(ac, ldb, def_obj_cat_val);
597 if (ac->dn == NULL) {
598 ldb_set_errstring(ldb,
599 "Invalid DN for 'defaultObjectCategory'!");
600 return LDB_ERR_CONSTRAINT_VIOLATION;
603 /* "defaultObjectCategory" has not been set by the
604 * caller. Use the entry DN for it. */
605 ac->dn = ac->msg->dn;
607 ret = samdb_msg_add_string(ldb, ac->msg, ac->msg,
608 "defaultObjectCategory",
609 ldb_dn_get_linearized(ac->dn));
610 if (ret != LDB_SUCCESS) {
616 ret = samldb_add_step(ac, samldb_add_entry);
617 if (ret != LDB_SUCCESS) return ret;
619 /* Now perform the checks for the 'defaultObjectCategory'. The
620 * lookup DN was already saved in "ac->dn" */
621 ret = samldb_add_step(ac, samldb_find_for_defaultObjectCategory);
622 if (ret != LDB_SUCCESS) return ret;
624 } else if (strcmp(ac->type, "attributeSchema") == 0) {
625 const struct ldb_val *rdn_value;
626 rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
627 if (!ldb_msg_find_element(ac->msg, "lDAPDisplayName")) {
628 /* the RDN has prefix "CN" */
629 ret = ldb_msg_add_string(ac->msg, "lDAPDisplayName",
630 samdb_cn_to_lDAPDisplayName(ac->msg,
631 (const char *) rdn_value->data));
632 if (ret != LDB_SUCCESS) {
638 /* do not allow to mark an attributeSchema as RODC filtered if it
639 * is system-critical */
640 if (check_rodc_critical_attribute(ac->msg)) {
641 ldb_asprintf_errstring(ldb, "Refusing schema add of %s - cannot combine critical attribute with RODC filtering",
642 ldb_dn_get_linearized(ac->msg->dn));
643 return LDB_ERR_UNWILLING_TO_PERFORM;
646 ret = samdb_find_or_add_attribute(ldb, ac->msg,
647 "isSingleValued", "FALSE");
648 if (ret != LDB_SUCCESS) return ret;
650 if (!ldb_msg_find_element(ac->msg, "schemaIDGUID")) {
653 guid = GUID_random();
654 ret = dsdb_msg_add_guid(ac->msg, &guid, "schemaIDGUID");
655 if (ret != LDB_SUCCESS) {
661 /* handle msDS-IntID attribute */
662 ret = samldb_add_handle_msDS_IntId(ac);
663 if (ret != LDB_SUCCESS) return ret;
665 ret = samldb_add_step(ac, samldb_add_entry);
666 if (ret != LDB_SUCCESS) return ret;
669 ldb_asprintf_errstring(ldb,
670 "Invalid entry type!");
671 return LDB_ERR_OPERATIONS_ERROR;
674 return samldb_first_step(ac);
677 static int samldb_fill_foreignSecurityPrincipal_object(struct samldb_ctx *ac)
679 struct ldb_context *ldb;
683 ldb = ldb_module_get_ctx(ac->module);
685 sid = samdb_result_dom_sid(ac->msg, ac->msg, "objectSid");
687 sid = dom_sid_parse_talloc(ac->msg,
688 (const char *)ldb_dn_get_rdn_val(ac->msg->dn)->data);
690 ldb_set_errstring(ldb,
691 "No valid SID found in "
692 "ForeignSecurityPrincipal CN!");
693 return LDB_ERR_CONSTRAINT_VIOLATION;
695 if (! samldb_msg_add_sid(ac->msg, "objectSid", sid)) {
696 return ldb_operr(ldb);
700 /* finally proceed with adding the entry */
701 ret = samldb_add_step(ac, samldb_add_entry);
702 if (ret != LDB_SUCCESS) return ret;
704 return samldb_first_step(ac);
707 static int samldb_schema_info_update(struct samldb_ctx *ac)
710 struct ldb_context *ldb;
711 struct dsdb_schema *schema;
713 /* replicated update should always go through */
714 if (ldb_request_get_control(ac->req, DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
718 /* do not update schemaInfo during provisioning */
719 if (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
723 ldb = ldb_module_get_ctx(ac->module);
724 schema = dsdb_get_schema(ldb, NULL);
726 ldb_debug_set(ldb, LDB_DEBUG_FATAL,
727 "samldb_schema_info_update: no dsdb_schema loaded");
728 DEBUG(0,(__location__ ": %s\n", ldb_errstring(ldb)));
729 return ldb_operr(ldb);
732 werr = dsdb_module_schema_info_update(ac->module, schema, DSDB_FLAG_NEXT_MODULE);
733 if (!W_ERROR_IS_OK(werr)) {
734 ldb_debug_set(ldb, LDB_DEBUG_FATAL,
735 "samldb_schema_info_update: "
736 "dsdb_module_schema_info_update failed with %s",
738 DEBUG(0,(__location__ ": %s\n", ldb_errstring(ldb)));
739 return ldb_operr(ldb);
746 * "Objectclass" trigger (MS-SAMR 3.1.1.8.1)
748 * Has to be invoked on "add" and "modify" operations on "user", "computer" and
750 * ac->msg contains the "add"/"modify" message
751 * ac->type contains the object type (main objectclass)
753 static int samldb_objectclass_trigger(struct samldb_ctx *ac)
755 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
756 struct loadparm_context *lp_ctx = talloc_get_type(ldb_get_opaque(ldb,
757 "loadparm"), struct loadparm_context);
758 struct ldb_message_element *el, *el2;
759 enum sid_generator sid_generator;
764 /* make sure that "sAMAccountType" is not specified */
765 el = ldb_msg_find_element(ac->msg, "sAMAccountType");
767 ldb_set_errstring(ldb,
768 "samldb: sAMAccountType must not be specified!");
769 return LDB_ERR_UNWILLING_TO_PERFORM;
772 /* Step 1: objectSid assignment */
774 /* Don't allow the objectSid to be changed. But beside the RELAX
775 * control we have also to guarantee that it can always be set with
776 * SYSTEM permissions. This is needed for the "samba3sam" backend. */
777 sid = samdb_result_dom_sid(ac, ac->msg, "objectSid");
778 if ((sid != NULL) && (!dsdb_module_am_system(ac->module)) &&
779 (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID) == NULL)) {
780 ldb_asprintf_errstring(ldb, "No SID may be specified in user/group modifications for %s",
781 ldb_dn_get_linearized(ac->msg->dn));
782 return LDB_ERR_UNWILLING_TO_PERFORM;
785 /* but generate a new SID when we do have an add operations */
786 if ((sid == NULL) && (ac->req->operation == LDB_ADD)) {
787 sid_generator = lpcfg_sid_generator(lp_ctx);
788 if (sid_generator == SID_GENERATOR_INTERNAL) {
789 ret = samldb_add_step(ac, samldb_allocate_sid);
790 if (ret != LDB_SUCCESS) return ret;
794 if (strcmp(ac->type, "user") == 0) {
795 /* Step 1.2: Default values */
796 tempstr = talloc_asprintf(ac->msg, "%d", UF_NORMAL_ACCOUNT);
797 if (tempstr == NULL) return ldb_operr(ldb);
798 ret = samdb_find_or_add_attribute(ldb, ac->msg,
799 "userAccountControl", tempstr);
800 if (ret != LDB_SUCCESS) return ret;
801 ret = samdb_find_or_add_attribute(ldb, ac->msg,
803 if (ret != LDB_SUCCESS) return ret;
804 ret = samdb_find_or_add_attribute(ldb, ac->msg,
806 if (ret != LDB_SUCCESS) return ret;
807 ret = samdb_find_or_add_attribute(ldb, ac->msg,
809 if (ret != LDB_SUCCESS) return ret;
810 ret = samdb_find_or_add_attribute(ldb, ac->msg,
811 "badPasswordTime", "0");
812 if (ret != LDB_SUCCESS) return ret;
813 ret = samdb_find_or_add_attribute(ldb, ac->msg,
815 if (ret != LDB_SUCCESS) return ret;
816 ret = samdb_find_or_add_attribute(ldb, ac->msg,
818 if (ret != LDB_SUCCESS) return ret;
819 ret = samdb_find_or_add_attribute(ldb, ac->msg,
821 if (ret != LDB_SUCCESS) return ret;
822 ret = samdb_find_or_add_attribute(ldb, ac->msg,
823 "accountExpires", "9223372036854775807");
824 if (ret != LDB_SUCCESS) return ret;
825 ret = samdb_find_or_add_attribute(ldb, ac->msg,
827 if (ret != LDB_SUCCESS) return ret;
829 el = ldb_msg_find_element(ac->msg, "userAccountControl");
831 uint32_t user_account_control, account_type;
833 /* Step 1.3: "userAccountControl" -> "sAMAccountType" mapping */
834 user_account_control = ldb_msg_find_attr_as_uint(ac->msg,
835 "userAccountControl",
838 /* Temporary duplicate accounts aren't allowed */
839 if ((user_account_control & UF_TEMP_DUPLICATE_ACCOUNT) != 0) {
840 return LDB_ERR_OTHER;
843 account_type = ds_uf2atype(user_account_control);
844 if (account_type == 0) {
845 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
846 return LDB_ERR_UNWILLING_TO_PERFORM;
848 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
851 if (ret != LDB_SUCCESS) {
854 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
855 el2->flags = LDB_FLAG_MOD_REPLACE;
857 if (user_account_control &
858 (UF_SERVER_TRUST_ACCOUNT | UF_PARTIAL_SECRETS_ACCOUNT)) {
859 ret = samdb_msg_set_string(ldb, ac->msg, ac->msg,
860 "isCriticalSystemObject",
862 if (ret != LDB_SUCCESS) {
865 el2 = ldb_msg_find_element(ac->msg,
866 "isCriticalSystemObject");
867 el2->flags = LDB_FLAG_MOD_REPLACE;
870 /* Step 1.4: "userAccountControl" -> "primaryGroupID" mapping */
871 if (!ldb_msg_find_element(ac->msg, "primaryGroupID")) {
872 uint32_t rid = ds_uf2prim_group_rid(user_account_control);
873 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
874 "primaryGroupID", rid);
875 if (ret != LDB_SUCCESS) {
878 el2 = ldb_msg_find_element(ac->msg,
880 el2->flags = LDB_FLAG_MOD_REPLACE;
883 /* Step 1.5: Add additional flags when needed */
884 if ((user_account_control & UF_NORMAL_ACCOUNT) &&
885 (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID) == NULL)) {
886 user_account_control |= UF_ACCOUNTDISABLE;
887 user_account_control |= UF_PASSWD_NOTREQD;
889 ret = samdb_msg_set_uint(ldb, ac->msg, ac->msg,
890 "userAccountControl",
891 user_account_control);
892 if (ret != LDB_SUCCESS) {
898 } else if (strcmp(ac->type, "group") == 0) {
899 /* Step 2.2: Default values */
900 tempstr = talloc_asprintf(ac->msg, "%d",
901 GTYPE_SECURITY_GLOBAL_GROUP);
902 if (tempstr == NULL) return ldb_operr(ldb);
903 ret = samdb_find_or_add_attribute(ldb, ac->msg,
904 "groupType", tempstr);
905 if (ret != LDB_SUCCESS) return ret;
907 /* Step 2.3: "groupType" -> "sAMAccountType" */
908 el = ldb_msg_find_element(ac->msg, "groupType");
910 uint32_t group_type, account_type;
912 group_type = ldb_msg_find_attr_as_uint(ac->msg,
915 /* The creation of builtin groups requires the
917 if (group_type == GTYPE_SECURITY_BUILTIN_LOCAL_GROUP) {
918 if (ldb_request_get_control(ac->req,
919 LDB_CONTROL_RELAX_OID) == NULL) {
920 return LDB_ERR_UNWILLING_TO_PERFORM;
924 account_type = ds_gtype2atype(group_type);
925 if (account_type == 0) {
926 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
927 return LDB_ERR_UNWILLING_TO_PERFORM;
929 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
932 if (ret != LDB_SUCCESS) {
935 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
936 el2->flags = LDB_FLAG_MOD_REPLACE;
944 * "Primary group ID" trigger (MS-SAMR 3.1.1.8.2)
946 * Has to be invoked on "add" and "modify" operations on "user" and "computer"
948 * ac->msg contains the "add"/"modify" message
951 static int samldb_prim_group_set(struct samldb_ctx *ac)
953 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
954 struct ldb_dn *prim_group_dn;
958 rid = ldb_msg_find_attr_as_uint(ac->msg, "primaryGroupID", (uint32_t) -1);
959 if (rid == (uint32_t) -1) {
960 /* we aren't affected of any primary group set */
963 } else if (!ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
964 ldb_set_errstring(ldb,
965 "The primary group isn't settable on add operations!");
966 return LDB_ERR_UNWILLING_TO_PERFORM;
969 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
971 return ldb_operr(ldb);
974 prim_group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
975 ldap_encode_ndr_dom_sid(ac, sid));
976 if (prim_group_dn == NULL) {
977 ldb_asprintf_errstring(ldb,
978 "Failed to find primary group with RID %u!",
980 return LDB_ERR_UNWILLING_TO_PERFORM;
986 static int samldb_prim_group_change(struct samldb_ctx *ac)
988 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
989 const char * attrs[] = { "primaryGroupID", "memberOf", NULL };
990 struct ldb_result *res;
991 struct ldb_message_element *el;
992 struct ldb_message *msg;
995 struct ldb_dn *prev_prim_group_dn, *new_prim_group_dn;
998 /* Fetch informations from the existing object */
1000 ret = ldb_search(ldb, ac, &res, ac->msg->dn, LDB_SCOPE_BASE, attrs,
1002 if (ret != LDB_SUCCESS) {
1006 /* Finds out the DN of the old primary group */
1008 rid = ldb_msg_find_attr_as_uint(res->msgs[0], "primaryGroupID", (uint32_t) -1);
1009 if (rid == (uint32_t) -1) {
1010 /* User objects do always have a mandatory "primaryGroupID"
1011 * attribute. If this doesn't exist then the object is of the
1012 * wrong type. This is the exact Windows error code */
1013 return LDB_ERR_OBJECT_CLASS_VIOLATION;
1016 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
1018 return ldb_operr(ldb);
1021 prev_prim_group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
1022 ldap_encode_ndr_dom_sid(ac, sid));
1023 if (prev_prim_group_dn == NULL) {
1024 return ldb_operr(ldb);
1027 /* Finds out the DN of the new primary group */
1029 rid = ldb_msg_find_attr_as_uint(ac->msg, "primaryGroupID", (uint32_t) -1);
1030 if (rid == (uint32_t) -1) {
1031 /* we aren't affected of any primary group change */
1035 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
1037 return ldb_operr(ldb);
1040 new_prim_group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
1041 ldap_encode_ndr_dom_sid(ac, sid));
1042 if (new_prim_group_dn == NULL) {
1043 /* Here we know if the specified new primary group candidate is
1045 return LDB_ERR_UNWILLING_TO_PERFORM;
1048 /* Only update the "member" attributes when we really do have a change */
1049 if (ldb_dn_compare(new_prim_group_dn, prev_prim_group_dn) != 0) {
1050 /* We need to be already a normal member of the new primary
1051 * group in order to be successful. */
1052 el = samdb_find_attribute(ldb, res->msgs[0], "memberOf",
1053 ldb_dn_get_linearized(new_prim_group_dn));
1055 return LDB_ERR_UNWILLING_TO_PERFORM;
1058 /* Remove the "member" attribute on the new primary group */
1059 msg = talloc_zero(ac, struct ldb_message);
1060 msg->dn = new_prim_group_dn;
1062 ret = samdb_msg_add_delval(ldb, ac, msg, "member",
1063 ldb_dn_get_linearized(ac->msg->dn));
1064 if (ret != LDB_SUCCESS) {
1068 ret = dsdb_module_modify(ac->module, msg, DSDB_FLAG_NEXT_MODULE);
1069 if (ret != LDB_SUCCESS) {
1073 /* Add a "member" attribute for the previous primary group */
1074 msg = talloc_zero(ac, struct ldb_message);
1075 msg->dn = prev_prim_group_dn;
1077 ret = samdb_msg_add_addval(ldb, ac, msg, "member",
1078 ldb_dn_get_linearized(ac->msg->dn));
1079 if (ret != LDB_SUCCESS) {
1083 ret = dsdb_module_modify(ac->module, msg, DSDB_FLAG_NEXT_MODULE);
1084 if (ret != LDB_SUCCESS) {
1092 static int samldb_prim_group_trigger(struct samldb_ctx *ac)
1096 if (ac->req->operation == LDB_ADD) {
1097 ret = samldb_prim_group_set(ac);
1099 ret = samldb_prim_group_change(ac);
1105 static int samldb_member_check(struct samldb_ctx *ac)
1107 struct ldb_context *ldb;
1108 struct ldb_message_element *el;
1109 struct ldb_dn *member_dn, *group_dn;
1110 uint32_t prim_group_rid;
1111 struct dom_sid *sid;
1114 ldb = ldb_module_get_ctx(ac->module);
1116 el = ldb_msg_find_element(ac->msg, "member");
1118 /* we aren't affected */
1122 for (i = 0; i < el->num_values; i++) {
1123 /* Denies to add "member"s to groups which are primary ones
1125 member_dn = ldb_dn_from_ldb_val(ac, ldb, &el->values[i]);
1126 if (!ldb_dn_validate(member_dn)) {
1127 return ldb_operr(ldb);
1130 prim_group_rid = samdb_search_uint(ldb, ac, (uint32_t) -1,
1131 member_dn, "primaryGroupID",
1133 if (prim_group_rid == (uint32_t) -1) {
1134 /* the member hasn't to be a user account -> therefore
1135 * no check needed in this case. */
1139 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb),
1142 return ldb_operr(ldb);
1145 group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
1146 ldap_encode_ndr_dom_sid(ac, sid));
1147 if (group_dn == NULL) {
1148 return ldb_operr(ldb);
1151 if (ldb_dn_compare(group_dn, ac->msg->dn) == 0) {
1152 return LDB_ERR_ENTRY_ALREADY_EXISTS;
1161 static int samldb_add(struct ldb_module *module, struct ldb_request *req)
1163 struct ldb_context *ldb;
1164 struct samldb_ctx *ac;
1167 ldb = ldb_module_get_ctx(module);
1168 ldb_debug(ldb, LDB_DEBUG_TRACE, "samldb_add\n");
1170 /* do not manipulate our control entries */
1171 if (ldb_dn_is_special(req->op.add.message->dn)) {
1172 return ldb_next_request(module, req);
1175 ac = samldb_ctx_init(module, req);
1177 return ldb_operr(ldb);
1180 /* build the new msg */
1181 ac->msg = ldb_msg_copy_shallow(ac, req->op.add.message);
1182 if (ac->msg == NULL) {
1184 ldb_debug(ldb, LDB_DEBUG_FATAL,
1185 "samldb_add: ldb_msg_copy_shallow failed!\n");
1186 return ldb_operr(ldb);
1189 if (samdb_find_attribute(ldb, ac->msg,
1190 "objectclass", "user") != NULL) {
1193 ret = samldb_prim_group_trigger(ac);
1194 if (ret != LDB_SUCCESS) {
1198 ret = samldb_objectclass_trigger(ac);
1199 if (ret != LDB_SUCCESS) {
1203 return samldb_fill_object(ac);
1206 if (samdb_find_attribute(ldb, ac->msg,
1207 "objectclass", "group") != NULL) {
1210 ret = samldb_objectclass_trigger(ac);
1211 if (ret != LDB_SUCCESS) {
1215 return samldb_fill_object(ac);
1218 /* perhaps a foreignSecurityPrincipal? */
1219 if (samdb_find_attribute(ldb, ac->msg,
1221 "foreignSecurityPrincipal") != NULL) {
1222 return samldb_fill_foreignSecurityPrincipal_object(ac);
1225 if (samdb_find_attribute(ldb, ac->msg,
1226 "objectclass", "classSchema") != NULL) {
1227 ret = samldb_schema_info_update(ac);
1228 if (ret != LDB_SUCCESS) {
1233 ac->type = "classSchema";
1234 return samldb_fill_object(ac);
1237 if (samdb_find_attribute(ldb, ac->msg,
1238 "objectclass", "attributeSchema") != NULL) {
1239 ret = samldb_schema_info_update(ac);
1240 if (ret != LDB_SUCCESS) {
1245 ac->type = "attributeSchema";
1246 return samldb_fill_object(ac);
1251 /* nothing matched, go on */
1252 return ldb_next_request(module, req);
1256 static int samldb_modify(struct ldb_module *module, struct ldb_request *req)
1258 struct ldb_context *ldb;
1259 struct samldb_ctx *ac;
1260 struct ldb_message_element *el, *el2;
1261 bool modified = false;
1263 uint32_t account_type;
1265 if (ldb_dn_is_special(req->op.mod.message->dn)) {
1266 /* do not manipulate our control entries */
1267 return ldb_next_request(module, req);
1270 ldb = ldb_module_get_ctx(module);
1272 /* make sure that "sAMAccountType" is not specified */
1273 el = ldb_msg_find_element(req->op.mod.message, "sAMAccountType");
1275 ldb_set_errstring(ldb,
1276 "samldb: sAMAccountType must not be specified!");
1277 return LDB_ERR_UNWILLING_TO_PERFORM;
1279 /* make sure that "isCriticalSystemObject" is not specified */
1280 el = ldb_msg_find_element(req->op.mod.message, "isCriticalSystemObject");
1282 if (ldb_request_get_control(req, LDB_CONTROL_RELAX_OID) == NULL) {
1283 ldb_set_errstring(ldb,
1284 "samldb: isCriticalSystemObject must not be specified!");
1285 return LDB_ERR_UNWILLING_TO_PERFORM;
1289 /* msDS-IntId is not allowed to be modified
1290 * except when modification comes from replication */
1291 if (ldb_msg_find_element(req->op.mod.message, "msDS-IntId")) {
1292 if (!ldb_request_get_control(req, DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
1293 return LDB_ERR_CONSTRAINT_VIOLATION;
1297 ac = samldb_ctx_init(module, req);
1299 return ldb_operr(ldb);
1302 /* build the new msg */
1303 ac->msg = ldb_msg_copy_shallow(ac, req->op.mod.message);
1304 if (ac->msg == NULL) {
1306 ldb_debug(ldb, LDB_DEBUG_FATAL,
1307 "samldb_modify: ldb_msg_copy_shallow failed!\n");
1308 return ldb_operr(ldb);
1311 el = ldb_msg_find_element(ac->msg, "groupType");
1312 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1313 uint32_t group_type, old_group_type;
1317 group_type = ldb_msg_find_attr_as_uint(ac->msg, "groupType", 0);
1318 old_group_type = samdb_search_uint(ldb, ac, 0, ac->msg->dn,
1320 if (old_group_type == 0) {
1321 return ldb_operr(ldb);
1324 /* Group type switching isn't so easy as it seems: We can only
1325 * change in this directions: global <-> universal <-> local
1326 * On each step also the group type itself
1327 * (security/distribution) is variable. */
1329 switch (group_type) {
1330 case GTYPE_SECURITY_GLOBAL_GROUP:
1331 case GTYPE_DISTRIBUTION_GLOBAL_GROUP:
1332 /* change to "universal" allowed */
1333 if ((old_group_type == GTYPE_SECURITY_DOMAIN_LOCAL_GROUP) ||
1334 (old_group_type == GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP)) {
1335 return LDB_ERR_UNWILLING_TO_PERFORM;
1339 case GTYPE_SECURITY_UNIVERSAL_GROUP:
1340 case GTYPE_DISTRIBUTION_UNIVERSAL_GROUP:
1341 /* each change allowed */
1344 case GTYPE_SECURITY_DOMAIN_LOCAL_GROUP:
1345 case GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP:
1346 /* change to "universal" allowed */
1347 if ((old_group_type == GTYPE_SECURITY_GLOBAL_GROUP) ||
1348 (old_group_type == GTYPE_DISTRIBUTION_GLOBAL_GROUP)) {
1349 return LDB_ERR_UNWILLING_TO_PERFORM;
1353 case GTYPE_SECURITY_BUILTIN_LOCAL_GROUP:
1355 /* we don't allow this "groupType" values */
1356 return LDB_ERR_UNWILLING_TO_PERFORM;
1360 account_type = ds_gtype2atype(group_type);
1361 if (account_type == 0) {
1362 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
1363 return LDB_ERR_UNWILLING_TO_PERFORM;
1365 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
1368 if (ret != LDB_SUCCESS) {
1371 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
1372 el2->flags = LDB_FLAG_MOD_REPLACE;
1374 el = ldb_msg_find_element(ac->msg, "groupType");
1375 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE)) {
1376 return LDB_ERR_UNWILLING_TO_PERFORM;
1379 el = ldb_msg_find_element(ac->msg, "primaryGroupID");
1380 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1383 ret = samldb_prim_group_change(ac);
1384 if (ret != LDB_SUCCESS) {
1388 el = ldb_msg_find_element(ac->msg, "primaryGroupID");
1389 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE)) {
1390 return LDB_ERR_UNWILLING_TO_PERFORM;
1393 el = ldb_msg_find_element(ac->msg, "userAccountControl");
1394 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1395 uint32_t user_account_control;
1399 user_account_control = ldb_msg_find_attr_as_uint(ac->msg,
1400 "userAccountControl",
1403 /* Temporary duplicate accounts aren't allowed */
1404 if ((user_account_control & UF_TEMP_DUPLICATE_ACCOUNT) != 0) {
1405 return LDB_ERR_OTHER;
1408 account_type = ds_uf2atype(user_account_control);
1409 if (account_type == 0) {
1410 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
1411 return LDB_ERR_UNWILLING_TO_PERFORM;
1413 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
1416 if (ret != LDB_SUCCESS) {
1419 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
1420 el2->flags = LDB_FLAG_MOD_REPLACE;
1422 if (user_account_control & (UF_SERVER_TRUST_ACCOUNT | UF_PARTIAL_SECRETS_ACCOUNT)) {
1423 ret = samdb_msg_add_string(ldb, ac->msg, ac->msg,
1424 "isCriticalSystemObject",
1426 if (ret != LDB_SUCCESS) {
1429 el2 = ldb_msg_find_element(ac->msg,
1430 "isCriticalSystemObject");
1431 el2->flags = LDB_FLAG_MOD_REPLACE;
1434 if (!ldb_msg_find_element(ac->msg, "primaryGroupID")) {
1435 uint32_t rid = ds_uf2prim_group_rid(user_account_control);
1437 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
1438 "primaryGroupID", rid);
1439 if (ret != LDB_SUCCESS) {
1442 el2 = ldb_msg_find_element(ac->msg,
1444 el2->flags = LDB_FLAG_MOD_REPLACE;
1447 el = ldb_msg_find_element(ac->msg, "userAccountControl");
1448 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE)) {
1449 return LDB_ERR_UNWILLING_TO_PERFORM;
1452 el = ldb_msg_find_element(ac->msg, "member");
1453 if (el && el->flags & (LDB_FLAG_MOD_ADD|LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1454 ret = samldb_member_check(ac);
1455 if (ret != LDB_SUCCESS) {
1461 struct ldb_request *child_req;
1463 /* Now perform the real modifications as a child request */
1464 ret = ldb_build_mod_req(&child_req, ldb, ac,
1467 req, dsdb_next_callback,
1469 LDB_REQ_SET_LOCATION(child_req);
1470 if (ret != LDB_SUCCESS) {
1474 return ldb_next_request(module, child_req);
1479 /* no change which interests us, go on */
1480 return ldb_next_request(module, req);
1485 static int samldb_prim_group_users_check(struct samldb_ctx *ac)
1487 struct ldb_context *ldb;
1488 struct dom_sid *sid;
1493 ldb = ldb_module_get_ctx(ac->module);
1495 /* Finds out the SID/RID of the SAM object */
1496 sid = samdb_search_dom_sid(ldb, ac, ac->req->op.del.dn, "objectSid",
1499 /* No SID - it might not be a SAM object - therefore ok */
1502 status = dom_sid_split_rid(ac, sid, NULL, &rid);
1503 if (!NT_STATUS_IS_OK(status)) {
1504 return ldb_operr(ldb);
1507 /* Special object (security principal?) */
1511 /* Deny delete requests from groups which are primary ones */
1512 count = samdb_search_count(ldb, NULL,
1513 "(&(primaryGroupID=%u)(objectClass=user))",
1516 return ldb_operr(ldb);
1519 return LDB_ERR_ENTRY_ALREADY_EXISTS;
1525 static int samldb_delete(struct ldb_module *module, struct ldb_request *req)
1527 struct samldb_ctx *ac;
1530 if (ldb_dn_is_special(req->op.del.dn)) {
1531 /* do not manipulate our control entries */
1532 return ldb_next_request(module, req);
1535 ac = samldb_ctx_init(module, req);
1537 return ldb_operr(ldb_module_get_ctx(module));
1540 ret = samldb_prim_group_users_check(ac);
1541 if (ret != LDB_SUCCESS) {
1547 return ldb_next_request(module, req);
1552 static int samldb_extended_allocate_rid_pool(struct ldb_module *module, struct ldb_request *req)
1554 struct ldb_context *ldb = ldb_module_get_ctx(module);
1555 struct dsdb_fsmo_extended_op *exop;
1558 exop = talloc_get_type(req->op.extended.data, struct dsdb_fsmo_extended_op);
1560 ldb_debug(ldb, LDB_DEBUG_FATAL, "samldb_extended_allocate_rid_pool: invalid extended data\n");
1561 return LDB_ERR_PROTOCOL_ERROR;
1564 ret = ridalloc_allocate_rid_pool_fsmo(module, exop);
1565 if (ret != LDB_SUCCESS) {
1569 return ldb_module_done(req, NULL, NULL, LDB_SUCCESS);
1572 static int samldb_extended(struct ldb_module *module, struct ldb_request *req)
1574 if (strcmp(req->op.extended.oid, DSDB_EXTENDED_ALLOCATE_RID_POOL) == 0) {
1575 return samldb_extended_allocate_rid_pool(module, req);
1578 return ldb_next_request(module, req);
1582 _PUBLIC_ const struct ldb_module_ops ldb_samldb_module_ops = {
1585 .modify = samldb_modify,
1586 .del = samldb_delete,
1587 .extended = samldb_extended