Constraining galaxy formation and cosmology with the conditional luminosity function of galaxies