Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Aug 2001 18:05:38 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Christoph Sold <so@i-clue.de>
Cc:        Joe McGuckin <joe@monk.via.net>, questions@FreeBSD.ORG
Subject:   Re: Largest UID value ?
Message-ID:  <20010806180538.A15453@student.uu.se>
In-Reply-To: <3B6EB389.97E0CFE3@i-clue.de>
References:  <200108042052.f74KqHM82410@monk.via.net> <3B6EB389.97E0CFE3@i-clue.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Aug 06, 2001 at 05:11:05PM +0200, Christoph Sold wrote:
> 
> 
> Joe McGuckin wrote:
> > 
> > What is the largest legitimate user id value?
> > 
> > getpwent() returns a uid_t which is a 32 bit unsigned it.
> > 
> > But, user 'nobody' (which historically had a user id of -1) has a
> > user id of 65534.
> 
> This is because the 32 bit signed integer -1 has exactly the same bit
> pattern than 32 bit unsigned int 65534. It's only a different
> interpretation of that bit pattern.

No, no, no.  The *16* bit signed integer -1 has the same bit pattern as
the 16 bit unsigned integer 65535.
The 16 bit unsigned integer 65534 has the same bit pattern as the 16
bit signed integer -2. 
(Assuming 2's-complement representation of negative numbers.)

> 
> > Will it break things if I start adding users with uid's  greater
> > than 65536 ?

I don't know. Try it :-)
I suspect that FreeBSD itself can handle this fine but some programs
might only use a 16-bit integer to represent UIDs. If they do and they
encounter a UID greater than 65535 they can get confused.
(For example, if you try to put the value 65536 into a 16-bit variable
the high order bits will be lost and the result will be merely 0. Bad.)

Any such programs are buggy and should be fixed but they might still
exist.

(Actually, such programs almost certainly exists.  I just looked in my
copy of _Unix Network Programming_ 1st ed. by W. Richard Stevens, from
1990. In many of the code examples in this book the user id is
represented by an unsigned short.  Since a short is a 16-bit value on
FreeBSD any code that follows those examples will probably break if
user ids larger than 65535 are used.)




> 
> Even 65536 will break things, as this is greater than MAXINT for
> unsigned 32 bit integer values. For organizational reasons, small
> negative values (which translate to values betwenn 65k and MAXINT)
> should also be avoided. Thus, as a rule of thumb, UIDs should stay below
> 65500.

This is a bit confused.
A 16-bit signed integer can  represent values between -32768 and 32767.
An unsigned 16 bit integer can represent values between 0 and 65535.
The bit patterns for an unsigned integer between 32768 and 65535 are
the same as those for a signed integer between -32768 and -1.
For 32-bit integers the limits are 
-2147483648 to 21474837 for signed integers and
0 to 4294967295 for unsigned.
(Again assuming 2's-complement representation for negative numbers.)





-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010806180538.A15453>