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
Nadezhda Ivanova
OpenLDAP
Commits
292b4d8a
Commit
292b4d8a
authored
Sep 06, 2002
by
Howard Chu
Browse files
Fix previous commit, committed getvalues.c twice (??)
parent
f03ff692
Changes
1
Hide whitespace changes
Inline
Side-by-side
libraries/libldap/getattr.c
View file @
292b4d8a
...
...
@@ -7,171 +7,151 @@
* Copyright (c) 1990 Regents of the University of Michigan.
* All rights reserved.
*
* get
values
.c
* get
attr
.c
*/
#include
"portable.h"
#include
<stdio.h>
#include
<ac/stdlib.h>
#include
<ac/ctype.h>
#include
<ac/socket.h>
#include
<ac/string.h>
#include
<ac/time.h>
#include
"ldap-int.h"
char
*
*
ldap_
get_values
(
LDAP
*
ld
,
LDAPMessage
*
entry
,
LDAP_CONST
char
*
targe
t
)
char
*
ldap_
first_attribute
(
LDAP
*
ld
,
LDAPMessage
*
entry
,
BerElement
**
berou
t
)
{
BerElement
ber
;
char
*
attr
;
int
found
=
0
;
char
**
vals
;
assert
(
ld
!=
NULL
);
assert
(
LDAP_VALID
(
ld
)
);
assert
(
entry
!=
NULL
);
assert
(
target
!=
NULL
);
int
rc
;
ber_tag_t
tag
;
ber_len_t
len
=
0
;
char
*
attr
;
BerElement
*
ber
;
#ifdef NEW_LOGGING
LDAP_LOG
(
OPERATION
,
ENTRY
,
"ldap_
get_values
\n
"
,
0
,
0
,
0
);
LDAP_LOG
(
OPERATION
,
ENTRY
,
"ldap_
first_attribute
\n
"
,
0
,
0
,
0
);
#else
Debug
(
LDAP_DEBUG_TRACE
,
"ldap_
get_values
\n
"
,
0
,
0
,
0
);
Debug
(
LDAP_DEBUG_TRACE
,
"ldap_
first_attribute
\n
"
,
0
,
0
,
0
);
#endif
ber
=
*
entry
->
lm_ber
;
/* skip sequence, dn, sequence of, and snag the first attr */
if
(
ber_scanf
(
&
ber
,
"{x{{a"
/*}}}*/
,
&
attr
)
==
LBER_ERROR
)
{
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
return
(
NULL
);
}
assert
(
ld
!=
NULL
);
assert
(
LDAP_VALID
(
ld
)
);
assert
(
entry
!=
NULL
);
assert
(
berout
!=
NULL
);
if
(
strcasecmp
(
target
,
attr
)
==
0
)
found
=
1
;
*
berout
=
NULL
;
/* break out on success, return out on error */
while
(
!
found
)
{
LDAP_FREE
(
attr
)
;
attr
=
NULL
;
ber
=
ldap_alloc_ber_with_options
(
ld
);
if
(
ber
==
NULL
)
{
return
NULL
;
}
if
(
ber_scanf
(
&
ber
,
/*{*/
"x}{a"
/*}*/
,
&
attr
)
==
LBER_ERROR
)
{
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
return
(
NULL
);
}
*
ber
=
*
entry
->
lm_ber
;
if
(
strcasecmp
(
target
,
attr
)
==
0
)
break
;
/*
* Skip past the sequence, dn, sequence of sequence leaving
* us at the first attribute.
*/
tag
=
ber_scanf
(
ber
,
"{xl{"
/*}}*/
,
&
len
);
if
(
tag
==
LBER_ERROR
)
{
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
ber_free
(
ber
,
0
);
return
NULL
;
}
LDAP_FREE
(
attr
);
attr
=
NULL
;
/* set the length to avoid overrun */
rc
=
ber_set_option
(
ber
,
LBER_OPT_REMAINING_BYTES
,
&
len
);
if
(
rc
!=
LBER_OPT_SUCCESS
)
{
ld
->
ld_errno
=
LDAP_LOCAL_ERROR
;
ber_free
(
ber
,
0
);
return
NULL
;
}
/*
* if we get this far, we've found the attribute and are sitting
* just before the set of values.
*/
if
(
ber_pvt_ber_remaining
(
ber
)
==
0
)
{
assert
(
len
==
0
);
ber_free
(
ber
,
0
);
return
NULL
;
}
assert
(
len
!=
0
);
if
(
ber_scanf
(
&
ber
,
"[v]"
,
&
vals
)
==
LBER_ERROR
)
{
/* snatch the first attribute */
tag
=
ber_scanf
(
ber
,
"{ax}"
,
&
attr
);
if
(
tag
==
LBER_ERROR
)
{
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
return
(
NULL
);
ber_free
(
ber
,
0
);
return
NULL
;
}
return
(
vals
);
*
berout
=
ber
;
return
attr
;
}
struct
berval
**
ldap_get_values_len
(
LDAP
*
ld
,
LDAPMessage
*
entry
,
LDAP_CONST
char
*
target
)
/* ARGSUSED */
char
*
ldap_next_attribute
(
LDAP
*
ld
,
LDAPMessage
*
entry
,
BerElement
*
ber
)
{
BerElement
ber
;
char
*
attr
;
int
found
=
0
;
struct
berval
**
vals
;
assert
(
ld
!=
NULL
);
assert
(
LDAP_VALID
(
ld
)
);
assert
(
entry
!=
NULL
);
assert
(
target
!=
NULL
);
ber_tag_t
tag
;
char
*
attr
;
#ifdef NEW_LOGGING
LDAP_LOG
(
OPERATION
,
ENTRY
,
"ldap_
get_values_len
\n
"
,
0
,
0
,
0
);
LDAP_LOG
(
OPERATION
,
ENTRY
,
"ldap_
next_attribute
\n
"
,
0
,
0
,
0
);
#else
Debug
(
LDAP_DEBUG_TRACE
,
"ldap_
get_values_len
\n
"
,
0
,
0
,
0
);
Debug
(
LDAP_DEBUG_TRACE
,
"ldap_
next_attribute
\n
"
,
0
,
0
,
0
);
#endif
ber
=
*
entry
->
lm_ber
;
/* skip sequence, dn, sequence of, and snag the first attr */
if
(
ber_scanf
(
&
ber
,
"{x{{a"
/* }}} */
,
&
attr
)
==
LBER_ERROR
)
{
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
return
(
NULL
);
}
if
(
strcasecmp
(
target
,
attr
)
==
0
)
found
=
1
;
/* break out on success, return out on error */
while
(
!
found
)
{
LDAP_FREE
(
attr
);
attr
=
NULL
;
if
(
ber_scanf
(
&
ber
,
/*{*/
"x}{a"
/*}*/
,
&
attr
)
==
LBER_ERROR
)
{
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
return
(
NULL
);
}
assert
(
ld
!=
NULL
);
assert
(
LDAP_VALID
(
ld
)
);
assert
(
entry
!=
NULL
);
assert
(
ber
!=
NULL
);
if
(
strcasecmp
(
target
,
att
r
)
==
0
)
break
;
if
(
ber_pvt_ber_remaining
(
be
r
)
==
0
)
{
return
NULL
;
}
LDAP_FREE
(
attr
);
attr
=
NULL
;
/*
* if we get this far, we've found the attribute and are sitting
* just before the set of values.
*/
if
(
ber_scanf
(
&
ber
,
"[V]"
,
&
vals
)
==
LBER_ERROR
)
{
/* skip sequence, snarf attribute type, skip values */
tag
=
ber_scanf
(
ber
,
"{ax}"
,
&
attr
);
if
(
tag
==
LBER_ERROR
)
{
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
return
(
NULL
)
;
return
NULL
;
}
return
(
vals
)
;
return
attr
;
}
/* Fetch attribute type and optionally fetch values */
/* ARGSUSED */
int
ldap_count_values
(
char
**
vals
)
ldap_get_attribute_ber
(
LDAP
*
ld
,
LDAPMessage
*
entry
,
BerElement
*
ber
,
BerValue
*
attr
,
BerVarray
*
vals
)
{
int
i
;
ber_tag_t
tag
;
int
rc
=
LDAP_SUCCESS
;
if
(
vals
==
NULL
)
return
(
0
);
for
(
i
=
0
;
vals
[
i
]
!=
NULL
;
i
++
)
;
/* NULL */
#
if
def NEW_LOGGING
LDAP_LOG
(
OPERATION
,
ENTRY
,
"ldap_get_attribute_ber
\n
"
,
0
,
0
,
0
);
#else
Debug
(
LDAP_DEBUG_TRACE
,
"ldap_get_attribute_ber
\n
"
,
0
,
0
,
0
)
;
#endif
return
(
i
);
}
assert
(
ld
!=
NULL
);
assert
(
LDAP_VALID
(
ld
)
);
assert
(
entry
!=
NULL
);
assert
(
ber
!=
NULL
);
assert
(
attr
!=
NULL
);
int
ldap_count_values_len
(
struct
berval
**
vals
)
{
return
(
ldap_count_values
(
(
char
**
)
vals
)
);
}
attr
->
bv_val
=
NULL
;
attr
->
bv_len
=
0
;
void
ldap_value_free
(
char
**
vals
)
{
LDAP_VFREE
(
vals
);
}
if
(
ber_pvt_ber_remaining
(
ber
)
)
{
/* skip sequence, snarf attribute type */
tag
=
ber_scanf
(
ber
,
vals
?
"{mW}"
:
"{mx}"
,
attr
,
vals
);
if
(
tag
==
LBER_ERROR
)
{
rc
=
ld
->
ld_errno
=
LDAP_DECODING_ERROR
;
}
}
void
ldap_value_free_len
(
struct
berval
**
vals
)
{
ber_bvecfree
(
vals
);
return
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