Username and Groupname Sizes on HP-UX
Developers should read this section in its entirety, along with the related appendices, to ensure all
issues are understood.
Developers should also become familiar with the administrative issues described in this paper.
5.1 Checklist to Find out Whether Your Program is Long User/Group
Name Clean and Methods to Make Them Clean
Please note, this checklist, assumes that "name" means user name or group name.
1. Does your program depend on LOGIN_NAME_MAX /_POSIX_LOGIN_NAME_MAX to identify
the maximum supported size of username/group name on the system?
Ø If so, use sysconf (_SC_LOGIN_NAME_MAX) to query the maximum supported size of
the user/group names. LOGIN_NAME_MAX is a constant and does not represent the run
time value. _POSIX_LOGIN_NAME_MAX is a constant which represents only the
minimum supported value.
Ø Because _SC_LOGIN_NAME_MAX system configuration variable is not available on
earlier versions of HP-UX, users may use conditional compilation in the following manner:
#include <unistd.h>
…….
…….
user_buf_size = 0;
#ifdef _SC_LOGIN_NAME_MAX
user_buf_size = sysconf (_SC_LOGIN_NAME_MAX) + 1;
#endif
if (user_buf_size <= 0) user_buf_size = 256;
userbuf = malloc(user_buf_size);
Ø If an array of size LOGIN_NAME_MAX/_POSIX_LOGIN_NAME_MAX is used, then
either the array size needs to be changed to 256 or it can be changed to a pointer and
the memory for it can be later on dynamically allocated based on the sysconf
(_SC_LOGIN_NAME_MAX).
2. Does your program use the obsolescent interface cuserid () and the macro L_cuserid?
Ø This interface is not enhanced for long user/group name. Use the appropriate
replacement interface by referring to the man page of cuserid ().
3. Insufficient storage
• Are any array buffers allocated to store a name, or a string that might contain a name?
Are they large enough? Trace through the code and identify where that buffer is used
and how it might impact the code.
• Are there any structures defined that contain an array for a name? Are they large
enough? Are they passed back to a user application?
• Are there any malloced memory regions used to store a name (or names)? Are they
large enough? Where is that memory accessed in other locations of the code?
Ø Allocate sufficient storage, and make sure the right pointer is passed.
4. Are there any message strings (such as in a message catalog) that contain a name? Does the
code assume the output does not exceed 80 bytes (to fit in a terminal window.)?
Ø Review your messages and message catalogs.
Ø Verify whether the change in output can cause readability or other display problems.
5. Are any file names created using a name that could exceed the limit of a legal file name length
on the file system?
• Note that different file systems types may have different limits (HFS supports 14 and
250 bytes.)
• Are any characters appended to a name, for example to create a temporary file name
by appending a random numeric value at the end?