mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 08:03:10 +02:00
Address review comments
- move the umask call before the try/except block - move comment in _prepare_single to the umask call Simplify the code comments, too. Tests still pass.
This commit is contained in:
@@ -59,16 +59,19 @@ to serve all files under specified web root ({0})."""
|
|||||||
|
|
||||||
logger.debug("Creating root challenges validation dir at %s",
|
logger.debug("Creating root challenges validation dir at %s",
|
||||||
self.full_roots[name])
|
self.full_roots[name])
|
||||||
try:
|
|
||||||
# Change the permissiosn to be writable (GH #1389)
|
# Change the permissiosn to be writable (GH #1389)
|
||||||
# We also set umask because os.makedirs's mode parameter does
|
# Umask is used instead of chmod to ensure the client can also
|
||||||
# not always work:
|
# run as non-root (GH #1795)
|
||||||
# https://stackoverflow.com/questions/5231901/permission-problems-when-creating-a-dir-with-os-makedirs-python
|
old_umask = os.umask(0o022)
|
||||||
# We set the umask instead of going the chmod route to ensure the client
|
|
||||||
# can also run as non-root (GH #1795)
|
try:
|
||||||
|
|
||||||
stat_path = os.stat(path)
|
stat_path = os.stat(path)
|
||||||
old_umask = os.umask(0o022)
|
# This is coupled with the "umask" call above because
|
||||||
|
# os.makedirs's "mode" parameter may not always work:
|
||||||
|
# https://stackoverflow.com/questions/5231901/permission-problems-when-creating-a-dir-with-os-makedirs-python
|
||||||
|
|
||||||
os.makedirs(self.full_roots[name], 0o0755)
|
os.makedirs(self.full_roots[name], 0o0755)
|
||||||
|
|
||||||
# Set owner as parent directory if possible
|
# Set owner as parent directory if possible
|
||||||
@@ -114,11 +117,11 @@ to serve all files under specified web root ({0})."""
|
|||||||
path = self._path_for_achall(achall)
|
path = self._path_for_achall(achall)
|
||||||
logger.debug("Attempting to save validation to %s", path)
|
logger.debug("Attempting to save validation to %s", path)
|
||||||
|
|
||||||
|
# Change permissions to be world-readable, owner-writable (GH #1795)
|
||||||
old_umask = os.umask(0o022)
|
old_umask = os.umask(0o022)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, "w") as validation_file:
|
with open(path, "w") as validation_file:
|
||||||
# Change permissions to be world-readable, owner-writable (GH #1795)
|
|
||||||
validation_file.write(validation.encode())
|
validation_file.write(validation.encode())
|
||||||
finally:
|
finally:
|
||||||
os.umask(old_umask)
|
os.umask(old_umask)
|
||||||
|
|||||||
Reference in New Issue
Block a user