(filename)
| 170 | # |
| 171 | # Returns true iff file appears to have appropriate permissions. |
| 172 | def checkSensitiveFilePermissions(filename): |
| 173 | if sys.platform == 'win32': |
| 174 | # TODO: This might deserve extra checks by someone familiar with |
| 175 | # Windows systems. |
| 176 | return True |
| 177 | elif sys.platform[:7] == 'freebsd': |
| 178 | # FreeBSD file systems are the same as major Linux file systems |
| 179 | present_permissions = os.stat(filename)[0] |
| 180 | disallowed_permissions = stat.S_IRWXG | stat.S_IRWXO |
| 181 | return present_permissions & disallowed_permissions == 0 |
| 182 | else: |
| 183 | try: |
| 184 | # Skip known problems for non-Win32 filesystems without POSIX permissions. |
| 185 | import subprocess |
| 186 | fstype = subprocess.check_output('stat -f -c "%%T" %s' % (filename), |
| 187 | shell=True, |
| 188 | stderr=subprocess.STDOUT) |
| 189 | if 'fuseblk' in fstype: |
| 190 | logger.info('Skipping file permissions check for %s. Filesystem fuseblk detected.', |
| 191 | filename) |
| 192 | return True |
| 193 | except: |
| 194 | # Swallow exception here, but we might run into trouble later! |
| 195 | logger.error('Could not determine filesystem type. %s', filename) |
| 196 | present_permissions = os.stat(filename)[0] |
| 197 | disallowed_permissions = stat.S_IRWXG | stat.S_IRWXO |
| 198 | return present_permissions & disallowed_permissions == 0 |
| 199 | |
| 200 | # Fixes permissions on a sensitive file. |
| 201 | def fixSensitiveFilePermissions(filename, hasEnabledKeys): |
no outgoing calls
no test coverage detected