I wrote some simple perl script that creates an Net::LDAP::LDIF
object on an input file and then reads the contents using $ldif->read_entry()
.
After some processing I'm writing the entries again to STDOUT
using $ldif->write_entry($entry)
.
The code works fine for "normal" LDIF files, but when processing an LDIF file that contains include
, it fails like this:
First line of LDIF entry does not begin with "dn:" at
...
Is there a way "pass though" such include
lines?
An example of such input would be:
dn: cn=schema,cn=config
objectClass: olcSchemaConfig
cn: schema
include: file:///etc/openldap/schema/core.ldif
include: file:///etc/openldap/schema/cosine.ldif
Such include files would contain DNs themselves, like this:
dn: cn=core,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: core
#...
The module version I'm using is perl-ldap-0.65-1.3.1.x86_64
(perl 5.26), just in case.
I wrote some simple perl script that creates an Net::LDAP::LDIF
object on an input file and then reads the contents using $ldif->read_entry()
.
After some processing I'm writing the entries again to STDOUT
using $ldif->write_entry($entry)
.
The code works fine for "normal" LDIF files, but when processing an LDIF file that contains include
, it fails like this:
First line of LDIF entry does not begin with "dn:" at
...
Is there a way "pass though" such include
lines?
An example of such input would be:
dn: cn=schema,cn=config
objectClass: olcSchemaConfig
cn: schema
include: file:///etc/openldap/schema/core.ldif
include: file:///etc/openldap/schema/cosine.ldif
Such include files would contain DNs themselves, like this:
dn: cn=core,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: core
#...
The module version I'm using is perl-ldap-0.65-1.3.1.x86_64
(perl 5.26), just in case.
- It doesn't look like that module processes include directives. You will have to do it yourself – Botje Commented Mar 25 at 12:01
- I don't want to process include direktives; I want to pass them on to the output unchanged. – U. Windl Commented Mar 25 at 12:22
- Don't think the module supports that, it needs a dn: line for writing entries. Copy the include: lines yourself and remove them from the input? – Botje Commented Mar 25 at 12:35
1 Answer
Reset to default 0Thinking about the problem I had the idea to "pre-convert" the includes in LDIF first, then process it, and finally "post-convert" the includes to the original syntax.
However my initial idea to make the includes comments failed, because comments are not copied to the output when using read_entry()
and write_entry()
.
Then I played with an ugly idea (having no more sophisticated idea): What happens if I prefix "dn: " to the include statements?
Interestingly that was parsed correctly by read_entry()
and copied to the output by write_entry()
.
So I "encode" the includes to a temporary LDIF file, do the usual processing of that temporary LDIF to another temporary file, and finally I "decode" the encoded includes in the last temporary file to the final output.
The essential code being used is:
while (<$ifh>) {
if ($encode) {
s/^include:\s/dn: $&/;
} else {
s/^dn: (include:\s)/$1/;
}
print $ofh $_;
}
close($ifh);
The code would not handle wrapped "include" directives correctly, however.
The only thing I noticed when comparing the results was that slapcat
seems to BASE64-encode values that write_entry()
does not, so I had different byte counts.
For example:
-olcRootPW:: e1NTSEF9eVpBSkE4WUhxSHdSbUloTlFJMklQNGVZOWl4Q1JVRlNSdz09
+olcRootPW: {SSHA}yZAJA8YHqHwRmIhNQI2IP4eY9ixCRUFSRw==
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744199982a4562835.html
评论列表(0条)