1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | DRS::prefixMap implementation
|
---|
5 |
|
---|
6 | Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 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 "librpc/gen_ndr/ndr_drsuapi.h"
|
---|
25 | #include "librpc/gen_ndr/ndr_drsblobs.h"
|
---|
26 | #include "../lib/util/asn1.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Determine range type for supplied ATTID
|
---|
31 | */
|
---|
32 | enum dsdb_attid_type dsdb_pfm_get_attid_type(uint32_t attid)
|
---|
33 | {
|
---|
34 | if (attid <= 0x7FFFFFFF) {
|
---|
35 | return DSDB_ATTID_TYPE_PFM;
|
---|
36 | }
|
---|
37 | else if (attid <= 0xBFFFFFFF) {
|
---|
38 | return DSDB_ATTID_TYPE_INTID;
|
---|
39 | }
|
---|
40 | else if (attid <= 0xFFFEFFFF) {
|
---|
41 | return DSDB_ATTID_TYPE_RESERVED;
|
---|
42 | }
|
---|
43 | else {
|
---|
44 | return DSDB_ATTID_TYPE_INTERNAL;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Allocates schema_prefixMap object in supplied memory context
|
---|
50 | */
|
---|
51 | static struct dsdb_schema_prefixmap *_dsdb_schema_prefixmap_talloc(TALLOC_CTX *mem_ctx,
|
---|
52 | uint32_t length)
|
---|
53 | {
|
---|
54 | struct dsdb_schema_prefixmap *pfm;
|
---|
55 |
|
---|
56 | pfm = talloc_zero(mem_ctx, struct dsdb_schema_prefixmap);
|
---|
57 | if (!pfm) {
|
---|
58 | return NULL;
|
---|
59 | }
|
---|
60 |
|
---|
61 | pfm->length = length;
|
---|
62 | pfm->prefixes = talloc_zero_array(pfm, struct dsdb_schema_prefixmap_oid,
|
---|
63 | pfm->length);
|
---|
64 | if (!pfm->prefixes) {
|
---|
65 | talloc_free(pfm);
|
---|
66 | return NULL;
|
---|
67 | }
|
---|
68 |
|
---|
69 | return pfm;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Initial prefixMap creation according to:
|
---|
74 | * [MS-DRSR] section 5.12.2
|
---|
75 | */
|
---|
76 | WERROR dsdb_schema_pfm_new(TALLOC_CTX *mem_ctx, struct dsdb_schema_prefixmap **_pfm)
|
---|
77 | {
|
---|
78 | uint32_t i;
|
---|
79 | struct dsdb_schema_prefixmap *pfm;
|
---|
80 | const struct {
|
---|
81 | uint32_t id;
|
---|
82 | const char *oid_prefix;
|
---|
83 | } pfm_init_data[] = {
|
---|
84 | {.id=0x00000000, .oid_prefix="2.5.4"},
|
---|
85 | {.id=0x00000001, .oid_prefix="2.5.6"},
|
---|
86 | {.id=0x00000002, .oid_prefix="1.2.840.113556.1.2"},
|
---|
87 | {.id=0x00000003, .oid_prefix="1.2.840.113556.1.3"},
|
---|
88 | {.id=0x00000004, .oid_prefix="2.16.840.1.101.2.2.1"},
|
---|
89 | {.id=0x00000005, .oid_prefix="2.16.840.1.101.2.2.3"},
|
---|
90 | {.id=0x00000006, .oid_prefix="2.16.840.1.101.2.1.5"},
|
---|
91 | {.id=0x00000007, .oid_prefix="2.16.840.1.101.2.1.4"},
|
---|
92 | {.id=0x00000008, .oid_prefix="2.5.5"},
|
---|
93 | {.id=0x00000009, .oid_prefix="1.2.840.113556.1.4"},
|
---|
94 | {.id=0x0000000A, .oid_prefix="1.2.840.113556.1.5"},
|
---|
95 | {.id=0x00000013, .oid_prefix="0.9.2342.19200300.100"},
|
---|
96 | {.id=0x00000014, .oid_prefix="2.16.840.1.113730.3"},
|
---|
97 | {.id=0x00000015, .oid_prefix="0.9.2342.19200300.100.1"},
|
---|
98 | {.id=0x00000016, .oid_prefix="2.16.840.1.113730.3.1"},
|
---|
99 | {.id=0x00000017, .oid_prefix="1.2.840.113556.1.5.7000"},
|
---|
100 | {.id=0x00000018, .oid_prefix="2.5.21"},
|
---|
101 | {.id=0x00000019, .oid_prefix="2.5.18"},
|
---|
102 | {.id=0x0000001A, .oid_prefix="2.5.20"},
|
---|
103 | };
|
---|
104 |
|
---|
105 | /* allocate mem for prefix map */
|
---|
106 | pfm = _dsdb_schema_prefixmap_talloc(mem_ctx, ARRAY_SIZE(pfm_init_data));
|
---|
107 | W_ERROR_HAVE_NO_MEMORY(pfm);
|
---|
108 |
|
---|
109 | /* build prefixes */
|
---|
110 | for (i = 0; i < pfm->length; i++) {
|
---|
111 | if (!ber_write_partial_OID_String(pfm, &pfm->prefixes[i].bin_oid, pfm_init_data[i].oid_prefix)) {
|
---|
112 | talloc_free(pfm);
|
---|
113 | return WERR_INTERNAL_ERROR;
|
---|
114 | }
|
---|
115 | pfm->prefixes[i].id = pfm_init_data[i].id;
|
---|
116 | }
|
---|
117 |
|
---|
118 | *_pfm = pfm;
|
---|
119 |
|
---|
120 | return WERR_OK;
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | struct dsdb_schema_prefixmap *dsdb_schema_pfm_copy_shallow(TALLOC_CTX *mem_ctx,
|
---|
125 | const struct dsdb_schema_prefixmap *pfm)
|
---|
126 | {
|
---|
127 | uint32_t i;
|
---|
128 | struct dsdb_schema_prefixmap *pfm_copy;
|
---|
129 |
|
---|
130 | pfm_copy = _dsdb_schema_prefixmap_talloc(mem_ctx, pfm->length);
|
---|
131 | if (!pfm_copy) {
|
---|
132 | return NULL;
|
---|
133 | }
|
---|
134 | for (i = 0; i < pfm_copy->length; i++) {
|
---|
135 | pfm_copy->prefixes[i] = pfm->prefixes[i];
|
---|
136 | }
|
---|
137 |
|
---|
138 | return pfm_copy;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Adds oid to prefix map.
|
---|
143 | * On success returns ID for newly added index
|
---|
144 | * or ID of existing entry that matches oid
|
---|
145 | * Reference: [MS-DRSR] section 5.12.2
|
---|
146 | *
|
---|
147 | * \param pfm prefixMap
|
---|
148 | * \param bin_oid OID prefix to be added to prefixMap
|
---|
149 | * \param pfm_id Location where to store prefixMap entry ID
|
---|
150 | */
|
---|
151 | static WERROR _dsdb_schema_pfm_add_entry(struct dsdb_schema_prefixmap *pfm, DATA_BLOB bin_oid, uint32_t *_idx)
|
---|
152 | {
|
---|
153 | uint32_t i;
|
---|
154 | struct dsdb_schema_prefixmap_oid * pfm_entry;
|
---|
155 | struct dsdb_schema_prefixmap_oid * prefixes_new;
|
---|
156 |
|
---|
157 | /* dup memory for bin-oid prefix to be added */
|
---|
158 | bin_oid = data_blob_dup_talloc(pfm, &bin_oid);
|
---|
159 | W_ERROR_HAVE_NO_MEMORY(bin_oid.data);
|
---|
160 |
|
---|
161 | /* make room for new entry */
|
---|
162 | prefixes_new = talloc_realloc(pfm, pfm->prefixes, struct dsdb_schema_prefixmap_oid, pfm->length + 1);
|
---|
163 | if (!prefixes_new) {
|
---|
164 | talloc_free(bin_oid.data);
|
---|
165 | return WERR_NOMEM;
|
---|
166 | }
|
---|
167 | pfm->prefixes = prefixes_new;
|
---|
168 |
|
---|
169 | /* make new unique ID in prefixMap */
|
---|
170 | pfm_entry = &pfm->prefixes[pfm->length];
|
---|
171 | pfm_entry->id = 0;
|
---|
172 | for (i = 0; i < pfm->length; i++) {
|
---|
173 | if (pfm_entry->id < pfm->prefixes[i].id)
|
---|
174 | pfm_entry->id = pfm->prefixes[i].id;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /* add new bin-oid prefix */
|
---|
178 | pfm_entry->id++;
|
---|
179 | pfm_entry->bin_oid = bin_oid;
|
---|
180 |
|
---|
181 | *_idx = pfm->length;
|
---|
182 | pfm->length++;
|
---|
183 |
|
---|
184 | return WERR_OK;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Make partial binary OID for supplied OID.
|
---|
190 | * Reference: [MS-DRSR] section 5.12.2
|
---|
191 | */
|
---|
192 | static WERROR _dsdb_pfm_make_binary_oid(const char *full_oid, TALLOC_CTX *mem_ctx,
|
---|
193 | DATA_BLOB *_bin_oid, uint32_t *_last_subid)
|
---|
194 | {
|
---|
195 | uint32_t last_subid;
|
---|
196 | const char *oid_subid;
|
---|
197 |
|
---|
198 | /* make last sub-identifier value */
|
---|
199 | oid_subid = strrchr(full_oid, '.');
|
---|
200 | if (!oid_subid) {
|
---|
201 | return WERR_INVALID_PARAMETER;
|
---|
202 | }
|
---|
203 | oid_subid++;
|
---|
204 | last_subid = strtoul(oid_subid, NULL, 10);
|
---|
205 |
|
---|
206 | /* encode oid in BER format */
|
---|
207 | if (!ber_write_OID_String(mem_ctx, _bin_oid, full_oid)) {
|
---|
208 | DEBUG(0,("ber_write_OID_String() failed for %s\n", full_oid));
|
---|
209 | return WERR_INTERNAL_ERROR;
|
---|
210 | }
|
---|
211 |
|
---|
212 | /* get the prefix of the OID */
|
---|
213 | if (last_subid < 128) {
|
---|
214 | _bin_oid->length -= 1;
|
---|
215 | } else {
|
---|
216 | _bin_oid->length -= 2;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /* return last_value if requested */
|
---|
220 | if (_last_subid) {
|
---|
221 | *_last_subid = last_subid;
|
---|
222 | }
|
---|
223 |
|
---|
224 | return WERR_OK;
|
---|
225 | }
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Lookup partial-binary-oid in prefixMap
|
---|
229 | */
|
---|
230 | WERROR dsdb_schema_pfm_find_binary_oid(const struct dsdb_schema_prefixmap *pfm,
|
---|
231 | DATA_BLOB bin_oid,
|
---|
232 | uint32_t *_idx)
|
---|
233 | {
|
---|
234 | uint32_t i;
|
---|
235 |
|
---|
236 | for (i = 0; i < pfm->length; i++) {
|
---|
237 | if (pfm->prefixes[i].bin_oid.length != bin_oid.length) {
|
---|
238 | continue;
|
---|
239 | }
|
---|
240 |
|
---|
241 | if (memcmp(pfm->prefixes[i].bin_oid.data, bin_oid.data, bin_oid.length) == 0) {
|
---|
242 | if (_idx) {
|
---|
243 | *_idx = i;
|
---|
244 | }
|
---|
245 | return WERR_OK;
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | return WERR_NOT_FOUND;
|
---|
250 | }
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Lookup full-oid in prefixMap
|
---|
254 | * Note: this may be slow.
|
---|
255 | */
|
---|
256 | WERROR dsdb_schema_pfm_find_oid(const struct dsdb_schema_prefixmap *pfm,
|
---|
257 | const char *full_oid,
|
---|
258 | uint32_t *_idx)
|
---|
259 | {
|
---|
260 | WERROR werr;
|
---|
261 | DATA_BLOB bin_oid;
|
---|
262 |
|
---|
263 | ZERO_STRUCT(bin_oid);
|
---|
264 |
|
---|
265 | /* make partial-binary-oid to look for */
|
---|
266 | werr = _dsdb_pfm_make_binary_oid(full_oid, NULL, &bin_oid, NULL);
|
---|
267 | W_ERROR_NOT_OK_RETURN(werr);
|
---|
268 |
|
---|
269 | /* lookup the partial-oid */
|
---|
270 | werr = dsdb_schema_pfm_find_binary_oid(pfm, bin_oid, _idx);
|
---|
271 |
|
---|
272 | data_blob_free(&bin_oid);
|
---|
273 |
|
---|
274 | return werr;
|
---|
275 | }
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Make ATTID for given OID
|
---|
279 | * If OID is not in prefixMap, new prefix
|
---|
280 | * may be added depending on 'can_change_pfm' flag
|
---|
281 | * Reference: [MS-DRSR] section 5.12.2
|
---|
282 | */
|
---|
283 | static WERROR dsdb_schema_pfm_make_attid_impl(struct dsdb_schema_prefixmap *pfm,
|
---|
284 | const char *oid,
|
---|
285 | bool can_change_pfm,
|
---|
286 | uint32_t *attid)
|
---|
287 | {
|
---|
288 | WERROR werr;
|
---|
289 | uint32_t idx;
|
---|
290 | uint32_t lo_word, hi_word;
|
---|
291 | uint32_t last_subid;
|
---|
292 | DATA_BLOB bin_oid;
|
---|
293 |
|
---|
294 | if (!pfm) {
|
---|
295 | return WERR_INVALID_PARAMETER;
|
---|
296 | }
|
---|
297 | if (!oid) {
|
---|
298 | return WERR_INVALID_PARAMETER;
|
---|
299 | }
|
---|
300 |
|
---|
301 | werr = _dsdb_pfm_make_binary_oid(oid, pfm, &bin_oid, &last_subid);
|
---|
302 | W_ERROR_NOT_OK_RETURN(werr);
|
---|
303 |
|
---|
304 | /* search the prefix in the prefix table, if none found, add
|
---|
305 | * one entry for new prefix.
|
---|
306 | */
|
---|
307 | werr = dsdb_schema_pfm_find_binary_oid(pfm, bin_oid, &idx);
|
---|
308 | if (W_ERROR_IS_OK(werr)) {
|
---|
309 | /* free memory allocated for bin_oid */
|
---|
310 | data_blob_free(&bin_oid);
|
---|
311 | } else {
|
---|
312 | /* return error in read-only mode */
|
---|
313 | if (!can_change_pfm) {
|
---|
314 | return werr;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /* entry does not exists, add it */
|
---|
318 | werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
|
---|
319 | W_ERROR_NOT_OK_RETURN(werr);
|
---|
320 | }
|
---|
321 |
|
---|
322 | /* compose the attid */
|
---|
323 | lo_word = last_subid % 16384; /* actually get lower 14 bits: lo_word & 0x3FFF */
|
---|
324 | if (last_subid >= 16384) {
|
---|
325 | /* mark it so that it is known to not be the whole lastValue
|
---|
326 | * This will raise 16-th bit*/
|
---|
327 | lo_word += 32768;
|
---|
328 | }
|
---|
329 | hi_word = pfm->prefixes[idx].id;
|
---|
330 |
|
---|
331 | /* make ATTID:
|
---|
332 | * HIWORD is prefixMap id
|
---|
333 | * LOWORD is truncated binary-oid */
|
---|
334 | *attid = (hi_word * 65536) + lo_word;
|
---|
335 |
|
---|
336 | return WERR_OK;
|
---|
337 | }
|
---|
338 |
|
---|
339 | /**
|
---|
340 | * Make ATTID for given OID
|
---|
341 | * Reference: [MS-DRSR] section 5.12.2
|
---|
342 | *
|
---|
343 | * Note: This function may change prefixMap if prefix
|
---|
344 | * for supplied 'oid' doesn't exists yet.
|
---|
345 | * It is recommended to be used mostly when caller
|
---|
346 | * want to add new prefixes.
|
---|
347 | * Otherwise dsdb_schema_pfm_attid_from_oid() should be used.
|
---|
348 | */
|
---|
349 | WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm,
|
---|
350 | const char *oid,
|
---|
351 | uint32_t *attid)
|
---|
352 | {
|
---|
353 | return dsdb_schema_pfm_make_attid_impl(pfm, oid, true, attid);
|
---|
354 | }
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * Make ATTID for given OID
|
---|
358 | * Reference: [MS-DRSR] section 5.12.2
|
---|
359 | */
|
---|
360 | WERROR dsdb_schema_pfm_attid_from_oid(struct dsdb_schema_prefixmap *pfm,
|
---|
361 | const char *oid,
|
---|
362 | uint32_t *attid)
|
---|
363 | {
|
---|
364 | return dsdb_schema_pfm_make_attid_impl(pfm, oid, false, attid);
|
---|
365 | }
|
---|
366 |
|
---|
367 | /**
|
---|
368 | * Make OID for given ATTID.
|
---|
369 | * Reference: [MS-DRSR] section 5.12.2
|
---|
370 | */
|
---|
371 | WERROR dsdb_schema_pfm_oid_from_attid(const struct dsdb_schema_prefixmap *pfm,
|
---|
372 | uint32_t attid,
|
---|
373 | TALLOC_CTX *mem_ctx, const char **_oid)
|
---|
374 | {
|
---|
375 | uint32_t i;
|
---|
376 | uint32_t hi_word, lo_word;
|
---|
377 | DATA_BLOB bin_oid = {NULL, 0};
|
---|
378 | char *oid;
|
---|
379 | struct dsdb_schema_prefixmap_oid *pfm_entry;
|
---|
380 | WERROR werr = WERR_OK;
|
---|
381 |
|
---|
382 | /* sanity check for attid requested */
|
---|
383 | if (dsdb_pfm_get_attid_type(attid) != DSDB_ATTID_TYPE_PFM) {
|
---|
384 | return WERR_INVALID_PARAMETER;
|
---|
385 | }
|
---|
386 |
|
---|
387 | /* crack attid value */
|
---|
388 | hi_word = attid >> 16;
|
---|
389 | lo_word = attid & 0xFFFF;
|
---|
390 |
|
---|
391 | /* locate corRespoNding prefixMap entry */
|
---|
392 | pfm_entry = NULL;
|
---|
393 | for (i = 0; i < pfm->length; i++) {
|
---|
394 | if (hi_word == pfm->prefixes[i].id) {
|
---|
395 | pfm_entry = &pfm->prefixes[i];
|
---|
396 | break;
|
---|
397 | }
|
---|
398 | }
|
---|
399 |
|
---|
400 | if (!pfm_entry) {
|
---|
401 | DEBUG(1,("Failed to find prefixMap entry for ATTID = 0x%08X (%d)\n",
|
---|
402 | attid, attid));
|
---|
403 | return WERR_DS_NO_ATTRIBUTE_OR_VALUE;
|
---|
404 | }
|
---|
405 |
|
---|
406 | /* copy oid prefix making enough room */
|
---|
407 | bin_oid.length = pfm_entry->bin_oid.length + 2;
|
---|
408 | bin_oid.data = talloc_array(mem_ctx, uint8_t, bin_oid.length);
|
---|
409 | W_ERROR_HAVE_NO_MEMORY(bin_oid.data);
|
---|
410 | memcpy(bin_oid.data, pfm_entry->bin_oid.data, pfm_entry->bin_oid.length);
|
---|
411 |
|
---|
412 | if (lo_word < 128) {
|
---|
413 | bin_oid.length = bin_oid.length - 1;
|
---|
414 | bin_oid.data[bin_oid.length-1] = lo_word;
|
---|
415 | }
|
---|
416 | else {
|
---|
417 | if (lo_word >= 32768) {
|
---|
418 | lo_word -= 32768;
|
---|
419 | }
|
---|
420 | bin_oid.data[bin_oid.length-2] = (0x80 | ((lo_word>>7) & 0x7f));
|
---|
421 | bin_oid.data[bin_oid.length-1] = lo_word & 0x7f;
|
---|
422 | }
|
---|
423 |
|
---|
424 | if (!ber_read_OID_String(mem_ctx, bin_oid, &oid)) {
|
---|
425 | DEBUG(0,("ber_read_OID_String() failed for %s\n",
|
---|
426 | hex_encode_talloc(bin_oid.data, bin_oid.data, bin_oid.length)));
|
---|
427 | werr = WERR_INTERNAL_ERROR;
|
---|
428 | }
|
---|
429 |
|
---|
430 | /* free locally allocated memory */
|
---|
431 | talloc_free(bin_oid.data);
|
---|
432 |
|
---|
433 | *_oid = oid;
|
---|
434 |
|
---|
435 | return werr;
|
---|
436 | }
|
---|
437 |
|
---|
438 |
|
---|
439 | /**
|
---|
440 | * Verifies drsuapi mappings.
|
---|
441 | */
|
---|
442 | static WERROR _dsdb_drsuapi_pfm_verify(const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr,
|
---|
443 | bool have_schema_info)
|
---|
444 | {
|
---|
445 | uint32_t i;
|
---|
446 | uint32_t num_mappings;
|
---|
447 | struct drsuapi_DsReplicaOIDMapping *mapping;
|
---|
448 |
|
---|
449 | /* check input params */
|
---|
450 | if (!ctr) {
|
---|
451 | return WERR_INVALID_PARAMETER;
|
---|
452 | }
|
---|
453 | if (!ctr->mappings) {
|
---|
454 | return WERR_INVALID_PARAMETER;
|
---|
455 | }
|
---|
456 | num_mappings = ctr->num_mappings;
|
---|
457 |
|
---|
458 | if (have_schema_info) {
|
---|
459 | DATA_BLOB blob;
|
---|
460 |
|
---|
461 | if (ctr->num_mappings < 2) {
|
---|
462 | return WERR_INVALID_PARAMETER;
|
---|
463 | }
|
---|
464 |
|
---|
465 | /* check last entry for being special */
|
---|
466 | mapping = &ctr->mappings[ctr->num_mappings - 1];
|
---|
467 | if (mapping->id_prefix != 0) {
|
---|
468 | return WERR_INVALID_PARAMETER;
|
---|
469 | }
|
---|
470 |
|
---|
471 | /* verify schemaInfo blob is valid one */
|
---|
472 | blob = data_blob_const(mapping->oid.binary_oid, mapping->oid.length);
|
---|
473 | if (!dsdb_schema_info_blob_is_valid(&blob)) {
|
---|
474 | return WERR_INVALID_PARAMETER;
|
---|
475 | }
|
---|
476 |
|
---|
477 | /* get number of read mappings in the map */
|
---|
478 | num_mappings--;
|
---|
479 | }
|
---|
480 |
|
---|
481 | /* now, verify rest of entries for being at least not null */
|
---|
482 | for (i = 0; i < num_mappings; i++) {
|
---|
483 | mapping = &ctr->mappings[i];
|
---|
484 | if (!mapping->oid.length) {
|
---|
485 | return WERR_INVALID_PARAMETER;
|
---|
486 | }
|
---|
487 | if (!mapping->oid.binary_oid) {
|
---|
488 | return WERR_INVALID_PARAMETER;
|
---|
489 | }
|
---|
490 | /* check it is not the special entry */
|
---|
491 | if (*mapping->oid.binary_oid == 0xFF) {
|
---|
492 | return WERR_INVALID_PARAMETER;
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|
496 | return WERR_OK;
|
---|
497 | }
|
---|
498 |
|
---|
499 | /**
|
---|
500 | * Convert drsuapi_ prefix map to prefixMap internal presentation.
|
---|
501 | *
|
---|
502 | * \param ctr Pointer to drsuapi_DsReplicaOIDMapping_Ctr which represents drsuapi_ prefixMap
|
---|
503 | * \param have_schema_info if drsuapi_prefixMap have schem_info in it or not
|
---|
504 | * \param mem_ctx TALLOC_CTX to make allocations in
|
---|
505 | * \param _pfm Out pointer to hold newly created prefixMap
|
---|
506 | * \param _schema_info Out param to store schema_info to. If NULL, schema_info is not decoded
|
---|
507 | */
|
---|
508 | WERROR dsdb_schema_pfm_from_drsuapi_pfm(const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr,
|
---|
509 | bool have_schema_info,
|
---|
510 | TALLOC_CTX *mem_ctx,
|
---|
511 | struct dsdb_schema_prefixmap **_pfm,
|
---|
512 | const char **_schema_info)
|
---|
513 | {
|
---|
514 | WERROR werr;
|
---|
515 | uint32_t i;
|
---|
516 | DATA_BLOB blob;
|
---|
517 | uint32_t num_mappings;
|
---|
518 | struct dsdb_schema_prefixmap *pfm;
|
---|
519 |
|
---|
520 | if (!_pfm) {
|
---|
521 | return WERR_INVALID_PARAMETER;
|
---|
522 | }
|
---|
523 |
|
---|
524 | /*
|
---|
525 | * error out if schema_info is requested
|
---|
526 | * but it is not in the drsuapi_prefixMap
|
---|
527 | */
|
---|
528 | if (_schema_info && !have_schema_info) {
|
---|
529 | return WERR_INVALID_PARAMETER;
|
---|
530 | }
|
---|
531 |
|
---|
532 | /* verify drsuapi_pefixMap */
|
---|
533 | werr =_dsdb_drsuapi_pfm_verify(ctr, have_schema_info);
|
---|
534 | W_ERROR_NOT_OK_RETURN(werr);
|
---|
535 |
|
---|
536 | /* allocate mem for prefix map */
|
---|
537 | num_mappings = ctr->num_mappings;
|
---|
538 | if (have_schema_info) {
|
---|
539 | num_mappings--;
|
---|
540 | }
|
---|
541 | pfm = _dsdb_schema_prefixmap_talloc(mem_ctx, num_mappings);
|
---|
542 | W_ERROR_HAVE_NO_MEMORY(pfm);
|
---|
543 |
|
---|
544 | /* copy entries from drsuapi_prefixMap */
|
---|
545 | for (i = 0; i < pfm->length; i++) {
|
---|
546 | blob = data_blob_talloc(pfm,
|
---|
547 | ctr->mappings[i].oid.binary_oid,
|
---|
548 | ctr->mappings[i].oid.length);
|
---|
549 | if (!blob.data) {
|
---|
550 | talloc_free(pfm);
|
---|
551 | return WERR_NOMEM;
|
---|
552 | }
|
---|
553 | pfm->prefixes[i].id = ctr->mappings[i].id_prefix;
|
---|
554 | pfm->prefixes[i].bin_oid = blob;
|
---|
555 | }
|
---|
556 |
|
---|
557 | /* fetch schema_info if requested */
|
---|
558 | if (_schema_info) {
|
---|
559 | /* by this time, i should have this value,
|
---|
560 | * but set it here for clarity */
|
---|
561 | i = ctr->num_mappings - 1;
|
---|
562 |
|
---|
563 | *_schema_info = hex_encode_talloc(mem_ctx,
|
---|
564 | ctr->mappings[i].oid.binary_oid,
|
---|
565 | ctr->mappings[i].oid.length);
|
---|
566 | if (!*_schema_info) {
|
---|
567 | talloc_free(pfm);
|
---|
568 | return WERR_NOMEM;
|
---|
569 | }
|
---|
570 | }
|
---|
571 |
|
---|
572 | /* schema_prefixMap created successfully */
|
---|
573 | *_pfm = pfm;
|
---|
574 |
|
---|
575 | return WERR_OK;
|
---|
576 | }
|
---|
577 |
|
---|
578 | /**
|
---|
579 | * Convert drsuapi_ prefix map to prefixMap internal presentation.
|
---|
580 | *
|
---|
581 | * \param pfm Schema prefixMap to be converted
|
---|
582 | * \param schema_info schema_info string - if NULL, we don't need it
|
---|
583 | * \param mem_ctx TALLOC_CTX to make allocations in
|
---|
584 | * \param _ctr Out pointer to drsuapi_DsReplicaOIDMapping_Ctr prefix map structure
|
---|
585 | */
|
---|
586 | WERROR dsdb_drsuapi_pfm_from_schema_pfm(const struct dsdb_schema_prefixmap *pfm,
|
---|
587 | const char *schema_info,
|
---|
588 | TALLOC_CTX *mem_ctx,
|
---|
589 | struct drsuapi_DsReplicaOIDMapping_Ctr **_ctr)
|
---|
590 | {
|
---|
591 | uint32_t i;
|
---|
592 | DATA_BLOB blob;
|
---|
593 | struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
|
---|
594 |
|
---|
595 | if (!_ctr) {
|
---|
596 | return WERR_INVALID_PARAMETER;
|
---|
597 | }
|
---|
598 | if (!pfm) {
|
---|
599 | return WERR_INVALID_PARAMETER;
|
---|
600 | }
|
---|
601 | if (pfm->length == 0) {
|
---|
602 | return WERR_INVALID_PARAMETER;
|
---|
603 | }
|
---|
604 |
|
---|
605 | /* allocate memory for the structure */
|
---|
606 | ctr = talloc_zero(mem_ctx, struct drsuapi_DsReplicaOIDMapping_Ctr);
|
---|
607 | W_ERROR_HAVE_NO_MEMORY(ctr);
|
---|
608 |
|
---|
609 | ctr->num_mappings = (schema_info ? pfm->length + 1 : pfm->length);
|
---|
610 | ctr->mappings = talloc_array(ctr, struct drsuapi_DsReplicaOIDMapping, ctr->num_mappings);
|
---|
611 | if (!ctr->mappings) {
|
---|
612 | talloc_free(ctr);
|
---|
613 | return WERR_NOMEM;
|
---|
614 | }
|
---|
615 |
|
---|
616 | /* copy entries from schema_prefixMap */
|
---|
617 | for (i = 0; i < pfm->length; i++) {
|
---|
618 | blob = data_blob_dup_talloc(ctr, &pfm->prefixes[i].bin_oid);
|
---|
619 | if (!blob.data) {
|
---|
620 | talloc_free(ctr);
|
---|
621 | return WERR_NOMEM;
|
---|
622 | }
|
---|
623 | ctr->mappings[i].id_prefix = pfm->prefixes[i].id;
|
---|
624 | ctr->mappings[i].oid.length = blob.length;
|
---|
625 | ctr->mappings[i].oid.binary_oid = blob.data;
|
---|
626 | }
|
---|
627 |
|
---|
628 | /* make schema_info entry if needed */
|
---|
629 | if (schema_info) {
|
---|
630 | /* by this time, i should have this value,
|
---|
631 | * but set it here for clarity */
|
---|
632 | i = ctr->num_mappings - 1;
|
---|
633 |
|
---|
634 | blob = strhex_to_data_blob(ctr, schema_info);
|
---|
635 | if (!blob.data) {
|
---|
636 | talloc_free(ctr);
|
---|
637 | return WERR_NOMEM;
|
---|
638 | }
|
---|
639 |
|
---|
640 | ctr->mappings[i].id_prefix = 0;
|
---|
641 | ctr->mappings[i].oid.length = blob.length;
|
---|
642 | ctr->mappings[i].oid.binary_oid = blob.data;
|
---|
643 | }
|
---|
644 |
|
---|
645 | /* drsuapi_prefixMap constructed successfully */
|
---|
646 | *_ctr = ctr;
|
---|
647 |
|
---|
648 | return WERR_OK;
|
---|
649 | }
|
---|
650 |
|
---|
651 | /**
|
---|
652 | * Verifies schema prefixMap and drsuapi prefixMap are same.
|
---|
653 | * Note that we just need to verify pfm contains prefixes
|
---|
654 | * from ctr, not that those prefixes has same id_prefix.
|
---|
655 | */
|
---|
656 | WERROR dsdb_schema_pfm_contains_drsuapi_pfm(const struct dsdb_schema_prefixmap *pfm,
|
---|
657 | const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
|
---|
658 | {
|
---|
659 | WERROR werr;
|
---|
660 | uint32_t i;
|
---|
661 | uint32_t idx;
|
---|
662 | DATA_BLOB bin_oid;
|
---|
663 |
|
---|
664 | /* verify drsuapi_pefixMap */
|
---|
665 | werr = _dsdb_drsuapi_pfm_verify(ctr, true);
|
---|
666 | W_ERROR_NOT_OK_RETURN(werr);
|
---|
667 |
|
---|
668 | /* check pfm contains every entry from ctr, except the last one */
|
---|
669 | for (i = 0; i < ctr->num_mappings - 1; i++) {
|
---|
670 | bin_oid.length = ctr->mappings[i].oid.length;
|
---|
671 | bin_oid.data = ctr->mappings[i].oid.binary_oid;
|
---|
672 |
|
---|
673 | werr = dsdb_schema_pfm_find_binary_oid(pfm, bin_oid, &idx);
|
---|
674 | if (!W_ERROR_IS_OK(werr)) {
|
---|
675 | return WERR_DS_DRA_SCHEMA_MISMATCH;
|
---|
676 | }
|
---|
677 | }
|
---|
678 |
|
---|
679 | return WERR_OK;
|
---|
680 | }
|
---|