]>
git.proxmox.com Git - pmg-api.git/blob - PMG/LDAPConfig.pm
1 package PMG
::LDAPConfig
;
9 use PVE
::JSONSchema
qw(get_standard_option);
11 use PVE
::SectionConfig
;
13 use base
qw(PVE::SectionConfig);
15 PVE
::JSONSchema
::register_format
('ldap-simple-attr', \
&verify_ldap_simple_attr
);
16 sub verify_ldap_simple_attr
{
17 my ($attr, $noerr) = @_;
19 if ($attr =~ m/^[a-zA-Z0-9]+$/) {
23 die "value '$attr' does not look like a simple ldap attribute name\n" if !$noerr;
28 my $inotify_file_id = 'pmg-ldap.conf';
29 my $config_filename = '/etc/pmg/ldap.conf';
33 type
=> { description
=> "Section type." },
35 description
=> "Profile ID.",
36 type
=> 'string', format
=> 'pve-configid',
45 description
=> "Flag to disable/deactivate the entry.",
50 description
=> "Description.",
56 description
=> "LDAP protocol mode ('ldap' or 'ldaps').",
58 enum
=> ['ldap', 'ldaps'],
62 description
=> "Server address.",
63 type
=> 'string', format
=> 'address',
67 description
=> "Fallback server address. Userd when the first server is not available.",
68 type
=> 'string', format
=> 'address',
72 description
=> "Specify the port to connect to.",
78 description
=> "Bind domain name.",
82 description
=> "Bind password.",
86 description
=> "Base domain name.",
90 description
=> "Base domain name for groups.",
94 description
=> "LDAP filter.",
98 description
=> "Account attribute name name.",
99 type
=> 'string', format
=> 'ldap-simple-attr-list',
100 default => 'sAMAccountName, uid',
103 description
=> "List of mail attribute names.",
104 type
=> 'string', format
=> 'ldap-simple-attr-list',
105 default => "mail, userPrincipalName, proxyAddresses, othermailbox, mailAlternativeAddress",
108 description
=> "List of objectclasses for groups.",
109 type
=> 'string', format
=> 'ldap-simple-attr-list',
110 default => "group, univentionGroup, ipausergroup",
117 disable
=> { optional
=> 1 },
118 comment
=> { optional
=> 1 },
119 server1
=> { optional
=> 0 },
120 server2
=> { optional
=> 1 },
121 port
=> { optional
=> 1 },
122 mode
=> { optional
=> 1 },
123 binddn
=> { optional
=> 1 },
124 bindpw
=> { optional
=> 1 },
125 basedn
=> { optional
=> 1 },
126 groupbasedn
=> { optional
=> 1 },
127 filter
=> { optional
=> 1 },
128 accountattr
=> { optional
=> 1 },
129 mailattr
=> { optional
=> 1 },
130 groupclass
=> { optional
=> 1 },
142 sub parse_section_header
{
143 my ($class, $line) = @_;
145 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
146 my ($type, $profileId) = ($1, $2);
147 my $errmsg = undef; # set if you want to skip whole section
148 eval { PVE
::JSONSchema
::pve_verify_configid
($profileId); };
150 my $config = {}; # to return additional attributes
151 return ($type, $profileId, $errmsg, $config);
157 my ($class, $filename, $raw) = @_;
159 my $cfg = $class->SUPER::parse_config
($filename, $raw);
161 foreach my $profile (keys %{$cfg->{ids
}}) {
162 my $data = $cfg->{ids
}->{$profile};
164 $data->{comment
} = PVE
::Tools
::decode_text
($data->{comment
})
165 if defined($data->{comment
});
167 $data->{bindpw
} = decode_base64
($data->{bindpw
})
168 if defined($data->{bindpw
});
175 my ($class, $filename, $cfg) = @_;
177 foreach my $profile (keys %{$cfg->{ids
}}) {
178 my $data = $cfg->{ids
}->{$profile};
180 $data->{comment
} = PVE
::Tools
::encode_text
($data->{comment
})
181 if defined($data->{comment
});
183 $data->{bindpw
} = encode_base64
($data->{bindpw
}, '')
184 if defined($data->{bindpw
});
187 $class->SUPER::write_config
($filename, $cfg);
193 my $class = ref($type) || $type;
195 my $cfg = PVE
::INotify
::read_file
($inotify_file_id);
197 return bless $cfg, $class;
203 PVE
::INotify
::write_file
($inotify_file_id, $self);
206 my $lockfile = "/var/lock/pmgldapconfig.lck";
209 my ($code, $errmsg) = @_;
211 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
213 $errmsg ?
die "$errmsg: $err" : die $err;
218 __PACKAGE__-
>register();
221 sub read_pmg_ldap_conf
{
222 my ($filename, $fh) = @_;
224 local $/ = undef; # slurp mode
226 my $raw = defined($fh) ?
<$fh> : '';
228 return __PACKAGE__-
>parse_config($filename, $raw);
231 sub write_pmg_ldap_conf
{
232 my ($filename, $fh, $cfg) = @_;
234 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
236 my $gid = getgrnam('www-data');
240 PVE
::Tools
::safe_print
($filename, $fh, $raw);
243 PVE
::INotify
::register_file
($inotify_file_id, $config_filename,
244 \
&read_pmg_ldap_conf
,
245 \
&write_pmg_ldap_conf
,
247 always_call_parser
=> 1);