2 # Common functions for the htaccess and htpasswd file management module
4 BEGIN { push(@INC, ".."); };
7 do 'htpasswd-file-lib.pl';
10 if ($module_info{'usermin'}) {
11 # Allowed directories are in module configuration
12 &switch_to_remote_user();
13 &create_user_config_dirs();
14 $default_dir = &resolve_links($remote_user_info[7]);
15 push(@accessdirs, $default_dir) if ($config{'home'});
17 foreach $d (split(/\t+/, $config{'dirs'})) {
18 push(@accessdirs, $d =~ /^\// ? $d : "$default_dir/$d");
20 $directories_file = "$user_module_config_directory/directories";
21 $apachemod = "htaccess";
22 $can_htpasswd = $config{'can_htpasswd'};
23 $can_htgroups = $config{'can_htgroups'};
24 $can_create = !$config{'nocreate'};
27 # Allowed directories come from ACL
28 %access = &get_module_acl();
30 if (&supports_users()) {
32 @uinfo = getpwnam($remote_user);
33 if ($access{'home'} && scalar(@uinfo)) {
34 push(@accessdirs, &resolve_links($uinfo[7]));
38 foreach $d (split(/\t+/, $access{'dirs'})) {
39 push(@accessdirs, $d =~ /^\// || !@uinfo ?
40 $d : &resolve_links("$uinfo[7]/$d"));
42 $directories_file = "$module_config_directory/directories";
43 $directories_file .= ".".$remote_user if ($access{'userdirs'});
44 $apachemod = "apache";
47 $default_dir = $accessdirs[0];
48 $can_sync = $access{'sync'};
49 $can_create = !$access{'uonly'};
52 # list_directories([even-if-missing])
53 # Returns a list of protected directories known to this module, and the
54 # users file, encryption mode, sync mode and groups file for each
58 open(DIRS, $directories_file);
61 local @dir = split(/\t+/, $_);
63 if ($_[0] || -d $dir[0] && -r "$dir[0]/$config{'htaccess'}") {
71 # save_directories(&dirs)
72 # Save the list of known directories, which must be in the same format as
73 # returned by list_directories
77 &open_tempfile(DIRS, ">$directories_file");
78 foreach $d (@{$_[0]}) {
79 &print_tempfile(DIRS, join("\t", @$d),"\n");
81 &close_tempfile(DIRS);
85 # Returns 1 if files can be created under some directory, 0 if not
88 return 1 if (!$ENV{'GATEWAY_INTERFACE'});
90 foreach $d (@accessdirs) {
91 return 1 if (&is_under_directory(&resolve_links($d),
92 &resolve_links($_[0])));
98 # Switch to the Unix user that files are accessed as.
99 # No need to do anything for Usermin, because the switch was done above.
102 if (!$module_info{'usermin'} &&
103 $access{'user'} ne 'root' && !defined($old_uid) && &supports_users()) {
104 local @uinfo = getpwnam($access{'user'} eq "*" ? $remote_user
108 $) = "$uinfo[3] $uinfo[3]";
115 if (defined($old_uid)) {
118 $old_uid = $old_gid = undef;