You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ge...@apache.org on 2019/12/06 20:45:05 UTC

[lucene-solr] branch branch_8x updated: SOLR-13087: Remove 'whoami' usage in bin/solr

This is an automated email from the ASF dual-hosted git repository.

gerlowskija pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new e44bcc0  SOLR-13087: Remove 'whoami' usage in bin/solr
e44bcc0 is described below

commit e44bcc05c44598eff3f60843018d72f8317fa3fe
Author: Jason Gerlowski <ge...@apache.org>
AuthorDate: Fri Dec 6 15:06:23 2019 -0500

    SOLR-13087: Remove 'whoami' usage in bin/solr
    
    whoami displays a warning if the effective-uid is not in /etc/password.
    This can happen in certain situations when running in a docker
    container.  This replaces the 'whoami' usage with a safer check.
---
 solr/CHANGES.txt | 3 +++
 solr/bin/solr    | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 395e1db..07dbe1a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -136,6 +136,9 @@ Bug Fixes
 
 * SOLR-13954: Embedded ZooKeeper in Solr now does not try to load JettyAdminServer (janhoy)
 
+* SOLR-13087: Use EUID instead of whoami to check for root in the bin/solr script (Martijn Koster via Jason Gerlowski)
+
+
 Other Changes
 ---------------------
 
diff --git a/solr/bin/solr b/solr/bin/solr
index 4b62365..9a5a4a2 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -1141,7 +1141,7 @@ if [[ "$SCRIPT_CMD" == "create" || "$SCRIPT_CMD" == "create_core" || "$SCRIPT_CM
     echo "         To turn off: bin/solr config -c $CREATE_NAME -p $CREATE_PORT -action set-user-property -property update.autoCreateFields -value false"
   fi
 
-  if [[ "$(whoami)" == "root" ]] && [[ "$FORCE" == "false" ]] ; then
+  if [[ $EUID -eq 0 ]] && [[ "$FORCE" == "false" ]] ; then
     echo "WARNING: Creating cores as the root user can cause Solr to fail and is not advisable. Exiting."
     echo "         If you started Solr as root (not advisable either), force core creation by adding argument -force"
     exit 1
@@ -1877,7 +1877,7 @@ if [ -z "$STOP_PORT" ]; then
 fi
 
 if [ "$SCRIPT_CMD" == "start" ] || [ "$SCRIPT_CMD" == "restart" ] ; then
-  if [[ "$(whoami)" == "root" ]] && [[ "$FORCE" == "false" ]] ; then
+  if [[ $EUID -eq 0 ]] && [[ "$FORCE" == "false" ]] ; then
     echo "WARNING: Starting Solr as the root user is a security risk and not considered best practice. Exiting."
     echo "         Please consult the Reference Guide. To override this check, start with argument '-force'"
     exit 1