mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Create ~/.pypirc securely (#13512).
There was a window between the write and the chmod where the user’s password would be exposed, depending on default permissions. Philip Jenvey’s patch fixes it.
This commit is contained in:
parent
3e4a3dcb23
commit
d61926e6be
3 changed files with 5 additions and 10 deletions
|
@ -4,7 +4,6 @@ Provides the PyPIRCCommand class, the base class for the command classes
|
|||
that uses .pypirc in the distutils.command package.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
from configparser import ConfigParser
|
||||
|
||||
from distutils.cmd import Command
|
||||
|
@ -43,16 +42,8 @@ class PyPIRCCommand(Command):
|
|||
def _store_pypirc(self, username, password):
|
||||
"""Creates a default .pypirc file."""
|
||||
rc = self._get_rc_file()
|
||||
f = open(rc, 'w')
|
||||
try:
|
||||
with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
|
||||
f.write(DEFAULT_PYPIRC % (username, password))
|
||||
finally:
|
||||
f.close()
|
||||
try:
|
||||
os.chmod(rc, 0o600)
|
||||
except OSError:
|
||||
# should do something better here
|
||||
pass
|
||||
|
||||
def _read_pypirc(self):
|
||||
"""Reads the .pypirc file."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue