3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
11 #include <ac/string.h>
17 * LDAP Password Modify (Extended) Operation <RFC 3062>
20 int ldap_parse_passwd(
23 struct berval *newpasswd )
27 struct berval *retdata;
30 assert( LDAP_VALID( ld ) );
31 assert( res != NULL );
32 assert( newpasswd != NULL );
34 newpasswd->bv_val = NULL;
35 newpasswd->bv_len = 0;
37 rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 0 );
39 if( rc != LDAP_SUCCESS ) {
43 if( retdata != NULL ) {
45 BerElement *ber = ber_init( retdata );
48 ld->ld_errno = LDAP_NO_MEMORY;
52 /* we should check the tag */
53 tag = ber_scanf( ber, "{o}", newpasswd );
56 if( tag == LBER_ERROR ) {
57 rc = ld->ld_errno = LDAP_DECODING_ERROR;
61 ber_memfree( retoid );
66 ldap_passwd( LDAP *ld,
75 struct berval bv = {0, NULL};
76 BerElement *ber = NULL;
79 assert( LDAP_VALID( ld ) );
80 assert( msgidp != NULL );
82 if( user != NULL || oldpw != NULL || newpw != NULL ) {
83 /* build change password control */
84 ber = ber_alloc_t( LBER_USE_DER );
87 ld->ld_errno = LDAP_NO_MEMORY;
91 ber_printf( ber, "{" /*}*/ );
94 ber_printf( ber, "tO",
95 LDAP_TAG_EXOP_MODIFY_PASSWD_ID, user );
99 ber_printf( ber, "tO",
100 LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, oldpw );
103 if( newpw != NULL ) {
104 ber_printf( ber, "tO",
105 LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, newpw );
108 ber_printf( ber, /*{*/ "N}" );
110 rc = ber_flatten2( ber, &bv, 0 );
113 ld->ld_errno = LDAP_ENCODING_ERROR;
119 rc = ldap_extended_operation( ld, LDAP_EXOP_MODIFY_PASSWD,
120 bv.bv_val ? &bv : NULL, sctrls, cctrls, msgidp );
131 struct berval *oldpw,
132 struct berval *newpw,
133 struct berval *newpasswd,
134 LDAPControl **sctrls,
135 LDAPControl **cctrls )
141 rc = ldap_passwd( ld, user, oldpw, newpw, sctrls, cctrls, &msgid );
142 if ( rc != LDAP_SUCCESS ) {
146 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) {
150 rc = ldap_parse_passwd( ld, res, newpasswd );
151 if( rc != LDAP_SUCCESS ) {
156 return( ldap_result2error( ld, res, 1 ) );