]>
git.proxmox.com Git - pmg-api.git/blob - PMG/LDAPConfig.pm
3e92fc4c9a0134f32809ab5da21e552db68a41ae
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',
31 description
=> "Flag to disable/deactivate the entry.",
36 description
=> "Description.",
42 description
=> "LDAP protocol mode ('ldap' or 'ldaps').",
44 enum
=> ['ldap', 'ldaps'],
48 description
=> "Server address.",
49 type
=> 'string', format
=> 'address',
53 description
=> "Fallback server address. Userd when the first server is not available.",
54 type
=> 'string', format
=> 'address',
58 description
=> "Specify the port to connect to.",
64 description
=> "Bind domain name.",
68 description
=> "Bind password.",
72 description
=> "Base domain name.",
76 description
=> "Base domain name for groups.",
80 description
=> "LDAP filter.",
84 description
=> "Account attribute name name.",
86 pattern
=> '[a-zA-Z0-9]+',
87 default => 'sAMAccountName',
90 description
=> "List of mail attribute names.",
91 type
=> 'string', format
=> 'string-list',
92 pattern
=> '[a-zA-Z0-9]+',
93 default => "mail, userPrincipalName, proxyAddresses, othermailbox",
100 disable
=> { optional
=> 1 },
101 comment
=> { optional
=> 1 },
102 server1
=> { optional
=> 0 },
103 server2
=> { optional
=> 1 },
104 port
=> { optional
=> 1 },
105 mode
=> { optional
=> 1 },
106 binddn
=> { optional
=> 1 },
107 bindpw
=> { optional
=> 1 },
108 basedn
=> { optional
=> 1 },
109 groupbasedn
=> { optional
=> 1 },
110 filter
=> { optional
=> 1 },
111 accountattr
=> { optional
=> 1 },
112 mailattr
=> { optional
=> 1 },
124 sub parse_section_header
{
125 my ($class, $line) = @_;
127 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
128 my ($type, $profileId) = ($1, $2);
129 my $errmsg = undef; # set if you want to skip whole section
130 eval { PVE
::JSONSchema
::pve_verify_configid
($profileId); };
132 my $config = {}; # to return additional attributes
133 return ($type, $profileId, $errmsg, $config);
139 my ($class, $filename, $raw) = @_;
141 my $cfg = $class->SUPER::parse_config
($filename, $raw);
143 foreach my $profile (keys %{$cfg->{ids
}}) {
144 my $data = $cfg->{ids
}->{$profile};
146 $data->{comment
} = PVE
::Tools
::decode_text
($data->{comment
})
147 if defined($data->{comment
});
149 $data->{bindpw
} = decode_base64
($data->{bindpw
})
150 if defined($data->{bindpw
});
157 my ($class, $filename, $cfg) = @_;
159 foreach my $profile (keys %{$cfg->{ids
}}) {
160 my $data = $cfg->{ids
}->{$profile};
162 $data->{comment
} = PVE
::Tools
::encode_text
($data->{comment
})
163 if defined($data->{comment
});
165 $data->{bindpw
} = encode_base64
($data->{bindpw
}, '')
166 if defined($data->{bindpw
});
169 $class->SUPER::write_config
($filename, $cfg);
175 my $class = ref($type) || $type;
177 my $cfg = PVE
::INotify
::read_file
($inotify_file_id);
179 return bless $cfg, $class;
185 PVE
::INotify
::write_file
($inotify_file_id, $self);
188 my $lockfile = "/var/lock/pmgldapconfig.lck";
191 my ($code, $errmsg) = @_;
193 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
195 $errmsg ?
die "$errmsg: $err" : die $err;
200 __PACKAGE__-
>register();
203 sub read_pmg_ldap_conf
{
204 my ($filename, $fh) = @_;
206 local $/ = undef; # slurp mode
208 my $raw = defined($fh) ?
<$fh> : '';
210 return __PACKAGE__-
>parse_config($filename, $raw);
213 sub write_pmg_ldap_conf
{
214 my ($filename, $fh, $cfg) = @_;
216 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
218 my $gid = getgrnam('www-data');
222 PVE
::Tools
::safe_print
($filename, $fh, $raw);
225 PVE
::INotify
::register_file
($inotify_file_id, $config_filename,
226 \
&read_pmg_ldap_conf
,
227 \
&write_pmg_ldap_conf
,
229 always_call_parser
=> 1);