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 3???>
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 );
36 rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 0 );
38 if( rc != LDAP_SUCCESS ) {
42 if( retdata != NULL ) {
44 BerElement *ber = ber_init( retdata );
47 ld->ld_errno = LDAP_NO_MEMORY;
51 /* we should check the tag */
52 tag = ber_scanf( ber, "{O}", newpasswd );
55 if( tag == LBER_ERROR ) {
56 rc = ld->ld_errno = LDAP_DECODING_ERROR;
60 ber_memfree( retoid );
65 ldap_passwd( LDAP *ld,
74 struct berval bv = {0, NULL};
75 BerElement *ber = NULL;
78 assert( LDAP_VALID( ld ) );
79 assert( msgidp != NULL );
81 if( user != NULL || oldpw != NULL || newpw != NULL ) {
82 /* build change password control */
83 ber = ber_alloc_t( LBER_USE_DER );
86 ld->ld_errno = LDAP_NO_MEMORY;
90 ber_printf( ber, "{" /*}*/ );
93 ber_printf( ber, "tO",
94 LDAP_TAG_EXOP_MODIFY_PASSWD_ID, user );
98 ber_printf( ber, "tO",
99 LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, oldpw );
102 if( newpw != NULL ) {
103 ber_printf( ber, "tO",
104 LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, newpw );
107 ber_printf( ber, /*{*/ "N}" );
109 rc = ber_flatten2( ber, &bv, 0 );
112 ld->ld_errno = LDAP_ENCODING_ERROR;
118 rc = ldap_extended_operation( ld, LDAP_EXOP_MODIFY_PASSWD,
119 bv.bv_val ? &bv : NULL, sctrls, cctrls, msgidp );
130 struct berval *oldpw,
131 struct berval *newpw,
132 struct berval **newpasswd,
133 LDAPControl **sctrls,
134 LDAPControl **cctrls )
140 rc = ldap_passwd( ld, user, oldpw, newpw, sctrls, cctrls, &msgid );
141 if ( rc != LDAP_SUCCESS ) {
145 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) {
149 rc = ldap_parse_passwd( ld, res, newpasswd );
150 if( rc != LDAP_SUCCESS ) {
155 return( ldap_result2error( ld, res, 1 ) );