More work on LDAP group creation
authorJamie Cameron <jcameron@webmin.com>
Wed, 15 Sep 2010 23:24:57 +0000 (16:24 -0700)
committerJamie Cameron <jcameron@webmin.com>
Wed, 15 Sep 2010 23:24:57 +0000 (16:24 -0700)
acl/acl-lib.pl
acl/webmin.schema
web-lib-funcs.pl

index ed9706b..2812dc8 100755 (executable)
@@ -715,7 +715,7 @@ my %miniserv;
 
 if ($miniserv{'userdb'} && !$miniserv{'userdb_addto'}) {
        # Adding to group database
-       my ($dbh, $proto) = &connect_userdb($miniserv{'userdb'});
+       my ($dbh, $proto, $prefix, $args) =&connect_userdb($miniserv{'userdb'});
         &error("Failed to connect to group database : $dbh") if (!ref($dbh));
        if ($proto eq "mysql" || $proto eq "postgresql") {
                # Add group with SQL
@@ -744,8 +744,32 @@ if ($miniserv{'userdb'} && !$miniserv{'userdb_addto'}) {
                        }
                }
        elsif ($proto eq "ldap") {
-               # Add user to LDAP
-               # XXX
+               # Add group to LDAP
+               my $dn = "cn=".$group{'name'}.",".$prefix;
+               my @attrs = ( "objectClass", $args->{'groupclass'},
+                             "cn", $group{'name'},
+                             "webminDesc", $group{'desc'} );
+               my @webminattrs;
+               foreach my $attr (keys %group) {
+                       next if ($attr eq "name" || $attr eq "desc" ||
+                                $attr eq "modules");
+                       my $value = $group{$attr};
+                       if ($attr eq "members" || $attr eq "ownmods") {
+                               $value = join(" ", @$value);
+                               }
+                       push(@webminattrs, $attr."=".$value);
+                       }
+               if (@webminattrs) {
+                       push(@attrs, "webminAttr", \@webminattrs);
+                       }
+               if (@{$group{'modules'}}) {
+                       push(@attrs, "webminModule", $group{'modules'});
+                       }
+               my $rv = $dbh->add($dn, attr => \@attrs);
+               if (!$rv || $rv->code) {
+                       &error("Failed to add group to LDAP : ".
+                              ($rv ? $rv->error : "Unknown error"));
+                       }
                }
        &disconnect_userdb($miniserv{'userdb'}, $dbh);
        $group{'proto'} = $proto;
index 1aa89b4..dcf82cc 100644 (file)
@@ -4,37 +4,33 @@
 # Attributes     : 1.3.6.1.4.1.9999.4.1.x
 # Object classes : 1.3.6.1.4.1.9999.4.2.x
 
-attributetype ( 1.3.6.1.4.1.9999.4.1.1 NAME 'webminName'
-       DESC 'Webmin username'
-       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} SINGLE-VALUE )
-
 attributetype ( 1.3.6.1.4.1.9999.4.1.2 NAME 'webminPass'
        DESC 'Webmin password'
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} SINGLE-VALUE )
 
 attributetype ( 1.3.6.1.4.1.9999.4.1.3 NAME 'webminAttr'
        DESC 'Webmin user attribute name=value format'
-       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} COLLECTIVE )
+       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} )
 
 attributetype ( 1.3.6.1.4.1.9999.4.1.4 NAME 'webminAcl'
        DESC 'Webmin user ACL module=name=value format'
-       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} COLLECTIVE )
+       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} )
 
 attributetype ( 1.3.6.1.4.1.9999.4.1.5 NAME 'webminDesc'
        DESC 'Webmin group description'
-       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} SINGLE-VALUE )
+       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} )
 
 attributetype ( 1.3.6.1.4.1.9999.4.1.6 NAME 'webminModule'
        DESC 'Webmin module name'
-       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} COLLECTIVE )
+       SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{255} )
 
-objectclass ( 1.3.6.1.4.1.9999.4.2.1 NAME 'webminUser' SUP top AUXILIARY
+objectclass ( 1.3.6.1.4.1.9999.4.2.1 NAME 'webminUser' SUP top STRUCTURAL
        DESC 'Webmin user account'
-       MUST ( webminName $ webminPass )
+       MUST ( cn $ webminPass )
        MAY ( webminAttr $ webminAcl $ webminModule ))
 
-objectclass ( 1.3.6.1.4.1.9999.4.2.2 NAME 'webminGroup' SUP top AUXILIARY
+objectclass ( 1.3.6.1.4.1.9999.4.2.2 NAME 'webminGroup' SUP top STRUCTURAL
        DESC 'Webmin group account'
-       MUST ( webminName $ webminDesc )
+       MUST ( cn $ webminDesc )
        MAY ( webminAttr $ webminAcl $ webminModule ))
 
index 2000918..f75c7f6 100755 (executable)
@@ -9004,7 +9004,7 @@ if ($proto eq "mysql") {
        my $dbh = $drh->connect($cstr, $user, $pass, { });
        $dbh || return &text('sql_emysqlconnect', $drh->errstr);
        $dbh->{'AutoCommit'} = 1;
-       return wantarray ? ($dbh, $proto) : $dbh;
+       return wantarray ? ($dbh, $proto, $prefix, $args) : $dbh;
        }
 elsif ($proto eq "postgresql") {
        # Connect to PostgreSQL with DBI
@@ -9016,7 +9016,7 @@ elsif ($proto eq "postgresql") {
        my $dbh = $drh->connect($cstr, $user, $pass);
        $dbh || return &text('sql_epostgresqlconnect', $drh->errstr);
        $dbh->{'AutoCommit'} = 1;
-       return wantarray ? ($dbh, $proto) : $dbh;
+       return wantarray ? ($dbh, $proto, $prefix, $args) : $dbh;
        }
 elsif ($proto eq "ldap") {
        # Connect with perl LDAP module
@@ -9051,7 +9051,7 @@ elsif ($proto eq "ldap") {
                return &text('sql_eldaplogin', $user,
                             $mesg ? $mesg->error : "Unknown error");
                }
-       return wantarray ? ($ldap, $proto) : $ldap;
+       return wantarray ? ($ldap, $proto, $prefix, $args) : $ldap;
        }
 else {
        return "Unknown protocol $proto";