summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHåkon Nessjøen <haakon.nessjoen@gmail.com>2011-02-27 15:09:56 +0100
committerHåkon Nessjøen <haakon.nessjoen@gmail.com>2011-02-27 15:09:56 +0100
commit9f9610327c6b5dd3f738b6dddcc77646376d9fd9 (patch)
tree6ed903e01267112bf521df01d3f871df8ab4fb51
parent5b786ccb2a21937fcc6e1a29167db47f1d78abb5 (diff)
downloadMAC-Telnet-9f9610327c6b5dd3f738b6dddcc77646376d9fd9.tar.gz
MAC-Telnet-9f9610327c6b5dd3f738b6dddcc77646376d9fd9.zip
Add foreground mode support for mactelnetd.
-rw-r--r--config/mactelnetd.users (renamed from mactelnetd.users)0
-rw-r--r--mactelnetd.c23
2 files changed, 15 insertions, 8 deletions
diff --git a/mactelnetd.users b/config/mactelnetd.users
index 7b215e1..7b215e1 100644
--- a/mactelnetd.users
+++ b/config/mactelnetd.users
diff --git a/mactelnetd.c b/mactelnetd.c
index 0654009..c2460f7 100644
--- a/mactelnetd.c
+++ b/mactelnetd.c
@@ -815,9 +815,13 @@ int main (int argc, char **argv) {
fd_set read_fds;
int c,optval = 1;
int print_help = 0;
+ int foreground = 0;
- while ((c = getopt(argc, argv, "nvh?")) != -1) {
+ while ((c = getopt(argc, argv, "fnvh?")) != -1) {
switch (c) {
+ case 'f':
+ foreground = 1;
+ break;
case 'n':
use_raw_socket = 1;
@@ -838,10 +842,11 @@ int main (int argc, char **argv) {
if (print_help) {
print_version();
- fprintf(stderr, "Usage: %s [-n] [-h]\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-f|-n|-h]\n", argv[0]);
if (print_help) {
fprintf(stderr, "\nParameters:\n");
+ fprintf(stderr, " -f Run process in foreground.\n");
fprintf(stderr, " -n Do not use broadcast packets. Just a tad less insecure.\n");
fprintf(stderr, " -h This help.\n");
fprintf(stderr, "\n");
@@ -849,17 +854,17 @@ int main (int argc, char **argv) {
return 1;
}
+ if (geteuid() != 0) {
+ fprintf(stderr, "You need to have root privileges to use %s.\n", argv[0]);
+ return 1;
+ }
+
/* Try to read user file */
read_userfile();
/* Seed randomizer */
srand(time(NULL));
- if (geteuid() != 0) {
- fprintf(stderr, "You need to have root privileges to use %s.\n", argv[0]);
- return 1;
- }
-
if (use_raw_socket) {
/* Transmit raw packets with this socket */
sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
@@ -922,7 +927,9 @@ int main (int argc, char **argv) {
setup_sockets();
- daemonize();
+ if (!foreground) {
+ daemonize();
+ }
openlog("mactelnetd", LOG_PID, LOG_DAEMON);