]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/sasl.c
Merge remote-tracking branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / libraries / liblutil / sasl.c
index c920eec66e30d8c5fb271407d87917c0fd0ecec2..add809be77a6963b2bcd3611656fb88b72814362 100644 (file)
@@ -1,7 +1,16 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 2000-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2013 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
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
@@ -20,6 +29,7 @@
 #endif
 
 #include <ldap.h>
+#include "ldap_pvt.h"
 #include "lutil_ldap.h"
 
 
@@ -29,9 +39,29 @@ typedef struct lutil_sasl_defaults_s {
        char *authcid;
        char *passwd;
        char *authzid;
+       char **resps;
+       int nresps;
 } lutilSASLdefaults;
 
 
+void
+lutil_sasl_freedefs(
+       void *defaults )
+{
+       lutilSASLdefaults *defs = defaults;
+
+       assert( defs != NULL );
+       
+       if (defs->mech) ber_memfree(defs->mech);
+       if (defs->realm) ber_memfree(defs->realm);
+       if (defs->authcid) ber_memfree(defs->authcid);
+       if (defs->passwd) ber_memfree(defs->passwd);
+       if (defs->authzid) ber_memfree(defs->authzid);
+       if (defs->resps) ldap_charray_free(defs->resps);
+
+       ber_memfree(defs);
+}
+
 void *
 lutil_sasl_defaults(
        LDAP *ld,
@@ -47,11 +77,11 @@ lutil_sasl_defaults(
 
        if( defaults == NULL ) return NULL;
 
-       defaults->mech = mech;
-       defaults->realm = realm;
-       defaults->authcid = authcid;
-       defaults->passwd = passwd;
-       defaults->authzid = authzid;
+       defaults->mech = mech ? ber_strdup(mech) : NULL;
+       defaults->realm = realm ? ber_strdup(realm) : NULL;
+       defaults->authcid = authcid ? ber_strdup(authcid) : NULL;
+       defaults->passwd = passwd ? ber_strdup(passwd) : NULL;
+       defaults->authzid = authzid ? ber_strdup(authzid) : NULL;
 
        if( defaults->mech == NULL ) {
                ldap_get_option( ld, LDAP_OPT_X_SASL_MECH, &defaults->mech );
@@ -65,6 +95,8 @@ lutil_sasl_defaults(
        if( defaults->authzid == NULL ) {
                ldap_get_option( ld, LDAP_OPT_X_SASL_AUTHZID, &defaults->authzid );
        }
+       defaults->resps = NULL;
+       defaults->nresps = 0;
 
        return defaults;
 }
@@ -118,16 +150,16 @@ static int interaction(
 
        if( challenge ) {
                if( interact->challenge ) {
-                       fprintf( stderr, "Challenge: %s\n", interact->challenge );
+                       fprintf( stderr, _("Challenge: %s\n"), interact->challenge );
                }
        }
 
        if( dflt ) {
-               fprintf( stderr, "Default: %s\n", dflt );
+               fprintf( stderr, _("Default: %s\n"), dflt );
        }
 
        snprintf( input, sizeof input, "%s: ",
-               interact->prompt ? interact->prompt : "Interact" );
+               interact->prompt ? interact->prompt : _("Interact") );
 
        if( noecho ) {
                interact->result = (char *) getpassphrase( input );
@@ -160,7 +192,8 @@ static int interaction(
        if( interact->len > 0 ) {
                /* duplicate */
                char *p = (char *)interact->result;
-               interact->result = strdup( p );
+               ldap_charray_add(&defaults->resps, interact->result);
+               interact->result = defaults->resps[defaults->nresps++];
 
                /* zap */
                memset( p, '\0', interact->len );
@@ -168,15 +201,8 @@ static int interaction(
        } else {
 use_default:
                /* input must be empty */
-               interact->result = strdup( (dflt && *dflt) ? dflt : "" );
-               interact->len = interact->result
-                       ? strlen( interact->result ) : 0;
-       }
-
-       if( defaults && defaults->passwd && interact->id == SASL_CB_PASS ) {
-               /* zap password after first use */
-               memset( defaults->passwd, '\0', strlen(defaults->passwd) );
-               defaults->passwd = NULL;
+               interact->result = (dflt && *dflt) ? dflt : "";
+               interact->len = strlen( interact->result );
        }
 
        return LDAP_SUCCESS;
@@ -190,16 +216,10 @@ int lutil_sasl_interact(
 {
        sasl_interact_t *interact = in;
 
-       if( interact->result ) {
-               /* we have results from a previous interaction */
-               free( (void *)interact->result );
-               interact->result = NULL;
-       }
-
        if( ld == NULL ) return LDAP_PARAM_ERROR;
 
        if( flags == LDAP_SASL_INTERACTIVE ) {
-               fputs( "SASL Interaction\n", stderr );
+               fputs( _("SASL Interaction\n"), stderr );
        }
 
        while( interact->id != SASL_CB_LIST_END ) {