[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: SOLVED:command to start sshfs at bootup?



On Sun, Apr 18, 2021 at 09:21:55AM -0400, Gene Heskett wrote:
> It boiled down to something, someplace, not liking a hostname starting 
> with a number, I recalled I had to rename another machine a couple 
> months ago because it didn't work either.
> 
> But I changed its hostname to dddprint, based on the previous 3dprint, 
> and it now works as requested. So my problem is solved.
> 
> Is that just a head scratcher, or is there a valid reason to not allow a 
> hostname such as 6040 or 3dprint? Something starting with a numeral IOW.

It was one of the thoughts that I had last night when I was suggesting
debugging steps.

As for why it happens -- well, it's something a programmer will understand
intuitively.  I can't say whether it's a bug, a lazy implementation,
or a feature.

Let's say you're writing a program that can accept either an IP address
or a hostname.  You'd like to make it as easy as possible for the user,
so you don't require the user to say "the following is a hostname" or
"the following is an IP address".  Instead, you write code that will
automatically detect which one it is.

Now, how much effort do you actually put into the piece of the program
that performs the automatic detection?  That's the tricky question.  Do
you want the code to be super efficient?  Do you want to handle all kinds
of bizarre cases?  That's up to the individual programmer, or the designer
of the application.

Someone who leans toward the "bizarre cases" side might decide to write
a regular expression that matches an IPv4 address, another regular
expression that matches an IPv6 address, and then apply both of those
(in one order or the other order) against the user's input, and the first
one that matches wins.  If neither one matches, then treat it as a
hostname.

The cost of this solution is quite high.  You have to link in a regular
expression library, and you have to write two nontrivial regular
expressions, and you have to actually compile them and perform the
matching, which is a fairly expensive (in terms of CPU time) operation.
On top of all that, now you're locked in to the current design notions
of IPv4 and IPv6 addresses.  If someone comes up with IPv7 in the future,
your code won't handle it.

On the other end of the spectrum, there's the quick and dirty way.  You
look at the first byte of the user's input, and see whether it's a digit.
If it's a digit, you assume it's an IPv4 address.  Otherwise, you assume
it's a hostname.  You don't handle IPv6 because you probably wrote this
code before IPv6 even existed.

This solution is extremely cheap.  No libraries are needed, and no
regular expressions have to be written or compiled or matched.  Grabbing
one byte of memory through a pointer you've already got is about as fast
a test as you can possibly have.

So, based on what you're telling us, you've got some program that went
with the quick and dirty solution.

Since your statements are so incredibly vague, we can't even guess *which*
program it is, but if you want to pursue it with the developers, that's
your choice.

For the record, this kind of quick-and-dirty detection is common in
other namespaces besides just hostnames.  It also happens with user names
and group names, for example.  "chown 1000 foobar" will change the
owner of the file foobar to UID 1000.  If you try to create a user whose
*name* is 1000, you will have problems.  Lots of problems, very serious
ones.  Even a username that starts with a digit is probably an extremely
bad idea, for the reasons given above.


Reply to: