mirror of
https://github.com/zhaojh329/rtty.git
synced 2026-02-27 09:53:17 +08:00
refactor: password not required for execute command
Usually, commands are executed in batches on multiple devices, but the password for each device is different. Therefore, the password parameter is removed. Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
+2
-21
@@ -44,24 +44,6 @@ static LIST_HEAD(task_pending);
|
|||||||
|
|
||||||
static void run_task(struct task *t);
|
static void run_task(struct task *t);
|
||||||
|
|
||||||
/* For execute command */
|
|
||||||
static bool login_test(const char *username, const char *password)
|
|
||||||
{
|
|
||||||
struct spwd *sp;
|
|
||||||
|
|
||||||
if (!username || *username == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sp = getspnam(username);
|
|
||||||
if (!sp || !sp->sp_pwdp[1])
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!password)
|
|
||||||
password = "";
|
|
||||||
|
|
||||||
return !strcmp(crypt(password, sp->sp_pwdp), sp->sp_pwdp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *cmd_lookup(const char *cmd)
|
static const char *cmd_lookup(const char *cmd)
|
||||||
{
|
{
|
||||||
struct stat s;
|
struct stat s;
|
||||||
@@ -342,15 +324,14 @@ static void add_task(struct rtty *rtty, const char *token, uid_t uid, const char
|
|||||||
void run_command(struct rtty *rtty, const char *data)
|
void run_command(struct rtty *rtty, const char *data)
|
||||||
{
|
{
|
||||||
const char *username = data;
|
const char *username = data;
|
||||||
const char *password = username + strlen(username) + 1;
|
const char *cmd = username + strlen(username) + 1;
|
||||||
const char *cmd = password + strlen(password) + 1;
|
|
||||||
const char *token = cmd + strlen(cmd) + 1;
|
const char *token = cmd + strlen(cmd) + 1;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
data = token + strlen(token) + 1;
|
data = token + strlen(token) + 1;
|
||||||
|
|
||||||
if (!username[0] || !login_test(username, password)) {
|
if (!username[0]) {
|
||||||
err = RTTY_CMD_ERR_PERMIT;
|
err = RTTY_CMD_ERR_PERMIT;
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,6 @@ port=5913
|
|||||||
|
|
||||||
# Your linux device's username and password
|
# Your linux device's username and password
|
||||||
username="test"
|
username="test"
|
||||||
password="test"
|
|
||||||
|
|
||||||
# Default wait 30s.
|
# Default wait 30s.
|
||||||
# If you don't care about the results, you can set it to 0, that is, don't wait
|
# If you don't care about the results, you can set it to 0, that is, don't wait
|
||||||
@@ -17,7 +16,7 @@ cmd="echo"
|
|||||||
params='["Hello, Rtty"]'
|
params='["Hello, Rtty"]'
|
||||||
|
|
||||||
|
|
||||||
resp=$(curl "http://$host:$port/cmd/$devid?wait=$wait" -d "{\"cmd\":\"$cmd\", \"params\": $params, \"username\": \"$username\", \"password\": \"$password\"}" 2>/dev/null)
|
resp=$(curl "http://$host:$port/cmd/$devid?wait=$wait" -d "{\"cmd\":\"$cmd\", \"params\": $params, \"username\": \"$username\"}" 2>/dev/null)
|
||||||
|
|
||||||
[ "$wait" = "0" ] && exit 0
|
[ "$wait" = "0" ] && exit 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user