Author: rhafer
Date: Tue Sep 2 10:32:43 2008
New Revision: 50544
URL: http://svn.opensuse.org/viewcvs/yast?rev=50544&view=rev
Log:
regroup methods (reformat patch, no real code changes)
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=50544&r1=50543&r2=50544&view=diff
==============================================================================
--- trunk/ldap-server/src/lib/slapd-config.cpp (original)
+++ trunk/ldap-server/src/lib/slapd-config.cpp Tue Sep 2 10:32:43 2008
@@ -21,14 +21,6 @@
-static void defaultLogCallback( int level, const std::string &msg,
- const char* file=0, const int line=0, const char* function=0)
-{
- std::cerr << msg << std::endl;
-}
-
-SlapdConfigLogCallback *OlcConfig::logCallback = defaultLogCallback;
-
#define log_it( level, string ) \
OlcConfig::logCallback( level, string, __FILE__, __LINE__ , __FUNCTION__ )
@@ -62,929 +54,1025 @@
return false;
}
+bool OlcConfigEntry::isDatabaseEntry ( const LDAPEntry& e )
+{
+ StringList oc = e.getAttributeByName("objectclass")->getValues();
+ for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
+ {
+ if ( strCaseIgnoreEquals(*i, "olcDatabaseConfig" ) )
+ {
+ return true;
+ }
+ }
+ return false;
+}
-OlcDatabase::OlcDatabase( const LDAPEntry& le=LDAPEntry()) : OlcConfigEntry(le)
+bool OlcConfigEntry::isGlobalEntry ( const LDAPEntry& e )
{
- std::string type(this->getStringValue("olcdatabase"));
- entryIndex = splitIndexFromString( type, m_type );
+ StringList oc = e.getAttributeByName("objectclass")->getValues();
+ for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
+ {
+ if ( strCaseIgnoreEquals(*i, "olcGlobal" ) )
+ {
+ return true;
+ }
+ }
+ return false;
}
-OlcDatabase::OlcDatabase( const std::string& type ) : m_type(type)
+bool OlcConfigEntry::isOverlayEntry ( const LDAPEntry& e )
{
- std::ostringstream dnstr;
- dnstr << "olcDatabase=" << m_type << ",cn=config";
- m_dbEntryChanged.setDN(dnstr.str());
- m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcDatabaseConfig"));
- m_dbEntryChanged.addAttribute(LDAPAttribute("olcDatabase", m_type));
+ StringList oc = e.getAttributeByName("objectclass")->getValues();
+ for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
+ {
+ if ( strCaseIgnoreEquals(*i, "olcOverlayConfig" ) )
+ {
+ return true;
+ }
+ }
+ return false;
}
-void OlcDatabase::updateEntryDn(bool origEntry )
+bool OlcConfigEntry::isScheamEntry ( const LDAPEntry& e )
{
- log_it(SLAPD_LOG_INFO, "updateEntryDN()");
- std::ostringstream dn, name;
- name << "{" << entryIndex << "}" << m_type;
- dn << "olcDatabase=" << name.str() << ",cn=config" ;
- m_dbEntryChanged.setDN(dn.str());
- m_dbEntryChanged.replaceAttribute(LDAPAttribute("olcDatabase", name.str()));
- if ( origEntry && (! m_dbEntry.getDN().empty()) )
+ StringList oc = e.getAttributeByName("objectclass")->getValues();
+ for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
{
- m_dbEntry.setDN(dn.str());
- m_dbEntry.replaceAttribute(LDAPAttribute("olcDatabase", name.str()));
+ if ( strCaseIgnoreEquals(*i, "olcSchemaConfig" ) )
+ {
+ return true;
+ }
}
+ return false;
}
-OlcBdbDatabase::OlcBdbDatabase( const std::string& type ) : OlcDatabase(type)
-{
- if ( type == "hdb" )
+OlcConfigEntry* OlcConfigEntry::createFromLdapEntry( const LDAPEntry& e )
+{
+ if ( OlcConfigEntry::isGlobalEntry(e) )
{
- m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcHdbConfig"));
+ log_it(SLAPD_LOG_INFO,"creating OlcGlobalConfig" );
+ return new OlcGlobalConfig(e);
+ }
+ else if ( OlcConfigEntry::isScheamEntry(e) )
+ {
+ log_it(SLAPD_LOG_INFO,"creating OlcSchemaConfig" );
+ return new OlcSchemaConfig(e);
+ }
+ else if ( OlcConfigEntry::isDatabaseEntry(e) )
+ {
+ log_it(SLAPD_LOG_INFO,"creating OlcDatabase" );;
+ return OlcDatabase::createFromLdapEntry(e);
+ }
+ else if ( OlcConfigEntry::isOverlayEntry(e) )
+ {
+ log_it(SLAPD_LOG_INFO,"creating OlcOverlay");
+ return new OlcConfigEntry(e);
}
else
{
- m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcBdbConfig"));
+ log_it(SLAPD_LOG_INFO,"unknown Config Object" );
+ return 0;
}
}
-OlcBdbDatabase::OlcBdbDatabase( const LDAPEntry& le) : OlcDatabase(le) { }
-
-inline void splitIndexString( const std::string &indexString, std::string &attr, std::string &indexes )
+void OlcConfigEntry::setIndex( int index, bool origEntry )
{
- std::string::size_type pos = indexString.find_first_of(" \t");
- attr = indexString.substr(0, pos);
- log_it(SLAPD_LOG_DEBUG, "AttributeType: " + attr );
- if ( pos != std::string::npos ) {
- pos = indexString.find_first_not_of(" \t", pos);
- if ( pos != std::string::npos ) {
- indexes = indexString.substr( pos, std::string::npos );
- }
- }
+ this->entryIndex = index;
+ this->updateEntryDn( origEntry );
}
-inline std::vector<IndexType> indexString2Type( const std::string &indexes )
+int OlcConfigEntry::getEntryIndex() const
{
- std::string::size_type pos, oldpos = 0;
- std::vector<IndexType> idx;
- do {
- pos = indexes.find( ',', oldpos );
- std::string index = indexes.substr( oldpos,
- (pos == std::string::npos ? std::string::npos : pos - oldpos) );
- log_it(SLAPD_LOG_INFO, std::string("Index: ") + index );
- oldpos = indexes.find_first_not_of( ", ", pos );
- if ( index == "pres" ) {
- idx.push_back(Present);
- } else if (index == "eq" ) {
- idx.push_back(Eq);
- } else if (index == "approx" ) {
- idx.push_back(Approx);
- } else if (index == "sub" ) {
- idx.push_back(Sub);
- } else if (index == "subinital" ) {
- idx.push_back(SpecialSubInitial);
- } else if (index == "subany" ) {
- idx.push_back(SpecialSubAny);
- } else if (index == "subfinal" ) {
- idx.push_back(SpecialSubFinal);
- } else if (index == "nolang" ) {
- idx.push_back(SpecialNoLang);
- } else if (index == "nosubtypes" ) {
- idx.push_back(SpecialNoSubTypes);
- }
- } while (pos != std::string::npos);
- return idx;
+ return this->entryIndex;
}
-IndexMap OlcBdbDatabase::getDatabaseIndexes() const
+void OlcConfigEntry::updateEntryDn( bool origEntry )
{
- const LDAPAttributeList *al = m_dbEntryChanged.getAttributes();
- const LDAPAttribute *attr = al->getAttributeByName("olcdbindex");
- IndexMap res;
- if (! attr ) {
- return res;
- };
-
- StringList sl = attr->getValues();
- StringList::const_iterator i;
- for (i = sl.begin(); i != sl.end(); i++ ) {
- std::string attrType;
- std::string indexes;
- splitIndexString(*i, attrType, indexes );
- log_it(SLAPD_LOG_INFO, "Indexes: " + indexes );
- std::vector<IndexType> idx = indexString2Type(indexes);
- res.insert(make_pair(attrType, idx));
- }
- return res;
}
-std::vector<IndexType> OlcBdbDatabase::getDatabaseIndex( const std::string &type ) const
+void OlcConfigEntry::clearChangedEntry()
{
- const LDAPAttributeList *al = m_dbEntryChanged.getAttributes();
- const LDAPAttribute *attr = al->getAttributeByName("olcdbindex");
- std::vector<IndexType> res;
- if (! attr ) {
- return res;
- };
-
- StringList sl = attr->getValues();
- StringList::const_iterator i;
- for (i = sl.begin(); i != sl.end(); i++ ) {
- std::string attrType;
- std::string indexes;
- splitIndexString(*i, attrType, indexes );
- if ( attrType == type )
- {
- res = indexString2Type(indexes);
- break;
- }
- }
- return res;
+ m_dbEntryChanged = LDAPEntry();
}
-void OlcBdbDatabase::addIndex(const std::string& attr, const std::vector<IndexType>& idx)
+void OlcConfigEntry::resetEntries( const LDAPEntry &e )
{
- std::string indexString = attr;
- std::vector<IndexType>::const_iterator i;
- bool first = true;
- for ( i = idx.begin(); i != idx.end(); i++ )
- {
- if (! first)
- {
- indexString += ",";
- } else {
- indexString += " ";
- first = false;
- }
- if ( *i == Present ) {
- indexString += "pres";
- }
- else if ( *i == Eq )
- {
- indexString += "eq";
- }
- else if ( *i == Sub )
- {
- indexString += "sub";
- }
- }
- log_it(SLAPD_LOG_INFO, "indexString: '" + indexString + "'");
- this->addStringValue( "olcDbIndex", indexString );
+ m_dbEntry = e;
+ m_dbEntryChanged = e;
+ this->resetMemberAttrs();
}
-void OlcBdbDatabase::deleteIndex(const std::string& type)
+StringList OlcConfigEntry::getStringValues(const std::string &type) const
{
- const LDAPAttribute *attr = m_dbEntryChanged.getAttributes()->getAttributeByName("olcdbindex");
- if (! attr ) {
- return;
- };
-
- StringList sl = attr->getValues();
- StringList newValues;
- StringList::const_iterator i;
- for (i = sl.begin(); i != sl.end(); i++ ) {
- std::string attrType;
- std::string indexes;
- splitIndexString(*i, attrType, indexes );
- if ( attrType != type )
- {
- newValues.add(*i);
- }
+ const LDAPAttribute *attr = m_dbEntryChanged.getAttributeByName(type);
+ if ( attr ) {
+ return attr->getValues();
+ } else {
+ return StringList();
}
- this->setStringValues("olcdbindex", newValues );
}
-void OlcBdbDatabase::setDirectory( const std::string &dir )
-{
- this->setStringValue("olcDbDirectory", dir);
+std::string OlcConfigEntry::getStringValue(const std::string &type) const
+{
+ StringList sl = this->getStringValues(type);
+ if ( sl.size() == 1 ) {
+ return *(sl.begin());
+ } else {
+ return "";
+ }
}
-int OlcBdbDatabase::getEntryCache() const
+void OlcConfigEntry::setStringValues(const std::string &type, const StringList &values)
{
- return this->getIntValue( "olcDbCachesize" );
+ LDAPAttribute attr(type, values);
+ m_dbEntryChanged.replaceAttribute(attr);
}
-void OlcBdbDatabase::setEntryCache( int cachesize )
+void OlcConfigEntry::setStringValue(const std::string &type, const std::string &value)
{
- if (! cachesize )
+ log_it(SLAPD_LOG_INFO,"setStringValue() " + type + " " + value);
+ if ( value.empty() )
{
- this->setStringValue( "olcDbCachesize", "" );
+ m_dbEntryChanged.delAttribute(type);
}
else
{
- this->setIntValue( "olcDbCachesize", cachesize );
+ LDAPAttribute attr(type, value);
+ m_dbEntryChanged.replaceAttribute(attr);
}
}
-int OlcBdbDatabase::getIdlCache() const
+void OlcConfigEntry::addStringValue(const std::string &type, const std::string &value)
{
- return this->getIntValue( "olcDbIdlCachesize" );
+ const LDAPAttribute *attr = m_dbEntryChanged.getAttributeByName(type);
+ if ( attr ) {
+ LDAPAttribute newAttr(*attr);
+ newAttr.addValue(value);
+ m_dbEntryChanged.replaceAttribute(newAttr);
+ } else {
+ LDAPAttribute newAttr(type, value);
+ m_dbEntryChanged.addAttribute(newAttr);
+ }
}
-void OlcBdbDatabase::setIdlCache( int cachesize )
+void OlcConfigEntry::addIndexedStringValue(const std::string &type,
+ const std::string &value, int index)
{
- if (! cachesize )
+ std::ostringstream oStr;
+ oStr << "{" << index << "}" << value;
+ this->addStringValue( type, oStr.str() );
+}
+
+int OlcConfigEntry::getIntValue( const std::string &type ) const
+{
+ StringList sl = this->getStringValues(type);
+ if ( sl.empty() )
{
- this->setStringValue( "olcDbIdlCachesize", "" );
+ return -1;
}
- else
- {
- this->setIntValue( "olcDbIdlCachesize", cachesize );
+ else if(sl.size() == 1 ) {
+ std::istringstream iStr(*sl.begin());
+ int value;
+ iStr >> value;
+ return value;
+ } else {
+ throw(std::runtime_error("Attribute is not single-valued") );
}
}
-void OlcBdbDatabase::setCheckPoint( int kbytes, int min )
+void OlcConfigEntry::setIntValue( const std::string &type, int value )
{
- if ( !kbytes && !min )
+ std::ostringstream oStr;
+ oStr << value;
+ this->setStringValue( type, oStr.str() );
+}
+
+std::string OlcConfigEntry::toLdif() const
+{
+ std::ostringstream ldifStream;
+ LdifWriter ldif(ldifStream);
+ ldif.writeRecord( m_dbEntryChanged );
+ return ldifStream.str();
+}
+
+bool OlcConfigEntry::isNewEntry() const
+{
+ return ( this->getDn().empty() );
+}
+bool OlcConfigEntry::isDeletedEntry() const
+{
+ return ( (!this->getDn().empty()) && this->getUpdatedDn().empty() );
+}
+
+LDAPModList OlcConfigEntry::entryDifftoMod() const {
+ LDAPAttributeList::const_iterator i = m_dbEntry.getAttributes()->begin();
+ LDAPModList modifications;
+ log_it(SLAPD_LOG_INFO, "Old Entry DN: " + m_dbEntry.getDN());
+ log_it(SLAPD_LOG_INFO,"New Entry DN: " + m_dbEntryChanged.getDN());
+ for(; i != m_dbEntry.getAttributes()->end(); i++ )
{
- this->setStringValue( "olcDbCheckpoint", "" );
+ log_it(SLAPD_LOG_INFO,i->getName());
+ const LDAPAttribute *changedAttr = m_dbEntryChanged.getAttributeByName(i->getName());
+ if ( changedAttr ) {
+ StringList::const_iterator j = i->getValues().begin();
+ StringList delValues, addValues;
+ for(; j != i->getValues().end(); j++ )
+ {
+ bool deleted = true;
+ StringList::const_iterator k = changedAttr->getValues().begin();
+ for( ; k != changedAttr->getValues().end(); k++ ) {
+ if ( *k == *j ) {
+ deleted = false;
+ break;
+ }
+ }
+ if ( deleted )
+ {
+ delValues.add(*j);
+ log_it(SLAPD_LOG_INFO,"Value deleted: " + *j );
+ }
+ }
+ j = changedAttr->getValues().begin();
+ for(; j != changedAttr->getValues().end(); j++ )
+ {
+ bool added = true;
+ StringList::const_iterator k = i->getValues().begin();
+ for( ; k != i->getValues().end(); k++ ) {
+ if ( *k == *j ) {
+ log_it(SLAPD_LOG_INFO,"Value unchanged: " + *k );
+ added = false;
+ break;
+ }
+ }
+ if ( added )
+ {
+ addValues.add(*j);
+ log_it(SLAPD_LOG_INFO,"Value added: " + *j);
+ }
+ }
+ bool replace = false;
+ if ( delValues.size() > 0 ) {
+ if ( (addValues.size() > 0) && ( (int)delValues.size() == i->getNumValues()) ) {
+ log_it(SLAPD_LOG_INFO,"All Values deleted, this is a replace" );
+ modifications.addModification(
+ LDAPModification( LDAPAttribute(i->getName(), addValues),
+ LDAPModification::OP_REPLACE)
+ );
+ replace = true;
+ } else {
+ modifications.addModification(
+ LDAPModification( LDAPAttribute(i->getName(), delValues ),
+ LDAPModification::OP_DELETE)
+ );
+ }
+ }
+ if (addValues.size() > 0 && !replace ) {
+ modifications.addModification(
+ LDAPModification( LDAPAttribute(i->getName(), addValues),
+ LDAPModification::OP_ADD)
+ );
+ }
+ } else {
+ log_it(SLAPD_LOG_INFO,"removed Attribute: " + i->getName() );
+ modifications.addModification(
+ LDAPModification( LDAPAttribute(i->getName()),
+ LDAPModification::OP_DELETE)
+ );
+ }
}
- else
+ i = m_dbEntryChanged.getAttributes()->begin();
+ for(; i != m_dbEntryChanged.getAttributes()->end(); i++ )
{
- std::ostringstream oStr;
- oStr << kbytes << " " << min;
- this->setStringValue( "olcDbCheckpoint", oStr.str() );
+ log_it(SLAPD_LOG_INFO,i->getName() );
+ const LDAPAttribute *old = m_dbEntry.getAttributeByName(i->getName());
+ if (! old ) {
+ log_it(SLAPD_LOG_INFO,"Attribute added: " + i->getName());
+ if (! i->getValues().empty() )
+ {
+ modifications.addModification(
+ LDAPModification( LDAPAttribute(i->getName(), i->getValues()),
+ LDAPModification::OP_ADD)
+ );
+ }
+ }
}
+ return modifications;
}
-void OlcBdbDatabase::getCheckPoint( int& kbytes, int& min) const
+OlcOverlay* OlcOverlay::createFromLdapEntry( const LDAPEntry& e)
{
- kbytes=0;
- min=0;
- std::string checkpointStr = this->getStringValue("olcDbCheckpoint");
- if (! checkpointStr.empty() )
- {
- std::istringstream iStr(checkpointStr);
- iStr >> kbytes >> std::skipws >> min;
- }
- return;
+ return new OlcOverlay(e);
}
-OlcGlobalConfig::OlcGlobalConfig() : OlcConfigEntry()
+OlcOverlay::OlcOverlay( const LDAPEntry& e) : OlcConfigEntry(e)
{
- m_dbEntryChanged.setDN("cn=config");
- m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcGlobal"));
- m_dbEntryChanged.addAttribute(LDAPAttribute("cn", "config"));
+ log_it(SLAPD_LOG_INFO,"OlcOverlay::OlcOverlay()" );
+ std::string type(this->getStringValue("olcoverlay"));
+ entryIndex = splitIndexFromString( type, m_type );
}
-OlcGlobalConfig::OlcGlobalConfig( const LDAPEntry &le) : OlcConfigEntry(le)
+OlcOverlay::OlcOverlay( const std::string &type, const std::string &parent )
+ : m_type(type), m_parent(parent)
{
- log_it(SLAPD_LOG_INFO, "OlcGlobalConfig::OlcGlobalConfig( const LDAPEntry &le) : OlcConfigEntry(le)");
+ std::ostringstream dnstr;
+ dnstr << "olcOverlay=" << m_type << "," << parent;
+ m_dbEntryChanged.setDN(dnstr.str());
+ m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcPpolicyConfig"));
+ m_dbEntryChanged.addAttribute(LDAPAttribute("olcoverlay", m_type));
+}
+const std::string OlcOverlay::getType() const
+{
+ return m_type;
}
-const std::vectorstd::string OlcGlobalConfig::getLogLevelString() const
+void OlcOverlay::newParentDn( const std::string& parent )
{
- StringList lvalues = this->getStringValues("olcLogLevel");
- StringList::const_iterator i;
- std::vectorstd::string lvls;
- for ( i = lvalues.begin(); i != lvalues.end(); i++ )
+ std::ostringstream dnstr;
+ m_parent = parent;
+ dnstr << "olcOverlay={" << entryIndex << "}" << m_type << "," << parent;
+ log_it(SLAPD_LOG_INFO, "Changing Overlay DN from: " + m_dbEntryChanged.getDN()
+ + " to: " + dnstr.str() );
+ if (! m_dbEntry.getDN().empty() )
{
- std::istringstream iss(*i);
- int intlogValue;
- if ( iss >> intlogValue ) {
- log_it(SLAPD_LOG_INFO,"IntegerValue " + *i );
- }
- else
- {
- log_it(SLAPD_LOG_INFO,"StringValue " + *i );
- lvls.push_back(*i);
- }
+ m_dbEntry.setDN(dnstr.str());
}
- return lvls;
+ m_dbEntryChanged.setDN(dnstr.str());
}
-//int OlcGlobalConfig::getIdleTimeout()
-//{
-//
-//}
-
-void OlcGlobalConfig::setLogLevel(const std::liststd::string &level) {
- const LDAPAttribute *sattr = m_dbEntryChanged.getAttributeByName("olcloglevel");
- LDAPAttribute attr( "olcloglevel" );
- if ( sattr ) {
- attr = *sattr;
- }
- StringList values;
- std::liststd::string::const_iterator i = level.begin();
- for(; i != level.end(); i++ )
+void OlcOverlay::resetMemberAttrs()
+{
+ std::string type(this->getStringValue("olcoverlay"));
+ entryIndex = splitIndexFromString( type, m_type );
+}
+void OlcOverlay::updateEntryDn(bool origEntry )
+{
+ log_it(SLAPD_LOG_INFO, "updateEntryDN()");
+ std::ostringstream dn, name;
+ name << "{" << entryIndex << "}" << m_type;
+ dn << "olcOverlay=" << name.str() << "," << m_parent;
+ m_dbEntryChanged.setDN(dn.str());
+ m_dbEntryChanged.replaceAttribute(LDAPAttribute("olcOverlay", name.str()));
+ if ( origEntry && (! m_dbEntry.getDN().empty()) )
{
- values.add(*i);
+ m_dbEntry.setDN(dn.str());
+ m_dbEntry.replaceAttribute(LDAPAttribute("olcOverlay", name.str()));
}
- attr.setValues(values);
- m_dbEntryChanged.replaceAttribute(attr);
}
-void OlcGlobalConfig::addLogLevel(std::string level) {
- const LDAPAttribute *sattr = m_dbEntryChanged.getAttributeByName("olcloglevel");
- LDAPAttribute attr;
- if ( sattr ) {
- attr = *sattr;
- }
- attr.addValue(level);
- m_dbEntryChanged.replaceAttribute(attr);
+
+OlcDatabase::OlcDatabase( const LDAPEntry& le=LDAPEntry()) : OlcConfigEntry(le)
+{
+ std::string type(this->getStringValue("olcdatabase"));
+ entryIndex = splitIndexFromString( type, m_type );
}
-const std::vectorstd::string OlcGlobalConfig::getAllowFeatures() const
+OlcDatabase::OlcDatabase( const std::string& type ) : m_type(type)
{
- StringList values = this->getStringValues("olcAllows");
- StringList::const_iterator i;
- std::vectorstd::string allow;
- for ( i = values.begin(); i != values.end(); i++ )
+ std::ostringstream dnstr;
+ dnstr << "olcDatabase=" << m_type << ",cn=config";
+ m_dbEntryChanged.setDN(dnstr.str());
+ m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcDatabaseConfig"));
+ m_dbEntryChanged.addAttribute(LDAPAttribute("olcDatabase", m_type));
+}
+
+void OlcDatabase::updateEntryDn(bool origEntry )
+{
+ log_it(SLAPD_LOG_INFO, "updateEntryDN()");
+ std::ostringstream dn, name;
+ name << "{" << entryIndex << "}" << m_type;
+ dn << "olcDatabase=" << name.str() << ",cn=config" ;
+ m_dbEntryChanged.setDN(dn.str());
+ m_dbEntryChanged.replaceAttribute(LDAPAttribute("olcDatabase", name.str()));
+ if ( origEntry && (! m_dbEntry.getDN().empty()) )
{
- allow.push_back(*i);
+ m_dbEntry.setDN(dn.str());
+ m_dbEntry.replaceAttribute(LDAPAttribute("olcDatabase", name.str()));
}
- return allow;
}
-void OlcGlobalConfig::setAllowFeatures(const std::liststd::string &allow )
+void OlcDatabase::setSuffix( const std::string &suffix)
{
- const LDAPAttribute *sattr = m_dbEntryChanged.getAttributeByName("olcAllows");
- LDAPAttribute attr( "olcAllows" );
- if ( sattr ) {
- attr = *sattr;
- }
- StringList values;
- std::liststd::string::const_iterator i = allow.begin();
- for(; i != allow.end(); i++ )
+ this->setStringValue("olcSuffix", suffix);
+}
+
+void OlcDatabase::setRootDn( const std::string &rootdn)
+{
+ this->setStringValue("olcRootDN", rootdn);
+}
+
+void OlcDatabase::setRootPw( const std::string &rootpw)
+{
+ this->setStringValue("olcRootPW", rootpw);
+}
+
+const std::string OlcDatabase::getSuffix() const
+{
+ return this->getStringValue("olcSuffix");
+}
+
+const std::string OlcDatabase::getType() const
+{
+ return this->m_type;
+}
+
+void OlcDatabase::addAccessControl(const std::string& acl, int index )
+{
+ if ( index < 0 )
{
- values.add(*i);
+ StringList sl = this->getStringValues( "olcAccess" );
+ index = sl.size();
}
- attr.setValues(values);
- m_dbEntryChanged.replaceAttribute(attr);
+ this->addIndexedStringValue( "olcAccess", acl, index );
}
-const std::vectorstd::string OlcGlobalConfig::getDisallowFeatures() const
+void OlcDatabase::replaceAccessControl(const StringList acllist )
{
- StringList values = this->getStringValues("olcDisallows");
+ // delete old Values first
+ this->setStringValue( "olcAccess", "" );
+
StringList::const_iterator i;
- std::vectorstd::string allow;
- for ( i = values.begin(); i != values.end(); i++ )
+ int j = 0;
+
+ for ( i = acllist.begin(); i != acllist.end(); i++ )
{
- allow.push_back(*i);
+ this->addAccessControl( *i, j );
+ j++;
}
- return allow;
}
-void OlcGlobalConfig::setDisallowFeatures(const std::liststd::string &disallow )
+void OlcDatabase::addOverlay(boost::shared_ptr<OlcOverlay> overlay)
{
- const LDAPAttribute *sattr = m_dbEntryChanged.getAttributeByName("olcDisallows");
- LDAPAttribute attr( "olcDisallows" );
- if ( sattr ) {
- attr = *sattr;
- }
- StringList values;
- std::liststd::string::const_iterator i = disallow.begin();
- for(; i != disallow.end(); i++ )
- {
- values.add(*i);
- }
- attr.setValues(values);
- m_dbEntryChanged.replaceAttribute(attr);
+ m_overlays.push_back(overlay);
}
+OlcOverlayList& OlcDatabase::getOverlays()
+{
+ return m_overlays;
+}
-OlcSchemaConfig::OlcSchemaConfig() : OlcConfigEntry()
+void OlcDatabase::resetMemberAttrs()
{
- m_dbEntryChanged.setDN("cn=schema,cn=config");
- m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcSchemaConfig"));
- m_dbEntryChanged.addAttribute(LDAPAttribute("cn", "schema"));
+ std::string type(this->getStringValue("olcdatabase"));
+ entryIndex = splitIndexFromString( type, m_type );
}
-OlcSchemaConfig::OlcSchemaConfig(const LDAPEntry &e) : OlcConfigEntry(e)
+bool OlcDatabase::isBdbDatabase( const LDAPEntry& e )
{
- log_it(SLAPD_LOG_INFO, "OlcSchemaConfig::OlcSchemaConfig(const LDAPEntry &e) : OlcConfigEntry(e)");
- std::string name(this->getStringValue("cn"));
- if ( name[0] == '{' )
+ StringList oc = e.getAttributeByName("objectclass")->getValues();
+ for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
{
- std::string::size_type pos = name.find('}');
- std::istringstream indexstr(name.substr(1, pos-1));
- indexstr >> entryIndex;
- m_name = name.substr( pos+1, std::string::npos );
- } else {
- m_name = name;
- entryIndex = 0;
+ if ( strCaseIgnoreEquals(*i, "olcBdbConfig" ) || strCaseIgnoreEquals(*i, "olcHdbConfig" ) )
+ {
+ return true;
+ }
}
+ return false;
}
-OlcSchemaConfig::OlcSchemaConfig(const LDAPEntry &e1, const LDAPEntry &e2) : OlcConfigEntry(e1, e2)
+
+OlcDatabase* OlcDatabase::createFromLdapEntry( const LDAPEntry& e)
{
- log_it(SLAPD_LOG_INFO, "OlcSchemaConfig::OlcSchemaConfig(const LDAPEntry &e) : OlcConfigEntry(e)");
- std::string name(this->getStringValue("cn"));
- entryIndex = splitIndexFromString( name, m_name );
+ if ( OlcDatabase::isBdbDatabase( e ) )
+ {
+ log_it(SLAPD_LOG_INFO,"creating OlcBbdDatabase()" );
+ return new OlcBdbDatabase(e);
+ }
+ else
+ {
+ log_it(SLAPD_LOG_INFO,"creating OlcDatabase()" );
+ return new OlcDatabase(e);
+ }
}
-void OlcSchemaConfig::clearChangedEntry()
+
+OlcBdbDatabase::OlcBdbDatabase( const std::string& type ) : OlcDatabase(type)
+{
+ if ( type == "hdb" )
+ {
+ m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcHdbConfig"));
+ }
+ else
+ {
+ m_dbEntryChanged.addAttribute(LDAPAttribute("objectclass", "olcBdbConfig"));
+ }
+}
+
+OlcBdbDatabase::OlcBdbDatabase( const LDAPEntry& le) : OlcDatabase(le) { }
+
+inline void splitIndexString( const std::string &indexString, std::string &attr, std::string &indexes )
{
- OlcConfigEntry::clearChangedEntry();
- m_name = "";
+ std::string::size_type pos = indexString.find_first_of(" \t");
+ attr = indexString.substr(0, pos);
+ log_it(SLAPD_LOG_DEBUG, "AttributeType: " + attr );
+ if ( pos != std::string::npos ) {
+ pos = indexString.find_first_not_of(" \t", pos);
+ if ( pos != std::string::npos ) {
+ indexes = indexString.substr( pos, std::string::npos );
+ }
+ }
}
-const std::string& OlcSchemaConfig::getName() const
+inline std::vector<IndexType> indexString2Type( const std::string &indexes )
{
- return m_name;
+ std::string::size_type pos, oldpos = 0;
+ std::vector<IndexType> idx;
+ do {
+ pos = indexes.find( ',', oldpos );
+ std::string index = indexes.substr( oldpos,
+ (pos == std::string::npos ? std::string::npos : pos - oldpos) );
+ log_it(SLAPD_LOG_INFO, std::string("Index: ") + index );
+ oldpos = indexes.find_first_not_of( ", ", pos );
+ if ( index == "pres" ) {
+ idx.push_back(Present);
+ } else if (index == "eq" ) {
+ idx.push_back(Eq);
+ } else if (index == "approx" ) {
+ idx.push_back(Approx);
+ } else if (index == "sub" ) {
+ idx.push_back(Sub);
+ } else if (index == "subinital" ) {
+ idx.push_back(SpecialSubInitial);
+ } else if (index == "subany" ) {
+ idx.push_back(SpecialSubAny);
+ } else if (index == "subfinal" ) {
+ idx.push_back(SpecialSubFinal);
+ } else if (index == "nolang" ) {
+ idx.push_back(SpecialNoLang);
+ } else if (index == "nosubtypes" ) {
+ idx.push_back(SpecialNoSubTypes);
+ }
+ } while (pos != std::string::npos);
+ return idx;
}
-const std::vector<LDAPAttrType> OlcSchemaConfig::getAttributeTypes() const
+IndexMap OlcBdbDatabase::getDatabaseIndexes() const
{
- std::vector<LDAPAttrType> res;
- StringList types = this->getStringValues("olcAttributeTypes");
- StringList::const_iterator j;
- for ( j = types.begin(); j != types.end(); j++ )
- {
- LDAPAttrType currentAttr;
- std::string tmp;
- splitIndexFromString( *j, tmp );
- currentAttr = LDAPAttrType( tmp, LDAP_SCHEMA_ALLOW_NO_OID |
- LDAP_SCHEMA_ALLOW_QUOTED | LDAP_SCHEMA_ALLOW_OID_MACRO );
- res.push_back(currentAttr);
+ const LDAPAttributeList *al = m_dbEntryChanged.getAttributes();
+ const LDAPAttribute *attr = al->getAttributeByName("olcdbindex");
+ IndexMap res;
+ if (! attr ) {
+ return res;
+ };
+
+ StringList sl = attr->getValues();
+ StringList::const_iterator i;
+ for (i = sl.begin(); i != sl.end(); i++ ) {
+ std::string attrType;
+ std::string indexes;
+ splitIndexString(*i, attrType, indexes );
+ log_it(SLAPD_LOG_INFO, "Indexes: " + indexes );
+ std::vector<IndexType> idx = indexString2Type(indexes);
+ res.insert(make_pair(attrType, idx));
}
return res;
}
-void OlcSchemaConfig::resetMemberAttrs()
-{
- std::string name(this->getStringValue("cn"));
- entryIndex = splitIndexFromString( name, m_name );
-}
-
-OlcTlsSettings OlcGlobalConfig::getTlsSettings() const
-{
- log_it(SLAPD_LOG_INFO, "OlcTlsSettings OlcGlobalConfig::getTlsSettings() const ");
- return OlcTlsSettings( *this );
-}
-
-void OlcGlobalConfig::setTlsSettings( const OlcTlsSettings& tls )
+std::vector<IndexType> OlcBdbDatabase::getDatabaseIndex( const std::string &type ) const
{
- tls.applySettings( *this );
-}
-
+ const LDAPAttributeList *al = m_dbEntryChanged.getAttributes();
+ const LDAPAttribute *attr = al->getAttributeByName("olcdbindex");
+ std::vector<IndexType> res;
+ if (! attr ) {
+ return res;
+ };
-bool OlcConfigEntry::isDatabaseEntry ( const LDAPEntry& e )
-{
- StringList oc = e.getAttributeByName("objectclass")->getValues();
- for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
- {
- if ( strCaseIgnoreEquals(*i, "olcDatabaseConfig" ) )
+ StringList sl = attr->getValues();
+ StringList::const_iterator i;
+ for (i = sl.begin(); i != sl.end(); i++ ) {
+ std::string attrType;
+ std::string indexes;
+ splitIndexString(*i, attrType, indexes );
+ if ( attrType == type )
{
- return true;
+ res = indexString2Type(indexes);
+ break;
}
}
- return false;
+ return res;
}
-bool OlcConfigEntry::isGlobalEntry ( const LDAPEntry& e )
+void OlcBdbDatabase::addIndex(const std::string& attr, const std::vector<IndexType>& idx)
{
- StringList oc = e.getAttributeByName("objectclass")->getValues();
- for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
+ std::string indexString = attr;
+ std::vector<IndexType>::const_iterator i;
+ bool first = true;
+ for ( i = idx.begin(); i != idx.end(); i++ )
{
- if ( strCaseIgnoreEquals(*i, "olcGlobal" ) )
+ if (! first)
{
- return true;
+ indexString += ",";
+ } else {
+ indexString += " ";
+ first = false;
+ }
+ if ( *i == Present ) {
+ indexString += "pres";
+ }
+ else if ( *i == Eq )
+ {
+ indexString += "eq";
+ }
+ else if ( *i == Sub )
+ {
+ indexString += "sub";
}
}
- return false;
+ log_it(SLAPD_LOG_INFO, "indexString: '" + indexString + "'");
+ this->addStringValue( "olcDbIndex", indexString );
}
-bool OlcConfigEntry::isOverlayEntry ( const LDAPEntry& e )
+void OlcBdbDatabase::deleteIndex(const std::string& type)
{
- StringList oc = e.getAttributeByName("objectclass")->getValues();
- for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
- {
- if ( strCaseIgnoreEquals(*i, "olcOverlayConfig" ) )
+ const LDAPAttribute *attr = m_dbEntryChanged.getAttributes()->getAttributeByName("olcdbindex");
+ if (! attr ) {
+ return;
+ };
+
+ StringList sl = attr->getValues();
+ StringList newValues;
+ StringList::const_iterator i;
+ for (i = sl.begin(); i != sl.end(); i++ ) {
+ std::string attrType;
+ std::string indexes;
+ splitIndexString(*i, attrType, indexes );
+ if ( attrType != type )
{
- return true;
+ newValues.add(*i);
}
}
- return false;
+ this->setStringValues("olcdbindex", newValues );
}
-bool OlcConfigEntry::isScheamEntry ( const LDAPEntry& e )
+void OlcBdbDatabase::setDirectory( const std::string &dir )
+{
+ this->setStringValue("olcDbDirectory", dir);
+}
+
+int OlcBdbDatabase::getEntryCache() const
{
- StringList oc = e.getAttributeByName("objectclass")->getValues();
- for( StringList::const_iterator i = oc.begin(); i != oc.end(); i++ )
- {
- if ( strCaseIgnoreEquals(*i, "olcSchemaConfig" ) )
- {
- return true;
- }
- }
- return false;
+ return this->getIntValue( "olcDbCachesize" );
}
-OlcConfigEntry* OlcConfigEntry::createFromLdapEntry( const LDAPEntry& e )
+void OlcBdbDatabase::setEntryCache( int cachesize )
{
- if ( OlcConfigEntry::isGlobalEntry(e) )
- {
- log_it(SLAPD_LOG_INFO,"creating OlcGlobalConfig" );
- return new OlcGlobalConfig(e);
- }
- else if ( OlcConfigEntry::isScheamEntry(e) )
- {
- log_it(SLAPD_LOG_INFO,"creating OlcSchemaConfig" );
- return new OlcSchemaConfig(e);
- }
- else if ( OlcConfigEntry::isDatabaseEntry(e) )
- {
- log_it(SLAPD_LOG_INFO,"creating OlcDatabase" );;
- return OlcDatabase::createFromLdapEntry(e);
- }
- else if ( OlcConfigEntry::isOverlayEntry(e) )
+ if (! cachesize )
{
- log_it(SLAPD_LOG_INFO,"creating OlcOverlay");
- return new OlcConfigEntry(e);
+ this->setStringValue( "olcDbCachesize", "" );
}
else
{
- log_it(SLAPD_LOG_INFO,"unknown Config Object" );
- return 0;
+ this->setIntValue( "olcDbCachesize", cachesize );
}
}
-//std::map