@@ -100,12 +100,7 @@ typedef int mode_t;
100
100
#else
101
101
#include < pthread.h>
102
102
#include < sys/resource.h> // getrlimit, setrlimit
103
- #include < unistd.h> // setuid, getuid
104
- #endif
105
-
106
- #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
107
- #include < pwd.h> // getpwnam()
108
- #include < grp.h> // getgrnam()
103
+ #include < unistd.h> // STDIN_FILENO, STDERR_FILENO
109
104
#endif
110
105
111
106
namespace node {
@@ -153,8 +148,6 @@ unsigned int reverted = 0;
153
148
154
149
bool v8_initialized = false ;
155
150
156
- bool linux_at_secure = false ;
157
-
158
151
// process-relative uptime base, initialized at start-up
159
152
double prog_start_time;
160
153
@@ -501,27 +494,6 @@ const char* signo_string(int signo) {
501
494
}
502
495
}
503
496
504
- // Look up environment variable unless running as setuid root.
505
- bool SafeGetenv (const char * key, std::string* text) {
506
- #if !defined(__CloudABI__) && !defined(_WIN32)
507
- if (linux_at_secure || getuid () != geteuid () || getgid () != getegid ())
508
- goto fail;
509
- #endif
510
-
511
- {
512
- Mutex::ScopedLock lock (environ_mutex);
513
- if (const char * value = getenv (key)) {
514
- *text = value;
515
- return true ;
516
- }
517
- }
518
-
519
- fail:
520
- text->clear ();
521
- return false ;
522
- }
523
-
524
-
525
497
void * ArrayBufferAllocator::Allocate (size_t size) {
526
498
if (zero_fill_field_ || per_process_opts->zero_fill_all_buffers )
527
499
return UncheckedCalloc (size);
@@ -1157,14 +1129,6 @@ void SetupProcessObject(Environment* env,
1157
1129
env->SetMethod (process, " dlopen" , binding::DLOpen);
1158
1130
env->SetMethod (process, " reallyExit" , Exit);
1159
1131
env->SetMethodNoSideEffect (process, " uptime" , Uptime);
1160
-
1161
- #if defined(__POSIX__) && !defined(__ANDROID__) && !defined(__CloudABI__)
1162
- env->SetMethodNoSideEffect (process, " getuid" , GetUid);
1163
- env->SetMethodNoSideEffect (process, " geteuid" , GetEUid);
1164
- env->SetMethodNoSideEffect (process, " getgid" , GetGid);
1165
- env->SetMethodNoSideEffect (process, " getegid" , GetEGid);
1166
- env->SetMethodNoSideEffect (process, " getgroups" , GetGroups);
1167
- #endif // __POSIX__ && !defined(__ANDROID__) && !defined(__CloudABI__)
1168
1132
}
1169
1133
1170
1134
@@ -1625,37 +1589,40 @@ void Init(std::vector<std::string>* argv,
1625
1589
{
1626
1590
std::string text;
1627
1591
default_env_options->pending_deprecation =
1628
- SafeGetenv (" NODE_PENDING_DEPRECATION" , &text) && text[0 ] == ' 1' ;
1592
+ credentials::SafeGetenv (" NODE_PENDING_DEPRECATION" , &text) &&
1593
+ text[0 ] == ' 1' ;
1629
1594
}
1630
1595
1631
1596
// Allow for environment set preserving symlinks.
1632
1597
{
1633
1598
std::string text;
1634
1599
default_env_options->preserve_symlinks =
1635
- SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) && text[0 ] == ' 1' ;
1600
+ credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) &&
1601
+ text[0 ] == ' 1' ;
1636
1602
}
1637
1603
1638
1604
{
1639
1605
std::string text;
1640
1606
default_env_options->preserve_symlinks_main =
1641
- SafeGetenv (" NODE_PRESERVE_SYMLINKS_MAIN" , &text) && text[0 ] == ' 1' ;
1607
+ credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS_MAIN" , &text) &&
1608
+ text[0 ] == ' 1' ;
1642
1609
}
1643
1610
1644
1611
if (default_env_options->redirect_warnings .empty ()) {
1645
- SafeGetenv (" NODE_REDIRECT_WARNINGS" ,
1646
- &default_env_options->redirect_warnings );
1612
+ credentials:: SafeGetenv (" NODE_REDIRECT_WARNINGS" ,
1613
+ &default_env_options->redirect_warnings );
1647
1614
}
1648
1615
1649
1616
#if HAVE_OPENSSL
1650
1617
std::string* openssl_config = &per_process_opts->openssl_config ;
1651
1618
if (openssl_config->empty ()) {
1652
- SafeGetenv (" OPENSSL_CONF" , openssl_config);
1619
+ credentials:: SafeGetenv (" OPENSSL_CONF" , openssl_config);
1653
1620
}
1654
1621
#endif
1655
1622
1656
1623
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
1657
1624
std::string node_options;
1658
- if (SafeGetenv (" NODE_OPTIONS" , &node_options)) {
1625
+ if (credentials:: SafeGetenv (" NODE_OPTIONS" , &node_options)) {
1659
1626
std::vector<std::string> env_argv;
1660
1627
// [0] is expected to be the program name, fill it in from the real argv.
1661
1628
env_argv.push_back (argv->at (0 ));
@@ -1687,7 +1654,7 @@ void Init(std::vector<std::string>* argv,
1687
1654
#if defined(NODE_HAVE_I18N_SUPPORT)
1688
1655
// If the parameter isn't given, use the env variable.
1689
1656
if (per_process_opts->icu_data_dir .empty ())
1690
- SafeGetenv (" NODE_ICU_DATA" , &per_process_opts->icu_data_dir );
1657
+ credentials:: SafeGetenv (" NODE_ICU_DATA" , &per_process_opts->icu_data_dir );
1691
1658
// Initialize ICU.
1692
1659
// If icu_data_dir is empty here, it will load the 'minimal' data.
1693
1660
if (!i18n::InitializeICUDirectory (per_process_opts->icu_data_dir )) {
@@ -2095,7 +2062,7 @@ int Start(int argc, char** argv) {
2095
2062
#if HAVE_OPENSSL
2096
2063
{
2097
2064
std::string extra_ca_certs;
2098
- if (SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
2065
+ if (credentials:: SafeGetenv (" NODE_EXTRA_CA_CERTS" , &extra_ca_certs))
2099
2066
crypto::UseExtraCaCerts (extra_ca_certs);
2100
2067
}
2101
2068
#ifdef NODE_FIPS_MODE
0 commit comments