From b388168318436000f7b01cc0c154881d26f61f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 15 Jul 2019 23:47:03 +0300 Subject: [PATCH] Get rid of sudo / running as root --- Makefile | 10 ++++++++++ ethermess.py | 6 +++++- test.sh | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e1692a0..0c13a6f 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,16 @@ install: $(BINS) $(LIBEXECS) mkdir -p $(DESTDIR)$(LIBEXECDIR) install $(BINS) $(DESTDIR)$(BINDIR) install $(LIBEXECS) $(DESTDIR)$(LIBEXECDIR) + @echo + @echo '--------------------------------------------------------------------------------' + @echo 'To finish the installation, set the CAP_NET_RAW on $(LIBEXECDIR)/ethermess-backend with' + @echo + @echo ' # setcap CAP_NET_RAW=ep $(LIBEXECDIR)/ethermess-backend' + @echo + @echo 'ethermess-backend needs to be able to create a raw ethernet packet socket, which' + @echo 'is a privileged operation. CAP_NET_RAW allows it to be done without root' + @echo 'privileges.' + @echo '--------------------------------------------------------------------------------' uninstall: cd $(DESTDIR)$(BINDIR) && rm $(BINS) diff --git a/ethermess.py b/ethermess.py index f044c94..9944cfc 100644 --- a/ethermess.py +++ b/ethermess.py @@ -516,9 +516,13 @@ def eventloop(proc): def main(): global own_nick, own_status + if len(sys.argv) != 3: + print("Usage: %s interface nick" % sys.argv[0], file=sys.stderr) + sys.exit(1) + _, interface, own_nick = sys.argv - proc = subprocess.Popen(['sudo', libexec_dir + '/ethermess-backend', interface], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = sys.stderr, bufsize = 0) + proc = subprocess.Popen([libexec_dir + '/ethermess-backend', interface], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = sys.stderr, bufsize = 0) # Tell the backend the status and nick own_status = statuses.available diff --git a/test.sh b/test.sh index eeda9a3..88c9490 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,4 @@ #!/bin/sh -sudo true && LIBEXECDIR=. make && +sudo setcap CAP_NET_RAW=ep ethermess-backend && ./ethermess "$@"