most important method inside news class is newsauth which takes
username, password and will return 1 if ldap authentification was OK.<br><br>actually
inn will call method authenticate which will call self.newsauth and
here comes the problem .. i ve got instead of call self.newsauth error
no module named py :<br>
<br>from authenticate :<br><br><span style="font-family: courier new,monospace;">try:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        syslog('notice', "result %s" % self.newsauth('boss','bbbb'))</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                except Exception, msg:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        syslog('notice', "error %s, %s, %s" % (type(msg),msg.args,msg))<br>
<br></span><br><div class="gmail_quote">On Thu, Jun 5, 2008 at 12:26 AM, David Hláčik <david@hlacik.eu> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello, what this beautifull mesage which is messing me whole day means :<br><br><b>python: error <type 'instance'>, ('No module named py',), No module named py</b><br><br>as a result of class pdg.py which is called from nnrpd_auth.py.<br>


<br>To be detailed ... news server inn is calling that when doing
autentification , it calls nnrpd_auth.py where instance of my class is
hooked into inn , when authentification begins it calls method
authenticate(arguments) from pdg.<br>
<br>I will provide as many information as needed to solve this mistery, becouse i really need to solve it.<br>Thanks!<br><br><br><span style="font-family: courier new,monospace;">#!/usr/bin/env python</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import ldap</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">from nnrpd import syslog</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">class news:</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        server = 'ldap://dev01.net.hlacik.eu'</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">        user_dn = 'cn=pdg,ou=Operators,o=Polarion'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        user_pw = 'Pdg1'</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        connectcodes = {   'READPOST':200,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                           'READ':201,</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                           'AUTHNEEDED':480,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                           'PERMDENIED':502</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        authcodes = {  'ALLOWED':281,</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                       'DENIED':502</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        def newsauth(self,match_username,match_password):</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                base_dn = 'ou=Users,o=Polarion'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                filter = "(uid=" +  match_username +  ")"</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                attrs = ['userPassword']</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                </span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                try :</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        l = ldap.initialize(self.server)</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        l.bind_s(self.user_dn, self.user_pw)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        raw_res = l.search_s( base_dn, ldap.SCOPE_SUBTREE, filter, attrs )</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        l.unbind()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                except ldap.SERVER_DOWN:</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        print "Error, server down"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        return 2</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                except ldap.INVALID_CREDENTIALS:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        print "Error, invalid credentials"</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        return 2</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                except ldap.LDAPError, e:</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        print "Error, %s" % e</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                for results in raw_res: </span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        (cn,search) = results </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        for password in search["userPassword"]:</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                                if password == match_password: return 1</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                return 0</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">        def authenticate(self, attributes):</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                # just for debugging purposes</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                syslog('notice', 'nnrpd_auth authenticate() invoked: hostname %s, ipaddress</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> %s, interface %s, user %s' % (\</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        attributes['hostname'], \</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        attributes['ipaddress'], \</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                        attributes['interface'], \</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        attributes['user']))</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                try:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        syslog('notice', "result %s" % self.newsauth('boss','bbbb'))</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                except Exception, msg:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                        syslog('notice', "error %s, %s, %s" % (type(msg),msg.args,msg))</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                # do username passworld authentication</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                #if self.newsauth(attributes['user'], str(attributes['pass'])):</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                #    syslog('notice', 'authentication by username succeeded')</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                #    return ( self.authcodes['ALLOWED'], 'No error' )</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                #else:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                #    syslog('notice', 'authentication by username failed')</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                #    return ( self.authcodes['DENIED'], 'Access Denied!')</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">


-------------------<br><br>nnrpd_auth_py :<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># Sample authentication and authorization class. It defines all methods known</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;"># to nnrpd.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;"># Import functions exposed by nnrpd. This import must succeed, or nothing</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># will work!</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">from nnrpd import *</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">from pdg import *</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">myauth = news()</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># ...and try to hook up on nnrpd. This would make auth object methods visible</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;"># to nnrpd.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">try:</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    set_auth_hook(myauth)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    syslog('notice', "authentication module successfully hooked into nnrpd")</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">except Exception, errmsg:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    syslog('error', "Cannot obtain nnrpd hook for authentication method: %s" % errmsg[0])</span>
</blockquote></div><br>