Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
orbea -
OpenLDAP
Commits
f5bef58c
Commit
f5bef58c
authored
Oct 31, 2018
by
Ondřej Kuzník
Browse files
Use LDIF API in slapd-addel
parent
04a52cef
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/progs/slapd-addel.c
View file @
f5bef58c
...
...
@@ -32,15 +32,16 @@
#include "ldap.h"
#include "lutil.h"
#include "ldif.h"
#include "slapd-common.h"
static
char
*
get_add_entry
(
char
*
filename
,
LDAPMod
***
mods
);
static
LDIFRecord
*
get_add_entry
(
char
*
filename
);
static
void
do_addel
(
struct
tester_conn_args
*
config
,
char
*
dn
,
LDAPMod
**
attrs
,
int
friendly
);
LDIFRecord
*
record
,
int
friendly
);
static
void
usage
(
char
*
name
,
char
opt
)
...
...
@@ -61,11 +62,13 @@ int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
char
*
filename
=
NULL
;
char
*
entry
=
NULL
;
char
*
filename
=
NULL
,
*
buf
=
NULL
;
int
friendly
=
0
;
LDAPMod
**
attrs
=
NULL
;
struct
LDIFFP
*
fp
;
LDIFRecord
record
=
{};
struct
tester_conn_args
*
config
;
struct
berval
bv
=
{};
unsigned
long
lineno
=
0
;
config
=
tester_init
(
"slapd-addel"
,
TESTER_ADDEL
);
...
...
@@ -96,18 +99,29 @@ main( int argc, char **argv )
if
(
filename
==
NULL
)
usage
(
argv
[
0
],
0
);
entry
=
get_add_entry
(
filename
,
&
attrs
);
if
((
entry
==
NULL
)
||
(
*
entry
==
'\0'
))
{
if
(
(
fp
=
ldif_open
(
filename
,
"r"
))
==
NULL
)
{
tester_perror
(
filename
,
"while reading ldif file"
);
exit
(
EXIT_FAILURE
);
}
fprintf
(
stderr
,
"%s: invalid entry DN in file
\"
%s
\"
.
\n
"
,
argv
[
0
],
filename
);
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
;
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
((
attrs
==
NULL
)
||
(
*
attrs
==
'\0'
)
)
{
if
(
(
record
.
lr_op
!=
LDAP_REQ_ADD
)
||
(
!
record
.
lrop_mods
)
)
{
fprintf
(
stderr
,
"%s: invalid
attrs
in file
\"
%s
\"
.
\n
"
,
fprintf
(
stderr
,
"%s: invalid
entry DN
in file
\"
%s
\"
.
\n
"
,
argv
[
0
],
filename
);
exit
(
EXIT_FAILURE
);
...
...
@@ -116,9 +130,10 @@ main( int argc, char **argv )
tester_config_finish
(
config
);
for
(
i
=
0
;
i
<
config
->
outerloops
;
i
++
)
{
do_addel
(
config
,
entry
,
attrs
,
friendly
);
do_addel
(
config
,
&
record
,
friendly
);
}
free
(
buf
);
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
do_addel
(
struct
tester_conn_args
*
config
,
char
*
entry
,
LDAPMod
**
attrs
,
LDIFRecord
*
record
,
int
friendly
)
{
LDAP
*
ld
=
NULL
;
...
...
@@ -258,13 +227,13 @@ retry:;
if
(
do_retry
==
config
->
retries
)
{
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
++
)
{
/* add the entry */
rc
=
ldap_add_ext_s
(
ld
,
entry
,
attr
s
,
NULL
,
NULL
);
rc
=
ldap_add_ext_s
(
ld
,
record
->
lr_dn
.
bv_val
,
record
->
lrop_mod
s
,
NULL
,
NULL
);
if
(
rc
!=
LDAP_SUCCESS
)
{
tester_ldap_error
(
ld
,
"ldap_add_ext_s"
,
NULL
);
switch
(
rc
)
{
...
...
@@ -297,7 +266,7 @@ retry:;
#endif
/* 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
)
{
tester_ldap_error
(
ld
,
"ldap_delete_ext_s"
,
NULL
);
switch
(
rc
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment