From 0e252039e1af47fa1bf62a3d52f8fcadd78d82d9 Mon Sep 17 00:00:00 2001 From: elie Date: Sun, 1 Feb 2015 21:14:42 +0000 Subject: secure boots file creation --- pysnmp/entity/engine.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pysnmp/entity/engine.py b/pysnmp/entity/engine.py index 8cf5d05..ecc0aa5 100644 --- a/pysnmp/entity/engine.py +++ b/pysnmp/entity/engine.py @@ -1,5 +1,6 @@ # SNMP engine import os +import sys import tempfile from pysnmp.proto.rfc3412 import MsgAndPduDispatcher from pysnmp.proto.mpmod.rfc2576 import SnmpV1MessageProcessingModel, \ @@ -87,11 +88,14 @@ class SnmpEngine: snmpEngineBoots.syntax = snmpEngineBoots.syntax.clone(1) try: - open(f, 'w').write(snmpEngineBoots.syntax.prettyPrint()) + fd, fn = tempfile.mkstemp(dir=persistentPath) + os.write(fd, snmpEngineBoots.syntax.prettyPrint()) + os.close(fd) + os.rename(fn, f) except: - pass - - debug.logger & debug.flagApp and debug.logger('SnmpEngine: stored SNMP Engine Boots: %s' % snmpEngineBoots.syntax.prettyPrint()) + debug.logger & debug.flagApp and debug.logger('SnmpEngine: could not stored SNMP Engine Boots: %s' % sys.exc_info()[1]) + else: + debug.logger & debug.flagApp and debug.logger('SnmpEngine: stored SNMP Engine Boots: %s' % snmpEngineBoots.syntax.prettyPrint()) # Transport dispatcher bindings -- cgit v1.2.1