]>
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);
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.",
85 type
=> 'string', format
=> 'string-list',
86 pattern
=> '[a-zA-Z0-9]+',
87 default => 'sAMAccountName, uid',
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",
96 description
=> "List of objectclasses for groups.",
97 type
=> 'string', format
=> 'string-list',
98 default => "group, univentionGroup, ipausergroup",
105 disable
=> { optional
=> 1 },
106 comment
=> { optional
=> 1 },
107 server1
=> { optional
=> 0 },
108 server2
=> { optional
=> 1 },
109 port
=> { optional
=> 1 },
110 mode
=> { optional
=> 1 },
111 binddn
=> { optional
=> 1 },
112 bindpw
=> { optional
=> 1 },
113 basedn
=> { optional
=> 1 },
114 groupbasedn
=> { optional
=> 1 },
115 filter
=> { optional
=> 1 },
116 accountattr
=> { optional
=> 1 },
117 mailattr
=> { optional
=> 1 },
118 groupclass
=> { optional
=> 1 },
130 sub parse_section_header
{
131 my ($class, $line) = @_;
133 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
134 my ($type, $profileId) = ($1, $2);
135 my $errmsg = undef; # set if you want to skip whole section
136 eval { PVE
::JSONSchema
::pve_verify_configid
($profileId); };
138 my $config = {}; # to return additional attributes
139 return ($type, $profileId, $errmsg, $config);
145 my ($class, $filename, $raw) = @_;
147 my $cfg = $class->SUPER::parse_config
($filename, $raw);
149 foreach my $profile (keys %{$cfg->{ids
}}) {
150 my $data = $cfg->{ids
}->{$profile};
152 $data->{comment
} = PVE
::Tools
::decode_text
($data->{comment
})
153 if defined($data->{comment
});
155 $data->{bindpw
} = decode_base64
($data->{bindpw
})
156 if defined($data->{bindpw
});
163 my ($class, $filename, $cfg) = @_;
165 foreach my $profile (keys %{$cfg->{ids
}}) {
166 my $data = $cfg->{ids
}->{$profile};
168 $data->{comment
} = PVE
::Tools
::encode_text
($data->{comment
})
169 if defined($data->{comment
});
171 $data->{bindpw
} = encode_base64
($data->{bindpw
}, '')
172 if defined($data->{bindpw
});
175 $class->SUPER::write_config
($filename, $cfg);
181 my $class = ref($type) || $type;
183 my $cfg = PVE
::INotify
::read_file
($inotify_file_id);
185 return bless $cfg, $class;
191 PVE
::INotify
::write_file
($inotify_file_id, $self);
194 my $lockfile = "/var/lock/pmgldapconfig.lck";
197 my ($code, $errmsg) = @_;
199 my $p = PVE
::Tools
::lock_file
($lockfile, undef, $code);
201 $errmsg ?
die "$errmsg: $err" : die $err;
206 __PACKAGE__-
>register();
209 sub read_pmg_ldap_conf
{
210 my ($filename, $fh) = @_;
212 local $/ = undef; # slurp mode
214 my $raw = defined($fh) ?
<$fh> : '';
216 return __PACKAGE__-
>parse_config($filename, $raw);
219 sub write_pmg_ldap_conf
{
220 my ($filename, $fh, $cfg) = @_;
222 my $raw = __PACKAGE__-
>write_config($filename, $cfg);
224 my $gid = getgrnam('www-data');
228 PVE
::Tools
::safe_print
($filename, $fh, $raw);
231 PVE
::INotify
::register_file
($inotify_file_id, $config_filename,
232 \
&read_pmg_ldap_conf
,
233 \
&write_pmg_ldap_conf
,
235 always_call_parser
=> 1);