]> git.sur5r.net Git - openldap/blob - libraries/libldap/getattr.c
272dbce04ff0641ab65267871d8b02385086a413
[openldap] / libraries / libldap / getattr.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*  Portions
7  *  Copyright (c) 1990 Regents of the University of Michigan.
8  *  All rights reserved.
9  *
10  *  getattr.c
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16 #include <ac/stdlib.h>
17
18 #include <ac/socket.h>
19 #include <ac/string.h>
20 #include <ac/time.h>
21
22 #include "ldap-int.h"
23
24 char *
25 ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **berout )
26 {
27         ber_tag_t rc;
28         ber_len_t len;
29         char *attr;
30         BerElement *ber;
31
32         Debug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
33
34         assert( ld != NULL );
35         assert( LDAP_VALID( ld ) );
36         assert( entry != NULL );
37         assert( berout != NULL );
38
39         ber = ldap_alloc_ber_with_options( ld );
40         if( ber == NULL ) {
41                 return NULL;
42         }
43
44         *ber = *entry->lm_ber;
45
46         /* 
47          * Skip past the sequence, dn, sequence of sequence leaving
48          * us at the first attribute.
49          */
50
51         rc = ber_scanf( ber, "{xl{" /*}}*/, &attr, &len );
52
53         if( rc == LBER_ERROR ) {
54                 ld->ld_errno = LDAP_DECODING_ERROR;
55                 ber_free( ber, 0 );
56                 return  NULL;
57         }
58
59 #if 0
60         if( len == 0 ) {
61                 return NULL;
62         }
63 #endif
64         
65         /* set the length to avoid overrun */
66         rc = ber_set_option( ber, LBER_OPT_REMAINING_BYTES, &len );
67
68         if( rc != LBER_OPT_SUCCESS ) {
69                 ld->ld_errno = LDAP_LOCAL_ERROR;
70                 ber_free( ber, 0 );
71                 return NULL;
72         }
73
74         /* snatch the first attribute */
75         rc = ber_scanf( ber, "{ax}", &attr );
76         if( rc == LBER_ERROR ) {
77                 ld->ld_errno = LDAP_DECODING_ERROR;
78                 ber_free( ber, 0 );
79                 return NULL;
80         }
81
82         *berout = ber;
83         return attr;
84 }
85
86 /* ARGSUSED */
87 char *
88 ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
89 {
90         ber_tag_t rc;
91         char *attr;
92
93         Debug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
94
95         assert( ld != NULL );
96         assert( LDAP_VALID( ld ) );
97         assert( entry != NULL );
98         assert( ber != NULL );
99
100 #if 0
101         if ( ber_pvt_ber_remaining( ber ) == 0 ) {
102                 return NULL;
103         }
104 #endif
105
106         /* skip sequence, snarf attribute type, skip values */
107         rc = ber_scanf( ber, "{ax}", &attr ); 
108         if( rc == LBER_ERROR ) {
109                 ld->ld_errno = LDAP_DECODING_ERROR;
110                 return NULL;
111         }
112
113         return attr;
114 }