error in trimdomain(3)

Brooks Davis brooks at one-eyed-alien.net
Mon Oct 3 11:24:07 PDT 2005


On Mon, Oct 03, 2005 at 07:18:08PM +0100, Ceri Davies wrote:
> On Mon, Oct 03, 2005 at 11:03:44AM -0700, Brooks Davis wrote:
> > On Mon, Oct 03, 2005 at 11:31:24AM +0100, Ceri Davies wrote:
> > > On Sat, Oct 01, 2005 at 02:35:50AM -0700, Brooks Davis wrote:
> > > > I discovered today that the trimdomain() implementation in libutil deviates
> > > > slightly from the manpage.  The manpage says:
> > > > 
> > > >      The function trimdomain() removes the current domain name from the passed
> > > >      fullhost name by writing a NUL character over the first period of the
> > > >                                                        ^^^^^^^^^^^^
> > > >      passed name.  The current domain name is determined by calling
> > > >      gethostname(3) and removing everything up to the first period.
> > > > 
> > > > which clearly indicates that trimdomain() should return either the
> > > > unmodified string or a host name with no domain.  In reality it will
> > > > remove the domain name even if the result is not a host name.  This
> > > > means that if the host b.com calls trimdomain with "a.b.com" as the
> > > > input string, the result is "a.b".
> > > 
> > > That's actually what the excerpt above says will happen.
> > > 
> > > gethostname returns "b.com", removing everything up to the first period
> > > yields ".com", and that removed from "a.b.com" gives you "a.b".
> > > 
> > > I don't care if it needs to be changed, but that does exactly what it
> > > says on the tin so far as I can see.
> > 
> > There are two refrences to "first period".  You are correct that the
> > domain name of b.com is .com, but the refrence I highlighted states that
> > the only allowable modification to the host name is writing a NUL to
> > the first period in the string (it's actually messier than this because
> > trimdomain also supports X11 DISPLAY strings and thus does a memmove and
> > reterminates if there is a :0 or :0.0 type string after domain.)
> 
> I agree that the documentation gives that impressions but the fact that
> it bothers to call gethostname at all makes me wonder; if it's just going
> to replace the first period with a NUL then I don't see why that call is
> necessary, unless the intention is to achieve the current behaviour.

My interpretation is that the function is intended to remove the domain
only if it is the local domain and thus implicit.

-- Brooks

-- 
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20051003/65b54b4e/attachment.bin


More information about the freebsd-arch mailing list