Skip to content

Commit

Permalink
build,src: Add CloudABI as a POSIX-like runtime environment.
Browse files Browse the repository at this point in the history
CloudABI is a compact POSIX-like runtime that makes use of
capability-based security. More details:
https://github.com/NuxiNL/cloudlibc

* src: Disable use of pwd.h, grp.h and get*uid() on CloudABI.
As CloudABI is intended to run applications in cluster contexts (e.g.,
on Kubernetes), they are oblivious of UNIX credentials. Extend the
existing preprocessor checks to disable any use of these interfaces,
just like on Windows, Android, etc.

* src: Explicitly include <netdb.h>.
cares_wrap.cc calls into functions like getnameinfo() and getaddrinfo().
These functions tend to be available implicitly through <uv.h>, but we'd
better still include this header explicitly.

On CloudABI, we make use of a custom implementation of libuv that does
not implicitly include header files like <netdb.h>.

PR-URL: #16612
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
EdSchouten authored and refack committed Nov 1, 2017
1 parent d1a9c02 commit 78dbcbe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
'cflags': [ '-pthread', ], 'cflags': [ '-pthread', ],
'ldflags': [ '-pthread' ], 'ldflags': [ '-pthread' ],
}], }],
[ 'OS in "linux freebsd openbsd solaris android aix"', { [ 'OS in "linux freebsd openbsd solaris android aix cloudabi"', {
'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ], 'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ],
'cflags_cc': [ '-fno-rtti', '-fno-exceptions', '-std=gnu++0x' ], 'cflags_cc': [ '-fno-rtti', '-fno-exceptions', '-std=gnu++0x' ],
'ldflags': [ '-rdynamic' ], 'ldflags': [ '-rdynamic' ],
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ from gyp_node import run_gyp
parser = optparse.OptionParser() parser = optparse.OptionParser()


valid_os = ('win', 'mac', 'solaris', 'freebsd', 'openbsd', 'linux', valid_os = ('win', 'mac', 'solaris', 'freebsd', 'openbsd', 'linux',
'android', 'aix') 'android', 'aix', 'cloudabi')
valid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'mips64el', 'ppc', valid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'mips64el', 'ppc',
'ppc64', 'x32','x64', 'x86', 's390', 's390x') 'ppc64', 'x32','x64', 'x86', 's390', 's390x')
valid_arm_float_abi = ('soft', 'softfp', 'hard') valid_arm_float_abi = ('soft', 'softfp', 'hard')
Expand Down
4 changes: 4 additions & 0 deletions src/cares_wrap.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <vector> #include <vector>
#include <unordered_set> #include <unordered_set>


#ifdef __POSIX__
# include <netdb.h>
#endif // __POSIX__

#if defined(__ANDROID__) || \ #if defined(__ANDROID__) || \
defined(__MINGW32__) || \ defined(__MINGW32__) || \
defined(__OpenBSD__) || \ defined(__OpenBSD__) || \
Expand Down
12 changes: 6 additions & 6 deletions src/node.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ typedef int mode_t;
#include <unistd.h> // setuid, getuid #include <unistd.h> // setuid, getuid
#endif #endif


#if defined(__POSIX__) && !defined(__ANDROID__) #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
#include <pwd.h> // getpwnam() #include <pwd.h> // getpwnam()
#include <grp.h> // getgrnam() #include <grp.h> // getgrnam()
#endif #endif
Expand Down Expand Up @@ -1002,7 +1002,7 @@ Local<Value> UVException(Isolate* isolate,


// Look up environment variable unless running as setuid root. // Look up environment variable unless running as setuid root.
bool SafeGetenv(const char* key, std::string* text) { bool SafeGetenv(const char* key, std::string* text) {
#ifndef _WIN32 #if !defined(__CloudABI__) && !defined(_WIN32)
if (linux_at_secure || getuid() != geteuid() || getgid() != getegid()) if (linux_at_secure || getuid() != geteuid() || getgid() != getegid())
goto fail; goto fail;
#endif #endif
Expand Down Expand Up @@ -2122,7 +2122,7 @@ static void Umask(const FunctionCallbackInfo<Value>& args) {
} }




#if defined(__POSIX__) && !defined(__ANDROID__) #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)


static const uid_t uid_not_found = static_cast<uid_t>(-1); static const uid_t uid_not_found = static_cast<uid_t>(-1);
static const gid_t gid_not_found = static_cast<gid_t>(-1); static const gid_t gid_not_found = static_cast<gid_t>(-1);
Expand Down Expand Up @@ -2441,7 +2441,7 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {
} }
} }


#endif // __POSIX__ && !defined(__ANDROID__) #endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__)




static void WaitForInspectorDisconnect(Environment* env) { static void WaitForInspectorDisconnect(Environment* env) {
Expand Down Expand Up @@ -3706,7 +3706,7 @@ void SetupProcessObject(Environment* env,


env->SetMethod(process, "umask", Umask); env->SetMethod(process, "umask", Umask);


#if defined(__POSIX__) && !defined(__ANDROID__) #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
env->SetMethod(process, "getuid", GetUid); env->SetMethod(process, "getuid", GetUid);
env->SetMethod(process, "geteuid", GetEUid); env->SetMethod(process, "geteuid", GetEUid);
env->SetMethod(process, "setuid", SetUid); env->SetMethod(process, "setuid", SetUid);
Expand All @@ -3720,7 +3720,7 @@ void SetupProcessObject(Environment* env,
env->SetMethod(process, "getgroups", GetGroups); env->SetMethod(process, "getgroups", GetGroups);
env->SetMethod(process, "setgroups", SetGroups); env->SetMethod(process, "setgroups", SetGroups);
env->SetMethod(process, "initgroups", InitGroups); env->SetMethod(process, "initgroups", InitGroups);
#endif // __POSIX__ && !defined(__ANDROID__) #endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__)


env->SetMethod(process, "_kill", Kill); env->SetMethod(process, "_kill", Kill);


Expand Down

0 comments on commit 78dbcbe

Please sign in to comment.