Shapes and gravitational fields of rotating two-layer Maclaurin ellipsoids: Application to planets and satellites