I found it.
Apparently, firestarter is installed on Ubuntu 12.04 either by default or as a dependency or recommendation to something I normally install. It was present on two different 12.04 machines but I don't remember installing it. Also never heard about it anywhere.
Firestarter only considers one of your network connections your internet gateway, and by default that's the wifi. So it sets up your linux firewall to block all incoming connections for wifi, but not ethernet, because it considers ethernet to be your local network.
The tricky part is that ufw and gufw, which seem to have replaced firestarter as Ubuntu's recommended firewall, have their own set of iptables rules, so they don't even notice firestarter is there and can't switch it off.
To get rid of the firestarter rules temporarily, launch firestarter and click the stop button.
To get rid of firestarter and its rules permanently, do:
sudo apt-get remove firestarter
You can now either leave the firewall as it is and possible disable samba when you're on public wifi, or you can set up a couple of rules of your own with ufw or gufw. I just left if off and plan to switch on gufw by hand if I go on public wifi.