Retrieving the user and group name length limit from the kernel

You can use commands and subroutines to retrieve the v_max_logname parameter from the kernel.

Using the getconf command

You can use the getconf command with the LOGIN_NAME_MAX parameter to retrieve the user and group name length limit in the kernel. The getconf command output includes the terminating NULL character.

The following example shows how to use getconf command to retrieve the current user and group name limit from the kernel:

$ getconf LOGIN_NAME_MAX
20
$

Using the sysconf subroutine

You can use the sysconf subroutine with the _SC_LOGIN_NAME_MAX parameter to retrieve the user and group name length limit in the kernel.

The following example shows how to use the sysconf subroutine to retrieve the user and group name length limit from the kernel:

#include <unistd.h>
main()
{
       long len;

       len = sysconf(_SC_LOGIN_NAME_MAX);

       printf("The name length limit is %d\n", len);
}

Using the sys_parm subroutine

You can use the sys_parm subroutine with the SYSP_V_MAX_LOGNAME parameter to retrieve the current user name length limit in the kernel.

The following example shows how to use the sys_parm subroutine to retrieve the user name length limit from the kernel:
#include <sys/types.h>
#include <sys/var.h>
#include <errno.h>
main()
{
   int rc;
   struct vario myvar;

   rc = sys_parm (SYSP_GET, SYSP_V_MAX_LOGNAME, &myvar);

   if (!rc)
      printf("Max_login_name = %d\n", myvar.v.v_max_logname.value);
   else
      printf("sys_parm() failed rc = %d, errno = %d\n", rc, errno);
}