]> git.sur5r.net Git - openldap/blob - libraries/libldap/getvalues.c
Set ciphers from slapd.conf.
[openldap] / libraries / libldap / getvalues.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 /*  Portions
6  *  Copyright (c) 1990 Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  getvalues.c
10  */
11
12 #include "portable.h"
13
14 #include <stdio.h>
15
16 #include <ac/stdlib.h>
17
18 #include <ac/ctype.h>
19 #include <ac/socket.h>
20 #include <ac/string.h>
21 #include <ac/time.h>
22
23 #include "ldap-int.h"
24
25 char **
26 ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
27 {
28         BerElement      ber;
29         char            *attr;
30         int             found = 0;
31         char            **vals;
32
33         assert( ld != NULL );
34         assert( LDAP_VALID( ld ) );
35         assert( entry != NULL );
36         assert( target != NULL );
37
38         Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 );
39
40         ber = *entry->lm_ber;
41
42         /* skip sequence, dn, sequence of, and snag the first attr */
43         if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) {
44                 ld->ld_errno = LDAP_DECODING_ERROR;
45                 return( NULL );
46         }
47
48         if ( strcasecmp( target, attr ) == 0 )
49                 found = 1;
50
51         /* break out on success, return out on error */
52         while ( ! found ) {
53                 LDAP_FREE(attr);
54                 attr = NULL;
55
56                 if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
57                         ld->ld_errno = LDAP_DECODING_ERROR;
58                         return( NULL );
59                 }
60
61                 if ( strcasecmp( target, attr ) == 0 )
62                         break;
63
64         }
65
66         LDAP_FREE(attr);
67         attr = NULL;
68
69         /* 
70          * if we get this far, we've found the attribute and are sitting
71          * just before the set of values.
72          */
73
74         if ( ber_scanf( &ber, "[v]", &vals ) == LBER_ERROR ) {
75                 ld->ld_errno = LDAP_DECODING_ERROR;
76                 return( NULL );
77         }
78
79         return( vals );
80 }
81
82 struct berval **
83 ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target )
84 {
85         BerElement      ber;
86         char            *attr;
87         int             found = 0;
88         struct berval   **vals;
89
90         assert( ld != NULL );
91         assert( LDAP_VALID( ld ) );
92         assert( entry != NULL );
93         assert( target != NULL );
94
95         Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 );
96
97         ber = *entry->lm_ber;
98
99         /* skip sequence, dn, sequence of, and snag the first attr */
100         if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) {
101                 ld->ld_errno = LDAP_DECODING_ERROR;
102                 return( NULL );
103         }
104
105         if ( strcasecmp( target, attr ) == 0 )
106                 found = 1;
107
108         /* break out on success, return out on error */
109         while ( ! found ) {
110                 LDAP_FREE( attr );
111                 attr = NULL;
112
113                 if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) {
114                         ld->ld_errno = LDAP_DECODING_ERROR;
115                         return( NULL );
116                 }
117
118                 if ( strcasecmp( target, attr ) == 0 )
119                         break;
120         }
121
122         LDAP_FREE( attr );
123         attr = NULL;
124
125         /* 
126          * if we get this far, we've found the attribute and are sitting
127          * just before the set of values.
128          */
129
130         if ( ber_scanf( &ber, "[V]", &vals ) == LBER_ERROR ) {
131                 ld->ld_errno = LDAP_DECODING_ERROR;
132                 return( NULL );
133         }
134
135         return( vals );
136 }
137
138 int
139 ldap_count_values( char **vals )
140 {
141         int     i;
142
143         if ( vals == NULL )
144                 return( 0 );
145
146         for ( i = 0; vals[i] != NULL; i++ )
147                 ;       /* NULL */
148
149         return( i );
150 }
151
152 int
153 ldap_count_values_len( struct berval **vals )
154 {
155         return( ldap_count_values( (char **) vals ) );
156 }
157
158 void
159 ldap_value_free( char **vals )
160 {
161         LDAP_VFREE( vals );
162 }
163
164 void
165 ldap_value_free_len( struct berval **vals )
166 {
167         ber_bvecfree( vals );
168 }