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