Skip to content

Commit

Permalink
[irods#8045] Use std::tolower() with std::transform() correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn authored and alanking committed Dec 6, 2024
1 parent 64b997d commit 5878fb0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 52 deletions.
4 changes: 3 additions & 1 deletion lib/core/include/irods/authentication_plugin_framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <fmt/format.h>
#include <nlohmann/json.hpp>

#include <cctype>
#include <functional>
#include <memory>
#include <string>
Expand Down Expand Up @@ -117,7 +118,8 @@ namespace irods::experimental::auth
using plugin_type = authentication_base;

std::string scheme = _scheme;
std::transform(scheme.begin(), scheme.end(), scheme.begin(), ::tolower);
std::transform(
scheme.begin(), scheme.end(), scheme.begin(), [](unsigned char _ch) { return std::tolower(_ch); });

const std::string name = fmt::format("irods_auth_plugin-{}_{}", scheme, _type);

Expand Down
7 changes: 3 additions & 4 deletions lib/core/include/irods/experimental_plugin_framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

// =-=-=-=-=-=-=-
// stl includes
#include <cctype>
#include <sstream>
#include <string>
#include <iostream>
Expand Down Expand Up @@ -145,10 +146,8 @@ namespace irods::experimental::api {
static auto resolve_api_plugin(const std::string& operation, const std::string& type)
{
std::string lower{operation};
std::transform(lower.begin(),
lower.end(),
lower.begin(),
::tolower );
std::transform(
lower.begin(), lower.end(), lower.begin(), [](unsigned char _ch) { return std::tolower(_ch); });

base* plugin{};
auto err = irods::load_plugin<base>(
Expand Down
6 changes: 2 additions & 4 deletions lib/core/include/irods/irods_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <fmt/format.h>

#include <algorithm>
#include <cctype>
#include <string>
#include <vector>

Expand Down Expand Up @@ -45,10 +46,7 @@ namespace irods

std::string lowered{_str};
std::transform(
lowered.begin(),
lowered.end(),
lowered.begin(),
::tolower);
lowered.begin(), lowered.end(), lowered.begin(), [](unsigned char _ch) { return std::tolower(_ch); });

if(GEN_STR == lowered) {
return GENERAL;
Expand Down
5 changes: 4 additions & 1 deletion lib/core/src/clientLogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <fmt/format.h>

#include <cctype>
#include <cerrno>
#include <cstdint>
#include <cstring>
Expand Down Expand Up @@ -344,7 +345,9 @@ int clientLogin(rcComm_t* _comm, const char* _context, const char* _scheme_overr
// =-=-=-=-=-=-=-
// ensure scheme is lower case for comparison
std::string lower_scheme = auth_scheme;
std::transform( auth_scheme.begin(), auth_scheme.end(), auth_scheme.begin(), ::tolower );
std::transform(auth_scheme.begin(), auth_scheme.end(), auth_scheme.begin(), [](unsigned char _ch) {
return std::tolower(_ch);
});

// =-=-=-=-=-=-=-
// filter out the pam auth as it is an extra special
Expand Down
10 changes: 4 additions & 6 deletions lib/core/src/irods_buffer_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <openssl/aes.h>
#include <openssl/md5.h>

#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
Expand Down Expand Up @@ -62,12 +63,9 @@ namespace irods {
salt_size_( _salt_sz ),
num_hash_rounds_( _num_rnds ),
algorithm_( _algo ) {

std::transform(
algorithm_.begin(),
algorithm_.end(),
algorithm_.begin(),
::tolower );
std::transform(algorithm_.begin(), algorithm_.end(), algorithm_.begin(), [](unsigned char _ch) {
return std::tolower(_ch);
});

// =-=-=-=-=-=-=-
// select some sane defaults
Expand Down
31 changes: 11 additions & 20 deletions lib/hasher/src/checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "irods/rodsKeyWdDef.h"
#include "irods/rcMisc.h"

#include <cctype>
#include <cstdio>
#include <ctime>
#include <cstring>
Expand Down Expand Up @@ -55,11 +56,9 @@ int chksumLocFile(
env_policy = env.rodsMatchHashPolicy;
// =-=-=-=-=-=-=-
// hash scheme keywords are all lowercase
std::transform(
env_scheme.begin(),
env_scheme.end(),
env_scheme.begin(),
::tolower );
std::transform(env_scheme.begin(), env_scheme.end(), env_scheme.begin(), [](unsigned char _ch) {
return std::tolower(_ch);
});
}

// =-=-=-=-=-=-=-
Expand All @@ -71,11 +70,9 @@ int chksumLocFile(
hash_scheme = _hash_scheme;
// =-=-=-=-=-=-=-
// hash scheme keywords are all lowercase
std::transform(
hash_scheme.begin(),
hash_scheme.end(),
hash_scheme.begin(),
::tolower );
std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) {
return std::tolower(_ch);
});
}
else {
hash_scheme = env_scheme;
Expand All @@ -84,17 +81,11 @@ int chksumLocFile(

// =-=-=-=-=-=-=-
// hash scheme keywords are all lowercase
std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) {
return std::tolower(_ch);
});
std::transform(
hash_scheme.begin(),
hash_scheme.end(),
hash_scheme.begin(),
::tolower );
std::transform(
env_scheme.begin(),
env_scheme.end(),
env_scheme.begin(),
::tolower );

env_scheme.begin(), env_scheme.end(), env_scheme.begin(), [](unsigned char _ch) { return std::tolower(_ch); });

// =-=-=-=-=-=-=-
// verify checksum scheme against configuration
Expand Down
6 changes: 1 addition & 5 deletions plugins/database/src/db_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,11 +2023,7 @@ irods::error db_debug_op(
// =-=-=-=-=-=-=-
// run tolower on mode
std::string mode( _mode );
std::transform(
mode.begin(),
mode.end(),
mode.begin(),
::tolower );
std::transform(mode.begin(), mode.end(), mode.begin(), [](unsigned char _ch) { return std::tolower(_ch); });

// =-=-=-=-=-=-=-
// if mode contains 'sql' then turn SQL logging on
Expand Down
13 changes: 7 additions & 6 deletions server/api/src/rsFileChksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <fmt/format.h>

#include <algorithm>
#include <cctype>
#include <climits>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -128,11 +129,9 @@ int fileChksum(rsComm_t* rsComm,
} catch ( const irods::exception& ) {}

// make sure the read parameter is lowercased
std::transform(
hash_scheme.begin(),
hash_scheme.end(),
hash_scheme.begin(),
::tolower );
std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) {
return std::tolower(_ch);
});

std::string hash_policy;
try {
Expand Down Expand Up @@ -302,7 +301,9 @@ int file_checksum(RsComm* _comm,
catch (const irods::exception&) {}

// Make sure the read parameter is lowercased.
std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), ::tolower);
std::transform(hash_scheme.begin(), hash_scheme.end(), hash_scheme.begin(), [](unsigned char _ch) {
return std::tolower(_ch);
});

std::string_view hash_policy;
try {
Expand Down
7 changes: 2 additions & 5 deletions server/icat/src/icatHighLevelRoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

// =-=-=-=-=-=-=-
// stl includes
#include <cctype> // For std::tolower
#include <string>
#include <iostream>
#include <sstream>
Expand All @@ -50,11 +51,7 @@ int chlDebug(
// =-=-=-=-=-=-=-
// run tolower on mode
std::string mode( _mode );
std::transform(
mode.begin(),
mode.end(),
mode.begin(),
::tolower );
std::transform(mode.begin(), mode.end(), mode.begin(), [](unsigned char _ch) { return std::tolower(_ch); });

// =-=-=-=-=-=-=-
// if mode contains 'sql' then turn SQL logging on
Expand Down

0 comments on commit 5878fb0

Please sign in to comment.