summaryrefslogtreecommitdiffstats
path: root/cobbler/modules/authz_configfile.py
blob: 84343e286ff1dd7e91c401a9521013fcbe97bf2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Authorization module that allow users listed in
/etc/cobbler/users.conf to be permitted to access resources.
For instance, when using authz_ldap, you want to use authn_configfile,
not authz_allowall, which will most likely NOT do what you want.

This software may be freely redistributed under the terms of the GNU
general public license.

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., 675 Mass Ave, Cambridge, MA 02139, USA.
"""

import distutils.sysconfig
import ConfigParser
import sys
import os
from utils import _

plib = distutils.sysconfig.get_python_lib()
mod_path="%s/cobbler" % plib
sys.path.insert(0, mod_path)

import cexceptions
import utils

CONFIG_FILE='/etc/cobbler/users.conf'

def register():
    """
    The mandatory cobbler module registration hook.
    """
    return "authz"

def __parse_config():
    if not os.path.exists(CONFIG_FILE):
        return []
    config = ConfigParser.SafeConfigParser()
    config.read(CONFIG_FILE)
    alldata = {}
    groups = config.sections()
    for g in groups:
       alldata[str(g)] = {}
       opts = config.options(g)
       for o in opts:
           alldata[g][o] = 1
    return alldata 


def authorize(api_handle,user,resource,arg1=None,arg2=None):
    """
    Validate a user against a resource.
    All users in the file are permitted by this module.
    """

    data = __parse_config()
    for g in data:
        if user in data[g]:
           return 1
    return 0

if __name__ == "__main__":
    print __parse_config()