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