]> git.sur5r.net Git - openldap/blob - servers/slapd/schemaparse.c
SLAPD compiles. Needs LDBM work to link.
[openldap] / servers / slapd / schemaparse.c
1 /* schemaparse.c - routines to parse config file objectclass definitions */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "slap.h"
11
12 extern char             **str2charray();
13 extern void             charray_merge();
14
15 struct objclass         *global_oc;
16 int                     global_schemacheck;
17
18 static void             oc_usage();
19
20 void
21 parse_oc(
22     Backend     *be,
23     char        *fname,
24     int         lineno,
25     int         argc,
26     char        **argv
27 )
28 {
29         int             i;
30         char            last;
31         struct objclass *oc;
32         struct objclass **ocp;
33
34         oc = (struct objclass *) ch_calloc( 1, sizeof(struct objclass) );
35         oc->oc_name = strdup( argv[1] );
36         for ( i = 2; i < argc; i++ ) {
37                 /* required attributes */
38                 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
39                         do {
40                                 i++;
41                                 if ( i < argc ) {
42                                         last = argv[i][strlen( argv[i] ) - 1];
43                                         charray_merge( &oc->oc_required,
44                                                 str2charray( argv[i], "," ) );
45                                 }
46                         } while ( i < argc && last == ',' );
47
48                 /* optional attributes */
49                 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
50                         do {
51                                 i++;
52                                 if ( i < argc ) {
53                                         last = argv[i][strlen( argv[i] ) - 1];
54                                         charray_merge( &oc->oc_allowed,
55                                                 str2charray( argv[i], "," ) );
56                                 }
57                         } while ( i < argc && last == ',' );
58
59                 } else {
60                         fprintf( stderr,
61             "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
62                             fname, lineno, argv[i] );
63                         oc_usage();
64                 }
65         }
66
67         ocp = &global_oc;
68         while ( *ocp != NULL ) {
69                 ocp = &(*ocp)->oc_next;
70         }
71         *ocp = oc;
72 }
73
74 static void
75 oc_usage()
76 {
77         fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
78         fprintf( stderr, "                [ requires <attrlist> ]\n" );
79         fprintf( stderr, "                [ allows <attrlist> ]\n" );
80         exit( 1 );
81 }
82