【问题标题】:How would one programmatically stop an app from reading computer files?如何以编程方式阻止应用程序读取计算机文件?
【发布时间】:2020-11-05 06:09:06
【问题描述】:

在诸如 Python 之类的脚本语言中,您将如何阻止应用程序读取计算机文件,尤其是敏感的系统级文件?

编辑:明确地说,我的意思是为该应用设置权限,使其无法访问计算机文件,即使在脚本运行完成后(设置权限)也是如此。

【问题讨论】:

  • 通过以无权访问所述文件的用户身份运行它。通常,这是文件系统权限问题,而不是编程问题。

标签: python security scripting permissions


【解决方案1】:

您应该以非特权用户身份运行您的 python 脚本 并在验证访问权限后读取文件

# check readability of the path 
if os.access("file.txt", os.R_OK):  
    # open txt file as file 
    with open("file.tx") as file: 
        return file.read() 

【讨论】:

  • 嗨维韦克,感谢您的回答。我应该更清楚,但我的意思是更改应用程序本身的权限以不再读取文件,即使在脚本运行后(权限设置)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-29
  • 1970-01-01
  • 1970-01-01
  • 2012-09-23
  • 1970-01-01
相关资源
最近更新 更多