]> git.sur5r.net Git - openldap/blob - libraries/libldap/groupings.c
Happy new year!
[openldap] / libraries / libldap / groupings.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2004-2006 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in the file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This program was orignally developed by Kurt D. Zeilenga for inclusion in
17  * OpenLDAP Software.
18  */
19
20 #include "portable.h"
21
22 #include <ac/stdlib.h>
23
24 #include <ac/time.h>
25 #include <ac/string.h>
26
27 #include "ldap-int.h"
28
29 #ifdef LDAP_EXOP_GROUPING_CREATE
30
31 int ldap_grouping_create(
32         LDAP *ld,
33         LDAP_CONST char *grpoid,
34         struct berval *grpdata,
35         LDAPControl **sctrls,
36         LDAPControl **cctrls,
37         int *msgidp )
38 {
39         int rc;
40         BerElement *ber = NULL;
41         struct berval bv = BER_BVNULL;
42
43         Debug( LDAP_DEBUG_TRACE, "ldap_grouping_create\n", 0, 0, 0 );
44
45         assert( ld != NULL );
46         assert( LDAP_VALID( ld ) );
47         assert( grpoid != NULL || *grpoid == '\0' );
48         assert( msgidp != NULL );
49
50         /* build the create grouping exop */
51         ber = ber_alloc_t( LBER_USE_DER );
52         if( ber == NULL ) {
53                 ld->ld_errno = LDAP_NO_MEMORY;
54                 return( ld->ld_errno );
55         }
56
57         if ( grpdata != NULL ) {
58                 ber_printf( ber, "{sON}", grpoid, grpdata );
59         } else {
60                 ber_printf( ber, "{sN}", grpoid );
61         }
62
63         rc = ber_flatten2( ber, &bv, 0 );
64         if( rc < 0 ) {
65                 ld->ld_errno = LDAP_ENCODING_ERROR;
66                 return( ld->ld_errno );
67         }
68
69         rc = ldap_extended_operation( ld, LDAP_EXOP_GROUPING_CREATE,
70                 &bv, sctrls, cctrls, msgidp );
71
72         ber_free( ber, 1 );
73         return rc;
74 }
75
76 int ldap_grouping_create_s(
77         LDAP *ld,
78         LDAP_CONST char *grpoid,
79         struct berval *grpdata,
80         LDAPControl **sctrls,
81         LDAPControl **cctrls,
82         struct berval **retgrpcookiep,
83         struct berval **retgrpdatap )
84 {
85         int     rc;
86         int     msgid;
87         LDAPMessage *res;
88
89         Debug( LDAP_DEBUG_TRACE, "ldap_grouping_create_s\n", 0, 0, 0 );
90
91         assert( ld != NULL );
92         assert( LDAP_VALID( ld ) );
93         assert( grpoid != NULL || *grpoid == '\0' );
94
95         rc = ldap_grouping_create( ld, grpoid, grpdata,
96                 sctrls, cctrls, &msgid );
97         if ( rc != LDAP_SUCCESS ) {
98                 return rc;
99         }
100  
101         if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) == -1 ) {
102                 return ld->ld_errno;
103         }
104
105         if ( retgrpcookiep != NULL ) *retgrpcookiep = NULL;
106         if ( retgrpdatap != NULL ) *retgrpdatap = NULL;
107
108 #if 0
109         rc = ldap_parse_extended_result( ld, res, retoidp, retdatap, 0 );
110 #else
111         rc = LDAP_NOT_SUPPORTED;
112 #endif
113
114         if( rc != LDAP_SUCCESS ) {
115                 ldap_msgfree( res );
116                 return rc;
117         }
118
119         return( ldap_result2error( ld, res, 1 ) );
120 }
121
122 int ldap_grouping_end(
123         LDAP *ld,
124         LDAP_CONST char *grpoid,
125         struct berval *grpdata,
126         LDAPControl **sctrls,
127         LDAPControl **cctrls,
128         int *msgidp )
129 {
130         return 0;
131 }
132
133 int ldap_grouping_end_s(
134         LDAP *ld,
135         LDAP_CONST char *grpoid,
136         struct berval *grpdata,
137         LDAPControl **sctrls,
138         LDAPControl **cctrls,
139         struct berval **retgrpdatap )
140 {
141         return 0;
142 }
143
144 #endif