[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Start making stuff work on win32 -- much more work need...
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv16360/lib/mixminion
Modified Files:
ClientMain.py Common.py Crypto.py test.py
Log Message:
Start making stuff work on win32 -- much more work needed, but at least it builds and passes all but 5 tests
Index: ClientMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientMain.py,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- ClientMain.py 8 Jul 2003 19:13:50 -0000 1.96
+++ ClientMain.py 10 Jul 2003 20:01:30 -0000 1.97
@@ -34,7 +34,8 @@
UsageError, ceilDiv, createPrivateDir, isPrintingAscii, isSMTPMailbox, \
formatDate, formatFnameTime, formatTime, Lockfile, openUnique, \
previousMidnight, readFile, readPickled, readPossiblyGzippedFile, \
- secureDelete, stringContains, succeedingMidnight, tryUnlink, writeFile, \
+ replaceFile, secureDelete, stringContains, succeedingMidnight, tryUnlink,\
+ writeFile, \
writePickled
from mixminion.Crypto import sha1, ctr_crypt, trng
from mixminion.Config import ClientConfig, ConfigError
@@ -211,9 +212,9 @@
# Install the new directory
if gz:
- os.rename(fname, os.path.join(self.dir, "dir.gz"))
+ replaceFile(fname, os.path.join(self.dir, "dir.gz"))
else:
- os.rename(fname, os.path.join(self.dir, "dir"))
+ replaceFile(fname, os.path.join(self.dir, "dir"))
# And regenerate the cache.
self.rescan()
@@ -984,7 +985,7 @@
self._save(fn+"_tmp",
cPickle.dumps(self.keyring,1),
"KEYRING1", self.keyringPassword)
- os.rename(fn+"_tmp", fn)
+ replaceFile(fn+"_tmp", fn)
def getSURBKey(self, name="", create=0, password=None):
"""Return the key for a given SURB identity."""
Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- Common.py 8 Jul 2003 19:13:50 -0000 1.98
+++ Common.py 10 Jul 2003 20:01:30 -0000 1.99
@@ -21,7 +21,6 @@
import calendar
import cPickle
import errno
-import fcntl
import gzip
import os
import re
@@ -40,6 +39,13 @@
del Queue
del Empty
+O_BINARY = getattr(os, 'O_BINARY', 0)
+
+try:
+ import fcntl
+except ImportError:
+ fcntl = None
+
try:
import pwd, grp
except ImportError:
@@ -356,9 +362,10 @@
raise MixFatalError("Nonexistant file %s" % fn)
if not os.path.isfile(fn):
raise MixFatalError("%s is not a regular file" % fn)
- me = os.getuid()
+
if _CHECK_UID and st[stat.ST_UID] != me:
- ownerName = _uidToName( st[stat.ST_UID])
+ me = os.getuid()
+ ownerName = _uidToName(st[stat.ST_UID])
myName = _uidToName(me)
raise MixFilePermissionError(
"File %s is owned by %s, but Mixminion is running as %s"
@@ -391,8 +398,9 @@
0700. All of d's parents must not be writable or owned by anybody but
this uid and uid 0. If any of these conditions are unmet, raise
MixFatalErrror. Otherwise, return None."""
- me = os.getuid()
- trusted_uids = _TRUSTED_UIDS + [ me ]
+ if _CHECK_UID:
+ me = os.getuid()
+ trusted_uids = _TRUSTED_UIDS + [ me ]
if not os.path.isabs(d):
d = os.path.abspath(d)
@@ -468,6 +476,18 @@
#----------------------------------------------------------------------
# File helpers
+
+
+#DOCDOC
+if sys.platform == 'win32':
+ def replaceFile(f1, f2):
+ if os.path.exists(f2):
+ os.unlink(f2)
+ os.rename(f1, f2)
+else:
+ def replaceFile(f1, f2):
+ os.rename(f1, f2)
+
class AtomicFile:
"""Wrapper around open/write/rename to encapsulate writing to a temporary
file, then moving to the final filename on close.
@@ -489,7 +509,7 @@
def close(self):
"""Close the underlying file and replace the destination file."""
- os.rename(self.tmpname, self.fname)
+ replaceFile(self.tmpname, self.fname)
self.f.close()
self.f = None
@@ -531,7 +551,7 @@
if os.path.exists(tmpname): os.unlink(tmpname)
raise
- os.rename(tmpname, fn)
+ replaceFile(tmpname, fn)
def readPickled(fn):
"""Given the name of a file containing a pickled object, return the pickled
@@ -557,7 +577,7 @@
if os.path.exists(tmpname): os.unlink(tmpname)
raise
- os.rename(tmpname, fn)
+ replaceFile(tmpname, fn)
def tryUnlink(fname):
"""Try to remove the file named fname. If the file is erased, return 1.
@@ -623,7 +643,7 @@
if sz > len(_NILSTR):
_NILSTR = '\x00' * sz
nil = _NILSTR[:sz]
- fd = os.open(f, os.O_WRONLY)
+ fd = os.open(f, os.O_WRONLY|O_BINARY)
try:
size = os.fstat(fd)[stat.ST_SIZE]
blocks = ceilDiv(size, sz)
@@ -1268,6 +1288,9 @@
options = 0
else:
options = os.WNOHANG
+ if sys.platform == 'win32':
+ LOG.warn("Skipping waitForChildren")
+ return
while 1:
try:
# WIN32 This won't work on Windows. What to do?
@@ -1299,6 +1322,10 @@
def installSIGCHLDHandler():
'''Register sigchld handler for this process.'''
+ #WWWWW
+ if sys.platform == 'win32':
+ LOG.warn("Skipping installSIGCHLDHandler")
+ return
signal.signal(signal.SIGCHLD, _sigChldHandler)
#----------------------------------------------------------------------
@@ -1322,11 +1349,15 @@
"""Helper function. Returns a file open for writing into the file named
'fname'. If fname already exists, opens 'fname.1' or 'fname.2' or
'fname.3' or so on."""
+ if 'b' in mode:
+ bin = O_BINARY
+ else:
+ bin = 0
base, rest = os.path.split(fname)
idx = 0
while 1:
try:
- fd = os.open(fname, os.O_WRONLY|os.O_CREAT|os.O_EXCL, perms)
+ fd = os.open(fname, os.O_WRONLY|os.O_CREAT|os.O_EXCL|bin, perms)
return os.fdopen(fd, mode), fname
except OSError, e:
if e.errno != errno.EEXIST:
@@ -1360,7 +1391,13 @@
write 'contents' to the lockfile. If 'blocking' is true, wait until
we can acquire the lock. If 'blocking' is false, raise IOError if
we can't acquire the lock."""
+
+ if not fcntl:
+ #WWWWW
+ LOG.warn("Skipping Lockfile.acquire")
+ return
if self.count > 0:
+
self.count += 1
return
@@ -1381,6 +1418,12 @@
def release(self):
"""Release the lock."""
+
+ if not fcntl:
+ #WWWWW
+ LOG.warn("Skipping Lockfile.release")
+ return
+
assert self.fd is not None
self.count -= 1
if self.count > 0:
Index: Crypto.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Crypto.py,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- Crypto.py 5 Jun 2003 18:41:40 -0000 1.45
+++ Crypto.py 10 Jul 2003 20:01:30 -0000 1.46
@@ -273,8 +273,8 @@
def pk_PEM_save(rsa, filename, password=None):
"""Save a PEM-encoded private key to a file. If <password> is provided,
encrypt the key using the password."""
- fd = os.open(filename, os.O_WRONLY|os.O_CREAT, 0600)
- f = os.fdopen(fd, 'wb')
+ fd = os.open(filename, os.O_WRONLY|os.O_CREAT,0600)
+ f = os.fdopen(fd, 'w')
if password:
rsa.PEM_write_key(f, 0, password)
else:
@@ -654,6 +654,7 @@
"""Initialize the true entropy source from a given Config object. If
none is provided, tries some sane defaults."""
global _TRNG_FILENAME
+ global _theTrueRNG
if config is not None:
requestedFile = config['Host'].get('EntropySource')
else:
@@ -686,14 +687,24 @@
break
if randFile is None and _TRNG_FILENAME is None:
- LOG.fatal("No entropy source available")
- raise MixFatalError("No entropy source available")
+ if sys.platform == 'win32':
+ LOG.warn("Using bogus screen snapshot for entropy source: beware!")
+ _ml.openssl_seed_win32()
+ _theTrueRNG = _OpensslRNG()
+ else:
+ LOG.fatal("No entropy source available")
+ raise MixFatalError("No entropy source available")
elif randFile is None:
LOG.warn("Falling back to previous entropy source %s",
_TRNG_FILENAME)
else:
LOG.info("Setting entropy source to %r", randFile)
_TRNG_FILENAME = randFile
+ _theTrueRNG = _TrueRNG(1024)
+
+
+# Global TRN instance, for use by trng().
+_theTrueRNG = None
class _TrueRNG(RNG):
'''Random number generator that yields pieces of entropy from
@@ -722,8 +733,13 @@
self.__lock.release()
return b
-# Global _TrueRNG instance, for use by trng().
-_theTrueRNG = _TrueRNG(1024)
+class _OpensslRNG(RNG):
+ """DOCDOC"""
+ def __init__(self):
+ """DOCDOC"""
+ RNG.__init__(self, 1024)
+ def _prng(self,n):
+ return _ml.openssl_rand(n)
# Return the shared instance of the true RNG.
def getTrueRNG():
Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- test.py 8 Jul 2003 19:13:50 -0000 1.133
+++ test.py 10 Jul 2003 20:01:30 -0000 1.134
@@ -2918,6 +2918,10 @@
log.addHandler(_FileLogHandler(t))
log.info("Abc")
log.info("Def")
+ if ON_WIN32: #WWWW
+ log.close()
+ return
+
os.rename(t,t1)
log.info("Ghi")
log.reset()