2 Unix SMB/CIFS mplementation.
5 Copyright (C) Stefan Metzmacher <metze@samba.org> 2006
6 Copyright (C) Simo Sorce 2005
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "dsdb/samdb/samdb.h"
25 #include "librpc/gen_ndr/ndr_drsuapi.h"
26 #include "librpc/gen_ndr/ndr_security.h"
27 #include "librpc/gen_ndr/ndr_misc.h"
29 #include <ldb_errors.h>
30 #include "system/time.h"
31 #include "../lib/util/charset/charset.h"
32 #include "librpc/ndr/libndr.h"
33 #include "../lib/util/asn1.h"
36 * Initialize dsdb_syntax_ctx with default values
39 void dsdb_syntax_ctx_init(struct dsdb_syntax_ctx
*ctx
,
40 struct ldb_context
*ldb
,
41 const struct dsdb_schema
*schema
)
47 * 'true' will keep current behavior,
48 * i.e. attributeID_id will be returned by default
50 ctx
->is_schema_nc
= true;
52 ctx
->pfm_remote
= NULL
;
57 * Returns ATTID for DRS attribute.
59 * ATTID depends on whether we are replicating
60 * Schema NC or msDs-IntId is set for schemaAttribute
63 uint32_t dsdb_attribute_get_attid(const struct dsdb_attribute
*attr
,
66 if (!for_schema_nc
&& attr
->msDS_IntId
) {
67 return attr
->msDS_IntId
;
70 return attr
->attributeID_id
;
74 * Map an ATTID from remote DC to a local ATTID
75 * using remote prefixMap
77 static bool dsdb_syntax_attid_from_remote_attid(const struct dsdb_syntax_ctx
*ctx
,
86 * map remote ATTID to local directly in case
87 * of no remote prefixMap (during provision for instance)
89 if (!ctx
->pfm_remote
) {
90 *id_local
= id_remote
;
94 werr
= dsdb_schema_pfm_oid_from_attid(ctx
->pfm_remote
, id_remote
, mem_ctx
, &oid
);
95 if (!W_ERROR_IS_OK(werr
)) {
96 DEBUG(0,("ATTID->OID failed (%s) for: 0x%08X\n", win_errstr(werr
), id_remote
));
100 werr
= dsdb_schema_pfm_attid_from_oid(ctx
->schema
->prefixmap
, oid
, id_local
);
101 if (!W_ERROR_IS_OK(werr
)) {
102 DEBUG(0,("OID->ATTID failed (%s) for: %s\n", win_errstr(werr
), oid
));
109 static WERROR
dsdb_syntax_FOOBAR_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
110 const struct dsdb_attribute
*attr
,
111 const struct drsuapi_DsReplicaAttribute
*in
,
113 struct ldb_message_element
*out
)
118 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
119 W_ERROR_HAVE_NO_MEMORY(out
->name
);
121 out
->num_values
= in
->value_ctr
.num_values
;
122 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
123 W_ERROR_HAVE_NO_MEMORY(out
->values
);
125 for (i
=0; i
< out
->num_values
; i
++) {
128 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
132 str
= talloc_asprintf(out
->values
, "%s: not implemented",
134 W_ERROR_HAVE_NO_MEMORY(str
);
136 out
->values
[i
] = data_blob_string_const(str
);
142 static WERROR
dsdb_syntax_FOOBAR_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
143 const struct dsdb_attribute
*attr
,
144 const struct ldb_message_element
*in
,
146 struct drsuapi_DsReplicaAttribute
*out
)
151 static WERROR
dsdb_syntax_FOOBAR_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
152 const struct dsdb_attribute
*attr
,
153 const struct ldb_message_element
*in
)
158 static WERROR
dsdb_syntax_BOOL_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
159 const struct dsdb_attribute
*attr
,
160 const struct drsuapi_DsReplicaAttribute
*in
,
162 struct ldb_message_element
*out
)
167 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
168 W_ERROR_HAVE_NO_MEMORY(out
->name
);
170 out
->num_values
= in
->value_ctr
.num_values
;
171 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
172 W_ERROR_HAVE_NO_MEMORY(out
->values
);
174 for (i
=0; i
< out
->num_values
; i
++) {
178 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
182 if (in
->value_ctr
.values
[i
].blob
->length
!= 4) {
186 v
= IVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
189 str
= talloc_strdup(out
->values
, "TRUE");
190 W_ERROR_HAVE_NO_MEMORY(str
);
192 str
= talloc_strdup(out
->values
, "FALSE");
193 W_ERROR_HAVE_NO_MEMORY(str
);
196 out
->values
[i
] = data_blob_string_const(str
);
202 static WERROR
dsdb_syntax_BOOL_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
203 const struct dsdb_attribute
*attr
,
204 const struct ldb_message_element
*in
,
206 struct drsuapi_DsReplicaAttribute
*out
)
211 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
212 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
215 out
->attid
= dsdb_attribute_get_attid(attr
,
217 out
->value_ctr
.num_values
= in
->num_values
;
218 out
->value_ctr
.values
= talloc_array(mem_ctx
,
219 struct drsuapi_DsAttributeValue
,
221 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
223 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
224 W_ERROR_HAVE_NO_MEMORY(blobs
);
226 for (i
=0; i
< in
->num_values
; i
++) {
227 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
229 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 4);
230 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
232 if (in
->values
[i
].length
>= 4 &&
233 strncmp("TRUE", (const char *)in
->values
[i
].data
, in
->values
[i
].length
) == 0) {
234 SIVAL(blobs
[i
].data
, 0, 0x00000001);
235 } else if (in
->values
[i
].length
>= 5 &&
236 strncmp("FALSE", (const char *)in
->values
[i
].data
, in
->values
[i
].length
) == 0) {
237 SIVAL(blobs
[i
].data
, 0, 0x00000000);
246 static WERROR
dsdb_syntax_BOOL_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
247 const struct dsdb_attribute
*attr
,
248 const struct ldb_message_element
*in
)
252 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
253 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
256 for (i
=0; i
< in
->num_values
; i
++) {
257 if (in
->values
[i
].length
== 0) {
258 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
261 if (in
->values
[i
].length
>= 4 &&
263 (const char *)in
->values
[i
].data
,
264 in
->values
[i
].length
) == 0) {
267 if (in
->values
[i
].length
>= 5 &&
269 (const char *)in
->values
[i
].data
,
270 in
->values
[i
].length
) == 0) {
273 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
279 static WERROR
dsdb_syntax_INT32_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
280 const struct dsdb_attribute
*attr
,
281 const struct drsuapi_DsReplicaAttribute
*in
,
283 struct ldb_message_element
*out
)
288 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
289 W_ERROR_HAVE_NO_MEMORY(out
->name
);
291 out
->num_values
= in
->value_ctr
.num_values
;
292 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
293 W_ERROR_HAVE_NO_MEMORY(out
->values
);
295 for (i
=0; i
< out
->num_values
; i
++) {
299 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
303 if (in
->value_ctr
.values
[i
].blob
->length
!= 4) {
307 v
= IVALS(in
->value_ctr
.values
[i
].blob
->data
, 0);
309 str
= talloc_asprintf(out
->values
, "%d", v
);
310 W_ERROR_HAVE_NO_MEMORY(str
);
312 out
->values
[i
] = data_blob_string_const(str
);
318 static WERROR
dsdb_syntax_INT32_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
319 const struct dsdb_attribute
*attr
,
320 const struct ldb_message_element
*in
,
322 struct drsuapi_DsReplicaAttribute
*out
)
327 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
328 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
331 out
->attid
= dsdb_attribute_get_attid(attr
,
333 out
->value_ctr
.num_values
= in
->num_values
;
334 out
->value_ctr
.values
= talloc_array(mem_ctx
,
335 struct drsuapi_DsAttributeValue
,
337 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
339 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
340 W_ERROR_HAVE_NO_MEMORY(blobs
);
342 for (i
=0; i
< in
->num_values
; i
++) {
345 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
347 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 4);
348 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
350 /* We've to use "strtoll" here to have the intended overflows.
351 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
352 v
= (int32_t) strtoll((char *)in
->values
[i
].data
, NULL
, 0);
354 SIVALS(blobs
[i
].data
, 0, v
);
360 static WERROR
dsdb_syntax_INT32_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
361 const struct dsdb_attribute
*attr
,
362 const struct ldb_message_element
*in
)
366 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
367 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
370 for (i
=0; i
< in
->num_values
; i
++) {
372 char buf
[sizeof("-2147483648")];
376 if (in
->values
[i
].length
>= sizeof(buf
)) {
377 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
380 memcpy(buf
, in
->values
[i
].data
, in
->values
[i
].length
);
382 v
= strtol(buf
, &end
, 10);
384 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
386 if (end
&& end
[0] != '\0') {
387 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
390 if (attr
->rangeLower
) {
391 if ((int32_t)v
< (int32_t)*attr
->rangeLower
) {
392 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
396 if (attr
->rangeUpper
) {
397 if ((int32_t)v
> (int32_t)*attr
->rangeUpper
) {
398 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
406 static WERROR
dsdb_syntax_INT64_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
407 const struct dsdb_attribute
*attr
,
408 const struct drsuapi_DsReplicaAttribute
*in
,
410 struct ldb_message_element
*out
)
415 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
416 W_ERROR_HAVE_NO_MEMORY(out
->name
);
418 out
->num_values
= in
->value_ctr
.num_values
;
419 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
420 W_ERROR_HAVE_NO_MEMORY(out
->values
);
422 for (i
=0; i
< out
->num_values
; i
++) {
426 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
430 if (in
->value_ctr
.values
[i
].blob
->length
!= 8) {
434 v
= BVALS(in
->value_ctr
.values
[i
].blob
->data
, 0);
436 str
= talloc_asprintf(out
->values
, "%lld", (long long int)v
);
437 W_ERROR_HAVE_NO_MEMORY(str
);
439 out
->values
[i
] = data_blob_string_const(str
);
445 static WERROR
dsdb_syntax_INT64_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
446 const struct dsdb_attribute
*attr
,
447 const struct ldb_message_element
*in
,
449 struct drsuapi_DsReplicaAttribute
*out
)
454 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
455 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
458 out
->attid
= dsdb_attribute_get_attid(attr
,
460 out
->value_ctr
.num_values
= in
->num_values
;
461 out
->value_ctr
.values
= talloc_array(mem_ctx
,
462 struct drsuapi_DsAttributeValue
,
464 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
466 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
467 W_ERROR_HAVE_NO_MEMORY(blobs
);
469 for (i
=0; i
< in
->num_values
; i
++) {
472 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
474 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 8);
475 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
477 v
= strtoll((const char *)in
->values
[i
].data
, NULL
, 10);
479 SBVALS(blobs
[i
].data
, 0, v
);
485 static WERROR
dsdb_syntax_INT64_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
486 const struct dsdb_attribute
*attr
,
487 const struct ldb_message_element
*in
)
491 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
492 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
495 for (i
=0; i
< in
->num_values
; i
++) {
497 char buf
[sizeof("-9223372036854775808")];
501 if (in
->values
[i
].length
>= sizeof(buf
)) {
502 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
504 memcpy(buf
, in
->values
[i
].data
, in
->values
[i
].length
);
507 v
= strtoll(buf
, &end
, 10);
509 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
511 if (end
&& end
[0] != '\0') {
512 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
515 if (attr
->rangeLower
) {
516 if ((int64_t)v
< (int64_t)*attr
->rangeLower
) {
517 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
521 if (attr
->rangeUpper
) {
522 if ((int64_t)v
> (int64_t)*attr
->rangeUpper
) {
523 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
530 static WERROR
dsdb_syntax_NTTIME_UTC_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
531 const struct dsdb_attribute
*attr
,
532 const struct drsuapi_DsReplicaAttribute
*in
,
534 struct ldb_message_element
*out
)
539 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
540 W_ERROR_HAVE_NO_MEMORY(out
->name
);
542 out
->num_values
= in
->value_ctr
.num_values
;
543 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
544 W_ERROR_HAVE_NO_MEMORY(out
->values
);
546 for (i
=0; i
< out
->num_values
; i
++) {
551 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
555 if (in
->value_ctr
.values
[i
].blob
->length
!= 8) {
559 v
= BVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
561 /* special case for 1601 zero timestamp */
562 out
->values
[i
] = data_blob_string_const("16010101000000.0Z");
566 t
= nt_time_to_unix(v
);
569 * NOTE: On a w2k3 server you can set a GeneralizedTime string
570 * via LDAP, but you get back an UTCTime string,
571 * but via DRSUAPI you get back the NTTIME_1sec value
572 * that represents the GeneralizedTime value!
574 * So if we store the UTCTime string in our ldb
575 * we'll loose information!
577 str
= ldb_timestring_utc(out
->values
, t
);
578 W_ERROR_HAVE_NO_MEMORY(str
);
579 out
->values
[i
] = data_blob_string_const(str
);
585 static WERROR
dsdb_syntax_NTTIME_UTC_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
586 const struct dsdb_attribute
*attr
,
587 const struct ldb_message_element
*in
,
589 struct drsuapi_DsReplicaAttribute
*out
)
594 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
595 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
598 out
->attid
= dsdb_attribute_get_attid(attr
,
600 out
->value_ctr
.num_values
= in
->num_values
;
601 out
->value_ctr
.values
= talloc_array(mem_ctx
,
602 struct drsuapi_DsAttributeValue
,
604 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
606 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
607 W_ERROR_HAVE_NO_MEMORY(blobs
);
609 for (i
=0; i
< in
->num_values
; i
++) {
613 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
615 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 8);
616 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
618 if (ldb_val_string_cmp(&in
->values
[i
], "16010101000000.0Z") == 0) {
619 SBVALS(blobs
[i
].data
, 0, 0);
623 t
= ldb_string_utc_to_time((const char *)in
->values
[i
].data
);
624 unix_to_nt_time(&v
, t
);
627 SBVAL(blobs
[i
].data
, 0, v
);
633 static WERROR
dsdb_syntax_NTTIME_UTC_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
634 const struct dsdb_attribute
*attr
,
635 const struct ldb_message_element
*in
)
639 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
640 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
643 for (i
=0; i
< in
->num_values
; i
++) {
645 char buf
[sizeof("090826075717Z")];
648 if (in
->values
[i
].length
>= sizeof(buf
)) {
649 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
651 memcpy(buf
, in
->values
[i
].data
, in
->values
[i
].length
);
653 t
= ldb_string_utc_to_time(buf
);
655 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
658 if (attr
->rangeLower
) {
659 if ((int32_t)t
< (int32_t)*attr
->rangeLower
) {
660 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
664 if (attr
->rangeUpper
) {
665 if ((int32_t)t
> (int32_t)*attr
->rangeLower
) {
666 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
671 * TODO: verify the comment in the
672 * dsdb_syntax_NTTIME_UTC_drsuapi_to_ldb() function!
679 static WERROR
dsdb_syntax_NTTIME_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
680 const struct dsdb_attribute
*attr
,
681 const struct drsuapi_DsReplicaAttribute
*in
,
683 struct ldb_message_element
*out
)
688 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
689 W_ERROR_HAVE_NO_MEMORY(out
->name
);
691 out
->num_values
= in
->value_ctr
.num_values
;
692 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
693 W_ERROR_HAVE_NO_MEMORY(out
->values
);
695 for (i
=0; i
< out
->num_values
; i
++) {
700 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
704 if (in
->value_ctr
.values
[i
].blob
->length
!= 8) {
708 v
= BVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
710 /* special case for 1601 zero timestamp */
711 out
->values
[i
] = data_blob_string_const("16010101000000.0Z");
715 t
= nt_time_to_unix(v
);
717 str
= ldb_timestring(out
->values
, t
);
718 W_ERROR_HAVE_NO_MEMORY(str
);
720 out
->values
[i
] = data_blob_string_const(str
);
726 static WERROR
dsdb_syntax_NTTIME_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
727 const struct dsdb_attribute
*attr
,
728 const struct ldb_message_element
*in
,
730 struct drsuapi_DsReplicaAttribute
*out
)
735 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
736 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
739 out
->attid
= dsdb_attribute_get_attid(attr
,
741 out
->value_ctr
.num_values
= in
->num_values
;
742 out
->value_ctr
.values
= talloc_array(mem_ctx
,
743 struct drsuapi_DsAttributeValue
,
745 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
747 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
748 W_ERROR_HAVE_NO_MEMORY(blobs
);
750 for (i
=0; i
< in
->num_values
; i
++) {
755 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
757 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 8);
758 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
760 if (ldb_val_string_cmp(&in
->values
[i
], "16010101000000.0Z") == 0) {
761 SBVALS(blobs
[i
].data
, 0, 0);
765 ret
= ldb_val_to_time(&in
->values
[i
], &t
);
766 if (ret
!= LDB_SUCCESS
) {
767 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
769 unix_to_nt_time(&v
, t
);
772 SBVAL(blobs
[i
].data
, 0, v
);
778 static WERROR
dsdb_syntax_NTTIME_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
779 const struct dsdb_attribute
*attr
,
780 const struct ldb_message_element
*in
)
784 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
785 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
788 for (i
=0; i
< in
->num_values
; i
++) {
792 ret
= ldb_val_to_time(&in
->values
[i
], &t
);
793 if (ret
!= LDB_SUCCESS
) {
794 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
797 if (attr
->rangeLower
) {
798 if ((int32_t)t
< (int32_t)*attr
->rangeLower
) {
799 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
803 if (attr
->rangeUpper
) {
804 if ((int32_t)t
> (int32_t)*attr
->rangeUpper
) {
805 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
813 static WERROR
dsdb_syntax_DATA_BLOB_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
814 const struct dsdb_attribute
*attr
,
815 const struct drsuapi_DsReplicaAttribute
*in
,
817 struct ldb_message_element
*out
)
822 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
823 W_ERROR_HAVE_NO_MEMORY(out
->name
);
825 out
->num_values
= in
->value_ctr
.num_values
;
826 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
827 W_ERROR_HAVE_NO_MEMORY(out
->values
);
829 for (i
=0; i
< out
->num_values
; i
++) {
830 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
834 if (in
->value_ctr
.values
[i
].blob
->length
== 0) {
838 out
->values
[i
] = data_blob_dup_talloc(out
->values
,
839 *in
->value_ctr
.values
[i
].blob
);
840 W_ERROR_HAVE_NO_MEMORY(out
->values
[i
].data
);
846 static WERROR
dsdb_syntax_DATA_BLOB_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
847 const struct dsdb_attribute
*attr
,
848 const struct ldb_message_element
*in
,
850 struct drsuapi_DsReplicaAttribute
*out
)
855 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
856 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
859 out
->attid
= dsdb_attribute_get_attid(attr
,
861 out
->value_ctr
.num_values
= in
->num_values
;
862 out
->value_ctr
.values
= talloc_array(mem_ctx
,
863 struct drsuapi_DsAttributeValue
,
865 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
867 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
868 W_ERROR_HAVE_NO_MEMORY(blobs
);
870 for (i
=0; i
< in
->num_values
; i
++) {
871 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
873 blobs
[i
] = data_blob_dup_talloc(blobs
, in
->values
[i
]);
874 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
880 static WERROR
dsdb_syntax_DATA_BLOB_validate_one_val(const struct dsdb_syntax_ctx
*ctx
,
881 const struct dsdb_attribute
*attr
,
882 const struct ldb_val
*val
)
884 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
885 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
888 if (attr
->rangeLower
) {
889 if ((uint32_t)val
->length
< (uint32_t)*attr
->rangeLower
) {
890 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
894 if (attr
->rangeUpper
) {
895 if ((uint32_t)val
->length
> (uint32_t)*attr
->rangeUpper
) {
896 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
903 static WERROR
dsdb_syntax_DATA_BLOB_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
904 const struct dsdb_attribute
*attr
,
905 const struct ldb_message_element
*in
)
910 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
911 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
914 for (i
=0; i
< in
->num_values
; i
++) {
915 if (in
->values
[i
].length
== 0) {
916 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
919 status
= dsdb_syntax_DATA_BLOB_validate_one_val(ctx
,
922 if (!W_ERROR_IS_OK(status
)) {
930 static WERROR
_dsdb_syntax_auto_OID_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
931 const struct dsdb_attribute
*attr
,
932 const struct drsuapi_DsReplicaAttribute
*in
,
934 struct ldb_message_element
*out
)
939 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
940 W_ERROR_HAVE_NO_MEMORY(out
->name
);
942 out
->num_values
= in
->value_ctr
.num_values
;
943 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
944 W_ERROR_HAVE_NO_MEMORY(out
->values
);
946 for (i
=0; i
< out
->num_values
; i
++) {
948 const struct dsdb_class
*c
;
949 const struct dsdb_attribute
*a
;
950 const char *str
= NULL
;
952 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
956 if (in
->value_ctr
.values
[i
].blob
->length
!= 4) {
960 v
= IVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
962 if ((c
= dsdb_class_by_governsID_id(ctx
->schema
, v
))) {
963 str
= talloc_strdup(out
->values
, c
->lDAPDisplayName
);
964 } else if ((a
= dsdb_attribute_by_attributeID_id(ctx
->schema
, v
))) {
965 str
= talloc_strdup(out
->values
, a
->lDAPDisplayName
);
968 SMB_ASSERT(ctx
->pfm_remote
);
969 werr
= dsdb_schema_pfm_oid_from_attid(ctx
->pfm_remote
, v
,
971 W_ERROR_NOT_OK_RETURN(werr
);
973 W_ERROR_HAVE_NO_MEMORY(str
);
975 /* the values need to be reversed */
976 out
->values
[out
->num_values
- (i
+ 1)] = data_blob_string_const(str
);
982 static WERROR
_dsdb_syntax_OID_obj_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
983 const struct dsdb_attribute
*attr
,
984 const struct drsuapi_DsReplicaAttribute
*in
,
986 struct ldb_message_element
*out
)
991 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
992 W_ERROR_HAVE_NO_MEMORY(out
->name
);
994 out
->num_values
= in
->value_ctr
.num_values
;
995 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
996 W_ERROR_HAVE_NO_MEMORY(out
->values
);
998 for (i
=0; i
< out
->num_values
; i
++) {
1000 const struct dsdb_class
*c
;
1003 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
1007 if (in
->value_ctr
.values
[i
].blob
->length
!= 4) {
1011 v
= IVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
1014 /* convert remote ATTID to local ATTID */
1015 if (!dsdb_syntax_attid_from_remote_attid(ctx
, mem_ctx
, v
, &v
)) {
1016 DEBUG(1,(__location__
": Failed to map remote ATTID to local ATTID!\n"));
1020 c
= dsdb_class_by_governsID_id(ctx
->schema
, v
);
1022 int dbg_level
= ctx
->schema
->resolving_in_progress
? 10 : 0;
1023 DEBUG(dbg_level
,(__location__
": %s unknown local governsID 0x%08X remote 0x%08X%s\n",
1024 attr
->lDAPDisplayName
, v
, vo
,
1025 ctx
->schema
->resolving_in_progress
? "resolving in progress" : ""));
1026 return WERR_DS_OBJ_CLASS_NOT_DEFINED
;
1029 str
= talloc_strdup(out
->values
, c
->lDAPDisplayName
);
1030 W_ERROR_HAVE_NO_MEMORY(str
);
1032 /* the values need to be reversed */
1033 out
->values
[out
->num_values
- (i
+ 1)] = data_blob_string_const(str
);
1039 static WERROR
_dsdb_syntax_OID_attr_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
1040 const struct dsdb_attribute
*attr
,
1041 const struct drsuapi_DsReplicaAttribute
*in
,
1042 TALLOC_CTX
*mem_ctx
,
1043 struct ldb_message_element
*out
)
1048 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
1049 W_ERROR_HAVE_NO_MEMORY(out
->name
);
1051 out
->num_values
= in
->value_ctr
.num_values
;
1052 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
1053 W_ERROR_HAVE_NO_MEMORY(out
->values
);
1055 for (i
=0; i
< out
->num_values
; i
++) {
1057 const struct dsdb_attribute
*a
;
1060 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
1061 DEBUG(0, ("Attribute has no value\n"));
1065 if (in
->value_ctr
.values
[i
].blob
->length
!= 4) {
1066 DEBUG(0, ("Attribute has a value with 0 length\n"));
1070 v
= IVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
1073 /* convert remote ATTID to local ATTID */
1074 if (!dsdb_syntax_attid_from_remote_attid(ctx
, mem_ctx
, v
, &v
)) {
1075 DEBUG(1,(__location__
": Failed to map remote ATTID to local ATTID!\n"));
1079 a
= dsdb_attribute_by_attributeID_id(ctx
->schema
, v
);
1081 int dbg_level
= ctx
->schema
->resolving_in_progress
? 10 : 0;
1082 DEBUG(dbg_level
,(__location__
": %s unknown local attributeID_id 0x%08X remote 0x%08X%s\n",
1083 attr
->lDAPDisplayName
, v
, vo
,
1084 ctx
->schema
->resolving_in_progress
? "resolving in progress" : ""));
1085 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1088 str
= talloc_strdup(out
->values
, a
->lDAPDisplayName
);
1089 W_ERROR_HAVE_NO_MEMORY(str
);
1091 /* the values need to be reversed */
1092 out
->values
[out
->num_values
- (i
+ 1)] = data_blob_string_const(str
);
1098 static WERROR
_dsdb_syntax_OID_oid_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
1099 const struct dsdb_attribute
*attr
,
1100 const struct drsuapi_DsReplicaAttribute
*in
,
1101 TALLOC_CTX
*mem_ctx
,
1102 struct ldb_message_element
*out
)
1105 const struct dsdb_schema_prefixmap
*prefixmap
;
1107 if (ctx
->pfm_remote
!= NULL
) {
1108 prefixmap
= ctx
->pfm_remote
;
1110 prefixmap
= ctx
->schema
->prefixmap
;
1112 SMB_ASSERT(prefixmap
);
1115 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
1116 W_ERROR_HAVE_NO_MEMORY(out
->name
);
1118 out
->num_values
= in
->value_ctr
.num_values
;
1119 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
1120 W_ERROR_HAVE_NO_MEMORY(out
->values
);
1122 for (i
=0; i
< out
->num_values
; i
++) {
1127 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
1131 if (in
->value_ctr
.values
[i
].blob
->length
!= 4) {
1135 attid
= IVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
1137 status
= dsdb_schema_pfm_oid_from_attid(prefixmap
, attid
,
1139 if (!W_ERROR_IS_OK(status
)) {
1140 DEBUG(0,(__location__
": Error: Unknown ATTID 0x%08X\n",
1145 out
->values
[i
] = data_blob_string_const(oid
);
1151 static WERROR
_dsdb_syntax_auto_OID_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
1152 const struct dsdb_attribute
*attr
,
1153 const struct ldb_message_element
*in
,
1154 TALLOC_CTX
*mem_ctx
,
1155 struct drsuapi_DsReplicaAttribute
*out
)
1160 out
->attid
= dsdb_attribute_get_attid(attr
,
1162 out
->value_ctr
.num_values
= in
->num_values
;
1163 out
->value_ctr
.values
= talloc_array(mem_ctx
,
1164 struct drsuapi_DsAttributeValue
,
1166 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
1168 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
1169 W_ERROR_HAVE_NO_MEMORY(blobs
);
1171 for (i
=0; i
< in
->num_values
; i
++) {
1172 const struct dsdb_class
*obj_class
;
1173 const struct dsdb_attribute
*obj_attr
;
1176 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
1178 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 4);
1179 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
1181 /* in DRS windows puts the classes in the opposite
1182 order to the order used in ldap */
1183 v
= &in
->values
[(in
->num_values
-1)-i
];
1185 if ((obj_class
= dsdb_class_by_lDAPDisplayName_ldb_val(ctx
->schema
, v
))) {
1186 SIVAL(blobs
[i
].data
, 0, obj_class
->governsID_id
);
1187 } else if ((obj_attr
= dsdb_attribute_by_lDAPDisplayName_ldb_val(ctx
->schema
, v
))) {
1188 SIVAL(blobs
[i
].data
, 0, obj_attr
->attributeID_id
);
1192 werr
= dsdb_schema_pfm_attid_from_oid(ctx
->schema
->prefixmap
,
1193 (const char *)v
->data
,
1195 W_ERROR_NOT_OK_RETURN(werr
);
1196 SIVAL(blobs
[i
].data
, 0, attid
);
1205 static WERROR
_dsdb_syntax_OID_obj_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
1206 const struct dsdb_attribute
*attr
,
1207 const struct ldb_message_element
*in
,
1208 TALLOC_CTX
*mem_ctx
,
1209 struct drsuapi_DsReplicaAttribute
*out
)
1214 out
->attid
= dsdb_attribute_get_attid(attr
,
1216 out
->value_ctr
.num_values
= in
->num_values
;
1217 out
->value_ctr
.values
= talloc_array(mem_ctx
,
1218 struct drsuapi_DsAttributeValue
,
1220 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
1222 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
1223 W_ERROR_HAVE_NO_MEMORY(blobs
);
1225 for (i
=0; i
< in
->num_values
; i
++) {
1226 const struct dsdb_class
*obj_class
;
1228 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
1230 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 4);
1231 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
1233 /* in DRS windows puts the classes in the opposite
1234 order to the order used in ldap */
1235 obj_class
= dsdb_class_by_lDAPDisplayName(ctx
->schema
,
1236 (const char *)in
->values
[(in
->num_values
-1)-i
].data
);
1240 SIVAL(blobs
[i
].data
, 0, obj_class
->governsID_id
);
1247 static WERROR
_dsdb_syntax_OID_attr_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
1248 const struct dsdb_attribute
*attr
,
1249 const struct ldb_message_element
*in
,
1250 TALLOC_CTX
*mem_ctx
,
1251 struct drsuapi_DsReplicaAttribute
*out
)
1256 out
->attid
= dsdb_attribute_get_attid(attr
,
1258 out
->value_ctr
.num_values
= in
->num_values
;
1259 out
->value_ctr
.values
= talloc_array(mem_ctx
,
1260 struct drsuapi_DsAttributeValue
,
1262 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
1264 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
1265 W_ERROR_HAVE_NO_MEMORY(blobs
);
1267 for (i
=0; i
< in
->num_values
; i
++) {
1268 const struct dsdb_attribute
*obj_attr
;
1270 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
1272 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 4);
1273 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
1275 obj_attr
= dsdb_attribute_by_lDAPDisplayName(ctx
->schema
, (const char *)in
->values
[i
].data
);
1277 DEBUG(0, ("Unable to find attribute %s in the schema\n", (const char *)in
->values
[i
].data
));
1280 SIVAL(blobs
[i
].data
, 0, obj_attr
->attributeID_id
);
1287 static WERROR
_dsdb_syntax_OID_oid_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
1288 const struct dsdb_attribute
*attr
,
1289 const struct ldb_message_element
*in
,
1290 TALLOC_CTX
*mem_ctx
,
1291 struct drsuapi_DsReplicaAttribute
*out
)
1296 out
->attid
= dsdb_attribute_get_attid(attr
,
1298 out
->value_ctr
.num_values
= in
->num_values
;
1299 out
->value_ctr
.values
= talloc_array(mem_ctx
,
1300 struct drsuapi_DsAttributeValue
,
1302 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
1304 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
1305 W_ERROR_HAVE_NO_MEMORY(blobs
);
1307 for (i
=0; i
< in
->num_values
; i
++) {
1311 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
1313 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 4);
1314 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
1316 status
= dsdb_schema_pfm_attid_from_oid(ctx
->schema
->prefixmap
,
1317 (const char *)in
->values
[i
].data
,
1319 W_ERROR_NOT_OK_RETURN(status
);
1321 SIVAL(blobs
[i
].data
, 0, attid
);
1327 static WERROR
dsdb_syntax_OID_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
1328 const struct dsdb_attribute
*attr
,
1329 const struct drsuapi_DsReplicaAttribute
*in
,
1330 TALLOC_CTX
*mem_ctx
,
1331 struct ldb_message_element
*out
)
1335 switch (attr
->attributeID_id
) {
1336 case DRSUAPI_ATTID_objectClass
:
1337 case DRSUAPI_ATTID_subClassOf
:
1338 case DRSUAPI_ATTID_auxiliaryClass
:
1339 case DRSUAPI_ATTID_systemAuxiliaryClass
:
1340 case DRSUAPI_ATTID_systemPossSuperiors
:
1341 case DRSUAPI_ATTID_possSuperiors
:
1342 werr
= _dsdb_syntax_OID_obj_drsuapi_to_ldb(ctx
, attr
, in
, mem_ctx
, out
);
1344 case DRSUAPI_ATTID_systemMustContain
:
1345 case DRSUAPI_ATTID_systemMayContain
:
1346 case DRSUAPI_ATTID_mustContain
:
1347 case DRSUAPI_ATTID_rDNAttId
:
1348 case DRSUAPI_ATTID_transportAddressAttribute
:
1349 case DRSUAPI_ATTID_mayContain
:
1350 werr
= _dsdb_syntax_OID_attr_drsuapi_to_ldb(ctx
, attr
, in
, mem_ctx
, out
);
1352 case DRSUAPI_ATTID_governsID
:
1353 case DRSUAPI_ATTID_attributeID
:
1354 case DRSUAPI_ATTID_attributeSyntax
:
1355 werr
= _dsdb_syntax_OID_oid_drsuapi_to_ldb(ctx
, attr
, in
, mem_ctx
, out
);
1358 DEBUG(0,(__location__
": Unknown handling for attributeID_id for %s\n",
1359 attr
->lDAPDisplayName
));
1360 return _dsdb_syntax_auto_OID_drsuapi_to_ldb(ctx
, attr
, in
, mem_ctx
, out
);
1363 /* When we are doing the vampire of a schema, we don't want
1364 * the inability to reference an OID to get in the way.
1365 * Otherwise, we won't get the new schema with which to
1366 * understand this */
1367 if (!W_ERROR_IS_OK(werr
) && ctx
->schema
->relax_OID_conversions
) {
1368 return _dsdb_syntax_OID_oid_drsuapi_to_ldb(ctx
, attr
, in
, mem_ctx
, out
);
1373 static WERROR
dsdb_syntax_OID_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
1374 const struct dsdb_attribute
*attr
,
1375 const struct ldb_message_element
*in
,
1376 TALLOC_CTX
*mem_ctx
,
1377 struct drsuapi_DsReplicaAttribute
*out
)
1379 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1380 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1383 switch (attr
->attributeID_id
) {
1384 case DRSUAPI_ATTID_objectClass
:
1385 case DRSUAPI_ATTID_subClassOf
:
1386 case DRSUAPI_ATTID_auxiliaryClass
:
1387 case DRSUAPI_ATTID_systemAuxiliaryClass
:
1388 case DRSUAPI_ATTID_systemPossSuperiors
:
1389 case DRSUAPI_ATTID_possSuperiors
:
1390 return _dsdb_syntax_OID_obj_ldb_to_drsuapi(ctx
, attr
, in
, mem_ctx
, out
);
1391 case DRSUAPI_ATTID_systemMustContain
:
1392 case DRSUAPI_ATTID_systemMayContain
:
1393 case DRSUAPI_ATTID_mustContain
:
1394 case DRSUAPI_ATTID_rDNAttId
:
1395 case DRSUAPI_ATTID_transportAddressAttribute
:
1396 case DRSUAPI_ATTID_mayContain
:
1397 return _dsdb_syntax_OID_attr_ldb_to_drsuapi(ctx
, attr
, in
, mem_ctx
, out
);
1398 case DRSUAPI_ATTID_governsID
:
1399 case DRSUAPI_ATTID_attributeID
:
1400 case DRSUAPI_ATTID_attributeSyntax
:
1401 return _dsdb_syntax_OID_oid_ldb_to_drsuapi(ctx
, attr
, in
, mem_ctx
, out
);
1404 DEBUG(0,(__location__
": Unknown handling for attributeID_id for %s\n",
1405 attr
->lDAPDisplayName
));
1407 return _dsdb_syntax_auto_OID_ldb_to_drsuapi(ctx
, attr
, in
, mem_ctx
, out
);
1410 static WERROR
_dsdb_syntax_OID_validate_numericoid(const struct dsdb_syntax_ctx
*ctx
,
1411 const struct dsdb_attribute
*attr
,
1412 const struct ldb_message_element
*in
)
1415 TALLOC_CTX
*tmp_ctx
;
1417 tmp_ctx
= talloc_new(ctx
->ldb
);
1418 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
1420 for (i
=0; i
< in
->num_values
; i
++) {
1423 const char *oid
= (const char*)in
->values
[i
].data
;
1425 if (in
->values
[i
].length
== 0) {
1426 talloc_free(tmp_ctx
);
1427 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1430 if (!ber_write_OID_String(tmp_ctx
, &blob
, oid
)) {
1431 DEBUG(0,("ber_write_OID_String() failed for %s\n", oid
));
1432 talloc_free(tmp_ctx
);
1433 return WERR_INVALID_PARAMETER
;
1436 if (!ber_read_OID_String(tmp_ctx
, blob
, &oid_out
)) {
1437 DEBUG(0,("ber_read_OID_String() failed for %s\n",
1438 hex_encode_talloc(tmp_ctx
, blob
.data
, blob
.length
)));
1439 talloc_free(tmp_ctx
);
1440 return WERR_INVALID_PARAMETER
;
1443 if (strcmp(oid
, oid_out
) != 0) {
1444 talloc_free(tmp_ctx
);
1445 return WERR_INVALID_PARAMETER
;
1449 talloc_free(tmp_ctx
);
1453 static WERROR
dsdb_syntax_OID_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
1454 const struct dsdb_attribute
*attr
,
1455 const struct ldb_message_element
*in
)
1458 struct drsuapi_DsReplicaAttribute drs_tmp
;
1459 struct ldb_message_element ldb_tmp
;
1460 TALLOC_CTX
*tmp_ctx
;
1462 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1463 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1466 switch (attr
->attributeID_id
) {
1467 case DRSUAPI_ATTID_governsID
:
1468 case DRSUAPI_ATTID_attributeID
:
1469 case DRSUAPI_ATTID_attributeSyntax
:
1470 return _dsdb_syntax_OID_validate_numericoid(ctx
, attr
, in
);
1474 * TODO: optimize and verify this code
1477 tmp_ctx
= talloc_new(ctx
->ldb
);
1478 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
1480 status
= dsdb_syntax_OID_ldb_to_drsuapi(ctx
,
1485 if (!W_ERROR_IS_OK(status
)) {
1486 talloc_free(tmp_ctx
);
1490 status
= dsdb_syntax_OID_drsuapi_to_ldb(ctx
,
1495 if (!W_ERROR_IS_OK(status
)) {
1496 talloc_free(tmp_ctx
);
1500 talloc_free(tmp_ctx
);
1504 static WERROR
dsdb_syntax_UNICODE_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
1505 const struct dsdb_attribute
*attr
,
1506 const struct drsuapi_DsReplicaAttribute
*in
,
1507 TALLOC_CTX
*mem_ctx
,
1508 struct ldb_message_element
*out
)
1513 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
1514 W_ERROR_HAVE_NO_MEMORY(out
->name
);
1516 out
->num_values
= in
->value_ctr
.num_values
;
1517 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
1518 W_ERROR_HAVE_NO_MEMORY(out
->values
);
1520 for (i
=0; i
< out
->num_values
; i
++) {
1521 size_t converted_size
= 0;
1524 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
1528 if (in
->value_ctr
.values
[i
].blob
->length
== 0) {
1532 if (!convert_string_talloc(out
->values
,
1534 in
->value_ctr
.values
[i
].blob
->data
,
1535 in
->value_ctr
.values
[i
].blob
->length
,
1536 (void **)&str
, &converted_size
)) {
1540 out
->values
[i
] = data_blob_const(str
, converted_size
);
1546 static WERROR
dsdb_syntax_UNICODE_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
1547 const struct dsdb_attribute
*attr
,
1548 const struct ldb_message_element
*in
,
1549 TALLOC_CTX
*mem_ctx
,
1550 struct drsuapi_DsReplicaAttribute
*out
)
1555 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1556 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1559 out
->attid
= dsdb_attribute_get_attid(attr
,
1561 out
->value_ctr
.num_values
= in
->num_values
;
1562 out
->value_ctr
.values
= talloc_array(mem_ctx
,
1563 struct drsuapi_DsAttributeValue
,
1565 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
1567 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
1568 W_ERROR_HAVE_NO_MEMORY(blobs
);
1570 for (i
=0; i
< in
->num_values
; i
++) {
1571 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
1573 if (!convert_string_talloc(blobs
,
1575 in
->values
[i
].data
, in
->values
[i
].length
,
1576 (void **)&blobs
[i
].data
, &blobs
[i
].length
)) {
1584 static WERROR
dsdb_syntax_UNICODE_validate_one_val(const struct dsdb_syntax_ctx
*ctx
,
1585 const struct dsdb_attribute
*attr
,
1586 const struct ldb_val
*val
)
1592 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1593 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1596 ok
= convert_string_talloc(ctx
->ldb
,
1604 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1607 if (attr
->rangeLower
) {
1608 if ((size
/2) < *attr
->rangeLower
) {
1609 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1613 if (attr
->rangeUpper
) {
1614 if ((size
/2) > *attr
->rangeUpper
) {
1615 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1622 static WERROR
dsdb_syntax_UNICODE_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
1623 const struct dsdb_attribute
*attr
,
1624 const struct ldb_message_element
*in
)
1629 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1630 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1633 for (i
=0; i
< in
->num_values
; i
++) {
1634 if (in
->values
[i
].length
== 0) {
1635 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1638 status
= dsdb_syntax_UNICODE_validate_one_val(ctx
,
1641 if (!W_ERROR_IS_OK(status
)) {
1649 static WERROR
dsdb_syntax_one_DN_drsuapi_to_ldb(TALLOC_CTX
*mem_ctx
, struct ldb_context
*ldb
,
1650 const struct dsdb_syntax
*syntax
,
1651 const DATA_BLOB
*in
, DATA_BLOB
*out
)
1653 struct drsuapi_DsReplicaObjectIdentifier3 id3
;
1654 enum ndr_err_code ndr_err
;
1655 DATA_BLOB guid_blob
;
1657 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
1662 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
1666 talloc_free(tmp_ctx
);
1670 if (in
->length
== 0) {
1671 talloc_free(tmp_ctx
);
1676 /* windows sometimes sends an extra two pad bytes here */
1677 ndr_err
= ndr_pull_struct_blob(in
,
1679 (ndr_pull_flags_fn_t
)ndr_pull_drsuapi_DsReplicaObjectIdentifier3
);
1680 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1681 status
= ndr_map_error2ntstatus(ndr_err
);
1682 talloc_free(tmp_ctx
);
1683 return ntstatus_to_werror(status
);
1686 dn
= ldb_dn_new(tmp_ctx
, ldb
, id3
.dn
);
1688 talloc_free(tmp_ctx
);
1689 /* If this fails, it must be out of memory, as it does not do much parsing */
1690 W_ERROR_HAVE_NO_MEMORY(dn
);
1693 if (!GUID_all_zero(&id3
.guid
)) {
1694 status
= GUID_to_ndr_blob(&id3
.guid
, tmp_ctx
, &guid_blob
);
1695 if (!NT_STATUS_IS_OK(status
)) {
1696 talloc_free(tmp_ctx
);
1697 return ntstatus_to_werror(status
);
1700 ret
= ldb_dn_set_extended_component(dn
, "GUID", &guid_blob
);
1701 if (ret
!= LDB_SUCCESS
) {
1702 talloc_free(tmp_ctx
);
1705 talloc_free(guid_blob
.data
);
1708 if (id3
.__ndr_size_sid
) {
1710 ndr_err
= ndr_push_struct_blob(&sid_blob
, tmp_ctx
, &id3
.sid
,
1711 (ndr_push_flags_fn_t
)ndr_push_dom_sid
);
1712 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1713 status
= ndr_map_error2ntstatus(ndr_err
);
1714 talloc_free(tmp_ctx
);
1715 return ntstatus_to_werror(status
);
1718 ret
= ldb_dn_set_extended_component(dn
, "SID", &sid_blob
);
1719 if (ret
!= LDB_SUCCESS
) {
1720 talloc_free(tmp_ctx
);
1725 *out
= data_blob_string_const(ldb_dn_get_extended_linearized(mem_ctx
, dn
, 1));
1726 talloc_free(tmp_ctx
);
1730 static WERROR
dsdb_syntax_DN_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
1731 const struct dsdb_attribute
*attr
,
1732 const struct drsuapi_DsReplicaAttribute
*in
,
1733 TALLOC_CTX
*mem_ctx
,
1734 struct ldb_message_element
*out
)
1739 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
1740 W_ERROR_HAVE_NO_MEMORY(out
->name
);
1742 out
->num_values
= in
->value_ctr
.num_values
;
1743 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
1744 W_ERROR_HAVE_NO_MEMORY(out
->values
);
1746 for (i
=0; i
< out
->num_values
; i
++) {
1747 WERROR status
= dsdb_syntax_one_DN_drsuapi_to_ldb(out
->values
, ctx
->ldb
, attr
->syntax
,
1748 in
->value_ctr
.values
[i
].blob
,
1750 if (!W_ERROR_IS_OK(status
)) {
1759 static WERROR
dsdb_syntax_DN_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
1760 const struct dsdb_attribute
*attr
,
1761 const struct ldb_message_element
*in
,
1762 TALLOC_CTX
*mem_ctx
,
1763 struct drsuapi_DsReplicaAttribute
*out
)
1768 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1769 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1772 out
->attid
= dsdb_attribute_get_attid(attr
,
1774 out
->value_ctr
.num_values
= in
->num_values
;
1775 out
->value_ctr
.values
= talloc_array(mem_ctx
,
1776 struct drsuapi_DsAttributeValue
,
1778 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
1780 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
1781 W_ERROR_HAVE_NO_MEMORY(blobs
);
1783 for (i
=0; i
< in
->num_values
; i
++) {
1784 struct drsuapi_DsReplicaObjectIdentifier3 id3
;
1785 enum ndr_err_code ndr_err
;
1787 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
1790 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
1792 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
1794 dn
= ldb_dn_from_ldb_val(tmp_ctx
, ctx
->ldb
, &in
->values
[i
]);
1796 W_ERROR_HAVE_NO_MEMORY(dn
);
1800 status
= dsdb_get_extended_dn_guid(dn
, &id3
.guid
, "GUID");
1801 if (!NT_STATUS_IS_OK(status
) &&
1802 !NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1803 talloc_free(tmp_ctx
);
1804 return ntstatus_to_werror(status
);
1807 status
= dsdb_get_extended_dn_sid(dn
, &id3
.sid
, "SID");
1808 if (!NT_STATUS_IS_OK(status
) &&
1809 !NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1810 talloc_free(tmp_ctx
);
1811 return ntstatus_to_werror(status
);
1814 id3
.dn
= ldb_dn_get_linearized(dn
);
1816 ndr_err
= ndr_push_struct_blob(&blobs
[i
], blobs
, &id3
, (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
1817 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1818 status
= ndr_map_error2ntstatus(ndr_err
);
1819 talloc_free(tmp_ctx
);
1820 return ntstatus_to_werror(status
);
1822 talloc_free(tmp_ctx
);
1828 static WERROR
dsdb_syntax_DN_validate_one_val(const struct dsdb_syntax_ctx
*ctx
,
1829 const struct dsdb_attribute
*attr
,
1830 const struct ldb_val
*val
,
1831 TALLOC_CTX
*mem_ctx
,
1832 struct dsdb_dn
**_dsdb_dn
)
1834 static const char * const extended_list
[] = { "GUID", "SID", NULL
};
1835 enum ndr_err_code ndr_err
;
1838 const DATA_BLOB
*sid_blob
;
1839 struct dsdb_dn
*dsdb_dn
;
1845 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
1848 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
1850 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1851 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1854 dsdb_dn
= dsdb_dn_parse(tmp_ctx
, ctx
->ldb
, val
,
1855 attr
->syntax
->ldap_oid
);
1857 talloc_free(tmp_ctx
);
1858 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1862 dn2
= ldb_dn_copy(tmp_ctx
, dn
);
1864 talloc_free(tmp_ctx
);
1868 num_components
= ldb_dn_get_comp_num(dn
);
1870 status
= dsdb_get_extended_dn_guid(dn
, &guid
, "GUID");
1871 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1873 } else if (!NT_STATUS_IS_OK(status
)) {
1874 talloc_free(tmp_ctx
);
1875 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1878 sid_blob
= ldb_dn_get_extended_component(dn
, "SID");
1881 ndr_err
= ndr_pull_struct_blob_all(sid_blob
,
1884 (ndr_pull_flags_fn_t
)ndr_pull_dom_sid
);
1885 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1886 talloc_free(tmp_ctx
);
1887 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1891 /* Do not allow links to the RootDSE */
1892 if (num_components
== 0) {
1893 talloc_free(tmp_ctx
);
1894 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1898 * We need to check that only "GUID" and "SID" are
1899 * specified as extended components, we do that
1900 * by comparing the dn's after removing all components
1901 * from one dn and only the allowed subset from the other
1904 ldb_dn_extended_filter(dn
, extended_list
);
1906 dn_str
= ldb_dn_get_extended_linearized(tmp_ctx
, dn
, 0);
1907 if (dn_str
== NULL
) {
1908 talloc_free(tmp_ctx
);
1909 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1911 dn2_str
= ldb_dn_get_extended_linearized(tmp_ctx
, dn2
, 0);
1912 if (dn2_str
== NULL
) {
1913 talloc_free(tmp_ctx
);
1914 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1917 if (strcmp(dn_str
, dn2_str
) != 0) {
1918 talloc_free(tmp_ctx
);
1919 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1922 *_dsdb_dn
= talloc_move(mem_ctx
, &dsdb_dn
);
1923 talloc_free(tmp_ctx
);
1927 static WERROR
dsdb_syntax_DN_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
1928 const struct dsdb_attribute
*attr
,
1929 const struct ldb_message_element
*in
)
1933 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
1934 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
1937 for (i
=0; i
< in
->num_values
; i
++) {
1939 struct dsdb_dn
*dsdb_dn
;
1940 TALLOC_CTX
*tmp_ctx
= talloc_new(ctx
->ldb
);
1941 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
1943 status
= dsdb_syntax_DN_validate_one_val(ctx
,
1947 if (!W_ERROR_IS_OK(status
)) {
1948 talloc_free(tmp_ctx
);
1952 if (dsdb_dn
->dn_format
!= DSDB_NORMAL_DN
) {
1953 talloc_free(tmp_ctx
);
1954 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
1957 talloc_free(tmp_ctx
);
1963 static WERROR
dsdb_syntax_DN_BINARY_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
1964 const struct dsdb_attribute
*attr
,
1965 const struct drsuapi_DsReplicaAttribute
*in
,
1966 TALLOC_CTX
*mem_ctx
,
1967 struct ldb_message_element
*out
)
1973 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
1974 W_ERROR_HAVE_NO_MEMORY(out
->name
);
1976 out
->num_values
= in
->value_ctr
.num_values
;
1977 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
1978 W_ERROR_HAVE_NO_MEMORY(out
->values
);
1980 for (i
=0; i
< out
->num_values
; i
++) {
1981 struct drsuapi_DsReplicaObjectIdentifier3Binary id3
;
1982 enum ndr_err_code ndr_err
;
1983 DATA_BLOB guid_blob
;
1985 struct dsdb_dn
*dsdb_dn
;
1987 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
1989 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
1992 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
1993 talloc_free(tmp_ctx
);
1997 if (in
->value_ctr
.values
[i
].blob
->length
== 0) {
1998 talloc_free(tmp_ctx
);
2003 /* windows sometimes sends an extra two pad bytes here */
2004 ndr_err
= ndr_pull_struct_blob(in
->value_ctr
.values
[i
].blob
,
2006 (ndr_pull_flags_fn_t
)ndr_pull_drsuapi_DsReplicaObjectIdentifier3Binary
);
2007 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2008 status
= ndr_map_error2ntstatus(ndr_err
);
2009 talloc_free(tmp_ctx
);
2010 return ntstatus_to_werror(status
);
2013 dn
= ldb_dn_new(tmp_ctx
, ctx
->ldb
, id3
.dn
);
2015 talloc_free(tmp_ctx
);
2016 /* If this fails, it must be out of memory, as it does not do much parsing */
2017 W_ERROR_HAVE_NO_MEMORY(dn
);
2020 if (!GUID_all_zero(&id3
.guid
)) {
2021 status
= GUID_to_ndr_blob(&id3
.guid
, tmp_ctx
, &guid_blob
);
2022 if (!NT_STATUS_IS_OK(status
)) {
2023 talloc_free(tmp_ctx
);
2024 return ntstatus_to_werror(status
);
2027 ret
= ldb_dn_set_extended_component(dn
, "GUID", &guid_blob
);
2028 if (ret
!= LDB_SUCCESS
) {
2029 talloc_free(tmp_ctx
);
2032 talloc_free(guid_blob
.data
);
2035 if (id3
.__ndr_size_sid
) {
2037 ndr_err
= ndr_push_struct_blob(&sid_blob
, tmp_ctx
, &id3
.sid
,
2038 (ndr_push_flags_fn_t
)ndr_push_dom_sid
);
2039 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2040 status
= ndr_map_error2ntstatus(ndr_err
);
2041 talloc_free(tmp_ctx
);
2042 return ntstatus_to_werror(status
);
2045 ret
= ldb_dn_set_extended_component(dn
, "SID", &sid_blob
);
2046 if (ret
!= LDB_SUCCESS
) {
2047 talloc_free(tmp_ctx
);
2052 /* set binary stuff */
2053 dsdb_dn
= dsdb_dn_construct(tmp_ctx
, dn
, id3
.binary
, attr
->syntax
->ldap_oid
);
2055 /* If this fails, it must be out of memory, we know the ldap_oid is valid */
2056 talloc_free(tmp_ctx
);
2057 W_ERROR_HAVE_NO_MEMORY(dsdb_dn
);
2059 out
->values
[i
] = data_blob_string_const(dsdb_dn_get_extended_linearized(out
->values
, dsdb_dn
, 1));
2060 talloc_free(tmp_ctx
);
2066 static WERROR
dsdb_syntax_DN_BINARY_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
2067 const struct dsdb_attribute
*attr
,
2068 const struct ldb_message_element
*in
,
2069 TALLOC_CTX
*mem_ctx
,
2070 struct drsuapi_DsReplicaAttribute
*out
)
2075 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
2076 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
2079 out
->attid
= dsdb_attribute_get_attid(attr
,
2081 out
->value_ctr
.num_values
= in
->num_values
;
2082 out
->value_ctr
.values
= talloc_array(mem_ctx
,
2083 struct drsuapi_DsAttributeValue
,
2085 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
2087 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
2088 W_ERROR_HAVE_NO_MEMORY(blobs
);
2090 for (i
=0; i
< in
->num_values
; i
++) {
2091 struct drsuapi_DsReplicaObjectIdentifier3Binary id3
;
2092 enum ndr_err_code ndr_err
;
2093 const DATA_BLOB
*sid_blob
;
2094 struct dsdb_dn
*dsdb_dn
;
2095 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
2098 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
2100 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
2102 dsdb_dn
= dsdb_dn_parse(tmp_ctx
, ctx
->ldb
, &in
->values
[i
], attr
->syntax
->ldap_oid
);
2105 talloc_free(tmp_ctx
);
2106 return ntstatus_to_werror(NT_STATUS_INVALID_PARAMETER
);
2111 status
= dsdb_get_extended_dn_guid(dsdb_dn
->dn
, &id3
.guid
, "GUID");
2112 if (!NT_STATUS_IS_OK(status
) &&
2113 !NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
2114 talloc_free(tmp_ctx
);
2115 return ntstatus_to_werror(status
);
2118 sid_blob
= ldb_dn_get_extended_component(dsdb_dn
->dn
, "SID");
2121 ndr_err
= ndr_pull_struct_blob_all(sid_blob
,
2123 (ndr_pull_flags_fn_t
)ndr_pull_dom_sid
);
2124 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2125 status
= ndr_map_error2ntstatus(ndr_err
);
2126 talloc_free(tmp_ctx
);
2127 return ntstatus_to_werror(status
);
2131 id3
.dn
= ldb_dn_get_linearized(dsdb_dn
->dn
);
2133 /* get binary stuff */
2134 id3
.binary
= dsdb_dn
->extra_part
;
2136 ndr_err
= ndr_push_struct_blob(&blobs
[i
], blobs
, &id3
, (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3Binary
);
2137 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2138 status
= ndr_map_error2ntstatus(ndr_err
);
2139 talloc_free(tmp_ctx
);
2140 return ntstatus_to_werror(status
);
2142 talloc_free(tmp_ctx
);
2148 static WERROR
dsdb_syntax_DN_BINARY_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
2149 const struct dsdb_attribute
*attr
,
2150 const struct ldb_message_element
*in
)
2154 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
2155 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
2158 for (i
=0; i
< in
->num_values
; i
++) {
2160 struct dsdb_dn
*dsdb_dn
;
2161 TALLOC_CTX
*tmp_ctx
= talloc_new(ctx
->ldb
);
2162 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
2164 status
= dsdb_syntax_DN_validate_one_val(ctx
,
2168 if (!W_ERROR_IS_OK(status
)) {
2169 talloc_free(tmp_ctx
);
2173 if (dsdb_dn
->dn_format
!= DSDB_BINARY_DN
) {
2174 talloc_free(tmp_ctx
);
2175 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
2178 status
= dsdb_syntax_DATA_BLOB_validate_one_val(ctx
,
2180 &dsdb_dn
->extra_part
);
2181 if (!W_ERROR_IS_OK(status
)) {
2182 talloc_free(tmp_ctx
);
2186 talloc_free(tmp_ctx
);
2192 static WERROR
dsdb_syntax_DN_STRING_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
2193 const struct dsdb_attribute
*attr
,
2194 const struct drsuapi_DsReplicaAttribute
*in
,
2195 TALLOC_CTX
*mem_ctx
,
2196 struct ldb_message_element
*out
)
2198 return dsdb_syntax_DN_BINARY_drsuapi_to_ldb(ctx
,
2205 static WERROR
dsdb_syntax_DN_STRING_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
2206 const struct dsdb_attribute
*attr
,
2207 const struct ldb_message_element
*in
,
2208 TALLOC_CTX
*mem_ctx
,
2209 struct drsuapi_DsReplicaAttribute
*out
)
2211 return dsdb_syntax_DN_BINARY_ldb_to_drsuapi(ctx
,
2218 static WERROR
dsdb_syntax_DN_STRING_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
2219 const struct dsdb_attribute
*attr
,
2220 const struct ldb_message_element
*in
)
2224 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
2225 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
2228 for (i
=0; i
< in
->num_values
; i
++) {
2230 struct dsdb_dn
*dsdb_dn
;
2231 TALLOC_CTX
*tmp_ctx
= talloc_new(ctx
->ldb
);
2232 W_ERROR_HAVE_NO_MEMORY(tmp_ctx
);
2234 status
= dsdb_syntax_DN_validate_one_val(ctx
,
2238 if (!W_ERROR_IS_OK(status
)) {
2239 talloc_free(tmp_ctx
);
2243 if (dsdb_dn
->dn_format
!= DSDB_STRING_DN
) {
2244 talloc_free(tmp_ctx
);
2245 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX
;
2248 status
= dsdb_syntax_UNICODE_validate_one_val(ctx
,
2250 &dsdb_dn
->extra_part
);
2251 if (!W_ERROR_IS_OK(status
)) {
2252 talloc_free(tmp_ctx
);
2256 talloc_free(tmp_ctx
);
2262 static WERROR
dsdb_syntax_PRESENTATION_ADDRESS_drsuapi_to_ldb(const struct dsdb_syntax_ctx
*ctx
,
2263 const struct dsdb_attribute
*attr
,
2264 const struct drsuapi_DsReplicaAttribute
*in
,
2265 TALLOC_CTX
*mem_ctx
,
2266 struct ldb_message_element
*out
)
2271 out
->name
= talloc_strdup(mem_ctx
, attr
->lDAPDisplayName
);
2272 W_ERROR_HAVE_NO_MEMORY(out
->name
);
2274 out
->num_values
= in
->value_ctr
.num_values
;
2275 out
->values
= talloc_array(mem_ctx
, struct ldb_val
, out
->num_values
);
2276 W_ERROR_HAVE_NO_MEMORY(out
->values
);
2278 for (i
=0; i
< out
->num_values
; i
++) {
2280 size_t converted_size
= 0;
2283 if (in
->value_ctr
.values
[i
].blob
== NULL
) {
2287 if (in
->value_ctr
.values
[i
].blob
->length
< 4) {
2291 len
= IVAL(in
->value_ctr
.values
[i
].blob
->data
, 0);
2293 if (len
!= in
->value_ctr
.values
[i
].blob
->length
) {
2297 if (!convert_string_talloc(out
->values
, CH_UTF16
, CH_UNIX
,
2298 in
->value_ctr
.values
[i
].blob
->data
+4,
2299 in
->value_ctr
.values
[i
].blob
->length
-4,
2300 (void **)&str
, &converted_size
)) {
2304 out
->values
[i
] = data_blob_string_const(str
);
2310 static WERROR
dsdb_syntax_PRESENTATION_ADDRESS_ldb_to_drsuapi(const struct dsdb_syntax_ctx
*ctx
,
2311 const struct dsdb_attribute
*attr
,
2312 const struct ldb_message_element
*in
,
2313 TALLOC_CTX
*mem_ctx
,
2314 struct drsuapi_DsReplicaAttribute
*out
)
2319 if (attr
->attributeID_id
== DRSUAPI_ATTID_INVALID
) {
2320 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
2323 out
->attid
= dsdb_attribute_get_attid(attr
,
2325 out
->value_ctr
.num_values
= in
->num_values
;
2326 out
->value_ctr
.values
= talloc_array(mem_ctx
,
2327 struct drsuapi_DsAttributeValue
,
2329 W_ERROR_HAVE_NO_MEMORY(out
->value_ctr
.values
);
2331 blobs
= talloc_array(mem_ctx
, DATA_BLOB
, in
->num_values
);
2332 W_ERROR_HAVE_NO_MEMORY(blobs
);
2334 for (i
=0; i
< in
->num_values
; i
++) {
2338 out
->value_ctr
.values
[i
].blob
= &blobs
[i
];
2340 if (!convert_string_talloc(blobs
, CH_UNIX
, CH_UTF16
,
2342 in
->values
[i
].length
,
2343 (void **)&data
, &ret
)) {
2347 blobs
[i
] = data_blob_talloc(blobs
, NULL
, 4 + ret
);
2348 W_ERROR_HAVE_NO_MEMORY(blobs
[i
].data
);
2350 SIVAL(blobs
[i
].data
, 0, 4 + ret
);
2353 memcpy(blobs
[i
].data
+ 4, data
, ret
);
2361 static WERROR
dsdb_syntax_PRESENTATION_ADDRESS_validate_ldb(const struct dsdb_syntax_ctx
*ctx
,
2362 const struct dsdb_attribute
*attr
,
2363 const struct ldb_message_element
*in
)
2365 return dsdb_syntax_UNICODE_validate_ldb(ctx
,
2370 #define OMOBJECTCLASS(val) { .length = sizeof(val) - 1, .data = discard_const_p(uint8_t, val) }
2372 static const struct dsdb_syntax dsdb_syntaxes
[] = {
2375 .ldap_oid
= LDB_SYNTAX_BOOLEAN
,
2377 .attributeSyntax_oid
= "2.5.5.8",
2378 .drsuapi_to_ldb
= dsdb_syntax_BOOL_drsuapi_to_ldb
,
2379 .ldb_to_drsuapi
= dsdb_syntax_BOOL_ldb_to_drsuapi
,
2380 .validate_ldb
= dsdb_syntax_BOOL_validate_ldb
,
2381 .equality
= "booleanMatch",
2382 .comment
= "Boolean",
2383 .auto_normalise
= true
2386 .ldap_oid
= LDB_SYNTAX_INTEGER
,
2388 .attributeSyntax_oid
= "2.5.5.9",
2389 .drsuapi_to_ldb
= dsdb_syntax_INT32_drsuapi_to_ldb
,
2390 .ldb_to_drsuapi
= dsdb_syntax_INT32_ldb_to_drsuapi
,
2391 .validate_ldb
= dsdb_syntax_INT32_validate_ldb
,
2392 .equality
= "integerMatch",
2393 .comment
= "Integer",
2394 .ldb_syntax
= LDB_SYNTAX_SAMBA_INT32
,
2395 .auto_normalise
= true
2397 .name
= "String(Octet)",
2398 .ldap_oid
= LDB_SYNTAX_OCTET_STRING
,
2400 .attributeSyntax_oid
= "2.5.5.10",
2401 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2402 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2403 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2404 .equality
= "octetStringMatch",
2405 .comment
= "Octet String",
2406 .userParameters
= true,
2407 .ldb_syntax
= LDB_SYNTAX_SAMBA_OCTET_STRING
2409 .name
= "String(Sid)",
2410 .ldap_oid
= LDB_SYNTAX_OCTET_STRING
,
2412 .attributeSyntax_oid
= "2.5.5.17",
2413 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2414 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2415 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2416 .equality
= "octetStringMatch",
2417 .comment
= "Octet String - Security Identifier (SID)",
2418 .ldb_syntax
= LDB_SYNTAX_SAMBA_SID
2420 .name
= "String(Object-Identifier)",
2421 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.38",
2423 .attributeSyntax_oid
= "2.5.5.2",
2424 .drsuapi_to_ldb
= dsdb_syntax_OID_drsuapi_to_ldb
,
2425 .ldb_to_drsuapi
= dsdb_syntax_OID_ldb_to_drsuapi
,
2426 .validate_ldb
= dsdb_syntax_OID_validate_ldb
,
2427 .equality
= "caseIgnoreMatch", /* Would use "objectIdentifierMatch" but most are ldap attribute/class names */
2428 .comment
= "OID String",
2429 .ldb_syntax
= LDB_SYNTAX_DIRECTORY_STRING
2431 .name
= "Enumeration",
2432 .ldap_oid
= LDB_SYNTAX_INTEGER
,
2434 .attributeSyntax_oid
= "2.5.5.9",
2435 .drsuapi_to_ldb
= dsdb_syntax_INT32_drsuapi_to_ldb
,
2436 .ldb_to_drsuapi
= dsdb_syntax_INT32_ldb_to_drsuapi
,
2437 .validate_ldb
= dsdb_syntax_INT32_validate_ldb
,
2438 .ldb_syntax
= LDB_SYNTAX_SAMBA_INT32
,
2439 .auto_normalise
= true
2441 /* not used in w2k3 forest */
2442 .name
= "String(Numeric)",
2443 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.36",
2445 .attributeSyntax_oid
= "2.5.5.6",
2446 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2447 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2448 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2449 .equality
= "numericStringMatch",
2450 .substring
= "numericStringSubstringsMatch",
2451 .comment
= "Numeric String",
2452 .ldb_syntax
= LDB_SYNTAX_DIRECTORY_STRING
,
2454 .name
= "String(Printable)",
2455 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.44",
2457 .attributeSyntax_oid
= "2.5.5.5",
2458 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2459 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2460 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2461 .ldb_syntax
= LDB_SYNTAX_SAMBA_OCTET_STRING
,
2463 .name
= "String(Teletex)",
2464 .ldap_oid
= "1.2.840.113556.1.4.905",
2466 .attributeSyntax_oid
= "2.5.5.4",
2467 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2468 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2469 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2470 .equality
= "caseIgnoreMatch",
2471 .substring
= "caseIgnoreSubstringsMatch",
2472 .comment
= "Case Insensitive String",
2473 .ldb_syntax
= LDB_SYNTAX_DIRECTORY_STRING
,
2475 .name
= "String(IA5)",
2476 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.26",
2478 .attributeSyntax_oid
= "2.5.5.5",
2479 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2480 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2481 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2482 .equality
= "caseExactIA5Match",
2483 .comment
= "Printable String",
2484 .ldb_syntax
= LDB_SYNTAX_SAMBA_OCTET_STRING
,
2486 .name
= "String(UTC-Time)",
2487 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.53",
2489 .attributeSyntax_oid
= "2.5.5.11",
2490 .drsuapi_to_ldb
= dsdb_syntax_NTTIME_UTC_drsuapi_to_ldb
,
2491 .ldb_to_drsuapi
= dsdb_syntax_NTTIME_UTC_ldb_to_drsuapi
,
2492 .validate_ldb
= dsdb_syntax_NTTIME_UTC_validate_ldb
,
2493 .equality
= "generalizedTimeMatch",
2494 .comment
= "UTC Time",
2495 .auto_normalise
= true
2497 .name
= "String(Generalized-Time)",
2498 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.24",
2500 .attributeSyntax_oid
= "2.5.5.11",
2501 .drsuapi_to_ldb
= dsdb_syntax_NTTIME_drsuapi_to_ldb
,
2502 .ldb_to_drsuapi
= dsdb_syntax_NTTIME_ldb_to_drsuapi
,
2503 .validate_ldb
= dsdb_syntax_NTTIME_validate_ldb
,
2504 .equality
= "generalizedTimeMatch",
2505 .comment
= "Generalized Time",
2506 .auto_normalise
= true
2508 /* not used in w2k3 schema */
2509 .name
= "String(Case Sensitive)",
2510 .ldap_oid
= "1.2.840.113556.1.4.1362",
2512 .attributeSyntax_oid
= "2.5.5.3",
2513 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2514 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2515 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2516 .equality
= "caseExactMatch",
2517 .substring
= "caseExactSubstringsMatch",
2518 /* TODO (kim): according to LDAP rfc we should be using same comparison
2519 * as Directory String (LDB_SYNTAX_DIRECTORY_STRING), but case sensitive.
2520 * But according to ms docs binary compare should do the job:
2521 * http://msdn.microsoft.com/en-us/library/cc223200(v=PROT.10).aspx */
2522 .ldb_syntax
= LDB_SYNTAX_SAMBA_OCTET_STRING
,
2524 .name
= "String(Unicode)",
2525 .ldap_oid
= LDB_SYNTAX_DIRECTORY_STRING
,
2527 .attributeSyntax_oid
= "2.5.5.12",
2528 .drsuapi_to_ldb
= dsdb_syntax_UNICODE_drsuapi_to_ldb
,
2529 .ldb_to_drsuapi
= dsdb_syntax_UNICODE_ldb_to_drsuapi
,
2530 .validate_ldb
= dsdb_syntax_UNICODE_validate_ldb
,
2531 .equality
= "caseIgnoreMatch",
2532 .substring
= "caseIgnoreSubstringsMatch",
2533 .comment
= "Directory String",
2535 .name
= "Interval/LargeInteger",
2536 .ldap_oid
= "1.2.840.113556.1.4.906",
2538 .attributeSyntax_oid
= "2.5.5.16",
2539 .drsuapi_to_ldb
= dsdb_syntax_INT64_drsuapi_to_ldb
,
2540 .ldb_to_drsuapi
= dsdb_syntax_INT64_ldb_to_drsuapi
,
2541 .validate_ldb
= dsdb_syntax_INT64_validate_ldb
,
2542 .equality
= "integerMatch",
2543 .comment
= "Large Integer",
2544 .ldb_syntax
= LDB_SYNTAX_INTEGER
,
2545 .auto_normalise
= true
2547 .name
= "String(NT-Sec-Desc)",
2548 .ldap_oid
= LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR
,
2550 .attributeSyntax_oid
= "2.5.5.15",
2551 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2552 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2553 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2555 .name
= "Object(DS-DN)",
2556 .ldap_oid
= LDB_SYNTAX_DN
,
2558 .oMObjectClass
= OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x4a"),
2559 .attributeSyntax_oid
= "2.5.5.1",
2560 .drsuapi_to_ldb
= dsdb_syntax_DN_drsuapi_to_ldb
,
2561 .ldb_to_drsuapi
= dsdb_syntax_DN_ldb_to_drsuapi
,
2562 .validate_ldb
= dsdb_syntax_DN_validate_ldb
,
2563 .equality
= "distinguishedNameMatch",
2564 .comment
= "Object(DS-DN) == a DN",
2566 .name
= "Object(DN-Binary)",
2567 .ldap_oid
= DSDB_SYNTAX_BINARY_DN
,
2569 .oMObjectClass
= OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x0b"),
2570 .attributeSyntax_oid
= "2.5.5.7",
2571 .drsuapi_to_ldb
= dsdb_syntax_DN_BINARY_drsuapi_to_ldb
,
2572 .ldb_to_drsuapi
= dsdb_syntax_DN_BINARY_ldb_to_drsuapi
,
2573 .validate_ldb
= dsdb_syntax_DN_BINARY_validate_ldb
,
2574 .equality
= "octetStringMatch",
2575 .comment
= "OctetString: Binary+DN",
2577 /* not used in w2k3 schema, but used in Exchange schema*/
2578 .name
= "Object(OR-Name)",
2579 .ldap_oid
= DSDB_SYNTAX_OR_NAME
,
2581 .oMObjectClass
= OMOBJECTCLASS("\x56\x06\x01\x02\x05\x0b\x1D"),
2582 .attributeSyntax_oid
= "2.5.5.7",
2583 .drsuapi_to_ldb
= dsdb_syntax_DN_BINARY_drsuapi_to_ldb
,
2584 .ldb_to_drsuapi
= dsdb_syntax_DN_BINARY_ldb_to_drsuapi
,
2585 .validate_ldb
= dsdb_syntax_DN_BINARY_validate_ldb
,
2586 .equality
= "caseIgnoreMatch",
2587 .ldb_syntax
= LDB_SYNTAX_DN
,
2590 * TODO: verify if DATA_BLOB is correct here...!
2592 * repsFrom and repsTo are the only attributes using
2593 * this attribute syntax, but they're not replicated...
2595 .name
= "Object(Replica-Link)",
2596 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.40",
2598 .oMObjectClass
= OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x06"),
2599 .attributeSyntax_oid
= "2.5.5.10",
2600 .drsuapi_to_ldb
= dsdb_syntax_DATA_BLOB_drsuapi_to_ldb
,
2601 .ldb_to_drsuapi
= dsdb_syntax_DATA_BLOB_ldb_to_drsuapi
,
2602 .validate_ldb
= dsdb_syntax_DATA_BLOB_validate_ldb
,
2604 .name
= "Object(Presentation-Address)",
2605 .ldap_oid
= "1.3.6.1.4.1.1466.115.121.1.43",
2607 .oMObjectClass
= OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x5c"),
2608 .attributeSyntax_oid
= "2.5.5.13",
2609 .drsuapi_to_ldb
= dsdb_syntax_PRESENTATION_ADDRESS_drsuapi_to_ldb
,
2610 .ldb_to_drsuapi
= dsdb_syntax_PRESENTATION_ADDRESS_ldb_to_drsuapi
,
2611 .validate_ldb
= dsdb_syntax_PRESENTATION_ADDRESS_validate_ldb
,
2612 .comment
= "Presentation Address",
2613 .ldb_syntax
= LDB_SYNTAX_DIRECTORY_STRING
,
2615 /* not used in w2k3 schema */
2616 .name
= "Object(Access-Point)",
2617 .ldap_oid
= DSDB_SYNTAX_ACCESS_POINT
,
2619 .oMObjectClass
= OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x3e"),
2620 .attributeSyntax_oid
= "2.5.5.14",
2621 .drsuapi_to_ldb
= dsdb_syntax_FOOBAR_drsuapi_to_ldb
,
2622 .ldb_to_drsuapi
= dsdb_syntax_FOOBAR_ldb_to_drsuapi
,
2623 .validate_ldb
= dsdb_syntax_FOOBAR_validate_ldb
,
2624 .ldb_syntax
= LDB_SYNTAX_DIRECTORY_STRING
,
2626 /* not used in w2k3 schema */
2627 .name
= "Object(DN-String)",
2628 .ldap_oid
= DSDB_SYNTAX_STRING_DN
,
2630 .oMObjectClass
= OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x0c"),
2631 .attributeSyntax_oid
= "2.5.5.14",
2632 .drsuapi_to_ldb
= dsdb_syntax_DN_STRING_drsuapi_to_ldb
,
2633 .ldb_to_drsuapi
= dsdb_syntax_DN_STRING_ldb_to_drsuapi
,
2634 .validate_ldb
= dsdb_syntax_DN_STRING_validate_ldb
,
2635 .equality
= "octetStringMatch",
2636 .comment
= "OctetString: String+DN",
2640 const struct dsdb_syntax
*find_syntax_map_by_ad_oid(const char *ad_oid
)
2643 for (i
=0; dsdb_syntaxes
[i
].ldap_oid
; i
++) {
2644 if (strcasecmp(ad_oid
, dsdb_syntaxes
[i
].attributeSyntax_oid
) == 0) {
2645 return &dsdb_syntaxes
[i
];
2651 const struct dsdb_syntax
*find_syntax_map_by_ad_syntax(int oMSyntax
)
2654 for (i
=0; dsdb_syntaxes
[i
].ldap_oid
; i
++) {
2655 if (oMSyntax
== dsdb_syntaxes
[i
].oMSyntax
) {
2656 return &dsdb_syntaxes
[i
];
2662 const struct dsdb_syntax
*find_syntax_map_by_standard_oid(const char *standard_oid
)
2665 for (i
=0; dsdb_syntaxes
[i
].ldap_oid
; i
++) {
2666 if (strcasecmp(standard_oid
, dsdb_syntaxes
[i
].ldap_oid
) == 0) {
2667 return &dsdb_syntaxes
[i
];
2673 const struct dsdb_syntax
*dsdb_syntax_for_attribute(const struct dsdb_attribute
*attr
)
2677 for (i
=0; i
< ARRAY_SIZE(dsdb_syntaxes
); i
++) {
2679 * We must pretend that userParamters was declared
2680 * binary string, so we can store the 'UTF16' (not
2681 * really string) structure as given over SAMR to samba
2683 if (dsdb_syntaxes
[i
].userParameters
&&
2684 (strcasecmp(attr
->lDAPDisplayName
, "userParameters") == 0))
2686 return &dsdb_syntaxes
[i
];
2688 if (attr
->oMSyntax
!= dsdb_syntaxes
[i
].oMSyntax
) continue;
2690 if (attr
->oMObjectClass
.length
!= dsdb_syntaxes
[i
].oMObjectClass
.length
) continue;
2692 if (attr
->oMObjectClass
.length
) {
2694 ret
= memcmp(attr
->oMObjectClass
.data
,
2695 dsdb_syntaxes
[i
].oMObjectClass
.data
,
2696 attr
->oMObjectClass
.length
);
2697 if (ret
!= 0) continue;
2700 if (strcmp(attr
->attributeSyntax_oid
, dsdb_syntaxes
[i
].attributeSyntax_oid
) != 0) continue;
2702 return &dsdb_syntaxes
[i
];
2708 WERROR
dsdb_attribute_drsuapi_remote_to_local(const struct dsdb_syntax_ctx
*ctx
,
2709 enum drsuapi_DsAttributeId remote_attid_as_enum
,
2710 enum drsuapi_DsAttributeId
*local_attid_as_enum
,
2711 const struct dsdb_attribute
**_sa
)
2713 TALLOC_CTX
*frame
= talloc_stackframe();
2714 const struct dsdb_attribute
*sa
;
2715 uint32_t attid_local
;
2718 if (ctx
->pfm_remote
== NULL
) {
2719 smb_panic(__location__
);
2722 switch (dsdb_pfm_get_attid_type(remote_attid_as_enum
)) {
2723 case DSDB_ATTID_TYPE_PFM
:
2724 /* map remote ATTID to local ATTID */
2725 ok
= dsdb_syntax_attid_from_remote_attid(ctx
, frame
,
2726 remote_attid_as_enum
,
2729 DEBUG(0,(__location__
": Can't find local ATTID for 0x%08X\n",
2730 remote_attid_as_enum
));
2732 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
2735 case DSDB_ATTID_TYPE_INTID
:
2736 /* use IntId value directly */
2737 attid_local
= remote_attid_as_enum
;
2740 /* we should never get here */
2741 DEBUG(0,(__location__
": Invalid ATTID type passed for conversion - 0x%08X\n",
2742 remote_attid_as_enum
));
2744 return WERR_INVALID_PARAMETER
;
2747 sa
= dsdb_attribute_by_attributeID_id(ctx
->schema
, attid_local
);
2749 int dbg_level
= ctx
->schema
->resolving_in_progress
? 10 : 0;
2750 DEBUG(dbg_level
,(__location__
": Unknown local attributeID_id 0x%08X remote 0x%08X%s\n",
2751 attid_local
, remote_attid_as_enum
,
2752 ctx
->schema
->resolving_in_progress
? "resolving in progress" : ""));
2754 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
2758 * We return the same class of attid as we were given. That
2759 * is, we trust the remote server not to use an
2760 * msDS-IntId value in the schema partition
2762 if (local_attid_as_enum
!= NULL
) {
2763 *local_attid_as_enum
= (enum drsuapi_DsAttributeId
)attid_local
;
2774 WERROR
dsdb_attribute_drsuapi_to_ldb(struct ldb_context
*ldb
,
2775 const struct dsdb_schema
*schema
,
2776 const struct dsdb_schema_prefixmap
*pfm_remote
,
2777 const struct drsuapi_DsReplicaAttribute
*in
,
2778 TALLOC_CTX
*mem_ctx
,
2779 struct ldb_message_element
*out
,
2780 enum drsuapi_DsAttributeId
*local_attid_as_enum
)
2782 struct dsdb_syntax_ctx syntax_ctx
;
2783 const struct dsdb_attribute
*sa
= NULL
;
2786 /* use default syntax conversion context */
2787 dsdb_syntax_ctx_init(&syntax_ctx
, ldb
, schema
);
2788 syntax_ctx
.pfm_remote
= pfm_remote
;
2790 werr
= dsdb_attribute_drsuapi_remote_to_local(&syntax_ctx
,
2792 local_attid_as_enum
,
2794 if (!W_ERROR_IS_OK(werr
)) {
2798 return sa
->syntax
->drsuapi_to_ldb(&syntax_ctx
, sa
, in
, mem_ctx
, out
);
2801 WERROR
dsdb_attribute_ldb_to_drsuapi(struct ldb_context
*ldb
,
2802 const struct dsdb_schema
*schema
,
2803 const struct ldb_message_element
*in
,
2804 TALLOC_CTX
*mem_ctx
,
2805 struct drsuapi_DsReplicaAttribute
*out
)
2807 const struct dsdb_attribute
*sa
;
2808 struct dsdb_syntax_ctx syntax_ctx
;
2810 sa
= dsdb_attribute_by_lDAPDisplayName(schema
, in
->name
);
2812 return WERR_DS_ATT_NOT_DEF_IN_SCHEMA
;
2815 /* use default syntax conversion context */
2816 dsdb_syntax_ctx_init(&syntax_ctx
, ldb
, schema
);
2818 return sa
->syntax
->ldb_to_drsuapi(&syntax_ctx
, sa
, in
, mem_ctx
, out
);