Changeset 740 for vendor/current/source4/utils/oLschema2ldif.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/utils/oLschema2ldif.c
r414 r740 36 36 #include "tools/cmdline.h" 37 37 #include "dsdb/samdb/samdb.h" 38 #include "../lib/crypto/sha256.h" 39 #include "../librpc/gen_ndr/ndr_misc.h" 40 #include "lib/cmdline/popt_common.h" 38 41 39 42 #define SCHEMA_UNKNOWN 0 … … 337 340 int n; 338 341 342 SHA256_CTX sha256_context; 343 uint8_t digest[SHA256_DIGEST_LENGTH]; 344 345 struct GUID guid; 346 347 bool isAttribute = false; 348 bool single_valued = false; 349 339 350 ctx = talloc_new(mem_ctx); 340 351 msg = ldb_msg_new(ctx); … … 352 363 c += 13; 353 364 MSG_ADD_STRING("objectClass", "attributeSchema"); 365 isAttribute = true; 354 366 break; 355 367 } … … 375 387 n = strcspn(c, " \t"); 376 388 s = talloc_strndup(msg, c, n); 377 MSG_ADD_STRING("attributeID", s); 389 if (isAttribute) { 390 MSG_ADD_STRING("attributeID", s); 391 } else { 392 MSG_ADD_STRING("governsID", s); 393 } 394 395 SHA256_Init(&sha256_context); 396 SHA256_Update(&sha256_context, (uint8_t*)s, strlen(s)); 397 SHA256_Final(digest, &sha256_context); 398 399 memcpy(&guid, digest, sizeof(struct GUID)); 400 401 if (dsdb_msg_add_guid(msg, &guid, "schemaIdGuid") != 0) { 402 goto failed; 403 } 404 378 405 c += n; 379 406 c = skip_spaces(c); … … 417 444 418 445 case SCHEMA_SINGLE_VALUE: 419 MSG_ADD_STRING("isSingleValued", "TRUE");446 single_valued = true; 420 447 break; 421 448 … … 434 461 case SCHEMA_SYNTAX: 435 462 { 436 const struct dsdb_syntax *map = 437 find_syntax_map_by_standard_oid(token->value); 463 char *syntax_oid; 464 const struct dsdb_syntax *map; 465 char *oMSyntax; 466 467 n = strcspn(token->value, "{"); 468 syntax_oid = talloc_strndup(ctx, token->value, n); 469 470 map = find_syntax_map_by_standard_oid(syntax_oid); 438 471 if (!map) { 439 472 break; 440 473 } 474 441 475 MSG_ADD_STRING("attributeSyntax", map->attributeSyntax_oid); 476 477 oMSyntax = talloc_asprintf(msg, "%d", map->oMSyntax); 478 MSG_ADD_STRING("oMSyntax", oMSyntax); 479 442 480 break; 443 481 } … … 449 487 fprintf(stderr, "Unknown Definition: %s\n", token->value); 450 488 } 489 } 490 491 if (isAttribute) { 492 MSG_ADD_STRING("isSingleValued", single_valued ? "TRUE" : "FALSE"); 493 } else { 494 MSG_ADD_STRING("defaultObjectCategory", ldb_dn_get_linearized(msg->dn)); 451 495 } 452 496 … … 541 585 } 542 586 587 static struct options { 588 const char *basedn; 589 const char *input; 590 const char *output; 591 } options; 592 593 static struct poptOption popt_options[] = { 594 POPT_AUTOHELP 595 { "basedn", 'b', POPT_ARG_STRING, &options.basedn, 0, "base DN", "DN" }, 596 { "input", 'I', POPT_ARG_STRING, &options.input, 0, 597 "inputfile of OpenLDAP style schema otherwise STDIN", "inputfile"}, 598 { "output", 'O', POPT_ARG_STRING, &options.output, 0, 599 "outputfile otherwise STDOUT", "outputfile"}, 600 POPT_COMMON_VERSION 601 { NULL } 602 }; 603 604 543 605 static void usage(void) 544 606 { 545 printf("Usage: oLschema2ldif -H NONE <options>\n"); 607 poptContext pc; 608 printf("Usage: oLschema2ldif <options>\n"); 546 609 printf("\nConvert OpenLDAP schema to AD-like LDIF format\n\n"); 547 printf("Options:\n");548 printf(" -I inputfile inputfile of OpenLDAP style schema otherwise STDIN\n");549 printf(" -O outputfile outputfile otherwise STDOUT\n");550 printf(" -o options pass options like modules to activate\n");551 printf(" e.g: -o modules:timestamps\n");552 printf("\n");553 610 printf("Converts records from an openLdap formatted schema to an ldif schema\n\n"); 611 pc = poptGetContext("oLschema2ldif", 0, NULL, popt_options, 612 POPT_CONTEXT_KEEP_FIRST); 613 poptPrintHelp(pc, stdout, 0); 554 614 exit(1); 555 615 } 616 556 617 557 618 int main(int argc, const char **argv) … … 559 620 TALLOC_CTX *ctx; 560 621 struct schema_conv ret; 561 struct ldb_cmdline *options;562 622 FILE *in = stdin; 563 623 FILE *out = stdout; 624 poptContext pc; 625 int opt; 626 564 627 ctx = talloc_new(NULL); 565 628 ldb_ctx = ldb_init(ctx, NULL); 566 629 567 630 setenv("LDB_URL", "NONE", 1); 568 options = ldb_cmdline_process(ldb_ctx, argc, argv, usage); 569 570 if (options->basedn == NULL) { 571 perror("Base DN not specified"); 631 632 pc = poptGetContext(argv[0], argc, argv, popt_options, 633 POPT_CONTEXT_KEEP_FIRST); 634 635 while((opt = poptGetNextOpt(pc)) != -1) { 636 fprintf(stderr, "Invalid option %s: %s\n", 637 poptBadOption(pc, 0), poptStrerror(opt)); 638 usage(); 639 } 640 641 if (options.basedn == NULL) { 642 printf("Base DN not specified\n"); 643 usage(); 572 644 exit(1); 573 645 } else { 574 basedn = ldb_dn_new(ctx, ldb_ctx, options ->basedn);646 basedn = ldb_dn_new(ctx, ldb_ctx, options.basedn); 575 647 if ( ! ldb_dn_validate(basedn)) { 576 perror("Malformed Base DN"); 648 printf("Malformed Base DN\n"); 649 usage(); 577 650 exit(1); 578 651 } 579 652 } 580 653 581 if (options ->input) {582 in = fopen(options ->input, "r");654 if (options.input) { 655 in = fopen(options.input, "r"); 583 656 if (!in) { 584 perror(options->input); 657 perror(options.input); 658 usage(); 585 659 exit(1); 586 660 } 587 661 } 588 if (options ->output) {589 out = fopen(options ->output, "w");662 if (options.output) { 663 out = fopen(options.output, "w"); 590 664 if (!out) { 591 perror(options->output); 665 perror(options.output); 666 usage(); 592 667 exit(1); 593 668 }
Note:
See TracChangeset
for help on using the changeset viewer.