233816f99a2f116186432e27120265a7a44764bc
[obnox/samba/samba-obnox.git] / source4 / dsdb / samdb / ldb_modules / schema.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4
5    Copyright (C) Andrew Tridgell 2009
6    Copyright (C) Andrew Bartlett <abartlet@samba.org> 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 #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"
31
32 /*
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.
36  */
37 const struct dsdb_class *get_last_structural_class(const struct dsdb_schema *schema,
38                                                    const struct ldb_message_element *element)
39 {
40         const struct dsdb_class *last_class;
41
42         if (schema == NULL) {
43                 return NULL;
44         }
45
46         if (element->num_values == 0) {
47                 return NULL;
48         }
49
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;
54         }
55         if (last_class->objectClassCategory > 1) {
56                 return NULL;
57         }
58
59         return last_class;
60 }
61
62