X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Faclparse.c;h=6a291fd2b127bf6cd308c3bb6e8c8704e5627ba6;hb=18393e882cd89e461fc804b8ef58817027e465a1;hp=f6e5d29ed369ddb1862e681098f64a3c51792d84;hpb=e2ee741ea86edb97a08b3f217760f1cd5972302e;p=openldap diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index f6e5d29ed3..6a291fd2b1 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -13,12 +13,12 @@ #include "slap.h" static void split(char *line, int splitchar, char **left, char **right); -static void acl_append(struct acl **l, struct acl *a); -static void access_append(struct access **l, struct access *a); +static void acl_append(AccessControl **l, AccessControl *a); +static void access_append(Access **l, Access *a); static void acl_usage(void); #ifdef LDAP_DEBUG -static void print_acl(struct acl *a); -static void print_access(struct access *b); +static void print_acl(AccessControl *a); +static void print_access(Access *b); #endif static int @@ -87,9 +87,9 @@ parse_acl( ) { int i; - char *e, *left, *right; - struct acl *a; - struct access *b; + char *left, *right; + AccessControl *a; + Access *b; a = NULL; for ( i = 1; i < argc; i++ ) { @@ -101,7 +101,7 @@ parse_acl( fname, lineno ); acl_usage(); } - a = (struct acl *) ch_calloc( 1, sizeof(struct acl) ); + a = (AccessControl *) ch_calloc( 1, sizeof(AccessControl) ); for ( ++i; i < argc; i++ ) { if ( strcasecmp( argv[i], "by" ) == 0 ) { i--; @@ -109,18 +109,7 @@ parse_acl( } if ( strcasecmp( argv[i], "*" ) == 0 ) { - int e; - if ((e = regcomp( &a->acl_dnre, ".*", - REG_EXTENDED|REG_ICASE))) - { - char buf[512]; - regerror(e, &a->acl_dnre, buf, sizeof(buf)); - fprintf( stderr, - "%s: line %d: regular expression \"%s\" bad because of %s\n", - fname, lineno, right, buf ); - acl_usage(); - } - a->acl_dnpat = ch_strdup( ".*" ); + a->acl_dn_pat = ch_strdup( ".*" ); continue; } @@ -140,27 +129,30 @@ parse_acl( fname, lineno, right ); acl_usage(); } + } else if ( strcasecmp( left, "dn" ) == 0 ) { int e; - if ((e = regcomp(&a->acl_dnre, right, + + if ((e = regcomp(&a->acl_dn_re, right, REG_EXTENDED|REG_ICASE))) { char buf[512]; - regerror(e, &a->acl_dnre, buf, sizeof(buf)); + regerror(e, &a->acl_dn_re, buf, sizeof(buf)); fprintf( stderr, "%s: line %d: regular expression \"%s\" bad because of %s\n", fname, lineno, right, buf ); acl_usage(); } else { - a->acl_dnpat = dn_upcase(ch_strdup( right )); + a->acl_dn_pat = ch_strdup( right ); } - } else if ( strncasecmp( left, "attr", 4 ) - == 0 ) { + + } else if ( strncasecmp( left, "attr", 4 ) == 0 ) { char **alist; alist = str2charray( right, "," ); charray_merge( &a->acl_attrs, alist ); - free( alist ); + charray_free( alist ); + } else { fprintf( stderr, "%s: line %d: expecting got \"%s\"\n", @@ -181,8 +173,7 @@ parse_acl( * by clause consists of and */ - b = (struct access *) ch_calloc( 1, - sizeof(struct access) ); + b = (Access *) ch_calloc( 1, sizeof(Access) ); if ( ++i == argc ) { fprintf( stderr, @@ -192,86 +183,150 @@ parse_acl( } /* get */ - split( argv[i], '=', &left, &right ); - if ( strcasecmp( argv[i], "*" ) == 0 ) { - b->a_dnpat = ch_strdup( ".*" ); - } else if ( strcasecmp( argv[i], "self" ) == 0 ) { - b->a_dnpat = ch_strdup( "self" ); - } else if ( strcasecmp( left, "dn" ) == 0 ) { - regtest(fname, lineno, right); - b->a_dnpat = dn_upcase( ch_strdup( right ) ); - } else if ( strcasecmp( left, "dnattr" ) == 0 ) { - b->a_dnattr = ch_strdup( right ); - -#ifdef SLAPD_ACLGROUPS - } else if ( strcasecmp( left, "group" ) == 0 ) { - char *name = NULL; - char *value = NULL; - regtest(fname, lineno, right); - - /* format of string is "group/objectClassValue/groupAttrName" - */ - if ((value = strchr(right, '/')) != NULL) { - *value++ = '\0'; - if (value && *value && (name = strchr(value, '/')) != NULL) - *name++ = '\0'; - } - - b->a_group = dn_upcase(ch_strdup( right )); - - if (value && *value) { - b->a_objectclassvalue = ch_strdup(value); - *--value = '/'; - } - else - b->a_objectclassvalue = ch_strdup("groupOfNames"); - - if (name && *name) { - b->a_groupattrname = ch_strdup(name); - *--name = '/'; - } - else - b->a_groupattrname = ch_strdup("member"); - - - -#endif /* SLAPD_ACLGROUPS */ - } else if ( strcasecmp( left, "domain" ) == 0 ) { - char *s; - regtest(fname, lineno, right); - b->a_domainpat = ch_strdup( right ); - - /* normalize the domain */ - for ( s = b->a_domainpat; *s; s++ ) { - *s = TOLOWER( *s ); + for ( ; i < argc; i++ ) { + char *pat; + split( argv[i], '=', &left, &right ); + + if ( strcasecmp( argv[i], "*" ) == 0 ) { + pat = ch_strdup( ".*" ); + } else if ( strcasecmp( argv[i], "anonymous" ) == 0 ) { + pat = ch_strdup( "anonymous" ); + } else if ( strcasecmp( argv[i], "self" ) == 0 ) { + pat = ch_strdup( "self" ); + } else if ( strcasecmp( left, "dn" ) == 0 ) { + regtest(fname, lineno, right); + pat = ch_strdup( right ); + } else { + pat = NULL; } - } else if ( strcasecmp( left, "addr" ) == 0 ) { - regtest(fname, lineno, right); - b->a_addrpat = ch_strdup( right ); - } else { - fprintf( stderr, - "%s: line %d: expecting got \"%s\"\n", - fname, lineno, left ); - acl_usage(); - } - if ( ++i == argc ) { - fprintf( stderr, - "%s: line %d: premature eol: expecting \n", - fname, lineno ); - acl_usage(); - } + if( pat != NULL ) { + if( b->a_dn_pat != NULL ) { + fprintf( stderr, + "%s: line %d: dn pattern already specified.\n", + fname, lineno ); + acl_usage(); + } - /* get */ - split( argv[i], '=', &left, &right ); - if ( (b->a_access = str2access( left )) == -1 ) { - fprintf( stderr, - "%s: line %d: expecting got \"%s\"\n", - fname, lineno, left ); - acl_usage(); - } - access_append( &a->acl_access, b ); + b->a_dn_pat = pat; + continue; + } + + if ( strcasecmp( left, "dnattr" ) == 0 ) { + if( b->a_dn_pat != NULL ) { + fprintf( stderr, + "%s: line %d: dnaddr already specified.\n", + fname, lineno ); + acl_usage(); + } + + b->a_dn_at = ch_strdup( right ); + continue; + } + if ( strncasecmp( left, "group", sizeof("group")-1 ) == 0 ) { + char *name = NULL; + char *value = NULL; + + if( b->a_group_pat != NULL ) { + fprintf( stderr, + "%s: line %d: group pattern already specified.\n", + fname, lineno ); + acl_usage(); + } + + /* format of string is "group/objectClassValue/groupAttrName" */ + if ((value = strchr(left, '/')) != NULL) { + *value++ = '\0'; + if (value && *value + && (name = strchr(value, '/')) != NULL) + { + *name++ = '\0'; + } + } + + regtest(fname, lineno, right); + b->a_group_pat = ch_strdup( right ); + + if (value && *value) { + b->a_group_oc = ch_strdup(value); + *--value = '/'; + } else { + b->a_group_oc = ch_strdup("groupOfNames"); + + if (name && *name) { + b->a_group_at = ch_strdup(name); + *--name = '/'; + + } else { + b->a_group_at = ch_strdup("member"); + } + } + continue; + } + + if ( strcasecmp( left, "peername" ) == 0 ) { + if( b->a_peername_pat != NULL ) { + fprintf( stderr, + "%s: line %d: peername pattern already specified.\n", + fname, lineno ); + acl_usage(); + } + + regtest(fname, lineno, right); + b->a_peername_pat = ch_strdup( right ); + continue; + } + + if ( strcasecmp( left, "sockname" ) == 0 ) { + if( b->a_sockname_pat != NULL ) { + fprintf( stderr, + "%s: line %d: sockname pattern already specified.\n", + fname, lineno ); + acl_usage(); + } + + regtest(fname, lineno, right); + b->a_sockname_pat = ch_strdup( right ); + continue; + } + + if ( strcasecmp( left, "domain" ) == 0 ) { + if( b->a_domain_pat != NULL ) { + fprintf( stderr, + "%s: line %d: domain pattern already specified.\n", + fname, lineno ); + acl_usage(); + } + + regtest(fname, lineno, right); + b->a_domain_pat = ch_strdup( right ); + continue; + } + + if ( strcasecmp( left, "sockurl" ) == 0 ) { + if( b->a_sockurl_pat != NULL ) { + fprintf( stderr, + "%s: line %d: sockurl pattern already specified.\n", + fname, lineno ); + acl_usage(); + } + + regtest(fname, lineno, right); + b->a_sockurl_pat = ch_strdup( right ); + continue; + } + + /* get */ + if ( ACL_IS_INVALID(ACL_SET(b->a_access, str2access( left ))) ) { + fprintf( stderr, + "%s: line %d: expecting got \"%s\"\n", + fname, lineno, left ); + acl_usage(); + } + access_append( &a->acl_access, b ); + break; + } } else { fprintf( stderr, "%s: line %d: expecting \"to\" or \"by\" got \"%s\"\n", @@ -312,22 +367,25 @@ access2str( int access ) { static char buf[12]; - if ( access & ACL_SELF ) { + if ( ACL_IS_SELF( access ) ) { strcpy( buf, "self" ); } else { buf[0] = '\0'; } - if ( access & ACL_NONE ) { + if ( ACL_IS_NONE(access) ) { strcat( buf, "none" ); - } else if ( access & ACL_COMPARE ) { + } else if ( ACL_IS_AUTH(access) ) { + strcat( buf, "auth" ); + } else if ( ACL_IS_COMPARE(access) ) { strcat( buf, "compare" ); - } else if ( access & ACL_SEARCH ) { + } else if ( ACL_IS_SEARCH(access) ) { strcat( buf, "search" ); - } else if ( access & ACL_READ ) { + } else if ( ACL_IS_READ(access) ) { strcat( buf, "read" ); - } else if ( access & ACL_WRITE ) { + } else if ( ACL_IS_WRITE(access) ) { strcat( buf, "write" ); + } else { strcat( buf, "unknown" ); } @@ -340,24 +398,27 @@ str2access( char *str ) { int access; - access = 0; + ACL_CLR(access); + if ( strncasecmp( str, "self", 4 ) == 0 ) { - access |= ACL_SELF; + ACL_SET_SELF(access); str += 4; } if ( strcasecmp( str, "none" ) == 0 ) { - access |= ACL_NONE; + ACL_SET_NONE(access); + } else if ( strcasecmp( str, "auth" ) == 0 ) { + ACL_SET_AUTH(access); } else if ( strcasecmp( str, "compare" ) == 0 ) { - access |= ACL_COMPARE; + ACL_SET_COMPARE(access); } else if ( strcasecmp( str, "search" ) == 0 ) { - access |= ACL_SEARCH; + ACL_SET_SEARCH(access); } else if ( strcasecmp( str, "read" ) == 0 ) { - access |= ACL_READ; + ACL_SET_READ(access); } else if ( strcasecmp( str, "write" ) == 0 ) { - access |= ACL_WRITE; + ACL_SET_WRITE(access); } else { - access = -1; + ACL_SET_INVALID(access); } return( access ); @@ -366,12 +427,18 @@ str2access( char *str ) static void acl_usage( void ) { - fprintf( stderr, "\n ::= access to [ by ]+ \n" ); - fprintf( stderr, " ::= * | [dn=] [filter=] [attrs=]\n" ); - fprintf( stderr, " ::= | , \n" ); - fprintf( stderr, " ::= | entry | children\n" ); - fprintf( stderr, " ::= * | self | dn= | addr= |\n\tdomain= | dnattr=\n" ); - fprintf( stderr, " ::= [self]{none | compare | search | read | write }\n" ); + fprintf( stderr, "\n" + " ::= access to [ by ]+ \n" + " ::= * | [dn=] [filter=] [attrs=]\n" + " ::= | , \n" + " ::= | entry | children\n" + " ::= [ * | anonymous | self | dn= ]\n" + "\t[dnattr=]\n" + "\t[group[/[/]]=]\n" + "\t[peername=] [sockname=]\n" + "\t[domain=] [sockurl=]\n" + " ::= [self]{none|auth|compare|search|read|write}\n" + ); exit( 1 ); } @@ -390,7 +457,7 @@ split( } static void -access_append( struct access **l, struct access *a ) +access_append( Access **l, Access *a ) { for ( ; *l != NULL; l = &(*l)->a_next ) ; /* NULL */ @@ -399,7 +466,7 @@ access_append( struct access **l, struct access *a ) } static void -acl_append( struct acl **l, struct acl *a ) +acl_append( AccessControl **l, AccessControl *a ) { for ( ; *l != NULL; l = &(*l)->acl_next ) ; /* NULL */ @@ -410,35 +477,61 @@ acl_append( struct acl **l, struct acl *a ) #ifdef LDAP_DEBUG static void -print_access( struct access *b ) +print_access( Access *b ) { - printf( "\tby" ); - if ( b->a_dnpat != NULL ) { - fprintf( stderr, " dn=%s", b->a_dnpat ); - } else if ( b->a_addrpat != NULL ) { - fprintf( stderr, " addr=%s", b->a_addrpat ); - } else if ( b->a_domainpat != NULL ) { - fprintf( stderr, " domain=%s", b->a_domainpat ); - } else if ( b->a_dnattr != NULL ) { - fprintf( stderr, " dnattr=%s", b->a_dnattr ); + fprintf( stderr, "\tby" ); + + if ( b->a_dn_pat != NULL ) { + if( strcmp(b->a_dn_pat, "anonymous") == 0 ) { + fprintf( stderr, " anonymous" ); + + } else if( strcmp(b->a_dn_pat, "self") == 0 ) { + fprintf( stderr, " self" ); + + } else { + fprintf( stderr, " dn=%s", b->a_dn_pat ); + } } -#ifdef SLAPD_ACLGROUPS - else if ( b->a_group != NULL ) { - fprintf( stderr, " group: %s", b->a_group ); - if ( b->a_objectclassvalue ) - fprintf( stderr, " objectClassValue: %s", b->a_objectclassvalue ); - if ( b->a_groupattrname ) - fprintf( stderr, " groupAttrName: %s", b->a_groupattrname ); - } -#endif + + if ( b->a_dn_at != NULL ) { + fprintf( stderr, " dnattr=%s", b->a_dn_at ); + } + + if ( b->a_group_pat != NULL ) { + fprintf( stderr, " group: %s", b->a_group_pat ); + + if ( b->a_group_oc ) { + fprintf( stderr, " objectClass: %s", b->a_group_oc ); + + if ( b->a_group_at ) { + fprintf( stderr, " attributeType: %s", b->a_group_at ); + } + } + } + + if ( b->a_peername_pat != NULL ) { + fprintf( stderr, " peername=%s", b->a_peername_pat ); + } + if ( b->a_sockname_pat != NULL ) { + fprintf( stderr, " sockname=%s", b->a_sockname_pat ); + } + + if ( b->a_domain_pat != NULL ) { + fprintf( stderr, " domain=%s", b->a_domain_pat ); + } + + if ( b->a_sockurl_pat != NULL ) { + fprintf( stderr, " sockurl=%s", b->a_sockurl_pat ); + } + fprintf( stderr, "\n" ); } static void -print_acl( struct acl *a ) +print_acl( AccessControl *a ) { int i; - struct access *b; + Access *b; if ( a == NULL ) { fprintf( stderr, "NULL\n" ); @@ -448,9 +541,9 @@ print_acl( struct acl *a ) fprintf( stderr," filter=" ); filter_print( a->acl_filter ); } - if ( a->acl_dnpat != NULL ) { + if ( a->acl_dn_pat != NULL ) { fprintf( stderr, " dn=" ); - fprintf( stderr, a->acl_dnpat ); + fprintf( stderr, a->acl_dn_pat ); } if ( a->acl_attrs != NULL ) { int first = 1;