]> git.proxmox.com Git - pmg-api.git/blobdiff - PMG/LDAPConfig.pm
PMG/Service/pmgproxy.pm - fix package names
[pmg-api.git] / PMG / LDAPConfig.pm
index b6bb49daa4ff29548c62c63471b4d89ffd7b7ab1..5f3c451b86f6dbb99440d6ba9ac5744e064aafe3 100644 (file)
@@ -12,11 +12,14 @@ use PVE::SectionConfig;
 
 use base qw(PVE::SectionConfig);
 
+my $inotify_file_id = 'pmg-ldap.conf';
+my $config_filename = '/etc/pmg/ldap.conf';
+
 my $defaultData = {
     propertyList => {
        type => { description => "Section type." },
-       section => {
-           description => "Secion ID.",
+       profile => {
+           description => "Profile ID.",
            type => 'string', format => 'pve-configid',
        },
     },
@@ -79,9 +82,9 @@ sub properties {
        },
        accountattr => {
            description => "Account attribute name name.",
-           type => 'string',
+           type => 'string', format => 'string-list',
            pattern => '[a-zA-Z0-9]+',
-           default => 'sAMAccountName',
+           default => 'sAMAccountName, uid',
        },
        mailattr => {
            description => "List of mail attribute names.",
@@ -89,6 +92,11 @@ sub properties {
            pattern => '[a-zA-Z0-9]+',
            default => "mail, userPrincipalName, proxyAddresses, othermailbox",
        },
+       groupclass => {
+           description => "List of objectclasses for groups.",
+           type => 'string', format => 'string-list',
+           default => "group, univentionGroup, ipausergroup",
+       },
     };
 }
 
@@ -107,6 +115,7 @@ sub options {
        filter => { optional => 1 },
        accountattr => { optional => 1 },
        mailattr => { optional => 1 },
+       groupclass => { optional => 1 },
     };
 }
 
@@ -122,12 +131,12 @@ sub parse_section_header {
     my ($class, $line) = @_;
 
     if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
-       my ($type, $sectionId) = ($1, $2);
+       my ($type, $profileId) = ($1, $2);
        my $errmsg = undef; # set if you want to skip whole section
-       eval { PVE::JSONSchema::pve_verify_configid($sectionId); };
+       eval { PVE::JSONSchema::pve_verify_configid($profileId); };
        $errmsg = $@ if $@;
        my $config = {}; # to return additional attributes
-       return ($type, $sectionId, $errmsg, $config);
+       return ($type, $profileId, $errmsg, $config);
     }
     return undef;
 }
@@ -137,8 +146,8 @@ sub parse_config {
 
     my $cfg = $class->SUPER::parse_config($filename, $raw);
 
-    foreach my $section (keys %{$cfg->{ids}}) {
-       my $data = $cfg->{ids}->{$section};
+    foreach my $profile (keys %{$cfg->{ids}}) {
+       my $data = $cfg->{ids}->{$profile};
 
        $data->{comment} = PVE::Tools::decode_text($data->{comment})
            if defined($data->{comment});
@@ -153,8 +162,8 @@ sub parse_config {
 sub write_config {
     my ($class, $filename, $cfg) = @_;
 
-    foreach my $section (keys %{$cfg->{ids}}) {
-       my $data = $cfg->{ids}->{$section};
+    foreach my $profile (keys %{$cfg->{ids}}) {
+       my $data = $cfg->{ids}->{$profile};
 
        $data->{comment} = PVE::Tools::encode_text($data->{comment})
            if defined($data->{comment});
@@ -166,6 +175,22 @@ sub write_config {
     $class->SUPER::write_config($filename, $cfg);
 }
 
+sub new {
+    my ($type) = @_;
+
+    my $class = ref($type) || $type;
+
+    my $cfg = PVE::INotify::read_file($inotify_file_id);
+
+    return bless $cfg, $class;
+}
+
+sub write {
+    my ($self) = @_;
+
+    PVE::INotify::write_file($inotify_file_id, $self);
+}
+
 my $lockfile = "/var/lock/pmgldapconfig.lck";
 
 sub lock_config {
@@ -186,7 +211,7 @@ sub read_pmg_ldap_conf {
 
     local $/ = undef; # slurp mode
 
-    my $raw = <$fh>;
+    my $raw = defined($fh) ? <$fh> : '';
 
     return __PACKAGE__->parse_config($filename, $raw);
 }
@@ -196,14 +221,18 @@ sub write_pmg_ldap_conf {
 
     my $raw = __PACKAGE__->write_config($filename, $cfg);
 
-    chmod(0600, $fh);
+    my $gid = getgrnam('www-data');
+    chown(0, $gid, $fh);
+    chmod(0640, $fh);
 
     PVE::Tools::safe_print($filename, $fh, $raw);
 }
 
-PVE::INotify::register_file('pmg-ldap.conf', "/etc/pmg/ldap.conf",
+PVE::INotify::register_file($inotify_file_id, $config_filename,
                            \&read_pmg_ldap_conf,
-                           \&write_pmg_ldap_conf);
+                           \&write_pmg_ldap_conf,
+                           undef,
+                           always_call_parser => 1);
 
 
 1;