diff options
author | Larkin Nickle <me@larbob.org> | 2019-09-28 16:31:43 -0400 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-28 22:37:14 +0200 |
commit | ab67f745881749eb1f6bca98ae3bcc511daaa884 (patch) | |
tree | e0b0dfa1827e5e7dffd0bdaa62b99c33c9fc2e46 /Servers/TelnetServer | |
parent | 801fe7beacc751b01de48b7883d418dcc3507a50 (diff) | |
download | serenity-ab67f745881749eb1f6bca98ae3bcc511daaa884.zip |
TelnetServer: Accept arbitrary command with -c
For example, this allows you to do something like
`TelnetServer -c /usr/bin/nyancat` to have the TelnetServer run
`/usr/bin/nyancat` instead of `/bin/Shell`.
Diffstat (limited to 'Servers/TelnetServer')
-rw-r--r-- | Servers/TelnetServer/main.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Servers/TelnetServer/main.cpp b/Servers/TelnetServer/main.cpp index dee7efb29c..9d47c28df1 100644 --- a/Servers/TelnetServer/main.cpp +++ b/Servers/TelnetServer/main.cpp @@ -85,13 +85,17 @@ int main(int argc, char** argv) int opt; u16 port = 23; - while ((opt = getopt(argc, argv, "p:")) != -1) { + const char* command = ""; + while ((opt = getopt(argc, argv, "p:c:")) != -1) { switch (opt) { case 'p': port = atoi(optarg); break; + case 'c': + command = optarg; + break; default: - fprintf(stderr, "Usage: %s [-p port]", argv[0]); + fprintf(stderr, "Usage: %s [-p port] [-c command]", argv[0]); exit(1); } } @@ -104,7 +108,7 @@ int main(int argc, char** argv) HashMap<int, NonnullRefPtr<Client>> clients; int next_id = 0; - server->on_ready_to_accept = [&next_id, &clients, &server] { + server->on_ready_to_accept = [&next_id, &clients, &server, command] { int id = next_id++; auto client_socket = server->accept(); @@ -120,7 +124,7 @@ int main(int argc, char** argv) return; } - run_command(ptm_fd, ""); + run_command(ptm_fd, command); auto client = Client::create(id, move(client_socket), ptm_fd); client->on_exit = [&clients, id] { clients.remove(id); }; |