comparison web/secure.py @ 226:da769023bf08

Fix race setting umask
author Matt Johnston <matt@ucc.asn.au>
date Sat, 28 Feb 2015 00:14:02 +0800
parents 59379b2bd056
children f7261dd970da
comparison
equal deleted inserted replaced
225:f2838211f6ec 226:da769023bf08
54 return False 54 return False
55 55
56 def setup_csrf(): 56 def setup_csrf():
57 NONCE_SIZE=16 57 NONCE_SIZE=16
58 global _csrf_fd, _csrf_key 58 global _csrf_fd, _csrf_key
59 _csrf_fd = open('%s/csrf.dat' % config.DATA_PATH, 'r+') 59 _csrf_fd = os.fdopen(os.open('%s/csrf.dat' % config.DATA_PATH, os.O_RDWR | os.O_CREAT, 0600), 'r+')
60 60
61 try: 61 try:
62 fcntl.lockf(_csrf_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) 62 fcntl.lockf(_csrf_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
63 os.fchmod(_csrf_fd.fileno(), 0600)
64 _csrf_fd.write("%d-%s" % (os.getpid(), binascii.hexlify(os.urandom(NONCE_SIZE)))) 63 _csrf_fd.write("%d-%s" % (os.getpid(), binascii.hexlify(os.urandom(NONCE_SIZE))))
65 _csrf_fd.flush() 64 _csrf_fd.flush()
66 _csrf_fd.seek(0) 65 _csrf_fd.seek(0)
67 except IOError: 66 except IOError:
68 pass 67 pass