Generally speaking if an officer makes an arrest, then he can search the area under control of the arrestee -car, house, dungeon, etc.
Without the arrest, the officer can look for anything "in plain sight".
Anytime the officer asks permission to search/enter, then you are protected by constitutional rights. That's why they ask--most folks are eager to show that they have nothing to hide. And when you say "yes" you have waived those rights.
Otherwise the officer will have to arrest you or get a warrant to do the search.