Able to set different permissions for subdirectories for different users?

46 views
Skip to first unread message

seravitae

unread,
Jul 11, 2011, 12:14:05 AM7/11/11
to Python FTP server library - Discussion group
Hello,

I was just wondering if it was possible with PyFTPD to set permissions
for subdirectories for different users. By this I mean:

/home/ftpd/project/ <-all users read, list, no write/delete
/home/ftpd/project/alice/ <-- alice full permissions, *bob readonly*
/home/ftpd/users/bob/ <-- bob full permissions, *alice readonly*

I am trying to develop a server to host student projects, I would like
every student to be able to read other student's work but only write
their own work into their own directory.

Is this possible? It seems the permissions overwrite method does not
seem to specify a user or allow tuples with the respective permission
set.

Cheers,
Sebastian

Giampaolo Rodolà

unread,
Jul 11, 2011, 5:10:27 AM7/11/11
to pyft...@googlegroups.com
Why doesn't override_perm method work for you?
You first define all users, then set /home/ftpd/project as home with
ro permissions and finally override /home/ftpd/project/{USERNAME} with
rw permissions:

users = ['alice', 'bob', 'bill', 'jim']

auth = DummyAuthorizer()
for user in users:
auth.add_user(user, 'somepasswd', '/home/ftpd/project/', perm='elr')
auth.override_perm(user, '/home/ftpd/project/' + user, perm='elradfmw',
recursive=True):

Regards,

Giampaolo


2011/7/11 seravitae <se...@tpg.com.au>:

> --
> You received this message because you are subscribed to the "Python FTP server library" project group:
> http://code.google.com/p/pyftpdlib/
> To post to this group, send email to pyft...@googlegroups.com
> To unsubscribe from this group, send email to pyftpdlib-...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/pyftpdlib

seravitae

unread,
Jul 13, 2011, 3:39:38 AM7/13/11
to Python FTP server library - Discussion group
Oh, you can do that? Thanks for that Giampaolo...

I was reading the tutorial text which says:

override_perm(directory, perm[, recursive=False])
Override permissions for a given directory.

this doesn't state a user parameter as you specified.. so I assumed it
was global parameters..

I guess the tutorial text is wrong?

Kind regards,
Sebastian

On Jul 11, 7:10 pm, Giampaolo Rodolà <g.rod...@gmail.com> wrote:
> Why doesn't override_perm method work for you?
> You first define all users, then set /home/ftpd/project as home with
> ro permissions and finally override /home/ftpd/project/{USERNAME} with
> rw permissions:
>
> users = ['alice', 'bob', 'bill', 'jim']
>
> auth = DummyAuthorizer()
> for user in users:
>     auth.add_user(user, 'somepasswd', '/home/ftpd/project/', perm='elr')
>     auth.override_perm(user, '/home/ftpd/project/' + user, perm='elradfmw',
>                        recursive=True):
>
> Regards,
>
> Giampaolo
>
> 2011/7/11 seravitae <s...@tpg.com.au>:

Giampaolo Rodolà

unread,
Jul 13, 2011, 3:43:35 AM7/13/11
to pyft...@googlegroups.com
Yeah, it was wrong, sorry. =)
It is fixed now.

2011/7/13 seravitae <se...@tpg.com.au>:

Brian Rak

unread,
Jul 13, 2011, 11:25:22 PM7/13/11
to Python FTP server library - Discussion group
It might be a bit more work for you (unless you know Python), but this
is pretty simple to do if you write your own authorizor (or ever just
override has_perm). We've implemented per-file and per-user
permissions this way, and it's pretty straightforward. If you do
choose to do this, you just need to return True/False from this
function depending on if they should have access or not. You can
check the contents of the 'perm' variable to see if they are
requesting write access or not. If perm is (a|d|f|w) they are trying
to write to the file, otherwise it's read-only.

seravitae

unread,
Jul 18, 2011, 9:31:40 AM7/18/11
to Python FTP server library - Discussion group
Thanks Giampaolo for the fix, glad I am not going insane! :)

Thanks Brian that also might be useful I will have a think about the
project requirements and maybe do that.
Reply all
Reply to author
Forward
0 new messages