It should be based on qualification alone. Not on race or gender.
But it's not based on qualification alone, not by a long shot. Studies have shown that legacy students are twice as likely to be admitted as students without legacy status because if the school rejects the legacy student, the parent's good will is likely to evaporate as will the gifts. Some lawmakers are even trying to make legacy admissions illegal, for they do, in fact, result in less qualified students being admitted over more qualified students.
Yet another reason affirmative action is still very much necessary; not just along racial and gender lines, but socioeconomic lines as well.