Multiple home directories.

273 views
Skip to first unread message

Petey

unread,
Jul 12, 2011, 1:53:08 PM7/12/11
to pyft...@googlegroups.com
Is it possible to create multiple home directories?

I tried:

homedir = 'D:/books', 'D:/pictures'
authorizer.add_user("user", "password", homedir, perm='elradfmw')

Error:
  File "build\bdist.win32\egg\pyftpdlib\ftpserver.py", line 384, in add_user
  File "C:\Python\lib\genericpath.py", line 41, in isdir
    st = os.stat(s)
TypeError: coercing to Unicode: need string or buffer, tuple found




Giampaolo Rodolà

unread,
Jul 12, 2011, 3:07:17 PM7/12/11
to pyft...@googlegroups.com
No it doesn't (what sense does it make?).


2011/7/12 Petey <efr...@gmail.com>:

> --
> 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

Petey

unread,
Jul 13, 2011, 10:57:56 AM7/13/11
to pyft...@googlegroups.com
I want to share files from more locations (folders or drives).

Will there be a way around?

Giampaolo Rodolà

unread,
Jul 13, 2011, 11:11:39 AM7/13/11
to pyft...@googlegroups.com
This is not Samba where you can share different folders then you see
them grouped togheter under a common root.
In FTP all users have a *single* home directory.
From there, the user can navigate the subdirectories
(pyftpdlib.ftpserver.AbstractedFs) or escape the home and navigate the
whole filesystem (pyftpdlib.contrib.filesystems.UnixFilesystem).

If you are on Windows and want to share different folders then you
have to put them in the home directory.

Regards,

Giampaolo

2011/7/13 Petey <efr...@gmail.com>:


> I want to share files from more locations (folders or drives).
>
> Will there be a way around?
>

Andrew Scheller

unread,
Jul 13, 2011, 12:17:00 PM7/13/11
to pyft...@googlegroups.com
> If you are on Windows and want to share different folders then you
> have to put them in the home directory.

Would using Junction Points (the Windows equivalent of symlinks) solve
the OP's question?
http://en.wikipedia.org/wiki/NTFS_junction_point

Andrew

Jay Loden

unread,
Jul 13, 2011, 12:26:08 PM7/13/11
to pyft...@googlegroups.com
As far as I know, hard links, symbolic links or junctions should all work if they create a home directory for the user that links to the directories they want to share. 


-Jay

Giampaolo Rodolà

unread,
Jul 13, 2011, 12:40:04 PM7/13/11
to pyft...@googlegroups.com
If Junction Points are the exact equivalent of UNIX symlinks then the
answer is no, at least by using base AbstractedFS.
AbstractedFS class has the peculiarity of:

- resolving all paths via os.path.realpath (hence symlinks are
resolved to their effective destination)
http://code.google.com/p/pyftpdlib/source/browse/tags/release-0.6.0/pyftpdlib/ftpserver.py#1417

- checking whether the path escapes the user home directory, in which
case the server denies access to that path
http://code.google.com/p/pyftpdlib/source/browse/tags/release-0.6.0/pyftpdlib/ftpserver.py#1303

I think we can eventually add an option to disable this behavior so
that symlinks can be used but we gotta pay attention because there
have been security related issues in the past:
http://code.google.com/p/pyftpdlib/issues/detail?id=9
http://code.google.com/p/pyftpdlib/issues/detail?id=55

2011/7/13 Andrew Scheller <gc...@loowis.durge.org>:

Jay Loden

unread,
Jul 13, 2011, 12:44:22 PM7/13/11
to pyft...@googlegroups.com
On Wed, Jul 13, 2011 at 12:40 PM, Giampaolo Rodolà <g.ro...@gmail.com> wrote:
If Junction Points are the exact equivalent of UNIX symlinks then the
answer is no, at least by using base AbstractedFS.
AbstractedFS class has the peculiarity of:

- resolving all paths via os.path.realpath (hence symlinks are
resolved to their effective destination)
http://code.google.com/p/pyftpdlib/source/browse/tags/release-0.6.0/pyftpdlib/ftpserver.py#1417

- checking whether the path escapes the user home directory, in which
case the server denies access to that path
http://code.google.com/p/pyftpdlib/source/browse/tags/release-0.6.0/pyftpdlib/ftpserver.py#1303

I think we can eventually add an option to disable this behavior so
that symlinks can be used but we gotta pay attention because there
have been security related issues in the past:
http://code.google.com/p/pyftpdlib/issues/detail?id=9
http://code.google.com/p/pyftpdlib/issues/detail?id=55

Hrm, I forgot that we resolve symlinks that way. I'm not sure offhand if symbolic links or junctions on windows resolve back with os.path.realpath() but I think hard links will still work. I just checked to confirm and os.path.realpath() does not resolve a hard link to the original path so it would not know that the link points to something outside the homedir. 

-Jay

Giampaolo Rodolà

unread,
Jul 13, 2011, 1:22:37 PM7/13/11
to pyft...@googlegroups.com
Ok, this should do the work.
Quickly tested on Linux and it seems to work. Not sure about Windows
and Junction Points.
I'd be interested to know how tests go there.


from pyftpdlib.ftpserver import FTPHandler, FTPServer,
DummyAuthorizer, AbstractedFS


class UnjailedAbstractedFS(AbstractedFS):
"""
Same as base AbstractedFS but the user can escape its
home directory and follow symlinks pointing outside
of it.
"""

def realpath(self, path):
return path

def validpath(self, path):
return True

def main():
authorizer = DummyAuthorizer()
authorizer.add_user('user', '12345', '.', perm='elradfmw')
authorizer.add_anonymous('.')
handler = FTPHandler
handler.authorizer = authorizer
handler.abstracted_fs = UnjailedAbstractedFS
ftpd = FTPServer(('', 21), handler)
ftpd.serve_forever()

if __name__ == '__main__':
main()

Andrew Scheller

unread,
Jul 13, 2011, 7:42:23 PM7/13/11
to pyft...@googlegroups.com
> but I think hard links will still work. I just checked to confirm and
> os.path.realpath() does not resolve a hard link to the original path so it
> would not know that the link points to something outside the homedir.

...except hardlinks only work for files, and the OP explicitly asked
for multiple directories ;)

Andrew

Jay Loden

unread,
Jul 14, 2011, 10:16:28 AM7/14/11
to pyft...@googlegroups.com
Yes you're right, it was actually a junction I tested, not a hard link. Sorry about that - but in my defense I created it over 2 years ago so I've had plenty of time to forget what I did :) 

Anyway, NTFS junction won't resolve via os.path.realpath() so you can safely use them on Windows as suggested. 

-Jay 
Reply all
Reply to author
Forward
0 new messages