dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / common / proxyauthctrl.c
blob478111d0cd0d6551b236fee1dca4d296a03b3c3b
1 #pragma ident "%Z%%M% %I% %E% SMI"
3 /*
4 * The contents of this file are subject to the Netscape Public
5 * License Version 1.1 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of
7 * the License at http://www.mozilla.org/NPL/
9 * Software distributed under the License is distributed on an "AS
10 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * rights and limitations under the License.
14 * The Original Code is Mozilla Communicator client code, released
15 * March 31, 1998.
17 * The Initial Developer of the Original Code is Netscape
18 * Communications Corporation. Portions created by Netscape are
19 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
20 * Rights Reserved.
22 * Contributor(s):
24 #include "ldap-int.h"
26 /* ldap_create_proxyauth_control
28 Create a "version 1" proxied authorization control.
30 Parameters are
32 ld LDAP pointer to the desired connection
34 dn The dn used in the proxy auth
36 ctl_iscritical Indicates whether the control is critical of not. If
37 this field is non-zero, the operation will only be car-
38 ried out if the control is recognized by the server
39 and/or client
41 ctrlp the address of a place to put the constructed control
44 int
45 LDAP_CALL
46 ldap_create_proxyauth_control (
47 LDAP *ld,
48 const char *dn,
49 const char ctl_iscritical,
50 LDAPControl **ctrlp
53 BerElement *ber;
54 int rc;
56 if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
57 return( LDAP_PARAM_ERROR );
60 if ( ctrlp == NULL ) {
61 LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
62 return ( LDAP_PARAM_ERROR );
64 if (NULL == dn)
66 dn = "";
69 /* create a ber package to hold the controlValue */
70 if ( ( nsldapi_alloc_ber_with_options( ld, &ber ) ) != LDAP_SUCCESS ) {
71 LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
72 return( LDAP_NO_MEMORY );
77 if ( LBER_ERROR == ber_printf( ber,
78 "{s}",
79 dn ) )
81 LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
82 ber_free( ber, 1 );
83 return( LDAP_ENCODING_ERROR );
86 rc = nsldapi_build_control( LDAP_CONTROL_PROXYAUTH, ber, 1,
87 ctl_iscritical, ctrlp );
89 LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
90 return( rc );
95 /* ldap_create_proxiedauth_control
97 Create a "version 2" proxied authorization control.
99 Parameters are
101 ld LDAP pointer to the desired connection
103 authzid The authorization identity used in the proxy auth,
104 e.g., dn:uid=bjensen,dc=example,dc=com
106 ctrlp the address of a place to put the constructed control
110 LDAP_CALL
111 ldap_create_proxiedauth_control (
112 LDAP *ld,
113 const char *authzid,
114 LDAPControl **ctrlp
117 BerElement *ber;
118 int rc;
120 if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
121 return( LDAP_PARAM_ERROR );
124 if ( ctrlp == NULL || authzid == NULL ) {
125 LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
126 return ( LDAP_PARAM_ERROR );
129 /* create a ber package to hold the controlValue */
130 if ( ( nsldapi_alloc_ber_with_options( ld, &ber ) ) != LDAP_SUCCESS ) {
131 LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
132 return( LDAP_NO_MEMORY );
137 if ( LBER_ERROR == ber_printf( ber,
138 "s",
139 authzid ) )
141 LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
142 ber_free( ber, 1 );
143 return( LDAP_ENCODING_ERROR );
146 rc = nsldapi_build_control( LDAP_CONTROL_PROXIEDAUTH, ber, 1, 1, ctrlp );
148 LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
149 return( rc );