!351 新增基线扫 描项'07管理员修改普通用户密码'

Merge pull request !351 from a-alpha/alpha-dev
This commit is contained in:
a-alpha 2023-11-16 07:33:44 +00:00 committed by Gitee
commit 82f239f865
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,88 @@
import os
import sys
################################
# 常量
# for get_env_lang()
STR_GET_ENV_LANG_ZH = "语言环境为中文"
STR_GET_ENV_LANG_EN = "语言环境为英文"
STR_GET_ENV_LANG_UNKNOW = "语言环境未知"
################################
# 环境检查函数
def get_env_lang():
# lang = os.getenv("LANG")
# if lang.startswith("zh"):
# return STR_GET_ENV_LANG_ZH
# elif lang.startswith("en"):
# return STR_GET_ENV_LANG_EN
# else:
# return STR_GET_ENV_LANG_UNKNOW
#
if arg_lang == "zh":
return STR_GET_ENV_LANG_ZH
elif arg_lang == "en":
return STR_GET_ENV_LANG_EN
else:
return STR_GET_ENV_LANG_UNKNOW
def is_root():
if os.geteuid() == 0:
print(STR_IS_ROOT_TRUE)
return True
else:
print(STR_IS_ROOT_FALSE)
return False
################################
# 辅助函数
def l_print(zh_str, en_str) :
if STR_GET_ENV_LANG_ZH == get_env_lang() :
print(zh_str);
else :
print(en_str);
################################
# 功能函数
def admin_user():
cmd1= 'echo {} | su -c "userdel -rf test1 > /dev/null 2>&1"'.format(root_passwd)
os.system(cmd1)
cmd2= 'echo {} | su -c "useradd test1"'.format(root_passwd)
os.system(cmd2)
output = os.popen('passwd test1 2>&1').read().strip()
if "不能查看" in output :
l_print("[OK] 测试通过",
"[OK] pass")
else:
l_print("[ERROR] 测试未通过",
"[ERROR] fail")
################################
# main
#接收传参
root_passwd = ''
def process_arguments():
args = sys.argv[1:]
if "--rootpwd" in args:
index = args.index("--rootpwd")
if index + 1 < len(args):
return args[index + 1]
return None
if __name__ == "__main__":
if len(sys.argv)>1:
arg_lang = sys.argv[1]
else:
arg_lang = 'zh'
root_passwd = process_arguments()
admin_user()
exit(0)

View File

@ -0,0 +1,26 @@
FormatVer: 20230623
Id: admin_user
Belong: baseline
SiteInfo:
Name: 07管理员修改普通用户密码
Power :
SiteRequests:
Implement:
ImArray:
- Inter : python3
onterArgs :
Exec : 07管理员修改普通用户密码.py
Args :
- zh
- --rootpwd
- ${ROOTPASSWORD}
Inter:
- "[ERROR]"
Condition: None
RepairArgs:
- Inter : python3
InterArgs :
Exec :
Args :
RepairPower: #root # root权限或者普通用户权限