enforce maxlength in usernames

Rich Felker dalias at aerifal.cx
Fri Jul 29 16:13:02 UTC 2011


On Fri, Jul 29, 2011 at 04:30:53PM +0200, Tito wrote:
> Hi,
> after more research about this topic I've found a few interesting things
> about this can of worms I've unknowningly uncovered:
> 
> 1) 3.426 User Name
> 
> A string that is used to identify a user; see also User Database. To be portable
> across systems conforming to IEEE Std 1003.1-2001, the value is composed
> of characters from the portable filename character set. 
> The hyphen should not be used as the first character of a portable user name.

The key phrase is "To be portable across systems conforming...". What
that means is that an application cannot hard-code a username that
uses characters outside the portable filename character set and be
portable to all POSIX implementations. It does not restrict the local
administrator's or user's choice of usernames.

> [...]
> So it seems fine to me that busybox's adduser and addgroup mimic this behaviour
> by checking for illegal characters and check the length of user names at creation

It's unclear to me that this behavior is desirable, but mimicing an
existing program is at least a better excuse than mis-interpreting
standards. However, in this case you should not use the
locale-specific isalpha or isalnum functions; you should instead
hard-code the list of ASCII codepoints that are valid. Otherwise the
utility will allow non-ASCII letters in legacy 8-bit locales, but
forbid all non-ASCII letters in modern UTF-8 locales, which is
probably not the desired behavior.

Portable ASCII isalnum:

#define ascii_isalnum ((c)-'0'<10u || ((c)|32u)-'a'<26u)

Rich


More information about the busybox mailing list