Get rid of sudo / running as root

This commit is contained in:
Juhani Krekelä 2019-07-15 23:47:03 +03:00
parent 7636dd1b10
commit b388168318
3 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -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

View File

@ -1,4 +1,4 @@
#!/bin/sh
sudo true &&
LIBEXECDIR=. make &&
sudo setcap CAP_NET_RAW=ep ethermess-backend &&
./ethermess "$@"