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