1*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate /*
4*0Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
5*0Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
6*0Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
7*0Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
10*0Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11*0Sstevel@tonic-gate * implied. See the License for the specific language governing
12*0Sstevel@tonic-gate * rights and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
15*0Sstevel@tonic-gate * March 31, 1998.
16*0Sstevel@tonic-gate *
17*0Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
18*0Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
19*0Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
20*0Sstevel@tonic-gate * Rights Reserved.
21*0Sstevel@tonic-gate *
22*0Sstevel@tonic-gate * Contributor(s):
23*0Sstevel@tonic-gate */
24*0Sstevel@tonic-gate #include "ldap-int.h"
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate /* ldap_create_proxyauth_control
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate Create a "version 1" proxied authorization control.
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate Parameters are
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate ld LDAP pointer to the desired connection
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate dn The dn used in the proxy auth
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate ctl_iscritical Indicates whether the control is critical of not. If
37*0Sstevel@tonic-gate this field is non-zero, the operation will only be car-
38*0Sstevel@tonic-gate ried out if the control is recognized by the server
39*0Sstevel@tonic-gate and/or client
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate ctrlp the address of a place to put the constructed control
42*0Sstevel@tonic-gate */
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate int
45*0Sstevel@tonic-gate LDAP_CALL
ldap_create_proxyauth_control(LDAP * ld,const char * dn,const char ctl_iscritical,LDAPControl ** ctrlp)46*0Sstevel@tonic-gate ldap_create_proxyauth_control (
47*0Sstevel@tonic-gate LDAP *ld,
48*0Sstevel@tonic-gate const char *dn,
49*0Sstevel@tonic-gate const char ctl_iscritical,
50*0Sstevel@tonic-gate LDAPControl **ctrlp
51*0Sstevel@tonic-gate )
52*0Sstevel@tonic-gate {
53*0Sstevel@tonic-gate BerElement *ber;
54*0Sstevel@tonic-gate int rc;
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
57*0Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
58*0Sstevel@tonic-gate }
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate if ( ctrlp == NULL ) {
61*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
62*0Sstevel@tonic-gate return ( LDAP_PARAM_ERROR );
63*0Sstevel@tonic-gate }
64*0Sstevel@tonic-gate if (NULL == dn)
65*0Sstevel@tonic-gate {
66*0Sstevel@tonic-gate dn = "";
67*0Sstevel@tonic-gate }
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate /* create a ber package to hold the controlValue */
70*0Sstevel@tonic-gate if ( ( nsldapi_alloc_ber_with_options( ld, &ber ) ) != LDAP_SUCCESS ) {
71*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
72*0Sstevel@tonic-gate return( LDAP_NO_MEMORY );
73*0Sstevel@tonic-gate }
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate if ( LBER_ERROR == ber_printf( ber,
78*0Sstevel@tonic-gate "{s}",
79*0Sstevel@tonic-gate dn ) )
80*0Sstevel@tonic-gate {
81*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
82*0Sstevel@tonic-gate ber_free( ber, 1 );
83*0Sstevel@tonic-gate return( LDAP_ENCODING_ERROR );
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate rc = nsldapi_build_control( LDAP_CONTROL_PROXYAUTH, ber, 1,
87*0Sstevel@tonic-gate ctl_iscritical, ctrlp );
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
90*0Sstevel@tonic-gate return( rc );
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate }
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate /* ldap_create_proxiedauth_control
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate Create a "version 2" proxied authorization control.
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gate Parameters are
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate ld LDAP pointer to the desired connection
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate authzid The authorization identity used in the proxy auth,
104*0Sstevel@tonic-gate e.g., dn:uid=bjensen,dc=example,dc=com
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate ctrlp the address of a place to put the constructed control
107*0Sstevel@tonic-gate */
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate int
110*0Sstevel@tonic-gate LDAP_CALL
ldap_create_proxiedauth_control(LDAP * ld,const char * authzid,LDAPControl ** ctrlp)111*0Sstevel@tonic-gate ldap_create_proxiedauth_control (
112*0Sstevel@tonic-gate LDAP *ld,
113*0Sstevel@tonic-gate const char *authzid,
114*0Sstevel@tonic-gate LDAPControl **ctrlp
115*0Sstevel@tonic-gate )
116*0Sstevel@tonic-gate {
117*0Sstevel@tonic-gate BerElement *ber;
118*0Sstevel@tonic-gate int rc;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
121*0Sstevel@tonic-gate return( LDAP_PARAM_ERROR );
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate if ( ctrlp == NULL || authzid == NULL ) {
125*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
126*0Sstevel@tonic-gate return ( LDAP_PARAM_ERROR );
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate /* create a ber package to hold the controlValue */
130*0Sstevel@tonic-gate if ( ( nsldapi_alloc_ber_with_options( ld, &ber ) ) != LDAP_SUCCESS ) {
131*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
132*0Sstevel@tonic-gate return( LDAP_NO_MEMORY );
133*0Sstevel@tonic-gate }
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate if ( LBER_ERROR == ber_printf( ber,
138*0Sstevel@tonic-gate "s",
139*0Sstevel@tonic-gate authzid ) )
140*0Sstevel@tonic-gate {
141*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
142*0Sstevel@tonic-gate ber_free( ber, 1 );
143*0Sstevel@tonic-gate return( LDAP_ENCODING_ERROR );
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gate rc = nsldapi_build_control( LDAP_CONTROL_PROXIEDAUTH, ber, 1, 1, ctrlp );
147*0Sstevel@tonic-gate
148*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
149*0Sstevel@tonic-gate return( rc );
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate }
152