@@ -1750,6 +1750,18 @@ static void GetGid(const FunctionCallbackInfo<Value>& args) { |
1750 | 1750 | } |
1751 | 1751 |
|
1752 | 1752 |
|
| 1753 | +static void GetEUid(const FunctionCallbackInfo<Value>& args) { |
| 1754 | + // uid_t is an uint32_t on all supported platforms. |
| 1755 | + args.GetReturnValue().Set(static_cast<uint32_t>(geteuid())); |
| 1756 | +} |
| 1757 | + |
| 1758 | + |
| 1759 | +static void GetEGid(const FunctionCallbackInfo<Value>& args) { |
| 1760 | + // gid_t is an uint32_t on all supported platforms. |
| 1761 | + args.GetReturnValue().Set(static_cast<uint32_t>(getegid())); |
| 1762 | +} |
| 1763 | + |
| 1764 | + |
1753 | 1765 | static void SetGid(const FunctionCallbackInfo<Value>& args) { |
1754 | 1766 | Environment* env = Environment::GetCurrent(args); |
1755 | 1767 |
|
@@ -1769,6 +1781,25 @@ static void SetGid(const FunctionCallbackInfo<Value>& args) { |
1769 | 1781 | } |
1770 | 1782 |
|
1771 | 1783 |
|
| 1784 | +static void SetEGid(const FunctionCallbackInfo<Value>& args) { |
| 1785 | + Environment* env = Environment::GetCurrent(args); |
| 1786 | + |
| 1787 | + if (!args[0]->IsUint32() && !args[0]->IsString()) { |
| 1788 | + return env->ThrowTypeError("setegid argument must be a number or string"); |
| 1789 | + } |
| 1790 | + |
| 1791 | + gid_t gid = gid_by_name(env->isolate(), args[0]); |
| 1792 | + |
| 1793 | + if (gid == gid_not_found) { |
| 1794 | + return env->ThrowError("setegid group id does not exist"); |
| 1795 | + } |
| 1796 | + |
| 1797 | + if (setegid(gid)) { |
| 1798 | + return env->ThrowErrnoException(errno, "setegid"); |
| 1799 | + } |
| 1800 | +} |
| 1801 | + |
| 1802 | + |
1772 | 1803 | static void SetUid(const FunctionCallbackInfo<Value>& args) { |
1773 | 1804 | Environment* env = Environment::GetCurrent(args); |
1774 | 1805 |
|
@@ -1788,6 +1819,25 @@ static void SetUid(const FunctionCallbackInfo<Value>& args) { |
1788 | 1819 | } |
1789 | 1820 |
|
1790 | 1821 |
|
| 1822 | +static void SetEUid(const FunctionCallbackInfo<Value>& args) { |
| 1823 | + Environment* env = Environment::GetCurrent(args); |
| 1824 | + |
| 1825 | + if (!args[0]->IsUint32() && !args[0]->IsString()) { |
| 1826 | + return env->ThrowTypeError("seteuid argument must be a number or string"); |
| 1827 | + } |
| 1828 | + |
| 1829 | + uid_t uid = uid_by_name(env->isolate(), args[0]); |
| 1830 | + |
| 1831 | + if (uid == uid_not_found) { |
| 1832 | + return env->ThrowError("seteuid user id does not exist"); |
| 1833 | + } |
| 1834 | + |
| 1835 | + if (seteuid(uid)) { |
| 1836 | + return env->ThrowErrnoException(errno, "seteuid"); |
| 1837 | + } |
| 1838 | +} |
| 1839 | + |
| 1840 | + |
1791 | 1841 | static void GetGroups(const FunctionCallbackInfo<Value>& args) { |
1792 | 1842 | Environment* env = Environment::GetCurrent(args); |
1793 | 1843 |
|
@@ -2821,10 +2871,14 @@ void SetupProcessObject(Environment* env, |
2821 | 2871 |
|
2822 | 2872 | #if defined(__POSIX__) && !defined(__ANDROID__) |
2823 | 2873 | env->SetMethod(process, "getuid", GetUid); |
| 2874 | + env->SetMethod(process, "geteuid", GetEUid); |
2824 | 2875 | env->SetMethod(process, "setuid", SetUid); |
| 2876 | + env->SetMethod(process, "seteuid", SetEUid); |
2825 | 2877 |
|
2826 | 2878 | env->SetMethod(process, "setgid", SetGid); |
| 2879 | + env->SetMethod(process, "setegid", SetEGid); |
2827 | 2880 | env->SetMethod(process, "getgid", GetGid); |
| 2881 | + env->SetMethod(process, "getegid", GetEGid); |
2828 | 2882 |
|
2829 | 2883 | env->SetMethod(process, "getgroups", GetGroups); |
2830 | 2884 | env->SetMethod(process, "setgroups", SetGroups); |
|