Updated with better shell quoting.

This commit is contained in:
Joshua Harlow 2012-02-17 14:46:20 -08:00
parent 17c8249342
commit 5180afe228
3 changed files with 25 additions and 4 deletions

View File

@ -43,7 +43,7 @@ CONFIG_DIR = "etc"
ROOT_CONF = "keystone.conf" ROOT_CONF = "keystone.conf"
CATALOG_CONF = 'default_catalog.templates' CATALOG_CONF = 'default_catalog.templates'
LOGGING_CONF = "logging.conf" LOGGING_CONF = "logging.conf"
LOGGING_SOURCE_FN = 'logging.cnf.sample' LOGGING_SOURCE_FN = 'logging.conf.sample'
CONFIGS = [ROOT_CONF, CATALOG_CONF, LOGGING_CONF] CONFIGS = [ROOT_CONF, CATALOG_CONF, LOGGING_CONF]
#this is a special conf #this is a special conf

View File

@ -16,7 +16,6 @@
from urlparse import urlunparse from urlparse import urlunparse
import re import re
import subprocess
from devstack import date from devstack import date
from devstack import env from devstack import env
@ -58,7 +57,7 @@ class RcGenerator(object):
return lines return lines
def _make_export(self, export_name, value): def _make_export(self, export_name, value):
escaped_val = subprocess.list2cmdline([str(value)]) escaped_val = sh.shellquote(value)
full_line = "export %s=%s" % (export_name, escaped_val) full_line = "export %s=%s" % (export_name, escaped_val)
return [full_line] return [full_line]

View File

@ -33,6 +33,14 @@ ROOT_USER = "root"
ROOT_USER_UID = 0 ROOT_USER_UID = 0
SUDO_UID = 'SUDO_UID' SUDO_UID = 'SUDO_UID'
SUDO_GID = 'SUDO_GID' SUDO_GID = 'SUDO_GID'
SHELL_QUOTE_REPLACERS = {
"'": "\\'",
"\"": "\\\"",
" ": "\\ ",
"(": "\\(",
")": "\\)",
}
FALSE_VALS = ['f', 'false', '0', 'off', False, 0, None]
#root context guard #root context guard
@ -163,6 +171,20 @@ def abspth(path):
return os.path.abspath(path) return os.path.abspath(path)
def shellquote(text):
#TODO since there doesn't seem to be a standard lib that actually works use this way...
do_adjust = False
for srch in SHELL_QUOTE_REPLACERS.keys():
if text.find(srch) != -1:
do_adjust = True
break
if not do_adjust:
return text
for (srch, replace) in SHELL_QUOTE_REPLACERS.items():
text = text.replace(srch, replace)
return "\"" + text + "\""
def listdir(path): def listdir(path):
return os.listdir(path) return os.listdir(path)
@ -231,7 +253,7 @@ def password(pw_prompt=None, pw_len=8):
ask_for_pw = env.get_key(PASS_ASK_ENV) ask_for_pw = env.get_key(PASS_ASK_ENV)
if ask_for_pw is not None: if ask_for_pw is not None:
ask_for_pw = ask_for_pw.lower().strip() ask_for_pw = ask_for_pw.lower().strip()
if ask_for_pw not in ['f', 'false', '0', 'off']: if ask_for_pw not in FALSE_VALS:
pw = prompt_password(pw_prompt) pw = prompt_password(pw_prompt)
if not pw: if not pw:
return _gen_password(pw_len) return _gen_password(pw_len)