What we seem to be trying to do in Afghanistan is to build a functional and legitimate state. On the face of it, this is a reasonable goal. After all, a functional state that can maintain order would (probably) lower the chances that terrorists would be able to establish bases within Afghan territory. This is, of course, our reason to be there. Of course, states do allow terrorists to train within their borders, so a functional state is obviously not a sufficient condition for this.
One challenge in creating a functional and legitimate state is dealing with corruption. As it stands, the government of Afghanistan is generally regarded as suffering from a high degree of corruption at all levels. While people tolerate and even expect governmental corruption, they will only tolerate it to a certain degree. When such corruption becomes too onerous to the people (for example, the bribes become too costly) or when the corruption prevents to government from meeting the needs of the people (such as maintaining order and services) then such governments tend to fail. Of course, a super power like the United States can try to prop up a corrupt government, but this can only work so far (as Vietnam showed).
So, to build a functional state in Afghanistan we not only need to establish the state as the dominant force for order, we also have to ensure that the corruption is kept to tolerable levels. This is defined in terms of both what the people are willing to tolerate and what a government can endure before it ceases to be a minimally functional state. To use an analogy, corruption can be seen as being a bit like plaque building up in the arteries. It impedes things and, if it grows too much, it can cause serious problems-including the death of the body.
Of course, there is something of a problem here-the people that we back tend to be those who we think are most amenable to our presence. These tend to be the folks who have the most to gain financially from the United States being there and who most need the presence of the United States forces to stay in power. Interestingly enough, these also seem to be the folks that would be most prone to be corrupt. Also, we seem to have a nasty habit of supporting corrupt regimes-provided that they claim to be on our side.
One final problem is that when we back a government we run the risk of lowering its legitimacy by making it seem like a puppet of the United States. This can lead to an increasing gap between the people and the government. Interestingly enough, as the government becomes more isolated it will tend to profess even greater devotion to the United States (a friend in need is a friend indeed), thus gaining more support from the United States as it continues to bleed legitimacy and support.