Yes, this is certainly possible. If all goes as planned, we'll publish a blog post on https://programtheblockchain.com next week showing exactly how to do this.
For a simplified, one-off contract, something like this would work:
address owner = msg.sender;
IERC20Token token = IERC20Token(0x...);
uint256 rate = 10; // 1 wei == 10 token units
function buyTokens() public payable {
uint256 tokenAmount = msg.value * rate;
require(token.transferFrom(owner, tokenAmount, msg.sender));
require(owner.transfer(msg.value));
}
You would need to allow
the number of tokens you're selling to this smart contract first.
And yes, this is essentially how decentralized exchanges work.