libcosmos
Linux C++ System Programming Library
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PasswdInfo.cxx
1// cosmos
2#include <cosmos/PasswdInfo.hxx>
3#include <cosmos/private/InfoBase.hxx>
4#include <cosmos/utils.hxx>
5
6namespace cosmos {
7
9 auto call = [&](struct passwd **res) -> int {
10 return getpwnam_r(name.raw(), &m_info,
11 m_buf.data(), m_buf.size(),
12 res);
13 };
14
15 m_valid = getInfo(call, "getpwnam_r()");
16
17 if (!m_valid)
18 reset();
19}
20
21PasswdInfo::PasswdInfo(const UserID uid) {
22 auto call = [&](struct passwd **res) -> int {
23 return getpwuid_r(to_integral(uid), &m_info,
24 m_buf.data(), m_buf.size(),
25 res);
26 };
27
28 m_valid = getInfo(call, "getpwuid_r()");
29
30 if (!m_valid)
31 reset();
32}
33
34} // end ns
bool getInfo(std::function< int(struct passwd **)> get_func, const char *errlabel)
Definition InfoBase.hxx:17
SysString passwd() const
Returns the optional encrypted password.
PasswdInfo(const SysString name)
Obtains PasswdInfo for the given username name.
Definition PasswdInfo.cxx:8
Wrapper type around a C-style string for use with system APIs.
Definition SysString.hxx:33