Skip to content

Fix handling of mysql passwords with weird characters in it #2660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixes for supporting passwords with weird characters
Use URL encoding in DATABASE_URL and return mysql_options
as an array (via ugly global variable), so each element
in it can be separately added to the command line using
`@` for expansion.

Because of changing the script to bash, also reverts some
of the changes in 483200a.
  • Loading branch information
eldering committed Jul 5, 2025
commit 49357f1089a7f07cef5a770079696aff755289f2
46 changes: 33 additions & 13 deletions sql/dj_setup_database.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# @configure_input@

# This script allows one to perform DOMjudge database setup actions.
Expand Down Expand Up @@ -52,30 +52,47 @@ not have to pass any of the options above.
EOF
}

urlencode()
{
php -r "echo rawurlencode('$1');"
}

# This is global variable to be able to return the output from
# mysql_options() below as an array, which is not possible otherwise.
declare -a _mysql_options

mysql_options()
{
local user pass
_mysql_options=()

# shellcheck disable=SC2153
if [ -n "$DBUSER" ]; then
_user="-u $DBUSER"
else
_user="${DBA_USER:+-u ${DBA_USER}}"
_mysql_options+=('-u' "$DBUSER")
elif [ -n "$DBA_USER" ]; then
_mysql_options+=('-u' "$DBA_USER")
fi
# shellcheck disable=SC2153
if [ -n "$PASSWD" ]; then
_pass="-p$PASSWD"
else
[ -n "$PROMPT_PASSWD" ] && _pass="-p"
[ -n "$DBA_PASSWD" ] && _pass="-p$DBA_PASSWD"
_mysql_options+=("-p$PASSWD")
elif [ -n "$DBA_PASSWD" ]; then
_mysql_options+=("-p$DBA_PASSWD")
elif [ -n "$PROMPT_PASSWD" ]; then
_mysql_options+=('-p')
fi

[ -z "$USE_SOCKET" ] && port="-P$DBPORT"
echo $_user ${_pass:+"$_pass"} -h "$DBHOST" ${port:+"$port"}
_mysql_options+=('-h' "$DBHOST")

if [ -z "$USE_SOCKET" ]; then
_mysql_options+=("-P$DBPORT")
fi
}

# Wrapper around mysql command to allow setting options, user, etc.
mysql()
{
command mysql $(mysql_options) --silent --skip-column-names "$@"
mysql_options
command mysql "${_mysql_options[@]}" --silent --skip-column-names "$@"
}

# Quick shell hack to get a key from an INI file.
Expand Down Expand Up @@ -126,10 +143,13 @@ symfony_console()
fi

if [ -n "$DBA_USER" ]; then
user=$(urlencode "${DBA_USER}")
host=$(urlencode "${domjudge_DBHOST}")
db=$(urlencode "${domjudge_DBNAME}")
if [ -n "$DBA_PASSWD" ]; then
DATABASE_URL=mysql://${DBA_USER}:${DBA_PASSWD}@${domjudge_DBHOST}:${domjudge_DBPORT}/${domjudge_DBNAME}
DATABASE_URL="mysql://$user:$(urlencode "${DBA_PASSWD}")@$host:${domjudge_DBPORT}/$db"
else
DATABASE_URL=mysql://${DBA_USER}@${domjudge_DBHOST}:${domjudge_DBPORT}/${domjudge_DBNAME}
DATABASE_URL="mysql://$user@$host:${domjudge_DBPORT}/$db"
fi
fi
fi
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy