]>
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
=> "Flag to disable/deactivate the entry.",
33 description
=> "Description.",
39 description
=> "LDAP protocol mode ('ldap' or 'ldaps').",
41 enum
=> ['ldap', 'ldaps'],
45 description
=> "Server address.",
46 type
=> 'string', format
=> 'address',
50 description
=> "Fallback server address. Userd when the first server is not available.",
51 type
=> 'string', format
=> 'address',
55 description
=> "Specify the port to connect to.",
61 description
=> "Bind domain name.",
65 description
=> "Bind password.",
69 description
=> "Base domain name.",
73 description
=> "Base domain name for groups.",
77 description
=> "LDAP filter.",
81 description
=> "Account attribute name name.",
83 pattern
=> '[a-zA-Z0-9]+',
84 default => 'sAMAccountName',
87 description
=> "List of mail attribute names.",
88 type
=> 'string', format
=> 'string-list',
89 pattern
=> '[a-zA-Z0-9]+',
90 default => "mail, userPrincipalName, proxyAddresses, othermailbox",
97 comment
=> { optional
=> 1 },
98 server1
=> { optional
=> 0 },
99 server2
=> { optional
=> 1 },
100 port
=> { optional
=> 1 },
101 mode
=> { optional
=> 1 },
102 binddn
=> { optional
=> 1 },
103 bindpw
=> { optional
=> 1 },
104 basedn
=> { optional
=> 1 },
105 groupbasedn
=> { optional
=> 1 },
106 filter
=> { optional
=> 1 },
107 accountattr
=> { optional
=> 1 },
108 mailattr
=> { optional
=> 1 },
120 sub parse_section_header
{
121 my ($class, $line) = @_;
123 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
124 my ($type, $sectionId) = ($1, $2);
125 my $errmsg = undef; # set if you want to skip whole section
126 eval { PVE
::JSONSchema
::pve_verify_configid
($sectionId); };
128 my $config = {}; # to return additional attributes
129 return ($type, $sectionId, $errmsg, $config);
135 my ($class, $filename, $raw) = @_;
137 my $cfg = $class->SUPER::parse_config
($filename, $raw);
139 foreach my $section (keys %{$cfg->{ids
}}) {
140 my $data = $cfg->{ids
}->{$section};
142 $data->{comment
} = PVE
::Tools
::decode_text
($data->{comment
})
143 if defined($data->{comment
});
145 $data->{bindpw
} = decode_base64
($data->{bindpw
})
146 if defined($data->{bindpw
});
153 my ($class, $filename, $cfg) = @_;
155 foreach my $section (keys %{$cfg->{ids
}}) {
156 my $data = $cfg->{ids
}->{$section};
158 $data->{comment
} = PVE
::Tools
::encode_text
($data->{comment
})
159 if defined($data->{comment
});
161 $data->{bindpw
} = encode_base64
($data->{bindpw
}, '')
162 if defined($data->{bindpw
});
165 $class->SUPER::write_config
($filename, $cfg);
168 my $lockfile = "/var/lock/pmgldapconfig.lck";
171 my ($code, $errmsg) = @_;
173 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
175 $errmsg ?
die "$errmsg: $err" : die $err;
180 __PACKAGE__-
>register();
183 sub read_pmg_ldap_conf
{
184 my ($filename, $fh) = @_;
186 local $/ = undef; # slurp mode
190 return __PACKAGE__-
>parse_config($filename, $raw);
193 sub write_pmg_ldap_conf
{
194 my ($filename, $fh, $cfg) = @_;
196 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
200 PVE
::Tools
::safe_print
($filename, $fh, $raw);
203 PVE
::INotify
::register_file
('pmg-ldap.conf', "/etc/pmg/ldap.conf",
204 \
&read_pmg_ldap_conf
,
205 \
&write_pmg_ldap_conf
);