From b0e3da7a2ce9732e14b5cc6b6d916ebf088c8107 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sun, 9 Feb 2003 01:56:04 +0000 Subject: [PATCH] Import cancel and passwd --- libraries/libldap/Makefile.in | 10 +- libraries/libldap/cancel.c | 66 ++++++++++++++ libraries/libldap/passwd.c | 156 ++++++++++++++++++++++++++++++++ libraries/libldap_r/Makefile.in | 6 +- 4 files changed, 229 insertions(+), 9 deletions(-) create mode 100644 libraries/libldap/cancel.c create mode 100644 libraries/libldap/passwd.c diff --git a/libraries/libldap/Makefile.in b/libraries/libldap/Makefile.in index e624abce16..22e60b365a 100644 --- a/libraries/libldap/Makefile.in +++ b/libraries/libldap/Makefile.in @@ -11,23 +11,21 @@ PROGRAMS = apitest dntest ftest ltest SRCS = bind.c open.c result.c error.c compare.c search.c \ controls.c messages.c references.c extended.c cyrus.c \ modify.c add.c modrdn.c delete.c abandon.c cache.c \ - sasl.c sbind.c kbind.c unbind.c \ + sasl.c sbind.c kbind.c unbind.c cancel.c \ filter.c free.c sort.c passwd.c whoami.c \ getdn.c getentry.c getattr.c getvalues.c addentry.c \ request.c os-ip.c url.c sortctrl.c vlvctrl.c \ init.c options.c print.c string.c util-int.c schema.c \ - charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \ - cancel.c + charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ controls.lo messages.lo references.lo extended.lo cyrus.lo \ modify.lo add.lo modrdn.lo delete.lo abandon.lo cache.lo \ - sasl.lo sbind.lo kbind.lo unbind.lo \ + sasl.lo sbind.lo kbind.lo unbind.lo cancel.lo \ filter.lo free.lo sort.lo passwd.lo whoami.lo \ getdn.lo getentry.lo getattr.lo getvalues.lo addentry.lo \ request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \ init.lo options.lo print.lo string.lo util-int.lo schema.lo \ - charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \ - cancel.lo + charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries diff --git a/libraries/libldap/cancel.c b/libraries/libldap/cancel.c new file mode 100644 index 0000000000..ffc026be75 --- /dev/null +++ b/libraries/libldap/cancel.c @@ -0,0 +1,66 @@ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +/* + * LDAPv3 Cancel Operation Request + */ + +#include "portable.h" + +#include +#include + +#include +#include +#include + +#include "ldap-int.h" +#include "ldap_log.h" + +#ifdef LDAP_EXOP_X_CANCEL + +int +ldap_cancel( + LDAP *ld, + int cancelid, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp ) +{ + BerElement *cancelidber = NULL; + struct berval *cancelidvalp = NULL; + int rc; + + cancelidber = ber_alloc_t( LBER_USE_DER ); + ber_printf( cancelidber, "{i}", cancelid ); + ber_flatten( cancelidber, &cancelidvalp ); + rc = ldap_extended_operation( ld, LDAP_EXOP_X_CANCEL, + cancelidvalp, sctrls, cctrls, msgidp ); + ber_free( cancelidber, 1 ); + return rc; +} + +int +ldap_cancel_s( + LDAP *ld, + int cancelid, + LDAPControl **sctrls, + LDAPControl **cctrls ) +{ + BerElement *cancelidber = NULL; + struct berval *cancelidvalp = NULL; + int rc; + + cancelidber = ber_alloc_t( LBER_USE_DER ); + ber_printf( cancelidber, "{i}", cancelid ); + ber_flatten( cancelidber, &cancelidvalp ); + rc = ldap_extended_operation_s( ld, LDAP_EXOP_X_CANCEL, + cancelidvalp, sctrls, cctrls, NULL, NULL ); + ber_free( cancelidber, 1 ); + return rc; +} + +#endif /* LDAP_EXOP_X_CANCEL */ diff --git a/libraries/libldap/passwd.c b/libraries/libldap/passwd.c new file mode 100644 index 0000000000..e8ef6fbf27 --- /dev/null +++ b/libraries/libldap/passwd.c @@ -0,0 +1,156 @@ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include +#include +#include +#include + +#include "ldap-int.h" + +/* + * LDAP Password Modify (Extended) Operation + */ + +int ldap_parse_passwd( + LDAP *ld, + LDAPMessage *res, + struct berval **newpasswd ) +{ + int rc; + char *retoid = NULL; + struct berval *retdata; + + 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 ); + + if( rc != LDAP_SUCCESS ) { + return rc; + } + + 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; + } + + /* we should check the tag */ + tag = ber_scanf( ber, "{o}", newpasswd ); + ber_free( ber, 1 ); + + if( tag == LBER_ERROR ) { + rc = ld->ld_errno = LDAP_DECODING_ERROR; + } + } + + ber_memfree( retoid ); + return rc; +} + +int +ldap_passwd( LDAP *ld, + struct berval *user, + struct berval *oldpw, + struct berval *newpw, + LDAPControl **sctrls, + LDAPControl **cctrls, + int *msgidp ) +{ + int rc; + struct berval bv = {0, NULL}; + BerElement *ber = NULL; + + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( msgidp != NULL ); + + if( user != NULL || oldpw != NULL || newpw != NULL ) { + /* build change password control */ + ber = ber_alloc_t( LBER_USE_DER ); + + if( ber == NULL ) { + ld->ld_errno = LDAP_NO_MEMORY; + return ld->ld_errno; + } + + ber_printf( ber, "{" /*}*/ ); + + if( user != NULL ) { + ber_printf( ber, "ts", + LDAP_TAG_EXOP_MODIFY_PASSWD_ID, user ); + } + + if( oldpw != NULL ) { + ber_printf( ber, "ts", + LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, oldpw ); + } + + if( newpw != NULL ) { + ber_printf( ber, "ts", + LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, newpw ); + } + + ber_printf( ber, /*{*/ "N}" ); + + rc = ber_flatten2( ber, &bv, 0 ); + + if( rc < 0 ) { + ld->ld_errno = LDAP_ENCODING_ERROR; + return ld->ld_errno; + } + + } + + rc = ldap_extended_operation( ld, LDAP_EXOP_MODIFY_PASSWD, + bv.bv_val ? &bv : NULL, sctrls, cctrls, msgidp ); + + ber_free( ber, 1 ); + + return rc; +} + +int +ldap_passwd_s( + LDAP *ld, + struct berval *user, + struct berval *oldpw, + struct berval *newpw, + struct berval **newpasswd, + LDAPControl **sctrls, + LDAPControl **cctrls ) +{ + int rc; + int msgid; + LDAPMessage *res; + + rc = ldap_passwd( ld, user, oldpw, newpw, sctrls, cctrls, &msgid ); + if ( rc != LDAP_SUCCESS ) { + return rc; + } + + if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) { + return ld->ld_errno; + } + + rc = ldap_parse_passwd( ld, res, newpasswd ); + if( rc != LDAP_SUCCESS ) { + ldap_msgfree( res ); + return rc; + } + + return( ldap_result2error( ld, res, 1 ) ); +} diff --git a/libraries/libldap_r/Makefile.in b/libraries/libldap_r/Makefile.in index fdb8a8d309..fd18f64333 100644 --- a/libraries/libldap_r/Makefile.in +++ b/libraries/libldap_r/Makefile.in @@ -1,5 +1,5 @@ # $OpenLDAP$ -## Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. +## Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. ## COPYING RESTRICTIONS APPLY, see COPYRIGHT file ## ## Makefile.in for LDAP -lldap @@ -14,7 +14,7 @@ XXSRCS = apitest.c test.c \ controls.c messages.c references.c extended.c cyrus.c \ modify.c add.c modrdn.c delete.c abandon.c cache.c \ sasl.c sbind.c kbind.c unbind.c \ - filter.c free.c sort.c \ + filter.c free.c sort.c passwd.c whoami.c \ getdn.c getentry.c getattr.c getvalues.c addentry.c \ request.c os-ip.c url.c sortctrl.c vlvctrl.c \ init.c options.c print.c string.c util-int.c schema.c \ @@ -29,7 +29,7 @@ OBJS = threads.lo rdwr.lo tpool.lo \ controls.lo messages.lo references.lo extended.lo cyrus.lo \ modify.lo add.lo modrdn.lo delete.lo abandon.lo cache.lo \ sasl.lo sbind.lo kbind.lo unbind.lo \ - filter.lo free.lo sort.lo \ + filter.lo free.lo sort.lo passwd.lo whoami.lo \ getdn.lo getentry.lo getattr.lo getvalues.lo addentry.lo \ request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \ init.lo options.lo print.lo string.lo util-int.lo schema.lo \ -- 2.39.5