Rules vary by National Forest and location. Generally, it's allowed in more isolated areas, which do not include the popular approaches to Yosemite National Park. Yosemite is surrounded by 3 National Forests: Inyo National Forest to the east, Stanislaus National Forest to the north and northwest, and Sierra National Forest to the south and southwest. In all cases you need a Campfire Permit, available from a Forest Service office.
National Forest campgrounds are available along the approaches to Yosemite. Here's a clickable map:
http://jrabold.net/yosemite/campn.shtml
Here's the relevant webpage quotes:
Inyo National Forest Camping
Most of the land in Inyo and Mono counties is publicly owned. Dispersed camping (camping outside of designated campgrounds) is allowed throughout much of the area. . . . Certain high-use recreation zones, including those along paved roads leading into the mountains, are not open to dispersed camping (see Inyo National Forest map).
http://www.fs.fed.us/r5/inyo/
Stanislaus National Forest
Camping on the Stanislaus National Forest is not limited to developed campgrounds. Most of the Forest is open to those who prefer the quiet and solitude of a completely undeveloped setting outside of developed campgrounds. This type of camping is called "dispersed camping," and visitors are asked to choose a fire safe camping spot and leave a minimal impact on the site.
http://www.fs.fed.us/r5/stanislaus/
Sierra National Forest Camping
Campfire permits are required when camping in undeveloped sites
http://www.fs.fed.us/r5/sierra/recreation/camping/