]>
git.proxmox.com Git - pmg-api.git/blob - PMG/LDAPConfig.pm
c75c1c14b7e72e62192feaf426a8f5cc29062fd5
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
=> "Profile 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 disable
=> { optional
=> 1 },
98 comment
=> { optional
=> 1 },
99 server1
=> { optional
=> 0 },
100 server2
=> { optional
=> 1 },
101 port
=> { optional
=> 1 },
102 mode
=> { optional
=> 1 },
103 binddn
=> { optional
=> 1 },
104 bindpw
=> { optional
=> 1 },
105 basedn
=> { optional
=> 1 },
106 groupbasedn
=> { optional
=> 1 },
107 filter
=> { optional
=> 1 },
108 accountattr
=> { optional
=> 1 },
109 mailattr
=> { optional
=> 1 },
121 sub parse_section_header
{
122 my ($class, $line) = @_;
124 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
125 my ($type, $profileId) = ($1, $2);
126 my $errmsg = undef; # set if you want to skip whole section
127 eval { PVE
::JSONSchema
::pve_verify_configid
($profileId); };
129 my $config = {}; # to return additional attributes
130 return ($type, $profileId, $errmsg, $config);
136 my ($class, $filename, $raw) = @_;
138 my $cfg = $class->SUPER::parse_config
($filename, $raw);
140 foreach my $profile (keys %{$cfg->{ids
}}) {
141 my $data = $cfg->{ids
}->{$profile};
143 $data->{comment
} = PVE
::Tools
::decode_text
($data->{comment
})
144 if defined($data->{comment
});
146 $data->{bindpw
} = decode_base64
($data->{bindpw
})
147 if defined($data->{bindpw
});
154 my ($class, $filename, $cfg) = @_;
156 foreach my $profile (keys %{$cfg->{ids
}}) {
157 my $data = $cfg->{ids
}->{$profile};
159 $data->{comment
} = PVE
::Tools
::encode_text
($data->{comment
})
160 if defined($data->{comment
});
162 $data->{bindpw
} = encode_base64
($data->{bindpw
}, '')
163 if defined($data->{bindpw
});
166 $class->SUPER::write_config
($filename, $cfg);
169 my $lockfile = "/var/lock/pmgldapconfig.lck";
172 my ($code, $errmsg) = @_;
174 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
176 $errmsg ?
die "$errmsg: $err" : die $err;
181 __PACKAGE__-
>register();
184 sub read_pmg_ldap_conf
{
185 my ($filename, $fh) = @_;
187 local $/ = undef; # slurp mode
191 return __PACKAGE__-
>parse_config($filename, $raw);
194 sub write_pmg_ldap_conf
{
195 my ($filename, $fh, $cfg) = @_;
197 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
201 PVE
::Tools
::safe_print
($filename, $fh, $raw);
204 PVE
::INotify
::register_file
('pmg-ldap.conf', "/etc/pmg/ldap.conf",
205 \
&read_pmg_ldap_conf
,
206 \
&write_pmg_ldap_conf
);