1 | from lib.SyncerTypes import * |
---|
2 | import pwd,grp |
---|
3 | |
---|
4 | class handler_users(IPlugin): |
---|
5 | def init_plugin(self): |
---|
6 | self.typeplug = 'users' |
---|
7 | self.params = ['action','options'] |
---|
8 | |
---|
9 | def get_current_user(self): |
---|
10 | user_id = os.getuid() |
---|
11 | user_name = pwd.getpwuid(user_id)[0] |
---|
12 | return user_name |
---|
13 | |
---|
14 | def get_current_groups(self,user_name=None): |
---|
15 | if (user_name == None): |
---|
16 | user_name=self.get_current_user() |
---|
17 | grupos = [group[0] for group in grp.getgrall() if user_name in group[3]] |
---|
18 | return grupos |
---|
19 | |
---|
20 | def process(self,*args,**kwargs): |
---|
21 | params = kwargs['params'] |
---|
22 | if (params['action']) == 'get_user': |
---|
23 | user_name=self.get_current_user() |
---|
24 | groups=self.get_current_groups(user_name) |
---|
25 | return True,[user_name,groups] |
---|
26 | if (params['action']) == 'assert_grp': |
---|
27 | grouplist=params['options'] |
---|
28 | groups_to_apply=grouplist.split(',') |
---|
29 | current_grps=self.get_current_groups() |
---|
30 | for g in groups_to_apply: |
---|
31 | if g in current_grps: |
---|
32 | return True, 'User is in group ' + g |
---|
33 | return False, 'Not in group' |
---|
34 | if (params['action']) == 'disavow_grp': |
---|
35 | grouplist=params['options'] |
---|
36 | groups_to_apply=grouplist.split(',') |
---|
37 | current_grps=self.get_current_groups() |
---|
38 | for g in groups_to_apply: |
---|
39 | if g in current_grps: |
---|
40 | return False, 'Not allowed for this group ' + g |
---|
41 | return True, 'User don\'t disavow condition {}'.format(grouplist) |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | |
---|