From owner-freebsd-questions Mon Aug 6 9: 6:58 2001 Delivered-To: freebsd-questions@freebsd.org Received: from maila.telia.com (maila.telia.com [194.22.194.231]) by hub.freebsd.org (Postfix) with ESMTP id 7710C37B431 for ; Mon, 6 Aug 2001 09:06:48 -0700 (PDT) (envelope-from ertr1013@student.uu.se) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by maila.telia.com (8.11.2/8.11.0) with ESMTP id f76G6jo12801 for ; Mon, 6 Aug 2001 18:06:46 +0200 (CEST) Received: from ertr1013.student.uu.se (h185n2fls20o913.telia.com [212.181.163.185]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id SAA15233 for ; Mon, 6 Aug 2001 18:06:43 +0200 (CEST) Received: (qmail 18734 invoked by uid 1001); 6 Aug 2001 16:05:38 -0000 Date: Mon, 6 Aug 2001 18:05:38 +0200 From: Erik Trulsson To: Christoph Sold Cc: Joe McGuckin , questions@FreeBSD.ORG Subject: Re: Largest UID value ? Message-ID: <20010806180538.A15453@student.uu.se> Mail-Followup-To: Christoph Sold , Joe McGuckin , questions@FreeBSD.ORG References: <200108042052.f74KqHM82410@monk.via.net> <3B6EB389.97E0CFE3@i-clue.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3B6EB389.97E0CFE3@i-clue.de> User-Agent: Mutt/1.3.20i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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.) -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message