python nnrpd auth or access hook import module error

David Hláčik david at hlacik.eu
Sun Jun 8 15:50:10 UTC 2008


Hello,

Lets just see a following scenario, this is my sample authenticate
method, i am importing there commands module (import commands) and
trying to post a result trough syslog to see it trough news.notice log
(please ignore other commands - as i just edited my nnrpd_auth.py)

def authenticate(self, attributes):
       """Called when python_auth is encountered in readers.conf"""

       # just for debugging purposes
       syslog('notice', 'n_a authenticate() invoked: hostname %s,
ipaddress %s, interface %s, user %s' % (\
               attributes['hostname'], \
               attributes['ipaddress'], \
               attributes['interface'], \
               attributes['user']))

       # do username passworld authentication
       #if 'foo' == str(attributes['user'])  \
       #   and 'foo' == str(attributes['pass']):
       #    syslog('notice', 'authentication by username succeeded')
       #    return ( self.authcodes['ALLOWED'], 'No error', 'default_user')
       #else:
       #    syslog('notice', 'authentication by username failed')
       #    return ( self.authcodes['DENIED'], 'Access Denied!')

       import os
       result = int(os.popen("%s %s %s"
%("/opt/pdg/newsauth.py",str(attributes['user']),str(attributes['pass'])),
"r").read())
       import commands
       syslog('notice', commands.getoutput("ls -l"))
       if result == 1:
               syslog('notice', 'authentication by username succeeded')
               return(self.authcodes['ALLOWED'], 'OK')
       else:
               syslog('notice', 'authentication by username failed')
               return ( self.authcodes['DENIED'], 'FAILED')

But instead of "ls -l" result inside news.notice log i see :

Jun  8 17:09:44 dev01 nnrpd[25107]: python: n_a authenticate()
invoked: hostname david-nb.net.hlacik.eu, ipaddress 10.10.10.199,
interface 10.10.10.183, user boss
Jun  8 17:09:44 dev01 nnrpd[25107]: python authenticate method
returned wrong result

As you can see it will hang on import commands part in authenticate
method and not continue .
I have tested it trought my test.py script to see if there is no bug
in python code. Code is clean.

Thanks again,

David



More information about the inn-bugs mailing list