libnyanpasu / clash-nyanpasu

Clash Nyanpasu~(∠・ω< )⌒☆​
https://nyanpasu.elaina.moe
GNU General Public License v3.0
9.29k stars 581 forks source link

nyanpasu-service安装失败 #1864

Open ValeriaXYN opened 1 week ago

ValeriaXYN commented 1 week ago

复现步骤 / Step to reproduce

以管理员身份打开PowerShell,输入 cd "\?\C:\Program Files (x86)\Clash Nyanpasu" ./nyanpasu-service install

预期行为 / Expected behavior

nyanpasu-service安装成功

实际行为 / Actual behavior

错误如下: PS C:\WINDOWS\system32> cd "\?\C:\Program Files (x86)\Clash Nyanpasu" PS Microsoft.PowerShell.Core\FileSystem::\?\C:\Program Files (x86)\Clash Nyanpasu> ./nyanpasu-service install error: the following required arguments were not provided: --user --nyanpasu-data-dir --nyanpasu-config-dir --nyanpasu-app-dir

Usage: nyanpasu-service.exe install --user --nyanpasu-data-dir --nyanpasu-config-dir --nyanpasu-app-dir

For more information, try '--help'.

应用日志 / App logs

No response

备注 / Addition details

在1.6.0版本更新之前可以成功安装服务模式,自从1.6.0版本更新之后就无法安装服务模式了

环境信息 / Environment information

----------- System ----------- OS: Windows 11 Home China 26100 Arch: x86 ----------- Device ----------- CPU: 13th Gen Intel(R) Core(TM) i7-13700H @ 2.40GHz x 20 Memory: 15.64 GiB ----------- Core ----------- mihomo: Mihomo Meta v1.18.9 windows 386 with go1.23.1 Sun Sep 29 09:46:29 UTC 2024 Use tags: with_gvisor clash-rs-alpha: clash-rs 0.6.0 mihomo-alpha: Mihomo Meta alpha-3e966e8 windows 386 with go1.23.2 Mon Oct 21 01:46:25 UTC 2024 Use tags: with_gvisor clash-rs: clash-rs 0.6.0 clash: Clash n2023-09-05-gdcc8d87 windows 386 with go1.21.0 Tue Sep 5 14:31:55 UTC 2023 ----------- Build Info ----------- App Name: clash-nyanpasu App Version: 0.1.0 Pkg Version: 2.0.0-alpha+1a0e047 Commit Hash: 1a0e047f962803daed1d626ade8f4e783af16ab2 Commit Author: github-actions[bot] Commit Date: 2024-10-22T22:21:20.000Z Build Date: 2024-10-23T00:46:46.413Z Build Profile: Nightly Build Platform: i686-pc-windows-msvc Rustc Version: rustc 1.84.0-nightly (439284741 2024-10-21) Llvm Version: 19.1

自查步骤 / Verify steps

ValeriaXYN commented 1 week ago

现在暂时的解决方案是卸载后回退到1.5.1版本(1.6.0更新前的最后一个版本),目前服务模式运行正常。

MNDIA commented 1 week ago
./nyanpasu-service install --user %USERNAME% --nyanpasu-data-dir "C:\Users\%USERNAME%\AppData\Local\Clash Nyanpasu\data" --nyanpasu-config-dir "C:\Users\%USERNAME%\AppData\Roaming\Clash Nyanpasu\config" --nyanpasu-app-dir "D:\NetWork\ClashNyan"

An example of use. Please change the directory of your own @ValeriaXYN

MNDIA commented 1 week ago

Not being able to auto-install is indeed a flaw, probably related to limitations of rust and windows group policy. a similar project clash_verge is able to auto-install, might be worth a reference

ValeriaXYN commented 1 week ago

Thank you very much! Now the service mode is running.

greenhat616 commented 1 week ago

Not being able to auto-install is indeed a flaw, probably related to limitations of rust and windows group policy. a similar project clash_verge is able to auto-install, might be worth a reference

I have no idea about the failures of service automatic installation on Windows.

The backend logic is same with the manual prompt, although the installation prompt in 1.6.1 is wrong.

greenhat616 commented 1 week ago

By the way, do you instal the winsw globally?

MNDIA commented 1 week ago

nop, windows doesn't include winsw by default. Does nyanpasu need winsw as pre-dependency?

ValeriaXYN commented 1 week ago

Not being able to auto-install is indeed a flaw, probably related to limitations of rust and windows group policy. a similar project clash_verge is able to auto-install, might be worth a reference

I have no idea about the failures of service automatic installation on Windows.

The backend logic is same with the manual prompt, although the installation prompt in 1.6.1 is wrong.

屏幕截图 2024-09-19 112230 I don't know, it just looked like this

MNDIA commented 1 week ago

image 🎉Congratulations: the problem has been pinpointed to the user variable in the get_service_install_args function in backend\tauri\src\core\service\control.rs When user is changed to a fixed string everything works without any errors: one-click auto-installation image

greenhat616 commented 1 week ago

nop, windows doesn't include winsw by default. Does nyanpasu need winsw as pre-dependency?

No. The upstream service manager deps prefers winsw, and sc.exe as fallback

greenhat616 commented 1 week ago

image

image

Congratulations: the problem has been pinpointed to the user variable in the get_service_install_args function in backend\tauri\src\core\service\control.rs

When user is changed to a fixed string everything works without any errors: one-click auto-installation

image

So, the syscall fails with errors?

Now, the user in windows do nothing. The DACL in windows is too complex to generate from our default preferences. We are planned to authorize the named pipe with RW permission only for the specified user.

MNDIA commented 1 week ago

at the upstream source code

pub async fn get_current_user_sid() -> IoResult<String> {
    let output = Command::new("cmd")
        .args(["/C", "wmic useraccount where name='%username%' get sid"])
        .creation_flags(0x0800_0000) // CREATE_NO_WINDOW
        .output()
        .await
        .map_err(|e| {
            IoError::new(
                IoErrorKind::Other,
                format!("Failed to execute command: {}", e),
            )
        })?;

    if !output.status.success() {
        return Err(IoError::new(IoErrorKind::Other, "Command failed"));
    }

    let output_str = String::from_utf8_lossy(&output.stdout);

    let lines: Vec<&str> = output_str.lines().collect();
    if lines.len() < 2 {
        return Err(IoError::new(IoErrorKind::Other, "Unexpected output format"));
    }

    let sid = lines[1].trim().to_string();
    Ok(sid)
}

it is equivalent to the cmd command

wmic useraccount where name='%username%' get sid

But the wmic utility may be deprecated or not installed in newer versions of Windows, which is where the problem occurs. image I tested %USERNAME% and it's perfectly fine to install service mode, so there's no need to use the sid form %username%(At least on newer versions of windows) image

greenhat616 commented 1 week ago

at the upstream source code


pub async fn get_current_user_sid() -> IoResult<String> {

    let output = Command::new("cmd")

        .args(["/C", "wmic useraccount where name='%username%' get sid"])

        .creation_flags(0x0800_0000) // CREATE_NO_WINDOW

        .output()

        .await

        .map_err(|e| {

            IoError::new(

                IoErrorKind::Other,

                format!("Failed to execute command: {}", e),

            )

        })?;

    if !output.status.success() {

        return Err(IoError::new(IoErrorKind::Other, "Command failed"));

    }

    let output_str = String::from_utf8_lossy(&output.stdout);

    let lines: Vec<&str> = output_str.lines().collect();

    if lines.len() < 2 {

        return Err(IoError::new(IoErrorKind::Other, "Unexpected output format"));

    }

    let sid = lines[1].trim().to_string();

    Ok(sid)

}

it is equivalent to the cmd command


wmic useraccount where name='%username%' get sid

But the wmic utility may be deprecated or not installed in newer versions of Windows, which is where the problem occurs.

image

I tested %USERNAME% and it's perfectly fine to install service mode, so there's no need to use the sid form %username%(At least on newer versions of windows)

image

The user do nothing now.

You can check the original code here: https://github.com/libnyanpasu/nyanpasu-service/blob/main/nyanpasu_ipc/src/server/mod.rs

I don't have a good idea to generate the sdsf correctly, so I grant public access for all users now.

Because of the unimplementation of the permissions, so Sids or usernames(Domain/User is better) are both acceptable.

lanterner3054 commented 1 week ago

我不太懂这方面,但我的nyanpasu存在相同的问题,我具体应该怎么做?

3gf8jv4dv commented 1 week ago

我不太懂这方面,但我的nyanpasu存在相同的问题,我具体应该怎么做?

@lanterner3054 Try using the latest development version, which should already have the fix. You can see if this resolves the issue.