X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fpasswd.c;h=0f2e2f13ee9fecb8415b16d3e16265c2a40268f4;hb=baad2b249d32aa364f95cb80e917b13a0bcf48e7;hp=245e9e99c52e38b084940b62ab1d0b4a4f36197e;hpb=6939c531700652491f4be4688c6a1f35a1ab8a18;p=openldap diff --git a/libraries/libldap/passwd.c b/libraries/libldap/passwd.c index 245e9e99c5..0f2e2f13ee 100644 --- a/libraries/libldap/passwd.c +++ b/libraries/libldap/passwd.c @@ -1,7 +1,20 @@ /* $OpenLDAP$ */ -/* - * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2008 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* ACKNOWLEDGEMENTS: + * This program was orignally developed by Kurt D. Zeilenga for inclusion in + * OpenLDAP Software. */ #include "portable.h" @@ -14,50 +27,51 @@ #include "ldap-int.h" /* - * LDAP Password Modify (Extended) Operation + * LDAP Password Modify (Extended) Operation (RFC 3062) */ int ldap_parse_passwd( LDAP *ld, LDAPMessage *res, - struct berval **newpasswd ) + struct berval *newpasswd ) { int rc; - char *retoid = NULL; - struct berval *retdata; + struct berval *retdata = NULL; assert( ld != NULL ); assert( LDAP_VALID( ld ) ); assert( res != NULL ); assert( newpasswd != NULL ); - *newpasswd = NULL; - - rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 0 ); + newpasswd->bv_val = NULL; + newpasswd->bv_len = 0; - if( rc != LDAP_SUCCESS ) { + rc = ldap_parse_extended_result( ld, res, NULL, &retdata, 0 ); + if ( rc != LDAP_SUCCESS ) { return rc; } - if( retdata != NULL ) { + if ( retdata != NULL ) { ber_tag_t tag; BerElement *ber = ber_init( retdata ); - if( ber == NULL ) { - ld->ld_errno = LDAP_NO_MEMORY; - return ld->ld_errno; + if ( ber == NULL ) { + rc = ld->ld_errno = LDAP_NO_MEMORY; + goto done; } /* we should check the tag */ tag = ber_scanf( ber, "{o}", newpasswd ); ber_free( ber, 1 ); - if( tag == -1 ) { + if ( tag == LBER_ERROR ) { rc = ld->ld_errno = LDAP_DECODING_ERROR; } } - ber_memfree( retoid ); +done:; + ber_bvfree( retdata ); + return rc; } @@ -71,7 +85,7 @@ ldap_passwd( LDAP *ld, int *msgidp ) { int rc; - struct berval bv = {0}; + struct berval bv = BER_BVNULL; BerElement *ber = NULL; assert( ld != NULL ); @@ -90,17 +104,17 @@ ldap_passwd( LDAP *ld, ber_printf( ber, "{" /*}*/ ); if( user != NULL ) { - ber_printf( ber, "ts", + ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_ID, user ); } if( oldpw != NULL ) { - ber_printf( ber, "ts", + ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, oldpw ); } if( newpw != NULL ) { - ber_printf( ber, "ts", + ber_printf( ber, "tO", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, newpw ); } @@ -129,7 +143,7 @@ ldap_passwd_s( struct berval *user, struct berval *oldpw, struct berval *newpw, - struct berval **newpasswd, + struct berval *newpasswd, LDAPControl **sctrls, LDAPControl **cctrls ) { @@ -142,7 +156,7 @@ ldap_passwd_s( return rc; } - if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) { + if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) == -1 || !res ) { return ld->ld_errno; }