Author: rhafer Date: Tue Sep 2 10:32:51 2008 New Revision: 50546 URL: http://svn.opensuse.org/viewcvs/yast?rev=50546&view=rev Log: parsing "by"-clauses Modified: trunk/ldap-server/src/lib/slapd-config.cpp Modified: trunk/ldap-server/src/lib/slapd-config.cpp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/slapd-config.cpp?rev=50546&r1=50545&r2=50546&view=diff ============================================================================== --- trunk/ldap-server/src/lib/slapd-config.cpp (original) +++ trunk/ldap-server/src/lib/slapd-config.cpp Tue Sep 2 10:32:51 2008 @@ -476,6 +476,43 @@ return this->m_type; } +static int extractAlcToken( const std::string& acl, std::string::size_type& startpos, bool quoted ) +{ + std::string::size_type pos; + + // skip leading whitespaces + startpos = acl.find_first_not_of("\t ", startpos ); + + if ( quoted && acl[startpos] == '"' ) + { + // find matching (unescapted) quote + startpos++; + pos = startpos; + bool found=false; + while( ! found ) + { + pos = acl.find_first_of('"', pos+1 ); + if ( pos == std::string::npos ) + { + break; + } + if ( acl[pos-1] != '\\' ) + { + found = true; + } + } + if ( !found ) + { + log_it(SLAPD_LOG_ERR, "Not matching quote found" ); + } + } + else + { + pos = acl.find_first_of("\t ", startpos ); + } + return pos; +} + void OlcDatabase::getAcl() const { const LDAPAttribute* aclAttr = m_dbEntryChanged.getAttributeByName("olcAccess"); @@ -510,6 +547,8 @@ if ( aclString[spos] == '*' ) { log_it(SLAPD_LOG_ERR, "acl matches all entries" ); + spos = tmppos+1; + tmppos = extractAlcToken( aclString, spos, true ); } else { @@ -529,43 +568,61 @@ break; } spos = tmppos+1; - tmppos = aclString.find_first_not_of("\t ", spos ); - // is this a quoted string ? - if ( aclString[tmppos] == '"' ) + + tmppos = extractAlcToken( aclString, spos, true ); + + log_it(SLAPD_LOG_INFO, "Whatvalue: " + aclString.substr(spos, tmppos-spos) ); + spos = aclString.find_first_not_of("\t ", tmppos+1 ); + } + } + } + // we should have reached the "by"-clauses now + while ( true ) + { + if ( aclString.substr(spos, tmppos-spos) != "by" ) + { + break; + } + else + { + spos = tmppos+1; + // skip whitespaces + tmppos = aclString.find_first_not_of("\t ", spos ); + if ( tmppos != std::string::npos && tmppos > spos ) + { + spos = tmppos; + } + + // we should be at the start of the "by" part now, might `*` + // or a string followed by '=' + if ( aclString[spos] == '*' ) + { + log_it(SLAPD_LOG_ERR, "by clause matches all entries" ); + } + tmppos = aclString.find_first_of("=\t ", spos ); + if ( tmppos == std::string::npos ) + { + log_it(SLAPD_LOG_ERR, "Unexpected end of ACL" ); + break; + } + else + { + log_it(SLAPD_LOG_INFO, "bytype: " + aclString.substr(spos, tmppos-spos) ); + if ( aclString[tmppos] == '=' ) { - // find matching (unescapted) quote spos = tmppos+1; - bool found=false; - while( ! found ) - { - tmppos = aclString.find_first_of('"', tmppos+1 ); - if ( tmppos == std::string::npos ) - { - break; - } - if ( aclString[tmppos-1] != '\\' ) - { - found = true; - } - } - if ( !found ) - { - log_it(SLAPD_LOG_ERR, "Not matching quote found" ); - break; - } + tmppos = extractAlcToken( aclString, spos, true ); + // is this a quoted string ? + log_it(SLAPD_LOG_INFO, "byvalue: " + aclString.substr(spos, tmppos-spos) ); } - else - { - spos = tmppos; - tmppos = aclString.find_first_of("\t ", spos ); - } - log_it(SLAPD_LOG_INFO, "Whatvalue: " + aclString.substr(spos, tmppos-spos) ); + spos = tmppos+1; + tmppos = extractAlcToken( aclString, spos, false ); + log_it(SLAPD_LOG_INFO, "access: " + aclString.substr(spos, tmppos-spos) ); spos = aclString.find_first_not_of("\t ", tmppos+1 ); + tmppos = aclString.find_first_of("\t ", spos ); } } - // we should have reached the "by"-clauses now } - } } } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org