I am setting a WebDAV server for my lab using Apache.
Setting the directives of the various users directory in the virtual host configuration works:
<Directory /home/userfoo>
DAV On
AuthName "webdav"
AuthType Basic
AuthBasicProvider external
AuthExternal pwauth
Require user userfoo
AssignUserID userfoo userfoo
Options +Indexes
AllowOverride all
</Directory>
<Directory /home/davtest>
DAV On
AuthName "webdav"
AuthType Basic
AuthBasicProvider external
AuthExternal pwauth
Require user davtest
AssignUserID davtest davtest
Options +Indexes
AllowOverride all
</Directory>
[...]
Aside using mod_macro (that would still need me to put each user individually) is there a way to use RegEx where part of the path in the Directory directive is re-used inside the directive? Something like:
<Directory ~ "/home/*+">
DAV On
AuthName "webdav"
AuthType Basic
AuthBasicProvider external
AuthExternal pwauth
Require user $1
AssignUserID $1 $1
Options +Indexes
AllowOverride all
</Directory>
Instead of Directive directive, you can use Apache's DirectoryMatch directive that gives you ability to match a regular expression and use capture groups:
<DirectoryMatch "^/home/(?<USERNAME>[^/]+)">
DAV On
AuthName "webdav"
AuthType Basic
AuthBasicProvider external
AuthExternal pwauth
Require user %{env:MATCH_USERNAME}
AssignUserID %{env:MATCH_USERNAME} %{env:MATCH_USERNAME}
Options +Indexes
AllowOverride all
</DirectoryMatch>
In my case capture groups didn't work.
Another flexible way to achieve this is by using the mod_perl module and choose the logic you want.
For example, in my case all "normal" users are under the users group, and I had installed the members utility, so I done just:
<Perl>
my $group = "users";
my $output = `members $group`;
chomp($output);
my @members = split(/\s+/, $output);
foreach ( @members ) {
push @PerlConfig, qq|
<Directory /home/$_ >
DAV On
AuthName "webdav"
AuthType Basic
AuthBasicProvider external
AuthExternal pwauth
Require user $_
AssignUserID $_ $_
Options +Indexes
AllowOverride all
</Directory> |;
}
</Perl>
Note that the perl script runs only once when apache loads the configuration, not for each request, so when you add a new user you need to reload the apache configuration, e.g. with service apache2 reload. If you use adduser you can do that automatically in /usr/local/sbin/adduser.local.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With