One telnet client at a time and ask for a password (it's 'xv6').

Hopefully this is enough to prevent all the random connections to josmp.
上级 36c8e1dc
...@@ -98,6 +98,7 @@ UPROGS= \ ...@@ -98,6 +98,7 @@ UPROGS= \
_forkexectree \ _forkexectree \
_forkexecbench \ _forkexecbench \
_forktree \ _forktree \
_login \
_ls \ _ls \
_mapbench \ _mapbench \
_maptest \ _maptest \
......
#include "types.h"
#include "user.h"
static const char *
readpw(void)
{
static char pw[64];
for (int i = 0; i < sizeof(pw); i++) {
int r = read(0, &pw[i], 1);
if (r != 1)
return 0;
if (pw[i] == '\r') {
pw[i] = 0;
} else if (pw[i] == '\n') {
pw[i] = 0;
return pw;
}
}
return 0;
}
int
main(void)
{
const char *pw;
printf(1, "password: ");
pw = readpw();
if (pw && !strcmp(pw, "xv6")) {
static const char *argv[] = { "/sh", 0 };
exec(argv[0], argv);
}
exit();
}
...@@ -46,16 +46,18 @@ main(void) ...@@ -46,16 +46,18 @@ main(void)
continue; continue;
} }
if (pid == 0) { if (pid == 0) {
static const char *argv[] = { "sh", 0 }; static const char *argv[] = { "/login", 0 };
close(0); close(0);
close(1); close(1);
close(2); close(2);
dup(ss); dup(ss);
dup(ss); dup(ss);
dup(ss); dup(ss);
exec("sh", argv); exec(argv[0], argv);
exit(); exit();
} }
close(ss); close(ss);
wait();
printf(1, "telnetd: connection closed\n");
} }
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论