]> git.sur5r.net Git - openldap/blob - servers/slapd/aclparse.c
more re-engineering; now rdn_attrs() and so are written in terms of ldap_str2rdn...
[openldap] / servers / slapd / aclparse.c
1 /* aclparse.c - routines to parse and check acl's */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/ctype.h>
13 #include <ac/regex.h>
14 #include <ac/socket.h>
15 #include <ac/string.h>
16 #include <ac/unistd.h>
17
18 #include "slap.h"
19
20 static void             split(char *line, int splitchar, char **left, char **right);
21 static void             access_append(Access **l, Access *a);
22 static void             acl_usage(void) LDAP_GCCATTR((noreturn));
23
24 static char             *acl_regex_normalized_dn(const char *pattern);
25
26 #ifdef LDAP_DEBUG
27 static void             print_acl(Backend *be, AccessControl *a);
28 static void             print_access(Access *b);
29 #endif
30
31 static int
32 regtest(const char *fname, int lineno, char *pat) {
33         int e;
34         regex_t re;
35
36         char buf[512];
37         unsigned size;
38
39         char *sp;
40         char *dp;
41         int  flag;
42
43         sp = pat;
44         dp = buf;
45         size = 0;
46         buf[0] = '\0';
47
48         for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
49                 if (flag) {
50                         if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
51                                 *dp++ = *sp;
52                                 size++;
53                         }
54                         flag = 0;
55
56                 } else {
57                         if (*sp == '$') {
58                                 flag = 1;
59                         } else {
60                                 *dp++ = *sp;
61                                 size++;
62                         }
63                 }
64         }
65
66         *dp = '\0';
67         if ( size >= (sizeof(buf)-1) ) {
68                 fprintf( stderr,
69                         "%s: line %d: regular expression \"%s\" too large\n",
70                         fname, lineno, pat );
71                 acl_usage();
72         }
73
74         if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
75                 char error[512];
76                 regerror(e, &re, error, sizeof(error));
77                 fprintf( stderr,
78                         "%s: line %d: regular expression \"%s\" bad because of %s\n",
79                         fname, lineno, pat, error );
80                 acl_usage();
81                 return(0);
82         }
83         regfree(&re);
84         return(1);
85 }
86
87 void
88 parse_acl(
89     Backend     *be,
90     const char  *fname,
91     int         lineno,
92     int         argc,
93     char        **argv
94 )
95 {
96         int             i;
97         char            *left, *right, *style;
98         AccessControl   *a;
99         Access  *b;
100         int rc;
101         const char *text;
102
103         a = NULL;
104         for ( i = 1; i < argc; i++ ) {
105                 /* to clause - select which entries are protected */
106                 if ( strcasecmp( argv[i], "to" ) == 0 ) {
107                         if ( a != NULL ) {
108                                 fprintf( stderr,
109                 "%s: line %d: only one to clause allowed in access line\n",
110                                     fname, lineno );
111                                 acl_usage();
112                         }
113                         a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
114                         for ( ++i; i < argc; i++ ) {
115                                 if ( strcasecmp( argv[i], "by" ) == 0 ) {
116                                         i--;
117                                         break;
118                                 }
119
120                                 if ( strcasecmp( argv[i], "*" ) == 0 ) {
121                                         if( a->acl_dn_pat.bv_len != 0 ) {
122                                                 fprintf( stderr,
123                                                         "%s: line %d: dn pattern"
124                                                         " already specified in to clause.\n",
125                                                         fname, lineno );
126                                                 acl_usage();
127                                         }
128
129                                         a->acl_dn_pat.bv_val = ch_strdup( "*" );
130                                         a->acl_dn_pat.bv_len = 1;
131                                         continue;
132                                 }
133
134                                 split( argv[i], '=', &left, &right );
135                                 split( left, '.', &left, &style );
136
137                                 if ( right == NULL ) {
138                                         fprintf( stderr,
139         "%s: line %d: missing \"=\" in \"%s\" in to clause\n",
140                                             fname, lineno, left );
141                                         acl_usage();
142                                 }
143
144                                 if ( strcasecmp( left, "dn" ) == 0 ) {
145                                         if( a->acl_dn_pat.bv_len != 0 ) {
146                                                 fprintf( stderr,
147                                                         "%s: line %d: dn pattern"
148                                                         " already specified in to clause.\n",
149                                                         fname, lineno );
150                                                 acl_usage();
151                                         }
152
153                                         if ( style == NULL || *style == '\0'
154                                                 || strcasecmp( style, "regex" ) == 0 )
155                                         {
156                                                 a->acl_dn_style = ACL_STYLE_REGEX;
157                                                 if ( strcmp(right, "*") == 0 
158                                                         || strcmp(right, ".*") == 0 
159                                                         || strcmp(right, ".*$") == 0 
160                                                         || strcmp(right, "^.*") == 0 
161                                                         || strcmp(right, "^.*$$") == 0
162                                                         || strcmp(right, ".*$$") == 0 
163                                                         || strcmp(right, "^.*$$") == 0 )
164                                                 {
165                                                         a->acl_dn_pat.bv_val = ch_strdup( "*" );
166                                                         a->acl_dn_pat.bv_len = 1;
167
168                                                 } else {
169                                                         a->acl_dn_pat.bv_val = acl_regex_normalized_dn( right );
170                                                         a->acl_dn_pat.bv_len = strlen( a->acl_dn_pat.bv_val );
171                                                 }
172                                         } else if ( strcasecmp( style, "base" ) == 0 ) {
173                                                 a->acl_dn_style = ACL_STYLE_BASE;
174                                                 a->acl_dn_pat.bv_val = ch_strdup( right );
175                                                 a->acl_dn_pat.bv_len = strlen( right );
176
177                                         } else if ( strcasecmp( style, "one" ) == 0 ) {
178                                                 a->acl_dn_style = ACL_STYLE_ONE;
179                                                 a->acl_dn_pat.bv_val = ch_strdup( right );
180                                                 a->acl_dn_pat.bv_len = strlen( right );
181
182                                         } else if ( strcasecmp( style, "subtree" ) == 0 ) {
183                                                 a->acl_dn_style = ACL_STYLE_SUBTREE;
184                                                 a->acl_dn_pat.bv_val = ch_strdup( right );
185                                                 a->acl_dn_pat.bv_len = strlen( right );
186
187                                         } else if ( strcasecmp( style, "children" ) == 0 ) {
188                                                 a->acl_dn_style = ACL_STYLE_CHILDREN;
189                                                 a->acl_dn_pat.bv_val = ch_strdup( right );
190                                                 a->acl_dn_pat.bv_len = strlen( right );
191
192                                         } else {
193                                                 fprintf( stderr,
194         "%s: line %d: unknown dn style \"%s\" in to clause\n",
195                                                     fname, lineno, style );
196                                                 acl_usage();
197                                         }
198
199                                         continue;
200                                 }
201
202                                 if ( strcasecmp( left, "filter" ) == 0 ) {
203                                         if ( (a->acl_filter = str2filter(
204                                             right )) == NULL ) {
205                                                 fprintf( stderr,
206                                 "%s: line %d: bad filter \"%s\" in to clause\n",
207                                                     fname, lineno, right );
208                                                 acl_usage();
209                                         }
210
211                                 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
212                                         char    **alist;
213
214                                         alist = str2charray( right, "," );
215                                         charray_merge( &a->acl_attrs, alist );
216                                         charray_free( alist );
217
218                                 } else {
219                                         fprintf( stderr,
220                                                 "%s: line %d: expecting <what> got \"%s\"\n",
221                                             fname, lineno, left );
222                                         acl_usage();
223                                 }
224                         }
225
226                         if ( a->acl_dn_pat.bv_len != 0 && strcmp(a->acl_dn_pat.bv_val, "*") == 0) {
227                                 free( a->acl_dn_pat.bv_val );
228                                 a->acl_dn_pat.bv_val = NULL;
229                                 a->acl_dn_pat.bv_len = 0;
230                         }
231                         
232                         if( a->acl_dn_pat.bv_len != 0 ) {
233                                 if ( a->acl_dn_style != ACL_STYLE_REGEX )
234                                 {
235                                         struct berval *bv = NULL;
236                                         dnNormalize( NULL, &a->acl_dn_pat, &bv);
237                                         free( a->acl_dn_pat.bv_val );
238                                         a->acl_dn_pat = *bv;
239                                         free( bv );
240                                 } else {
241                                         int e = regcomp( &a->acl_dn_re, a->acl_dn_pat.bv_val,
242                                                          REG_EXTENDED | REG_ICASE );
243                                         if ( e ) {
244                                                 char buf[512];
245                                                 regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
246                                                 fprintf( stderr,
247                                         "%s: line %d: regular expression \"%s\" bad because of %s\n",
248                                                          fname, lineno, right, buf );
249                                                 acl_usage();
250                                         }
251                                 }
252                         }
253
254                 /* by clause - select who has what access to entries */
255                 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
256                         if ( a == NULL ) {
257                                 fprintf( stderr,
258                                         "%s: line %d: to clause required before by clause in access line\n",
259                                     fname, lineno );
260                                 acl_usage();
261                         }
262
263                         /*
264                          * by clause consists of <who> and <access>
265                          */
266
267                         b = (Access *) ch_calloc( 1, sizeof(Access) );
268
269                         ACL_INVALIDATE( b->a_access_mask );
270
271                         if ( ++i == argc ) {
272                                 fprintf( stderr,
273                             "%s: line %d: premature eol: expecting <who>\n",
274                                     fname, lineno );
275                                 acl_usage();
276                         }
277
278                         /* get <who> */
279                         for ( ; i < argc; i++ ) {
280                                 char *pat;
281                                 slap_style_t sty = ACL_STYLE_REGEX;
282
283                                 split( argv[i], '=', &left, &right );
284                                 split( left, '.', &left, &style );
285                                 if ( style == NULL || *style == '\0'
286                                         || strcasecmp( style, "regex" ) == 0 )
287                                 {
288                                         sty = ACL_STYLE_REGEX;
289                                 } else if ( strcasecmp( style, "exact" ) == 0 ) {
290                                         sty = ACL_STYLE_EXACT;
291                                 } else if ( strcasecmp( style, "base" ) == 0 ) {
292                                         sty = ACL_STYLE_BASE;
293                                 } else if ( strcasecmp( style, "one" ) == 0 ) {
294                                         sty = ACL_STYLE_ONE;
295                                 } else if ( strcasecmp( style, "subtree" ) == 0 ) {
296                                         sty = ACL_STYLE_SUBTREE;
297                                 } else if ( strcasecmp( style, "children" ) == 0 ) {
298                                         sty = ACL_STYLE_CHILDREN;
299                                 } else {
300                                         fprintf( stderr,
301                                                 "%s: line %d: unknown style \"%s\" in by clause\n",
302                                             fname, lineno, style );
303                                         acl_usage();
304                                 }
305
306                                 if ( strcasecmp( argv[i], "*" ) == 0 ) {
307                                         pat = ch_strdup( "*" );
308
309                                 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
310                                         pat = ch_strdup( "anonymous" );
311
312                                 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
313                                         pat = ch_strdup( "self" );
314
315                                 } else if ( strcasecmp( argv[i], "users" ) == 0 ) {
316                                         pat = ch_strdup( "users" );
317
318                                 } else if ( strcasecmp( left, "dn" ) == 0 ) {
319                                         if ( sty == ACL_STYLE_REGEX ) {
320                                                 b->a_dn_style = ACL_STYLE_REGEX;
321                                                 if( right == NULL ) {
322                                                         /* no '=' */
323                                                         pat = ch_strdup( "users" );
324
325                                                 } else if (*right == '\0' ) {
326                                                         /* dn="" */
327                                                         pat = ch_strdup( "anonymous" );
328
329                                                 } else if ( strcmp( right, "*" ) == 0 ) {
330                                                         /* dn=* */
331                                                         /* any or users?  users for now */
332                                                         pat = ch_strdup( "users" );
333
334                                                 } else if ( strcmp( right, ".+" ) == 0
335                                                         || strcmp( right, "^.+" ) == 0
336                                                         || strcmp( right, ".+$" ) == 0
337                                                         || strcmp( right, "^.+$" ) == 0
338                                                         || strcmp( right, ".+$$" ) == 0
339                                                         || strcmp( right, "^.+$$" ) == 0 )
340                                                 {
341                                                         pat = ch_strdup( "users" );
342
343                                                 } else if ( strcmp( right, ".*" ) == 0
344                                                         || strcmp( right, "^.*" ) == 0
345                                                         || strcmp( right, ".*$" ) == 0
346                                                         || strcmp( right, "^.*$" ) == 0
347                                                         || strcmp( right, ".*$$" ) == 0
348                                                         || strcmp( right, "^.*$$" ) == 0 )
349                                                 {
350                                                         pat = ch_strdup( "*" );
351
352                                                 } else {
353                                                         pat = acl_regex_normalized_dn( right );
354                                                         regtest(fname, lineno, pat);
355                                                 }
356                                         } else if ( right == NULL || *right == '\0' ) {
357                                                 fprintf( stderr,
358                                                         "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
359                                                     fname, lineno, left );
360                                                 acl_usage();
361
362                                         } else {
363                                                 pat = ch_strdup( right );
364                                         }
365
366                                 } else {
367                                         pat = NULL;
368                                 }
369
370                                 if( pat != NULL ) {
371                                         if( b->a_dn_pat.bv_len != 0 ) {
372                                                 fprintf( stderr,
373                                                     "%s: line %d: dn pattern already specified.\n",
374                                                     fname, lineno );
375                                                 acl_usage();
376                                         }
377
378                                         b->a_dn_pat.bv_val = pat;
379                                         b->a_dn_pat.bv_len = strlen( pat );
380                                         b->a_dn_style = sty;
381                                         if ( sty != ACL_STYLE_REGEX )
382                                                 dn_normalize(pat);
383                                         continue;
384                                 }
385
386                                 if ( strcasecmp( left, "dnattr" ) == 0 ) {
387                                         if ( right == NULL || right[ 0 ] == '\0' ) {
388                                                 fprintf( stderr,
389                                                         "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
390                                                         fname, lineno, left );
391                                                 acl_usage();
392                                         }
393
394                                         if( b->a_dn_at != NULL ) {
395                                                 fprintf( stderr,
396                                                         "%s: line %d: dnattr already specified.\n",
397                                                         fname, lineno );
398                                                 acl_usage();
399                                         }
400
401                                         rc = slap_str2ad( right, &b->a_dn_at, &text );
402
403                                         if( rc != LDAP_SUCCESS ) {
404                                                 fprintf( stderr,
405                                                         "%s: line %d: dnattr \"%s\": %s\n",
406                                                         fname, lineno, right, text );
407                                                 acl_usage();
408                                         }
409
410
411                                         if( !is_at_syntax( b->a_dn_at->ad_type,
412                                                 SLAPD_DN_SYNTAX ) &&
413                                                 !is_at_syntax( b->a_dn_at->ad_type,
414                                                 SLAPD_NAMEUID_SYNTAX ))
415                                         {
416                                                 fprintf( stderr,
417                                                         "%s: line %d: dnattr \"%s\": "
418                                                         "inappropriate syntax: %s\n",
419                                                         fname, lineno, right,
420                                                         b->a_dn_at->ad_type->sat_syntax_oid );
421                                                 acl_usage();
422                                         }
423
424                                         continue;
425                                 }
426
427                                 if (sty != ACL_STYLE_REGEX && sty != ACL_STYLE_BASE) {
428                                         fprintf( stderr,
429                                                 "%s: line %d: inappropriate style \"%s\" in by clause\n",
430                                             fname, lineno, style );
431                                         acl_usage();
432                                 }
433
434                                 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
435                                         char *name = NULL;
436                                         char *value = NULL;
437
438                                         if ( right == NULL || right[ 0 ] == '\0' ) {
439                                                 fprintf( stderr,
440                                                         "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
441                                                         fname, lineno, left );
442                                                 acl_usage();
443                                         }
444
445                                         if( b->a_group_pat != NULL ) {
446                                                 fprintf( stderr,
447                                                         "%s: line %d: group pattern already specified.\n",
448                                                         fname, lineno );
449                                                 acl_usage();
450                                         }
451
452                                         /* format of string is "group/objectClassValue/groupAttrName" */
453                                         if ((value = strchr(left, '/')) != NULL) {
454                                                 *value++ = '\0';
455                                                 if (*value
456                                                         && (name = strchr(value, '/')) != NULL)
457                                                 {
458                                                         *name++ = '\0';
459                                                 }
460                                         }
461
462                                         b->a_group_style = sty;
463                                         if (sty == ACL_STYLE_REGEX) {
464                                                 char *tmp = acl_regex_normalized_dn( right );
465                                                 regtest(fname, lineno, tmp);
466                                                 b->a_group_pat = tmp;
467                                         } else {
468                                                 b->a_group_pat = ch_strdup( right );
469                                                 dn_normalize(b->a_group_pat);
470                                         }
471
472                                         if (value && *value) {
473                                                 b->a_group_oc = oc_find( value );
474                                                 *--value = '/';
475
476                                                 if( b->a_group_oc == NULL ) {
477                                                         fprintf( stderr,
478                                                                 "%s: line %d: group objectclass "
479                                                                 "\"%s\" unknown\n",
480                                                                 fname, lineno, value );
481                                                         acl_usage();
482                                                 }
483                                         } else {
484                                                 b->a_group_oc = oc_find(SLAPD_GROUP_CLASS);
485
486                                                 if( b->a_group_oc == NULL ) {
487                                                         fprintf( stderr,
488                                                                 "%s: line %d: group default objectclass "
489                                                                 "\"%s\" unknown\n",
490                                                                 fname, lineno, SLAPD_GROUP_CLASS );
491                                                         acl_usage();
492                                                 }
493                                         }
494
495                                         if( is_object_subclass( b->a_group_oc,
496                                                 slap_schema.si_oc_referral ) )
497                                         {
498                                                 fprintf( stderr,
499                                                         "%s: line %d: group objectclass \"%s\" "
500                                                         "is subclass of referral\n",
501                                                         fname, lineno, value );
502                                                 acl_usage();
503                                         }
504
505                                         if( is_object_subclass( b->a_group_oc,
506                                                 slap_schema.si_oc_alias ) )
507                                         {
508                                                 fprintf( stderr,
509                                                         "%s: line %d: group objectclass \"%s\" "
510                                                         "is subclass of alias\n",
511                                                         fname, lineno, value );
512                                                 acl_usage();
513                                         }
514
515                                         if (name && *name) {
516                                                 rc = slap_str2ad( name, &b->a_group_at, &text );
517
518                                                 if( rc != LDAP_SUCCESS ) {
519                                                         fprintf( stderr,
520                                                                 "%s: line %d: group \"%s\": %s\n",
521                                                                 fname, lineno, right, text );
522                                                         acl_usage();
523                                                 }
524                                                 *--name = '/';
525                                         } else {
526                                                 rc = slap_str2ad( SLAPD_GROUP_ATTR, &b->a_group_at, &text );
527
528                                                 if( rc != LDAP_SUCCESS ) {
529                                                         fprintf( stderr,
530                                                                 "%s: line %d: group \"%s\": %s\n",
531                                                                 fname, lineno, SLAPD_GROUP_ATTR, text );
532                                                         acl_usage();
533                                                 }
534                                         }
535
536                                         if( !is_at_syntax( b->a_group_at->ad_type,
537                                                 SLAPD_DN_SYNTAX ) &&
538                                             !is_at_syntax( b->a_group_at->ad_type,
539                                                 SLAPD_NAMEUID_SYNTAX ) )
540                                         {
541                                                 fprintf( stderr,
542                                                         "%s: line %d: group \"%s\": inappropriate syntax: %s\n",
543                                                         fname, lineno, right,
544                                                         b->a_group_at->ad_type->sat_syntax_oid );
545                                                 acl_usage();
546                                         }
547
548
549                                         {
550                                                 int rc;
551                                                 struct berval val;
552                                                 struct berval *vals[2];
553
554                                                 val.bv_val = b->a_group_oc->soc_oid;
555                                                 val.bv_len = strlen(val.bv_val);
556                                                 vals[0] = &val;
557                                                 vals[1] = NULL;
558
559
560                                                 rc = oc_check_allowed( b->a_group_at->ad_type, vals, NULL );
561
562                                                 if( rc != 0 ) {
563                                                         fprintf( stderr,
564                                                                 "%s: line %d: group: \"%s\" not allowed by \"%s\"\n",
565                                                                 fname, lineno,
566                                                                 b->a_group_at->ad_cname.bv_val,
567                                                                 b->a_group_oc->soc_oid );
568                                                         acl_usage();
569                                                 }
570                                         }
571                                         continue;
572                                 }
573
574                                 if ( strcasecmp( left, "peername" ) == 0 ) {
575                                         if ( right == NULL || right[ 0 ] == '\0' ) {
576                                                 fprintf( stderr,
577                                                         "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
578                                                         fname, lineno, left );
579                                                 acl_usage();
580                                         }
581
582                                         if( b->a_peername_pat != NULL ) {
583                                                 fprintf( stderr,
584                                                         "%s: line %d: peername pattern already specified.\n",
585                                                         fname, lineno );
586                                                 acl_usage();
587                                         }
588
589                                         b->a_peername_style = sty;
590                                         if (sty == ACL_STYLE_REGEX) {
591                                                 char *tmp = acl_regex_normalized_dn( right );
592                                                 regtest(fname, lineno, tmp);
593                                                 b->a_peername_pat = tmp;
594                                         } else {
595                                                 b->a_peername_pat = ch_strdup( right );
596                                         }
597                                         continue;
598                                 }
599
600                                 if ( strcasecmp( left, "sockname" ) == 0 ) {
601                                         if ( right == NULL || right[ 0 ] == '\0' ) {
602                                                 fprintf( stderr,
603                                                         "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
604                                                         fname, lineno, left );
605                                                 acl_usage();
606                                         }
607
608                                         if( b->a_sockname_pat != NULL ) {
609                                                 fprintf( stderr,
610                                                         "%s: line %d: sockname pattern already specified.\n",
611                                                         fname, lineno );
612                                                 acl_usage();
613                                         }
614
615                                         b->a_sockname_style = sty;
616                                         if (sty == ACL_STYLE_REGEX) {
617                                                 char *tmp = acl_regex_normalized_dn( right );
618                                                 regtest(fname, lineno, tmp);
619                                                 b->a_sockname_pat = tmp;
620                                         } else {
621                                                 b->a_sockname_pat = ch_strdup( right );
622                                         }
623                                         continue;
624                                 }
625
626                                 if ( strcasecmp( left, "domain" ) == 0 ) {
627                                         if ( right == NULL || right[ 0 ] == '\0' ) {
628                                                 fprintf( stderr,
629                                                         "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
630                                                         fname, lineno, left );
631                                                 acl_usage();
632                                         }
633
634                                         if( b->a_domain_pat != NULL ) {
635                                                 fprintf( stderr,
636                                                         "%s: line %d: domain pattern already specified.\n",
637                                                         fname, lineno );
638                                                 acl_usage();
639                                         }
640
641                                         b->a_domain_style = sty;
642                                         if (sty == ACL_STYLE_REGEX) {
643                                                 char *tmp = acl_regex_normalized_dn( right );
644                                                 regtest(fname, lineno, tmp);
645                                                 b->a_domain_pat = tmp;
646                                         } else {
647                                                 b->a_domain_pat = ch_strdup( right );
648                                         }
649                                         continue;
650                                 }
651
652                                 if ( strcasecmp( left, "sockurl" ) == 0 ) {
653                                         if ( right == NULL || right[ 0 ] == '\0' ) {
654                                                 fprintf( stderr,
655                                                         "%s: line %d: missing \"=\" in (or value after) \"%s\" in by clause\n",
656                                                         fname, lineno, left );
657                                                 acl_usage();
658                                         }
659
660                                         if( b->a_sockurl_pat != NULL ) {
661                                                 fprintf( stderr,
662                                                         "%s: line %d: sockurl pattern already specified.\n",
663                                                         fname, lineno );
664                                                 acl_usage();
665                                         }
666
667                                         b->a_sockurl_style = sty;
668                                         if (sty == ACL_STYLE_REGEX) {
669                                                 char *tmp = acl_regex_normalized_dn( right );
670                                                 regtest(fname, lineno, tmp);
671                                                 b->a_sockurl_pat = tmp;
672                                         } else {
673                                                 b->a_sockurl_pat = ch_strdup( right );
674                                         }
675                                         continue;
676                                 }
677
678                                 if ( strcasecmp( left, "set" ) == 0 ) {
679                                         if( b->a_set_pat.bv_len != 0 ) {
680                                                 fprintf( stderr,
681                                                         "%s: line %d: set attribute already specified.\n",
682                                                         fname, lineno );
683                                                 acl_usage();
684                                         }
685
686                                         if ( right == NULL || *right == '\0' ) {
687                                                 fprintf( stderr,
688                                                         "%s: line %d: no set is defined\n",
689                                                         fname, lineno );
690                                                 acl_usage();
691                                         }
692
693                                         b->a_set_style = sty;
694                                         b->a_set_pat.bv_val = ch_strdup(right);
695                                         b->a_set_pat.bv_len = strlen(right);
696
697                                         continue;
698                                 }
699
700 #ifdef SLAPD_ACI_ENABLED
701                                 if ( strcasecmp( left, "aci" ) == 0 ) {
702                                         if( b->a_aci_at != NULL ) {
703                                                 fprintf( stderr,
704                                                         "%s: line %d: aci attribute already specified.\n",
705                                                         fname, lineno );
706                                                 acl_usage();
707                                         }
708
709                                         if ( right != NULL && *right != '\0' ) {
710                                                 rc = slap_str2ad( right, &b->a_aci_at, &text );
711
712                                                 if( rc != LDAP_SUCCESS ) {
713                                                         fprintf( stderr,
714                                                                 "%s: line %d: aci \"%s\": %s\n",
715                                                                 fname, lineno, right, text );
716                                                         acl_usage();
717                                                 }
718
719                                         } else {
720                                                 rc = slap_str2ad( SLAPD_ACI_ATTR, &b->a_aci_at, &text );
721
722                                                 if( rc != LDAP_SUCCESS ) {
723                                                         fprintf( stderr,
724                                                                 "%s: line %d: aci \"%s\": %s\n",
725                                                                 fname, lineno, SLAPD_ACI_ATTR, text );
726                                                         acl_usage();
727                                                 }
728                                         }
729
730                                         if( !is_at_syntax( b->a_aci_at->ad_type,
731                                                 SLAPD_ACI_SYNTAX) )
732                                         {
733                                                 fprintf( stderr,
734                                                         "%s: line %d: aci \"%s\": inappropriate syntax: %s\n",
735                                                         fname, lineno, right,
736                                                         b->a_aci_at->ad_type->sat_syntax_oid );
737                                                 acl_usage();
738                                         }
739
740                                         continue;
741                                 }
742 #endif /* SLAPD_ACI_ENABLED */
743
744                                 if ( strcasecmp( left, "ssf" ) == 0 ) {
745                                         if( b->a_authz.sai_ssf ) {
746                                                 fprintf( stderr,
747                                                         "%s: line %d: ssf attribute already specified.\n",
748                                                         fname, lineno );
749                                                 acl_usage();
750                                         }
751
752                                         if ( right == NULL || *right == '\0' ) {
753                                                 fprintf( stderr,
754                                                         "%s: line %d: no ssf is defined\n",
755                                                         fname, lineno );
756                                                 acl_usage();
757                                         }
758
759                                         b->a_authz.sai_ssf = atoi( right );
760
761                                         if( !b->a_authz.sai_ssf ) {
762                                                 fprintf( stderr,
763                                                         "%s: line %d: invalid ssf value (%s)\n",
764                                                         fname, lineno, right );
765                                                 acl_usage();
766                                         }
767                                         continue;
768                                 }
769
770                                 if ( strcasecmp( left, "transport_ssf" ) == 0 ) {
771                                         if( b->a_authz.sai_transport_ssf ) {
772                                                 fprintf( stderr,
773                                                         "%s: line %d: transport_ssf attribute already specified.\n",
774                                                         fname, lineno );
775                                                 acl_usage();
776                                         }
777
778                                         if ( right == NULL || *right == '\0' ) {
779                                                 fprintf( stderr,
780                                                         "%s: line %d: no transport_ssf is defined\n",
781                                                         fname, lineno );
782                                                 acl_usage();
783                                         }
784
785                                         b->a_authz.sai_transport_ssf = atoi( right );
786
787                                         if( !b->a_authz.sai_transport_ssf ) {
788                                                 fprintf( stderr,
789                                                         "%s: line %d: invalid transport_ssf value (%s)\n",
790                                                         fname, lineno, right );
791                                                 acl_usage();
792                                         }
793                                         continue;
794                                 }
795
796                                 if ( strcasecmp( left, "tls_ssf" ) == 0 ) {
797                                         if( b->a_authz.sai_tls_ssf ) {
798                                                 fprintf( stderr,
799                                                         "%s: line %d: tls_ssf attribute already specified.\n",
800                                                         fname, lineno );
801                                                 acl_usage();
802                                         }
803
804                                         if ( right == NULL || *right == '\0' ) {
805                                                 fprintf( stderr,
806                                                         "%s: line %d: no tls_ssf is defined\n",
807                                                         fname, lineno );
808                                                 acl_usage();
809                                         }
810
811                                         b->a_authz.sai_tls_ssf = atoi( right );
812
813                                         if( !b->a_authz.sai_tls_ssf ) {
814                                                 fprintf( stderr,
815                                                         "%s: line %d: invalid tls_ssf value (%s)\n",
816                                                         fname, lineno, right );
817                                                 acl_usage();
818                                         }
819                                         continue;
820                                 }
821
822                                 if ( strcasecmp( left, "sasl_ssf" ) == 0 ) {
823                                         if( b->a_authz.sai_sasl_ssf ) {
824                                                 fprintf( stderr,
825                                                         "%s: line %d: sasl_ssf attribute already specified.\n",
826                                                         fname, lineno );
827                                                 acl_usage();
828                                         }
829
830                                         if ( right == NULL || *right == '\0' ) {
831                                                 fprintf( stderr,
832                                                         "%s: line %d: no sasl_ssf is defined\n",
833                                                         fname, lineno );
834                                                 acl_usage();
835                                         }
836
837                                         b->a_authz.sai_sasl_ssf = atoi( right );
838
839                                         if( !b->a_authz.sai_sasl_ssf ) {
840                                                 fprintf( stderr,
841                                                         "%s: line %d: invalid sasl_ssf value (%s)\n",
842                                                         fname, lineno, right );
843                                                 acl_usage();
844                                         }
845                                         continue;
846                                 }
847
848                                 if( right != NULL ) {
849                                         /* unsplit */
850                                         right[-1] = '=';
851                                 }
852                                 break;
853                         }
854
855                         if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) { 
856                                 /* out of arguments or plain stop */
857
858                                 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
859                                 b->a_type = ACL_STOP;
860
861                                 access_append( &a->acl_access, b );
862                                 continue;
863                         }
864
865                         if( strcasecmp( left, "continue" ) == 0 ) {
866                                 /* plain continue */
867
868                                 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
869                                 b->a_type = ACL_CONTINUE;
870
871                                 access_append( &a->acl_access, b );
872                                 continue;
873                         }
874
875                         if( strcasecmp( left, "break" ) == 0 ) {
876                                 /* plain continue */
877
878                                 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
879                                 b->a_type = ACL_BREAK;
880
881                                 access_append( &a->acl_access, b );
882                                 continue;
883                         }
884
885                         if ( strcasecmp( left, "by" ) == 0 ) {
886                                 /* we've gone too far */
887                                 --i;
888                                 ACL_PRIV_ASSIGN(b->a_access_mask, ACL_PRIV_ADDITIVE);
889                                 b->a_type = ACL_STOP;
890
891                                 access_append( &a->acl_access, b );
892                                 continue;
893                         }
894
895                         /* get <access> */
896                         if( strncasecmp( left, "self", 4 ) == 0 ) {
897                                 b->a_dn_self = 1;
898                                 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( &left[4] ) );
899
900                         } else {
901                                 ACL_PRIV_ASSIGN( b->a_access_mask, str2accessmask( left ) );
902                         }
903
904                         if( ACL_IS_INVALID( b->a_access_mask ) ) {
905                                 fprintf( stderr,
906                                         "%s: line %d: expecting <access> got \"%s\"\n",
907                                         fname, lineno, left );
908                                 acl_usage();
909                         }
910
911                         b->a_type = ACL_STOP;
912
913                         if( ++i == argc ) {
914                                 /* out of arguments or plain stop */
915                                 access_append( &a->acl_access, b );
916                                 continue;
917                         }
918
919                         if( strcasecmp( argv[i], "continue" ) == 0 ) {
920                                 /* plain continue */
921                                 b->a_type = ACL_CONTINUE;
922
923                         } else if( strcasecmp( argv[i], "break" ) == 0 ) {
924                                 /* plain continue */
925                                 b->a_type = ACL_BREAK;
926
927                         } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
928                                 /* gone to far */
929                                 i--;
930                         }
931
932                         access_append( &a->acl_access, b );
933
934                 } else {
935                         fprintf( stderr,
936                     "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
937                             fname, lineno, argv[i] );
938                         acl_usage();
939                 }
940         }
941
942         /* if we have no real access clause, complain and do nothing */
943         if ( a == NULL ) {
944                         fprintf( stderr,
945                                 "%s: line %d: warning: no access clause(s) specified in access line\n",
946                             fname, lineno );
947
948         } else {
949 #ifdef LDAP_DEBUG
950                 if (ldap_debug & LDAP_DEBUG_ACL)
951                         print_acl(be, a);
952 #endif
953         
954                 if ( a->acl_access == NULL ) {
955                         fprintf( stderr,
956                         "%s: line %d: warning: no by clause(s) specified in access line\n",
957                             fname, lineno );
958                 }
959
960                 if ( be != NULL ) {
961                         acl_append( &be->be_acl, a );
962                 } else {
963                         acl_append( &global_acl, a );
964                 }
965         }
966 }
967
968 char *
969 accessmask2str( slap_mask_t mask, char *buf )
970 {
971         int none=1;
972
973         assert( buf != NULL );
974
975         if ( ACL_IS_INVALID( mask ) ) {
976                 return "invalid";
977         }
978
979         buf[0] = '\0';
980
981         if ( ACL_IS_LEVEL( mask ) ) {
982                 if ( ACL_LVL_IS_NONE(mask) ) {
983                         strcat( buf, "none" );
984
985                 } else if ( ACL_LVL_IS_AUTH(mask) ) {
986                         strcat( buf, "auth" );
987
988                 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
989                         strcat( buf, "compare" );
990
991                 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
992                         strcat( buf, "search" );
993
994                 } else if ( ACL_LVL_IS_READ(mask) ) {
995                         strcat( buf, "read" );
996
997                 } else if ( ACL_LVL_IS_WRITE(mask) ) {
998                         strcat( buf, "write" );
999                 } else {
1000                         strcat( buf, "unknown" );
1001                 }
1002                 
1003                 strcat(buf, " (");
1004         }
1005
1006         if( ACL_IS_ADDITIVE( mask ) ) {
1007                 strcat( buf, "+" );
1008
1009         } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
1010                 strcat( buf, "-" );
1011
1012         } else {
1013                 strcat( buf, "=" );
1014         }
1015
1016         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
1017                 none = 0;
1018                 strcat( buf, "w" );
1019         } 
1020
1021         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
1022                 none = 0;
1023                 strcat( buf, "r" );
1024         } 
1025
1026         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
1027                 none = 0;
1028                 strcat( buf, "s" );
1029         } 
1030
1031         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
1032                 none = 0;
1033                 strcat( buf, "c" );
1034         } 
1035
1036         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
1037                 none = 0;
1038                 strcat( buf, "x" );
1039         } 
1040
1041         if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
1042                 none = 0;
1043                 strcat( buf, "n" );
1044         } 
1045
1046         if ( none ) {
1047                 strcat( buf, "0" );
1048         }
1049
1050         if ( ACL_IS_LEVEL( mask ) ) {
1051                 strcat(buf, ")");
1052         } 
1053         return buf;
1054 }
1055
1056 slap_mask_t
1057 str2accessmask( const char *str )
1058 {
1059         slap_mask_t     mask;
1060
1061         if( !ASCII_ALPHA(str[0]) ) {
1062                 int i;
1063
1064                 if ( str[0] == '=' ) {
1065                         ACL_INIT(mask);
1066
1067                 } else if( str[0] == '+' ) {
1068                         ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
1069
1070                 } else if( str[0] == '-' ) {
1071                         ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
1072
1073                 } else {
1074                         ACL_INVALIDATE(mask);
1075                         return mask;
1076                 }
1077
1078                 for( i=1; str[i] != '\0'; i++ ) {
1079                         if( TOLOWER(str[i]) == 'w' ) {
1080                                 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
1081
1082                         } else if( TOLOWER(str[i]) == 'r' ) {
1083                                 ACL_PRIV_SET(mask, ACL_PRIV_READ);
1084
1085                         } else if( TOLOWER(str[i]) == 's' ) {
1086                                 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
1087
1088                         } else if( TOLOWER(str[i]) == 'c' ) {
1089                                 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
1090
1091                         } else if( TOLOWER(str[i]) == 'x' ) {
1092                                 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
1093
1094                         } else if( str[i] != '0' ) {
1095                                 ACL_INVALIDATE(mask);
1096                                 return mask;
1097                         }
1098                 }
1099
1100                 return mask;
1101         }
1102
1103         if ( strcasecmp( str, "none" ) == 0 ) {
1104                 ACL_LVL_ASSIGN_NONE(mask);
1105
1106         } else if ( strcasecmp( str, "auth" ) == 0 ) {
1107                 ACL_LVL_ASSIGN_AUTH(mask);
1108
1109         } else if ( strcasecmp( str, "compare" ) == 0 ) {
1110                 ACL_LVL_ASSIGN_COMPARE(mask);
1111
1112         } else if ( strcasecmp( str, "search" ) == 0 ) {
1113                 ACL_LVL_ASSIGN_SEARCH(mask);
1114
1115         } else if ( strcasecmp( str, "read" ) == 0 ) {
1116                 ACL_LVL_ASSIGN_READ(mask);
1117
1118         } else if ( strcasecmp( str, "write" ) == 0 ) {
1119                 ACL_LVL_ASSIGN_WRITE(mask);
1120
1121         } else {
1122                 ACL_INVALIDATE( mask );
1123         }
1124
1125         return mask;
1126 }
1127
1128 static void
1129 acl_usage( void )
1130 {
1131         fprintf( stderr, "\n"
1132                 "<access clause> ::= access to <what> "
1133                                 "[ by <who> <access> [ <control> ] ]+ \n"
1134                 "<what> ::= * | [dn[.<dnstyle>]=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
1135                 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
1136                 "<attr> ::= <attrname> | entry | children\n"
1137                 "<who> ::= [ * | anonymous | users | self | dn[.<dnstyle>]=<regex> ]\n"
1138                         "\t[dnattr=<attrname>]\n"
1139                         "\t[group[/<objectclass>[/<attrname>]][.<style>]=<regex>]\n"
1140                         "\t[peername[.<style>]=<regex>] [sockname[.<style>]=<regex>]\n"
1141                         "\t[domain[.<style>]=<regex>] [sockurl[.<style>]=<regex>]\n"
1142 #ifdef SLAPD_ACI_ENABLED
1143                         "\t[aci=<attrname>]\n"
1144 #endif
1145                         "\t[ssf=<n>] [transport_ssf=<n>] [tls_ssf=<n>] [sasl_ssf=<n>]\n"
1146                 "<dnstyle> ::= regex | base | exact (alias of base) | one | sub | children\n"
1147                 "<style> ::= regex | base | exact (alias of base)\n"
1148                 "<groupflags> ::= R\n"
1149                 "<access> ::= [self]{<level>|<priv>}\n"
1150                 "<level> ::= none | auth | compare | search | read | write\n"
1151                 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
1152                 "<control> ::= [ stop | continue | break ]\n"
1153                 );
1154         exit( EXIT_FAILURE );
1155 }
1156
1157 /*
1158  * At present it simply eats the (optional) space after 
1159  * a RDN separator (,)
1160  * Eventually will evolve in a more complete normalization
1161  */
1162 static char *
1163 acl_regex_normalized_dn(
1164         const char *pattern
1165 )
1166 {
1167         char *str, *p;
1168
1169         str = ch_strdup( pattern );
1170
1171         if ( str == NULL ) {
1172                 return( NULL );
1173         }
1174
1175         for ( p = str; p[ 0 ]; p++ ) {
1176                 /* escape */
1177                 if ( p[ 0 ] == '\\' ) {
1178                         p++;
1179                 }
1180
1181                 if ( p[ 0 ] == ',' ) {
1182                         if ( p[ 1 ] == ' ' ) {
1183                                 char *q;
1184                         
1185                                 for ( q = &p[ 2 ]; q[ 0 ] == ' '; q++ ) {
1186                                         /* DO NOTHING */ ;
1187                                 }
1188                                 AC_MEMCPY( &p[ 1 ], &q[ 0 ], strlen( q ) + 1 );
1189                         }
1190                 }
1191         }
1192
1193         return( str );
1194 }
1195
1196 static void
1197 split(
1198     char        *line,
1199     int         splitchar,
1200     char        **left,
1201     char        **right
1202 )
1203 {
1204         *left = line;
1205         if ( (*right = strchr( line, splitchar )) != NULL ) {
1206                 *((*right)++) = '\0';
1207         }
1208 }
1209
1210 static void
1211 access_append( Access **l, Access *a )
1212 {
1213         for ( ; *l != NULL; l = &(*l)->a_next )
1214                 ;       /* NULL */
1215
1216         *l = a;
1217 }
1218
1219 void
1220 acl_append( AccessControl **l, AccessControl *a )
1221 {
1222         for ( ; *l != NULL; l = &(*l)->acl_next )
1223                 ;       /* NULL */
1224
1225         *l = a;
1226 }
1227
1228 static void
1229 access_free( Access *a )
1230 {
1231         if ( a->a_dn_pat.bv_val )
1232                 free ( a->a_dn_pat.bv_val );
1233         if ( a->a_peername_pat )
1234                 free ( a->a_peername_pat );
1235         if ( a->a_sockname_pat )
1236                 free ( a->a_sockname_pat );
1237         if ( a->a_domain_pat )
1238                 free ( a->a_domain_pat );
1239         if ( a->a_sockurl_pat )
1240                 free ( a->a_sockurl_pat );
1241         if ( a->a_set_pat.bv_len )
1242                 free ( a->a_set_pat.bv_val );
1243         if ( a->a_group_pat )
1244                 free ( a->a_group_pat );
1245         free( a );
1246 }
1247
1248 void
1249 acl_free( AccessControl *a )
1250 {
1251         Access *n;
1252
1253         if ( a->acl_filter )
1254                 filter_free( a->acl_filter );
1255         if ( a->acl_dn_pat.bv_len )
1256                 free ( a->acl_dn_pat.bv_val );
1257         if ( a->acl_attrs )
1258                 charray_free( a->acl_attrs );
1259         for (; a->acl_access; a->acl_access = n) {
1260                 n = a->acl_access->a_next;
1261                 access_free( a->acl_access );
1262         }
1263         free( a );
1264 }
1265
1266 /* Because backend_startup uses acl_append to tack on the global_acl to
1267  * the end of each backend's acl, we cannot just take one argument and
1268  * merrily free our way to the end of the list. backend_destroy calls us
1269  * with the be_acl in arg1, and global_acl in arg2 to give us a stopping
1270  * point. config_destroy calls us with global_acl in arg1 and NULL in
1271  * arg2, so we then proceed to polish off the global_acl.
1272  */
1273 void
1274 acl_destroy( AccessControl *a, AccessControl *end )
1275 {
1276         AccessControl *n;
1277
1278         for (; a && a!= end; a=n) {
1279                 n = a->acl_next;
1280                 acl_free( a );
1281         }
1282 }
1283
1284 char *
1285 access2str( slap_access_t access )
1286 {
1287         if ( access == ACL_NONE ) {
1288                 return "none";
1289
1290         } else if ( access == ACL_AUTH ) {
1291                 return "auth";
1292
1293         } else if ( access == ACL_COMPARE ) {
1294                 return "compare";
1295
1296         } else if ( access == ACL_SEARCH ) {
1297                 return "search";
1298
1299         } else if ( access == ACL_READ ) {
1300                 return "read";
1301
1302         } else if ( access == ACL_WRITE ) {
1303                 return "write";
1304         }
1305
1306         return "unknown";
1307 }
1308
1309 slap_access_t
1310 str2access( const char *str )
1311 {
1312         if ( strcasecmp( str, "none" ) == 0 ) {
1313                 return ACL_NONE;
1314
1315         } else if ( strcasecmp( str, "auth" ) == 0 ) {
1316                 return ACL_AUTH;
1317
1318         } else if ( strcasecmp( str, "compare" ) == 0 ) {
1319                 return ACL_COMPARE;
1320
1321         } else if ( strcasecmp( str, "search" ) == 0 ) {
1322                 return ACL_SEARCH;
1323
1324         } else if ( strcasecmp( str, "read" ) == 0 ) {
1325                 return ACL_READ;
1326
1327         } else if ( strcasecmp( str, "write" ) == 0 ) {
1328                 return ACL_WRITE;
1329         }
1330
1331         return( ACL_INVALID_ACCESS );
1332 }
1333
1334 #ifdef LDAP_DEBUG
1335
1336 static char *style_strings[5] = {
1337                         "regex",
1338                         "base",
1339                         "one",
1340                         "subtree",
1341                         "children"
1342                 };
1343
1344
1345 static void
1346 print_access( Access *b )
1347 {
1348         char maskbuf[ACCESSMASK_MAXLEN];
1349
1350         fprintf( stderr, "\tby" );
1351
1352         if ( b->a_dn_pat.bv_len != 0 ) {
1353                 if( strcmp(b->a_dn_pat.bv_val, "*") == 0
1354                         || strcmp(b->a_dn_pat.bv_val, "users") == 0 
1355                         || strcmp(b->a_dn_pat.bv_val, "anonymous") == 0 
1356                         || strcmp(b->a_dn_pat.bv_val, "self") == 0 )
1357                 {
1358                         fprintf( stderr, " %s", b->a_dn_pat.bv_val );
1359
1360                 } else {
1361                         fprintf( stderr, " dn.%s=%s", style_strings[b->a_dn_style], b->a_dn_pat.bv_val );
1362                 }
1363         }
1364
1365         if ( b->a_dn_at != NULL ) {
1366                 fprintf( stderr, " dnattr=%s", b->a_dn_at->ad_cname.bv_val );
1367         }
1368
1369         if ( b->a_group_pat != NULL ) {
1370                 fprintf( stderr, " group=%s", b->a_group_pat );
1371
1372                 if ( b->a_group_oc ) {
1373                         fprintf( stderr, " objectClass: %s",
1374                                 b->a_group_oc->soc_oclass.oc_oid );
1375
1376                         if ( b->a_group_at ) {
1377                                 fprintf( stderr, " attributeType: %s", b->a_group_at->ad_cname.bv_val );
1378                         }
1379                 }
1380     }
1381
1382         if ( b->a_peername_pat != NULL ) {
1383                 fprintf( stderr, " peername=%s", b->a_peername_pat );
1384         }
1385
1386         if ( b->a_sockname_pat != NULL ) {
1387                 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
1388         }
1389
1390         if ( b->a_domain_pat != NULL ) {
1391                 fprintf( stderr, " domain=%s", b->a_domain_pat );
1392         }
1393
1394         if ( b->a_sockurl_pat != NULL ) {
1395                 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
1396         }
1397
1398 #ifdef SLAPD_ACI_ENABLED
1399         if ( b->a_aci_at != NULL ) {
1400                 fprintf( stderr, " aci=%s", b->a_aci_at->ad_cname.bv_val );
1401         }
1402 #endif
1403
1404         /* Security Strength Factors */
1405         if ( b->a_authz.sai_ssf ) {
1406                 fprintf( stderr, " ssf=%u",
1407                         b->a_authz.sai_ssf );
1408         }
1409         if ( b->a_authz.sai_transport_ssf ) {
1410                 fprintf( stderr, " transport_ssf=%u",
1411                         b->a_authz.sai_transport_ssf );
1412         }
1413         if ( b->a_authz.sai_tls_ssf ) {
1414                 fprintf( stderr, " tls_ssf=%u",
1415                         b->a_authz.sai_tls_ssf );
1416         }
1417         if ( b->a_authz.sai_sasl_ssf ) {
1418                 fprintf( stderr, " sasl_ssf=%u",
1419                         b->a_authz.sai_sasl_ssf );
1420         }
1421
1422         fprintf( stderr, " %s%s",
1423                 b->a_dn_self ? "self" : "",
1424                 accessmask2str( b->a_access_mask, maskbuf ) );
1425
1426         if( b->a_type == ACL_BREAK ) {
1427                 fprintf( stderr, " break" );
1428
1429         } else if( b->a_type == ACL_CONTINUE ) {
1430                 fprintf( stderr, " continue" );
1431
1432         } else if( b->a_type != ACL_STOP ) {
1433                 fprintf( stderr, " unknown-control" );
1434         }
1435
1436         fprintf( stderr, "\n" );
1437 }
1438
1439
1440 static void
1441 print_acl( Backend *be, AccessControl *a )
1442 {
1443         int             to = 0;
1444         Access  *b;
1445
1446         fprintf( stderr, "%s ACL: access to",
1447                 be == NULL ? "Global" : "Backend" );
1448
1449         if ( a->acl_dn_pat.bv_len != 0 ) {
1450                 to++;
1451                 fprintf( stderr, " dn.%s=%s\n",
1452                         style_strings[a->acl_dn_style], a->acl_dn_pat.bv_val );
1453         }
1454
1455         if ( a->acl_filter != NULL ) {
1456                 to++;
1457                 fprintf( stderr, " filter=" );
1458                 filter_print( a->acl_filter );
1459                 fprintf( stderr, "\n" );
1460         }
1461
1462         if ( a->acl_attrs != NULL ) {
1463                 int     i, first = 1;
1464                 to++;
1465
1466                 fprintf( stderr, " attrs=" );
1467                 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
1468                         if ( ! first ) {
1469                                 fprintf( stderr, "," );
1470                         }
1471                         fprintf( stderr, a->acl_attrs[i] );
1472                         first = 0;
1473                 }
1474                 fprintf(  stderr, "\n" );
1475         }
1476
1477         if( !to ) {
1478                 fprintf( stderr, " *\n" );
1479         }
1480
1481         for ( b = a->acl_access; b != NULL; b = b->a_next ) {
1482                 print_access( b );
1483         }
1484
1485         fprintf( stderr, "\n" );
1486 }
1487
1488 #endif /* LDAP_DEBUG */