From ff682be26e0ed05d1ccfc75961844462dd73a815 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 15 Dec 2001 12:41:53 +0000 Subject: [PATCH] Added acl_destroy, acl_free. --- servers/slapd/aclparse.c | 56 ++++++++++++++++++++++++++++++++++++++ servers/slapd/backend.c | 1 + servers/slapd/config.c | 1 + servers/slapd/proto-slap.h | 2 ++ 4 files changed, 60 insertions(+) diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index 00c93c23b1..eaf3e0cdac 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -1217,6 +1217,62 @@ acl_append( AccessControl **l, AccessControl *a ) *l = a; } +static void +access_free( Access *a ) +{ + if ( a->a_dn_pat ) + free ( a->a_dn_pat ); + if ( a->a_peername_pat ) + free ( a->a_peername_pat ); + if ( a->a_sockname_pat ) + free ( a->a_sockname_pat ); + if ( a->a_domain_pat ) + free ( a->a_domain_pat ); + if ( a->a_sockurl_pat ) + free ( a->a_sockurl_pat ); + if ( a->a_set_pat ) + free ( a->a_set_pat ); + if ( a->a_group_pat ) + free ( a->a_group_pat ); + free( a ); +} + +void +acl_free( AccessControl *a ) +{ + Access *n; + + if ( a->acl_filter ) + filter_free( a->acl_filter ); + if ( a->acl_dn_pat ) + free ( a->acl_dn_pat ); + if ( a->acl_attrs ) + charray_free( a->acl_attrs ); + for (; a->acl_access; a->acl_access = n) { + n = a->acl_access->a_next; + access_free( a->acl_access ); + } + free( a ); +} + +/* Because backend_startup uses acl_append to tack on the global_acl to + * the end of each backend's acl, we cannot just take one argument and + * merrily free our way to the end of the list. backend_destroy calls us + * with the be_acl in arg1, and global_acl in arg2 to give us a stopping + * point. config_destroy calls us with global_acl in arg1 and NULL in + * arg2, so we then proceed to polish off the global_acl. + */ +void +acl_destroy( AccessControl *a, AccessControl *end ) +{ + AccessControl *n; + + for (; a && a!= end; a=n) { + n = a->acl_next; + acl_free( a ); + } +} + char * access2str( slap_access_t access ) { diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 5398d8e21d..6054ff89e2 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -422,6 +422,7 @@ int backend_destroy(void) free( backendDB[i].be_root_dn ); free( backendDB[i].be_root_ndn ); free( backendDB[i].be_root_pw.bv_val ); + acl_destroy( backendDB[i].be_acl, global_acl ); } free( backendDB ); diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 1cbb00fcf3..52eca16169 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -2382,4 +2382,5 @@ config_destroy( ) free ( slapd_args_file ); if ( slapd_pid_file ) free ( slapd_pid_file ); + acl_destroy( global_acl, NULL ); } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 5571ec2fb6..7b3c9a088b 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -81,6 +81,8 @@ LDAP_SLAPD_F (slap_access_t) str2access LDAP_P(( const char *str )); #define ACCESSMASK_MAXLEN sizeof("unknown (+wrscan)") LDAP_SLAPD_F (char *) accessmask2str LDAP_P(( slap_mask_t mask, char* )); LDAP_SLAPD_F (slap_mask_t) str2accessmask LDAP_P(( const char *str )); +LDAP_SLAPD_F (void) acl_destroy LDAP_P(( AccessControl*, AccessControl* )); +LDAP_SLAPD_F (void) acl_free LDAP_P(( AccessControl *a )); /* * at.c -- 2.39.5