chiark / gitweb /
WIP before any changes resulting from reading SM API stuff
[inn-innduct.git] / samples / nnrpd_auth_wrapper.py
1 ##  $Id: nnrpd_auth_wrapper.py 7899 2008-06-22 18:22:07Z iulius $
2 ##
3 ##  Example wrapper for support of old Python authentication scripts,
4 ##  by Erik Klavon.
5 ##
6 ##  This file contains a sample Python script which can be used to
7 ##  duplicate the behaviour of the old nnrppythonauth functionality.
8 ##  This script only supports authentication.
9 ##
10 ##  How to use this wrapper:
11 ##    - insert your authentication class into this file;
12 ##    - rename your authentication class OLDAUTH.
13 ##
14 ##  See the INN Python Filtering and Authentication Hooks documentation
15 ##  for more information.
16 ##  The use of this file is *discouraged*.
17
18 ##  Old AUTH class.
19 ##  Insert your old auth class here.
20 ##  Do not include the code which sets the hook.
21
22
23
24
25 ##  Wrapper AUTH class.  It creates an instance of the old class and
26 ##  calls its methods.  Arguments and return values are munged as
27 ##  needed to fit the new way of doing things.
28
29 class MYAUTH:
30     """Provide auth callbacks to nnrpd."""
31     def authen_init(self):
32         self.old = OLDAUTH()
33
34     def authenticate(self, attributes):
35         attributes['type'] = buffer('authinfo')
36         perm = (self.old).authenticate(attributes)
37         err_str = "No error"
38         if perm[0] == 502:
39                 err_str = "Python authentication error!"        
40         return (perm[0],err_str)                
41
42     def authen_close(self):
43         (self.old).close()
44
45
46 ##  The rest is used to hook up the auth module on nnrpd.  It is unlikely
47 ##  you will ever need to modify this.
48
49 ##  Import functions exposed by nnrpd.  This import must succeed, or nothing
50 ##  will work!
51 from nnrpd import *
52
53 ##  Create a class instance.
54 myauth = MYAUTH()
55
56 ##  ...and try to hook up on nnrpd.  This would make auth object methods visible
57 ##  to nnrpd.
58 try:
59     set_auth_hook(myauth)
60     syslog('notice', "authentication module successfully hooked into nnrpd")
61 except Exception, errmsg:
62     syslog('error', "Cannot obtain nnrpd hook for authentication method: %s" % errmsg[0])