]>
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);
17 type
=> { description
=> "Section type." },
19 description
=> "Secion ID.",
20 type
=> 'string', format
=> 'pve-configid',
28 description
=> "LDAP protocol mode ('ldap' or 'ldaps').",
30 enum
=> ['ldap', 'ldaps'],
34 description
=> "Server address.",
35 type
=> 'string', format
=> 'address',
38 description
=> "Fallback server address. Userd when the first server is not available.",
39 type
=> 'string', format
=> 'address',
42 description
=> "Specify the port to connect to.",
48 description
=> "Bind domain name.",
52 description
=> "Bind password.",
56 description
=> "Base domain name.",
60 description
=> "Base domain name for groups.",
64 description
=> "LDAP filter.",
68 description
=> "Account attribute name name.",
70 pattern
=> '[a-zA-Z0-9]+',
71 default => 'sAMAccountName',
74 description
=> "List of mail attribute names.",
75 type
=> 'string', format
=> 'string-list',
76 pattern
=> '[a-zA-Z0-9]+',
77 default => "mail, userPrincipalName, proxyAddresses, othermailbox",
84 server1
=> { optional
=> 0 },
85 server2
=> { optional
=> 1 },
86 port
=> { optional
=> 1 },
87 mode
=> { optional
=> 1 },
88 binddn
=> { optional
=> 1 },
89 bindpw
=> { optional
=> 1 },
90 basedn
=> { optional
=> 1 },
91 groupbasedn
=> { optional
=> 1 },
92 filter
=> { optional
=> 1 },
93 accountattr
=> { optional
=> 1 },
94 mailattr
=> { optional
=> 1 },
107 my ($class, $type, $key, $value) = @_;
109 $value = decode_base64
($value) if $key eq 'bindpw';
115 my ($class, $type, $key, $value) = @_;
117 $value = encode_base64
($value, '') if $key eq 'bindpw';
122 sub parse_section_header
{
123 my ($class, $line) = @_;
125 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
126 my ($type, $sectionId) = ($1, $2);
127 my $errmsg = undef; # set if you want to skip whole section
128 eval { PVE
::JSONSchema
::pve_verify_configid
($sectionId); };
130 my $config = {}; # to return additional attributes
131 return ($type, $sectionId, $errmsg, $config);
136 my $lockfile = "/var/lock/pmgldapconfig.lck";
139 my ($code, $errmsg) = @_;
141 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
143 $errmsg ?
die "$errmsg: $err" : die $err;
148 __PACKAGE__-
>register();
151 sub read_pmg_ldap_conf
{
152 my ($filename, $fh) = @_;
154 local $/ = undef; # slurp mode
158 return __PACKAGE__-
>parse_config($filename, $raw);
161 sub write_pmg_ldap_conf
{
162 my ($filename, $fh, $cfg) = @_;
164 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
168 PVE
::Tools
::safe_print
($filename, $fh, $raw);
171 PVE
::INotify
::register_file
('pmg-ldap.conf', "/etc/pmg/ldap.conf",
172 \
&read_pmg_ldap_conf
,
173 \
&write_pmg_ldap_conf
);