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