Skip to content

Commit

Permalink
fix: fix issues reported by cpplint
Browse files Browse the repository at this point in the history
  • Loading branch information
jsurkont committed May 31, 2021
1 parent 5a9ef68 commit e9fe5d6
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,5 @@ fabric.properties

# Google C++ test library
googletest*

config.json
2 changes: 2 additions & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set noparent
filter=-legal/copyright,-build/c++11,-build/header_guard
5 changes: 2 additions & 3 deletions src/include/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ void Config::load(const char *path) {
j.at("oauth").at("username_attribute").get<std::string>();
qr_error_correction_level =
j.at("qr").at("error_correction_level").get<int>();
if (j.find("ldap") != j.end() and
j["ldap"].find("hosts") != j["ldap"].end()) {
if (j.find("ldap") != j.end() && j["ldap"].find("hosts") != j["ldap"].end()) {
for (auto &host : j["ldap"]["hosts"]) {
ldap_hosts.insert((std::string)host);
}
Expand All @@ -46,7 +45,7 @@ void Config::load(const char *path) {
}
}
}
request_mfa = bool(false);
request_mfa = false;
if (j["oauth"].contains("request_mfa")) {
request_mfa = j.at("oauth").at("request_mfa").get<bool>();
}
Expand Down
9 changes: 5 additions & 4 deletions src/include/ldapquery.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ldapquery.h"
#include "ldapquery.h" // NOLINT(build/include_subdir)

#include <ldap.h>
#include <stdio.h>
Expand Down Expand Up @@ -29,8 +29,9 @@ int ldap_check_attr(const char *host, const char *basedn, const char *user,
return LDAPQUERY_ERROR;
}

passwd_local = (char *)malloc(strlen(passwd) + 1);
strcpy(passwd_local, passwd);
passwd_local =
(char *)malloc(strlen(passwd) + 1); // NOLINT(readability/casting)
strcpy(passwd_local, passwd); // NOLINT(runtime/printf)
cred.bv_val = passwd_local;
cred.bv_len = strlen(passwd);
rc = ldap_sasl_bind_s(ld, user, LDAP_SASL_SIMPLE, &cred, NULL, NULL,
Expand Down Expand Up @@ -81,4 +82,4 @@ int ldap_check_attr(const char *host, const char *basedn, const char *user,
ldap_msgfree(res);
ldap_unbind_ext_s(ld, NULL, NULL);
return rc;
}
}
2 changes: 1 addition & 1 deletion src/include/ldapquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ int ldap_check_attr(const char *host, const char *basedn, const char *user,
const char *passwd, const char *filter, const char *attr,
const char *value);

#endif // PAM_OAUTH2_DEVICE_LDAPQUERY_H
#endif // PAM_OAUTH2_DEVICE_LDAPQUERY_H
10 changes: 5 additions & 5 deletions src/pam_oauth2_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ std::string DeviceAuthResponse::get_prompt(const int qr_ecc = 0) {

static size_t WriteCallback(void *contents, size_t size, size_t nmemb,
void *userp) {
((std::string *)userp)->append((char *)contents, size * nmemb);
((std::string *)userp)
->append(reinterpret_cast<char *>(contents), size * nmemb);
return size * nmemb;
}

Expand All @@ -128,7 +129,6 @@ void make_authorization_request(const char *client_id,
params += "&acr_values=https://refeds.org/profile/mfa";
params +=
" urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";
;
}
curl_easy_setopt(curl, CURLOPT_URL, device_endpoint);
curl_easy_setopt(curl, CURLOPT_USERNAME, client_id);
Expand Down Expand Up @@ -160,7 +160,7 @@ void make_authorization_request(const char *client_id,

void poll_for_token(const char *client_id, const char *client_secret,
const char *token_endpoint, const char *device_code,
std::string &token) {
std::string *token) {
int timeout = 300, interval = 3;
CURL *curl;
CURLcode res;
Expand Down Expand Up @@ -201,7 +201,7 @@ void poll_for_token(const char *client_id, const char *client_secret,
try {
data = json::parse(readBuffer);
if (data["error"].empty()) {
token = data.at("access_token");
token->assign(data.at("access_token"));
break;
} else if (data["error"] == "authorization_pending") {
// Do nothing
Expand Down Expand Up @@ -389,7 +389,7 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
show_prompt(pamh, config.qr_error_correction_level, &device_auth_response);
poll_for_token(config.client_id.c_str(), config.client_secret.c_str(),
config.token_endpoint.c_str(),
device_auth_response.device_code.c_str(), token);
device_auth_response.device_code.c_str(), &token);
get_userinfo(config.userinfo_endpoint.c_str(), token.c_str(),
config.username_attribute.c_str(), &userinfo);
} catch (PamError &e) {
Expand Down
4 changes: 2 additions & 2 deletions src/pam_oauth2_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void make_authorization_request(const char *client_id,

void poll_for_token(const char *client_id, const char *client_secret,
const char *token_endpoint, const char *device_code,
std::string &token);
std::string *token);

void get_userinfo(const char *userinfo_endpoint, const char *token,
const char *username_attribute, Userinfo *userinfo);

#endif // PAM_OAUTH2_DEVICE_HPP
#endif // PAM_OAUTH2_DEVICE_HPP
2 changes: 1 addition & 1 deletion test/test_pam_oauth2_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST(PamTest, Device) {

TEST(PamTest, Token) {
std::string token;
poll_for_token(CLIENT_ID, CLIENT_SECRET, TOKEN_ENDPOINT, DEVICE_CODE, token);
poll_for_token(CLIENT_ID, CLIENT_SECRET, TOKEN_ENDPOINT, DEVICE_CODE, &token);
EXPECT_EQ(token, ACCESS_TOKEN);
}

Expand Down

0 comments on commit e9fe5d6

Please sign in to comment.