s4/dsdb: schemaInfo revision may be 0
[Samba.git] / source4 / dsdb / schema / schema_syntax.c
bloba0eed3d7c0d26295a8e35d8b3e25062ac9fd3efe
1 /*
2 Unix SMB/CIFS mplementation.
3 DSDB schema syntaxes
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/>.
23 #include "includes.h"
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"
28 #include "lib/ldb/include/ldb.h"
29 #include "lib/ldb/include/ldb_errors.h"
30 #include "system/time.h"
31 #include "../lib/util/charset/charset.h"
32 #include "librpc/ndr/libndr.h"
34 static WERROR dsdb_syntax_FOOBAR_drsuapi_to_ldb(struct ldb_context *ldb,
35 const struct dsdb_schema *schema,
36 const struct dsdb_attribute *attr,
37 const struct drsuapi_DsReplicaAttribute *in,
38 TALLOC_CTX *mem_ctx,
39 struct ldb_message_element *out)
41 unsigned int i;
43 out->flags = 0;
44 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
45 W_ERROR_HAVE_NO_MEMORY(out->name);
47 out->num_values = in->value_ctr.num_values;
48 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
49 W_ERROR_HAVE_NO_MEMORY(out->values);
51 for (i=0; i < out->num_values; i++) {
52 char *str;
54 if (in->value_ctr.values[i].blob == NULL) {
55 return WERR_FOOBAR;
58 str = talloc_asprintf(out->values, "%s: not implemented",
59 attr->syntax->name);
60 W_ERROR_HAVE_NO_MEMORY(str);
62 out->values[i] = data_blob_string_const(str);
65 return WERR_OK;
68 static WERROR dsdb_syntax_FOOBAR_ldb_to_drsuapi(struct ldb_context *ldb,
69 const struct dsdb_schema *schema,
70 const struct dsdb_attribute *attr,
71 const struct ldb_message_element *in,
72 TALLOC_CTX *mem_ctx,
73 struct drsuapi_DsReplicaAttribute *out)
75 return WERR_FOOBAR;
78 static WERROR dsdb_syntax_FOOBAR_validate_ldb(struct ldb_context *ldb,
79 const struct dsdb_schema *schema,
80 const struct dsdb_attribute *attr,
81 const struct ldb_message_element *in)
83 return WERR_FOOBAR;
86 static WERROR dsdb_syntax_BOOL_drsuapi_to_ldb(struct ldb_context *ldb,
87 const struct dsdb_schema *schema,
88 const struct dsdb_attribute *attr,
89 const struct drsuapi_DsReplicaAttribute *in,
90 TALLOC_CTX *mem_ctx,
91 struct ldb_message_element *out)
93 unsigned int i;
95 out->flags = 0;
96 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
97 W_ERROR_HAVE_NO_MEMORY(out->name);
99 out->num_values = in->value_ctr.num_values;
100 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
101 W_ERROR_HAVE_NO_MEMORY(out->values);
103 for (i=0; i < out->num_values; i++) {
104 uint32_t v;
105 char *str;
107 if (in->value_ctr.values[i].blob == NULL) {
108 return WERR_FOOBAR;
111 if (in->value_ctr.values[i].blob->length != 4) {
112 return WERR_FOOBAR;
115 v = IVAL(in->value_ctr.values[i].blob->data, 0);
117 if (v != 0) {
118 str = talloc_strdup(out->values, "TRUE");
119 W_ERROR_HAVE_NO_MEMORY(str);
120 } else {
121 str = talloc_strdup(out->values, "FALSE");
122 W_ERROR_HAVE_NO_MEMORY(str);
125 out->values[i] = data_blob_string_const(str);
128 return WERR_OK;
131 static WERROR dsdb_syntax_BOOL_ldb_to_drsuapi(struct ldb_context *ldb,
132 const struct dsdb_schema *schema,
133 const struct dsdb_attribute *attr,
134 const struct ldb_message_element *in,
135 TALLOC_CTX *mem_ctx,
136 struct drsuapi_DsReplicaAttribute *out)
138 unsigned int i;
139 DATA_BLOB *blobs;
141 if (attr->attributeID_id == 0xFFFFFFFF) {
142 return WERR_FOOBAR;
145 out->attid = attr->attributeID_id;
146 out->value_ctr.num_values = in->num_values;
147 out->value_ctr.values = talloc_array(mem_ctx,
148 struct drsuapi_DsAttributeValue,
149 in->num_values);
150 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
152 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
153 W_ERROR_HAVE_NO_MEMORY(blobs);
155 for (i=0; i < in->num_values; i++) {
156 out->value_ctr.values[i].blob = &blobs[i];
158 blobs[i] = data_blob_talloc(blobs, NULL, 4);
159 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
161 if (strcmp("TRUE", (const char *)in->values[i].data) == 0) {
162 SIVAL(blobs[i].data, 0, 0x00000001);
163 } else if (strcmp("FALSE", (const char *)in->values[i].data) == 0) {
164 SIVAL(blobs[i].data, 0, 0x00000000);
165 } else {
166 return WERR_FOOBAR;
170 return WERR_OK;
173 static WERROR dsdb_syntax_BOOL_validate_ldb(struct ldb_context *ldb,
174 const struct dsdb_schema *schema,
175 const struct dsdb_attribute *attr,
176 const struct ldb_message_element *in)
178 unsigned int i;
180 if (attr->attributeID_id == 0xFFFFFFFF) {
181 return WERR_FOOBAR;
184 for (i=0; i < in->num_values; i++) {
185 int t, f;
187 t = strncmp("TRUE",
188 (const char *)in->values[i].data,
189 in->values[i].length);
190 f = strncmp("FALSE",
191 (const char *)in->values[i].data,
192 in->values[i].length);
194 if (t != 0 && f != 0) {
195 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
199 return WERR_OK;
202 static WERROR dsdb_syntax_INT32_drsuapi_to_ldb(struct ldb_context *ldb,
203 const struct dsdb_schema *schema,
204 const struct dsdb_attribute *attr,
205 const struct drsuapi_DsReplicaAttribute *in,
206 TALLOC_CTX *mem_ctx,
207 struct ldb_message_element *out)
209 unsigned int i;
211 out->flags = 0;
212 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
213 W_ERROR_HAVE_NO_MEMORY(out->name);
215 out->num_values = in->value_ctr.num_values;
216 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
217 W_ERROR_HAVE_NO_MEMORY(out->values);
219 for (i=0; i < out->num_values; i++) {
220 int32_t v;
221 char *str;
223 if (in->value_ctr.values[i].blob == NULL) {
224 return WERR_FOOBAR;
227 if (in->value_ctr.values[i].blob->length != 4) {
228 return WERR_FOOBAR;
231 v = IVALS(in->value_ctr.values[i].blob->data, 0);
233 str = talloc_asprintf(out->values, "%d", v);
234 W_ERROR_HAVE_NO_MEMORY(str);
236 out->values[i] = data_blob_string_const(str);
239 return WERR_OK;
242 static WERROR dsdb_syntax_INT32_ldb_to_drsuapi(struct ldb_context *ldb,
243 const struct dsdb_schema *schema,
244 const struct dsdb_attribute *attr,
245 const struct ldb_message_element *in,
246 TALLOC_CTX *mem_ctx,
247 struct drsuapi_DsReplicaAttribute *out)
249 unsigned int i;
250 DATA_BLOB *blobs;
252 if (attr->attributeID_id == 0xFFFFFFFF) {
253 return WERR_FOOBAR;
256 out->attid = attr->attributeID_id;
257 out->value_ctr.num_values = in->num_values;
258 out->value_ctr.values = talloc_array(mem_ctx,
259 struct drsuapi_DsAttributeValue,
260 in->num_values);
261 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
263 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
264 W_ERROR_HAVE_NO_MEMORY(blobs);
266 for (i=0; i < in->num_values; i++) {
267 int32_t v;
269 out->value_ctr.values[i].blob = &blobs[i];
271 blobs[i] = data_blob_talloc(blobs, NULL, 4);
272 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
274 /* We've to use "strtoll" here to have the intended overflows.
275 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
276 v = (int32_t) strtoll((char *)in->values[i].data, NULL, 0);
278 SIVALS(blobs[i].data, 0, v);
281 return WERR_OK;
284 static WERROR dsdb_syntax_INT32_validate_ldb(struct ldb_context *ldb,
285 const struct dsdb_schema *schema,
286 const struct dsdb_attribute *attr,
287 const struct ldb_message_element *in)
289 unsigned int i;
291 if (attr->attributeID_id == 0xFFFFFFFF) {
292 return WERR_FOOBAR;
295 for (i=0; i < in->num_values; i++) {
296 long v;
297 char buf[sizeof("-2147483648")];
298 char *end = NULL;
300 ZERO_STRUCT(buf);
301 if (in->values[i].length >= sizeof(buf)) {
302 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
305 memcpy(buf, in->values[i].data, in->values[i].length);
306 errno = 0;
307 v = strtol(buf, &end, 10);
308 if (errno != 0) {
309 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
311 if (end && end[0] != '\0') {
312 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
315 if (attr->rangeLower) {
316 if ((int32_t)v < (int32_t)*attr->rangeLower) {
317 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
321 if (attr->rangeUpper) {
322 if ((int32_t)v > (int32_t)*attr->rangeUpper) {
323 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
328 return WERR_OK;
331 static WERROR dsdb_syntax_INT64_drsuapi_to_ldb(struct ldb_context *ldb,
332 const struct dsdb_schema *schema,
333 const struct dsdb_attribute *attr,
334 const struct drsuapi_DsReplicaAttribute *in,
335 TALLOC_CTX *mem_ctx,
336 struct ldb_message_element *out)
338 unsigned int i;
340 out->flags = 0;
341 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
342 W_ERROR_HAVE_NO_MEMORY(out->name);
344 out->num_values = in->value_ctr.num_values;
345 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
346 W_ERROR_HAVE_NO_MEMORY(out->values);
348 for (i=0; i < out->num_values; i++) {
349 int64_t v;
350 char *str;
352 if (in->value_ctr.values[i].blob == NULL) {
353 return WERR_FOOBAR;
356 if (in->value_ctr.values[i].blob->length != 8) {
357 return WERR_FOOBAR;
360 v = BVALS(in->value_ctr.values[i].blob->data, 0);
362 str = talloc_asprintf(out->values, "%lld", (long long int)v);
363 W_ERROR_HAVE_NO_MEMORY(str);
365 out->values[i] = data_blob_string_const(str);
368 return WERR_OK;
371 static WERROR dsdb_syntax_INT64_ldb_to_drsuapi(struct ldb_context *ldb,
372 const struct dsdb_schema *schema,
373 const struct dsdb_attribute *attr,
374 const struct ldb_message_element *in,
375 TALLOC_CTX *mem_ctx,
376 struct drsuapi_DsReplicaAttribute *out)
378 unsigned int i;
379 DATA_BLOB *blobs;
381 if (attr->attributeID_id == 0xFFFFFFFF) {
382 return WERR_FOOBAR;
385 out->attid = attr->attributeID_id;
386 out->value_ctr.num_values = in->num_values;
387 out->value_ctr.values = talloc_array(mem_ctx,
388 struct drsuapi_DsAttributeValue,
389 in->num_values);
390 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
392 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
393 W_ERROR_HAVE_NO_MEMORY(blobs);
395 for (i=0; i < in->num_values; i++) {
396 int64_t v;
398 out->value_ctr.values[i].blob = &blobs[i];
400 blobs[i] = data_blob_talloc(blobs, NULL, 8);
401 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
403 v = strtoll((const char *)in->values[i].data, NULL, 10);
405 SBVALS(blobs[i].data, 0, v);
408 return WERR_OK;
411 static WERROR dsdb_syntax_INT64_validate_ldb(struct ldb_context *ldb,
412 const struct dsdb_schema *schema,
413 const struct dsdb_attribute *attr,
414 const struct ldb_message_element *in)
416 unsigned int i;
418 if (attr->attributeID_id == 0xFFFFFFFF) {
419 return WERR_FOOBAR;
422 for (i=0; i < in->num_values; i++) {
423 long long v;
424 char buf[sizeof("-9223372036854775808")];
425 char *end = NULL;
427 ZERO_STRUCT(buf);
428 if (in->values[i].length >= sizeof(buf)) {
429 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
431 memcpy(buf, in->values[i].data, in->values[i].length);
433 errno = 0;
434 v = strtoll(buf, &end, 10);
435 if (errno != 0) {
436 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
438 if (end && end[0] != '\0') {
439 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
442 if (attr->rangeLower) {
443 if ((int64_t)v < (int64_t)*attr->rangeLower) {
444 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
448 if (attr->rangeUpper) {
449 if ((int64_t)v > (int64_t)*attr->rangeUpper) {
450 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
455 return WERR_OK;
457 static WERROR dsdb_syntax_NTTIME_UTC_drsuapi_to_ldb(struct ldb_context *ldb,
458 const struct dsdb_schema *schema,
459 const struct dsdb_attribute *attr,
460 const struct drsuapi_DsReplicaAttribute *in,
461 TALLOC_CTX *mem_ctx,
462 struct ldb_message_element *out)
464 unsigned int i;
466 out->flags = 0;
467 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
468 W_ERROR_HAVE_NO_MEMORY(out->name);
470 out->num_values = in->value_ctr.num_values;
471 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
472 W_ERROR_HAVE_NO_MEMORY(out->values);
474 for (i=0; i < out->num_values; i++) {
475 NTTIME v;
476 time_t t;
477 char *str;
479 if (in->value_ctr.values[i].blob == NULL) {
480 return WERR_FOOBAR;
483 if (in->value_ctr.values[i].blob->length != 8) {
484 return WERR_FOOBAR;
487 v = BVAL(in->value_ctr.values[i].blob->data, 0);
488 v *= 10000000;
489 t = nt_time_to_unix(v);
492 * NOTE: On a w2k3 server you can set a GeneralizedTime string
493 * via LDAP, but you get back an UTCTime string,
494 * but via DRSUAPI you get back the NTTIME_1sec value
495 * that represents the GeneralizedTime value!
497 * So if we store the UTCTime string in our ldb
498 * we'll loose information!
500 str = ldb_timestring_utc(out->values, t);
501 W_ERROR_HAVE_NO_MEMORY(str);
502 out->values[i] = data_blob_string_const(str);
505 return WERR_OK;
508 static WERROR dsdb_syntax_NTTIME_UTC_ldb_to_drsuapi(struct ldb_context *ldb,
509 const struct dsdb_schema *schema,
510 const struct dsdb_attribute *attr,
511 const struct ldb_message_element *in,
512 TALLOC_CTX *mem_ctx,
513 struct drsuapi_DsReplicaAttribute *out)
515 unsigned int i;
516 DATA_BLOB *blobs;
518 if (attr->attributeID_id == 0xFFFFFFFF) {
519 return WERR_FOOBAR;
522 out->attid = attr->attributeID_id;
523 out->value_ctr.num_values = in->num_values;
524 out->value_ctr.values = talloc_array(mem_ctx,
525 struct drsuapi_DsAttributeValue,
526 in->num_values);
527 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
529 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
530 W_ERROR_HAVE_NO_MEMORY(blobs);
532 for (i=0; i < in->num_values; i++) {
533 NTTIME v;
534 time_t t;
536 out->value_ctr.values[i].blob = &blobs[i];
538 blobs[i] = data_blob_talloc(blobs, NULL, 8);
539 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
541 t = ldb_string_utc_to_time((const char *)in->values[i].data);
542 unix_to_nt_time(&v, t);
543 v /= 10000000;
545 SBVAL(blobs[i].data, 0, v);
548 return WERR_OK;
551 static WERROR dsdb_syntax_NTTIME_UTC_validate_ldb(struct ldb_context *ldb,
552 const struct dsdb_schema *schema,
553 const struct dsdb_attribute *attr,
554 const struct ldb_message_element *in)
556 unsigned int i;
558 if (attr->attributeID_id == 0xFFFFFFFF) {
559 return WERR_FOOBAR;
562 for (i=0; i < in->num_values; i++) {
563 time_t t;
564 char buf[sizeof("090826075717Z")];
566 ZERO_STRUCT(buf);
567 if (in->values[i].length >= sizeof(buf)) {
568 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
570 memcpy(buf, in->values[i].data, in->values[i].length);
572 errno = 0;
573 t = ldb_string_utc_to_time(buf);
574 if (errno != 0) {
575 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
578 if (attr->rangeLower) {
579 if ((int32_t)t < (int32_t)*attr->rangeLower) {
580 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
584 if (attr->rangeUpper) {
585 if ((int32_t)t > (int32_t)*attr->rangeLower) {
586 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
591 * TODO: verify the comment in the
592 * dsdb_syntax_NTTIME_UTC_drsuapi_to_ldb() function!
596 return WERR_OK;
599 static WERROR dsdb_syntax_NTTIME_drsuapi_to_ldb(struct ldb_context *ldb,
600 const struct dsdb_schema *schema,
601 const struct dsdb_attribute *attr,
602 const struct drsuapi_DsReplicaAttribute *in,
603 TALLOC_CTX *mem_ctx,
604 struct ldb_message_element *out)
606 unsigned int i;
608 out->flags = 0;
609 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
610 W_ERROR_HAVE_NO_MEMORY(out->name);
612 out->num_values = in->value_ctr.num_values;
613 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
614 W_ERROR_HAVE_NO_MEMORY(out->values);
616 for (i=0; i < out->num_values; i++) {
617 NTTIME v;
618 time_t t;
619 char *str;
621 if (in->value_ctr.values[i].blob == NULL) {
622 return WERR_FOOBAR;
625 if (in->value_ctr.values[i].blob->length != 8) {
626 return WERR_FOOBAR;
629 v = BVAL(in->value_ctr.values[i].blob->data, 0);
630 v *= 10000000;
631 t = nt_time_to_unix(v);
633 str = ldb_timestring(out->values, t);
634 W_ERROR_HAVE_NO_MEMORY(str);
636 out->values[i] = data_blob_string_const(str);
639 return WERR_OK;
642 static WERROR dsdb_syntax_NTTIME_ldb_to_drsuapi(struct ldb_context *ldb,
643 const struct dsdb_schema *schema,
644 const struct dsdb_attribute *attr,
645 const struct ldb_message_element *in,
646 TALLOC_CTX *mem_ctx,
647 struct drsuapi_DsReplicaAttribute *out)
649 unsigned int i;
650 DATA_BLOB *blobs;
652 if (attr->attributeID_id == 0xFFFFFFFF) {
653 return WERR_FOOBAR;
656 out->attid = attr->attributeID_id;
657 out->value_ctr.num_values = in->num_values;
658 out->value_ctr.values = talloc_array(mem_ctx,
659 struct drsuapi_DsAttributeValue,
660 in->num_values);
661 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
663 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
664 W_ERROR_HAVE_NO_MEMORY(blobs);
666 for (i=0; i < in->num_values; i++) {
667 NTTIME v;
668 time_t t;
669 int ret;
671 out->value_ctr.values[i].blob = &blobs[i];
673 blobs[i] = data_blob_talloc(blobs, NULL, 8);
674 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
676 ret = ldb_val_to_time(&in->values[i], &t);
677 if (ret != LDB_SUCCESS) {
678 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
680 unix_to_nt_time(&v, t);
681 v /= 10000000;
683 SBVAL(blobs[i].data, 0, v);
686 return WERR_OK;
689 static WERROR dsdb_syntax_NTTIME_validate_ldb(struct ldb_context *ldb,
690 const struct dsdb_schema *schema,
691 const struct dsdb_attribute *attr,
692 const struct ldb_message_element *in)
694 unsigned int i;
696 if (attr->attributeID_id == 0xFFFFFFFF) {
697 return WERR_FOOBAR;
700 for (i=0; i < in->num_values; i++) {
701 time_t t;
702 int ret;
704 ret = ldb_val_to_time(&in->values[i], &t);
705 if (ret != LDB_SUCCESS) {
706 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
709 if (attr->rangeLower) {
710 if ((int32_t)t < (int32_t)*attr->rangeLower) {
711 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
715 if (attr->rangeUpper) {
716 if ((int32_t)t > (int32_t)*attr->rangeLower) {
717 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
722 return WERR_OK;
725 static WERROR dsdb_syntax_DATA_BLOB_drsuapi_to_ldb(struct ldb_context *ldb,
726 const struct dsdb_schema *schema,
727 const struct dsdb_attribute *attr,
728 const struct drsuapi_DsReplicaAttribute *in,
729 TALLOC_CTX *mem_ctx,
730 struct ldb_message_element *out)
732 unsigned int i;
734 out->flags = 0;
735 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
736 W_ERROR_HAVE_NO_MEMORY(out->name);
738 out->num_values = in->value_ctr.num_values;
739 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
740 W_ERROR_HAVE_NO_MEMORY(out->values);
742 for (i=0; i < out->num_values; i++) {
743 if (in->value_ctr.values[i].blob == NULL) {
744 return WERR_FOOBAR;
747 if (in->value_ctr.values[i].blob->length == 0) {
748 return WERR_FOOBAR;
751 out->values[i] = data_blob_dup_talloc(out->values,
752 in->value_ctr.values[i].blob);
753 W_ERROR_HAVE_NO_MEMORY(out->values[i].data);
756 return WERR_OK;
759 static WERROR dsdb_syntax_DATA_BLOB_ldb_to_drsuapi(struct ldb_context *ldb,
760 const struct dsdb_schema *schema,
761 const struct dsdb_attribute *attr,
762 const struct ldb_message_element *in,
763 TALLOC_CTX *mem_ctx,
764 struct drsuapi_DsReplicaAttribute *out)
766 unsigned int i;
767 DATA_BLOB *blobs;
769 if (attr->attributeID_id == 0xFFFFFFFF) {
770 return WERR_FOOBAR;
773 out->attid = attr->attributeID_id;
774 out->value_ctr.num_values = in->num_values;
775 out->value_ctr.values = talloc_array(mem_ctx,
776 struct drsuapi_DsAttributeValue,
777 in->num_values);
778 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
780 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
781 W_ERROR_HAVE_NO_MEMORY(blobs);
783 for (i=0; i < in->num_values; i++) {
784 out->value_ctr.values[i].blob = &blobs[i];
786 blobs[i] = data_blob_dup_talloc(blobs, &in->values[i]);
787 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
790 return WERR_OK;
793 static WERROR dsdb_syntax_DATA_BLOB_validate_one_val(struct ldb_context *ldb,
794 const struct dsdb_schema *schema,
795 const struct dsdb_attribute *attr,
796 const struct ldb_val *val)
798 if (attr->attributeID_id == 0xFFFFFFFF) {
799 return WERR_FOOBAR;
802 if (attr->rangeLower) {
803 if ((uint32_t)val->length < (uint32_t)*attr->rangeLower) {
804 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
808 if (attr->rangeUpper) {
809 if ((uint32_t)val->length > (uint32_t)*attr->rangeUpper) {
810 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
814 return WERR_OK;
817 static WERROR dsdb_syntax_DATA_BLOB_validate_ldb(struct ldb_context *ldb,
818 const struct dsdb_schema *schema,
819 const struct dsdb_attribute *attr,
820 const struct ldb_message_element *in)
822 unsigned int i;
823 WERROR status;
825 if (attr->attributeID_id == 0xFFFFFFFF) {
826 return WERR_FOOBAR;
829 for (i=0; i < in->num_values; i++) {
830 if (in->values[i].length == 0) {
831 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
834 status = dsdb_syntax_DATA_BLOB_validate_one_val(ldb,
835 schema,
836 attr,
837 &in->values[i]);
838 if (!W_ERROR_IS_OK(status)) {
839 return status;
843 return WERR_OK;
846 static WERROR _dsdb_syntax_auto_OID_drsuapi_to_ldb(struct ldb_context *ldb,
847 const struct dsdb_schema *schema,
848 const struct dsdb_attribute *attr,
849 const struct drsuapi_DsReplicaAttribute *in,
850 TALLOC_CTX *mem_ctx,
851 struct ldb_message_element *out)
853 unsigned int i;
855 out->flags = 0;
856 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
857 W_ERROR_HAVE_NO_MEMORY(out->name);
859 out->num_values = in->value_ctr.num_values;
860 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
861 W_ERROR_HAVE_NO_MEMORY(out->values);
863 for (i=0; i < out->num_values; i++) {
864 uint32_t v;
865 const struct dsdb_class *c;
866 const struct dsdb_attribute *a;
867 const char *str = NULL;
869 if (in->value_ctr.values[i].blob == NULL) {
870 return WERR_FOOBAR;
873 if (in->value_ctr.values[i].blob->length != 4) {
874 return WERR_FOOBAR;
877 v = IVAL(in->value_ctr.values[i].blob->data, 0);
879 if ((c = dsdb_class_by_governsID_id(schema, v))) {
880 str = talloc_strdup(out->values, c->lDAPDisplayName);
881 } else if ((a = dsdb_attribute_by_attributeID_id(schema, v))) {
882 str = talloc_strdup(out->values, a->lDAPDisplayName);
883 } else {
884 WERROR werr;
885 werr = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, v, out->values, &str);
886 W_ERROR_NOT_OK_RETURN(werr);
888 W_ERROR_HAVE_NO_MEMORY(str);
890 /* the values need to be reversed */
891 out->values[out->num_values - (i + 1)] = data_blob_string_const(str);
894 return WERR_OK;
897 static WERROR _dsdb_syntax_OID_obj_drsuapi_to_ldb(struct ldb_context *ldb,
898 const struct dsdb_schema *schema,
899 const struct dsdb_attribute *attr,
900 const struct drsuapi_DsReplicaAttribute *in,
901 TALLOC_CTX *mem_ctx,
902 struct ldb_message_element *out)
904 unsigned int i;
906 out->flags = 0;
907 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
908 W_ERROR_HAVE_NO_MEMORY(out->name);
910 out->num_values = in->value_ctr.num_values;
911 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
912 W_ERROR_HAVE_NO_MEMORY(out->values);
914 for (i=0; i < out->num_values; i++) {
915 uint32_t v;
916 const struct dsdb_class *c;
917 const char *str;
919 if (in->value_ctr.values[i].blob == NULL) {
920 return WERR_FOOBAR;
923 if (in->value_ctr.values[i].blob->length != 4) {
924 return WERR_FOOBAR;
927 v = IVAL(in->value_ctr.values[i].blob->data, 0);
929 c = dsdb_class_by_governsID_id(schema, v);
930 if (!c) {
931 return WERR_FOOBAR;
934 str = talloc_strdup(out->values, c->lDAPDisplayName);
935 W_ERROR_HAVE_NO_MEMORY(str);
937 /* the values need to be reversed */
938 out->values[out->num_values - (i + 1)] = data_blob_string_const(str);
941 return WERR_OK;
944 static WERROR _dsdb_syntax_OID_attr_drsuapi_to_ldb(struct ldb_context *ldb,
945 const struct dsdb_schema *schema,
946 const struct dsdb_attribute *attr,
947 const struct drsuapi_DsReplicaAttribute *in,
948 TALLOC_CTX *mem_ctx,
949 struct ldb_message_element *out)
951 unsigned int i;
953 out->flags = 0;
954 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
955 W_ERROR_HAVE_NO_MEMORY(out->name);
957 out->num_values = in->value_ctr.num_values;
958 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
959 W_ERROR_HAVE_NO_MEMORY(out->values);
961 for (i=0; i < out->num_values; i++) {
962 uint32_t v;
963 const struct dsdb_attribute *a;
964 const char *str;
966 if (in->value_ctr.values[i].blob == NULL) {
967 return WERR_FOOBAR;
970 if (in->value_ctr.values[i].blob->length != 4) {
971 return WERR_FOOBAR;
974 v = IVAL(in->value_ctr.values[i].blob->data, 0);
976 a = dsdb_attribute_by_attributeID_id(schema, v);
977 if (!a) {
978 return WERR_FOOBAR;
981 str = talloc_strdup(out->values, a->lDAPDisplayName);
982 W_ERROR_HAVE_NO_MEMORY(str);
984 /* the values need to be reversed */
985 out->values[out->num_values - (i + 1)] = data_blob_string_const(str);
988 return WERR_OK;
991 static WERROR _dsdb_syntax_OID_oid_drsuapi_to_ldb(struct ldb_context *ldb,
992 const struct dsdb_schema *schema,
993 const struct dsdb_attribute *attr,
994 const struct drsuapi_DsReplicaAttribute *in,
995 TALLOC_CTX *mem_ctx,
996 struct ldb_message_element *out)
998 unsigned int i;
1000 out->flags = 0;
1001 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
1002 W_ERROR_HAVE_NO_MEMORY(out->name);
1004 out->num_values = in->value_ctr.num_values;
1005 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
1006 W_ERROR_HAVE_NO_MEMORY(out->values);
1008 for (i=0; i < out->num_values; i++) {
1009 uint32_t attid;
1010 WERROR status;
1011 const char *oid;
1013 if (in->value_ctr.values[i].blob == NULL) {
1014 return WERR_FOOBAR;
1017 if (in->value_ctr.values[i].blob->length != 4) {
1018 return WERR_FOOBAR;
1021 attid = IVAL(in->value_ctr.values[i].blob->data, 0);
1023 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid, out->values, &oid);
1024 W_ERROR_NOT_OK_RETURN(status);
1026 out->values[i] = data_blob_string_const(oid);
1029 return WERR_OK;
1032 static WERROR _dsdb_syntax_auto_OID_ldb_to_drsuapi(struct ldb_context *ldb,
1033 const struct dsdb_schema *schema,
1034 const struct dsdb_attribute *attr,
1035 const struct ldb_message_element *in,
1036 TALLOC_CTX *mem_ctx,
1037 struct drsuapi_DsReplicaAttribute *out)
1039 unsigned int i;
1040 DATA_BLOB *blobs;
1042 out->attid= attr->attributeID_id;
1043 out->value_ctr.num_values= in->num_values;
1044 out->value_ctr.values= talloc_array(mem_ctx,
1045 struct drsuapi_DsAttributeValue,
1046 in->num_values);
1047 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
1049 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
1050 W_ERROR_HAVE_NO_MEMORY(blobs);
1052 for (i=0; i < in->num_values; i++) {
1053 const struct dsdb_class *obj_class;
1054 const struct dsdb_attribute *obj_attr;
1055 struct ldb_val *v;
1057 out->value_ctr.values[i].blob= &blobs[i];
1059 blobs[i] = data_blob_talloc(blobs, NULL, 4);
1060 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
1062 /* in DRS windows puts the classes in the opposite
1063 order to the order used in ldap */
1064 v = &in->values[(in->num_values-1)-i];
1066 if ((obj_class = dsdb_class_by_lDAPDisplayName_ldb_val(schema, v))) {
1067 SIVAL(blobs[i].data, 0, obj_class->governsID_id);
1068 } else if ((obj_attr = dsdb_attribute_by_lDAPDisplayName_ldb_val(schema, v))) {
1069 SIVAL(blobs[i].data, 0, obj_attr->attributeID_id);
1070 } else {
1071 uint32_t attid;
1072 WERROR werr;
1073 werr = dsdb_schema_pfm_make_attid(schema->prefixmap,
1074 (const char *)v->data,
1075 &attid);
1076 W_ERROR_NOT_OK_RETURN(werr);
1077 SIVAL(blobs[i].data, 0, attid);
1083 return WERR_OK;
1086 static WERROR _dsdb_syntax_OID_obj_ldb_to_drsuapi(struct ldb_context *ldb,
1087 const struct dsdb_schema *schema,
1088 const struct dsdb_attribute *attr,
1089 const struct ldb_message_element *in,
1090 TALLOC_CTX *mem_ctx,
1091 struct drsuapi_DsReplicaAttribute *out)
1093 unsigned int i;
1094 DATA_BLOB *blobs;
1096 out->attid= attr->attributeID_id;
1097 out->value_ctr.num_values= in->num_values;
1098 out->value_ctr.values= talloc_array(mem_ctx,
1099 struct drsuapi_DsAttributeValue,
1100 in->num_values);
1101 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
1103 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
1104 W_ERROR_HAVE_NO_MEMORY(blobs);
1106 for (i=0; i < in->num_values; i++) {
1107 const struct dsdb_class *obj_class;
1109 out->value_ctr.values[i].blob= &blobs[i];
1111 blobs[i] = data_blob_talloc(blobs, NULL, 4);
1112 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
1114 /* in DRS windows puts the classes in the opposite
1115 order to the order used in ldap */
1116 obj_class = dsdb_class_by_lDAPDisplayName(schema,
1117 (const char *)in->values[(in->num_values-1)-i].data);
1118 if (!obj_class) {
1119 return WERR_FOOBAR;
1121 SIVAL(blobs[i].data, 0, obj_class->governsID_id);
1125 return WERR_OK;
1128 static WERROR _dsdb_syntax_OID_attr_ldb_to_drsuapi(struct ldb_context *ldb,
1129 const struct dsdb_schema *schema,
1130 const struct dsdb_attribute *attr,
1131 const struct ldb_message_element *in,
1132 TALLOC_CTX *mem_ctx,
1133 struct drsuapi_DsReplicaAttribute *out)
1135 unsigned int i;
1136 DATA_BLOB *blobs;
1138 out->attid= attr->attributeID_id;
1139 out->value_ctr.num_values= in->num_values;
1140 out->value_ctr.values= talloc_array(mem_ctx,
1141 struct drsuapi_DsAttributeValue,
1142 in->num_values);
1143 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
1145 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
1146 W_ERROR_HAVE_NO_MEMORY(blobs);
1148 for (i=0; i < in->num_values; i++) {
1149 const struct dsdb_attribute *obj_attr;
1151 out->value_ctr.values[i].blob= &blobs[i];
1153 blobs[i] = data_blob_talloc(blobs, NULL, 4);
1154 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
1156 obj_attr = dsdb_attribute_by_lDAPDisplayName(schema, (const char *)in->values[i].data);
1157 if (!obj_attr) {
1158 return WERR_FOOBAR;
1160 SIVAL(blobs[i].data, 0, obj_attr->attributeID_id);
1164 return WERR_OK;
1167 static WERROR _dsdb_syntax_OID_oid_ldb_to_drsuapi(struct ldb_context *ldb,
1168 const struct dsdb_schema *schema,
1169 const struct dsdb_attribute *attr,
1170 const struct ldb_message_element *in,
1171 TALLOC_CTX *mem_ctx,
1172 struct drsuapi_DsReplicaAttribute *out)
1174 unsigned int i;
1175 DATA_BLOB *blobs;
1177 out->attid= attr->attributeID_id;
1178 out->value_ctr.num_values= in->num_values;
1179 out->value_ctr.values= talloc_array(mem_ctx,
1180 struct drsuapi_DsAttributeValue,
1181 in->num_values);
1182 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
1184 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
1185 W_ERROR_HAVE_NO_MEMORY(blobs);
1187 for (i=0; i < in->num_values; i++) {
1188 uint32_t attid;
1189 WERROR status;
1191 out->value_ctr.values[i].blob= &blobs[i];
1193 blobs[i] = data_blob_talloc(blobs, NULL, 4);
1194 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
1196 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
1197 (const char *)in->values[i].data,
1198 &attid);
1199 W_ERROR_NOT_OK_RETURN(status);
1201 SIVAL(blobs[i].data, 0, attid);
1204 return WERR_OK;
1207 static WERROR dsdb_syntax_OID_drsuapi_to_ldb(struct ldb_context *ldb,
1208 const struct dsdb_schema *schema,
1209 const struct dsdb_attribute *attr,
1210 const struct drsuapi_DsReplicaAttribute *in,
1211 TALLOC_CTX *mem_ctx,
1212 struct ldb_message_element *out)
1214 switch (attr->attributeID_id) {
1215 case DRSUAPI_ATTRIBUTE_objectClass:
1216 case DRSUAPI_ATTRIBUTE_subClassOf:
1217 case DRSUAPI_ATTRIBUTE_auxiliaryClass:
1218 case DRSUAPI_ATTRIBUTE_systemAuxiliaryClass:
1219 case DRSUAPI_ATTRIBUTE_systemPossSuperiors:
1220 case DRSUAPI_ATTRIBUTE_possSuperiors:
1221 return _dsdb_syntax_OID_obj_drsuapi_to_ldb(ldb, schema, attr, in, mem_ctx, out);
1222 case DRSUAPI_ATTRIBUTE_systemMustContain:
1223 case DRSUAPI_ATTRIBUTE_systemMayContain:
1224 case DRSUAPI_ATTRIBUTE_mustContain:
1225 case DRSUAPI_ATTRIBUTE_rDNAttId:
1226 case DRSUAPI_ATTRIBUTE_transportAddressAttribute:
1227 case DRSUAPI_ATTRIBUTE_mayContain:
1228 return _dsdb_syntax_OID_attr_drsuapi_to_ldb(ldb, schema, attr, in, mem_ctx, out);
1229 case DRSUAPI_ATTRIBUTE_governsID:
1230 case DRSUAPI_ATTRIBUTE_attributeID:
1231 case DRSUAPI_ATTRIBUTE_attributeSyntax:
1232 return _dsdb_syntax_OID_oid_drsuapi_to_ldb(ldb, schema, attr, in, mem_ctx, out);
1235 DEBUG(0,(__location__ ": Unknown handling for attributeID_id for %s\n",
1236 attr->lDAPDisplayName));
1237 return _dsdb_syntax_auto_OID_drsuapi_to_ldb(ldb, schema, attr, in, mem_ctx, out);
1240 static WERROR dsdb_syntax_OID_ldb_to_drsuapi(struct ldb_context *ldb,
1241 const struct dsdb_schema *schema,
1242 const struct dsdb_attribute *attr,
1243 const struct ldb_message_element *in,
1244 TALLOC_CTX *mem_ctx,
1245 struct drsuapi_DsReplicaAttribute *out)
1247 if (attr->attributeID_id == 0xFFFFFFFF) {
1248 return WERR_FOOBAR;
1251 switch (attr->attributeID_id) {
1252 case DRSUAPI_ATTRIBUTE_objectClass:
1253 case DRSUAPI_ATTRIBUTE_subClassOf:
1254 case DRSUAPI_ATTRIBUTE_auxiliaryClass:
1255 case DRSUAPI_ATTRIBUTE_systemAuxiliaryClass:
1256 case DRSUAPI_ATTRIBUTE_systemPossSuperiors:
1257 case DRSUAPI_ATTRIBUTE_possSuperiors:
1258 return _dsdb_syntax_OID_obj_ldb_to_drsuapi(ldb, schema, attr, in, mem_ctx, out);
1259 case DRSUAPI_ATTRIBUTE_systemMustContain:
1260 case DRSUAPI_ATTRIBUTE_systemMayContain:
1261 case DRSUAPI_ATTRIBUTE_mustContain:
1262 case DRSUAPI_ATTRIBUTE_rDNAttId:
1263 case DRSUAPI_ATTRIBUTE_transportAddressAttribute:
1264 case DRSUAPI_ATTRIBUTE_mayContain:
1265 return _dsdb_syntax_OID_attr_ldb_to_drsuapi(ldb, schema, attr, in, mem_ctx, out);
1266 case DRSUAPI_ATTRIBUTE_governsID:
1267 case DRSUAPI_ATTRIBUTE_attributeID:
1268 case DRSUAPI_ATTRIBUTE_attributeSyntax:
1269 return _dsdb_syntax_OID_oid_ldb_to_drsuapi(ldb, schema, attr, in, mem_ctx, out);
1272 DEBUG(0,(__location__ ": Unknown handling for attributeID_id for %s\n",
1273 attr->lDAPDisplayName));
1275 return _dsdb_syntax_auto_OID_ldb_to_drsuapi(ldb, schema, attr, in, mem_ctx, out);
1278 static WERROR dsdb_syntax_OID_validate_ldb(struct ldb_context *ldb,
1279 const struct dsdb_schema *schema,
1280 const struct dsdb_attribute *attr,
1281 const struct ldb_message_element *in)
1283 WERROR status;
1284 struct drsuapi_DsReplicaAttribute drs_tmp;
1285 struct ldb_message_element ldb_tmp;
1286 TALLOC_CTX *tmp_ctx;
1288 if (attr->attributeID_id == 0xFFFFFFFF) {
1289 return WERR_FOOBAR;
1293 * TODO: optimize and verify this code
1296 tmp_ctx = talloc_new(ldb);
1297 if (tmp_ctx == NULL) {
1298 return WERR_NOMEM;
1301 status = dsdb_syntax_OID_ldb_to_drsuapi(ldb,
1302 schema,
1303 attr,
1305 tmp_ctx,
1306 &drs_tmp);
1307 if (!W_ERROR_IS_OK(status)) {
1308 talloc_free(tmp_ctx);
1309 return status;
1312 status = dsdb_syntax_OID_drsuapi_to_ldb(ldb,
1313 schema,
1314 attr,
1315 &drs_tmp,
1316 tmp_ctx,
1317 &ldb_tmp);
1318 if (!W_ERROR_IS_OK(status)) {
1319 talloc_free(tmp_ctx);
1320 return status;
1323 talloc_free(tmp_ctx);
1324 return WERR_OK;
1327 static WERROR dsdb_syntax_UNICODE_drsuapi_to_ldb(struct ldb_context *ldb,
1328 const struct dsdb_schema *schema,
1329 const struct dsdb_attribute *attr,
1330 const struct drsuapi_DsReplicaAttribute *in,
1331 TALLOC_CTX *mem_ctx,
1332 struct ldb_message_element *out)
1334 unsigned int i;
1336 out->flags = 0;
1337 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
1338 W_ERROR_HAVE_NO_MEMORY(out->name);
1340 out->num_values = in->value_ctr.num_values;
1341 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
1342 W_ERROR_HAVE_NO_MEMORY(out->values);
1344 for (i=0; i < out->num_values; i++) {
1345 char *str;
1347 if (in->value_ctr.values[i].blob == NULL) {
1348 return WERR_FOOBAR;
1351 if (in->value_ctr.values[i].blob->length == 0) {
1352 return WERR_FOOBAR;
1355 if (!convert_string_talloc_convenience(out->values,
1356 schema->iconv_convenience,
1357 CH_UTF16, CH_UNIX,
1358 in->value_ctr.values[i].blob->data,
1359 in->value_ctr.values[i].blob->length,
1360 (void **)&str, NULL, false)) {
1361 return WERR_FOOBAR;
1364 out->values[i] = data_blob_string_const(str);
1367 return WERR_OK;
1370 static WERROR dsdb_syntax_UNICODE_ldb_to_drsuapi(struct ldb_context *ldb,
1371 const struct dsdb_schema *schema,
1372 const struct dsdb_attribute *attr,
1373 const struct ldb_message_element *in,
1374 TALLOC_CTX *mem_ctx,
1375 struct drsuapi_DsReplicaAttribute *out)
1377 unsigned int i;
1378 DATA_BLOB *blobs;
1380 if (attr->attributeID_id == 0xFFFFFFFF) {
1381 return WERR_FOOBAR;
1384 out->attid = attr->attributeID_id;
1385 out->value_ctr.num_values = in->num_values;
1386 out->value_ctr.values = talloc_array(mem_ctx,
1387 struct drsuapi_DsAttributeValue,
1388 in->num_values);
1389 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
1391 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
1392 W_ERROR_HAVE_NO_MEMORY(blobs);
1394 for (i=0; i < in->num_values; i++) {
1395 out->value_ctr.values[i].blob = &blobs[i];
1397 if (!convert_string_talloc_convenience(blobs,
1398 schema->iconv_convenience, CH_UNIX, CH_UTF16,
1399 in->values[i].data, in->values[i].length,
1400 (void **)&blobs[i].data, &blobs[i].length, false)) {
1401 return WERR_FOOBAR;
1405 return WERR_OK;
1408 static WERROR dsdb_syntax_UNICODE_validate_one_val(struct ldb_context *ldb,
1409 const struct dsdb_schema *schema,
1410 const struct dsdb_attribute *attr,
1411 const struct ldb_val *val)
1413 void *dst = NULL;
1414 size_t size;
1415 bool ok;
1417 if (attr->attributeID_id == 0xFFFFFFFF) {
1418 return WERR_FOOBAR;
1421 ok = convert_string_talloc_convenience(ldb,
1422 schema->iconv_convenience,
1423 CH_UNIX, CH_UTF16,
1424 val->data,
1425 val->length,
1426 (void **)&dst,
1427 &size, false);
1428 TALLOC_FREE(dst);
1429 if (!ok) {
1430 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1433 if (attr->rangeLower) {
1434 if ((size/2) < *attr->rangeLower) {
1435 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1439 if (attr->rangeUpper) {
1440 if ((size/2) > *attr->rangeUpper) {
1441 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1445 return WERR_OK;
1448 static WERROR dsdb_syntax_UNICODE_validate_ldb(struct ldb_context *ldb,
1449 const struct dsdb_schema *schema,
1450 const struct dsdb_attribute *attr,
1451 const struct ldb_message_element *in)
1453 WERROR status;
1454 unsigned int i;
1456 if (attr->attributeID_id == 0xFFFFFFFF) {
1457 return WERR_FOOBAR;
1460 for (i=0; i < in->num_values; i++) {
1461 if (in->values[i].length == 0) {
1462 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1465 status = dsdb_syntax_UNICODE_validate_one_val(ldb,
1466 schema,
1467 attr,
1468 &in->values[i]);
1469 if (!W_ERROR_IS_OK(status)) {
1470 return status;
1474 return WERR_OK;
1477 WERROR dsdb_syntax_one_DN_drsuapi_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
1478 const struct dsdb_syntax *syntax,
1479 struct smb_iconv_convenience *iconv_convenience,
1480 const DATA_BLOB *in, DATA_BLOB *out)
1482 struct drsuapi_DsReplicaObjectIdentifier3 id3;
1483 enum ndr_err_code ndr_err;
1484 DATA_BLOB guid_blob;
1485 struct ldb_dn *dn;
1486 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
1487 int ret;
1488 NTSTATUS status;
1490 if (!tmp_ctx) {
1491 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
1494 if (in == NULL) {
1495 talloc_free(tmp_ctx);
1496 return WERR_FOOBAR;
1499 if (in->length == 0) {
1500 talloc_free(tmp_ctx);
1501 return WERR_FOOBAR;
1505 /* windows sometimes sends an extra two pad bytes here */
1506 ndr_err = ndr_pull_struct_blob(in,
1507 tmp_ctx, iconv_convenience, &id3,
1508 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3);
1509 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1510 status = ndr_map_error2ntstatus(ndr_err);
1511 talloc_free(tmp_ctx);
1512 return ntstatus_to_werror(status);
1515 dn = ldb_dn_new(tmp_ctx, ldb, id3.dn);
1516 if (!dn) {
1517 talloc_free(tmp_ctx);
1518 /* If this fails, it must be out of memory, as it does not do much parsing */
1519 W_ERROR_HAVE_NO_MEMORY(dn);
1522 if (!GUID_all_zero(&id3.guid)) {
1523 status = GUID_to_ndr_blob(&id3.guid, tmp_ctx, &guid_blob);
1524 if (!NT_STATUS_IS_OK(status)) {
1525 talloc_free(tmp_ctx);
1526 return ntstatus_to_werror(status);
1529 ret = ldb_dn_set_extended_component(dn, "GUID", &guid_blob);
1530 if (ret != LDB_SUCCESS) {
1531 talloc_free(tmp_ctx);
1532 return WERR_FOOBAR;
1534 talloc_free(guid_blob.data);
1537 if (id3.__ndr_size_sid) {
1538 DATA_BLOB sid_blob;
1539 ndr_err = ndr_push_struct_blob(&sid_blob, tmp_ctx, iconv_convenience, &id3.sid,
1540 (ndr_push_flags_fn_t)ndr_push_dom_sid);
1541 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1542 status = ndr_map_error2ntstatus(ndr_err);
1543 talloc_free(tmp_ctx);
1544 return ntstatus_to_werror(status);
1547 ret = ldb_dn_set_extended_component(dn, "SID", &sid_blob);
1548 if (ret != LDB_SUCCESS) {
1549 talloc_free(tmp_ctx);
1550 return WERR_FOOBAR;
1554 *out = data_blob_string_const(ldb_dn_get_extended_linearized(mem_ctx, dn, 1));
1555 talloc_free(tmp_ctx);
1556 return WERR_OK;
1559 static WERROR dsdb_syntax_DN_drsuapi_to_ldb(struct ldb_context *ldb,
1560 const struct dsdb_schema *schema,
1561 const struct dsdb_attribute *attr,
1562 const struct drsuapi_DsReplicaAttribute *in,
1563 TALLOC_CTX *mem_ctx,
1564 struct ldb_message_element *out)
1566 unsigned int i;
1568 out->flags = 0;
1569 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
1570 W_ERROR_HAVE_NO_MEMORY(out->name);
1572 out->num_values = in->value_ctr.num_values;
1573 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
1574 W_ERROR_HAVE_NO_MEMORY(out->values);
1576 for (i=0; i < out->num_values; i++) {
1577 WERROR status = dsdb_syntax_one_DN_drsuapi_to_ldb(out->values, ldb, attr->syntax,
1578 schema->iconv_convenience,
1579 in->value_ctr.values[i].blob,
1580 &out->values[i]);
1581 if (!W_ERROR_IS_OK(status)) {
1582 return status;
1587 return WERR_OK;
1590 static WERROR dsdb_syntax_DN_ldb_to_drsuapi(struct ldb_context *ldb,
1591 const struct dsdb_schema *schema,
1592 const struct dsdb_attribute *attr,
1593 const struct ldb_message_element *in,
1594 TALLOC_CTX *mem_ctx,
1595 struct drsuapi_DsReplicaAttribute *out)
1597 unsigned int i;
1598 DATA_BLOB *blobs;
1600 if (attr->attributeID_id == 0xFFFFFFFF) {
1601 return WERR_FOOBAR;
1604 out->attid = attr->attributeID_id;
1605 out->value_ctr.num_values = in->num_values;
1606 out->value_ctr.values = talloc_array(mem_ctx,
1607 struct drsuapi_DsAttributeValue,
1608 in->num_values);
1609 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
1611 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
1612 W_ERROR_HAVE_NO_MEMORY(blobs);
1614 for (i=0; i < in->num_values; i++) {
1615 struct drsuapi_DsReplicaObjectIdentifier3 id3;
1616 enum ndr_err_code ndr_err;
1617 struct ldb_dn *dn;
1618 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
1619 NTSTATUS status;
1621 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
1623 out->value_ctr.values[i].blob = &blobs[i];
1625 dn = ldb_dn_from_ldb_val(tmp_ctx, ldb, &in->values[i]);
1627 W_ERROR_HAVE_NO_MEMORY(dn);
1629 ZERO_STRUCT(id3);
1631 status = dsdb_get_extended_dn_guid(dn, &id3.guid, "GUID");
1632 if (!NT_STATUS_IS_OK(status) &&
1633 !NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1634 talloc_free(tmp_ctx);
1635 return ntstatus_to_werror(status);
1638 status = dsdb_get_extended_dn_sid(dn, &id3.sid, "SID");
1639 if (!NT_STATUS_IS_OK(status) &&
1640 !NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1641 talloc_free(tmp_ctx);
1642 return ntstatus_to_werror(status);
1645 id3.dn = ldb_dn_get_linearized(dn);
1647 ndr_err = ndr_push_struct_blob(&blobs[i], blobs, schema->iconv_convenience, &id3, (ndr_push_flags_fn_t)ndr_push_drsuapi_DsReplicaObjectIdentifier3);
1648 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1649 status = ndr_map_error2ntstatus(ndr_err);
1650 talloc_free(tmp_ctx);
1651 return ntstatus_to_werror(status);
1653 talloc_free(tmp_ctx);
1656 return WERR_OK;
1659 static WERROR dsdb_syntax_DN_validate_one_val(struct ldb_context *ldb,
1660 const struct dsdb_schema *schema,
1661 const struct dsdb_attribute *attr,
1662 const struct ldb_val *val,
1663 TALLOC_CTX *mem_ctx,
1664 struct dsdb_dn **_dsdb_dn)
1666 static const char * const extended_list[] = { "GUID", "SID", NULL };
1667 enum ndr_err_code ndr_err;
1668 struct GUID guid;
1669 struct dom_sid sid;
1670 const DATA_BLOB *sid_blob;
1671 struct dsdb_dn *dsdb_dn;
1672 struct ldb_dn *dn;
1673 char *dn_str;
1674 struct ldb_dn *dn2;
1675 char *dn2_str;
1676 int num_components;
1677 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
1678 NTSTATUS status;
1680 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
1682 if (attr->attributeID_id == 0xFFFFFFFF) {
1683 return WERR_FOOBAR;
1686 dsdb_dn = dsdb_dn_parse(tmp_ctx, ldb, val,
1687 attr->syntax->ldap_oid);
1688 if (!dsdb_dn) {
1689 talloc_free(tmp_ctx);
1690 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1692 dn = dsdb_dn->dn;
1694 dn2 = ldb_dn_copy(tmp_ctx, dn);
1695 if (dn == NULL) {
1696 talloc_free(tmp_ctx);
1697 return WERR_NOMEM;
1700 num_components = ldb_dn_get_comp_num(dn);
1702 status = dsdb_get_extended_dn_guid(dn, &guid, "GUID");
1703 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1704 num_components++;
1705 } else if (!NT_STATUS_IS_OK(status)) {
1706 talloc_free(tmp_ctx);
1707 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1710 sid_blob = ldb_dn_get_extended_component(dn, "SID");
1711 if (sid_blob) {
1712 num_components++;
1713 ndr_err = ndr_pull_struct_blob_all(sid_blob,
1714 tmp_ctx,
1715 schema->iconv_convenience,
1716 &sid,
1717 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
1718 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1719 talloc_free(tmp_ctx);
1720 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1724 /* Do not allow links to the RootDSE */
1725 if (num_components == 0) {
1726 talloc_free(tmp_ctx);
1727 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1731 * We need to check that only "GUID" and "SID" are
1732 * specified as extended components, we do that
1733 * by comparing the dn's after removing all components
1734 * from one dn and only the allowed subset from the other
1735 * one.
1737 ldb_dn_extended_filter(dn, extended_list);
1739 dn_str = ldb_dn_get_extended_linearized(tmp_ctx, dn, 0);
1740 if (dn_str == NULL) {
1741 talloc_free(tmp_ctx);
1742 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1744 dn2_str = ldb_dn_get_extended_linearized(tmp_ctx, dn2, 0);
1745 if (dn2_str == NULL) {
1746 talloc_free(tmp_ctx);
1747 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1750 if (strcmp(dn_str, dn2_str) != 0) {
1751 talloc_free(tmp_ctx);
1752 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1755 *_dsdb_dn = talloc_move(mem_ctx, &dsdb_dn);
1756 talloc_free(tmp_ctx);
1757 return WERR_OK;
1760 static WERROR dsdb_syntax_DN_validate_ldb(struct ldb_context *ldb,
1761 const struct dsdb_schema *schema,
1762 const struct dsdb_attribute *attr,
1763 const struct ldb_message_element *in)
1765 unsigned int i;
1767 if (attr->attributeID_id == 0xFFFFFFFF) {
1768 return WERR_FOOBAR;
1771 for (i=0; i < in->num_values; i++) {
1772 WERROR status;
1773 struct dsdb_dn *dsdb_dn;
1774 TALLOC_CTX *tmp_ctx = talloc_new(ldb);
1775 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
1777 status = dsdb_syntax_DN_validate_one_val(ldb,
1778 schema,
1779 attr,
1780 &in->values[i],
1781 tmp_ctx, &dsdb_dn);
1782 if (!W_ERROR_IS_OK(status)) {
1783 talloc_free(tmp_ctx);
1784 return status;
1787 if (dsdb_dn->dn_format != DSDB_NORMAL_DN) {
1788 talloc_free(tmp_ctx);
1789 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
1792 talloc_free(tmp_ctx);
1795 return WERR_OK;
1798 static WERROR dsdb_syntax_DN_BINARY_drsuapi_to_ldb(struct ldb_context *ldb,
1799 const struct dsdb_schema *schema,
1800 const struct dsdb_attribute *attr,
1801 const struct drsuapi_DsReplicaAttribute *in,
1802 TALLOC_CTX *mem_ctx,
1803 struct ldb_message_element *out)
1805 unsigned int i;
1806 int ret;
1808 out->flags = 0;
1809 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
1810 W_ERROR_HAVE_NO_MEMORY(out->name);
1812 out->num_values = in->value_ctr.num_values;
1813 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
1814 W_ERROR_HAVE_NO_MEMORY(out->values);
1816 for (i=0; i < out->num_values; i++) {
1817 struct drsuapi_DsReplicaObjectIdentifier3Binary id3;
1818 enum ndr_err_code ndr_err;
1819 DATA_BLOB guid_blob;
1820 struct ldb_dn *dn;
1821 struct dsdb_dn *dsdb_dn;
1822 NTSTATUS status;
1823 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
1824 if (!tmp_ctx) {
1825 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
1828 if (in->value_ctr.values[i].blob == NULL) {
1829 talloc_free(tmp_ctx);
1830 return WERR_FOOBAR;
1833 if (in->value_ctr.values[i].blob->length == 0) {
1834 talloc_free(tmp_ctx);
1835 return WERR_FOOBAR;
1839 /* windows sometimes sends an extra two pad bytes here */
1840 ndr_err = ndr_pull_struct_blob(in->value_ctr.values[i].blob,
1841 tmp_ctx, schema->iconv_convenience, &id3,
1842 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3Binary);
1843 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1844 status = ndr_map_error2ntstatus(ndr_err);
1845 talloc_free(tmp_ctx);
1846 return ntstatus_to_werror(status);
1849 dn = ldb_dn_new(tmp_ctx, ldb, id3.dn);
1850 if (!dn) {
1851 talloc_free(tmp_ctx);
1852 /* If this fails, it must be out of memory, as it does not do much parsing */
1853 W_ERROR_HAVE_NO_MEMORY(dn);
1856 status = GUID_to_ndr_blob(&id3.guid, tmp_ctx, &guid_blob);
1857 if (!NT_STATUS_IS_OK(status)) {
1858 talloc_free(tmp_ctx);
1859 return ntstatus_to_werror(status);
1862 ret = ldb_dn_set_extended_component(dn, "GUID", &guid_blob);
1863 if (ret != LDB_SUCCESS) {
1864 talloc_free(tmp_ctx);
1865 return WERR_FOOBAR;
1868 talloc_free(guid_blob.data);
1870 if (id3.__ndr_size_sid) {
1871 DATA_BLOB sid_blob;
1872 ndr_err = ndr_push_struct_blob(&sid_blob, tmp_ctx, schema->iconv_convenience, &id3.sid,
1873 (ndr_push_flags_fn_t)ndr_push_dom_sid);
1874 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1875 status = ndr_map_error2ntstatus(ndr_err);
1876 talloc_free(tmp_ctx);
1877 return ntstatus_to_werror(status);
1880 ret = ldb_dn_set_extended_component(dn, "SID", &sid_blob);
1881 if (ret != LDB_SUCCESS) {
1882 talloc_free(tmp_ctx);
1883 return WERR_FOOBAR;
1887 /* set binary stuff */
1888 dsdb_dn = dsdb_dn_construct(tmp_ctx, dn, id3.binary, attr->syntax->ldap_oid);
1889 if (!dsdb_dn) {
1890 /* If this fails, it must be out of memory, we know the ldap_oid is valid */
1891 talloc_free(tmp_ctx);
1892 W_ERROR_HAVE_NO_MEMORY(dsdb_dn);
1894 out->values[i] = data_blob_string_const(dsdb_dn_get_extended_linearized(out->values, dsdb_dn, 1));
1895 talloc_free(tmp_ctx);
1898 return WERR_OK;
1901 static WERROR dsdb_syntax_DN_BINARY_ldb_to_drsuapi(struct ldb_context *ldb,
1902 const struct dsdb_schema *schema,
1903 const struct dsdb_attribute *attr,
1904 const struct ldb_message_element *in,
1905 TALLOC_CTX *mem_ctx,
1906 struct drsuapi_DsReplicaAttribute *out)
1908 unsigned int i;
1909 DATA_BLOB *blobs;
1911 if (attr->attributeID_id == 0xFFFFFFFF) {
1912 return WERR_FOOBAR;
1915 out->attid = attr->attributeID_id;
1916 out->value_ctr.num_values = in->num_values;
1917 out->value_ctr.values = talloc_array(mem_ctx,
1918 struct drsuapi_DsAttributeValue,
1919 in->num_values);
1920 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
1922 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
1923 W_ERROR_HAVE_NO_MEMORY(blobs);
1925 for (i=0; i < in->num_values; i++) {
1926 struct drsuapi_DsReplicaObjectIdentifier3Binary id3;
1927 enum ndr_err_code ndr_err;
1928 const DATA_BLOB *sid_blob;
1929 struct dsdb_dn *dsdb_dn;
1930 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
1931 NTSTATUS status;
1933 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
1935 out->value_ctr.values[i].blob = &blobs[i];
1937 dsdb_dn = dsdb_dn_parse(tmp_ctx, ldb, &in->values[i], attr->syntax->ldap_oid);
1939 if (!dsdb_dn) {
1940 talloc_free(tmp_ctx);
1941 return ntstatus_to_werror(NT_STATUS_INVALID_PARAMETER);
1944 ZERO_STRUCT(id3);
1946 status = dsdb_get_extended_dn_guid(dsdb_dn->dn, &id3.guid, "GUID");
1947 if (!NT_STATUS_IS_OK(status) &&
1948 !NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1949 talloc_free(tmp_ctx);
1950 return ntstatus_to_werror(status);
1953 sid_blob = ldb_dn_get_extended_component(dsdb_dn->dn, "SID");
1954 if (sid_blob) {
1956 ndr_err = ndr_pull_struct_blob_all(sid_blob,
1957 tmp_ctx, schema->iconv_convenience, &id3.sid,
1958 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
1959 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1960 status = ndr_map_error2ntstatus(ndr_err);
1961 talloc_free(tmp_ctx);
1962 return ntstatus_to_werror(status);
1966 id3.dn = ldb_dn_get_linearized(dsdb_dn->dn);
1968 /* get binary stuff */
1969 id3.binary = dsdb_dn->extra_part;
1971 ndr_err = ndr_push_struct_blob(&blobs[i], blobs, schema->iconv_convenience, &id3, (ndr_push_flags_fn_t)ndr_push_drsuapi_DsReplicaObjectIdentifier3Binary);
1972 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1973 status = ndr_map_error2ntstatus(ndr_err);
1974 talloc_free(tmp_ctx);
1975 return ntstatus_to_werror(status);
1977 talloc_free(tmp_ctx);
1980 return WERR_OK;
1983 static WERROR dsdb_syntax_DN_BINARY_validate_ldb(struct ldb_context *ldb,
1984 const struct dsdb_schema *schema,
1985 const struct dsdb_attribute *attr,
1986 const struct ldb_message_element *in)
1988 unsigned int i;
1990 if (attr->attributeID_id == 0xFFFFFFFF) {
1991 return WERR_FOOBAR;
1994 for (i=0; i < in->num_values; i++) {
1995 WERROR status;
1996 struct dsdb_dn *dsdb_dn;
1997 TALLOC_CTX *tmp_ctx = talloc_new(ldb);
1998 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
2000 status = dsdb_syntax_DN_validate_one_val(ldb,
2001 schema,
2002 attr,
2003 &in->values[i],
2004 tmp_ctx, &dsdb_dn);
2005 if (!W_ERROR_IS_OK(status)) {
2006 talloc_free(tmp_ctx);
2007 return status;
2010 if (dsdb_dn->dn_format != DSDB_BINARY_DN) {
2011 talloc_free(tmp_ctx);
2012 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
2015 status = dsdb_syntax_DATA_BLOB_validate_one_val(ldb,
2016 schema,
2017 attr,
2018 &dsdb_dn->extra_part);
2019 if (!W_ERROR_IS_OK(status)) {
2020 talloc_free(tmp_ctx);
2021 return status;
2024 talloc_free(tmp_ctx);
2027 return WERR_OK;
2030 static WERROR dsdb_syntax_DN_STRING_drsuapi_to_ldb(struct ldb_context *ldb,
2031 const struct dsdb_schema *schema,
2032 const struct dsdb_attribute *attr,
2033 const struct drsuapi_DsReplicaAttribute *in,
2034 TALLOC_CTX *mem_ctx,
2035 struct ldb_message_element *out)
2037 return dsdb_syntax_DN_BINARY_drsuapi_to_ldb(ldb,
2038 schema,
2039 attr,
2041 mem_ctx,
2042 out);
2045 static WERROR dsdb_syntax_DN_STRING_ldb_to_drsuapi(struct ldb_context *ldb,
2046 const struct dsdb_schema *schema,
2047 const struct dsdb_attribute *attr,
2048 const struct ldb_message_element *in,
2049 TALLOC_CTX *mem_ctx,
2050 struct drsuapi_DsReplicaAttribute *out)
2052 return dsdb_syntax_DN_BINARY_ldb_to_drsuapi(ldb,
2053 schema,
2054 attr,
2056 mem_ctx,
2057 out);
2060 static WERROR dsdb_syntax_DN_STRING_validate_ldb(struct ldb_context *ldb,
2061 const struct dsdb_schema *schema,
2062 const struct dsdb_attribute *attr,
2063 const struct ldb_message_element *in)
2065 unsigned int i;
2067 if (attr->attributeID_id == 0xFFFFFFFF) {
2068 return WERR_FOOBAR;
2071 for (i=0; i < in->num_values; i++) {
2072 WERROR status;
2073 struct dsdb_dn *dsdb_dn;
2074 TALLOC_CTX *tmp_ctx = talloc_new(ldb);
2075 W_ERROR_HAVE_NO_MEMORY(tmp_ctx);
2077 status = dsdb_syntax_DN_validate_one_val(ldb,
2078 schema,
2079 attr,
2080 &in->values[i],
2081 tmp_ctx, &dsdb_dn);
2082 if (!W_ERROR_IS_OK(status)) {
2083 talloc_free(tmp_ctx);
2084 return status;
2087 if (dsdb_dn->dn_format != DSDB_STRING_DN) {
2088 talloc_free(tmp_ctx);
2089 return WERR_DS_INVALID_ATTRIBUTE_SYNTAX;
2092 status = dsdb_syntax_UNICODE_validate_one_val(ldb,
2093 schema,
2094 attr,
2095 &dsdb_dn->extra_part);
2096 if (!W_ERROR_IS_OK(status)) {
2097 talloc_free(tmp_ctx);
2098 return status;
2101 talloc_free(tmp_ctx);
2104 return WERR_OK;
2107 static WERROR dsdb_syntax_PRESENTATION_ADDRESS_drsuapi_to_ldb(struct ldb_context *ldb,
2108 const struct dsdb_schema *schema,
2109 const struct dsdb_attribute *attr,
2110 const struct drsuapi_DsReplicaAttribute *in,
2111 TALLOC_CTX *mem_ctx,
2112 struct ldb_message_element *out)
2114 unsigned int i;
2116 out->flags = 0;
2117 out->name = talloc_strdup(mem_ctx, attr->lDAPDisplayName);
2118 W_ERROR_HAVE_NO_MEMORY(out->name);
2120 out->num_values = in->value_ctr.num_values;
2121 out->values = talloc_array(mem_ctx, struct ldb_val, out->num_values);
2122 W_ERROR_HAVE_NO_MEMORY(out->values);
2124 for (i=0; i < out->num_values; i++) {
2125 size_t len;
2126 char *str;
2128 if (in->value_ctr.values[i].blob == NULL) {
2129 return WERR_FOOBAR;
2132 if (in->value_ctr.values[i].blob->length < 4) {
2133 return WERR_FOOBAR;
2136 len = IVAL(in->value_ctr.values[i].blob->data, 0);
2138 if (len != in->value_ctr.values[i].blob->length) {
2139 return WERR_FOOBAR;
2142 if (!convert_string_talloc_convenience(out->values, schema->iconv_convenience, CH_UTF16, CH_UNIX,
2143 in->value_ctr.values[i].blob->data+4,
2144 in->value_ctr.values[i].blob->length-4,
2145 (void **)&str, NULL, false)) {
2146 return WERR_FOOBAR;
2149 out->values[i] = data_blob_string_const(str);
2152 return WERR_OK;
2155 static WERROR dsdb_syntax_PRESENTATION_ADDRESS_ldb_to_drsuapi(struct ldb_context *ldb,
2156 const struct dsdb_schema *schema,
2157 const struct dsdb_attribute *attr,
2158 const struct ldb_message_element *in,
2159 TALLOC_CTX *mem_ctx,
2160 struct drsuapi_DsReplicaAttribute *out)
2162 unsigned int i;
2163 DATA_BLOB *blobs;
2165 if (attr->attributeID_id == 0xFFFFFFFF) {
2166 return WERR_FOOBAR;
2169 out->attid = attr->attributeID_id;
2170 out->value_ctr.num_values = in->num_values;
2171 out->value_ctr.values = talloc_array(mem_ctx,
2172 struct drsuapi_DsAttributeValue,
2173 in->num_values);
2174 W_ERROR_HAVE_NO_MEMORY(out->value_ctr.values);
2176 blobs = talloc_array(mem_ctx, DATA_BLOB, in->num_values);
2177 W_ERROR_HAVE_NO_MEMORY(blobs);
2179 for (i=0; i < in->num_values; i++) {
2180 uint8_t *data;
2181 size_t ret;
2183 out->value_ctr.values[i].blob = &blobs[i];
2185 if (!convert_string_talloc_convenience(blobs, schema->iconv_convenience, CH_UNIX, CH_UTF16,
2186 in->values[i].data,
2187 in->values[i].length,
2188 (void **)&data, &ret, false)) {
2189 return WERR_FOOBAR;
2192 blobs[i] = data_blob_talloc(blobs, NULL, 4 + ret);
2193 W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
2195 SIVAL(blobs[i].data, 0, 4 + ret);
2197 if (ret > 0) {
2198 memcpy(blobs[i].data + 4, data, ret);
2199 talloc_free(data);
2203 return WERR_OK;
2206 static WERROR dsdb_syntax_PRESENTATION_ADDRESS_validate_ldb(struct ldb_context *ldb,
2207 const struct dsdb_schema *schema,
2208 const struct dsdb_attribute *attr,
2209 const struct ldb_message_element *in)
2211 return dsdb_syntax_UNICODE_validate_ldb(ldb,
2212 schema,
2213 attr,
2214 in);
2217 #define OMOBJECTCLASS(val) { .length = sizeof(val) - 1, .data = discard_const_p(uint8_t, val) }
2219 static const struct dsdb_syntax dsdb_syntaxes[] = {
2221 .name = "Boolean",
2222 .ldap_oid = LDB_SYNTAX_BOOLEAN,
2223 .oMSyntax = 1,
2224 .attributeSyntax_oid = "2.5.5.8",
2225 .drsuapi_to_ldb = dsdb_syntax_BOOL_drsuapi_to_ldb,
2226 .ldb_to_drsuapi = dsdb_syntax_BOOL_ldb_to_drsuapi,
2227 .validate_ldb = dsdb_syntax_BOOL_validate_ldb,
2228 .equality = "booleanMatch",
2229 .comment = "Boolean"
2231 .name = "Integer",
2232 .ldap_oid = LDB_SYNTAX_INTEGER,
2233 .oMSyntax = 2,
2234 .attributeSyntax_oid = "2.5.5.9",
2235 .drsuapi_to_ldb = dsdb_syntax_INT32_drsuapi_to_ldb,
2236 .ldb_to_drsuapi = dsdb_syntax_INT32_ldb_to_drsuapi,
2237 .validate_ldb = dsdb_syntax_INT32_validate_ldb,
2238 .equality = "integerMatch",
2239 .comment = "Integer",
2240 .ldb_syntax = LDB_SYNTAX_SAMBA_INT32
2242 .name = "String(Octet)",
2243 .ldap_oid = LDB_SYNTAX_OCTET_STRING,
2244 .oMSyntax = 4,
2245 .attributeSyntax_oid = "2.5.5.10",
2246 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2247 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2248 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2249 .equality = "octetStringMatch",
2250 .comment = "Octet String",
2252 .name = "String(Sid)",
2253 .ldap_oid = LDB_SYNTAX_OCTET_STRING,
2254 .oMSyntax = 4,
2255 .attributeSyntax_oid = "2.5.5.17",
2256 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2257 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2258 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2259 .equality = "octetStringMatch",
2260 .comment = "Octet String - Security Identifier (SID)",
2261 .ldb_syntax = LDB_SYNTAX_SAMBA_SID
2263 .name = "String(Object-Identifier)",
2264 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.38",
2265 .oMSyntax = 6,
2266 .attributeSyntax_oid = "2.5.5.2",
2267 .drsuapi_to_ldb = dsdb_syntax_OID_drsuapi_to_ldb,
2268 .ldb_to_drsuapi = dsdb_syntax_OID_ldb_to_drsuapi,
2269 .validate_ldb = dsdb_syntax_OID_validate_ldb,
2270 .equality = "caseIgnoreMatch", /* Would use "objectIdentifierMatch" but most are ldap attribute/class names */
2271 .comment = "OID String",
2272 .ldb_syntax = LDB_SYNTAX_DIRECTORY_STRING
2274 .name = "Enumeration",
2275 .ldap_oid = LDB_SYNTAX_INTEGER,
2276 .oMSyntax = 10,
2277 .attributeSyntax_oid = "2.5.5.9",
2278 .drsuapi_to_ldb = dsdb_syntax_INT32_drsuapi_to_ldb,
2279 .ldb_to_drsuapi = dsdb_syntax_INT32_ldb_to_drsuapi,
2280 .validate_ldb = dsdb_syntax_INT32_validate_ldb,
2281 .ldb_syntax = LDB_SYNTAX_SAMBA_INT32
2283 /* not used in w2k3 forest */
2284 .name = "String(Numeric)",
2285 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.36",
2286 .oMSyntax = 18,
2287 .attributeSyntax_oid = "2.5.5.6",
2288 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2289 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2290 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2291 .equality = "numericStringMatch",
2292 .substring = "numericStringSubstringsMatch",
2293 .comment = "Numeric String",
2294 .ldb_syntax = LDB_SYNTAX_DIRECTORY_STRING,
2296 .name = "String(Printable)",
2297 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.44",
2298 .oMSyntax = 19,
2299 .attributeSyntax_oid = "2.5.5.5",
2300 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2301 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2302 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2303 .ldb_syntax = LDB_SYNTAX_OCTET_STRING,
2305 .name = "String(Teletex)",
2306 .ldap_oid = "1.2.840.113556.1.4.905",
2307 .oMSyntax = 20,
2308 .attributeSyntax_oid = "2.5.5.4",
2309 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2310 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2311 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2312 .equality = "caseIgnoreMatch",
2313 .substring = "caseIgnoreSubstringsMatch",
2314 .comment = "Case Insensitive String",
2315 .ldb_syntax = LDB_SYNTAX_DIRECTORY_STRING,
2317 .name = "String(IA5)",
2318 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.26",
2319 .oMSyntax = 22,
2320 .attributeSyntax_oid = "2.5.5.5",
2321 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2322 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2323 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2324 .equality = "caseExactIA5Match",
2325 .comment = "Printable String",
2326 .ldb_syntax = LDB_SYNTAX_OCTET_STRING,
2328 .name = "String(UTC-Time)",
2329 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.53",
2330 .oMSyntax = 23,
2331 .attributeSyntax_oid = "2.5.5.11",
2332 .drsuapi_to_ldb = dsdb_syntax_NTTIME_UTC_drsuapi_to_ldb,
2333 .ldb_to_drsuapi = dsdb_syntax_NTTIME_UTC_ldb_to_drsuapi,
2334 .validate_ldb = dsdb_syntax_NTTIME_UTC_validate_ldb,
2335 .equality = "generalizedTimeMatch",
2336 .comment = "UTC Time",
2338 .name = "String(Generalized-Time)",
2339 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.24",
2340 .oMSyntax = 24,
2341 .attributeSyntax_oid = "2.5.5.11",
2342 .drsuapi_to_ldb = dsdb_syntax_NTTIME_drsuapi_to_ldb,
2343 .ldb_to_drsuapi = dsdb_syntax_NTTIME_ldb_to_drsuapi,
2344 .validate_ldb = dsdb_syntax_NTTIME_validate_ldb,
2345 .equality = "generalizedTimeMatch",
2346 .comment = "Generalized Time",
2347 .ldb_syntax = LDB_SYNTAX_UTC_TIME,
2349 /* not used in w2k3 schema */
2350 .name = "String(Case Sensitive)",
2351 .ldap_oid = "1.2.840.113556.1.4.1362",
2352 .oMSyntax = 27,
2353 .attributeSyntax_oid = "2.5.5.3",
2354 .drsuapi_to_ldb = dsdb_syntax_FOOBAR_drsuapi_to_ldb,
2355 .ldb_to_drsuapi = dsdb_syntax_FOOBAR_ldb_to_drsuapi,
2356 .validate_ldb = dsdb_syntax_FOOBAR_validate_ldb,
2358 .name = "String(Unicode)",
2359 .ldap_oid = LDB_SYNTAX_DIRECTORY_STRING,
2360 .oMSyntax = 64,
2361 .attributeSyntax_oid = "2.5.5.12",
2362 .drsuapi_to_ldb = dsdb_syntax_UNICODE_drsuapi_to_ldb,
2363 .ldb_to_drsuapi = dsdb_syntax_UNICODE_ldb_to_drsuapi,
2364 .validate_ldb = dsdb_syntax_UNICODE_validate_ldb,
2365 .equality = "caseIgnoreMatch",
2366 .substring = "caseIgnoreSubstringsMatch",
2367 .comment = "Directory String",
2369 .name = "Interval/LargeInteger",
2370 .ldap_oid = "1.2.840.113556.1.4.906",
2371 .oMSyntax = 65,
2372 .attributeSyntax_oid = "2.5.5.16",
2373 .drsuapi_to_ldb = dsdb_syntax_INT64_drsuapi_to_ldb,
2374 .ldb_to_drsuapi = dsdb_syntax_INT64_ldb_to_drsuapi,
2375 .validate_ldb = dsdb_syntax_INT64_validate_ldb,
2376 .equality = "integerMatch",
2377 .comment = "Large Integer",
2378 .ldb_syntax = LDB_SYNTAX_INTEGER,
2380 .name = "String(NT-Sec-Desc)",
2381 .ldap_oid = LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR,
2382 .oMSyntax = 66,
2383 .attributeSyntax_oid = "2.5.5.15",
2384 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2385 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2386 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2388 .name = "Object(DS-DN)",
2389 .ldap_oid = LDB_SYNTAX_DN,
2390 .oMSyntax = 127,
2391 .oMObjectClass = OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x4a"),
2392 .attributeSyntax_oid = "2.5.5.1",
2393 .drsuapi_to_ldb = dsdb_syntax_DN_drsuapi_to_ldb,
2394 .ldb_to_drsuapi = dsdb_syntax_DN_ldb_to_drsuapi,
2395 .validate_ldb = dsdb_syntax_DN_validate_ldb,
2396 .equality = "distinguishedNameMatch",
2397 .comment = "Object(DS-DN) == a DN",
2399 .name = "Object(DN-Binary)",
2400 .ldap_oid = DSDB_SYNTAX_BINARY_DN,
2401 .oMSyntax = 127,
2402 .oMObjectClass = OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x0b"),
2403 .attributeSyntax_oid = "2.5.5.7",
2404 .drsuapi_to_ldb = dsdb_syntax_DN_BINARY_drsuapi_to_ldb,
2405 .ldb_to_drsuapi = dsdb_syntax_DN_BINARY_ldb_to_drsuapi,
2406 .validate_ldb = dsdb_syntax_DN_BINARY_validate_ldb,
2407 .equality = "octetStringMatch",
2408 .comment = "OctetString: Binary+DN",
2410 /* not used in w2k3 schema, but used in Exchange schema*/
2411 .name = "Object(OR-Name)",
2412 .ldap_oid = DSDB_SYNTAX_OR_NAME,
2413 .oMSyntax = 127,
2414 .oMObjectClass = OMOBJECTCLASS("\x56\x06\x01\x02\x05\x0b\x1D"),
2415 .attributeSyntax_oid = "2.5.5.7",
2416 .drsuapi_to_ldb = dsdb_syntax_DN_BINARY_drsuapi_to_ldb,
2417 .ldb_to_drsuapi = dsdb_syntax_DN_BINARY_ldb_to_drsuapi,
2418 .validate_ldb = dsdb_syntax_DN_BINARY_validate_ldb,
2419 .equality = "caseIgnoreMatch",
2420 .ldb_syntax = LDB_SYNTAX_DN,
2423 * TODO: verify if DATA_BLOB is correct here...!
2425 * repsFrom and repsTo are the only attributes using
2426 * this attribute syntax, but they're not replicated...
2428 .name = "Object(Replica-Link)",
2429 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.40",
2430 .oMSyntax = 127,
2431 .oMObjectClass = OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x06"),
2432 .attributeSyntax_oid = "2.5.5.10",
2433 .drsuapi_to_ldb = dsdb_syntax_DATA_BLOB_drsuapi_to_ldb,
2434 .ldb_to_drsuapi = dsdb_syntax_DATA_BLOB_ldb_to_drsuapi,
2435 .validate_ldb = dsdb_syntax_DATA_BLOB_validate_ldb,
2437 .name = "Object(Presentation-Address)",
2438 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.43",
2439 .oMSyntax = 127,
2440 .oMObjectClass = OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x5c"),
2441 .attributeSyntax_oid = "2.5.5.13",
2442 .drsuapi_to_ldb = dsdb_syntax_PRESENTATION_ADDRESS_drsuapi_to_ldb,
2443 .ldb_to_drsuapi = dsdb_syntax_PRESENTATION_ADDRESS_ldb_to_drsuapi,
2444 .validate_ldb = dsdb_syntax_PRESENTATION_ADDRESS_validate_ldb,
2445 .comment = "Presentation Address",
2446 .ldb_syntax = LDB_SYNTAX_DIRECTORY_STRING,
2448 /* not used in w2k3 schema */
2449 .name = "Object(Access-Point)",
2450 .ldap_oid = "1.3.6.1.4.1.1466.115.121.1.2",
2451 .oMSyntax = 127,
2452 .oMObjectClass = OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x3e"),
2453 .attributeSyntax_oid = "2.5.5.14",
2454 .drsuapi_to_ldb = dsdb_syntax_FOOBAR_drsuapi_to_ldb,
2455 .ldb_to_drsuapi = dsdb_syntax_FOOBAR_ldb_to_drsuapi,
2456 .validate_ldb = dsdb_syntax_FOOBAR_validate_ldb,
2457 .ldb_syntax = LDB_SYNTAX_DIRECTORY_STRING,
2459 /* not used in w2k3 schema */
2460 .name = "Object(DN-String)",
2461 .ldap_oid = DSDB_SYNTAX_STRING_DN,
2462 .oMSyntax = 127,
2463 .oMObjectClass = OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x0c"),
2464 .attributeSyntax_oid = "2.5.5.14",
2465 .drsuapi_to_ldb = dsdb_syntax_DN_STRING_drsuapi_to_ldb,
2466 .ldb_to_drsuapi = dsdb_syntax_DN_STRING_ldb_to_drsuapi,
2467 .validate_ldb = dsdb_syntax_DN_STRING_validate_ldb,
2468 .equality = "octetStringMatch",
2469 .comment = "OctetString: String+DN",
2473 const struct dsdb_syntax *find_syntax_map_by_ad_oid(const char *ad_oid)
2475 unsigned int i;
2476 for (i=0; dsdb_syntaxes[i].ldap_oid; i++) {
2477 if (strcasecmp(ad_oid, dsdb_syntaxes[i].attributeSyntax_oid) == 0) {
2478 return &dsdb_syntaxes[i];
2481 return NULL;
2484 const struct dsdb_syntax *find_syntax_map_by_ad_syntax(int oMSyntax)
2486 unsigned int i;
2487 for (i=0; dsdb_syntaxes[i].ldap_oid; i++) {
2488 if (oMSyntax == dsdb_syntaxes[i].oMSyntax) {
2489 return &dsdb_syntaxes[i];
2492 return NULL;
2495 const struct dsdb_syntax *find_syntax_map_by_standard_oid(const char *standard_oid)
2497 unsigned int i;
2498 for (i=0; dsdb_syntaxes[i].ldap_oid; i++) {
2499 if (strcasecmp(standard_oid, dsdb_syntaxes[i].ldap_oid) == 0) {
2500 return &dsdb_syntaxes[i];
2503 return NULL;
2505 const struct dsdb_syntax *dsdb_syntax_for_attribute(const struct dsdb_attribute *attr)
2507 unsigned int i;
2509 for (i=0; i < ARRAY_SIZE(dsdb_syntaxes); i++) {
2510 if (attr->oMSyntax != dsdb_syntaxes[i].oMSyntax) continue;
2512 if (attr->oMObjectClass.length != dsdb_syntaxes[i].oMObjectClass.length) continue;
2514 if (attr->oMObjectClass.length) {
2515 int ret;
2516 ret = memcmp(attr->oMObjectClass.data,
2517 dsdb_syntaxes[i].oMObjectClass.data,
2518 attr->oMObjectClass.length);
2519 if (ret != 0) continue;
2522 if (strcmp(attr->attributeSyntax_oid, dsdb_syntaxes[i].attributeSyntax_oid) != 0) continue;
2524 return &dsdb_syntaxes[i];
2527 return NULL;
2530 WERROR dsdb_attribute_drsuapi_to_ldb(struct ldb_context *ldb,
2531 const struct dsdb_schema *schema,
2532 const struct drsuapi_DsReplicaAttribute *in,
2533 TALLOC_CTX *mem_ctx,
2534 struct ldb_message_element *out)
2536 const struct dsdb_attribute *sa;
2538 sa = dsdb_attribute_by_attributeID_id(schema, in->attid);
2539 if (!sa) {
2540 return WERR_FOOBAR;
2543 return sa->syntax->drsuapi_to_ldb(ldb, schema, sa, in, mem_ctx, out);
2546 WERROR dsdb_attribute_ldb_to_drsuapi(struct ldb_context *ldb,
2547 const struct dsdb_schema *schema,
2548 const struct ldb_message_element *in,
2549 TALLOC_CTX *mem_ctx,
2550 struct drsuapi_DsReplicaAttribute *out)
2552 const struct dsdb_attribute *sa;
2554 sa = dsdb_attribute_by_lDAPDisplayName(schema, in->name);
2555 if (!sa) {
2556 return WERR_FOOBAR;
2559 return sa->syntax->ldb_to_drsuapi(ldb, schema, sa, in, mem_ctx, out);
2562 WERROR dsdb_attribute_validate_ldb(struct ldb_context *ldb,
2563 const struct dsdb_schema *schema,
2564 const struct ldb_message_element *in)
2566 const struct dsdb_attribute *sa;
2568 sa = dsdb_attribute_by_lDAPDisplayName(schema, in->name);
2569 if (!sa) {
2570 return WERR_DS_ATTRIBUTE_TYPE_UNDEFINED;
2573 return sa->syntax->validate_ldb(ldb, schema, sa, in);