3 * Copyright 1998-2002 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 );
56 rc = ld->ld_errno = LDAP_DECODING_ERROR;
60 ber_memfree( retoid );
65 ldap_passwd( LDAP *ld,
74 struct berval *bv = NULL;
77 assert( LDAP_VALID( ld ) );
78 assert( msgidp != NULL );
80 if( user != NULL || oldpw != NULL || newpw != NULL ) {
81 /* build change password control */
82 BerElement *ber = ber_alloc_t( LBER_USE_DER );
85 ld->ld_errno = LDAP_NO_MEMORY;
89 ber_printf( ber, "{" /*}*/ );
92 ber_printf( ber, "ts",
93 LDAP_TAG_EXOP_MODIFY_PASSWD_ID, user );
97 ber_printf( ber, "ts",
98 LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, oldpw );
101 if( newpw != NULL ) {
102 ber_printf( ber, "ts",
103 LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, newpw );
106 ber_printf( ber, /*{*/ "N}" );
108 rc = ber_flatten( ber, &bv );
113 ld->ld_errno = LDAP_ENCODING_ERROR;
119 rc = ldap_extended_operation( ld, LDAP_EXOP_MODIFY_PASSWD,
120 bv, sctrls, cctrls, msgidp );
129 struct berval *oldpw,
130 struct berval *newpw,
131 struct berval **newpasswd,
132 LDAPControl **sctrls,
133 LDAPControl **cctrls )
139 rc = ldap_passwd( ld, user, oldpw, newpw, sctrls, cctrls, &msgid );
140 if ( rc != LDAP_SUCCESS ) {
144 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) {
148 rc = ldap_parse_passwd( ld, res, newpasswd );
149 if( rc != LDAP_SUCCESS ) {
154 return( ldap_result2error( ld, res, 1 ) );