user_channel: switch to lg2
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I80149836f196f01eb09cc874f74eec0d787b5ac5
diff --git a/user_channel/channel_layer.cpp b/user_channel/channel_layer.cpp
index 85c3426..02dd055 100644
--- a/user_channel/channel_layer.cpp
+++ b/user_channel/channel_layer.cpp
@@ -19,7 +19,7 @@
#include "channel_mgmt.hpp"
#include "cipher_mgmt.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace ipmi
{
@@ -34,8 +34,7 @@
if (stat(devName.data(), &fileStat) != 0)
{
- phosphor::logging::log<phosphor::logging::level::DEBUG>(
- "Ethernet device not found");
+ lg2::debug("Ethernet device not found");
return false;
}
diff --git a/user_channel/channel_mgmt.cpp b/user_channel/channel_mgmt.cpp
index 841cce5..13ea55b 100644
--- a/user_channel/channel_mgmt.cpp
+++ b/user_channel/channel_mgmt.cpp
@@ -39,8 +39,6 @@
namespace ipmi
{
-using namespace phosphor::logging;
-
static constexpr const char* channelAccessDefaultFilename =
"/usr/share/ipmi-providers/channel_access.json";
static constexpr const char* channelConfigDefaultFilename =
diff --git a/user_channel/channelcommands.cpp b/user_channel/channelcommands.cpp
index cd0a33b..321526f 100644
--- a/user_channel/channelcommands.cpp
+++ b/user_channel/channelcommands.cpp
@@ -18,12 +18,10 @@
#include "channel_layer.hpp"
#include <ipmid/api.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <regex>
-using namespace phosphor::logging;
-
namespace ipmi
{
@@ -51,7 +49,7 @@
if (reserved1 || reserved2 ||
!isValidPrivLimit(static_cast<uint8_t>(channelPrivLimit)))
{
- log<level::DEBUG>("Set channel access - Invalid field in request");
+ lg2::debug("Set channel access - Invalid field in request");
return responseInvalidFieldRequest();
}
@@ -60,7 +58,8 @@
if ((getChannelSessionSupport(chNum) == EChannelSessSupported::none) ||
(!isValidChannel(chNum)))
{
- log<level::DEBUG>("Set channel access - No support on channel");
+ lg2::debug("Set channel access - No support on channel: {CHANNEL}",
+ "CHANNEL", chNum);
return response(ccActionNotSupportedForChannel);
}
@@ -96,7 +95,7 @@
case reserved:
default:
- log<level::DEBUG>("Set channel access - Invalid access set mode");
+ lg2::debug("Set channel access - Invalid access set mode");
return response(ccAccessModeNotSupportedForChannel);
}
@@ -117,7 +116,7 @@
break;
case reserved:
default:
- log<level::DEBUG>("Set channel access - Invalid access priv mode");
+ lg2::debug("Set channel access - Invalid access priv mode");
return response(ccAccessModeNotSupportedForChannel);
}
@@ -126,7 +125,7 @@
compCode = setChannelAccessPersistData(chNum, chNVData, setNVFlag);
if (compCode != ccSuccess)
{
- log<level::DEBUG>("Set channel access - Failed to set access data");
+ lg2::debug("Set channel access - Failed to set access data");
return response(compCode);
}
}
@@ -136,7 +135,7 @@
compCode = setChannelAccessData(chNum, chActData, setActFlag);
if (compCode != ccSuccess)
{
- log<level::DEBUG>("Set channel access - Failed to set access data");
+ lg2::debug("Set channel access - Failed to set access data");
return response(compCode);
}
}
@@ -174,14 +173,14 @@
{
if (reserved1 || reserved2)
{
- log<level::DEBUG>("Get channel access - Invalid field in request");
+ lg2::debug("Get channel access - Invalid field in request");
return responseInvalidFieldRequest();
}
if ((types::enum_cast<EChannelActionType>(accessSetMode) == doNotSet) ||
(types::enum_cast<EChannelActionType>(accessSetMode) == reserved))
{
- log<level::DEBUG>("Get channel access - Invalid Access mode");
+ lg2::debug("Get channel access - Invalid Access mode");
return responseInvalidFieldRequest();
}
@@ -191,7 +190,8 @@
if ((getChannelSessionSupport(chNum) == EChannelSessSupported::none) ||
(!isValidChannel(chNum)))
{
- log<level::DEBUG>("Get channel access - No support on channel");
+ lg2::debug("Get channel access - No support on channel: {CHANNEL}",
+ "CHANNEL", chNum);
return response(ccActionNotSupportedForChannel);
}
@@ -252,7 +252,7 @@
{
if (reserved)
{
- log<level::DEBUG>("Get channel access - Invalid field in request");
+ lg2::debug("Get channel access - Invalid field in request");
return responseInvalidFieldRequest();
}
@@ -260,7 +260,8 @@
ctx->channel);
if (!isValidChannel(chNum))
{
- log<level::DEBUG>("Get channel Info - No support on channel");
+ lg2::debug("Get channel Info - No support on channel: {CHANNEL}",
+ "CHANNEL", chNum);
return responseInvalidFieldRequest();
}
@@ -268,9 +269,9 @@
Cc compCode = getChannelInfo(chNum, chInfo);
if (compCode != ccSuccess)
{
- log<level::ERR>("Failed to get channel info",
- entry("CHANNEL=%x", chNum),
- entry("ERRNO=%x", compCode));
+ lg2::error("Failed to get channel info, channel: {CHANNEL}, "
+ "errno: {ERRNO}",
+ "CHANNEL", chNum, "ERRNO", compCode);
return response(compCode);
}
@@ -329,14 +330,14 @@
if (!doesDeviceExist(chNum) || !isValidChannel(chNum) || reserved)
{
- log<level::DEBUG>("Get channel payload - Invalid field in request");
+ lg2::debug("Get channel payload - Invalid field in request");
return responseInvalidFieldRequest();
}
// Session support is available in active LAN channels.
if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
{
- log<level::DEBUG>("Get channel payload - No support on channel");
+ lg2::debug("Get channel payload - No support on channel");
return response(ccActionNotSupportedForChannel);
}
constexpr uint16_t stdPayloadType = standardPayloadBit(PayloadType::IPMI) |
@@ -374,22 +375,19 @@
if (reserved || !isValidChannel(channel))
{
- log<level::DEBUG>(
- "Get channel payload version - Invalid field in request");
+ lg2::debug("Get channel payload version - Invalid field in request");
return responseInvalidFieldRequest();
}
if (getChannelSessionSupport(channel) == EChannelSessSupported::none)
{
- log<level::DEBUG>(
- "Get channel payload version - No support on channel");
+ lg2::debug("Get channel payload version - No support on channel");
return response(payloadTypeNotSupported);
}
if (!isValidPayloadType(static_cast<PayloadType>(payloadTypeNum)))
{
- log<level::ERR>(
- "Get channel payload version - Payload type unavailable");
+ lg2::error("Get channel payload version - Payload type unavailable");
return response(payloadTypeNotSupported);
}
diff --git a/user_channel/cipher_mgmt.cpp b/user_channel/cipher_mgmt.cpp
index a2f024b..f1bc543 100644
--- a/user_channel/cipher_mgmt.cpp
+++ b/user_channel/cipher_mgmt.cpp
@@ -20,7 +20,7 @@
#include <sys/types.h>
#include <unistd.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <filesystem>
#include <fstream>
@@ -28,7 +28,6 @@
namespace ipmi
{
-using namespace phosphor::logging;
using Json = nlohmann::json;
namespace fs = std::filesystem;
@@ -51,7 +50,7 @@
{
if (!fs::exists(cipherSuiteDefaultPrivFileName))
{
- log<level::ERR>("CS privilege levels default file does not exist...");
+ lg2::error("CS privilege levels default file does not exist...");
}
else
{
@@ -98,7 +97,7 @@
std::ifstream jsonFile(csFileName);
if (!jsonFile.good())
{
- log<level::ERR>("JSON file not found");
+ lg2::error("JSON file not found");
return nullptr;
}
@@ -109,8 +108,9 @@
}
catch (const Json::parse_error& e)
{
- log<level::ERR>("Corrupted cipher suite privilege levels config file.",
- entry("MSG: %s", e.what()));
+ lg2::error(
+ "Corrupted cipher suite privilege levels config file: {ERROR}",
+ "ERROR", e);
}
return data;
@@ -129,8 +129,8 @@
if (fd < 0)
{
- log<level::ERR>("Error opening CS privilege level config file",
- entry("FILE_NAME=%s", tmpFile.c_str()));
+ lg2::error("Error opening CS privilege level config file: {FILE_NAME}",
+ "FILE_NAME", tmpFile);
return -EIO;
}
const auto& writeData = jsonData.dump();
@@ -138,8 +138,8 @@
static_cast<ssize_t>(writeData.size()))
{
close(fd);
- log<level::ERR>("Error writing CS privilege level config file",
- entry("FILE_NAME=%s", tmpFile.c_str()));
+ lg2::error("Error writing CS privilege level config file: {FILE_NAME}",
+ "FILE_NAME", tmpFile);
unlink(tmpRandomFile.data());
return -EIO;
}
@@ -147,8 +147,8 @@
if (std::rename(tmpRandomFile.data(), cipherSuitePrivFileName.c_str()))
{
- log<level::ERR>("Error renaming CS privilege level config file",
- entry("FILE_NAME=%s", tmpFile.c_str()));
+ lg2::error("Error renaming CS privilege level config file: {FILE_NAME}",
+ "FILE_NAME", tmpFile);
unlink(tmpRandomFile.data());
return -EIO;
}
@@ -161,8 +161,7 @@
auto iter = std::find(ipmi::privList.begin(), ipmi::privList.end(), value);
if (iter == privList.end())
{
- log<level::ERR>("Invalid privilege.",
- entry("PRIV_STR=%s", value.c_str()));
+ lg2::error("Invalid privilege: {PRIV_STR}", "PRIV_STR", value);
return ccUnspecifiedError;
}
@@ -179,7 +178,7 @@
{
if (!isValidChannel(chNum))
{
- log<level::ERR>("Invalid channel number", entry("CHANNEL=%u", chNum));
+ lg2::error("Invalid channel number: {CHANNEL}", "CHANNEL", chNum);
return ccInvalidFieldRequest;
}
@@ -195,15 +194,15 @@
{
if (!isValidChannel(chNum))
{
- log<level::ERR>("Invalid channel number", entry("CHANNEL=%u", chNum));
+ lg2::error("Invalid channel number: {CHANNEL}", "CHANNEL", chNum);
return ccInvalidFieldRequest;
}
Json jsonData;
if (!fs::exists(cipherSuitePrivFileName))
{
- log<level::INFO>("CS privilege levels user settings file does not "
- "exist. Creating...");
+ lg2::info("CS privilege levels user settings file does not "
+ "exist. Creating...");
}
else
{
@@ -234,7 +233,7 @@
if (writeCSPrivilegeLevels(jsonData))
{
- log<level::ERR>("Error in setting CS Privilege Levels.");
+ lg2::error("Error in setting CS Privilege Levels.");
return ccUnspecifiedError;
}
diff --git a/user_channel/passwd_mgr.cpp b/user_channel/passwd_mgr.cpp
index acf7c74..9b35ac7 100644
--- a/user_channel/passwd_mgr.cpp
+++ b/user_channel/passwd_mgr.cpp
@@ -26,7 +26,7 @@
#include <sys/stat.h>
#include <unistd.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <cerrno>
#include <cstring>
@@ -59,8 +59,6 @@
size_t macSize;
};
-using namespace phosphor::logging;
-
PasswdMgr::PasswdMgr()
{
restrictFilesPermission();
@@ -77,7 +75,7 @@
{
if (chmod(passwdFileName, S_IRUSR | S_IWUSR) == -1)
{
- log<level::DEBUG>("Error setting chmod for ipmi_pass file");
+ lg2::debug("Error setting chmod for ipmi_pass file");
}
}
}
@@ -88,7 +86,7 @@
{
if (chmod(encryptKeyFileName, S_IRUSR | S_IWUSR) == -1)
{
- log<level::DEBUG>("Error setting chmod for ipmi_pass file");
+ lg2::debug("Error setting chmod for ipmi_pass file");
}
}
}
@@ -116,7 +114,7 @@
{
if (passwdMapList.find(userName) == passwdMapList.end())
{
- log<level::DEBUG>("User not found");
+ lg2::debug("User not found");
return 0;
}
}
@@ -124,11 +122,11 @@
// Write passwdMap to Encryted file
if (updatePasswdSpecialFile(userName, newUserName) != 0)
{
- log<level::DEBUG>("Passwd file update failed");
+ lg2::debug("Passwd file update failed");
return -EIO;
}
- log<level::DEBUG>("Passwd file updated successfully");
+ lg2::debug("Passwd file updated successfully");
return 0;
}
@@ -137,7 +135,7 @@
std::time_t updatedTime = getUpdatedFileTime();
if (fileLastUpdatedTime != updatedTime && updatedTime != -1)
{
- log<level::DEBUG>("Reloading password map list");
+ lg2::debug("Reloading password map list");
passwdMapList.clear();
initPasswordMap();
}
@@ -155,7 +153,7 @@
(size_t)EVP_CIPHER_key_length(cipher) > keyLen ||
(size_t)EVP_CIPHER_iv_length(cipher) > ivLen)
{
- log<level::DEBUG>("Error Invalid Inputs");
+ lg2::debug("Error Invalid Inputs");
return -EINVAL;
}
@@ -169,13 +167,13 @@
calMac.data(),
reinterpret_cast<unsigned int*>(&calMacLen)))
{
- log<level::DEBUG>("Error: Failed to calculate MAC");
+ lg2::debug("Error: Failed to calculate MAC");
return -EIO;
}
if (!((calMacLen == *macLen) &&
(std::memcmp(calMac.data(), mac, calMacLen) == 0)))
{
- log<level::DEBUG>("Authenticated message doesn't match");
+ lg2::debug("Authenticated message doesn't match");
return -EBADMSG;
}
}
@@ -185,7 +183,7 @@
if (!ctx)
{
- log<level::DEBUG>("Error: EVP_CIPHER_CTX is NULL");
+ lg2::debug("Error: EVP_CIPHER_CTX is NULL");
return -ENOMEM;
}
@@ -196,8 +194,7 @@
static_cast<int>(doEncrypt));
if (!retval)
{
- log<level::DEBUG>("EVP_CipherInit_ex failed",
- entry("RET_VAL=%d", retval));
+ lg2::debug("EVP_CipherInit_ex failed: {RET_VAL}", "RET_VAL", retval);
return -EIO;
}
@@ -214,15 +211,13 @@
}
else
{
- log<level::DEBUG>("EVP_CipherFinal fails",
- entry("RET_VAL=%d", retval));
+ lg2::debug("EVP_CipherFinal fails: {RET_VAL}", "RET_VAL", retval);
return -EIO;
}
}
else
{
- log<level::DEBUG>("EVP_CipherUpdate fails",
- entry("RET_VAL=%d", retval));
+ lg2::debug("EVP_CipherUpdate fails: {RET_VAL}", "RET_VAL", retval);
return -EIO;
}
@@ -232,7 +227,7 @@
if (NULL == HMAC(EVP_sha256(), key, keyLen, outBytes, *outBytesLen, mac,
reinterpret_cast<unsigned int*>(macLen)))
{
- log<level::DEBUG>("Failed to create authentication");
+ lg2::debug("Failed to create authentication");
return -EIO;
}
}
@@ -246,7 +241,7 @@
if (readPasswdFileData(dataBuf) != 0)
{
- log<level::DEBUG>("Error in reading the encrypted pass file");
+ lg2::debug("Error in reading the encrypted pass file");
return;
}
@@ -283,20 +278,20 @@
std::ifstream keyFile(encryptKeyFileName, std::ios::in | std::ios::binary);
if (!keyFile.is_open())
{
- log<level::DEBUG>("Error in opening encryption key file");
+ lg2::debug("Error in opening encryption key file");
return -EIO;
}
keyFile.read(reinterpret_cast<char*>(keyBuff.data()), keyBuff.size());
if (keyFile.fail())
{
- log<level::DEBUG>("Error in reading encryption key file");
+ lg2::debug("Error in reading encryption key file");
return -EIO;
}
std::ifstream passwdFile(passwdFileName, std::ios::in | std::ios::binary);
if (!passwdFile.is_open())
{
- log<level::DEBUG>("Error in opening ipmi password file");
+ lg2::debug("Error in opening ipmi password file");
return -EIO;
}
@@ -308,7 +303,7 @@
passwdFile.read(reinterpret_cast<char*>(input.data()), fileSize);
if (passwdFile.fail())
{
- log<level::DEBUG>("Error in reading encryption key file");
+ lg2::debug("Error in reading encryption key file");
return -EIO;
}
@@ -317,7 +312,7 @@
if (std::strncmp(metaData->signature, META_PASSWD_SIG,
sizeof(metaData->signature)))
{
- log<level::DEBUG>("Error signature mismatch in password file");
+ lg2::debug("Error signature mismatch in password file");
return -EBADMSG;
}
@@ -325,7 +320,7 @@
// If data is empty i.e no password map then return success
if (inBytesLen == 0)
{
- log<level::DEBUG>("Empty password file");
+ lg2::debug("Empty password file");
return 0;
}
@@ -336,7 +331,7 @@
input.data() + sizeof(*metaData), metaData->hashSize,
key.data(), reinterpret_cast<unsigned int*>(&keyLen)))
{
- log<level::DEBUG>("Failed to create MAC for authentication");
+ lg2::debug("Failed to create MAC for authentication");
return -EIO;
}
@@ -355,7 +350,7 @@
reinterpret_cast<unsigned char*>(outBytes.data()),
&outBytesLen) != 0)
{
- log<level::DEBUG>("Error in decryption");
+ lg2::debug("Error in decryption");
return -EIO;
}
// Resize the vector to outBytesLen
@@ -382,7 +377,7 @@
// Check user existance and return if not exist.
if (readPasswdFileData(dataBuf) != 0)
{
- log<level::DEBUG>("Error in reading the encrypted pass file");
+ lg2::debug("Error in reading the encrypted pass file");
return -EIO;
}
@@ -430,7 +425,7 @@
}
if (!isUsrFound)
{
- log<level::DEBUG>("User doesn't exist");
+ lg2::debug("User doesn't exist");
return 0;
}
@@ -439,13 +434,13 @@
std::ifstream keyFile(encryptKeyFileName, std::ios::in | std::ios::binary);
if (!keyFile.good())
{
- log<level::DEBUG>("Error in opening encryption key file");
+ lg2::debug("Error in opening encryption key file");
return -EIO;
}
keyFile.read(reinterpret_cast<char*>(keyBuff.data()), keyBuff.size());
if (keyFile.fail())
{
- log<level::DEBUG>("Error in reading encryption key file");
+ lg2::debug("Error in reading encryption key file");
return -EIO;
}
keyFile.close();
@@ -454,7 +449,7 @@
struct stat st = {};
if (stat(passwdFileName, &st) != 0)
{
- log<level::DEBUG>("Error in getting password file fstat()");
+ lg2::debug("Error in getting password file fstat()");
return -EIO;
}
@@ -468,7 +463,7 @@
int fd = mkstemp((char*)tempFileName.data());
if (fd == -1)
{
- log<level::DEBUG>("Error creating temp file");
+ lg2::debug("Error creating temp file");
return -EIO;
}
@@ -480,14 +475,14 @@
if ((temp)() == NULL)
{
close(fd);
- log<level::DEBUG>("Error creating temp file");
+ lg2::debug("Error creating temp file");
return -EIO;
}
// Set the file mode as read-write for owner only
if (fchmod(fileno((temp)()), S_IRUSR | S_IWUSR) < 0)
{
- log<level::DEBUG>("Error setting fchmod for temp file");
+ lg2::debug("Error setting fchmod for temp file");
return -EIO;
}
@@ -505,21 +500,21 @@
// encryption.
if (RAND_bytes(hash.data(), hashLen) != 1)
{
- log<level::DEBUG>("Hash genertion failed, bailing out");
+ lg2::debug("Hash genertion failed, bailing out");
return -EIO;
}
if (NULL == HMAC(digest, keyBuff.data(), keyBuff.size(), hash.data(),
hashLen, key.data(),
reinterpret_cast<unsigned int*>(&keyLen)))
{
- log<level::DEBUG>("Failed to create MAC for authentication");
+ lg2::debug("Failed to create MAC for authentication");
return -EIO;
}
// Generate IV values
if (RAND_bytes(iv.data(), ivLen) != 1)
{
- log<level::DEBUG>("UV genertion failed, bailing out");
+ lg2::debug("UV genertion failed, bailing out");
return -EIO;
}
@@ -533,7 +528,7 @@
reinterpret_cast<unsigned char*>(inBytes.data()), inBytesLen,
mac.data(), &macLen, outBytes.data(), &outBytesLen) != 0)
{
- log<level::DEBUG>("Error while encrypting the data");
+ lg2::debug("Error while encrypting the data");
return -EIO;
}
outBytes[outBytesLen] = 0;
@@ -550,38 +545,37 @@
if (fwrite(&metaData, 1, sizeof(metaData), (temp)()) != sizeof(metaData))
{
- log<level::DEBUG>("Error in writing meta data");
+ lg2::debug("Error in writing meta data");
return -EIO;
}
if (fwrite(&hash[0], 1, hashLen, (temp)()) != hashLen)
{
- log<level::DEBUG>("Error in writing hash data");
+ lg2::debug("Error in writing hash data");
return -EIO;
}
if (fwrite(&iv[0], 1, ivLen, (temp)()) != ivLen)
{
- log<level::DEBUG>("Error in writing IV data");
+ lg2::debug("Error in writing IV data");
return -EIO;
}
if (fwrite(&outBytes[0], 1, outBytesLen, (temp)()) != outBytesLen)
{
- log<level::DEBUG>("Error in writing encrypted data");
+ lg2::debug("Error in writing encrypted data");
return -EIO;
}
if (fwrite(&mac[0], 1, macLen, (temp)()) != macLen)
{
- log<level::DEBUG>("Error in writing MAC data");
+ lg2::debug("Error in writing MAC data");
return -EIO;
}
if (fflush((temp)()))
{
- log<level::DEBUG>(
- "File fflush error while writing entries to special file");
+ lg2::debug("File fflush error while writing entries to special file");
return -EIO;
}
@@ -590,7 +584,7 @@
// Rename the tmp file to actual file
if (std::rename(strTempFileName.data(), passwdFileName) != 0)
{
- log<level::DEBUG>("Failed to rename tmp file to ipmi-pass");
+ lg2::debug("Failed to rename tmp file to ipmi-pass");
return -EIO;
}
@@ -602,7 +596,7 @@
struct stat fileStat = {};
if (stat(passwdFileName, &fileStat) != 0)
{
- log<level::DEBUG>("Error - Getting passwd file time stamp");
+ lg2::debug("Error - Getting passwd file time stamp");
return -EIO;
}
return fileStat.st_mtime;
diff --git a/user_channel/shadowlock.hpp b/user_channel/shadowlock.hpp
index c869aca..1dc5f3b 100644
--- a/user_channel/shadowlock.hpp
+++ b/user_channel/shadowlock.hpp
@@ -3,6 +3,7 @@
#include <shadow.h>
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace phosphor
{
@@ -31,7 +32,7 @@
{
if (!lckpwdf())
{
- log<level::ERR>("Locking Shadow failed");
+ lg2::error("Locking Shadow failed");
elog<InternalFailure>();
}
}
@@ -39,7 +40,7 @@
{
if (!ulckpwdf())
{
- log<level::ERR>("Un-Locking Shadow failed");
+ lg2::error("Un-Locking Shadow failed");
elog<InternalFailure>();
}
}
diff --git a/user_channel/user_mgmt.cpp b/user_channel/user_mgmt.cpp
index 00ed142..979aaa6 100644
--- a/user_channel/user_mgmt.cpp
+++ b/user_channel/user_mgmt.cpp
@@ -28,7 +28,7 @@
#include <ipmid/types.hpp>
#include <nlohmann/json.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus/match.hpp>
#include <sdbusplus/server/object.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -166,10 +166,10 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Failed to set property",
- entry("PROPERTY=%s", property.c_str()),
- entry("PATH=%s", objPath.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ lg2::error("Failed to set {PROPERTY}, path: {PATH}, "
+ "interface: {INTERFACE}",
+ "PROPERTY", property, "PATH", objPath, "INTERFACE",
+ interface);
throw;
}
}
@@ -234,9 +234,9 @@
}
if (usrIndex > ipmiMaxUsers)
{
- log<level::DEBUG>("User not found for signal",
- entry("USER_NAME=%s", userName.c_str()),
- entry("USER_EVENT=%d", userEvent));
+ lg2::debug("User not found for signal, user name: {USER_NAME}, "
+ "user event: {USER_EVENT}",
+ "USER_NAME", userName, "USER_EVENT", userEvent);
return;
}
switch (userEvent)
@@ -288,16 +288,16 @@
}
default:
{
- log<level::ERR>("Unhandled user event",
- entry("USER_EVENT=%d", userEvent));
+ lg2::error("Unhandled user event: {USER_EVENT}", "USER_EVENT",
+ userEvent);
return;
}
}
}
usrAccess.writeUserData();
- log<level::DEBUG>("User event handled successfully",
- entry("USER_NAME=%s", userName.c_str()),
- entry("USER_EVENT=%d", userEvent));
+ lg2::debug("User event handled successfully, user name: {USER_NAME}, "
+ "user event: {USER_EVENT}",
+ "USER_NAME", userName.c_str(), "USER_EVENT", userEvent);
return;
}
@@ -347,15 +347,14 @@
}
else
{
- log<level::ERR>("Unknown user update signal",
- entry("SIGNAL=%s", signal.c_str()));
+ lg2::error("Unknown user update signal: {SIGNAL}", "SIGNAL", signal);
return;
}
if (signal.empty() || userName.empty() ||
(signal == userRenamedSignal && newUserName.empty()))
{
- log<level::ERR>("Invalid inputs received");
+ lg2::error("Invalid inputs received");
return;
}
@@ -411,10 +410,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::DEBUG>(
- "Failed to excute method",
- entry("METHOD=%s", getAllPropertiesMethod),
- entry("PATH=%s", msg.get_path()));
+ lg2::debug("Failed to excute {METHOD}, path: {PATH}",
+ "METHOD", getAllPropertiesMethod, "PATH",
+ msg.get_path());
return;
}
usrAccess.getUserProperties(properties, groups, priv,
@@ -457,7 +455,7 @@
std::ofstream::out | std::ofstream::app);
if (!mutexCleanUpFile.good())
{
- log<level::DEBUG>("Unable to open mutex cleanup file");
+ lg2::debug("Unable to open mutex cleanup file");
return;
}
mutexCleanUpFile.close();
@@ -527,8 +525,8 @@
{
return static_cast<CommandPrivilege>(privNoAccess);
}
- log<level::ERR>("Error in converting to IPMI privilege",
- entry("PRIV=%s", value.c_str()));
+ lg2::error("Error in converting to IPMI privilege: {PRIV}", "PRIV",
+ value);
throw std::out_of_range("Out of range - convertToIPMIPrivilege");
}
else
@@ -550,8 +548,8 @@
}
catch (const std::out_of_range& e)
{
- log<level::ERR>("Error in converting to system privilege",
- entry("PRIV=%d", static_cast<uint8_t>(value)));
+ lg2::error("Error in converting to system privilege: {PRIV}", "PRIV",
+ value);
throw std::out_of_range("Out of range - convertToSystemPrivilege");
}
}
@@ -560,18 +558,18 @@
{
if (userName.empty())
{
- log<level::ERR>("userName is empty");
+ lg2::error("userName is empty");
return false;
}
if (!std::regex_match(userName.c_str(),
std::regex("[a-zA-Z_][a-zA-Z_0-9]*")))
{
- log<level::ERR>("Unsupported characters in user name");
+ lg2::error("Unsupported characters in user name");
return false;
}
if (userName == "root")
{
- log<level::ERR>("Invalid user name - root");
+ lg2::error("Invalid user name - root");
return false;
}
std::map<DbusUserObjPath, DbusUserObjValue> properties;
@@ -585,9 +583,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Failed to excute method",
- entry("METHOD=%s", getManagedObjectsMethod),
- entry("PATH=%s", userMgrObjBasePath));
+ lg2::error("Failed to excute {METHOD}, path: {PATH}", "METHOD",
+ getManagedObjectsMethod, "PATH", userMgrObjBasePath);
return false;
}
@@ -597,8 +594,8 @@
if (properties.find(usersPath) != properties.end())
{
- log<level::DEBUG>("User name already exists",
- entry("USER_NAME=%s", userName.c_str()));
+ lg2::debug("Username {USER_NAME} already exists", "USER_NAME",
+ userName);
return false;
}
@@ -719,7 +716,7 @@
if (pam_start("dropbear", username.data(), &localConversation,
&localAuthHandle) != PAM_SUCCESS)
{
- log<level::ERR>("User Authentication Failure");
+ lg2::error("User Authentication Failure");
return false;
}
@@ -728,8 +725,8 @@
if (retval != PAM_SUCCESS)
{
- log<level::DEBUG>("pam_authenticate returned failure",
- entry("ERROR=%d", retval));
+ lg2::debug("pam_authenticate returned failure: {ERROR}", "ERROR",
+ retval);
pam_end(localAuthHandle, retval);
return false;
@@ -754,7 +751,7 @@
{
if (pamUpdatePasswd(userName.c_str(), userPassword.c_str()) != PAM_SUCCESS)
{
- log<level::DEBUG>("Failed to update password");
+ lg2::debug("Failed to update password");
return ccUnspecifiedError;
}
return ccSuccess;
@@ -765,8 +762,8 @@
std::string userName;
if (ipmiUserGetUserName(userId, userName) != ccSuccess)
{
- log<level::DEBUG>("User Name not found",
- entry("USER-ID=%d", (uint8_t)userId));
+ lg2::debug("User Name not found, user Id: {USER_ID}", "USER_ID",
+ userId);
return ccParmOutOfRange;
}
@@ -783,13 +780,13 @@
}
case PAM_AUTHTOK_ERR:
{
- log<level::DEBUG>("Bad authentication token");
+ lg2::debug("Bad authentication token");
return ccInvalidFieldRequest;
}
default:
{
- log<level::DEBUG>("Failed to update password",
- entry("USER-ID=%d", (uint8_t)userId));
+ lg2::debug("Failed to update password, user Id: {USER_ID}",
+ "USER_ID", userId);
return ccUnspecifiedError;
}
}
@@ -810,7 +807,7 @@
ipmiMaxUserName);
if (userName.empty())
{
- log<level::DEBUG>("User name not set / invalid");
+ lg2::debug("User name not set / invalid");
return ccUnspecifiedError;
}
if (userInfo->userEnabled != enabledState)
@@ -827,7 +824,7 @@
}
catch (const std::exception& e)
{
- log<level::DEBUG>("Write user data failed");
+ lg2::debug("Write user data failed");
return ccUnspecifiedError;
}
}
@@ -882,7 +879,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Write user data failed");
+ lg2::error("Write user data failed");
return ccUnspecifiedError;
}
return ccSuccess;
@@ -908,7 +905,7 @@
ipmiMaxUserName);
if (userName.empty())
{
- log<level::DEBUG>("User name not set / invalid");
+ lg2::debug("User name not set / invalid");
return ccUnspecifiedError;
}
std::string priv = convertToSystemPrivilege(
@@ -939,7 +936,7 @@
}
catch (const std::exception& e)
{
- log<level::DEBUG>("Write user data failed");
+ lg2::debug("Write user data failed");
return ccUnspecifiedError;
}
return ccSuccess;
@@ -964,8 +961,7 @@
}
if (usrIndex > ipmiMaxUsers)
{
- log<level::DEBUG>("User not found",
- entry("USER_NAME=%s", userName.c_str()));
+ lg2::debug("Username {USER_NAME} not found", "USER_NAME", userName);
return invalidUserId;
}
@@ -1039,9 +1035,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::DEBUG>("Failed to excute method",
- entry("METHOD=%s", deleteUserMethod),
- entry("PATH=%s", userPath.c_str()));
+ lg2::debug("Failed to excute {METHOD}, path:{PATH}", "METHOD",
+ deleteUserMethod, "PATH", userPath);
return ccUnspecifiedError;
}
deleteUserIndex(userId);
@@ -1064,9 +1059,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::DEBUG>("Failed to excute method",
- entry("METHOD=%s", createUserMethod),
- entry("PATH=%s", userMgrObjBasePath));
+ lg2::debug("Failed to excute {METHOD}, path: {PATH}", "METHOD",
+ createUserMethod, "PATH", userMgrObjBasePath);
return ccUnspecifiedError;
}
@@ -1093,9 +1087,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::DEBUG>("Failed to excute method",
- entry("METHOD=%s", renameUserMethod),
- entry("PATH=%s", userMgrObjBasePath));
+ lg2::debug("Failed to excute {METHOD}, path: {PATH}", "METHOD",
+ renameUserMethod, "PATH", userMgrObjBasePath);
return ccUnspecifiedError;
}
std::fill(static_cast<uint8_t*>(userInfo->userName),
@@ -1120,7 +1113,7 @@
}
catch (const std::exception& e)
{
- log<level::DEBUG>("Write user data failed");
+ lg2::debug("Write user data failed");
return ccUnspecifiedError;
}
return ccSuccess;
@@ -1234,7 +1227,7 @@
std::ifstream iUsrData(ipmiUserDataFile, std::ios::in | std::ios::binary);
if (!iUsrData.good())
{
- log<level::ERR>("Error in reading IPMI user data file");
+ lg2::error("Error in reading IPMI user data file");
throw std::ios_base::failure("Error opening IPMI user data file");
}
@@ -1243,8 +1236,7 @@
if (jsonUsersTbl.size() != ipmiMaxUsers)
{
- log<level::ERR>(
- "Error in reading IPMI user data file - User count issues");
+ lg2::error("Error in reading IPMI user data file - User count issues");
throw std::runtime_error(
"Corrupted IPMI user data file - invalid user count");
}
@@ -1255,8 +1247,8 @@
Json userInfo = jsonUsersTbl[usrIndex - 1]; // json array starts with 0.
if (userInfo.is_null())
{
- log<level::ERR>("Error in reading IPMI user data file - "
- "user info corrupted");
+ lg2::error("Error in reading IPMI user data file - "
+ "user info corrupted");
throw std::runtime_error(
"Corrupted IPMI user data file - invalid user info");
}
@@ -1300,8 +1292,8 @@
if (stdPayload[payloadNum].size() != ipmiMaxChannels ||
oemPayload[payloadNum].size() != ipmiMaxChannels)
{
- log<level::ERR>("Error in reading IPMI user data file - "
- "payload properties corrupted");
+ lg2::error("Error in reading IPMI user data file - "
+ "payload properties corrupted");
throw std::runtime_error(
"Corrupted IPMI user data file - payload properties");
}
@@ -1319,8 +1311,8 @@
linkAuthEnabled.size() != ipmiMaxChannels ||
accessCallback.size() != ipmiMaxChannels)
{
- log<level::ERR>("Error in reading IPMI user data file - "
- "properties corrupted");
+ lg2::error("Error in reading IPMI user data file - "
+ "properties corrupted");
throw std::runtime_error(
"Corrupted IPMI user data file - properties");
}
@@ -1346,7 +1338,7 @@
userInfo[jsonFixedUser].get<bool>();
}
- log<level::DEBUG>("User data read from IPMI data file");
+ lg2::debug("User data read from IPMI data file");
iUsrData.close();
// Update the timestamp
fileLastUpdatedTime = getUpdatedFileTime();
@@ -1410,7 +1402,7 @@
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0)
{
- log<level::ERR>("Error in creating temporary IPMI user data file");
+ lg2::error("Error in creating temporary IPMI user data file");
throw std::ios_base::failure(
"Error in creating temporary IPMI user data file");
}
@@ -1419,7 +1411,7 @@
static_cast<ssize_t>(writeStr.size()))
{
close(fd);
- log<level::ERR>("Error in writing temporary IPMI user data file");
+ lg2::error("Error in writing temporary IPMI user data file");
throw std::ios_base::failure(
"Error in writing temporary IPMI user data file");
}
@@ -1427,7 +1419,7 @@
if (std::rename(tmpFile.c_str(), ipmiUserDataFile) != 0)
{
- log<level::ERR>("Error in renaming temporary IPMI user data file");
+ lg2::error("Error in renaming temporary IPMI user data file");
throw std::runtime_error("Error in renaming IPMI user data file");
}
// Update the timestamp
@@ -1448,8 +1440,7 @@
ipmiMaxUserName);
if (userName == curName)
{
- log<level::DEBUG>("User name exists",
- entry("USER_NAME=%s", userName.c_str()));
+ lg2::debug("Username {USER_NAME} exists", "USER_NAME", userName);
return false; // user name exists.
}
@@ -1462,7 +1453,7 @@
}
if (freeIndex == 0xFF)
{
- log<level::ERR>("No empty slots found");
+ lg2::error("No empty slots found");
return false;
}
std::strncpy(reinterpret_cast<char*>(userData->user[freeIndex].userName),
@@ -1544,9 +1535,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::DEBUG>("Failed to excute method",
- entry("METHOD=%s", getAllPropertiesMethod),
- entry("PATH=%s", userMgrObjBasePath));
+ lg2::debug("Failed to excute {METHOD}, path: {PATH}", "METHOD",
+ getAllPropertiesMethod, "PATH", userMgrObjBasePath);
return;
}
for (const auto& t : properties)
@@ -1570,7 +1560,7 @@
struct stat fileStat;
if (stat(ipmiUserDataFile, &fileStat) != 0)
{
- log<level::DEBUG>("Error in getting last updated time stamp");
+ lg2::debug("Error in getting last updated time stamp");
return std::timespec{0, 0};
}
return fileStat.st_mtim;
@@ -1644,7 +1634,7 @@
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0)
{
- log<level::ERR>("Error in creating IPMI user signal lock file");
+ lg2::error("Error in creating IPMI user signal lock file");
throw std::ios_base::failure(
"Error in creating temporary IPMI user signal lock file");
}
@@ -1655,7 +1645,7 @@
// host-ipmid
if (userUpdatedSignal == nullptr && sigHndlrLock.try_lock())
{
- log<level::DEBUG>("Registering signal handler");
+ lg2::debug("Registering signal handler");
userUpdatedSignal = std::make_unique<sdbusplus::bus::match_t>(
bus,
sdbusplus::bus::match::rules::type::signal() +
@@ -1696,9 +1686,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::DEBUG>("Failed to excute method",
- entry("METHOD=%s", getManagedObjectsMethod),
- entry("PATH=%s", userMgrObjBasePath));
+ lg2::debug("Failed to excute {METHOD}, path: {PATH}", "METHOD",
+ getManagedObjectsMethod, "PATH", userMgrObjBasePath);
return;
}
bool updateRequired = false;
@@ -1783,7 +1772,7 @@
std::string usrObjPath = std::string(usrObj.first);
if (getUserNameFromPath(usrObj.first.str, userName) != 0)
{
- log<level::ERR>("Error in user object path");
+ lg2::error("Error in user object path");
continue;
}
getUserObjProperties(usrObj.second, usrGrps, usrPriv, usrEnabled);
diff --git a/user_channel/usercommands.cpp b/user_channel/usercommands.cpp
index 6467e45..53b34f8 100644
--- a/user_channel/usercommands.cpp
+++ b/user_channel/usercommands.cpp
@@ -23,15 +23,13 @@
#include <security/pam_appl.h>
#include <ipmid/api.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <regex>
namespace ipmi
{
-using namespace phosphor::logging;
-
static constexpr uint8_t enableOperation = 0x00;
static constexpr uint8_t disableOperation = 0x01;
@@ -64,7 +62,7 @@
if (reserved1 || reserved2 || sessLimit ||
!ipmiUserIsValidPrivilege(static_cast<uint8_t>(privilege)))
{
- log<level::DEBUG>("Set user access - Invalid field in request");
+ lg2::debug("Set user access - Invalid field in request");
return ipmi::responseInvalidFieldRequest();
}
@@ -72,17 +70,17 @@
ctx->channel);
if (!isValidChannel(chNum))
{
- log<level::DEBUG>("Set user access - Invalid channel request");
+ lg2::debug("Set user access - Invalid channel request");
return ipmi::response(invalidChannel);
}
if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
{
- log<level::DEBUG>("Set user access - No support on channel");
+ lg2::debug("Set user access - No support on channel");
return ipmi::response(ccActionNotSupportedForChannel);
}
if (!ipmiUserIsValidUserId(static_cast<uint8_t>(userId)))
{
- log<level::DEBUG>("Set user access - Parameter out of range");
+ lg2::debug("Set user access - Parameter out of range");
return ipmi::responseParmOutOfRange();
}
@@ -144,18 +142,18 @@
if (reserved1 || reserved2 || !isValidChannel(chNum))
{
- log<level::DEBUG>("Get user access - Invalid field in request");
+ lg2::debug("Get user access - Invalid field in request");
return ipmi::responseInvalidFieldRequest();
}
if (getChannelSessionSupport(chNum) == EChannelSessSupported::none)
{
- log<level::DEBUG>("Get user access - No support on channel");
+ lg2::debug("Get user access - No support on channel");
return ipmi::response(ccActionNotSupportedForChannel);
}
if (!ipmiUserIsValidUserId(static_cast<uint8_t>(userId)))
{
- log<level::DEBUG>("Get user access - Parameter out of range");
+ lg2::debug("Get user access - Parameter out of range");
return ipmi::responseParmOutOfRange();
}
@@ -219,7 +217,7 @@
uint8_t userId = static_cast<uint8_t>(id);
if (!ipmiUserIsValidUserId(userId))
{
- log<level::DEBUG>("Set user name - Invalid user id");
+ lg2::debug("Set user name - Invalid user id");
return ipmi::responseParmOutOfRange();
}
@@ -252,7 +250,8 @@
std::string userName;
if (ipmiUserGetUserName(userId, userName) != ccSuccess)
{ // Invalid User ID
- log<level::DEBUG>("User Name not found", entry("USER-ID=%u", userId));
+ lg2::debug("User Name not found, user Id: {USER_ID}", "USER_ID",
+ userId);
return ipmi::responseParmOutOfRange();
}
// copy the std::string into a fixed array
@@ -280,7 +279,7 @@
{
if (reserved1 || reserved2)
{
- log<level::DEBUG>("Invalid data field in request");
+ lg2::debug("Invalid data field in request");
return ipmi::responseInvalidFieldRequest();
}
@@ -295,7 +294,7 @@
((pwLen20 && (userPassword.size() != maxIpmi20PasswordSize)) ||
(!pwLen20 && (userPassword.size() != maxIpmi15PasswordSize))))
{
- log<level::DEBUG>("Invalid Length");
+ lg2::debug("Invalid Length");
return ipmi::responseReqDataLenInvalid();
}
@@ -305,7 +304,8 @@
std::string userName;
if (ipmiUserGetUserName(userId, userName) != ccSuccess)
{
- log<level::DEBUG>("User Name not found", entry("USER-ID=%d", userId));
+ lg2::debug("User Name not found, user Id: {USER_ID}", "USER_ID",
+ userId);
return ipmi::responseParmOutOfRange();
}
@@ -352,8 +352,8 @@
pwBad |= pwLenDiffers;
if (pwBad)
{
- log<level::DEBUG>("Test password failed",
- entry("USER-ID=%d", userId));
+ lg2::debug("Test password failed, user Id: {USER_ID}", "USER_ID",
+ userId);
static constexpr ipmi::Cc ipmiCCPasswdFailMismatch = 0x80;
return ipmi::response(ipmiCCPasswdFailMismatch);
}
@@ -417,15 +417,13 @@
if (reserved1 || reserved2 || !isValidChannel(channel) ||
!isValidPrivLimit(static_cast<uint8_t>(privLevel)))
{
- log<level::DEBUG>(
- "Get channel auth capabilities - Invalid field in request");
+ lg2::debug("Get channel auth capabilities - Invalid field in request");
return ipmi::responseInvalidFieldRequest();
}
if (getChannelSessionSupport(channel) == EChannelSessSupported::none)
{
- log<level::DEBUG>(
- "Get channel auth capabilities - No support on channel");
+ lg2::debug("Get channel auth capabilities - No support on channel");
return ipmi::response(ccActionNotSupportedForChannel);
}