summaryrefslogtreecommitdiffstats
path: root/user.hpp
diff options
context:
space:
mode:
authorVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-09-06 11:39:22 +0530
committerVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-09-13 12:54:39 +0530
commitbdb298f744cc71421f0c2e6f50254f933c6bb3cc (patch)
tree1505ad26fc8078c7fa6e0bd427d4e6f2ef9941c6 /user.hpp
parent54309f17f35169e9f4b617b98fec43f6ac6507e1 (diff)
downloadphosphor-user-manager-bdb298f744cc71421f0c2e6f50254f933c6bb3cc.tar.gz
phosphor-user-manager-bdb298f744cc71421f0c2e6f50254f933c6bb3cc.zip
Extract crypto algorithm field and add utility functions
Password field of a user in /etc/shadow contains 3 parts: [Crypt algorithm, Salt, encrypted password] Example: A value of "1" in crypt algorithm maps to MD5 Need to use the same crypt algorithm that is already used before when the new password is to be updated. Change-Id: Ib7d8e0ad6f3bcce30f5c2be89b4e033230c07bf4 Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'user.hpp')
-rw-r--r--user.hpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/user.hpp b/user.hpp
index 25c7e62..aa40820 100644
--- a/user.hpp
+++ b/user.hpp
@@ -1,6 +1,7 @@
#pragma once
-#include <string>
+#include <cstring>
+#include <experimental/filesystem>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
#include <xyz/openbmc_project/User/Password/server.hpp>
@@ -9,6 +10,9 @@ namespace phosphor
namespace user
{
+using CryptAlgo = std::string;
+
+namespace fs = std::experimental::filesystem;
namespace Base = sdbusplus::xyz::openbmc_project::User::server;
using Interface = sdbusplus::server::object::object<Base::Password>;
@@ -35,7 +39,8 @@ class User : public Interface
User(sdbusplus::bus::bus& bus, const char* path)
: Interface(bus, path),
bus(bus),
- path(path)
+ path(path),
+ user(fs::path(path).filename())
{
// Do nothing
}
@@ -56,6 +61,34 @@ class User : public Interface
/** @brief object path */
const std::string& path;
+
+ /** @brief User id extracted from object path */
+ const std::string user;
+
+ /** @brief Extracts crypto number from the shadow entry for user
+ *
+ * @param[in] spPwdp - sp_pwdp of struct spwd
+ */
+ static CryptAlgo getCryptField(char* spPwdp);
+
+ /** @brief Generates one-way hash based on salt and password
+ *
+ * @param[in] password - clear text password
+ * @param[in] salt - Combination of crypto method and salt
+ * Eg: $1$HELLO$, where in 1 is crypto method
+ * and HELLO is salt
+ */
+ static std::string generateHash(const std::string& password,
+ const std::string& salt);
+
+ /** @brief returns salt string with $ delimiter.
+ * Eg: If crypt is 1 and salt is HELLO, returns $1$HELLO$
+ *
+ * @param[in] crypt - Crypt number in string
+ * @param[in] salt - salt
+ */
+ static std::string getSaltString(const std::string& crypt,
+ const std::string& salt);
};
} // namespace user
OpenPOWER on IntegriCloud