user_channel: switch to lg2

Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I80149836f196f01eb09cc874f74eec0d787b5ac5
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;