cpython: 6396d1fc72da (original) (raw)

Mercurial > cpython

changeset 85739:6396d1fc72da 3.1

#14984: On POSIX, enforce permissions when reading default .netrc. Initial patch by Bruno Piguet. This is implemented as if a useful .netrc file could exist without passwords, which is possible in the general case; but in fact our netrc implementation does not support it. Fixing that issue will be an enhancement. [#14984]

R David Murray rdmurray@bitdance.com
date Tue, 17 Sep 2013 20:30:02 -0400
parents c39f42f46a05
children 0d9e471221da 713d71048ab9
files Doc/library/netrc.rst Lib/netrc.py Lib/test/test_netrc.py Misc/NEWS
diffstat 4 files changed, 61 insertions(+), 6 deletions(-)[+] [-] Doc/library/netrc.rst 8 Lib/netrc.py 27 Lib/test/test_netrc.py 26 Misc/NEWS 6

line wrap: on

line diff

--- a/Doc/library/netrc.rst +++ b/Doc/library/netrc.rst @@ -19,6 +19,14 @@ the Unix :program:ftp program and othe no argument is given, the file :file:.netrc in the user's home directory will be read. Parse errors will raise :exc:NetrcParseError with diagnostic information including the file name, line number, and terminating token.

.. exception:: NetrcParseError

--- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -2,7 +2,7 @@

Module and documentation by Eric S. Raymond, 21 Dec 1998

-import io, os, shlex +import io, os, shlex, stat, pwd all = ["netrc", "NetrcParseError"] @@ -21,6 +21,7 @@ class NetrcParseError(Exception): class netrc: def init(self, file=None):

@@ -29,9 +30,9 @@ class netrc: self.hosts = {} self.macros = {} with open(file) as fp:

@@ -86,6 +87,26 @@ class netrc: elif tt == 'account': account = lexer.get_token() elif tt == 'password':

--- a/Lib/test/test_netrc.py +++ b/Lib/test/test_netrc.py @@ -5,9 +5,6 @@ temp_filename = support.TESTFN class NetrcTestCase(unittest.TestCase):

- def make_nrc(self, test_data): test_data = textwrap.dedent(test_data) mode = 'w' @@ -15,6 +12,7 @@ class NetrcTestCase(unittest.TestCase): mode += 't' with open(temp_filename, mode) as fp: fp.write(test_data)

def test_default(self): @@ -103,6 +101,28 @@ class NetrcTestCase(unittest.TestCase): """, '#pass')

+ def test_main(): support.run_unittest(NetrcTestCase)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,12 @@ Core and Builtins Library ------- +- Issue #14984: On POSIX systems, when netrc is called without a filename