]>
git.proxmox.com Git - pmg-api.git/blob - src/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 my $inotify_file_id = 'pmg-ldap.conf';
16 my $config_filename = '/etc/pmg/ldap.conf';
20 type
=> { description
=> "Section type." },
22 description
=> "Profile ID.",
23 type
=> 'string', format
=> 'pve-configid',
32 description
=> "Flag to disable/deactivate the entry.",
37 description
=> "Description.",
43 description
=> "LDAP protocol mode ('ldap', 'ldaps' or 'ldap+starttls').",
45 enum
=> ['ldap', 'ldaps', 'ldap+starttls'],
49 description
=> "Verify server certificate. Only useful with ldaps or ldap+starttls.",
55 description
=> "Path to CA file. Only useful with option 'verify'",
60 description
=> "Server address.",
61 type
=> 'string', format
=> 'address',
65 description
=> "Fallback server address. Userd when the first server is not available.",
66 type
=> 'string', format
=> 'address',
70 description
=> "Specify the port to connect to.",
76 description
=> "Bind domain name.",
80 description
=> "Bind password.",
84 description
=> "Base domain name.",
88 description
=> "Base domain name for groups.",
92 description
=> "LDAP filter.",
96 description
=> "Account attribute name name.",
97 type
=> 'string', format
=> 'ldap-simple-attr-list',
98 default => 'sAMAccountName, uid',
101 description
=> "List of mail attribute names.",
102 type
=> 'string', format
=> 'ldap-simple-attr-list',
103 default => "mail, userPrincipalName, proxyAddresses, othermailbox, mailAlternativeAddress",
106 description
=> "List of objectclasses for groups.",
107 type
=> 'string', format
=> 'ldap-simple-attr-list',
108 default => "group, univentionGroup, ipausergroup",
115 disable
=> { optional
=> 1 },
116 comment
=> { optional
=> 1 },
117 server1
=> { optional
=> 0 },
118 server2
=> { optional
=> 1 },
119 port
=> { optional
=> 1 },
120 mode
=> { optional
=> 1 },
121 binddn
=> { optional
=> 1 },
122 bindpw
=> { optional
=> 1 },
123 basedn
=> { optional
=> 1 },
124 groupbasedn
=> { optional
=> 1 },
125 filter
=> { optional
=> 1 },
126 accountattr
=> { optional
=> 1 },
127 mailattr
=> { optional
=> 1 },
128 groupclass
=> { optional
=> 1 },
129 verify
=> { optional
=> 1 },
130 cafile
=> { 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);