Index: gerrit_util.py |
diff --git a/gerrit_util.py b/gerrit_util.py |
index 3a4cc07660b4cc8315a140d74b3dc2ecf236b607..62fc1b9ab53cac7ddbf60f3f1dc70fae8ba93afd 100755 |
--- a/gerrit_util.py |
+++ b/gerrit_util.py |
@@ -15,14 +15,33 @@ import logging |
import netrc |
import os |
import re |
+import stat |
+import sys |
import time |
import urllib |
from cStringIO import StringIO |
+_netrc_file = '_netrc' if sys.platform.startswith('win') else '.netrc' |
+_netrc_file = os.path.join(os.environ['HOME'], _netrc_file) |
try: |
- NETRC = netrc.netrc() |
-except (IOError, netrc.NetrcParseError): |
+ NETRC = netrc.netrc(_netrc_file) |
+except IOError: |
+ print >> sys.stderr, 'WARNING: Could not read netrc file %s' % _netrc_file |
NETRC = netrc.netrc(os.devnull) |
+except netrc.NetrcParseError as e: |
+ _netrc_stat = os.stat(e.filename) |
+ if _netrc_stat.st_mode & (stat.S_IRWXG | stat.S_IRWXO): |
+ print >> sys.stderr, ( |
+ 'WARNING: netrc file %s cannot be used because its file permissions ' |
+ 'are insecure. netrc file permissions should be 600.' % _netrc_file) |
+ else: |
+ print >> sys.stderr, ('ERROR: Cannot use netrc file %s due to a parsing ' |
+ 'error.' % _netrc_file) |
+ raise |
+ del _netrc_stat |
+ NETRC = netrc.netrc(os.devnull) |
+del _netrc_file |
+ |
LOGGER = logging.getLogger() |
TRY_LIMIT = 5 |