2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
24 #include <folly/String.h>
26 #include "hphp/util/exception.h"
30 struct UserInfo final
{
31 explicit UserInfo(const char* name
) {
32 ::passwd
* retpwptr
= nullptr;
33 int pwbuflen
= ::sysconf(_SC_GETPW_R_SIZE_MAX
);
35 throw Exception("Could not get _SC_GETPW_R_SIZE_MAX");
37 pwbuf
.resize(pwbuflen
);
39 if (::getpwnam_r(name
, &pwd
, pwbuf
.data(), pwbuf
.size(), &retpwptr
)) {
40 throw Exception("getpwnam_r: %s", folly::errnoStr(errno
).c_str());
44 throw Exception("getpwnam_r: no such user: %s", name
);
48 explicit UserInfo(uid_t uid
) {
49 ::passwd
* retpwptr
= nullptr;
50 int pwbuflen
= ::sysconf(_SC_GETPW_R_SIZE_MAX
);
52 throw Exception("Could not get _SC_GETPW_R_SIZE_MAX");
54 pwbuf
.resize(pwbuflen
);
56 if (::getpwuid_r(uid
, &pwd
, pwbuf
.data(), pwbuf
.size(), &retpwptr
)) {
57 throw Exception("getpwuid_r: %s", folly::errnoStr(errno
).c_str());
61 throw Exception("getpwuid_r: no such uid: %u", uid
);
66 std::vector
<char> pwbuf
;
69 struct GroupInfo final
{
70 explicit GroupInfo(const char* name
) {
71 ::group
* retgrptr
= nullptr;
72 int grbuflen
= ::sysconf(_SC_GETGR_R_SIZE_MAX
);
74 throw Exception("Could not get _SC_GETGR_R_SIZE_MAX");
76 grbuf
.resize(grbuflen
);
78 if (::getgrnam_r(name
, &gr
, grbuf
.data(), grbuf
.size(), &retgrptr
)) {
79 throw Exception("getgrnam_r: %s", folly::errnoStr(errno
).c_str());
83 throw Exception("getgrnam_r: no such group: %s", name
);
88 std::vector
<char> grbuf
;