A law enforcement officer is entitled to search the property or person of any citizen if they have probable cause to believe a crime is being or has been committed. So if an officer sees someone wearing a ski mask driving away from a bank at a high rate of speed, stopping and searching the vehicle is reasonable. If an officer noticed white powder near the nose of the suspect, he/she has probable cause to conduct a search of the vehicle for drugs. If a drug dog "hits" on the car, that would be considered probable cause.
The other instance would be if an arrest is made. Say you are pulled over for speeding, and everything is legal except there is a warrant out for your arrest on issues unrelated to your driving. Since you are in custody, the officer can search the car for anything illegal without a warrant.