52
51
Returns (None, None) if the path is empty.
54
53
>>> stubconfig = {'paths': {'jails': {'mounts': '/jails'}}}
55
>>> url_to_local(stubconfig, '')
57
55
>>> url_to_local(stubconfig, 'joe/foo/bar/baz')
58
56
('joe', '/jails/joe/home/joe/foo/bar/baz')
57
>>> url_to_local(stubconfig, 'joe')
58
('joe', '/jails/joe/home/joe')
59
>>> url_to_local(stubconfig, 'joe/')
60
('joe', '/jails/joe/home/joe')
62
We have some protection from various potential attacks. An empty,
63
absolute, or ..-prefixed path yields a special result.
65
>>> url_to_local(stubconfig, '')
67
>>> url_to_local(stubconfig, '/foo')
69
>>> url_to_local(stubconfig, '../bar')
61
73
# First normalise the path
87
99
urlpath: See urlpath in url_to_local.
89
>>> url_to_jailpaths("joe/mydir/myfile")
90
('joe', '/var/lib/ivle/jailmounts/joe', '/home/joe/mydir/myfile')
101
>>> stubconfig = {'paths': {'jails': {'mounts': '/jails'}}}
92
>>> url_to_jailpaths("")
103
>>> url_to_jailpaths(stubconfig, "joe/mydir//myfile/.././myfile")
104
('joe', '/jails/joe', '/home/joe/mydir/myfile')
105
>>> url_to_jailpaths(stubconfig, "")
107
>>> url_to_jailpaths(stubconfig, "../foo")
109
>>> url_to_jailpaths(stubconfig, "/foo")
93
110
(None, None, None)
95
112
# First normalise the path
96
113
urlpath = os.path.normpath(urlpath)
97
# Now if it begins with ".." then it's illegal
98
if urlpath.startswith(".."):
114
# Now if it begins with "..", or is absolute, then it's illegal
115
if urlpath.startswith("..") or os.path.isabs(urlpath):
99
116
return (None, None, None)
100
117
# Note: User can be a group name. There is absolutely no difference in our
101
118
# current directory scheme.
102
119
(user, subpath) = util.split_path(urlpath)
103
120
if user is None: return (None, None, None)
105
jail = os.path.join(ivle.conf.jail_base, user)
106
path = url_path_to_jail_path(urlpath)
122
jail = os.path.join(config['paths']['jails']['mounts'], user)
123
path = to_home_path(urlpath)
108
125
return (user, jail, path)
110
def url_path_to_jail_path(urlpath):
111
"""Given a URL path (eg. joe/foo/bar/baz), returns a path within the jail.
127
def to_home_path(urlpath):
128
"""Given a URL path (eg. joe/foo/bar/baz), returns a path within the home.
113
>>> url_path_to_jail_path('joe/foo/bar/baz')
130
>>> to_home_path('joe/foo/bar/baz')
114
131
'/home/joe/foo/bar/baz'
132
>>> to_home_path('joe/foo//bar/baz/../../')
134
>>> to_home_path('joe/foo//bar/baz/../../../../../') is None
138
urlpath = os.path.normpath(urlpath)
139
# If it begins with '..', it's illegal.
140
if urlpath.startswith(".."):
116
143
return os.path.join('/home', urlpath)
118
145
def svnpublished(path):