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 "dsdb/samdb/samdb.h"
|
---|
24 | #include <ldb_module.h>
|
---|
25 | #include "librpc/ndr/libndr.h"
|
---|
26 | #include "libcli/security/dom_sid.h"
|
---|
27 |
|
---|
28 | /*
|
---|
29 | convert a dsdb_dn to a linked attribute data blob
|
---|
30 | */
|
---|
31 | WERROR dsdb_dn_la_to_blob(struct ldb_context *sam_ctx,
|
---|
32 | const struct dsdb_attribute *schema_attrib,
|
---|
33 | const struct dsdb_schema *schema,
|
---|
34 | TALLOC_CTX *mem_ctx,
|
---|
35 | struct dsdb_dn *dsdb_dn, DATA_BLOB **blob)
|
---|
36 | {
|
---|
37 | struct ldb_val v;
|
---|
38 | WERROR werr;
|
---|
39 | struct ldb_message_element val_el;
|
---|
40 | struct drsuapi_DsReplicaAttribute drs;
|
---|
41 | struct dsdb_syntax_ctx syntax_ctx;
|
---|
42 |
|
---|
43 | /* use default syntax conversion context */
|
---|
44 | dsdb_syntax_ctx_init(&syntax_ctx, sam_ctx, schema);
|
---|
45 |
|
---|
46 | /* we need a message_element with just one value in it */
|
---|
47 | v = data_blob_string_const(dsdb_dn_get_extended_linearized(mem_ctx, dsdb_dn, 1));
|
---|
48 |
|
---|
49 | val_el.name = schema_attrib->lDAPDisplayName;
|
---|
50 | val_el.values = &v;
|
---|
51 | val_el.num_values = 1;
|
---|
52 |
|
---|
53 | werr = schema_attrib->syntax->ldb_to_drsuapi(&syntax_ctx, schema_attrib, &val_el, mem_ctx, &drs);
|
---|
54 | W_ERROR_NOT_OK_RETURN(werr);
|
---|
55 |
|
---|
56 | if (drs.value_ctr.num_values != 1) {
|
---|
57 | DEBUG(1,(__location__ ": Failed to build DRS blob for linked attribute %s\n",
|
---|
58 | schema_attrib->lDAPDisplayName));
|
---|
59 | return WERR_DS_DRA_INTERNAL_ERROR;
|
---|
60 | }
|
---|
61 |
|
---|
62 | *blob = drs.value_ctr.values[0].blob;
|
---|
63 | return WERR_OK;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /*
|
---|
67 | convert a data blob to a dsdb_dn
|
---|
68 | */
|
---|
69 | WERROR dsdb_dn_la_from_blob(struct ldb_context *sam_ctx,
|
---|
70 | const struct dsdb_attribute *schema_attrib,
|
---|
71 | const struct dsdb_schema *schema,
|
---|
72 | TALLOC_CTX *mem_ctx,
|
---|
73 | DATA_BLOB *blob,
|
---|
74 | struct dsdb_dn **dsdb_dn)
|
---|
75 | {
|
---|
76 | WERROR werr;
|
---|
77 | struct ldb_message_element new_el;
|
---|
78 | struct drsuapi_DsReplicaAttribute drs;
|
---|
79 | struct drsuapi_DsAttributeValue val;
|
---|
80 | struct dsdb_syntax_ctx syntax_ctx;
|
---|
81 |
|
---|
82 | /* use default syntax conversion context */
|
---|
83 | dsdb_syntax_ctx_init(&syntax_ctx, sam_ctx, schema);
|
---|
84 |
|
---|
85 | drs.value_ctr.num_values = 1;
|
---|
86 | drs.value_ctr.values = &val;
|
---|
87 | val.blob = blob;
|
---|
88 |
|
---|
89 | werr = schema_attrib->syntax->drsuapi_to_ldb(&syntax_ctx, schema_attrib, &drs, mem_ctx, &new_el);
|
---|
90 | W_ERROR_NOT_OK_RETURN(werr);
|
---|
91 |
|
---|
92 | if (new_el.num_values != 1) {
|
---|
93 | return WERR_INTERNAL_ERROR;
|
---|
94 | }
|
---|
95 |
|
---|
96 | *dsdb_dn = dsdb_dn_parse(mem_ctx, sam_ctx, &new_el.values[0], schema_attrib->syntax->ldap_oid);
|
---|
97 | if (!*dsdb_dn) {
|
---|
98 | return WERR_INTERNAL_ERROR;
|
---|
99 | }
|
---|
100 |
|
---|
101 | return WERR_OK;
|
---|
102 | }
|
---|