summaryrefslogtreecommitdiffstats
path: root/user.hpp
diff options
context:
space:
mode:
authorRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-05-24 10:49:10 +0530
committerRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-09-03 14:16:20 +0530
commit9f630d9eb0ce1c103532a4304ea080066199094e (patch)
treeb102a63e2617d928ce82215b07637336ded2db7d /user.hpp
parent10eb23f8d64d197dade920178b193c1979235156 (diff)
downloadphosphor-user-manager-9f630d9eb0ce1c103532a4304ea080066199094e.tar.gz
phosphor-user-manager-9f630d9eb0ce1c103532a4304ea080066199094e.zip
Basic support for User manager service
Basic support for User Manager service methods are implemented. Change-Id: Id42432ec6dd421b99971268add931dcd70876f7c Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'user.hpp')
-rw-r--r--user.hpp208
1 files changed, 101 insertions, 107 deletions
diff --git a/user.hpp b/user.hpp
index ca8673f..2e57702 100644
--- a/user.hpp
+++ b/user.hpp
@@ -23,113 +23,107 @@ using Interface = sdbusplus::server::object::object<Base::Password>;
*/
class User : public Interface
{
- public:
- User() = delete;
- ~User() = default;
- User(const User&) = delete;
- User& operator=(const User&) = delete;
- User(User&&) = delete;
- User& operator=(User&&) = delete;
-
- /** @brief Constructs User object.
- *
- * @param[in] bus - sdbusplus handler
- * @param[in] path - D-Bus path
- */
- User(sdbusplus::bus::bus& bus, const char* path)
- : Interface(bus, path),
- bus(bus),
- path(path),
- user(fs::path(path).filename())
- {
- // Do nothing
- }
-
- /** @brief user password set method. If this is called for
- * a user ID that already has the password, the password
- * would be updated, else password would be created.
- * Since this needs an already authenticated session,
- * old password is not needed.
- *
- * @param[in] newPassword - New password
- */
- void setPassword(std::string newPassword) override;
-
-
- private:
- /** @brief sdbusplus handler */
- sdbusplus::bus::bus& bus;
-
- /** @brief object path */
- const std::string& path;
-
- /** @brief User id extracted from object path */
- const std::string user;
-
- /** @brief Returns a random string from set [A-Za-z0-9./]
- * of length size
- *
- * @param[in] numChars - length of string
- */
- static const std::string randomString(int length);
-
- /** @brief Returns password hash created with crypt algo,
- * salt and password
- *
- * @param[in] spPwdp - sp_pwdp of struct spwd
- * @param[in] password - clear text password
- * @param[in] salt - Random salt
- */
- std::string hashPassword(char* spPwdp,
- const std::string& password,
- const std::string& salt);
-
- /** @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);
-
- /** @brief Applies the password for a given user.
- * Writes shadow entries into a temp file
- *
- * @param[in] shadowFile - shadow password file
- * @param[in] password - clear text password
- * @param[in] salt - salt
- */
- void applyPassword(const std::string& shadowFile,
- const std::string& password,
- const std::string& salt);
-
- /** @brief Wrapper for raising exception
- *
- * @param[in] errNo - errno
- * @param[in] errMsg - Error message
- */
- void raiseException(int errNo,
- const std::string& errMsg);
-
- /** @brief For enabling test cases */
- friend class UserTest;
+ public:
+ User() = delete;
+ ~User() = default;
+ User(const User&) = delete;
+ User& operator=(const User&) = delete;
+ User(User&&) = delete;
+ User& operator=(User&&) = delete;
+
+ /** @brief Constructs User object.
+ *
+ * @param[in] bus - sdbusplus handler
+ * @param[in] path - D-Bus path
+ */
+ User(sdbusplus::bus::bus& bus, const char* path) :
+ Interface(bus, path), bus(bus), path(path),
+ user(fs::path(path).filename())
+ {
+ // Do nothing
+ }
+
+ /** @brief user password set method. If this is called for
+ * a user ID that already has the password, the password
+ * would be updated, else password would be created.
+ * Since this needs an already authenticated session,
+ * old password is not needed.
+ *
+ * @param[in] newPassword - New password
+ */
+ void setPassword(std::string newPassword) override;
+
+ private:
+ /** @brief sdbusplus handler */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief object path */
+ const std::string& path;
+
+ /** @brief User id extracted from object path */
+ const std::string user;
+
+ /** @brief Returns a random string from set [A-Za-z0-9./]
+ * of length size
+ *
+ * @param[in] numChars - length of string
+ */
+ static const std::string randomString(int length);
+
+ /** @brief Returns password hash created with crypt algo,
+ * salt and password
+ *
+ * @param[in] spPwdp - sp_pwdp of struct spwd
+ * @param[in] password - clear text password
+ * @param[in] salt - Random salt
+ */
+ std::string hashPassword(char* spPwdp, const std::string& password,
+ const std::string& salt);
+
+ /** @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);
+
+ /** @brief Applies the password for a given user.
+ * Writes shadow entries into a temp file
+ *
+ * @param[in] shadowFile - shadow password file
+ * @param[in] password - clear text password
+ * @param[in] salt - salt
+ */
+ void applyPassword(const std::string& shadowFile,
+ const std::string& password, const std::string& salt);
+
+ /** @brief Wrapper for raising exception
+ *
+ * @param[in] errNo - errno
+ * @param[in] errMsg - Error message
+ */
+ void raiseException(int errNo, const std::string& errMsg);
+
+ /** @brief For enabling test cases */
+ friend class UserTest;
};
} // namespace user
OpenPOWER on IntegriCloud