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:
Jianhui Zhao
2025-06-11 11:04:49 +08:00
parent db79642ae8
commit 1cbe223d79
2 changed files with 3 additions and 23 deletions
+2 -21
View File
@@ -44,24 +44,6 @@ static LIST_HEAD(task_pending);
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)
{
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)
{
const char *username = data;
const char *password = username + strlen(username) + 1;
const char *cmd = password + strlen(password) + 1;
const char *cmd = username + strlen(username) + 1;
const char *token = cmd + strlen(cmd) + 1;
struct passwd *pw;
int err = 0;
data = token + strlen(token) + 1;
if (!username[0] || !login_test(username, password)) {
if (!username[0]) {
err = RTTY_CMD_ERR_PERMIT;
goto ERR;
}
+1 -2
View File
@@ -6,7 +6,6 @@ port=5913
# Your linux device's username and password
username="test"
password="test"
# Default wait 30s.
# 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"]'
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