mirror of https://github.com/jumpserver/jumpserver
fix sudo bug
parent
a73fa7811c
commit
08cbaa1622
|
@ -701,7 +701,7 @@ class Nav(object):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not file_path:
|
if not file_path:
|
||||||
print "文件路径为空"
|
color_print("文件路径为空")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
runner.run('fetch', module_args='src=%s dest=%s' % (file_path, tmp_dir), pattern=pattern)
|
runner.run('fetch', module_args='src=%s dest=%s' % (file_path, tmp_dir), pattern=pattern)
|
||||||
|
|
|
@ -5,15 +5,15 @@ real_file=/etc/sudoers
|
||||||
tmp_file=$(mktemp /tmp/XXXXXXX)
|
tmp_file=$(mktemp /tmp/XXXXXXX)
|
||||||
|
|
||||||
# Backup sudoers file
|
# Backup sudoers file
|
||||||
cp ${sudo_file} ${sudo_file_bak}
|
cp ${real_file} ${tmp_file}
|
||||||
|
|
||||||
# Add Command Aliases
|
# Add Command Aliases
|
||||||
add_cmd_alias() {
|
add_cmd_alias() {
|
||||||
sudo_file=$1
|
sudo_file=$1
|
||||||
{% for sudo_name, sudo_cmd in sudo_alias.items %}
|
{% for sudo_name, sudo_cmd in sudo_alias.items %}
|
||||||
{% if sudo_name != 'ALL' %}
|
{% if sudo_name != 'ALL' %}
|
||||||
if $(grep '^Cmnd_Alias {{ sudo_name }}' ${sudo_file} &> /dev/null); then
|
if $(grep '^Cmnd_Alias \<{{ sudo_name }}\>' ${sudo_file} &> /dev/null); then
|
||||||
sed -i 's@^Cmnd_Alias.*{{ sudo_name }}.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file}
|
sed -i 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file}
|
||||||
else
|
else
|
||||||
echo "Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}" >> ${sudo_file}
|
echo "Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}" >> ${sudo_file}
|
||||||
fi
|
fi
|
||||||
|
@ -26,8 +26,8 @@ add_cmd_alias() {
|
||||||
add_role_chosen() {
|
add_role_chosen() {
|
||||||
sudo_file=$1
|
sudo_file=$1
|
||||||
{% for user, alias in sudo_user.items %}
|
{% for user, alias in sudo_user.items %}
|
||||||
if $(grep '^{{ user }}.*' ${sudo_file} &> /dev/null); then
|
if $(grep '^{{ user }}\>' ${sudo_file} &> /dev/null); then
|
||||||
sed -i 's@^{{ user }}.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file}
|
sed -i 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file}
|
||||||
else
|
else
|
||||||
echo "{{ user }} ALL = (root) NOPASSWD: {{ alias }}" >> ${sudo_file}
|
echo "{{ user }} ALL = (root) NOPASSWD: {{ alias }}" >> ${sudo_file}
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue