235 lines
10 KiB
Python
Executable File
235 lines
10 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
|
|
# Glasnost
|
|
# By: Odile Bénassy <obenassy@entrouvert.com>
|
|
# Romain Chantereau <rchantereau@entrouvert.com>
|
|
# Nicolas Clapiès <nclapies@easter-eggs.org>
|
|
# Pierre-Antoine Dejace <padejace@entrouvert.be>
|
|
# Thierry Dulieu <tdulieu@easter-eggs.com>
|
|
# Florent Monnier <monnier@codelutin.com>
|
|
# Cédric Musso <cmusso@easter-eggs.org>
|
|
# Frédéric Péters <fpeters@entrouvert.be>
|
|
# Benjamin Poussin <poussin@codelutin.com>
|
|
# Emmanuel Raviart <eraviart@entrouvert.com>
|
|
# Sébastien Régnier <regnier@codelutin.com>
|
|
# Emmanuel Saracco <esaracco@easter-eggs.com>
|
|
#
|
|
# Copyright (C) 2000, 2001 Easter-eggs & Emmanuel Raviart
|
|
# Copyright (C) 2002 Odile Bénassy, Code Lutin, Thierry Dulieu, Easter-eggs,
|
|
# Entr'ouvert, Frédéric Péters, Benjamin Poussin, Emmanuel Raviart,
|
|
# Emmanuel Saracco & Théridion
|
|
# Copyright (C) 2003 Odile Bénassy, Romain Chantereau, Nicolas Clapiès,
|
|
# Code Lutin, Pierre-Antoine Dejace, Thierry Dulieu, Easter-eggs,
|
|
# Entr'ouvert, Florent Monnier, Cédric Musso, Ouvaton, Frédéric Péters,
|
|
# Benjamin Poussin, Rodolphe Quiédeville, Emmanuel Raviart, Sébastien
|
|
# Régnier, Emmanuel Saracco, Théridion & Vecam
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
__doc__ = """Glasnost Password Accounts Server"""
|
|
|
|
__version__ = '$Revision$'[11:-2]
|
|
|
|
|
|
import copy
|
|
import sys
|
|
|
|
glasnostPythonDir = '/usr/local/lib/glasnost-devel' # changed on make install
|
|
sys.path.insert(0, glasnostPythonDir)
|
|
|
|
import glasnost
|
|
|
|
import glasnost.common.context as context
|
|
import glasnost.common.faults as faults
|
|
import glasnost.common.PasswordAccountsCommon as commonPasswordAccounts
|
|
from glasnost.common.tools import iso8859_15
|
|
import glasnost.common.tools_new as commonTools
|
|
|
|
import glasnost.server.ObjectsServer as objects
|
|
|
|
from glasnost.proxy.tools import getProxy
|
|
|
|
|
|
applicationName = 'PasswordAccountsServer'
|
|
applicationRole = 'passwordaccounts'
|
|
dispatcher = None
|
|
|
|
|
|
# FIXME: those classes are necessary to upgrade data from
|
|
# AuthenticationLoginPasswordServer.pickle; they should be removed as
|
|
# soon as it is no longer necessary to access this file.
|
|
class AccountLoginPassword: pass
|
|
class AdminAuthenticationLoginPassword: pass
|
|
class AuthenticationLoginPasswordVirtualServer: pass
|
|
|
|
|
|
class AdminPasswordAccounts(objects.AdminServerMixin,
|
|
commonPasswordAccounts.AdminPasswordAccounts):
|
|
def checkModifyIsPossible(self, changes, givenSlotNames = None):
|
|
# This change is irreversible.
|
|
if self.storePasswordsInClearText == 0 \
|
|
and changes.storePasswordsInClearText == 1:
|
|
raise faults.UnableToChangePasswordStorage()
|
|
objects.AdminServerMixin.checkModifyIsPossible(
|
|
self, changes, givenSlotNames = givenSlotNames)
|
|
objects.register(AdminPasswordAccounts)
|
|
|
|
|
|
class PasswordAccount(objects.ObjectServerMixin,
|
|
commonPasswordAccounts.PasswordAccount):
|
|
def checkModifyIsPossible(self, changes, givenSlotNames = None):
|
|
objects.ObjectServerMixin.checkModifyIsPossible(
|
|
self, changes, givenSlotNames = givenSlotNames)
|
|
virtualServerId = context.getVar('applicationId')
|
|
virtualServer = self.getServer().getVirtualServer(virtualServerId)
|
|
if (not givenSlotNames or 'login' in givenSlotNames) \
|
|
and changes.login != self.login and changes.login is not None:
|
|
if virtualServer.objectsByLogin.has_key(changes.login) \
|
|
and changes.id != virtualServer.objectsByLogin[
|
|
changes.login].id:
|
|
raise faults.DuplicateLogin(changes.login)
|
|
|
|
def clear(self):
|
|
objectsByLogin = self.getServer().virtualServer.objectsByLogin
|
|
if objectsByLogin.has_key(self.login):
|
|
del objectsByLogin[self.login]
|
|
|
|
def modify(self, changes, givenSlotNames = None):
|
|
virtualServerId = context.getVar('applicationId')
|
|
virtualServer = self.getServer().getVirtualServer(virtualServerId)
|
|
login = self.login
|
|
if not virtualServer.admin.userCanChoosePassword:
|
|
self.password_kind = copy.copy(self.password_kind)
|
|
self.password_kind.hasToModify = 0
|
|
objects.ObjectServerMixin.modify(
|
|
self, changes, givenSlotNames = givenSlotNames)
|
|
if not virtualServer.admin.userCanChoosePassword:
|
|
del self.password_kind
|
|
if self.login != login:
|
|
if login is not None:
|
|
del virtualServer.objectsByLogin[login]
|
|
if self.login is not None:
|
|
virtualServer.objectsByLogin[self.login] = self
|
|
objects.register(PasswordAccount)
|
|
|
|
|
|
class PasswordAccountsVirtualServer(objects.ObjectsVirtualServer):
|
|
objectsByLogin = None
|
|
|
|
def init(self):
|
|
objects.ObjectsVirtualServer.init(self)
|
|
self.objectsByLogin = {}
|
|
|
|
|
|
class PasswordAccountsServer(
|
|
commonPasswordAccounts.PasswordAccountsCommonMixin,
|
|
objects.ObjectsServer):
|
|
VirtualServer = PasswordAccountsVirtualServer
|
|
|
|
def addObjectXmlRpc(self, objectImport):
|
|
objectId = objects.ObjectsServer.addObjectXmlRpc(self, objectImport)
|
|
virtualServerId = context.getVar('applicationId')
|
|
virtualServer = self.getVirtualServer(virtualServerId)
|
|
object = virtualServer.loadObjectCore(objectId)
|
|
if virtualServer.objectsByLogin.has_key(object.login):
|
|
# Login already used.
|
|
del virtualServer.objects[objectId]
|
|
virtualServer.markObjectAsDeleted(objectId)
|
|
virtualServer.markCoreAsDirty()
|
|
raise faults.DuplicateLogin(object.login)
|
|
|
|
virtualServer.objectsByLogin[object.login] = object
|
|
virtualServer.markCoreAsDirty()
|
|
return objectId
|
|
|
|
def checkObjectAuthenticationXmlRpc(self, loginImport, passwordImport):
|
|
virtualServerId = context.getVar('applicationId')
|
|
virtualServer = self.getVirtualServer(virtualServerId)
|
|
login = iso8859_15(loginImport)
|
|
password = iso8859_15(passwordImport)
|
|
if not virtualServer.objectsByLogin.has_key(login):
|
|
raise faults.WrongLogin(login)
|
|
object = virtualServer.objectsByLogin[login]
|
|
if object.password and password != object.password:
|
|
raise faults.WrongPassword(password)
|
|
identitiesProxy = getProxy(object.identityId)
|
|
return [identitiesProxy.getUserToken(object.identityId), 'password']
|
|
|
|
def fillEmptyVirtualServer(self, virtualServer):
|
|
objects.ObjectsServer.fillEmptyVirtualServer(self, virtualServer)
|
|
|
|
# Upgrade to version 0001_0028.
|
|
import cPickle
|
|
import os
|
|
authenticationPickleFilePath = os.path.join(
|
|
virtualServer.dataDirectoryPath,
|
|
'AuthenticationLoginPasswordServer.pickle')
|
|
if os.access(authenticationPickleFilePath, os.F_OK):
|
|
print 'Importing AuthenticationLoginPasswordServer data for %s.' \
|
|
% virtualServer.virtualServerId
|
|
authenticationRcFile = open(authenticationPickleFilePath, 'rb')
|
|
authenticationVersion = self.readFileVersion(authenticationRcFile)
|
|
authenticationVirtualServer = cPickle.load(authenticationRcFile)
|
|
authenticationRcFile.close()
|
|
|
|
admin = virtualServer.admin
|
|
authenticationAdmin = authenticationVirtualServer.admin
|
|
if hasattr(authenticationAdmin, 'stockPasswordsInClearText'):
|
|
admin.storePasswordsInClearText \
|
|
= authenticationAdmin.stockPasswordsInClearText
|
|
if hasattr(authenticationAdmin, 'userCanChoosePassword'):
|
|
admin.userCanChoosePassword \
|
|
= authenticationAdmin.userCanChoosePassword
|
|
virtualServer.markAdminAsDirty(virtualServer.admin)
|
|
|
|
personIds = authenticationVirtualServer.authentications.keys()
|
|
personIds.sort() # IdentitiesServer uses the same order.
|
|
for personId in personIds:
|
|
authentication = authenticationVirtualServer.authentications[
|
|
personId]
|
|
passwordAccount = PasswordAccount()
|
|
passwordAccount.login = authentication.login
|
|
passwordAccount.password = authentication.password
|
|
virtualServer.nextLocalId = int(commonTools.extractLocalId(
|
|
personId))
|
|
passwordAccount.setAutomaticalSlots()
|
|
passwordAccount.identityId = '%s/%s' % (
|
|
commonTools.makeApplicationId(passwordAccount.id,
|
|
'identities'),
|
|
commonTools.extractLocalId(passwordAccount.id))
|
|
virtualServer.objects[passwordAccount.id] = passwordAccount
|
|
virtualServer.objectsByLogin[
|
|
passwordAccount.login] = passwordAccount
|
|
passwordAccount.saveNonCore()
|
|
passwordAccount.releaseNonCore()
|
|
virtualServer.markObjectAsDirty(passwordAccount)
|
|
virtualServer.markCoreAsDirty()
|
|
|
|
|
|
def registerPublicMethods(self):
|
|
objects.ObjectsServer.registerPublicMethods(self)
|
|
self.registerPublicMethod('checkObjectAuthentication',
|
|
self.checkObjectAuthenticationXmlRpc)
|
|
|
|
|
|
passwordAccountsServer = PasswordAccountsServer()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
passwordAccountsServer.launch(applicationName, applicationRole)
|