/src/sudo/lib/util/login_max.c
Line | Count | Source |
1 | | /* |
2 | | * SPDX-License-Identifier: ISC |
3 | | * |
4 | | * Copyright (c) 2025 Todd C. Miller <Todd.Miller@sudo.ws> |
5 | | * |
6 | | * Permission to use, copy, modify, and distribute this software for any |
7 | | * purpose with or without fee is hereby granted, provided that the above |
8 | | * copyright notice and this permission notice appear in all copies. |
9 | | * |
10 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | | */ |
18 | | |
19 | | #include <config.h> |
20 | | |
21 | | #include <stdlib.h> |
22 | | #include <unistd.h> |
23 | | #include <limits.h> |
24 | | |
25 | | #include <sudo_compat.h> |
26 | | #include <sudo_util.h> |
27 | | |
28 | | #ifndef LOGIN_NAME_MAX |
29 | | # ifdef _POSIX_LOGIN_NAME_MAX |
30 | | # define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX |
31 | | # else |
32 | | # define LOGIN_NAME_MAX 9 |
33 | | # endif |
34 | | #endif /* LOGIN_NAME_MAX */ |
35 | | |
36 | | size_t |
37 | | sudo_login_name_max_v1(void) |
38 | 0 | { |
39 | 0 | static size_t maxval; |
40 | |
|
41 | 0 | if (maxval == 0) { |
42 | 0 | long lval; |
43 | |
|
44 | 0 | #ifdef _SC_LOGIN_NAME_MAX |
45 | 0 | lval = sysconf(_SC_LOGIN_NAME_MAX); |
46 | 0 | if (lval < 0) |
47 | 0 | #endif |
48 | 0 | lval = LOGIN_NAME_MAX; |
49 | 0 | maxval = (size_t)lval; |
50 | 0 | } |
51 | |
|
52 | 0 | return maxval; |
53 | 0 | } |