Fix getting theme and language from LDAP
authorJamie Cameron <jcameron@webmin.com>
Fri, 17 Sep 2010 22:13:22 +0000 (15:13 -0700)
committerJamie Cameron <jcameron@webmin.com>
Fri, 17 Sep 2010 22:13:22 +0000 (15:13 -0700)
acl/acl-lib.pl
miniserv.pl
web-lib-funcs.pl

index 6f90899..f4291f0 100755 (executable)
@@ -1348,7 +1348,7 @@ my ($dbh, $proto, $fromid, $toid);
 # Check if the source user/group is in a DB
 my $userdb = &get_userdb_string();
 if ($userdb) {
-       ($dbh, $proto) = &connect_userdb($userdb);
+       ($dbh, $proto, $prefix, $args) = &connect_userdb($userdb);
        &error($dbh) if (!ref($dbh));
        if ($proto eq "mysql" || $proto eq "postgresql") {
                # Search in SQL DB
@@ -1365,26 +1365,41 @@ if ($userdb) {
                }
        elsif ($proto eq "ldap") {
                # Search in LDAP
-               # XXX
+               my $fromclass = $fromtype eq "user" ? "userclass"
+                                                   : "groupclass";
+               my $rv = $dbh->search(
+                       base => $prefix,
+                       filter => '(&(cn='.$from.')(objectClass='.
+                                 $fromclass.'))',
+                       scope => 'sub');
+               $rv->code && &error($rv->error);
+               my ($fromobj) = $rv->all_entries;
+               $fromid = $fromobj ? $fromobj->dn() : undef;
+               my $toclass = $totype eq "user" ? "userclass"
+                                               : "groupclass";
+               my $rv = $dbh->search(
+                       base => $prefix,
+                       filter => '(&(cn='.$to.')(objectClass='.
+                                 $toclass.'))',
+                       scope => 'sub');
+               $rv->code && &error($rv->error);
+               my ($toobj) = $rv->all_entries;
+               $toid = $toobj ? $toobj->dn() : undef;
                }
        }
 
-if (defined($fromid) && defined($toid)) {
+if (defined($fromid) && defined($toid) &&
+    ($proto eq "mysql" || $proto eq "postgresql")) {
        # Copy from database to database
-       if ($proto eq "mysql" || $proto eq "postgresql") {
-               my $delcmd = $dbh->prepare("delete from webmin_${totype}_acl where id = ? and module = ?");
-               my $cmd = $dbh->prepare("insert into webmin_${totype}_acl select ?,module,attr,value from webmin_${fromtype}_acl where id = ? and module = ?");
-               foreach my $m (@$mods) {
-                       $delcmd && $delcmd->execute($toid, $m) ||
-                               &error("Failed to clear ACLs : ".$dbh->errstr);
-                       $delcmd->finish();
-                       $cmd && $cmd->execute($toid, $fromid, $m) ||
-                               &error("Failed to copy ACLs : ".$dbh->errstr);
-                       $cmd->finish();
-                       }
-               }
-       elsif ($proto eq "ldap") {
-               # XXX
+       my $delcmd = $dbh->prepare("delete from webmin_${totype}_acl where id = ? and module = ?");
+       my $cmd = $dbh->prepare("insert into webmin_${totype}_acl select ?,module,attr,value from webmin_${fromtype}_acl where id = ? and module = ?");
+       foreach my $m (@$mods) {
+               $delcmd && $delcmd->execute($toid, $m) ||
+                       &error("Failed to clear ACLs : ".$dbh->errstr);
+               $delcmd->finish();
+               $cmd && $cmd->execute($toid, $fromid, $m) ||
+                       &error("Failed to copy ACLs : ".$dbh->errstr);
+               $cmd->finish();
                }
        }
 elsif (!defined($fromid) && !defined($toid)) {
index 6fa5ec7..21f4dec 100755 (executable)
@@ -2067,6 +2067,7 @@ if (&get_type($full) eq "internal/cgi" && $validated != 4) {
                }
        print DEBUG "REMOTE_USER = ",$ENV{"REMOTE_USER"},"\n";
        print DEBUG "BASE_REMOTE_USER = ",$ENV{"BASE_REMOTE_USER"},"\n";
+       print DEBUG "proto=$uinfo->{'proto'} id=$uinfo->{'id'}\n" if ($uinfo);
        $ENV{"SSL_USER"} = $peername if ($validated == 2);
        $ENV{"ANONYMOUS_USER"} = "1" if ($validated == 3 || $validated == 4);
        $ENV{"DOCUMENT_ROOT"} = $roots[0];
@@ -4166,11 +4167,11 @@ if ($config{'userdb'}) {
                        }
 
                # Extract attributes
+               my $pass = $u->get_value('pass');
                $user = { 'name' => $username,
                          'id' => $u->dn(),
-                         'pass' => $u->get_value('pass'),
+                         'pass' => $pass,
                          'proto' => $proto };
-               my %attrs;
                foreach my $la ($u->get_value('webminAttr')) {
                        my ($attr, $value) = split(/=/, $la, 2);
                        $attrs{$attr} = $value;
index 7c96188..c073dde 100755 (executable)
@@ -3391,7 +3391,7 @@ elsif ($u ne '') {
                                my ($acl) = $rv->all_entries;
                                if ($acl) {
                                        foreach my $av ($acl->get_value(
-                                                               'webminAcl')) {
+                                                       'webminAclEntry')) {
                                                my ($a, $v) = split(/=/, $av,2);
                                                $rv{$a} = $v;
                                                }
@@ -3478,7 +3478,7 @@ if ($userdb) {
                my ($group) = $rv->all_entries;
 
                # Find ACL sub-object for the module
-               my $ldapm = $m;
+               my $ldapm = $m || "global";
                if ($group) {
                        my $rv = $dbh->search(
                                base => $group->dn(),
@@ -3490,7 +3490,8 @@ if ($userdb) {
                                }
                        my ($acl) = $rv->all_entries;
                        if ($acl) {
-                               foreach my $av ($acl->get_value('webminAcl')) {
+                               foreach my $av ($acl->get_value(
+                                               'webminAclEntry')) {
                                        my ($a, $v) = split(/=/, $av, 2);
                                        $rv{$a} = $v;
                                        }
@@ -3596,6 +3597,7 @@ if ($userdb && ($u ne $base_remote_user || $remote_user_proto)) {
 
                if ($user) {
                        # Find the ACL sub-object for the module
+                       $foundindb = 1;
                        my $ldapm = $m || "global";
                        my $rv = $dbh->search(
                                base => $user->dn(),
@@ -3607,20 +3609,20 @@ if ($userdb && ($u ne $base_remote_user || $remote_user_proto)) {
                                }
                        my ($acl) = $rv->all_entries;
 
-                       my @attrs;
+                       my @al;
                        foreach my $a (keys %{$_[0]}) {
-                               push(@attrs, "webminAclEntry",
-                                            $a."=".$_[0]->{$a});
+                               push(@al, $a."=".$_[0]->{$a});
                                }
                        if ($acl) {
                                # Update attributes
                                $rv = $dbh->modify($acl->dn(),
-                                                  replace => { @attrs });
+                                 replace => { "webminAclEntry", \@al });
                                }
                        else {
                                # Add a sub-object
-                               push(@attrs, "cn", $ldapm,
-                                            "objectClass", "webminAcl");
+                               my @attrs = ( "cn", $ldapm,
+                                             "objectClass", "webminAcl",
+                                             "webminAclEntry", \@al );
                                $rv = $dbh->add("cn=".$ldapm.",".$user->dn(),
                                                attr => \@attrs);
                                }
@@ -3732,9 +3734,10 @@ if ($userdb) {
                        }
                my ($group) = $rv->all_entries;
 
-               my $ldapm = $m;
+               my $ldapm = $m || "global";
                if ($group) {
                        # Find the ACL sub-object for the module
+                       $foundindb = 1;
                        my $rv = $dbh->search(
                                base => $group->dn(),
                                filter => '(cn='.$ldapm.')',
@@ -3745,20 +3748,20 @@ if ($userdb) {
                                }
                        my ($acl) = $rv->all_entries;
 
-                       my @attrs;
+                       my @al;
                        foreach my $a (keys %{$_[0]}) {
-                               push(@attrs, "webminAclEntry",
-                                            $a."=".$_[0]->{$a});
+                               push(@al, $a."=".$_[0]->{$a});
                                }
                        if ($acl) {
                                # Update attributes
                                $rv = $dbh->modify($acl->dn(),
-                                                  replace => { @attrs });
+                                       replace => { "webminAclEntry", \@al });
                                }
                        else {
                                # Add a sub-object
-                               push(@attrs, "cn", $ldapm,
-                                            "objectClass", "webminAcl");
+                               my @attrs = ( "cn", $ldapm,
+                                             "objectClass", "webminAcl",
+                                             "webminAclEntry", \@al );
                                $rv = $dbh->add("cn=".$ldapm.",".$group->dn(),
                                                attr => \@attrs);
                                }