开发者

python user permissions

开发者 https://www.devze.com 2023-03-23 17:50 出处:网络
I have a question related to user permissions in python. I have a project that uses the file system to store information about specific tasks. Of course this can be edited/deleted if user wants to. No

I have a question related to user permissions in python. I have a project that uses the file system to store information about specific tasks. Of course this can be edited/deleted if user wants to. Now say a user starts the program using sudo sh start.sh. He then does some operations and data is stored. Now if anyone else or even the same user will start the program without sudo rights when trying to delete/modify those file a permission denied OSError is raised. Now this seems logical but my question is:

  1. Does python offer any way to choose the permissions when writing/creating a file/folder? More precisely can you create files that will be accessible to all users from sudo ?

  2. Does python offer any way to request a users开发者_运维百科 permission when starting the program/ during program execution?

Regards, Bogdan


Looks like you need os.fchown().

I don't know what you mean by your second question - do you want to ask for a root password and use it to gain access to a file that the normal user wouldn't have access to?

0

精彩评论

暂无评论...
验证码 换一张
取 消