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"
41 #include "param/param.h"
45 typedef int (*samldb_step_fn_t)(struct samldb_ctx *);
48 struct samldb_step *next;
53 struct ldb_module *module;
54 struct ldb_request *req;
56 /* used for add operations */
59 /* the resulting message */
60 struct ldb_message *msg;
62 /* used in "samldb_find_for_defaultObjectCategory" */
63 struct ldb_dn *dn, *res_dn;
65 /* all the async steps necessary to complete the operation */
66 struct samldb_step *steps;
67 struct samldb_step *curstep;
69 /* If someone set an ares to forward controls and response back to the caller */
70 struct ldb_reply *ares;
73 static struct samldb_ctx *samldb_ctx_init(struct ldb_module *module,
74 struct ldb_request *req)
76 struct ldb_context *ldb;
77 struct samldb_ctx *ac;
79 ldb = ldb_module_get_ctx(module);
81 ac = talloc_zero(req, struct samldb_ctx);
93 static int samldb_add_step(struct samldb_ctx *ac, samldb_step_fn_t fn)
95 struct samldb_step *step, *stepper;
97 step = talloc_zero(ac, struct samldb_step);
99 return ldb_oom(ldb_module_get_ctx(ac->module));
104 if (ac->steps == NULL) {
108 if (ac->curstep == NULL)
109 return ldb_operr(ldb_module_get_ctx(ac->module));
110 for (stepper = ac->curstep; stepper->next != NULL;
111 stepper = stepper->next);
112 stepper->next = step;
118 static int samldb_first_step(struct samldb_ctx *ac)
120 if (ac->steps == NULL) {
121 return ldb_operr(ldb_module_get_ctx(ac->module));
124 ac->curstep = ac->steps;
125 return ac->curstep->fn(ac);
128 static int samldb_next_step(struct samldb_ctx *ac)
130 if (ac->curstep->next) {
131 ac->curstep = ac->curstep->next;
132 return ac->curstep->fn(ac);
135 /* we exit the samldb module here */
136 /* If someone set an ares to forward controls and response back to the caller, use them */
138 return ldb_module_done(ac->req, ac->ares->controls,
139 ac->ares->response, LDB_SUCCESS);
141 return ldb_module_done(ac->req, NULL, NULL, LDB_SUCCESS);
146 /* sAMAccountName handling */
148 static int samldb_generate_sAMAccountName(struct ldb_context *ldb, struct ldb_message *msg)
152 /* Format: $000000-000000000000 */
154 name = talloc_asprintf(msg, "$%.6X-%.6X%.6X",
155 (unsigned int)generate_random(),
156 (unsigned int)generate_random(),
157 (unsigned int)generate_random());
161 return ldb_msg_add_steal_string(msg, "sAMAccountName", name);
164 static int samldb_check_sAMAccountName(struct samldb_ctx *ac)
166 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
170 if (ldb_msg_find_element(ac->msg, "sAMAccountName") == NULL) {
171 ret = samldb_generate_sAMAccountName(ldb, ac->msg);
172 if (ret != LDB_SUCCESS) {
177 name = ldb_msg_find_attr_as_string(ac->msg, "sAMAccountName", NULL);
179 return ldb_operr(ldb);
182 ret = samdb_search_count(ldb, NULL, "(sAMAccountName=%s)",
183 ldb_binary_encode_string(ac, name));
184 if ((ret < 0) || (ret > 1)) {
185 return ldb_operr(ldb);
188 return LDB_ERR_ENTRY_ALREADY_EXISTS;
191 return samldb_next_step(ac);
195 static bool samldb_msg_add_sid(struct ldb_message *msg,
197 const struct dom_sid *sid)
200 enum ndr_err_code ndr_err;
202 ndr_err = ndr_push_struct_blob(&v, msg, sid,
203 (ndr_push_flags_fn_t)ndr_push_dom_sid);
204 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
207 return (ldb_msg_add_value(msg, name, &v, NULL) == 0);
211 /* allocate a SID using our RID Set */
212 static int samldb_allocate_sid(struct samldb_ctx *ac)
216 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
219 ret = ridalloc_allocate_rid(ac->module, &rid);
220 if (ret != LDB_SUCCESS) {
224 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
226 return ldb_module_oom(ac->module);
229 if ( ! samldb_msg_add_sid(ac->msg, "objectSid", sid)) {
230 return ldb_operr(ldb);
233 return samldb_next_step(ac);
237 see if a krbtgt_number is available
239 static bool samldb_krbtgtnumber_available(struct samldb_ctx *ac, unsigned krbtgt_number)
241 TALLOC_CTX *tmp_ctx = talloc_new(ac);
242 struct ldb_result *res;
243 const char *attrs[] = { NULL };
246 ret = dsdb_module_search(ac->module, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE,
247 attrs, DSDB_FLAG_NEXT_MODULE,
248 "msDC-SecondaryKrbTgtNumber=%u", krbtgt_number);
249 if (ret == LDB_SUCCESS && res->count == 0) {
250 talloc_free(tmp_ctx);
253 talloc_free(tmp_ctx);
257 /* special handling for add in RODC join */
258 static int samldb_rodc_add(struct samldb_ctx *ac)
260 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
261 uint32_t krbtgt_number, i_start, i;
265 /* find a unused msDC-SecondaryKrbTgtNumber */
266 i_start = generate_random() & 0xFFFF;
271 for (i=i_start; i<=0xFFFF; i++) {
272 if (samldb_krbtgtnumber_available(ac, i)) {
277 for (i=1; i<i_start; i++) {
278 if (samldb_krbtgtnumber_available(ac, i)) {
284 ldb_asprintf_errstring(ldb,
285 "%08X: Unable to find available msDS-SecondaryKrbTgtNumber",
286 W_ERROR_V(WERR_NO_SYSTEM_RESOURCES));
287 return LDB_ERR_OTHER;
290 ret = ldb_msg_add_empty(ac->msg, "msDS-SecondaryKrbTgtNumber", LDB_FLAG_INTERNAL_DISABLE_VALIDATION, NULL);
291 if (ret != LDB_SUCCESS) {
292 return ldb_operr(ldb);
295 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
296 "msDS-SecondaryKrbTgtNumber", krbtgt_number);
297 if (ret != LDB_SUCCESS) {
298 return ldb_operr(ldb);
301 ret = ldb_msg_add_fmt(ac->msg, "sAMAccountName", "krbtgt_%u", krbtgt_number);
302 if (ret != LDB_SUCCESS) {
303 return ldb_operr(ldb);
306 newpass = generate_random_password(ac, 128, 255);
307 if (newpass == NULL) {
308 return ldb_operr(ldb);
311 ret = ldb_msg_add_steal_string(ac->msg, "clearTextPassword", newpass);
312 if (ret != LDB_SUCCESS) {
313 return ldb_operr(ldb);
316 return samldb_next_step(ac);
319 static int samldb_find_for_defaultObjectCategory(struct samldb_ctx *ac)
321 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
322 struct ldb_result *res;
323 const char *no_attrs[] = { NULL };
328 ret = dsdb_module_search(ac->module, ac, &res,
329 ac->dn, LDB_SCOPE_BASE, no_attrs,
330 DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT | DSDB_FLAG_NEXT_MODULE,
331 "(objectClass=classSchema)");
332 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
333 /* Don't be pricky when the DN doesn't exist if we have the */
334 /* RELAX control specified */
335 if (ldb_request_get_control(ac->req,
336 LDB_CONTROL_RELAX_OID) == NULL) {
337 ldb_set_errstring(ldb,
338 "samldb_find_defaultObjectCategory: "
339 "Invalid DN for 'defaultObjectCategory'!");
340 return LDB_ERR_CONSTRAINT_VIOLATION;
343 if ((ret != LDB_ERR_NO_SUCH_OBJECT) && (ret != LDB_SUCCESS)) {
349 return samldb_next_step(ac);
353 * msDS-IntId attributeSchema attribute handling
354 * during LDB_ADD request processing
356 static int samldb_add_handle_msDS_IntId(struct samldb_ctx *ac)
361 int32_t system_flags;
362 struct ldb_context *ldb;
363 struct ldb_result *ldb_res;
364 struct ldb_dn *schema_dn;
366 ldb = ldb_module_get_ctx(ac->module);
367 schema_dn = ldb_get_schema_basedn(ldb);
369 /* replicated update should always go through */
370 if (ldb_request_get_control(ac->req, DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
374 /* msDS-IntId is handled by system and should never be
375 * passed by clients */
376 if (ldb_msg_find_element(ac->msg, "msDS-IntId")) {
377 return LDB_ERR_UNWILLING_TO_PERFORM;
380 /* do not generate msDS-IntId if Relax control is passed */
381 if (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
385 /* check Functional Level */
386 if (dsdb_functional_level(ldb) < DS_DOMAIN_FUNCTION_2003) {
390 /* check systemFlags for SCHEMA_BASE_OBJECT flag */
391 system_flags = ldb_msg_find_attr_as_int(ac->msg, "systemFlags", 0);
392 if (system_flags & SYSTEM_FLAG_SCHEMA_BASE_OBJECT) {
396 /* Generate new value for msDs-IntId
397 * Value should be in 0x80000000..0xBFFFFFFF range */
398 msds_intid = generate_random() % 0X3FFFFFFF;
399 msds_intid += 0x80000000;
401 /* probe id values until unique one is found */
404 if (msds_intid > 0xBFFFFFFF) {
405 msds_intid = 0x80000001;
408 ret = dsdb_module_search(ac->module, ac,
410 schema_dn, LDB_SCOPE_ONELEVEL, NULL,
411 DSDB_FLAG_NEXT_MODULE,
412 "(msDS-IntId=%d)", msds_intid);
413 if (ret != LDB_SUCCESS) {
414 ldb_debug_set(ldb, LDB_DEBUG_ERROR,
415 __location__": Searching for msDS-IntId=%d failed - %s\n",
418 return ldb_operr(ldb);
420 id_exists = (ldb_res->count > 0);
422 talloc_free(ldb_res);
425 return samdb_msg_add_int(ldb, ac->msg, ac->msg, "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 ret = dsdb_module_schema_info_update(ac->module, schema, DSDB_FLAG_NEXT_MODULE);
733 if (ret != LDB_SUCCESS) {
734 ldb_asprintf_errstring(ldb, "samldb_schema_info_update: dsdb_module_schema_info_update failed with %s",
743 * "Objectclass" trigger (MS-SAMR 3.1.1.8.1)
745 * Has to be invoked on "add" and "modify" operations on "user", "computer" and
747 * ac->msg contains the "add"/"modify" message
748 * ac->type contains the object type (main objectclass)
750 static int samldb_objectclass_trigger(struct samldb_ctx *ac)
752 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
753 struct loadparm_context *lp_ctx = talloc_get_type(ldb_get_opaque(ldb,
754 "loadparm"), struct loadparm_context);
755 struct ldb_message_element *el, *el2;
756 enum sid_generator sid_generator;
761 /* make sure that "sAMAccountType" is not specified */
762 el = ldb_msg_find_element(ac->msg, "sAMAccountType");
764 ldb_set_errstring(ldb,
765 "samldb: sAMAccountType must not be specified!");
766 return LDB_ERR_UNWILLING_TO_PERFORM;
769 /* Step 1: objectSid assignment */
771 /* Don't allow the objectSid to be changed. But beside the RELAX
772 * control we have also to guarantee that it can always be set with
773 * SYSTEM permissions. This is needed for the "samba3sam" backend. */
774 sid = samdb_result_dom_sid(ac, ac->msg, "objectSid");
775 if ((sid != NULL) && (!dsdb_module_am_system(ac->module)) &&
776 (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID) == NULL)) {
777 ldb_asprintf_errstring(ldb, "No SID may be specified in user/group modifications for %s",
778 ldb_dn_get_linearized(ac->msg->dn));
779 return LDB_ERR_UNWILLING_TO_PERFORM;
782 /* but generate a new SID when we do have an add operations */
783 if ((sid == NULL) && (ac->req->operation == LDB_ADD)) {
784 sid_generator = lpcfg_sid_generator(lp_ctx);
785 if (sid_generator == SID_GENERATOR_INTERNAL) {
786 ret = samldb_add_step(ac, samldb_allocate_sid);
787 if (ret != LDB_SUCCESS) return ret;
791 if (strcmp(ac->type, "user") == 0) {
792 /* Step 1.2: Default values */
793 tempstr = talloc_asprintf(ac->msg, "%d", UF_NORMAL_ACCOUNT);
794 if (tempstr == NULL) return ldb_operr(ldb);
795 ret = samdb_find_or_add_attribute(ldb, ac->msg,
796 "userAccountControl", tempstr);
797 if (ret != LDB_SUCCESS) return ret;
798 ret = samdb_find_or_add_attribute(ldb, ac->msg,
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,
808 "badPasswordTime", "0");
809 if (ret != LDB_SUCCESS) return ret;
810 ret = samdb_find_or_add_attribute(ldb, ac->msg,
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,
820 "accountExpires", "9223372036854775807");
821 if (ret != LDB_SUCCESS) return ret;
822 ret = samdb_find_or_add_attribute(ldb, ac->msg,
824 if (ret != LDB_SUCCESS) return ret;
826 el = ldb_msg_find_element(ac->msg, "userAccountControl");
828 uint32_t user_account_control, account_type;
830 /* Step 1.3: "userAccountControl" -> "sAMAccountType" mapping */
831 user_account_control = ldb_msg_find_attr_as_uint(ac->msg,
832 "userAccountControl",
835 /* Temporary duplicate accounts aren't allowed */
836 if ((user_account_control & UF_TEMP_DUPLICATE_ACCOUNT) != 0) {
837 return LDB_ERR_OTHER;
840 account_type = ds_uf2atype(user_account_control);
841 if (account_type == 0) {
842 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
843 return LDB_ERR_UNWILLING_TO_PERFORM;
845 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
848 if (ret != LDB_SUCCESS) {
851 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
852 el2->flags = LDB_FLAG_MOD_REPLACE;
854 if (user_account_control &
855 (UF_SERVER_TRUST_ACCOUNT | UF_PARTIAL_SECRETS_ACCOUNT)) {
856 ret = samdb_msg_set_string(ldb, ac->msg, ac->msg,
857 "isCriticalSystemObject",
859 if (ret != LDB_SUCCESS) {
862 el2 = ldb_msg_find_element(ac->msg,
863 "isCriticalSystemObject");
864 el2->flags = LDB_FLAG_MOD_REPLACE;
867 /* Step 1.4: "userAccountControl" -> "primaryGroupID" mapping */
868 if (!ldb_msg_find_element(ac->msg, "primaryGroupID")) {
869 uint32_t rid = ds_uf2prim_group_rid(user_account_control);
870 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
871 "primaryGroupID", rid);
872 if (ret != LDB_SUCCESS) {
875 el2 = ldb_msg_find_element(ac->msg,
877 el2->flags = LDB_FLAG_MOD_REPLACE;
880 /* Step 1.5: Add additional flags when needed */
881 if ((user_account_control & UF_NORMAL_ACCOUNT) &&
882 (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID) == NULL)) {
883 user_account_control |= UF_ACCOUNTDISABLE;
884 user_account_control |= UF_PASSWD_NOTREQD;
886 ret = samdb_msg_set_uint(ldb, ac->msg, ac->msg,
887 "userAccountControl",
888 user_account_control);
889 if (ret != LDB_SUCCESS) {
895 } else if (strcmp(ac->type, "group") == 0) {
896 /* Step 2.2: Default values */
897 tempstr = talloc_asprintf(ac->msg, "%d",
898 GTYPE_SECURITY_GLOBAL_GROUP);
899 if (tempstr == NULL) return ldb_operr(ldb);
900 ret = samdb_find_or_add_attribute(ldb, ac->msg,
901 "groupType", tempstr);
902 if (ret != LDB_SUCCESS) return ret;
904 /* Step 2.3: "groupType" -> "sAMAccountType" */
905 el = ldb_msg_find_element(ac->msg, "groupType");
907 uint32_t group_type, account_type;
909 group_type = ldb_msg_find_attr_as_uint(ac->msg,
912 /* The creation of builtin groups requires the
914 if (group_type == GTYPE_SECURITY_BUILTIN_LOCAL_GROUP) {
915 if (ldb_request_get_control(ac->req,
916 LDB_CONTROL_RELAX_OID) == NULL) {
917 return LDB_ERR_UNWILLING_TO_PERFORM;
921 account_type = ds_gtype2atype(group_type);
922 if (account_type == 0) {
923 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
924 return LDB_ERR_UNWILLING_TO_PERFORM;
926 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
929 if (ret != LDB_SUCCESS) {
932 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
933 el2->flags = LDB_FLAG_MOD_REPLACE;
941 * "Primary group ID" trigger (MS-SAMR 3.1.1.8.2)
943 * Has to be invoked on "add" and "modify" operations on "user" and "computer"
945 * ac->msg contains the "add"/"modify" message
948 static int samldb_prim_group_set(struct samldb_ctx *ac)
950 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
951 struct ldb_dn *prim_group_dn;
955 rid = ldb_msg_find_attr_as_uint(ac->msg, "primaryGroupID", (uint32_t) -1);
956 if (rid == (uint32_t) -1) {
957 /* we aren't affected of any primary group set */
960 } else if (!ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
961 ldb_set_errstring(ldb,
962 "The primary group isn't settable on add operations!");
963 return LDB_ERR_UNWILLING_TO_PERFORM;
966 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
968 return ldb_operr(ldb);
971 prim_group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
972 ldap_encode_ndr_dom_sid(ac, sid));
973 if (prim_group_dn == NULL) {
974 ldb_asprintf_errstring(ldb,
975 "Failed to find primary group with RID %u!",
977 return LDB_ERR_UNWILLING_TO_PERFORM;
983 static int samldb_prim_group_change(struct samldb_ctx *ac)
985 struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
986 const char * attrs[] = { "primaryGroupID", "memberOf", NULL };
987 struct ldb_result *res;
988 struct ldb_message_element *el;
989 struct ldb_message *msg;
992 struct ldb_dn *prev_prim_group_dn, *new_prim_group_dn;
995 /* Fetch informations from the existing object */
997 ret = ldb_search(ldb, ac, &res, ac->msg->dn, LDB_SCOPE_BASE, attrs,
999 if (ret != LDB_SUCCESS) {
1003 /* Finds out the DN of the old primary group */
1005 rid = ldb_msg_find_attr_as_uint(res->msgs[0], "primaryGroupID", (uint32_t) -1);
1006 if (rid == (uint32_t) -1) {
1007 /* User objects do always have a mandatory "primaryGroupID"
1008 * attribute. If this doesn't exist then the object is of the
1009 * wrong type. This is the exact Windows error code */
1010 return LDB_ERR_OBJECT_CLASS_VIOLATION;
1013 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
1015 return ldb_operr(ldb);
1018 prev_prim_group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
1019 ldap_encode_ndr_dom_sid(ac, sid));
1020 if (prev_prim_group_dn == NULL) {
1021 return ldb_operr(ldb);
1024 /* Finds out the DN of the new primary group */
1026 rid = ldb_msg_find_attr_as_uint(ac->msg, "primaryGroupID", (uint32_t) -1);
1027 if (rid == (uint32_t) -1) {
1028 /* we aren't affected of any primary group change */
1032 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
1034 return ldb_operr(ldb);
1037 new_prim_group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
1038 ldap_encode_ndr_dom_sid(ac, sid));
1039 if (new_prim_group_dn == NULL) {
1040 /* Here we know if the specified new primary group candidate is
1042 return LDB_ERR_UNWILLING_TO_PERFORM;
1045 /* Only update the "member" attributes when we really do have a change */
1046 if (ldb_dn_compare(new_prim_group_dn, prev_prim_group_dn) != 0) {
1047 /* We need to be already a normal member of the new primary
1048 * group in order to be successful. */
1049 el = samdb_find_attribute(ldb, res->msgs[0], "memberOf",
1050 ldb_dn_get_linearized(new_prim_group_dn));
1052 return LDB_ERR_UNWILLING_TO_PERFORM;
1055 /* Remove the "member" attribute on the new primary group */
1056 msg = talloc_zero(ac, struct ldb_message);
1057 msg->dn = new_prim_group_dn;
1059 ret = samdb_msg_add_delval(ldb, ac, msg, "member",
1060 ldb_dn_get_linearized(ac->msg->dn));
1061 if (ret != LDB_SUCCESS) {
1065 ret = dsdb_module_modify(ac->module, msg, DSDB_FLAG_NEXT_MODULE);
1066 if (ret != LDB_SUCCESS) {
1070 /* Add a "member" attribute for the previous primary group */
1071 msg = talloc_zero(ac, struct ldb_message);
1072 msg->dn = prev_prim_group_dn;
1074 ret = samdb_msg_add_addval(ldb, ac, msg, "member",
1075 ldb_dn_get_linearized(ac->msg->dn));
1076 if (ret != LDB_SUCCESS) {
1080 ret = dsdb_module_modify(ac->module, msg, DSDB_FLAG_NEXT_MODULE);
1081 if (ret != LDB_SUCCESS) {
1089 static int samldb_prim_group_trigger(struct samldb_ctx *ac)
1093 if (ac->req->operation == LDB_ADD) {
1094 ret = samldb_prim_group_set(ac);
1096 ret = samldb_prim_group_change(ac);
1102 static int samldb_member_check(struct samldb_ctx *ac)
1104 struct ldb_context *ldb;
1105 struct ldb_message_element *el;
1106 struct ldb_dn *member_dn, *group_dn;
1107 uint32_t prim_group_rid;
1108 struct dom_sid *sid;
1111 ldb = ldb_module_get_ctx(ac->module);
1113 el = ldb_msg_find_element(ac->msg, "member");
1115 /* we aren't affected */
1119 for (i = 0; i < el->num_values; i++) {
1120 /* Denies to add "member"s to groups which are primary ones
1122 member_dn = ldb_dn_from_ldb_val(ac, ldb, &el->values[i]);
1123 if (!ldb_dn_validate(member_dn)) {
1124 return ldb_operr(ldb);
1127 prim_group_rid = samdb_search_uint(ldb, ac, (uint32_t) -1,
1128 member_dn, "primaryGroupID",
1130 if (prim_group_rid == (uint32_t) -1) {
1131 /* the member hasn't to be a user account -> therefore
1132 * no check needed in this case. */
1136 sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb),
1139 return ldb_operr(ldb);
1142 group_dn = samdb_search_dn(ldb, ac, NULL, "(objectSid=%s)",
1143 ldap_encode_ndr_dom_sid(ac, sid));
1144 if (group_dn == NULL) {
1145 return ldb_operr(ldb);
1148 if (ldb_dn_compare(group_dn, ac->msg->dn) == 0) {
1149 return LDB_ERR_ENTRY_ALREADY_EXISTS;
1158 static int samldb_add(struct ldb_module *module, struct ldb_request *req)
1160 struct ldb_context *ldb;
1161 struct samldb_ctx *ac;
1164 ldb = ldb_module_get_ctx(module);
1165 ldb_debug(ldb, LDB_DEBUG_TRACE, "samldb_add\n");
1167 /* do not manipulate our control entries */
1168 if (ldb_dn_is_special(req->op.add.message->dn)) {
1169 return ldb_next_request(module, req);
1172 ac = samldb_ctx_init(module, req);
1174 return ldb_operr(ldb);
1177 /* build the new msg */
1178 ac->msg = ldb_msg_copy_shallow(ac, req->op.add.message);
1179 if (ac->msg == NULL) {
1181 ldb_debug(ldb, LDB_DEBUG_FATAL,
1182 "samldb_add: ldb_msg_copy_shallow failed!\n");
1183 return ldb_operr(ldb);
1186 if (samdb_find_attribute(ldb, ac->msg,
1187 "objectclass", "user") != NULL) {
1190 ret = samldb_prim_group_trigger(ac);
1191 if (ret != LDB_SUCCESS) {
1195 ret = samldb_objectclass_trigger(ac);
1196 if (ret != LDB_SUCCESS) {
1200 return samldb_fill_object(ac);
1203 if (samdb_find_attribute(ldb, ac->msg,
1204 "objectclass", "group") != NULL) {
1207 ret = samldb_objectclass_trigger(ac);
1208 if (ret != LDB_SUCCESS) {
1212 return samldb_fill_object(ac);
1215 /* perhaps a foreignSecurityPrincipal? */
1216 if (samdb_find_attribute(ldb, ac->msg,
1218 "foreignSecurityPrincipal") != NULL) {
1219 return samldb_fill_foreignSecurityPrincipal_object(ac);
1222 if (samdb_find_attribute(ldb, ac->msg,
1223 "objectclass", "classSchema") != NULL) {
1224 ret = samldb_schema_info_update(ac);
1225 if (ret != LDB_SUCCESS) {
1230 ac->type = "classSchema";
1231 return samldb_fill_object(ac);
1234 if (samdb_find_attribute(ldb, ac->msg,
1235 "objectclass", "attributeSchema") != NULL) {
1236 ret = samldb_schema_info_update(ac);
1237 if (ret != LDB_SUCCESS) {
1242 ac->type = "attributeSchema";
1243 return samldb_fill_object(ac);
1248 /* nothing matched, go on */
1249 return ldb_next_request(module, req);
1253 static int samldb_modify(struct ldb_module *module, struct ldb_request *req)
1255 struct ldb_context *ldb;
1256 struct samldb_ctx *ac;
1257 struct ldb_message_element *el, *el2;
1258 bool modified = false;
1260 uint32_t account_type;
1262 if (ldb_dn_is_special(req->op.mod.message->dn)) {
1263 /* do not manipulate our control entries */
1264 return ldb_next_request(module, req);
1267 ldb = ldb_module_get_ctx(module);
1269 /* make sure that "sAMAccountType" is not specified */
1270 el = ldb_msg_find_element(req->op.mod.message, "sAMAccountType");
1272 ldb_set_errstring(ldb,
1273 "samldb: sAMAccountType must not be specified!");
1274 return LDB_ERR_UNWILLING_TO_PERFORM;
1276 /* make sure that "isCriticalSystemObject" is not specified */
1277 el = ldb_msg_find_element(req->op.mod.message, "isCriticalSystemObject");
1279 if (ldb_request_get_control(req, LDB_CONTROL_RELAX_OID) == NULL) {
1280 ldb_set_errstring(ldb,
1281 "samldb: isCriticalSystemObject must not be specified!");
1282 return LDB_ERR_UNWILLING_TO_PERFORM;
1286 /* msDS-IntId is not allowed to be modified
1287 * except when modification comes from replication */
1288 if (ldb_msg_find_element(req->op.mod.message, "msDS-IntId")) {
1289 if (!ldb_request_get_control(req, DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
1290 return LDB_ERR_CONSTRAINT_VIOLATION;
1294 ac = samldb_ctx_init(module, req);
1296 return ldb_operr(ldb);
1299 /* build the new msg */
1300 ac->msg = ldb_msg_copy_shallow(ac, req->op.mod.message);
1301 if (ac->msg == NULL) {
1303 ldb_debug(ldb, LDB_DEBUG_FATAL,
1304 "samldb_modify: ldb_msg_copy_shallow failed!\n");
1305 return ldb_operr(ldb);
1308 el = ldb_msg_find_element(ac->msg, "groupType");
1309 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1310 uint32_t group_type, old_group_type;
1314 group_type = ldb_msg_find_attr_as_uint(ac->msg, "groupType", 0);
1315 old_group_type = samdb_search_uint(ldb, ac, 0, ac->msg->dn,
1317 if (old_group_type == 0) {
1318 return ldb_operr(ldb);
1321 /* Group type switching isn't so easy as it seems: We can only
1322 * change in this directions: global <-> universal <-> local
1323 * On each step also the group type itself
1324 * (security/distribution) is variable. */
1326 switch (group_type) {
1327 case GTYPE_SECURITY_GLOBAL_GROUP:
1328 case GTYPE_DISTRIBUTION_GLOBAL_GROUP:
1329 /* change to "universal" allowed */
1330 if ((old_group_type == GTYPE_SECURITY_DOMAIN_LOCAL_GROUP) ||
1331 (old_group_type == GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP)) {
1332 return LDB_ERR_UNWILLING_TO_PERFORM;
1336 case GTYPE_SECURITY_UNIVERSAL_GROUP:
1337 case GTYPE_DISTRIBUTION_UNIVERSAL_GROUP:
1338 /* each change allowed */
1341 case GTYPE_SECURITY_DOMAIN_LOCAL_GROUP:
1342 case GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP:
1343 /* change to "universal" allowed */
1344 if ((old_group_type == GTYPE_SECURITY_GLOBAL_GROUP) ||
1345 (old_group_type == GTYPE_DISTRIBUTION_GLOBAL_GROUP)) {
1346 return LDB_ERR_UNWILLING_TO_PERFORM;
1350 case GTYPE_SECURITY_BUILTIN_LOCAL_GROUP:
1352 /* we don't allow this "groupType" values */
1353 return LDB_ERR_UNWILLING_TO_PERFORM;
1357 account_type = ds_gtype2atype(group_type);
1358 if (account_type == 0) {
1359 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
1360 return LDB_ERR_UNWILLING_TO_PERFORM;
1362 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
1365 if (ret != LDB_SUCCESS) {
1368 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
1369 el2->flags = LDB_FLAG_MOD_REPLACE;
1371 el = ldb_msg_find_element(ac->msg, "groupType");
1372 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE)) {
1373 return LDB_ERR_UNWILLING_TO_PERFORM;
1376 el = ldb_msg_find_element(ac->msg, "primaryGroupID");
1377 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1380 ret = samldb_prim_group_change(ac);
1381 if (ret != LDB_SUCCESS) {
1385 el = ldb_msg_find_element(ac->msg, "primaryGroupID");
1386 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE)) {
1387 return LDB_ERR_UNWILLING_TO_PERFORM;
1390 el = ldb_msg_find_element(ac->msg, "userAccountControl");
1391 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1392 uint32_t user_account_control;
1396 user_account_control = ldb_msg_find_attr_as_uint(ac->msg,
1397 "userAccountControl",
1400 /* Temporary duplicate accounts aren't allowed */
1401 if ((user_account_control & UF_TEMP_DUPLICATE_ACCOUNT) != 0) {
1402 return LDB_ERR_OTHER;
1405 account_type = ds_uf2atype(user_account_control);
1406 if (account_type == 0) {
1407 ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
1408 return LDB_ERR_UNWILLING_TO_PERFORM;
1410 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
1413 if (ret != LDB_SUCCESS) {
1416 el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
1417 el2->flags = LDB_FLAG_MOD_REPLACE;
1419 if (user_account_control & (UF_SERVER_TRUST_ACCOUNT | UF_PARTIAL_SECRETS_ACCOUNT)) {
1420 ret = samdb_msg_add_string(ldb, ac->msg, ac->msg,
1421 "isCriticalSystemObject",
1423 if (ret != LDB_SUCCESS) {
1426 el2 = ldb_msg_find_element(ac->msg,
1427 "isCriticalSystemObject");
1428 el2->flags = LDB_FLAG_MOD_REPLACE;
1431 if (!ldb_msg_find_element(ac->msg, "primaryGroupID")) {
1432 uint32_t rid = ds_uf2prim_group_rid(user_account_control);
1434 ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
1435 "primaryGroupID", rid);
1436 if (ret != LDB_SUCCESS) {
1439 el2 = ldb_msg_find_element(ac->msg,
1441 el2->flags = LDB_FLAG_MOD_REPLACE;
1444 el = ldb_msg_find_element(ac->msg, "userAccountControl");
1445 if (el && (LDB_FLAG_MOD_TYPE(el->flags) == LDB_FLAG_MOD_DELETE)) {
1446 return LDB_ERR_UNWILLING_TO_PERFORM;
1449 el = ldb_msg_find_element(ac->msg, "member");
1450 if (el && el->flags & (LDB_FLAG_MOD_ADD|LDB_FLAG_MOD_REPLACE) && el->num_values == 1) {
1451 ret = samldb_member_check(ac);
1452 if (ret != LDB_SUCCESS) {
1458 struct ldb_request *child_req;
1460 /* Now perform the real modifications as a child request */
1461 ret = ldb_build_mod_req(&child_req, ldb, ac,
1464 req, dsdb_next_callback,
1466 LDB_REQ_SET_LOCATION(child_req);
1467 if (ret != LDB_SUCCESS) {
1471 return ldb_next_request(module, child_req);
1476 /* no change which interests us, go on */
1477 return ldb_next_request(module, req);
1482 static int samldb_prim_group_users_check(struct samldb_ctx *ac)
1484 struct ldb_context *ldb;
1485 struct dom_sid *sid;
1490 ldb = ldb_module_get_ctx(ac->module);
1492 /* Finds out the SID/RID of the SAM object */
1493 sid = samdb_search_dom_sid(ldb, ac, ac->req->op.del.dn, "objectSid",
1496 /* No SID - it might not be a SAM object - therefore ok */
1499 status = dom_sid_split_rid(ac, sid, NULL, &rid);
1500 if (!NT_STATUS_IS_OK(status)) {
1501 return ldb_operr(ldb);
1504 /* Special object (security principal?) */
1508 /* Deny delete requests from groups which are primary ones */
1509 count = samdb_search_count(ldb, NULL,
1510 "(&(primaryGroupID=%u)(objectClass=user))",
1513 return ldb_operr(ldb);
1516 return LDB_ERR_ENTRY_ALREADY_EXISTS;
1522 static int samldb_delete(struct ldb_module *module, struct ldb_request *req)
1524 struct samldb_ctx *ac;
1527 if (ldb_dn_is_special(req->op.del.dn)) {
1528 /* do not manipulate our control entries */
1529 return ldb_next_request(module, req);
1532 ac = samldb_ctx_init(module, req);
1534 return ldb_operr(ldb_module_get_ctx(module));
1537 ret = samldb_prim_group_users_check(ac);
1538 if (ret != LDB_SUCCESS) {
1544 return ldb_next_request(module, req);
1549 static int samldb_extended_allocate_rid_pool(struct ldb_module *module, struct ldb_request *req)
1551 struct ldb_context *ldb = ldb_module_get_ctx(module);
1552 struct dsdb_fsmo_extended_op *exop;
1555 exop = talloc_get_type(req->op.extended.data, struct dsdb_fsmo_extended_op);
1557 ldb_debug(ldb, LDB_DEBUG_FATAL, "samldb_extended_allocate_rid_pool: invalid extended data\n");
1558 return LDB_ERR_PROTOCOL_ERROR;
1561 ret = ridalloc_allocate_rid_pool_fsmo(module, exop);
1562 if (ret != LDB_SUCCESS) {
1566 return ldb_module_done(req, NULL, NULL, LDB_SUCCESS);
1569 static int samldb_extended(struct ldb_module *module, struct ldb_request *req)
1571 if (strcmp(req->op.extended.oid, DSDB_EXTENDED_ALLOCATE_RID_POOL) == 0) {
1572 return samldb_extended_allocate_rid_pool(module, req);
1575 return ldb_next_request(module, req);
1579 _PUBLIC_ const struct ldb_module_ops ldb_samldb_module_ops = {
1582 .modify = samldb_modify,
1583 .del = samldb_delete,
1584 .extended = samldb_extended