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