dKj4 ~ d Z ddlmZmZ ddlZddlZddlZddlmZ ddl m
Z
dZdZde
d efd
Zde
d e
e
fdZdS )z"Module for work with wp_config.php )absolute_importprint_functionN)Path)Listz
wp-config.phpi abs_wp_pathreturnc , t | t S )z,
Return path to wp-config.php file.
)r WP_CONFIG_SUFFIX)r s py/clwpos/wp_config.pypathr s -... c t j t | t j t j z t j z } t j | }t j |j s t dt | d |j t k r(t dt | dt d t dz }g }|}|dk rEt j
|| }|sn-| | |t | z }|dk Et j | n# t j | w xY wd | }t | t k r(t dt | dt d t% j t% j | d 5 }| cd
d
d
S # 1 swxY w Y d
S )a-
Read wp-config.php located in specified WP path.
The file is tenant-owned, so open it with O_NOFOLLOW (reject a symlinked
final component) and O_NONBLOCK (open() cannot block on a FIFO with no
writer), fstat the opened fd to require a regular file (reject
FIFO/device/socket/dir), and bound the actual read to MAX_WP_CONFIG_BYTES.
The fstat st_size is only a fast-reject of an already-oversized file; it
does not bound the read, because a tenant can grow (append to) the file
after the fstat but before/while the bytes are consumed, so the read itself
must be hard-capped: pull at most MAX_WP_CONFIG_BYTES + 1 bytes and reject
if the file yielded more than the cap (a grown/sparse file), rather than
returning a truncated config that would corrupt the file on write-back.
The bytes are then split into lines exactly as the previous
open(errors='surrogateescape').readlines() did (universal-newline text
decode), so a small regular config returns the identical list of lines.
Because the type check is on the actually-opened fd it also closes the
stat-vs-open TOCTOU window. A symlinked path or a non-regular/oversized file
raises OSError, matching the missing/unreadable semantics of the previous
bare open() so callers' error handling is intact.
zwp-config.php at z is not a regular filez exceeds z bytes r r
surrogateescape)errorsN)osopenr O_RDONLY
O_NOFOLLOW
O_NONBLOCKfstatstatS_ISREGst_modeOSErrorst_sizeMAX_WP_CONFIG_BYTESreadappendlenclosejoinio
TextIOWrapperBytesIO readlines) r fdstlimitchunks remainingchunkrawfs r r r s ,
k""BK"-$?"-$O P PB
Xb\\|BJ'' YWd;.?.?WWWXXX
:+++ed;.?.?eeJ]eeefff
$a' !mmGB **E
MM% U#I !mm
((6
C
3xx%%%a${*;*;aaFYaaabbb
"*S//2C D D D {{}} s CD; ;EG22G69G6)__doc__
__future__r r r# r r pathlibr typingr r
r strr r r
r