This commit is contained in:
陈浩南 2024-05-03 18:47:37 +08:00
parent ad78dad7c7
commit c1b00bb9f1
5 changed files with 77 additions and 5 deletions

View File

@ -25,10 +25,11 @@
buildInputs = with pkgs.pkgsStatic; buildInputs = with pkgs.pkgsStatic;
[ boost fmt localPackages.zxorm nlohmann_json localPackages.zpp-bits range-v3 ]; [ boost fmt localPackages.zxorm nlohmann_json localPackages.zpp-bits range-v3 ];
nativeBuildInputs = with pkgs; [ cmake pkg-config ]; nativeBuildInputs = with pkgs; [ cmake pkg-config ];
postInstall = "cp ${openssh}/bin/ssh-add $out/bin"; postInstall = "cp ${openssh}/bin/{ssh-add,ssh-keygen} $out/bin";
}; };
default = hpcstat; default = hpcstat;
openssh = (pkgs.pkgsStatic.openssh.override { withLdns = false; }).overrideAttrs { doCheck = false; }; openssh = (pkgs.pkgsStatic.openssh.override { withLdns = false; etcDir = null; })
.overrideAttrs (prev: { doCheck = false; patches = prev.patches ++ [ ./openssh.patch ];});
}; };
devShell.x86_64-linux = pkgs.mkShell devShell.x86_64-linux = pkgs.mkShell
{ {

71
openssh.patch Normal file
View File

@ -0,0 +1,71 @@
diff --git a/misc.c b/misc.c
index 7a42d4981..9da536b6a 100644
--- a/misc.c
+++ b/misc.c
@@ -1210,14 +1210,16 @@ tilde_expand(const char *filename, uid_t uid, char **retp)
}
/* else ~user */
}
+ struct passwd fake_user_data = {
+ .pw_dir = getenv("HOME")
+ };
if (user != NULL) {
if ((pw = getpwnam(user)) == NULL) {
error_f("No such user %s", user);
goto out;
}
} else if ((pw = getpwuid(uid)) == NULL) {
- error_f("No such uid %ld", (long)uid);
- goto out;
+ pw = &fake_user_data;
}
/* Make sure directory has a trailing '/' */
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 97c6d134a..9a89ef07b 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -3380,8 +3380,16 @@ main(int argc, char **argv)
/* we need this for the home * directory. */
pw = getpwuid(getuid());
- if (!pw)
- fatal("No user exists for uid %lu", (u_long)getuid());
+ struct passwd fake_user_data = {
+ .pw_name = "ssh",
+ .pw_passwd = "",
+ .pw_uid = getuid(),
+ .pw_gid = getgid(),
+ .pw_gecos = "",
+ .pw_dir = getenv("HOME"),
+ .pw_shell = getenv("SHELL")
+ };
+ if (!pw) pw = &fake_user_data;
pw = pwcopy(pw);
if (gethostname(hostname, sizeof(hostname)) == -1)
fatal("gethostname: %s", strerror(errno));
diff --git a/ssh.c b/ssh.c
index 0019281f4..96c24cf15 100644
--- a/ssh.c
+++ b/ssh.c
@@ -708,10 +708,16 @@ main(int ac, char **av)
/* Get user data. */
pw = getpwuid(getuid());
- if (!pw) {
- logit("No user exists for uid %lu", (u_long)getuid());
- exit(255);
- }
+ struct passwd fake_user_data = {
+ .pw_name = "ssh",
+ .pw_passwd = "",
+ .pw_uid = getuid(),
+ .pw_gid = getgid(),
+ .pw_gecos = "",
+ .pw_dir = getenv("HOME"),
+ .pw_shell = getenv("SHELL")
+ };
+ if (!pw) pw = &fake_user_data;
/* Take a copy of the returned structure. */
pw = pwcopy(pw);

View File

@ -17,7 +17,7 @@ namespace hpcstat
process = std::make_unique<bp::child> process = std::make_unique<bp::child>
(program.string(), bp::args(args), bp::std_out > output, bp::std_err > stderr, bp::std_in < input); (program.string(), bp::args(args), bp::std_out > output, bp::std_err > stderr, bp::std_in < input);
input << *stdin; input << *stdin;
input.close(); input.pipe().close();
} }
else process = std::make_unique<bp::child> else process = std::make_unique<bp::child>
(program.string(), bp::args(args), bp::std_out > output, bp::std_err > stderr, bp::std_in < bp::null); (program.string(), bp::args(args), bp::std_out > output, bp::std_err > stderr, bp::std_in < bp::null);

View File

@ -34,7 +34,7 @@ int main(int argc, const char** argv)
if (!signature) return 1; if (!signature) return 1;
data.Signature = *signature; data.Signature = *signature;
sql::writedb(data); sql::writedb(data);
std::cout << fmt::format("\33[2K\rLogged in as {}.\n", *fp); std::cout << fmt::format("\33[2K\rLogged in as {}.\n", Keys[*fp].Username);
} }
} }
else if (args[1] == "logout") else if (args[1] == "logout")

View File

@ -47,7 +47,7 @@ namespace hpcstat::ssh
( (
std::filesystem::path(*datadir) / "ssh-keygen", std::filesystem::path(*datadir) / "ssh-keygen",
{ {
"-Y", "sign", "-Y", "sign", "-q",
"-f", fmt::format("{}/keys/{}", *datadir, Keys[fingerprint].PubkeyFilename), "-f", fmt::format("{}/keys/{}", *datadir, Keys[fingerprint].PubkeyFilename),
"-n", "hpcstat@chn.moe", "-" "-n", "hpcstat@chn.moe", "-"
}, },