Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to offer our users an Apache WebDav space where they can store their calendar (.ics) files. I've got Dav and LDAP authentication running already. But I fail to jail users to some sub-directories. After all I don't want them to access each other's calendar files.

Example: Let's say user johndoe logs in. Then I'd like to have his "/" path be mapped to /var/www/users/johndoe on disk. So that every user has their own directory.

What I have tried so far:

  1. UserDir /var/www/users/*/

    but it seems like this directory just sets the path for /~johndoe/ requests which is not what I want.

  2. RewriteRule ^/ /users/%{REMOTE_USER} [R]

    Fails. And it's probably just rewriting the path which isn't what I want.

  3. AliasMatch ^/ /var/www/users/%{REMOTE_USER}/

    This should map the path to a directory on disk but the %{REMOTE_USER} does not get expanded.

Is is possible to jail logged in users to some subdirectory? Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

If you are willing to use a directory prefix instead of "/", you can use something like this:

# Let's setup WebDAV first
<Directory /var/lib/storage>
        Dav On
        Options Indexes
        AllowOverride None
</Directory>
# Now we'll set up the user area mapping
RewriteCond %{REQUEST_URI} ^/storage/
RewriteRule ^/storage/(.*?)$ /var/lib/storage/user/%{LA-U:REMOTE_USER}/$1 [L]

Moreover, the same user directories can be accessed read-only using the /~user/ syntax

# Public area can be accessed as https://server/~user/
RewriteCond %{REQUEST_URI} ^/~
RewriteCond %{REQUEST_METHOD} ^(GET|POST)$
RewriteRule ^/~([^/]+)/?(.*)    /var/lib/storage/user/$1/$2 [L]

YMMV

share|improve this answer
    
Thanks for your response. Your solution worked well and pushed me in the right direction. Now my final solution is: RewriteEngine On RewriteRule ^/calendar.ics$ /var/www/users/%{LA-U:REMOTE_USER}.ics [L] RewriteRule !^/calendar.ics$ - [R=404,L] Users can use server/calendar.ics whch is remapped to /var/www/users/USERNAME.ics The problem with your solution is that I had to pre-create all the directories for the users. Apache doesn't handle that and returns a 404 if the directory didn't exist. As I just need a single file this works well. Thanks again. –  Signum Nov 17 '09 at 11:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.