Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nyanpasu-service安装失败 #1864

Open
6 tasks done
ValeriaXYN opened this issue Oct 23, 2024 · 15 comments
Open
6 tasks done

nyanpasu-service安装失败 #1864

ValeriaXYN opened this issue Oct 23, 2024 · 15 comments
Labels
C: Backend T: Bug Something isn't working

Comments

@ValeriaXYN
Copy link

ValeriaXYN commented Oct 23, 2024

复现步骤 / 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_DATA_DIR>
--nyanpasu-config-dir <NYANPASU_CONFIG_DIR>
--nyanpasu-app-dir <NYANPASU_APP_DIR>

Usage: nyanpasu-service.exe install --user --nyanpasu-data-dir <NYANPASU_DATA_DIR> --nyanpasu-config-dir <NYANPASU_CONFIG_DIR> --nyanpasu-app-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: 1a0e047
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

  • 如果您有足够的时间和能力,并愿意为此提交 PR,请勾上此复选框 / Pull request is welcome. Check this if you want to start a pull request
  • 您已知悉如果没有提供正确的系统信息,以及日志,您的 Issue 会直接被关闭 / You have known that if you don't provide correct system information and logs, your issue will be closed directly
  • 您已仔细查看并知情 Q&AFAQ 中的内容 / You have read and understood the contents of Q&A and FAQ
  • 您已搜索过 Issue Tracker,没有找到类似内容 / I have searched on Issue Tracker, No duplicate or related open issue has been found
  • 您确保这个 Issue 只提及一个问题。如果您有多个问题报告,烦请发起多个 Issue / Ensure there is only one bug report in this issue. Please make multiply issue for multiply bugs
  • 您确保已使用最新 Pre-release 版本测试,并且该问题在最新 Pre-release 版本中并未解决 / This bug have not solved in latest Pre-release version
@ValeriaXYN ValeriaXYN added S: Untriaged T: Bug Something isn't working labels Oct 23, 2024
@ValeriaXYN
Copy link
Author

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

@MNDIA
Copy link
Contributor

MNDIA commented Oct 23, 2024

./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
Copy link
Contributor

MNDIA commented Oct 23, 2024

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
Copy link
Author

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

@greenhat616
Copy link
Collaborator

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
Copy link
Collaborator

By the way, do you instal the winsw globally?

@MNDIA
Copy link
Contributor

MNDIA commented Oct 23, 2024

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

@ValeriaXYN
Copy link
Author

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
Copy link
Contributor

MNDIA commented Oct 23, 2024

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Contributor

MNDIA commented Oct 24, 2024

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
Copy link
Collaborator

greenhat616 commented Oct 24, 2024

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.

greenhat616 added a commit that referenced this issue Oct 26, 2024
…to mihomo limitation (#1866)

[1]#1862 Fix DNS policy order for mihomo
1.  Just don't touch lua for mihomo core. JS processing can maintain dictionary order.
This way, at least for now, it works fine when users are not using their own lua for processing.
2.  Preserve todo for lua defects

[2]#1819 Support group hidden display for mihomo
1.   `hidden` wasn't working.
2.   The `hidden` decision should be present at all times, so fixed the logic hole

[3]#1864 Fix one-click installation service on windows
1.  `wmic` utility may be deprecated or not installed in newer versions of Windows



Solved some very critical usage issues,  it's time to update a release. Please point out if anything is inappropriate


COMMIT HISTORY:

* Ditch lua's default processing, switch to js

* prettier

* Fix hidden logic when deferredProxiesFilter doesn't exist

* Fix issue with getting current user SID on Windows

* Keep todo markfor the root cause of the problem

* Add fallback for new version of windows

* Keep the sid method and fix it in the upstream

* chore: correct fronend code styles

---------

Co-authored-by: Jonson Petard <41122242+greenhat616@users.noreply.github.com>
@lanterner3054
Copy link

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

@3gf8jv4dv
Copy link
Contributor

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Backend T: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants