开发者

How big of a buffer should I create for the longest possible user or group name on Linux?

开发者 https://www.devze.com 2023-03-06 06:02 出处:网络
What is the maximum number of characters that a user name or group name may be on Linux? I need to allocate a buffer and would like to know how much space I need to allocate to guarantee it is large

What is the maximum number of characters that a user name or group name may be on Linux?

I need to allocate a buffer and would like to know how much space I need to allocate to guarantee it is large enough for whatever group or user 开发者_如何学Pythonname my application might encounter.


(Putting my comment into an answer now that the question has been reopened)

POSIX specifies that LOGIN_NAME_MAX must be >= _POSIX_LOGIN_NAME_MAX. _POSIX_LOGIN_NAME_MAX, in turn, is defined to 9. On Linux it seems LOGIN_NAME_MAX is 256.

For groups, I don't think there is anything similar. Some kind of upper bound can be guesstimated via the getgrnam_r() and getgrgid_r() functions, which take a user supplied buffer for the char* entries in struct group. The maximum needed size for this buffer can be retrieved via sysconf(_SC_GETGR_R_SIZE_MAX) or the macro NSS_BUFLEN_GROUP. On Linux, NSS_BUFLEN_GROUP seems to be 1024.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号