]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Import cancel and passwd
authorKurt Zeilenga <kurt@openldap.org>
Sun, 9 Feb 2003 01:56:04 +0000 (01:56 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Sun, 9 Feb 2003 01:56:04 +0000 (01:56 +0000)
libraries/libldap/Makefile.in
libraries/libldap/cancel.c [new file with mode: 0644]
libraries/libldap/passwd.c [new file with mode: 0644]
libraries/libldap_r/Makefile.in

index e624abce1662cb9e9b1bc245011c9ffb1567f013..22e60b365a05c7695ad0108f172706905a45db68 100644 (file)
@@ -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 (file)
index 0000000..ffc026b
--- /dev/null
@@ -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 <stdio.h>
+#include <ac/stdlib.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#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 (file)
index 0000000..e8ef6fb
--- /dev/null
@@ -0,0 +1,156 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+#include <ac/stdlib.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#include "ldap-int.h"
+
+/*
+ * LDAP Password Modify (Extended) Operation <RFC 3???>
+ */
+
+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 ) );
+}
index fdb8a8d3092b9f00de869cc58526d8b49a7c8774..fd18f64333858c373c25e715aeee503749314ad2 100644 (file)
@@ -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 \