from Products.ZPatterns.PlugIns import PlugIn from Products.LoginManager.UserSources import BasicUserSource,LoginUser from Products.LoginManager.LoginMethods import LoginMethod from Products.LoginManager import LoginManager import nis, string, crypt from Products.ZPatterns.PlugIns import defaultConstructors class NisUserSource(BasicUserSource, PlugIn): __plugin_kind__ = "User Source" meta_type = "NIS User Source" f=open('/tmp/zopelog', 'a', 0) i=0 def dbg(self, str): self.f.write('[%03d] %s\n' % (self.i, str)) self.i = self.i + 1 def retrieveItem(self, name): self.dbg('retrieveItem: %s' % name) try: passwd=nis.match(name, 'passwd.byname') except nis.error: return None user=LoginUser(name) user._setRack(self) self.dbg('retrieveItem: %s ok.' % user.getUserName()) return user def authenticateUser(self, user, password, REQUEST=None): self.dbg('authenticateUser: %s %s' % (user, 'password')) name=user.getUserName() if name is None: return None try: passwd=nis.match(name, 'passwd.byname') except nis.error: return None crypted=string.split(passwd, ':')[1] test=crypt.crypt(password, crypted) self.dbg('%s == %s: %d' % (crypted, test, crypted==test)) return crypted==test def rolesForUser(self, user): if user.getUserName() == 'bpe': return ['Write Access'] else: return ['Read Access'] def domainsForUser(self, user): return [] def initialize(context): context.registerPlugInClass( NisUserSource, permission = 'Add NIS User Source', constructors = defaultConstructors(NisUserSource, globals()), )