Vishwanatha Subbanna | d20225f | 2017-09-06 11:36:04 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Vishwanatha Subbanna | bdb298f | 2017-09-06 11:39:22 +0530 | [diff] [blame^] | 3 | #include <cstring> |
| 4 | #include <experimental/filesystem> |
Vishwanatha Subbanna | d20225f | 2017-09-06 11:36:04 +0530 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
| 6 | #include <sdbusplus/server/object.hpp> |
| 7 | #include <xyz/openbmc_project/User/Password/server.hpp> |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace user |
| 11 | { |
| 12 | |
Vishwanatha Subbanna | bdb298f | 2017-09-06 11:39:22 +0530 | [diff] [blame^] | 13 | using CryptAlgo = std::string; |
| 14 | |
| 15 | namespace fs = std::experimental::filesystem; |
Vishwanatha Subbanna | d20225f | 2017-09-06 11:36:04 +0530 | [diff] [blame] | 16 | namespace Base = sdbusplus::xyz::openbmc_project::User::server; |
| 17 | using Interface = sdbusplus::server::object::object<Base::Password>; |
| 18 | |
| 19 | /** @class User |
| 20 | * @brief Responsible for managing a specific user account. |
| 21 | * It is implementing just the Password interface |
| 22 | * for now. |
| 23 | */ |
| 24 | class User : public Interface |
| 25 | { |
| 26 | public: |
| 27 | User() = delete; |
| 28 | ~User() = default; |
| 29 | User(const User&) = delete; |
| 30 | User& operator=(const User&) = delete; |
| 31 | User(User&&) = delete; |
| 32 | User& operator=(User&&) = delete; |
| 33 | |
| 34 | /** @brief Constructs User object. |
| 35 | * |
| 36 | * @param[in] bus - sdbusplus handler |
| 37 | * @param[in] path - D-Bus path |
| 38 | */ |
| 39 | User(sdbusplus::bus::bus& bus, const char* path) |
| 40 | : Interface(bus, path), |
| 41 | bus(bus), |
Vishwanatha Subbanna | bdb298f | 2017-09-06 11:39:22 +0530 | [diff] [blame^] | 42 | path(path), |
| 43 | user(fs::path(path).filename()) |
Vishwanatha Subbanna | d20225f | 2017-09-06 11:36:04 +0530 | [diff] [blame] | 44 | { |
| 45 | // Do nothing |
| 46 | } |
| 47 | |
| 48 | /** @brief user password set method. If this is called for |
| 49 | * a user ID that already has the password, the password |
| 50 | * would be updated, else password would be created. |
| 51 | * Since this needs an already authenticated session, |
| 52 | * old password is not needed. |
| 53 | * |
| 54 | * @param[in] newPassword - New password |
| 55 | */ |
| 56 | void setPassword(std::string newPassword) override; |
| 57 | |
| 58 | private: |
| 59 | /** @brief sdbusplus handler */ |
| 60 | sdbusplus::bus::bus& bus; |
| 61 | |
| 62 | /** @brief object path */ |
| 63 | const std::string& path; |
Vishwanatha Subbanna | bdb298f | 2017-09-06 11:39:22 +0530 | [diff] [blame^] | 64 | |
| 65 | /** @brief User id extracted from object path */ |
| 66 | const std::string user; |
| 67 | |
| 68 | /** @brief Extracts crypto number from the shadow entry for user |
| 69 | * |
| 70 | * @param[in] spPwdp - sp_pwdp of struct spwd |
| 71 | */ |
| 72 | static CryptAlgo getCryptField(char* spPwdp); |
| 73 | |
| 74 | /** @brief Generates one-way hash based on salt and password |
| 75 | * |
| 76 | * @param[in] password - clear text password |
| 77 | * @param[in] salt - Combination of crypto method and salt |
| 78 | * Eg: $1$HELLO$, where in 1 is crypto method |
| 79 | * and HELLO is salt |
| 80 | */ |
| 81 | static std::string generateHash(const std::string& password, |
| 82 | const std::string& salt); |
| 83 | |
| 84 | /** @brief returns salt string with $ delimiter. |
| 85 | * Eg: If crypt is 1 and salt is HELLO, returns $1$HELLO$ |
| 86 | * |
| 87 | * @param[in] crypt - Crypt number in string |
| 88 | * @param[in] salt - salt |
| 89 | */ |
| 90 | static std::string getSaltString(const std::string& crypt, |
| 91 | const std::string& salt); |
Vishwanatha Subbanna | d20225f | 2017-09-06 11:36:04 +0530 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace user |
| 95 | } // namespace phosphor |