Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions problems running snmpsim as root #164

Open
e107steved opened this issue Jul 12, 2021 · 0 comments
Open

Permissions problems running snmpsim as root #164

e107steved opened this issue Jul 12, 2021 · 0 comments

Comments

@e107steved
Copy link

Environment: Debian Buster (on Raspberry Pi)
Running snmpsim as root (so that I can attach to port 161) using sudo, so created a non-privileged user to run the listener.
Any directory or file created (in /tmp) at startup is given root-only permissions; so access attempts by the non-privileged user fail.
The workaround is to open another console after starting snmpsim, to firstly extend the permissions on /tmp/snmpsim to 'all', and secondly to delete the root-created data files so that they are recreated by the non-privileged user. (For the second case, likely that extending permissions on the files would also work).
I've made some really nasty additions to the code to deal with this for my use case:
a) in snmpsimd.py, around line 835:
if not os.path.exists(confdir.cache):
try:
os.makedirs(confdir.cache)
## Added - change permissions of temporary directory
os.chmod(confdir.cache, 0o777)
except OSError:
log.error('failed to create cache directory "%s": %s' % (confdir.cache, sys.exc_info()[1]))
sys.exit(-1)
else:
log.info('Cache directory "%s" created' % confdir.cache)

b) In snmpsim\record\search\data.py (around line 158) I've extended permissions:
log.msg('...%d entries indexed' % lineNo)
## Added - change permissions of temporary directory
## - but bodge because '.db' appended to the file name we store
dbFileName = self.__dbFile + '.db'
log.msg("Change permissions on %s" % (dbFileName))
os.chmod(dbFileName, 0o777)

A 'proper' solution would, I suggest, need to just add permissions to the non-privileged user, or implement some other solution (which might involve telling me what I've done wrong!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant