summaryrefslogtreecommitdiff
path: root/include/pam_authenticate.hpp
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2018-09-05 18:30:59 +0300
committerEd Tanous <ed.tanous@intel.com>2018-09-05 18:44:12 +0300
commit1abe55ef9844afcddcab9d862ae06118f3a2390c (patch)
treed0b5fcfd0b1cd679a8995af3eb0b6d31b368380e /include/pam_authenticate.hpp
parenta38b0b206300c792979b900f506b85e535f5708a (diff)
downloadbmcweb-1abe55ef9844afcddcab9d862ae06118f3a2390c.tar.xz
Move to clang-format-6.0
This commit moves the codebase to the lastest clang-format file from upstream, as well as clang-format-6.0. Change-Id: Ice8313468097c0c42317fbb9e10ddf036e8cff4c Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Diffstat (limited to 'include/pam_authenticate.hpp')
-rw-r--r--include/pam_authenticate.hpp112
1 files changed, 62 insertions, 50 deletions
diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp
index 65e47402f7..f51f9aaddb 100644
--- a/include/pam_authenticate.hpp
+++ b/include/pam_authenticate.hpp
@@ -1,72 +1,84 @@
#pragma once
#include <security/pam_appl.h>
+
+#include <boost/utility/string_view.hpp>
#include <cstring>
#include <memory>
-#include <boost/utility/string_view.hpp>
// function used to get user input
inline int pamFunctionConversation(int numMsg, const struct pam_message** msg,
- struct pam_response** resp,
- void* appdataPtr) {
- if (appdataPtr == nullptr) {
- return PAM_AUTH_ERR;
- }
- auto* pass = reinterpret_cast<char*>(
- malloc(std::strlen(reinterpret_cast<char*>(appdataPtr)) + 1));
- std::strcpy(pass, reinterpret_cast<char*>(appdataPtr));
+ struct pam_response** resp, void* appdataPtr)
+{
+ if (appdataPtr == nullptr)
+ {
+ return PAM_AUTH_ERR;
+ }
+ auto* pass = reinterpret_cast<char*>(
+ malloc(std::strlen(reinterpret_cast<char*>(appdataPtr)) + 1));
+ std::strcpy(pass, reinterpret_cast<char*>(appdataPtr));
- *resp = reinterpret_cast<pam_response*>(
- calloc(numMsg, sizeof(struct pam_response)));
+ *resp = reinterpret_cast<pam_response*>(
+ calloc(numMsg, sizeof(struct pam_response)));
- for (int i = 0; i < numMsg; ++i) {
- /* Ignore all PAM messages except prompting for hidden input */
- if (msg[i]->msg_style != PAM_PROMPT_ECHO_OFF) {
- continue;
- }
+ for (int i = 0; i < numMsg; ++i)
+ {
+ /* Ignore all PAM messages except prompting for hidden input */
+ if (msg[i]->msg_style != PAM_PROMPT_ECHO_OFF)
+ {
+ continue;
+ }
- /* Assume PAM is only prompting for the password as hidden input */
- resp[i]->resp = pass;
- }
+ /* Assume PAM is only prompting for the password as hidden input */
+ resp[i]->resp = pass;
+ }
- return PAM_SUCCESS;
+ return PAM_SUCCESS;
}
inline bool pamAuthenticateUser(const boost::string_view username,
- const boost::string_view password) {
- std::string userStr(username);
- std::string passStr(password);
- const struct pam_conv localConversation = {
- pamFunctionConversation, const_cast<char*>(passStr.c_str())};
- pam_handle_t* localAuthHandle = NULL; // this gets set by pam_start
+ const boost::string_view password)
+{
+ std::string userStr(username);
+ std::string passStr(password);
+ const struct pam_conv localConversation = {
+ pamFunctionConversation, const_cast<char*>(passStr.c_str())};
+ pam_handle_t* localAuthHandle = NULL; // this gets set by pam_start
- if (pam_start("webserver", userStr.c_str(), &localConversation,
- &localAuthHandle) != PAM_SUCCESS) {
- return false;
- }
- int retval =
- pam_authenticate(localAuthHandle, PAM_SILENT | PAM_DISALLOW_NULL_AUTHTOK);
+ if (pam_start("webserver", userStr.c_str(), &localConversation,
+ &localAuthHandle) != PAM_SUCCESS)
+ {
+ return false;
+ }
+ int retval = pam_authenticate(localAuthHandle,
+ PAM_SILENT | PAM_DISALLOW_NULL_AUTHTOK);
- if (retval != PAM_SUCCESS) {
- if (retval == PAM_AUTH_ERR) {
- // printf("Authentication failure.\n");
- } else {
- // printf("pam_authenticate returned %d\n", retval);
+ if (retval != PAM_SUCCESS)
+ {
+ if (retval == PAM_AUTH_ERR)
+ {
+ // printf("Authentication failure.\n");
+ }
+ else
+ {
+ // printf("pam_authenticate returned %d\n", retval);
+ }
+ pam_end(localAuthHandle, PAM_SUCCESS);
+ return false;
}
- pam_end(localAuthHandle, PAM_SUCCESS);
- return false;
- }
- /* check that the account is healthy */
- if (pam_acct_mgmt(localAuthHandle, PAM_DISALLOW_NULL_AUTHTOK) !=
- PAM_SUCCESS) {
- pam_end(localAuthHandle, PAM_SUCCESS);
- return false;
- }
+ /* check that the account is healthy */
+ if (pam_acct_mgmt(localAuthHandle, PAM_DISALLOW_NULL_AUTHTOK) !=
+ PAM_SUCCESS)
+ {
+ pam_end(localAuthHandle, PAM_SUCCESS);
+ return false;
+ }
- if (pam_end(localAuthHandle, PAM_SUCCESS) != PAM_SUCCESS) {
- return false;
- }
+ if (pam_end(localAuthHandle, PAM_SUCCESS) != PAM_SUCCESS)
+ {
+ return false;
+ }
- return true;
+ return true;
}