aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/ldapschema.c
blob: 16dae899b92051fda9a73c31b74c2297a89a9849 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
/*
 *  LDAP Utilities
 *  Copyright (C) 2019 David M. Syzdek <david@syzdek.net>.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are
 *  met:
 *
 *     1. Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *
 *     2. Redistributions in binary form must reproduce the above copyright
 *        notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 *
 *     3. Neither the name of the copyright holder nor the names of its
 *        contributors may be used to endorse or promote products derived from
 *        this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 *  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
 *  @file src/ldapschema.c display LDAP schema
 */
/*
 *  Simple Build:
 *     export CFLAGS='-DPROGRAM_NAME="ldapschema" -Wall -I../include'
 *     gcc ${CFLAGS} -c ldapschema.c
 *     gcc ${CFLAGS} -lldap -o ldapschema ldapschema.o
 *
 *  Libtool Build:
 *     export CFLAGS='-DPROGRAM_NAME="ldapschema" -Wall -I../include'
 *     libtool --mode=compile --tag=CC gcc ${CFLAGS} -c ldapschema.c
 *     libtool --mode=link    --tag=CC gcc ${CFLAGS} -lldap -o ldapschema \
 *             ldapschema.lo
 *
 *  Libtool Clean:
 *     libtool --mode=clean rm -f ldapschema.lo ldapschema
 */
#define _LDAP_UTILS_SRC_LDAPSCHEMA 1


///////////////
//           //
//  Headers  //
//           //
///////////////
#ifdef __LDAPUTILS_PMARK
#pragma mark - Headers
#endif

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <getopt.h>
#include <assert.h>

#define LDAP_DEPRECATED 1
#include <ldap.h>
#include <ldaputils.h>
#include <ldapschema.h>


///////////////////
//               //
//  Definitions  //
//               //
///////////////////
#ifdef __LDAPUTILS_PMARK
#pragma mark - Definitions
#endif

#ifndef PROGRAM_NAME
#define PROGRAM_NAME "ldaptree"
#endif

#define MY_SHORT_OPTIONS LDAPUTILS_OPTIONS_COMMON LDAPUTILS_OPTIONS_SEARCH "87:6:5:4:3"

#define MY_EXIT_SCHEMAERR     2
#define MY_EXIT_NOT_FOUND     3

#define MY_OBJ_ATTR          0x01
#define MY_OBJ_SYNTAX        0x02
#define MY_OBJ_MATCHING      0x04
#define MY_OBJ_OBJCLS        0x08

#define MY_ACTION_LIST       1
#define MY_ACTION_LINT       2
#define MY_ACTION_DUMP       3


/////////////////
//             //
//  Datatypes  //
//             //
/////////////////
#ifdef __LDAPUTILS_PMARK
#pragma mark - Datatypes
#endif

/* configuration union */
typedef struct my_config MyConfig;
struct my_config
{
   LDAPUtils          * lud;
   LDAPSchema         * lsd;
   int                  noextra;
   int                  action;
   uint64_t             types;
   char               ** args;
};


/////////////////
//             //
//  Variables  //
//             //
/////////////////

static struct
{
   const char *   type;
   uint64_t       flag;
   const char *   desc;
} my_obj_types[] =
{
   { "attributeTypes",  MY_OBJ_ATTR,     NULL },
   { "ldapSyntaxes",    MY_OBJ_SYNTAX,   NULL },
   { "matchingRules",   MY_OBJ_MATCHING, NULL },
   { "objectClasses",   MY_OBJ_OBJCLS,   NULL},
   { NULL, 0, NULL },
};


//////////////////
//              //
//  Prototypes  //
//              //
//////////////////
#ifdef __LDAPUTILS_PMARK
#pragma mark - Prototypes
#endif

// main statement
int main(int argc, char * argv[]);

// parses configuration
int my_config(int argc, char * argv[], MyConfig ** cnfp);

int my_list_add(LDAPSchemaModel *** listp, size_t * lenp, LDAPSchemaModel * mod);
int my_run_details(MyConfig * cnf);
int my_run_dump(MyConfig * cnf);
int my_run_lint(MyConfig * cnf);
int my_run_list(MyConfig * cnf);

// fress resources
void my_unbind(MyConfig * cnf);


/////////////////
//             //
//  Functions  //
//             //
/////////////////
#ifdef __LDAPUTILS_PMARK
#pragma mark - Functions
#endif

/// prints program usage and exits
void ldaputils_usage(void)
{
   size_t idx;

   printf("Usage: %s [options] oid [oid ...]\n", PROGRAM_NAME);
   printf("       %s [options] --lint\n", PROGRAM_NAME);
   printf("       %s [options] --list\n", PROGRAM_NAME);
   printf("       %s [options] --dump\n", PROGRAM_NAME);
   ldaputils_usage_common(MY_SHORT_OPTIONS);
   printf("Schema options:\n");
   printf("  --dump                    list details of objects in schema\n");
   printf("  --lint                    display schema errors\n");
   printf("  --list                    list objects in schema\n");
   printf("  --noextra                 do not include related objects or data\n");
   printf("  --type=type               restrict operations to specific object types\n");
   printf("Object types\n");
   for(idx = 0; ((my_obj_types[idx].type)); idx++)
   {
      if ((my_obj_types[idx].desc))
         printf("  %-25s %s\n", my_obj_types[idx].type, my_obj_types[idx].desc);
      else
         printf("  %s\n", my_obj_types[idx].type);
   }
   printf("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
   return;
}


/// main statement
/// @param[in] argc   number of arguments
/// @param[in] argv   array of arguments
int main(int argc, char * argv[])
{
   int                    err;
   MyConfig             * cnf;

   cnf = NULL;

   // initializes resources and parses CLI arguments
   if ((err = my_config(argc, argv, &cnf)) != 0)
      return(1);
   if (!(cnf))
      return(0);

   // starts TLS and binds to LDAP
   if ((err = ldaputils_bind_s(cnf->lud)) != LDAP_SUCCESS)
   {
      fprintf(stderr, "%s: ldap_sasl_bind_s(): %s\n", cnf->lud->prog_name, ldap_err2string(err));
      my_unbind(cnf);
      return(1);
   };

   // fetches schema
   if ( ((err = ldapschema_fetch(cnf->lsd, cnf->lud->ld)) != LDAP_SUCCESS) && (err != LDAPSCHEMA_SCHEMA_ERROR) )
   {
      fprintf(stderr, "%s: ldapschema_fetch(): %s\n", cnf->lud->prog_name, ldapschema_err2string(err));
      my_unbind(cnf);
      return(1);
   };

   // act as schema lint and exit
   switch(cnf->action)
   {
      case MY_ACTION_DUMP: err = my_run_dump(cnf);    break;
      case MY_ACTION_LINT: err = my_run_lint(cnf);    break;
      case MY_ACTION_LIST: err = my_run_list(cnf);    break;
      default:             err = my_run_details(cnf); break;
   };

   // frees resources
   my_unbind(cnf);

   return(err);
}


/// parses configuration
/// @param[in] argc   number of arguments
/// @param[in] argv   array of arguments
/// @param[in] cnfp   reference to configuration pointer
int my_config(int argc, char * argv[], MyConfig ** cnfp)
{
   int            c;
   int            err;
   int            option_index;
   MyConfig     * cnf;
   uint64_t       flag;
   int            i;
   size_t         idx;
   size_t         len;

   static char   short_options[] = MY_SHORT_OPTIONS "98:76";
   static struct option long_options[] =
   {
      {"schemalint",    no_argument,       0, '9'},
      {"lint",          no_argument,       0, '9'},
      {"type",          required_argument, 0, '8'},
      {"list",          no_argument,       0, '7'},
      {"dump",          no_argument,       0, '6'},
      {"noextra",       no_argument,       0, '5'},
      {"help",          no_argument,       0, 'h'},
      {"verbose",       no_argument,       0, 'v'},
      {"version",       no_argument,       0, 'V'},
      {NULL,            0,                 0, 0  }
   };

   // allocates memory for configuration
   if (!(cnf = (MyConfig *) malloc(sizeof(MyConfig))))
   {
      fprintf(stderr, "%s: out of virtual memory\n", PROGRAM_NAME);
      return(1);
   };
   memset(cnf, 0, sizeof(MyConfig));

   // initialize ldap utilities
   if ((err = ldaputils_initialize(&cnf->lud, PROGRAM_NAME)) != LDAP_SUCCESS)
   {
      fprintf(stderr, "%s: ldaputils_initialize(): %s\n", PROGRAM_NAME, ldap_err2string(err));
      my_unbind(cnf);
      return(1);
   };

   // initialize ldap schema
   if ((err = ldapschema_initialize(&cnf->lsd)) != LDAP_SUCCESS)
   {
      fprintf(stderr, "%s: ldapschema_initialize(): %s\n", PROGRAM_NAME, ldapschema_err2string(err));
      my_unbind(cnf);
      return(1);
   };

   // loops through args
   option_index = 0;
   while((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1)
   {
      switch(ldaputils_getopt(cnf->lud, c, optarg))
      {
         // shared option exit without error
         case -2:
         my_unbind(cnf);
         return(0);

         // no more arguments
         case -1:
         break;

         // long options toggles
         case 0:
         break;

         // shared option error
         case 1:
         my_unbind(cnf);
         return(1);

         // --schemalint option
         case '9':
         if ((cnf->action))
         {
            fprintf(stderr, "%s: incompatible options `--schemalint', `--dump', and `--list'\n", PROGRAM_NAME);
            fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
            my_unbind(cnf);
            return(1);
         };
         cnf->action = MY_ACTION_LINT;
         break;

         // --type=type
         case '8':
         flag = 0;
         for(idx = 0; ((my_obj_types[idx].type)); idx++)
         {
            if ((strncasecmp(optarg, my_obj_types[idx].type, strlen(optarg))))
               continue;
            if ((flag))
            {
               fprintf(stderr, "%s: ambiguous type -- \"%s\"\n", PROGRAM_NAME, optarg);
               fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
               my_unbind(cnf);
               return(1);
            };
            flag = my_obj_types[idx].flag;
         };
         if (!(flag))
         {
            fprintf(stderr, "%s: unknown type -- \"%s\"\n", PROGRAM_NAME, optarg);
            fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
            my_unbind(cnf);
            return(1);
         };
         cnf->types |= flag;
         break;

         // --list
         case '7':
         if ((cnf->action))
         {
            fprintf(stderr, "%s: incompatible options `--schemalint', `--dump', and `--list'\n", PROGRAM_NAME);
            fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
            my_unbind(cnf);
            return(1);
         };
         cnf->action = MY_ACTION_LIST;
         break;

         // --dump option
         case '6':
         if ((cnf->action))
         {
            fprintf(stderr, "%s: incompatible options `--schemalint', `--dump', and `--list'\n", PROGRAM_NAME);
            fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
            my_unbind(cnf);
            return(1);
         };
         cnf->action = MY_ACTION_DUMP;
         break;

         // --noextra option
         case '5':
         cnf->noextra++;
         break;

         // argument error
         case '?':
         fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
         my_unbind(cnf);
         return(1);

         // unknown argument error
         default:
         fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c);
         fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
         my_unbind(cnf);
         return(1);
      };
   };

   if ( (argc < (optind+1)) && (!(cnf->action)) )
   {
      fprintf(stderr, "%s: missing required options or arguments\n", PROGRAM_NAME);
      fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
      my_unbind(cnf);
      return(1);
   };
   if ( (argc > optind) && ((cnf->action)) )
   {
      fprintf(stderr, "%s: incompatible arguments `--list', `--dump', `--lint', and `%s'\n", PROGRAM_NAME, argv[optind]);
      fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
      my_unbind(cnf);
      return(1);
   };

   if (!(cnf->types))
      cnf->types = 0xffffffff;

   // copies arguments
   if (argc > optind)
   {
      len = (size_t)(argc-optind);
      if ((cnf->args = malloc(sizeof(char *)*(size_t)(len+2))) == NULL)
         return(1);
      bzero(cnf->args, (sizeof(char*)*(len+2)));

      for(i = 0; (argc > (optind+i)); i++)
         cnf->args[i] = argv[optind+i];
      cnf->args[i] = NULL;
   };

   // reads password
   if ((err = ldaputils_pass(cnf->lud)) != 0)
   {
      my_unbind(cnf);
      return(1);
   };

   *cnfp = cnf;

   return(0);
}


int my_list_add(LDAPSchemaModel *** listp, size_t * lenp, LDAPSchemaModel * mod)
{
   void *               ptr;
   size_t               idx;

   if (!(mod))
      return(0);

   for(idx = 0; (idx < (*lenp)); idx++)
      if (!(ldapschema_compar_models(&mod, &listp[0][idx])))
         return(0);

   if ((ptr = realloc(*listp, (sizeof(LDAPSchemaModel *)*(*lenp +2)))) == NULL)
   {
      fprintf(stderr, "%s: out of virtual memory\n", PROGRAM_NAME);
      return(1);
   };
   *listp            = ptr;
   listp[0][*lenp]   = mod;
   (*lenp)++;
   listp[0][*lenp]   = NULL;

   return(0);
}


int my_run_details(MyConfig * cnf)
{
   size_t                     idx;
   size_t                     list_len;
   LDAPSchemaModel         ** list;
   LDAPSchemaSyntax         * syntax;
   LDAPSchemaAttributeType  * attr;
   LDAPSchemaAttributeType  * attrsup;
   LDAPSchemaObjectclass    * objcls;
   LDAPSchemaObjectclass    * objclssup;
   LDAPSchemaMatchingRule   * mtchngrl;

   list     = NULL;
   list_len = 0;

   // look for matching ldapSyntax
   for(idx = 0; ((cnf->args[idx])); idx++)
      if ((syntax = ldapschema_find_ldapsyntax(cnf->lsd, cnf->args[idx])) != NULL)
         my_list_add(&list, &list_len, (LDAPSchemaModel *)syntax);

   // look for matching matchingRules and add ldapSyntax
   for(idx = 0; ((cnf->args[idx])); idx++)
   {
      if ((mtchngrl = ldapschema_find_matchingrule(cnf->lsd, cnf->args[idx])) == NULL)
         continue;
      ldapschema_get_info_matchingrule(cnf->lsd, mtchngrl, LDAPSCHEMA_FLD_SYNTAX, &syntax);
      my_list_add(&list, &list_len, (LDAPSchemaModel *)syntax);
   };

   // look for matching attributeType and add syntaxes
   for(idx = 0; (((cnf->args[idx])) && (!(cnf->noextra))); idx++)
   {
      if ((attr = ldapschema_find_attributetype(cnf->lsd, cnf->args[idx])) == NULL)
         continue;
      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SYNTAX,   &syntax);
      my_list_add(&list, &list_len, (LDAPSchemaModel *)syntax);
      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SUPERIOR, &attrsup);
      while ((attrsup))
      {
         attr = attrsup;
         ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SYNTAX,   &syntax);
         my_list_add(&list, &list_len, (LDAPSchemaModel *)syntax);
         ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SUPERIOR, &attrsup);
      };
   };

   // look for matching attributeType and add matchingRules
   for(idx = 0; (((cnf->args[idx])) && (!(cnf->noextra))); idx++)
   {
      if ((attr = ldapschema_find_attributetype(cnf->lsd, cnf->args[idx])) == NULL)
         continue;

      // add syntaxes
      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_EQUALITY,   &mtchngrl);
      if ((mtchngrl))
      {
         ldapschema_get_info_matchingrule(cnf->lsd, mtchngrl, LDAPSCHEMA_FLD_SYNTAX, &syntax);
         my_list_add(&list, &list_len, (LDAPSchemaModel *)syntax);
      };

      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_ORDERING,   &mtchngrl);
      if ((mtchngrl))
      {
         ldapschema_get_info_matchingrule(cnf->lsd, mtchngrl, LDAPSCHEMA_FLD_SYNTAX, &syntax);
         my_list_add(&list, &list_len, (LDAPSchemaModel *)syntax);
      };

      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SUBSTR,   &mtchngrl);
      if ((mtchngrl))
      {
         ldapschema_get_info_matchingrule(cnf->lsd, mtchngrl, LDAPSCHEMA_FLD_SYNTAX, &syntax);
         my_list_add(&list, &list_len, (LDAPSchemaModel *)syntax);
      };

      // add matching rules
      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_EQUALITY,   &mtchngrl);
      my_list_add(&list, &list_len, (LDAPSchemaModel *)mtchngrl);

      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_ORDERING,   &mtchngrl);
      my_list_add(&list, &list_len, (LDAPSchemaModel *)mtchngrl);

      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SUBSTR,   &mtchngrl);
      my_list_add(&list, &list_len, (LDAPSchemaModel *)mtchngrl);
   };

   // look for matching matchingRule
   for(idx = 0; ((cnf->args[idx])); idx++)
      if ((mtchngrl = ldapschema_find_matchingrule(cnf->lsd, cnf->args[idx])) != NULL)
         my_list_add(&list, &list_len, (LDAPSchemaModel *)mtchngrl);

   // look for matching attributeType and add attributes
   for(idx = 0; (((cnf->args[idx])) && (!(cnf->noextra))); idx++)
   {
      if ((attr = ldapschema_find_attributetype(cnf->lsd, cnf->args[idx])) == NULL)
         continue;
      ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SUPERIOR, &attrsup);
      while ((attrsup))
      {
         attr = attrsup;
         my_list_add(&list, &list_len, (LDAPSchemaModel *)attr);
         ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SUPERIOR, &attrsup);
      };
   };
   for(idx = 0; ((cnf->args[idx])); idx++)
      if ((attr = ldapschema_find_attributetype(cnf->lsd, cnf->args[idx])) != NULL)
         my_list_add(&list, &list_len, (LDAPSchemaModel *)attr);

   // look for matching objectclasses
   for(idx = 0; (((cnf->args[idx])) && (!(cnf->noextra))); idx++)
   {
      if ((objcls = ldapschema_find_objectclass(cnf->lsd, cnf->args[idx])) == NULL)
         continue;
      ldapschema_get_info_objectclass(cnf->lsd, objcls, LDAPSCHEMA_FLD_SUPERIOR, &objclssup);
      while ((objclssup))
      {
         objcls = objclssup;
         my_list_add(&list, &list_len, (LDAPSchemaModel *)objcls);
         ldapschema_get_info_objectclass(cnf->lsd, objcls, LDAPSCHEMA_FLD_SUPERIOR, &objclssup);
      };
   };
   for(idx = 0; ((cnf->args[idx])); idx++)
      if ((objcls = ldapschema_find_objectclass(cnf->lsd, cnf->args[idx])) != NULL)
         my_list_add(&list, &list_len, (LDAPSchemaModel *)objcls);

   // print results
   for(idx = 0; (idx < list_len); idx++)
   {
      ldapschema_print(cnf->lsd, list[idx]);
      printf("\n\n");
   };

   free(list);

   return(0);
}


int my_run_dump(MyConfig * cnf)
{
   if ((cnf->types & MY_OBJ_SYNTAX) != 0)
      ldapschema_printall(cnf->lsd, LDAPSCHEMA_SYNTAX);

   if ((cnf->types & MY_OBJ_MATCHING) != 0)
      ldapschema_printall(cnf->lsd, LDAPSCHEMA_MATCHINGRULE);

   if ((cnf->types & MY_OBJ_ATTR) != 0)
      ldapschema_printall(cnf->lsd, LDAPSCHEMA_ATTRIBUTETYPE);

   if ((cnf->types & MY_OBJ_OBJCLS) != 0)
      ldapschema_printall(cnf->lsd, LDAPSCHEMA_OBJECTCLASS);

   return(0);
}



int my_run_lint(MyConfig * cnf)
{
   int         err;
   char     ** errs;
   size_t      pos;

   if ((err = ldapschema_errno(cnf->lsd)) == LDAPSCHEMA_SUCCESS)
   {
      printf("no schema errors detected\n");
      return(0);
   };

   if ((errs = ldapschema_schema_errors(cnf->lsd)) == NULL)
   {
      printf("unknown schema error detected\n");
      return(MY_EXIT_SCHEMAERR);
   };

   for(pos = 0; ((errs[pos])); pos++)
      printf("%s\n", errs[pos]);
   ldapschema_value_free(errs);

   printf("%zu issues reported\n", pos);

   return(MY_EXIT_SCHEMAERR);
}


int my_run_list(MyConfig * cnf)
{
   size_t                              idx;
   LDAPSchemaCur                       cur;
   const LDAPSchemaAttributeType *     attr;
   const LDAPSchemaObjectclass *       objcls;
   const LDAPSchemaSyntax *            syntax;
   const LDAPSchemaMatchingRule *      rule;
   char *                              oid;
   char *                              desc;
   char **                             names;
   char                                buff[256];
   size_t                              len;

   if ((cnf->types & MY_OBJ_SYNTAX) != 0)
   {
      cur = NULL;
      syntax = ldapschema_first_ldapsyntax(cnf->lsd, &cur);
      while ((syntax))
      {
         ldapschema_get_info_ldapsyntax(cnf->lsd, syntax, LDAPSCHEMA_FLD_OID,  &oid);
         ldapschema_get_info_ldapsyntax(cnf->lsd, syntax, LDAPSCHEMA_FLD_DESC, &desc);
         if ((desc))
         {
            printf("%-15s %-35s DESC ( %s )\n", "ldapsyntax:", oid, desc);
            ldapschema_memfree(desc);
         } else
         {
            printf("%-15s %s\n", "ldapsyntax:", oid);
         };
         ldapschema_memfree(oid);
         syntax = ldapschema_next_ldapsyntax(cnf->lsd, cur);
      };
      ldapschema_curfree(cur);
   };

   if ((cnf->types & MY_OBJ_MATCHING) != 0)
   {
      cur = NULL;
      rule = ldapschema_first_matchingrule(cnf->lsd, &cur);
      while ((rule))
      {
         ldapschema_get_info_matchingrule(cnf->lsd, rule, LDAPSCHEMA_FLD_OID,  &oid);
         ldapschema_get_info_matchingrule(cnf->lsd, rule, LDAPSCHEMA_FLD_NAME, &names);
         if ((names))
         {
            printf("%-15s %-35s NAME ( %s", "matchingRule:", oid, names[0]);
            for(idx = 1; ((names[idx])); idx++)
               printf(" $ %s", names[idx]);
            printf(" )\n");
            ldapschema_value_free(names);
         } else
         {
            printf("%-15s %-35s", "matchingRule:", oid);
         };
         ldapschema_memfree(oid);
         rule = ldapschema_next_matchingrule(cnf->lsd, cur);
      };
      ldapschema_curfree(cur);
   };

   if ((cnf->types & MY_OBJ_ATTR) != 0)
   {
      cur = NULL;
      attr = ldapschema_first_attributetype(cnf->lsd, &cur);
      while ((attr))
      {
         ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_OID,  &oid);
         ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_NAME, &names);
         ldapschema_get_info_attributetype(cnf->lsd, attr, LDAPSCHEMA_FLD_SYNTAX, &syntax);
         buff[0] = '\0';
         if ((names))
         {
            snprintf(buff, sizeof(buff), "( %s", names[0]);
            for(idx = 1; ((names[idx])); idx++)
            {
               len = strlen(buff);
               snprintf(&buff[len], (sizeof(buff)-len-2), " $ %s", names[idx]);
            };
            len = strlen(buff);
            snprintf(&buff[len], (sizeof(buff)-len-2), " )");
            ldapschema_memfree(names);
         };
         if ( ((syntax)) && (!(cnf->noextra)) )
            printf("%-15s %-35s NAME %-30s", "attributeType:", oid, buff);
         else
            printf("%-15s %-35s NAME %s", "attributeType:", oid, buff);
         ldapschema_memfree(oid);
         if ( ((syntax)) && (!(cnf->noextra)) )
         {
            ldapschema_get_info_ldapsyntax(cnf->lsd, syntax, LDAPSCHEMA_FLD_DESC, &desc);
            printf("   [ %s ]", desc);
            ldapschema_memfree(desc);
         };
         printf("\n");
         attr = ldapschema_next_attributetype(cnf->lsd, cur);
      };
      ldapschema_curfree(cur);
   };

   if ((cnf->types & MY_OBJ_OBJCLS) != 0)
   {
      cur = NULL;
      objcls = ldapschema_first_objectclass(cnf->lsd, &cur);
      while ((objcls))
      {
         ldapschema_get_info_objectclass(cnf->lsd, objcls, LDAPSCHEMA_FLD_OID,  &oid);
         ldapschema_get_info_objectclass(cnf->lsd, objcls, LDAPSCHEMA_FLD_NAME, &names);
         if ((names))
         {
            printf("%-15s %-35s NAME ( %s", "objectClass:", oid, names[0]);
            for(idx = 1; ((names[idx])); idx++)
               printf(" $ %s", names[idx]);
            printf(" )\n");
            ldapschema_memfree(names);
         } else
         {
            printf("%-15s %-35s", "objectClass:", oid);
         };
         ldapschema_memfree(oid);
         objcls = ldapschema_next_objectclass(cnf->lsd, cur);
      };
      ldapschema_curfree(cur);
   };

   return(0);
}


// fress resources
void my_unbind(MyConfig * cnf)
{
   assert(cnf != NULL);

   if ((cnf->lud))
      ldaputils_unbind(cnf->lud);

   if ((cnf->lsd))
      ldapschema_free(cnf->lsd);

   if ((cnf->args))
      free(cnf->args);

   free(cnf);

   return;
}

/* end of source file */