s4:dsdb - introduce a only constant-time "get_last_structural_class()" call
[Samba/bjacke.git] / source4 / dsdb / samdb / ldb_modules / schema.c
blob333fb1b0a68bbe2731a07d8f2ba398599ae3fe09
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
5 Copyright (C) Andrew Tridgell 2009
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "ldb.h"
24 #include "ldb_module.h"
25 #include "librpc/ndr/libndr.h"
26 #include "dsdb/samdb/ldb_modules/util.h"
27 #include "dsdb/samdb/samdb.h"
28 #include "dsdb/common/util.h"
29 #include "libcli/security/security.h"
30 #include "dsdb/samdb/ldb_modules/schema.h"
33 * This function determines the (last) structural or 88 object class of a passed
34 * "objectClass" attribute - per MS-ADTS 3.1.1.1.4 this is the last value.
35 * Without schema this does not work and hence NULL is returned.
37 const struct dsdb_class *get_last_structural_class(const struct dsdb_schema *schema,
38 const struct ldb_message_element *element)
40 const struct dsdb_class *last_class;
42 if (schema == NULL) {
43 return NULL;
46 if (element->num_values == 0) {
47 return NULL;
50 last_class = dsdb_class_by_lDAPDisplayName_ldb_val(schema,
51 &element->values[element->num_values-1]);
52 if (last_class == NULL) {
53 return NULL;
55 if (last_class->objectClassCategory > 1) {
56 return NULL;
59 return last_class;
62 const struct GUID *get_oc_guid_from_message(struct ldb_module *module,
63 const struct dsdb_schema *schema,
64 struct ldb_message *msg)
66 struct ldb_message_element *oc_el;
68 oc_el = ldb_msg_find_element(msg, "objectClass");
69 if (!oc_el) {
70 return NULL;
73 return class_schemaid_guid_by_lDAPDisplayName(schema,
74 (char *)oc_el->values[oc_el->num_values-1].data);