[yast-commit] r48638 - in /trunk/ldap-server/src: LdapServer.pm agent/SlapdConfigAgent.cc tree_structure.ycp
Author: rhafer Date: Fri Jun 27 15:59:52 2008 New Revision: 48638 URL: http://svn.opensuse.org/viewcvs/yast?rev=48638&view=rev Log: support for adding Schema from old .schema Files (instead of LDIF-only) Modified: trunk/ldap-server/src/LdapServer.pm trunk/ldap-server/src/agent/SlapdConfigAgent.cc trunk/ldap-server/src/tree_structure.ycp Modified: trunk/ldap-server/src/LdapServer.pm URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/LdapServer.pm?rev... ============================================================================== --- trunk/ldap-server/src/LdapServer.pm (original) +++ trunk/ldap-server/src/LdapServer.pm Fri Jun 27 15:59:52 2008 @@ -605,6 +605,19 @@ return $rc; } +BEGIN { $TYPEINFO {AddSchemaToSchemaList} = ["function", "boolean", "string" ]; } +sub AddSchemaToSchemaList +{ + my ($self, $file) = @_; + + my $rc = SCR->Write(".ldapserver.schema.addFromSchemafile", $file); + if ( ! $rc ) { + my $err = SCR->Error(".ldapserver"); + $self->SetError( $err->{'summary'}, $err->{'description'} ); + } + return $rc; +} + BEGIN { $TYPEINFO {AddLdifToSchemaList} = ["function", "boolean", "string" ]; } sub AddLdifToSchemaList { Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfig... ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.cc (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.cc Fri Jun 27 15:59:52 2008 @@ -682,6 +682,25 @@ return YCPBoolean(ret); } +int getSchemaLine( std::istream &input, std::string &schemaLine) +{ + if ( ! getline(input, schemaLine) ) + { + return -1; + } + while ( input && + (input.peek() == ' ' || input.peek() == '\t')) + { + std::string cat; + if (input.peek() == '\t' ) + schemaLine += ' '; + input.ignore(); + getline(input, cat); + schemaLine += cat; + } + return 0; +} + YCPBoolean SlapdConfigAgent::WriteSchema( const YCPPath &path, const YCPValue &arg, const YCPValue &arg2) @@ -712,8 +731,82 @@ YCPString(std::string( e.what() ) ) ); return YCPBoolean(false); } + } + else if ( subpath == "addFromSchemafile" ) + { + std::string filename = arg->asString()->value_cstr(); + y2milestone("reading Schema from File: %s", filename.c_str()); + // build RDN for new schema entry + std::string::size_type pos = filename.find_last_of('/'); + std::string rdn = filename.substr(pos+1); + // does file name end with .schema? + if ( rdn.size() >= 7 ) + { + if ( rdn.substr( rdn.size()-7 ) == ".schema" ) + { + rdn = rdn.substr(0, rdn.size()-7 ); + } + } + std::string dn = "cn="; + dn += rdn; + dn += ",cn=schema,cn=config"; + y2milestone("RDN will be: %s", dn.c_str()); + + std::ifstream input(filename.c_str()); + std::string schemaLine; + LDAPEntry entry(dn), oldEntry; + entry.addAttribute( LDAPAttribute( "objectClass", "olcSchemaConfig" ) ); + entry.addAttribute( LDAPAttribute( "cn", rdn ) ); + + while ( ! getSchemaLine(input, schemaLine) ) + { + y2milestone("Read schema Line: %s", schemaLine.c_str() ); + // empty or comment? + if ( schemaLine[0] == '#' || schemaLine.size() == 0 ) + { + y2milestone("Comment or empty" ); + continue; + } + int pos=schemaLine.find_last_not_of(" \t\n"); + if (pos != std::string::npos ) + schemaLine.erase(pos+1, std::string::npos ); + + // FIXME: should validate Schema syntax here + if ( ! schemaLine.compare(0, sizeof("objectidentifier")-1, "objectidentifier" ) ) + { + pos = schemaLine.find_first_not_of(" \t", sizeof("objectidentifier") ); + schemaLine.erase(0, pos ); + y2milestone("objectIdentifier Line <%s>", schemaLine.c_str() ); + entry.addAttribute(LDAPAttribute("olcObjectIdentifier", schemaLine) ); + } + else if ( ! schemaLine.compare(0, sizeof("attributetype")-1, "attributetype" ) ) + { + int pos = schemaLine.find_first_not_of(" \t", sizeof("attributetype") ); + schemaLine.erase(0, pos ); + entry.addAttribute(LDAPAttribute("olcAttributeTypes", schemaLine) ); + } + else if ( ! schemaLine.compare(0, sizeof("objectClass")-1, "objectClass" ) ) + { + int pos = schemaLine.find_first_not_of(" \t", sizeof("objectClass") ); + schemaLine.erase(0, pos ); + entry.addAttribute(LDAPAttribute("olcObjectClasses", schemaLine) ); + } + else + { + lastError->add(YCPString("summary"), + YCPString("Error while parsing Schema file") ); + lastError->add(YCPString("description"), YCPString("") ); + return YCPBoolean(false); + } + } + schema.push_back( boost::shared_ptr<OlcSchemaConfig>(new OlcSchemaConfig(oldEntry, entry)) ); + + //lastError->add( YCPString("summary"), + // YCPString("Error while parsing Schema file") ); + //lastError->add( YCPString("description"), YCPString("") ); + return YCPBoolean(true); } - if ( subpath == "remove" ) + else if ( subpath == "remove" ) { std::string name = arg->asString()->value_cstr(); y2milestone("remove Schema Entry: %s", name.c_str()); Modified: trunk/ldap-server/src/tree_structure.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/tree_structure.yc... ============================================================================== --- trunk/ldap-server/src/tree_structure.ycp (original) +++ trunk/ldap-server/src/tree_structure.ycp Fri Jun 27 15:59:52 2008 @@ -86,7 +86,6 @@ ``{ y2milestone( "calling schema read handler" ); list<string> inclist = LdapServer::GetSchemaList(); -// //store current include list for later order changes update_schemalist( inclist ); return true; } @@ -134,8 +133,13 @@ } if ( regexpmatch( new_item, ".*\.schema$" ) ) { - callback_error = _(".schema Files not supported yet"); - return false; + if (! LdapServer::AddSchemaToSchemaList(new_item) ) { + map<string, string> err = LdapServer::GetError(); + callback_error = err["msg"]:"" + "\n" + err["details"]:""; + return false; + } + list<string> inclist = LdapServer::GetSchemaList(); + update_schemalist( inclist ); } else if (! LdapServer::AddLdifToSchemaList(new_item) ) { -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
rhafer@svn.opensuse.org