| 1 | /* Copyright (C) 1996-2023 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | |
| 4 | The GNU C Library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | The GNU C Library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with the GNU C Library; if not, see |
| 16 | <https://www.gnu.org/licenses/>. */ |
| 17 | |
| 18 | #include <libc-lock.h> |
| 19 | #include <errno.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <utmp.h> |
| 22 | |
| 23 | #include "utmp-private.h" |
| 24 | |
| 25 | |
| 26 | /* We have to use the lock in getutent_r.c. */ |
| 27 | __libc_lock_define (extern, __libc_utmp_lock attribute_hidden) |
| 28 | |
| 29 | |
| 30 | int |
| 31 | __getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result) |
| 32 | { |
| 33 | int retval; |
| 34 | |
| 35 | /* Test whether ID has any of the legal types. */ |
| 36 | if (id->ut_type != RUN_LVL && id->ut_type != BOOT_TIME |
| 37 | && id->ut_type != OLD_TIME && id->ut_type != NEW_TIME |
| 38 | && id->ut_type != INIT_PROCESS && id->ut_type != LOGIN_PROCESS |
| 39 | && id->ut_type != USER_PROCESS && id->ut_type != DEAD_PROCESS) |
| 40 | /* No, using '<' and '>' for the test is not possible. */ |
| 41 | { |
| 42 | __set_errno (EINVAL); |
| 43 | *result = NULL; |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | __libc_lock_lock (__libc_utmp_lock); |
| 48 | |
| 49 | retval = __libc_getutid_r (id, buffer, result); |
| 50 | |
| 51 | __libc_lock_unlock (__libc_utmp_lock); |
| 52 | |
| 53 | return retval; |
| 54 | } |
| 55 | libc_hidden_def (__getutid_r) |
| 56 | weak_alias (__getutid_r, getutid_r) |
| 57 | |