开发者

Python: Verifying NFS authentication

开发者 https://www.devze.com 2023-02-17 18:07 出处:网络
Folks, I believe there are two questions I have: one python specific and the other NFS. The basic point is that my program gets the \'username\', \'uid\', NFS server IP and exported_path as input fro

Folks, I believe there are two questions I have: one python specific and the other NFS.

The basic point is that my program gets the 'username', 'uid', NFS server IP and exported_path as input from the user. It now has to verify that the NFS exported path is readable/writable by this user/uid.

My program is running as root on the local machine. The straight-forward approach is to 'useradd' a user with the given username and uid, mount the NFS exported path (run as root for mount) on some temporary mount_point and then execute 'su username -c touch /mnt_pt/tempfile'. IF the usernam开发者_运维知识库e and userid input were correct (and the NFS server was setup correctly) this touch of tempfile will succeed creating tempfile on the NFS remote directory. This is the goal.

Now the two questions are: (i) Is there a simpler way to do this than creating a new unix user, mounting and touching a file to verify the NFS permissions?

(ii) If this is what needs to be done, then I wonder if there are any python modules/packages that will help me execute 'useradd', 'userdel' related commands? I currently intend to use the respective binaries(/usr/sbin/useradd etc) and then invoke subprocess.Popen to execute the command and get the output.

Thank you for any insight.


i) You could do something more arcane, but short of actually touching the file you probably aren't going to be testing exactly what you need to test, so I think I'd probably do it the way you suggest.

ii) You might want to check out the python pwd module if you want to verify user existance or the like, but you'll probably need to leverage the useradd/userdel programs themselves to do the dirty work.

You might want to consider leveraging sudo for your program so the entire thing doesn't have to run as root, it seems like a pretty risky proposition.


There is a python suite to test NFS server functionality.

git://git.linux-nfs.org/projects/bfields/pynfs.git

While it's for NFSv4 you can simply adopt it for v3 as well.

0

精彩评论

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