]> git.sur5r.net Git - openldap/blob - servers/slapd/aclparse.c
813c5d88ad7fd3fc191c244dec414398d0e4a259
[openldap] / servers / slapd / aclparse.c
1 /* acl.c - routines to parse and check acl's */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 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 #ifdef LDAP_DEBUG
25 static void             print_acl(Backend *be, AccessControl *a);
26 static void             print_access(Access *b);
27 #endif
28
29 static int
30 regtest(const char *fname, int lineno, char *pat) {
31         int e;
32         regex_t re;
33
34         char buf[512];
35         unsigned size;
36
37         char *sp;
38         char *dp;
39         int  flag;
40
41         sp = pat;
42         dp = buf;
43         size = 0;
44         buf[0] = '\0';
45
46         for (size = 0, flag = 0; (size < sizeof(buf)) && *sp; sp++) {
47                 if (flag) {
48                         if (*sp == '$'|| (*sp >= '0' && *sp <= '9')) {
49                                 *dp++ = *sp;
50                                 size++;
51                         }
52                         flag = 0;
53
54                 } else {
55                         if (*sp == '$') {
56                                 flag = 1;
57                         } else {
58                                 *dp++ = *sp;
59                                 size++;
60                         }
61                 }
62         }
63
64         *dp = '\0';
65         if ( size >= (sizeof(buf)-1) ) {
66                 fprintf( stderr,
67                         "%s: line %d: regular expression \"%s\" too large\n",
68                         fname, lineno, pat );
69                 acl_usage();
70         }
71
72         if ((e = regcomp(&re, buf, REG_EXTENDED|REG_ICASE))) {
73                 char error[512];
74                 regerror(e, &re, error, sizeof(error));
75                 fprintf( stderr,
76                         "%s: line %d: regular expression \"%s\" bad because of %s\n",
77                         fname, lineno, pat, error );
78                 acl_usage();
79                 return(0);
80         }
81         regfree(&re);
82         return(1);
83 }
84
85 void
86 parse_acl(
87     Backend     *be,
88     const char  *fname,
89     int         lineno,
90     int         argc,
91     char        **argv
92 )
93 {
94         int             i;
95         char            *left, *right;
96         AccessControl   *a;
97         Access  *b;
98
99         a = NULL;
100         for ( i = 1; i < argc; i++ ) {
101                 /* to clause - select which entries are protected */
102                 if ( strcasecmp( argv[i], "to" ) == 0 ) {
103                         if ( a != NULL ) {
104                                 fprintf( stderr,
105                 "%s: line %d: only one to clause allowed in access line\n",
106                                     fname, lineno );
107                                 acl_usage();
108                         }
109                         a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) );
110                         a->acl_filter = NULL;
111                         a->acl_dn_pat = NULL;
112                         a->acl_attrs  = NULL;
113                         a->acl_access = NULL;
114                         a->acl_next   = NULL;
115                         for ( ++i; i < argc; i++ ) {
116                                 if ( strcasecmp( argv[i], "by" ) == 0 ) {
117                                         i--;
118                                         break;
119                                 }
120
121                                 if ( strcasecmp( argv[i], "*" ) == 0 ) {
122                                         a->acl_dn_pat = ch_strdup( ".*" );
123                                         continue;
124                                 }
125
126                                 split( argv[i], '=', &left, &right );
127                                 if ( right == NULL || *right == '\0' ) {
128                                         fprintf( stderr,
129         "%s: line %d: missing \"=\" in (or value after) \"%s\" in to clause\n",
130                                             fname, lineno, left );
131                                         acl_usage();
132                                 }
133
134                                 if ( strcasecmp( left, "filter" ) == 0 ) {
135                                         if ( (a->acl_filter = str2filter(
136                                             right )) == NULL ) {
137                                                 fprintf( stderr,
138                                 "%s: line %d: bad filter \"%s\" in to clause\n",
139                                                     fname, lineno, right );
140                                                 acl_usage();
141                                         }
142
143                                 } else if ( strcasecmp( left, "dn" ) == 0 ) {
144                                                 a->acl_dn_pat = ch_strdup( right );
145
146                                 } else if ( strncasecmp( left, "attr", 4 ) == 0 ) {
147                                         char    **alist;
148
149                                         alist = str2charray( right, "," );
150                                         charray_merge( &a->acl_attrs, alist );
151                                         charray_free( alist );
152
153                                 } else {
154                                         fprintf( stderr,
155                                                 "%s: line %d: expecting <what> got \"%s\"\n",
156                                             fname, lineno, left );
157                                         acl_usage();
158                                 }
159                         }
160
161                         if ( a->acl_dn_pat != NULL ) {
162                                 int e = regcomp( &a->acl_dn_re, a->acl_dn_pat,
163                                                  REG_EXTENDED | REG_ICASE );
164                                 if ( e ) {
165                                         char buf[512];
166                                         regerror( e, &a->acl_dn_re, buf, sizeof(buf) );
167                                         fprintf( stderr,
168                                 "%s: line %d: regular expression \"%s\" bad because of %s\n",
169                                                  fname, lineno, right, buf );
170                                         acl_usage();
171                                 }
172                         }
173
174                 /* by clause - select who has what access to entries */
175                 } else if ( strcasecmp( argv[i], "by" ) == 0 ) {
176                         if ( a == NULL ) {
177                                 fprintf( stderr,
178                                         "%s: line %d: to clause required before by clause in access line\n",
179                                     fname, lineno );
180                                 acl_usage();
181                         }
182
183                         /*
184                          * by clause consists of <who> and <access>
185                          */
186
187                         b = (Access *) ch_calloc( 1, sizeof(Access) );
188
189                         ACL_INVALIDATE( b->a_mask );
190
191                         if ( ++i == argc ) {
192                                 fprintf( stderr,
193                             "%s: line %d: premature eol: expecting <who>\n",
194                                     fname, lineno );
195                                 acl_usage();
196                         }
197
198                         /* get <who> */
199                         for ( ; i < argc; i++ ) {
200                                 char *pat;
201                                 split( argv[i], '=', &left, &right );
202
203                                 if ( strcasecmp( argv[i], "*" ) == 0 ) {
204                                         pat = ch_strdup( ".*" );
205                                 } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) {
206                                         pat = ch_strdup( "anonymous" );
207                                 } else if ( strcasecmp( argv[i], "self" ) == 0 ) {
208                                         pat = ch_strdup( "self" );
209                                 } else if ( strcasecmp( left, "dn" ) == 0 ) {
210                                         regtest(fname, lineno, right);
211                                         pat = ch_strdup( right );
212                                 } else {
213                                         pat = NULL;
214                                 }
215
216                                 if( pat != NULL ) {
217                                         if( b->a_dn_pat != NULL ) {
218                                                 fprintf( stderr,
219                                                     "%s: line %d: dn pattern already specified.\n",
220                                                     fname, lineno );
221                                                 acl_usage();
222                                         }
223
224                                         b->a_dn_pat = pat;
225                                         continue;
226                                 }
227
228                                 if ( strcasecmp( left, "dnattr" ) == 0 ) {
229                                         if( b->a_dn_pat != NULL ) {
230                                                 fprintf( stderr,
231                                                         "%s: line %d: dnaddr already specified.\n",
232                                                         fname, lineno );
233                                                 acl_usage();
234                                         }
235
236                                         b->a_dn_at = ch_strdup( right );
237                                         continue;
238                                 }
239
240                                 if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) {
241                                         char *name = NULL;
242                                         char *value = NULL;
243
244                                         if( b->a_group_pat != NULL ) {
245                                                 fprintf( stderr,
246                                                         "%s: line %d: group pattern already specified.\n",
247                                                         fname, lineno );
248                                                 acl_usage();
249                                         }
250
251                                         /* format of string is "group/objectClassValue/groupAttrName" */
252                                         if ((value = strchr(left, '/')) != NULL) {
253                                                 *value++ = '\0';
254                                                 if (value && *value
255                                                         && (name = strchr(value, '/')) != NULL)
256                                                 {
257                                                         *name++ = '\0';
258                                                 }
259                                         }
260
261                                         regtest(fname, lineno, right);
262                                         b->a_group_pat = ch_strdup( right );
263
264                                         if (value && *value) {
265                                                 b->a_group_oc = ch_strdup(value);
266                                                 *--value = '/';
267                                         } else {
268                                                 b->a_group_oc = ch_strdup("groupOfNames");
269
270                                                 if (name && *name) {
271                                                         b->a_group_at = ch_strdup(name);
272                                                         *--name = '/';
273
274                                                 } else {
275                                                         b->a_group_at = ch_strdup("member");
276                                                 }
277                                         }
278                                         continue;
279                                 }
280
281                                 if ( strcasecmp( left, "peername" ) == 0 ) {
282                                         if( b->a_peername_pat != NULL ) {
283                                                 fprintf( stderr,
284                                                         "%s: line %d: peername pattern already specified.\n",
285                                                         fname, lineno );
286                                                 acl_usage();
287                                         }
288
289                                         regtest(fname, lineno, right);
290                                         b->a_peername_pat = ch_strdup( right );
291                                         continue;
292                                 }
293
294                                 if ( strcasecmp( left, "sockname" ) == 0 ) {
295                                         if( b->a_sockname_pat != NULL ) {
296                                                 fprintf( stderr,
297                                                         "%s: line %d: sockname pattern already specified.\n",
298                                                         fname, lineno );
299                                                 acl_usage();
300                                         }
301
302                                         regtest(fname, lineno, right);
303                                         b->a_sockname_pat = ch_strdup( right );
304                                         continue;
305                                 }
306
307                                 if ( strcasecmp( left, "domain" ) == 0 ) {
308                                         if( b->a_domain_pat != NULL ) {
309                                                 fprintf( stderr,
310                                                         "%s: line %d: domain pattern already specified.\n",
311                                                         fname, lineno );
312                                                 acl_usage();
313                                         }
314
315                                         regtest(fname, lineno, right);
316                                         b->a_domain_pat = ch_strdup( right );
317                                         continue;
318                                 }
319
320                                 if ( strcasecmp( left, "sockurl" ) == 0 ) {
321                                         if( b->a_sockurl_pat != NULL ) {
322                                                 fprintf( stderr,
323                                                         "%s: line %d: sockurl pattern already specified.\n",
324                                                         fname, lineno );
325                                                 acl_usage();
326                                         }
327
328                                         regtest(fname, lineno, right);
329                                         b->a_sockurl_pat = ch_strdup( right );
330                                         continue;
331                                 }
332
333 #ifdef SLAPD_ACI_ENABLED
334                                 if ( strcasecmp( left, "aci" ) == 0 ) {
335                                         if( b->a_aci_at != NULL ) {
336                                                 fprintf( stderr,
337                                                         "%s: line %d: aci attribute already specified.\n",
338                                                         fname, lineno );
339                                                 acl_usage();
340                                         }
341
342                                         if ( right != NULL && *right != '\0' )
343                                                 b->a_aci_at = ch_strdup( right );
344                                         else
345                                                 b->a_aci_at = ch_strdup( SLAPD_ACI_DEFAULT_ATTR );
346                                         continue;
347                                 }
348 #endif
349
350                                 if( right != NULL ) {
351                                         /* unsplit */
352                                         right[-1] = '=';
353                                 }
354                                 break;
355                         }
356
357                         if( i == argc || ( strcasecmp( left, "stop" ) == 0 )) { 
358                                 /* out of arguments or plain stop */
359
360                                 ACL_PRIV_ASSIGN(b->a_mask, ACL_PRIV_ADDITIVE);
361                                 b->a_type = ACL_STOP;
362
363                                 access_append( &a->acl_access, b );
364                                 continue;
365                         }
366
367                         if( strcasecmp( left, "continue" ) == 0 ) {
368                                 /* plain continue */
369
370                                 ACL_PRIV_ASSIGN(b->a_mask, ACL_PRIV_ADDITIVE);
371                                 b->a_type = ACL_CONTINUE;
372
373                                 access_append( &a->acl_access, b );
374                                 continue;
375                         }
376
377                         if( strcasecmp( left, "break" ) == 0 ) {
378                                 /* plain continue */
379
380                                 ACL_PRIV_ASSIGN(b->a_mask, ACL_PRIV_ADDITIVE);
381                                 b->a_type = ACL_BREAK;
382
383                                 access_append( &a->acl_access, b );
384                                 continue;
385                         }
386
387                         if ( strcasecmp( left, "by" ) == 0 ) {
388                                 /* we've gone too far */
389                                 --i;
390                                 ACL_PRIV_ASSIGN(b->a_mask, ACL_PRIV_ADDITIVE);
391                                 b->a_type = ACL_STOP;
392
393                                 access_append( &a->acl_access, b );
394                                 continue;
395                         }
396
397                         /* get <access> */
398                         if( strncasecmp( left, "self", 4 ) == 0 ) {
399                                 b->a_dn_self = 1;
400                                 ACL_PRIV_ASSIGN( b->a_mask, str2accessmask( &left[4] ) );
401
402                         } else {
403                                 ACL_PRIV_ASSIGN( b->a_mask, str2accessmask( left ) );
404                         }
405
406                         if( ACL_IS_INVALID( b->a_mask ) ) {
407                                 fprintf( stderr,
408                                         "%s: line %d: expecting <access> got \"%s\"\n",
409                                         fname, lineno, left );
410                                 acl_usage();
411                         }
412
413                         b->a_type = ACL_STOP;
414
415                         if( ++i == argc ) {
416                                 /* out of arguments or plain stop */
417                                 access_append( &a->acl_access, b );
418                                 continue;
419                         }
420
421                         if( strcasecmp( argv[i], "continue" ) == 0 ) {
422                                 /* plain continue */
423                                 b->a_type = ACL_CONTINUE;
424
425                         } else if( strcasecmp( argv[i], "break" ) == 0 ) {
426                                 /* plain continue */
427                                 b->a_type = ACL_BREAK;
428
429                         } else if ( strcasecmp( argv[i], "stop" ) != 0 ) {
430                                 /* gone to far */
431                                 i--;
432                         }
433
434                         access_append( &a->acl_access, b );
435
436                 } else {
437                         fprintf( stderr,
438                     "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n",
439                             fname, lineno, argv[i] );
440                         acl_usage();
441                 }
442         }
443
444         /* if we have no real access clause, complain and do nothing */
445         if ( a == NULL ) {
446                         fprintf( stderr,
447                                 "%s: line %d: warning: no access clause(s) specified in access line\n",
448                             fname, lineno );
449
450         } else {
451
452 #ifdef LDAP_DEBUG
453                 if (ldap_debug & LDAP_DEBUG_ACL)
454                     print_acl(be, a);
455 #endif
456         
457                 if ( a->acl_access == NULL ) {
458                         fprintf( stderr,
459                         "%s: line %d: warning: no by clause(s) specified in access line\n",
460                             fname, lineno );
461                 }
462
463                 if ( be != NULL ) {
464                         acl_append( &be->be_acl, a );
465                 } else {
466                         acl_append( &global_acl, a );
467                 }
468         }
469 }
470
471 char *
472 accessmask2str( slap_access_mask_t mask )
473 {
474         static char     buf[sizeof("unknown (+wrsca0)")]; 
475         int none=1;
476
477         if ( ACL_IS_INVALID( mask ) ) {
478                 return "invalid";
479         }
480
481         buf[0] = '\0';
482
483         if ( ACL_IS_LEVEL( mask ) ) {
484                 if ( ACL_LVL_IS_NONE(mask) ) {
485                         strcat( buf, "none" );
486
487                 } else if ( ACL_LVL_IS_AUTH(mask) ) {
488                         strcat( buf, "auth" );
489
490                 } else if ( ACL_LVL_IS_COMPARE(mask) ) {
491                         strcat( buf, "compare" );
492
493                 } else if ( ACL_LVL_IS_SEARCH(mask) ) {
494                         strcat( buf, "search" );
495
496                 } else if ( ACL_LVL_IS_READ(mask) ) {
497                         strcat( buf, "read" );
498
499                 } else if ( ACL_LVL_IS_WRITE(mask) ) {
500                         strcat( buf, "write" );
501                 } else {
502                         strcat( buf, "unknown" );
503                 }
504                 
505                 strcat(buf, " (");
506         }
507
508         if( ACL_IS_ADDITIVE( mask ) ) {
509                 strcat( buf, "+" );
510
511         } else if( ACL_IS_SUBTRACTIVE( mask ) ) {
512                 strcat( buf, "-" );
513
514         } else {
515                 strcat( buf, "=" );
516         }
517
518         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_WRITE) ) {
519                 none = 0;
520                 strcat( buf, "w" );
521         } 
522
523         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_READ) ) {
524                 none = 0;
525                 strcat( buf, "r" );
526         } 
527
528         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_SEARCH) ) {
529                 none = 0;
530                 strcat( buf, "s" );
531         } 
532
533         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_COMPARE) ) {
534                 none = 0;
535                 strcat( buf, "c" );
536         } 
537
538         if ( ACL_PRIV_ISSET(mask, ACL_PRIV_AUTH) ) {
539                 none = 0;
540                 strcat( buf, "x" );
541         } 
542
543         if ( none && ACL_PRIV_ISSET(mask, ACL_PRIV_NONE) ) {
544                 none = 0;
545                 strcat( buf, "n" );
546         } 
547
548         if ( none ) {
549                 strcat( buf, "0" );
550         }
551
552         if ( ACL_IS_LEVEL( mask ) ) {
553                 strcat(buf, ")");
554         } 
555         return buf;
556 }
557
558 slap_access_mask_t
559 str2accessmask( const char *str )
560 {
561         slap_access_mask_t      mask;
562
563         if( !isalpha(str[0]) ) {
564                 int i;
565
566                 if ( str[0] == '=' ) {
567                         ACL_INIT(mask);
568
569                 } else if( str[0] == '+' ) {
570                         ACL_PRIV_ASSIGN(mask, ACL_PRIV_ADDITIVE);
571
572                 } else if( str[0] == '-' ) {
573                         ACL_PRIV_ASSIGN(mask, ACL_PRIV_SUBSTRACTIVE);
574
575                 } else {
576                         ACL_INVALIDATE(mask);
577                         return mask;
578                 }
579
580                 for( i=1; str[i] != '\0'; i++ ) {
581                         if( TOLOWER(str[i]) == 'w' ) {
582                                 ACL_PRIV_SET(mask, ACL_PRIV_WRITE);
583
584                         } else if( TOLOWER(str[i]) == 'r' ) {
585                                 ACL_PRIV_SET(mask, ACL_PRIV_READ);
586
587                         } else if( TOLOWER(str[i]) == 's' ) {
588                                 ACL_PRIV_SET(mask, ACL_PRIV_SEARCH);
589
590                         } else if( TOLOWER(str[i]) == 'c' ) {
591                                 ACL_PRIV_SET(mask, ACL_PRIV_COMPARE);
592
593                         } else if( TOLOWER(str[i]) == 'x' ) {
594                                 ACL_PRIV_SET(mask, ACL_PRIV_AUTH);
595
596                         } else if( str[i] != '0' ) {
597                                 ACL_INVALIDATE(mask);
598                                 return mask;
599                         }
600                 }
601
602                 return mask;
603         }
604
605         if ( strcasecmp( str, "none" ) == 0 ) {
606                 ACL_LVL_ASSIGN_NONE(mask);
607
608         } else if ( strcasecmp( str, "auth" ) == 0 ) {
609                 ACL_LVL_ASSIGN_AUTH(mask);
610
611         } else if ( strcasecmp( str, "compare" ) == 0 ) {
612                 ACL_LVL_ASSIGN_COMPARE(mask);
613
614         } else if ( strcasecmp( str, "search" ) == 0 ) {
615                 ACL_LVL_ASSIGN_SEARCH(mask);
616
617         } else if ( strcasecmp( str, "read" ) == 0 ) {
618                 ACL_LVL_ASSIGN_READ(mask);
619
620         } else if ( strcasecmp( str, "write" ) == 0 ) {
621                 ACL_LVL_ASSIGN_WRITE(mask);
622
623         } else {
624                 ACL_INVALIDATE( mask );
625         }
626
627         return mask;
628 }
629
630 static void
631 acl_usage( void )
632 {
633         fprintf( stderr, "\n"
634                 "<access clause> ::= access to <what> "
635                                 "[ by <who> <access> <control> ]+ \n"
636                 "<what> ::= * | [dn=<regex>] [filter=<ldapfilter>] [attrs=<attrlist>]\n"
637                 "<attrlist> ::= <attr> | <attr> , <attrlist>\n"
638                 "<attr> ::= <attrname> | entry | children\n"
639                 "<who> ::= [ * | anonymous | self | dn=<regex> ]\n"
640                         "\t[dnattr=<attrname>]\n"
641                         "\t[group[/<objectclass>[/<attrname>]]=<regex>]\n"
642                         "\t[peername=<regex>] [sockname=<regex>]\n"
643                         "\t[domain=<regex>] [sockurl=<regex>]\n"
644 #ifdef SLAPD_ACI_ENABLED
645                         "\t[aci=<attrname>]\n"
646 #endif
647                 "<access> ::= [self]{<level>|<priv>}\n"
648                 "<level> ::= none | auth | compare | search | read | write\n"
649                 "<priv> ::= {=|+|-}{w|r|s|c|x}+\n"
650                 "<control> ::= [ stop | continue | break ]\n"
651                 );
652         exit( EXIT_FAILURE );
653 }
654
655 static void
656 split(
657     char        *line,
658     int         splitchar,
659     char        **left,
660     char        **right
661 )
662 {
663         *left = line;
664         if ( (*right = strchr( line, splitchar )) != NULL ) {
665                 *((*right)++) = '\0';
666         }
667 }
668
669 static void
670 access_append( Access **l, Access *a )
671 {
672         for ( ; *l != NULL; l = &(*l)->a_next )
673                 ;       /* NULL */
674
675         *l = a;
676 }
677
678 void
679 acl_append( AccessControl **l, AccessControl *a )
680 {
681         for ( ; *l != NULL; l = &(*l)->acl_next )
682                 ;       /* NULL */
683
684         *l = a;
685 }
686
687 #ifdef LDAP_DEBUG
688
689 static void
690 print_access( Access *b )
691 {
692         fprintf( stderr, "\tby" );
693
694         if ( b->a_dn_pat != NULL ) {
695                 if( strcmp(b->a_dn_pat, "anonymous") == 0 ) {
696                         fprintf( stderr, " anonymous" );
697
698                 } else if( strcmp(b->a_dn_pat, "self") == 0 ) {
699                         fprintf( stderr, " self" );
700
701                 } else {
702                         fprintf( stderr, " dn=%s", b->a_dn_pat );
703                 }
704         }
705
706         if ( b->a_dn_at != NULL ) {
707                 fprintf( stderr, " dnattr=%s", b->a_dn_at );
708         }
709
710         if ( b->a_group_pat != NULL ) {
711                 fprintf( stderr, " group: %s", b->a_group_pat );
712
713                 if ( b->a_group_oc ) {
714                         fprintf( stderr, " objectClass: %s", b->a_group_oc );
715
716                         if ( b->a_group_at ) {
717                                 fprintf( stderr, " attributeType: %s", b->a_group_at );
718                         }
719                 }
720     }
721
722         if ( b->a_peername_pat != NULL ) {
723                 fprintf( stderr, " peername=%s", b->a_peername_pat );
724         }
725
726         if ( b->a_sockname_pat != NULL ) {
727                 fprintf( stderr, " sockname=%s", b->a_sockname_pat );
728         }
729
730         if ( b->a_domain_pat != NULL ) {
731                 fprintf( stderr, " domain=%s", b->a_domain_pat );
732         }
733
734         if ( b->a_sockurl_pat != NULL ) {
735                 fprintf( stderr, " sockurl=%s", b->a_sockurl_pat );
736         }
737
738 #ifdef SLAPD_ACI_ENABLED
739         if ( b->a_aci_at != NULL ) {
740                 fprintf( stderr, " aci=%s", b->a_aci_at );
741         }
742 #endif
743
744         fprintf( stderr, " %s%s",
745                 b->a_dn_self ? "self" : "",
746                 accessmask2str( b->a_mask ) );
747
748         if( b->a_type == ACL_BREAK ) {
749                 fprintf( stderr, " break" );
750
751         } else if( b->a_type == ACL_CONTINUE ) {
752                 fprintf( stderr, " continue" );
753
754         } else if( b->a_type != ACL_STOP ) {
755                 fprintf( stderr, " unknown-control" );
756         }
757
758         fprintf( stderr, "\n" );
759 }
760
761 char *
762 access2str( slap_access_t access )
763 {
764         if ( access == ACL_NONE ) {
765                 return "none";
766
767         } else if ( access == ACL_AUTH ) {
768                 return "auth";
769
770         } else if ( access == ACL_COMPARE ) {
771                 return "compare";
772
773         } else if ( access == ACL_SEARCH ) {
774                 return "search";
775
776         } else if ( access == ACL_READ ) {
777                 return "read";
778
779         } else if ( access == ACL_WRITE ) {
780                 return "write";
781         }
782
783         return "unknown";
784 }
785
786 slap_access_t
787 str2access( const char *str )
788 {
789         if ( strcasecmp( str, "none" ) == 0 ) {
790                 return ACL_NONE;
791
792         } else if ( strcasecmp( str, "auth" ) == 0 ) {
793                 return ACL_AUTH;
794
795         } else if ( strcasecmp( str, "compare" ) == 0 ) {
796                 return ACL_COMPARE;
797
798         } else if ( strcasecmp( str, "search" ) == 0 ) {
799                 return ACL_SEARCH;
800
801         } else if ( strcasecmp( str, "read" ) == 0 ) {
802                 return ACL_READ;
803
804         } else if ( strcasecmp( str, "write" ) == 0 ) {
805                 return ACL_WRITE;
806         }
807
808         return( ACL_INVALID_ACCESS );
809 }
810
811
812 static void
813 print_acl( Backend *be, AccessControl *a )
814 {
815         int             to = 0;
816         Access  *b;
817
818         fprintf( stderr, "%s ACL: access to",
819                 be == NULL ? "Global" : "Backend" );
820
821         if ( a->acl_dn_pat != NULL ) {
822                 to++;
823                 fprintf( stderr, " dn=%s\n",
824                         a->acl_dn_pat );
825         }
826
827         if ( a->acl_filter != NULL ) {
828                 to++;
829                 fprintf( stderr, " filter=" );
830                 filter_print( a->acl_filter );
831                 fprintf( stderr, "\n" );
832         }
833
834         if ( a->acl_attrs != NULL ) {
835                 int     i, first = 1;
836                 to++;
837
838                 fprintf( stderr, " attrs=" );
839                 for ( i = 0; a->acl_attrs[i] != NULL; i++ ) {
840                         if ( ! first ) {
841                                 fprintf( stderr, "," );
842                         }
843                         fprintf( stderr, a->acl_attrs[i] );
844                         first = 0;
845                 }
846                 fprintf(  stderr, "\n" );
847         }
848
849         if( !to ) {
850                 fprintf( stderr, " *\n" );
851         }
852
853         for ( b = a->acl_access; b != NULL; b = b->a_next ) {
854                 print_access( b );
855         }
856
857         fprintf( stderr, "\n" );
858 }
859
860 #endif /* LDAP_DEBUG */