QgldExportLdif - Export LDIF File (LDAP)
Q: I'm looking for an RPG example of using the QgldExportLdif API. This
API creates a .LDIF file of your entire LDAP on the iSeries so it can be
exported to another iSeries LDAP.
A: Okay, here's an example that I wrote up real quick:
H DFTACTGRP(*NO)
D QgldExportLdif PR Extproc('QgldExportLdif')
D InputData 32767A const options(*varsize)
D InputLen 10I 0 value
D Format 8A const
D ErrorCode 32767A options(*varsize)
D LDIF0100 DS
D File_off 10I 0
D File_len 10I 0
D AdminDN_off 10I 0
D AdminDN_len 10I 0
D AdminPW_off 10I 0
D AdminPW_len 10I 0
D Subtree_off 10I 0
D Subtree_len 10I 0
D File 200C CCSID(13488)
D AdminDN 200C CCSID(13488)
D AdminPW 200C CCSID(13488)
D Subtree 200C CCSID(13488)
D ErrorCode ds
D BytesProv 10I 0 inz(0)
D BytesAvail 10I 0 inz(0)
/free
// Set parameters
// FIXME: Change these to appropriate values!!
File = %ucs2('/tmp/dirsrv_output.ldif');
AdminDN = %ucs2('cn=Administrator');
AdminPW = %ucs2('mySecretPassword');
Subtree = *blanks;
// Calculate offsets
File_off = %addr(file) - %addr(LDIF0100);
AdminDN_off = %addr(AdminDN) - %addr(LDIF0100);
AdminPW_off = %addr(AdminPW) - %addr(LDIF0100);
Subtree_off = %addr(Subtree) - %addr(LDIF0100);
// Calculate lengths
File_len = %len(%trimr(file));
AdminDN_len = %len(%trimr(AdminDN));
AdminPW_len = %len(%trimr(AdminPW));
Subtree_len = 0;
// Call API
QgldExportLdif( LDIF0100
: %size(LDIF0100)
: 'LDIF0100'
: ErrorCode );
*inlr = *on;
/end-free
In this example, it dumps the whole directory server (since I set the
subtree length to zero, it won't do a subtree, it'll do everything) to a
file named /tmp/dirsrv_output.ldif in the IFS.
Obviously, you'll have to change the userid, password and maybe the IFS
filename to be something appropriate for your system.
> Also, if anyone has an RPG example of the QgldImportLdif API that will
> load the .LDIF file into the destination iSeries.
I haven't used QgldImportLdif. (I export it for import into an OpenLDAP2
server, not for another iSeries) but I took a quick peek at the docs, and
they appear to be just about identical to those for QgldExportLdif, so you
might be able to use the same program, just change the prototype name (and
the EXTPROC keyword) from Export to Import.
Note that the contents of the ExtProc() keyword are case-sensitive. Make
sure you capitalize it the same way I did.
Note also that the 2nd parameter to QgldExportLdif is passed by VALUE...
this one was tricky at first, since it doesn't say anything about this in
the IBM docs (unless they've changed them since I wrote this?) You have
to look at the C prototype to know this :)
> I realize that the export and import can be done via iSeries Navigator,
> but I want to do the export and import as scheduled jobs that will run
> unattended during the middle of the night. Any help is greatly
> appreciated.
It's probably also possible from QShell using ldapsearch, but I haven't
tried it. This API seems simpler, actually :)
Thanks to Scott Klement
阅读(923) | 评论(0) | 转发(0) |