mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-20 22:59:34 -05:00
Use LDIF API in slapd-addel
This commit is contained in:
parent
04a52cef40
commit
f5bef58cae
1 changed files with 34 additions and 65 deletions
|
|
@ -32,15 +32,16 @@
|
||||||
|
|
||||||
#include "ldap.h"
|
#include "ldap.h"
|
||||||
#include "lutil.h"
|
#include "lutil.h"
|
||||||
|
#include "ldif.h"
|
||||||
|
|
||||||
#include "slapd-common.h"
|
#include "slapd-common.h"
|
||||||
|
|
||||||
static char *
|
static LDIFRecord *
|
||||||
get_add_entry( char *filename, LDAPMod ***mods );
|
get_add_entry( char *filename );
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_addel( struct tester_conn_args *config,
|
do_addel( struct tester_conn_args *config,
|
||||||
char *dn, LDAPMod **attrs, int friendly );
|
LDIFRecord *record, int friendly );
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage( char *name, char opt )
|
usage( char *name, char opt )
|
||||||
|
|
@ -61,11 +62,13 @@ int
|
||||||
main( int argc, char **argv )
|
main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *filename = NULL;
|
char *filename = NULL, *buf = NULL;
|
||||||
char *entry = NULL;
|
|
||||||
int friendly = 0;
|
int friendly = 0;
|
||||||
LDAPMod **attrs = NULL;
|
struct LDIFFP *fp;
|
||||||
|
LDIFRecord record = {};
|
||||||
struct tester_conn_args *config;
|
struct tester_conn_args *config;
|
||||||
|
struct berval bv = {};
|
||||||
|
unsigned long lineno = 0;
|
||||||
|
|
||||||
config = tester_init( "slapd-addel", TESTER_ADDEL );
|
config = tester_init( "slapd-addel", TESTER_ADDEL );
|
||||||
|
|
||||||
|
|
@ -96,18 +99,29 @@ main( int argc, char **argv )
|
||||||
if ( filename == NULL )
|
if ( filename == NULL )
|
||||||
usage( argv[0], 0 );
|
usage( argv[0], 0 );
|
||||||
|
|
||||||
entry = get_add_entry( filename, &attrs );
|
if ( (fp = ldif_open( filename, "r" )) == NULL ) {
|
||||||
if (( entry == NULL ) || ( *entry == '\0' )) {
|
tester_perror( filename, "while reading ldif file" );
|
||||||
|
|
||||||
fprintf( stderr, "%s: invalid entry DN in file \"%s\".\n",
|
|
||||||
argv[0], filename );
|
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (( attrs == NULL ) || ( *attrs == '\0' )) {
|
i = 0;
|
||||||
|
if ( ldif_read_record( fp, &lineno, &buf, &i ) < 0 ) {
|
||||||
|
tester_error( "ldif_read_record failed" );
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
bv.bv_val = buf;
|
||||||
|
bv.bv_len = i;
|
||||||
|
|
||||||
fprintf( stderr, "%s: invalid attrs in file \"%s\".\n",
|
if ( ldap_parse_ldif_record( &bv, lineno, &record, "slapd-addel",
|
||||||
|
LDIF_DEFAULT_ADD | LDIF_ENTRIES_ONLY ) ) {
|
||||||
|
tester_error( "ldif_read_record failed" );
|
||||||
|
exit( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
ldif_close( fp );
|
||||||
|
|
||||||
|
if ( ( record.lr_op != LDAP_REQ_ADD ) || ( !record.lrop_mods ) ) {
|
||||||
|
|
||||||
|
fprintf( stderr, "%s: invalid entry DN in file \"%s\".\n",
|
||||||
argv[0], filename );
|
argv[0], filename );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
|
|
||||||
|
|
@ -116,9 +130,10 @@ main( int argc, char **argv )
|
||||||
tester_config_finish( config );
|
tester_config_finish( config );
|
||||||
|
|
||||||
for ( i = 0; i < config->outerloops; i++ ) {
|
for ( i = 0; i < config->outerloops; i++ ) {
|
||||||
do_addel( config, entry, attrs, friendly );
|
do_addel( config, &record, friendly );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free( buf );
|
||||||
exit( EXIT_SUCCESS );
|
exit( EXIT_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,56 +210,10 @@ addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
get_add_entry( char *filename, LDAPMod ***mods )
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
char *entry = NULL;
|
|
||||||
|
|
||||||
if ( (fp = fopen( filename, "r" )) != NULL ) {
|
|
||||||
char line[BUFSIZ];
|
|
||||||
|
|
||||||
if ( fgets( line, BUFSIZ, fp )) {
|
|
||||||
char *nl;
|
|
||||||
|
|
||||||
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
||||||
*nl = '\0';
|
|
||||||
nl = line;
|
|
||||||
if ( !strncasecmp( nl, "dn: ", 4 ))
|
|
||||||
nl += 4;
|
|
||||||
entry = strdup( nl );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
while ( fgets( line, BUFSIZ, fp )) {
|
|
||||||
char *nl;
|
|
||||||
char *value;
|
|
||||||
|
|
||||||
if (( nl = strchr( line, '\r' )) || ( nl = strchr( line, '\n' )))
|
|
||||||
*nl = '\0';
|
|
||||||
|
|
||||||
if ( *line == '\0' ) break;
|
|
||||||
if ( !( value = strchr( line, ':' ))) break;
|
|
||||||
|
|
||||||
*value++ = '\0';
|
|
||||||
while ( *value && isspace( (unsigned char) *value ))
|
|
||||||
value++;
|
|
||||||
|
|
||||||
addmodifyop( mods, LDAP_MOD_ADD, line, value, strlen( value ));
|
|
||||||
|
|
||||||
}
|
|
||||||
fclose( fp );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( entry );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_addel(
|
do_addel(
|
||||||
struct tester_conn_args *config,
|
struct tester_conn_args *config,
|
||||||
char *entry,
|
LDIFRecord *record,
|
||||||
LDAPMod **attrs,
|
|
||||||
int friendly )
|
int friendly )
|
||||||
{
|
{
|
||||||
LDAP *ld = NULL;
|
LDAP *ld = NULL;
|
||||||
|
|
@ -258,13 +227,13 @@ retry:;
|
||||||
|
|
||||||
if ( do_retry == config->retries ) {
|
if ( do_retry == config->retries ) {
|
||||||
fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n",
|
fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n",
|
||||||
(long) pid, config->loops, entry );
|
(long) pid, config->loops, record->lr_dn.bv_val );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ; i < config->loops; i++ ) {
|
for ( ; i < config->loops; i++ ) {
|
||||||
|
|
||||||
/* add the entry */
|
/* add the entry */
|
||||||
rc = ldap_add_ext_s( ld, entry, attrs, NULL, NULL );
|
rc = ldap_add_ext_s( ld, record->lr_dn.bv_val, record->lrop_mods, NULL, NULL );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
tester_ldap_error( ld, "ldap_add_ext_s", NULL );
|
tester_ldap_error( ld, "ldap_add_ext_s", NULL );
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
|
|
@ -297,7 +266,7 @@ retry:;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* now delete the entry again */
|
/* now delete the entry again */
|
||||||
rc = ldap_delete_ext_s( ld, entry, NULL, NULL );
|
rc = ldap_delete_ext_s( ld, record->lr_dn.bv_val, NULL, NULL );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
tester_ldap_error( ld, "ldap_delete_ext_s", NULL );
|
tester_ldap_error( ld, "ldap_delete_ext_s", NULL );
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue