1 | #!/usr/bin/env python |
---|
2 | import hwdetector.Detector as Detector |
---|
3 | import hwdetector.utils.log as log |
---|
4 | |
---|
5 | log.debug("File "+__name__+" loaded") |
---|
6 | |
---|
7 | class LlxUsersTest(Detector): |
---|
8 | _NEEDS=['MOUNTS_INFO','USER_TEST'] |
---|
9 | _PROVIDES=['LLXUSERS_TEST'] |
---|
10 | |
---|
11 | def make_result(self,*args,**kwargs): |
---|
12 | ret='' |
---|
13 | if not ('result' in kwargs and 'msg' in kwargs): |
---|
14 | return |
---|
15 | if isinstance(kwargs['result'],list): |
---|
16 | result=kwargs['result'] |
---|
17 | else: |
---|
18 | result=[str(kwargs['result'])] |
---|
19 | |
---|
20 | for x in result: |
---|
21 | ret+='{}> {}: {}\n'.format(self.__class__.__name__,x,kwargs['msg']) |
---|
22 | return ret |
---|
23 | |
---|
24 | def run(self,*args,**kwargs): |
---|
25 | msg=[] |
---|
26 | status = False |
---|
27 | msg_debug=[] |
---|
28 | mounts_info=kwargs['MOUNTS_INFO'] |
---|
29 | user_test=kwargs['USER_TEST'] |
---|
30 | for u in sorted(user_test.iterkeys()): |
---|
31 | status=True |
---|
32 | if user_test[u]['HAS_HOME']: |
---|
33 | msg_debug.append('\n{}\n'.format(u.upper())) |
---|
34 | for k in user_test[u]: |
---|
35 | if k != 'MOUNTS_OK': |
---|
36 | msg_debug.append('{} {}\n'.format(k,user_test[u][k])) |
---|
37 | if user_test[u][k] == False: |
---|
38 | msg_debug.append('Home of user {} has wrong permission,owners or acl\'s\n'.format(u)) |
---|
39 | msg.append(self.make_result(result=['Home of user {} has wrong permission,owners or acl\'s'.format(u)],msg='Nok !')) |
---|
40 | status = False |
---|
41 | else: |
---|
42 | msg_debug.append('{} {}\nMESSAGES:\n{}\n'.format(k,user_test[u][k][0],'\n'.join(user_test[u][k][1]))) |
---|
43 | if user_test[u][k][0] == False: |
---|
44 | msg.append(self.make_result(result=['User {} has wrong mounts, detection says'.format(u)],msg='')) |
---|
45 | msg.append(self.make_result(result=user_test[u]['MOUNTS_OK'][1],msg='')) |
---|
46 | status = False |
---|
47 | if status: |
---|
48 | msg.append(self.make_result(result=['Home of user {} seems with good permission,owners and acl\'s'.format(u)],msg='Ok!')) |
---|
49 | if 'NOT_LOGGED_IN' in user_test[u]['MOUNTS_OK'][1]: |
---|
50 | msg.append(self.make_result(result='User {} not logged in, so i can\'t expect to analyze any mounts'.format(u),msg='')) |
---|
51 | else: |
---|
52 | msg.append(self.make_result(result=['User {} has correct mounts, detection says'.format(u)],msg='')) |
---|
53 | msg.append(self.make_result(result=user_test[u]['MOUNTS_OK'][1],msg='Ok!')) |
---|
54 | |
---|
55 | msg=''.join(msg) |
---|
56 | msg_debug=''.join(msg_debug) |
---|
57 | log.debug(msg_debug) |
---|
58 | return {'LLXUSERS_TEST':{'status':status,'msg':msg}} |
---|