1. 名称使用 loongnix 而不是 loongnix-server 是由于部分脚本是通过 /etc/loongnix-release 的文件名去判断版本的,这样只 能匹配到 loongnix. 2. loongnix-server 修改LD_LIBRARY_PATH 之后,会导致 sudo ,su等命令失 效,只好在执行su命令的时候 export LD_LIBRARY_PATH=/usr/lib64, 保证su 命令成功, 试过 alias su='export LD_LIBRARY_PATH=/usr/lib64; su' 但是 py 需要 subprocess.run(cmd, shell=True) 才能读取这种环境变量,还是 全部替换了。
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
# -*- coding:utf-8 -*-
|
|
#############################################################################
|
|
# Portions Copyright (c) 2020 Huawei Technologies Co.,Ltd.
|
|
# Portions Copyright (c) 2007 Agendaless Consulting and Contributors.
|
|
#
|
|
# openGauss is licensed under Mulan PSL v2.
|
|
# You can use this software according to the terms
|
|
# and conditions of the Mulan PSL v2.
|
|
# You may obtain a copy of Mulan PSL v2 at:
|
|
#
|
|
# http://license.coscl.org.cn/MulanPSL2
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OF ANY KIND,
|
|
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
# See the Mulan PSL v2 for more details.
|
|
# Description : hide_password.py is utility for hiding password in ps commands.
|
|
#############################################################################
|
|
|
|
class HidePassword(object):
|
|
"""
|
|
hiding password in ps commands
|
|
"""
|
|
@staticmethod
|
|
def get_su_user_cmd_without_real_cmd(user):
|
|
"""
|
|
get su command and the command doesn't have real command
|
|
"""
|
|
return 'export LD_LIBRARY_PATH=/usr/lib64; su - %s -c "sh -"' % user
|
|
|
|
@staticmethod
|
|
def get_su_cmd_for_hide_password(cmd, user):
|
|
"""
|
|
get su command, and the command has been hidden the password
|
|
"""
|
|
su_command = HidePassword.get_su_user_cmd_without_real_cmd(user)
|
|
return 'echo %s | %s' % (cmd, su_command)
|