Writing

Feed Software, technology, sysadmin war stories, and more.

Monday, April 9, 2018

The perils of letting your computer dial the phone

Connecting a computer to a phone line can occasionally be hazardous. I'm not necessarily talking about the part where you zap yourself by handling live wires when they ring (been there, done that, hello, 90 VAC!). No, this is more like the phone bill you get at the end of the month when you find out what it's been up to while you weren't paying attention.

Many years ago, I had a BBS which ran this "netmail" software, wherein it would call other local area systems and would exchange messages. Some of the people in the local "net" were kind enough to act as "hubs", and did long-distance hauls to certain other parts of the country... and sometimes the world.

They would also allow me to send messages to them, which they would hang onto, and then would forward down these long-distance lines to the other hosts. This way, we only needed one set of calls between cities -- usually one in, one out, so it was fair.

This whole thing was controlled by a "routing file" on the disk which let you direct entire ranges of the network to various other places. It looked a bit like this:

accept 000-199/000-999 -> 200/123
accept 200/000-999
accept 201-999/000-999 -> 200/456

This looks kind of messy, so I'll explain it. First, the numbering scheme is net number first, then the slash, then the node number. Let's say our host is net 200, node 150, or 200/150. With that in mind, here's what those rules mean:

First, send any mail for nets 000 through 199 (covering all hosts in them) to 200/123, who is someone else local in town. Maybe they call that part of the world regularly.

Next, send mail to any host in net 200 direct, since they're all local anyway. That's easy enough - it makes a (free) local call, shoots the mail over, and calls it done.

After that, send any mail for nets 201 through 999 (again, all hosts in those nets) to 200/456, who is yet another person in town doing hubbing roles, and maybe they call that part of the world and don't mind.

This covers the entire spectrum, so it's all good. All mail is spoken for, no matter where it needs to go. There is no concept of a "default route through another host" in this system, incidentally. Without a routing file, all mail goes... direct. Got mail for host X? We'll call host X. Multiple times if we have to. Until it gets through.

But, yeah, I had a routing file, so my machine was well-behaved. It called the other local hosts, forwarded everything to them, and that was that.

Well, it was, until it wasn't. One day, my machine had no routing file. Or, at least, it had no routing instructions. These were the bad old days of MS-DOS, and one of the things which could happen was the notion of "cross-linked" files. This is where you'd reboot, run this thing called "chkdsk" (think fsck), and it would notice something wrong, and would try to make the best of it. It would usually end up pointing at least one directory entry for a file at complete garbage.

One day, that's exactly what happened on my poor machine. The routing file was there, but it contained garbage. The "helpful" netmail software tried to parse it, found no "accept" lines, and figured, okay, I have no routing rules. What do I do when I have no routing rules? That's right, I dial direct!

I had mail for a system in Australia, and so it dialed Australia multiple times. I found out a while later when the person in question replied to my mail and said "by the way, your machine called me direct to deliver this... is that what you wanted?", believe it or not. That lead me down into the logs, where I found that yes, the machine knows how to dial internationally. It had a list of every single other host in the network, complete with their phone numbers, and it knew how to prepend the magic "011" to dial internationally from the US phone system.

Obviously, I had to pay for this dumb thing my machine did, but I also had to come up with a way to never let it happen again, knowing full well that the routing file could be corrupted again at any time. My solution was to fork the "nodelist" -- that is, the file which contained all of the phone numbers for other systems.

Instead of taking updates and just storing them on my machine as-is, I'd write new copies of the nodelist under another name where the netmail software would never find it. Then, I wrote something small and goofy which would open the file for reading, open the actual nodelist path for writing, and would copy it line by line. The trick was that any host not in the local network would have its number replaced with some placeholder like "Unlisted". Those existed, and the netmail software knew it couldn't dial them, and just had to hang on and hope they dialed you instead.

I ran that system with that hack in place for almost a decade. It never called internationally without my explicit permission again.

Dumb, but effective.

Epilogue: it turns out I still have the binary around, although the source code is apparently L-O-N-G gone. Somehow, the mtime has been preserved, and so I can tell exactly when this happened so many years ago.

-r-xr-xr-x 1 root root 35750 Sep 11  1991 phonswap.exe