  Reconfigurable Intelligent Surfaces (RIS) show great promise in the realm of
6th generation (6G) wireless systems, particularly in the areas of localization
and communication. Their cost-effectiveness and energy efficiency enable the
integration of numerous passive and reflective elements, enabling near-field
propagation. In this paper, we tackle the challenges of RIS-aided 3D
localization and synchronization in multipath environments, focusing on the
near-field of mmWave systems. Specifically, our approach involves formulating a
maximum likelihood (ML) estimation problem for the channel parameters. To
initiate this process, we leverage a combination of canonical polyadic
decomposition (CPD) and orthogonal matching pursuit (OMP) to obtain coarse
estimates of the time of arrival (ToA) and angle of departure (AoD) under the
far-field approximation. Subsequently, distances are estimated using
$l_{1}$-regularization based on a near-field model. Additionally, we introduce
a refinement phase employing the spatial alternating generalized expectation
maximization (SAGE) algorithm. Finally, a weighted least squares approach is
applied to convert channel parameters into position and clock offset estimates.
To extend the estimation algorithm to ultra-large (UL) RIS-assisted
localization scenarios, it is further enhanced to reduce errors associated with
far-field approximations, especially in the presence of significant near-field
effects, achieved by narrowing the RIS aperture. Moreover, the Cram\'er-Rao
Bound (CRB) is derived and the RIS phase shifts are optimized to improve the
positioning accuracy. Numerical results affirm the efficacy of the proposed
estimation algorithm.
