From 7731832751ab9f3c6ddeb66f186d3d7fa1934a6d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 13:11:40 +0200 Subject: Adding upstream version 2.4.57+dfsg. Signed-off-by: Daniel Baumann --- contrib/ldapc++/src/SaslInteractionHandler.cpp | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 contrib/ldapc++/src/SaslInteractionHandler.cpp (limited to 'contrib/ldapc++/src/SaslInteractionHandler.cpp') diff --git a/contrib/ldapc++/src/SaslInteractionHandler.cpp b/contrib/ldapc++/src/SaslInteractionHandler.cpp new file mode 100644 index 0000000..966531f --- /dev/null +++ b/contrib/ldapc++/src/SaslInteractionHandler.cpp @@ -0,0 +1,101 @@ +// $OpenLDAP$ +/* + * Copyright 2007-2021 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include +#include +#include +#include "config.h" + +#ifdef HAVE_TERMIOS_H +#include +#include +#include +#endif + +#include +#include "SaslInteractionHandler.h" +#include "SaslInteraction.h" +#include "debug.h" + +void DefaultSaslInteractionHandler::handleInteractions( + const std::list &cb ) +{ + DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::handleCallbacks()" + << std::endl ); + std::list::const_iterator i; + + for (i = cb.begin(); i != cb.end(); i++ ) { + bool noecho; + + cleanupList.push_back(*i); + + std::cout << (*i)->getPrompt(); + if (! (*i)->getDefaultResult().empty() ) { + std::cout << "(" << (*i)->getDefaultResult() << ")" ; + } + std:: cout << ": "; + + switch ( (*i)->getId() ) { + case SASL_CB_PASS: + case SASL_CB_ECHOPROMPT: + noecho = true; + noecho = true; + break; + default: + noecho = false; + break; + } +#ifdef HAVE_TERMIOS_H + /* turn off terminal echo if needed */ + struct termios old_attr; + if ( noecho ) { + struct termios attr; + if (tcgetattr(STDIN_FILENO, &attr) < 0) { + perror("tcgetattr"); + } + + /* save terminal attributes */ + memcpy(&old_attr, &attr, sizeof(attr)); + + /* disable echo */ + attr.c_lflag &= ~(ECHO); + + /* write attributes to terminal */ + if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) < 0) { + perror("tcsetattr"); + } + } +#endif /* HAVE_TERMIOS_H */ + std::string input; + std::cin >> std::noskipws >> input; + std::cin >> std::skipws; + (*i)->setResult(input); + if( std::cin.fail() ) { + std::cin.clear(); + } + /* ignore the rest of the input line */ + std::cin.ignore(std::numeric_limits::max(), '\n'); + +#ifdef HAVE_TERMIOS_H + /* restore terminal settings */ + if ( noecho ) { + tcsetattr(STDIN_FILENO, TCSANOW, &old_attr); + std::cout << std::endl; + } +#endif /* HAVE_TERMIOS_H */ + } +} + +DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler() +{ + DEBUG(LDAP_DEBUG_TRACE, "DefaultSaslInteractionHandler::~DefaultSaslInteractionHandler()" + << std::endl ); + + std::list::const_iterator i; + for (i = cleanupList.begin(); i != cleanupList.end(); i++ ) { + delete(*i); + } +} -- cgit v1.2.3