etingof / snmpfwd

SNMP Proxy Forwarder
http://snmplabs.com/snmpfwd/
BSD 2-Clause "Simplified" License
67 stars 18 forks source link

No errors shown if run as root #42

Open pmorch opened 4 years ago

pmorch commented 4 years ago

Not knowing any better, I tried running snmpfwd-* as root.

# snmpfwd-server.py --config-file=server.conf --logging-method=stdout --log-level=debug

The process exited immediately with error code 1 and no output what so ever, which was a little frurstrating. "What am I doing wrong?"

After this patch:

# diff -u bin/snmpfwd-server.py.orig bin/snmpfwd-server.py
--- bin/snmpfwd-server.py.orig  2019-12-04 04:13:34.191820738 +0100
+++ bin/snmpfwd-server.py   2019-12-04 04:16:58.710370002 +0100
@@ -986,7 +986,7 @@

     except Exception:
         for line in traceback.format_exception(*sys.exc_info()):
-            log.error(line.replace('\n', ';'))
+            print(line.replace('\n', ';'))

     log.info('process terminated')

I saw:

# /snmpfwd-server.py --config-file=server.conf --logging-method=stdout --log-level=debug
Traceback (most recent call last):;
  File "/root/snmpfwd/bin/snmpfwd-server.py", line 981, in <module>;    main();
  File "/root/snmpfwd/bin/snmpfwd-server.py", line 556, in main;    with daemon.PrivilegesOf(procUser, procGroup):;
  File "/root/snmpfwd/local/lib/python2.7/site-packages/snmpfwd/daemon.py", line 104, in __enter__;    raise error.SnmpfwdError('Must drop privileges to a non-privileged user&group');
SnmpfwdError: Must drop privileges to a non-privileged user&group;

Which allowed me to discover that I needed to run it as non-root and things started working.

It would be better not to have to patch the executable to see the error.

tripsankur commented 4 years ago

@pmorch From where did you get the Patch? I have faced similar issues, but for me, there is no error itself. The process will just exit. I have been trying to run the server on privileged port (162) via root, but haven't been able to. Have you faced something similar ?

etingof commented 4 years ago

That's surprising that you do not get anything on stderr. I assume it did not go into a logfile/syslog.

Meanwhile, you can run daemons as root if you make them dropping superuser privileges later on.

pmorch commented 4 years ago

Thanks for your reply @etingof. With --logging-method=stdout I'm assuming that it should go to STDOUT. I didn't think to check syslog and I don't know what other logfiles to check. Regardless, with --logging-method=stdout logging should be directly visible in the terminal, right? It wasn't.