eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/generalFilePermissions.py

branch
eric7
changeset 8312
800c432b34c8
parent 8222
5994b80b8760
child 8881
54e42bc2437a
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2020 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a check for setting too permissive file permissions.
8 """
9
10 #
11 # This is a modified version of the one found in the bandit package.
12 #
13 # Original Copyright 2014 Hewlett-Packard Development Company, L.P.
14 #
15 # SPDX-License-Identifier: Apache-2.0
16 #
17
18 import stat
19
20
21 def getChecks():
22 """
23 Public method to get a dictionary with checks handled by this module.
24
25 @return dictionary containing checker lists containing checker function and
26 list of codes
27 @rtype dict
28 """
29 return {
30 "Call": [
31 (checkFilePermissions, ("S102",)),
32 ],
33 }
34
35
36 def checkFilePermissions(reportError, context, config):
37 """
38 Function to check for setting too permissive file permissions.
39
40 @param reportError function to be used to report errors
41 @type func
42 @param context security context object
43 @type SecurityContext
44 @param config dictionary with configuration data
45 @type dict
46 """
47 if (
48 'chmod' in context.callFunctionName and
49 context.callArgsCount == 2
50 ):
51 mode = context.getCallArgAtPosition(1)
52
53 if (
54 mode is not None and
55 isinstance(mode, int) and
56 (mode & stat.S_IWOTH or mode & stat.S_IXGRP)
57 ):
58 # world writable is an HIGH, group executable is a MEDIUM
59 if mode & stat.S_IWOTH:
60 severity = "H"
61 else:
62 severity = "M"
63
64 filename = context.getCallArgAtPosition(0)
65 if filename is None:
66 filename = 'NOT PARSED'
67
68 reportError(
69 context.node.lineno - 1,
70 context.node.col_offset,
71 "S103",
72 severity,
73 "H",
74 oct(mode),
75 filename
76 )

eric ide

mercurial