From patchwork Fri Aug 9 14:22:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1970968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=nPbMaPP/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgR3F1kTgz1yYl for ; Sat, 10 Aug 2024 00:23:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFD92385C6CD for ; Fri, 9 Aug 2024 14:23:18 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 07BED3858420 for ; Fri, 9 Aug 2024 14:22:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07BED3858420 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 07BED3858420 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::231 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723213379; cv=none; b=aZLF9kxZyOEMwzYGsHAVbh5GQCJJNuPmaklAhWzwpG0fT/6UwzExqjgEbDIAheMn3EEkRSbb94qaktI2y5LnXmSevV8KhiifKcmi990LtAcQfgEtmXZU79aT6mNeysX73LiaC9SwwAcyyV3Bvj4npAVF0UAUAxjtixGWu6+7dMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723213379; c=relaxed/simple; bh=jgwc7aPuVboeURUbd54/M7ge4wtaBPc7fshvFfpsU80=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=u7hX35VCxEIsIyMUGG0fL7VZARb3k4tsKmE6/j2vXruWd1SUFmW53l3xCeGJQFyuRvz3jp8PYEj4XYH0Dm1OcvDU6DWoKzqW9MX0fufQOup8Z0McPvmAhU8FaJvF8GJixBDuehQ3dnl0wy+JbFCUWwvxWCkhq2sXTF0EyFO9MIE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3db145c8010so1367741b6e.3 for ; Fri, 09 Aug 2024 07:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723213376; x=1723818176; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TGvSvn01E0d7GjJz8njF/UaOKkcNTsv6FEGurLX6ZMw=; b=nPbMaPP/QnEAK8umgyxKu3WnA+3YSnOfqzQI4Dq50QMNFmKqtOtb6s81DLN/g3kH/7 32u/D9JS6jUxrgoRXp1UPsKmMX4yyU3yy9X2nFOZ9WRNQTBRX/MLI88Le37LbkT3W91q iAM0q8ADv9uF20bHVKAp69pgkzhpTfJtkAuGC6Ybca3onbWuN01azjWOwmNm7q0Nge0l rnJP4bxkR3okJb6+8kIOWevfxlRz5/41g/WyoREFLWOg0YgkyZFwN9+APRqsc4kumtbQ vUxH4cH3wQryOYH0kQQvyNXEooRuY3M5KKBitKvPTv7BnoXHAU9GdinYBH4R2maAMOXH /9bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723213376; x=1723818176; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TGvSvn01E0d7GjJz8njF/UaOKkcNTsv6FEGurLX6ZMw=; b=WPR9X+Pf/V07q8iy/py/N6QhhH5Ov6WzgJC26+/hOQh8WAaozEa76rfyvG23N4aoyN dSGIvyYCePRUKOBMfXke3WjpYkesx4DsA768q4SvJLsYWSxzdZL8aE6TVim08EttR81k BpPKGpLqPgygq792fQtcvJkTL8Q4H1t5crbHpHHnEvL8EJM/myhjcTYNcsAu3Ep9SZvV 0QCdarrfGlRmNyZhn0c1dvWnQka3lqtAStyFfJLeY1L9TxpdoZ6oyvU0QpDHwoT2xh11 JscgghnWSCLm89piFoBj8qR70Xr8+2G6bPnO5Dlyekb2mCKuJ4hnmG18L1KcQ/D2mBML 38xA== X-Gm-Message-State: AOJu0Yy73JBgwTBbEr2KZwvJjE8awD2iE/szCOd3/CYLBTtcF7AXz2qk MkovfKKrHMZALg3b8Itf6h3w8wZ23qqNHNTtxwgilRshKEQBkhFCRHOG/aG1Y3er/yAvIVofX+v thpI= X-Google-Smtp-Source: AGHT+IEZqnWfPq7/ezJPe72tE+kDVcUad1Qsyp1uCihqILzY3px8mLizWc/FKEhSE53d6E+B4Xt7Rg== X-Received: by 2002:a05:6870:1681:b0:25e:b999:d24 with SMTP id 586e51a60fabf-26c6297c975mr1740094fac.0.1723213375490; Fri, 09 Aug 2024 07:22:55 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:347e:ece3:50dc:7701:b6f7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb20d8e1sm2668222b3a.39.2024.08.09.07.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 07:22:54 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Thorsten Kukuk , Paul Eggert , Florian Weimer Subject: [PATCH v2 1/2] login: Remove utmp fallback for getlogin Date: Fri, 9 Aug 2024 11:22:14 -0300 Message-ID: <20240809142248.929824-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240809142248.929824-1-adhemerval.zanella@linaro.org> References: <20240809142248.929824-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org With upcoming utmp no-op, the getutline_r will always fail. The default getlogin is now based on getlogin_r, which allows to consolidate Linux and Hurd implementation. Checked on x86_64-linux-gnu and i686-linux-gnu. --- include/unistd.h | 3 - login/getlogin.c | 13 ++-- sysdeps/mach/hurd/getlogin.c | 35 --------- sysdeps/unix/getlogin.c | 81 --------------------- sysdeps/unix/getlogin_r.c | 103 --------------------------- sysdeps/unix/sysv/linux/getlogin.c | 39 ---------- sysdeps/unix/sysv/linux/getlogin_r.c | 34 ++------- 7 files changed, 16 insertions(+), 292 deletions(-) delete mode 100644 sysdeps/mach/hurd/getlogin.c delete mode 100644 sysdeps/unix/getlogin.c delete mode 100644 sysdeps/unix/getlogin_r.c delete mode 100644 sysdeps/unix/sysv/linux/getlogin.c diff --git a/include/unistd.h b/include/unistd.h index e241603b81..f9bf9f133f 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -215,9 +215,6 @@ extern __pid_t __libc_fork (void); This always returns -1 and sets `errno' to EINTR. */ extern int __libc_pause (void); -extern int __getlogin_r_loginuid (char *name, size_t namesize) - attribute_hidden; - # if IS_IN (rtld) # include # endif diff --git a/login/getlogin.c b/login/getlogin.c index 6f77574db6..e06d84aa3f 100644 --- a/login/getlogin.c +++ b/login/getlogin.c @@ -18,14 +18,19 @@ #include #include #include +#include + +#ifndef LOGIN_NAME_MAX +# define LOGIN_NAME_MAX 1024 +#endif +static char name[LOGIN_NAME_MAX]; /* Return the login name of the user, or NULL if it can't be determined. The returned pointer, if not NULL, is good only until the next call. */ char * getlogin (void) { - __set_errno (ENOSYS); - return NULL; + if (__getlogin_r (name, sizeof name) != 0) + return NULL; + return name[0] != '\0' ? name : NULL; } - -stub_warning (getlogin) diff --git a/sysdeps/mach/hurd/getlogin.c b/sysdeps/mach/hurd/getlogin.c deleted file mode 100644 index 05b287e413..0000000000 --- a/sysdeps/mach/hurd/getlogin.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 1991-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -/* Return the login name of the user, or NULL if it can't be determined. - The returned pointer, if not NULL, is good only until the next call. */ -char * -getlogin (void) -{ - static char login[1024]; /* XXX */ - error_t err; - - if (err = __USEPORT (PROC, __proc_getlogin (port, login))) - return __hurd_fail (err), NULL; - - return login; -} diff --git a/sysdeps/unix/getlogin.c b/sysdeps/unix/getlogin.c deleted file mode 100644 index 4a7fc03ef5..0000000000 --- a/sysdeps/unix/getlogin.c +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (C) 1991-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include -#include - -#include - -static char name[UT_NAMESIZE + 1]; - -/* Return the login name of the user, or NULL if it can't be determined. - The returned pointer, if not NULL, is good only until the next call. */ - -#ifdef STATIC -STATIC -#endif -char * -getlogin (void) -{ - char tty_pathname[2 + 2 * NAME_MAX]; - char *real_tty_path = tty_pathname; - int err; - char *result = NULL; - struct utmp *ut, line, buffer; - - /* Get name of tty connected to fd 0. Return NULL if not a tty or - if fd 0 isn't open. Note that a lot of documentation says that - getlogin() is based on the controlling terminal---what they - really mean is "the terminal connected to standard input". The - getlogin() implementation of DEC Unix, SunOS, Solaris, HP-UX all - return NULL if fd 0 has been closed, so this is the compatible - thing to do. Note that ttyname(open("/dev/tty")) on those - systems returns /dev/tty, so that is not a possible solution for - getlogin(). */ - err = __ttyname_r (0, real_tty_path, sizeof (tty_pathname)); - if (err != 0) - { - __set_errno (err); - return NULL; - } - - real_tty_path += 5; /* Remove "/dev/". */ - - __setutent (); - strncpy (line.ut_line, real_tty_path, sizeof line.ut_line); - if (__getutline_r (&line, &buffer, &ut) < 0) - { - if (errno == ESRCH) - /* The caller expects ENOENT if nothing is found. */ - __set_errno (ENOENT); - result = NULL; - } - else - { - strncpy (name, ut->ut_user, UT_NAMESIZE); - name[UT_NAMESIZE] = '\0'; - result = name; - } - - __endutent (); - - return result; -} diff --git a/sysdeps/unix/getlogin_r.c b/sysdeps/unix/getlogin_r.c deleted file mode 100644 index 77281f85b4..0000000000 --- a/sysdeps/unix/getlogin_r.c +++ /dev/null @@ -1,103 +0,0 @@ -/* Reentrant function to return the current login name. Unix version. - Copyright (C) 1991-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include -#include - -#include -#include "../login/utmp-private.h" - -/* Return at most NAME_LEN characters of the login name of the user in NAME. - If it cannot be determined or some other error occurred, return the error - code. Otherwise return 0. */ - -#ifdef STATIC -STATIC -#endif -int -__getlogin_r (char *name, size_t name_len) -{ - char tty_pathname[2 + 2 * NAME_MAX]; - char *real_tty_path = tty_pathname; - int result; - struct utmp *ut, line, buffer; - - /* Get name of tty connected to fd 0. Return if not a tty or - if fd 0 isn't open. Note that a lot of documentation says that - getlogin() is based on the controlling terminal---what they - really mean is "the terminal connected to standard input". The - getlogin() implementation of DEC Unix, SunOS, Solaris, HP-UX all - return NULL if fd 0 has been closed, so this is the compatible - thing to do. Note that ttyname(open("/dev/tty")) on those - systems returns /dev/tty, so that is not a possible solution for - getlogin(). */ - - result = __ttyname_r (0, real_tty_path, sizeof (tty_pathname)); - - if (result != 0) - return result; - - real_tty_path += 5; /* Remove "/dev/". */ - strncpy (line.ut_line, real_tty_path, sizeof line.ut_line); - - /* We don't use the normal entry points __setutent et al, because we - want setutent + getutline_r + endutent all to happen with the lock - held so that our search is thread-safe. */ - - __libc_lock_lock (__libc_utmp_lock); - __libc_setutent (); - result = __libc_getutline_r (&line, &buffer, &ut); - if (result < 0) - { - if (errno == ESRCH) - /* The caller expects ENOENT if nothing is found. */ - result = ENOENT; - else - result = errno; - } - __libc_endutent (); - __libc_lock_unlock (__libc_utmp_lock); - - if (result == 0) - { - size_t needed = __strnlen (ut->ut_user, UT_NAMESIZE) + 1; - - if (needed > name_len) - { - __set_errno (ERANGE); - result = ERANGE; - } - else - { - memcpy (name, ut->ut_user, needed - 1); - name[needed - 1] = 0; - result = 0; - } - } - - return result; -} -#ifndef STATIC -libc_hidden_def (__getlogin_r) -weak_alias (__getlogin_r, getlogin_r) -libc_hidden_weak (getlogin_r) -#endif diff --git a/sysdeps/unix/sysv/linux/getlogin.c b/sysdeps/unix/sysv/linux/getlogin.c deleted file mode 100644 index 5019062b48..0000000000 --- a/sysdeps/unix/sysv/linux/getlogin.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2010-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -#define STATIC static -#define getlogin getlogin_fd0 -#include -#undef getlogin - - -/* Return the login name of the user, or NULL if it can't be determined. - The returned pointer, if not NULL, is good only until the next call. */ - -char * -getlogin (void) -{ - int res = __getlogin_r_loginuid (name, sizeof (name)); - if (res >= 0) - return res == 0 ? name : NULL; - - return getlogin_fd0 (); -} diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c index 8f8decc8c0..c32f6658e8 100644 --- a/sysdeps/unix/sysv/linux/getlogin_r.c +++ b/sysdeps/unix/sysv/linux/getlogin_r.c @@ -19,29 +19,24 @@ #include #include #include +#include -#define STATIC static -static int getlogin_r_fd0 (char *name, size_t namesize); -#define __getlogin_r getlogin_r_fd0 -#include -#undef __getlogin_r - +/* Return at most NAME_LEN characters of the login name of the user in NAME. + If it cannot be determined or some other error occurred, return the error + code. Otherwise return 0. -/* Try to determine login name from /proc/self/loginuid and return 0 + Try to determine login name from /proc/self/loginuid and return 0 if successful. If /proc/self/loginuid cannot be read return -1. Otherwise return the error number. */ int -attribute_hidden -__getlogin_r_loginuid (char *name, size_t namesize) +__getlogin_r (char *name, size_t namesize) { int fd = __open_nocancel ("/proc/self/loginuid", O_RDONLY); if (fd == -1) return -1; - /* We are reading a 32-bit number. 12 bytes are enough for the text - representation. If not, something is wrong. */ - char uidbuf[12]; + char uidbuf[INT_BUFSIZE_BOUND (uid_t)]; ssize_t n = TEMP_FAILURE_RETRY (__read_nocancel (fd, uidbuf, sizeof (uidbuf))); __close_nocancel_nostatus (fd); @@ -98,21 +93,6 @@ __getlogin_r_loginuid (char *name, size_t namesize) scratch_buffer_free (&tmpbuf); return result; } - - -/* Return at most NAME_LEN characters of the login name of the user in NAME. - If it cannot be determined or some other error occurred, return the error - code. Otherwise return 0. */ - -int -__getlogin_r (char *name, size_t namesize) -{ - int res = __getlogin_r_loginuid (name, namesize); - if (res >= 0) - return res; - - return getlogin_r_fd0 (name, namesize); -} libc_hidden_def (__getlogin_r) weak_alias (__getlogin_r, getlogin_r) libc_hidden_weak (getlogin_r) From patchwork Fri Aug 9 14:22:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1970969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=vDep7xG/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgR4c0KHTz1yYl for ; Sat, 10 Aug 2024 00:24:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CAC33858CD9 for ; Fri, 9 Aug 2024 14:24:30 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 58D02385C6C7 for ; Fri, 9 Aug 2024 14:23:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58D02385C6C7 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58D02385C6C7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723213389; cv=none; b=T03Gz1PyFVm3MYBD4KtoVU781ilFrEe+AXxfz2SvhmGC/T0X7e1O5uuNeph38EpqbR9zmnVIOnuWTMEyHsprJt+lZd9XHyEnswwQaXPvfMtxZ3YNi+jLcv34/F96COpei6VSyXKwNuIEI8BHSx6h17QkoOJix1//yj3EAZy3djM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723213389; c=relaxed/simple; bh=/7nSXLmr3mxC/FfGnOY+lTwEkRb9evjOpHH4i5Fkfao=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=N5wYtU/l44Vxz3WwpodTQlnCl3ne1aF1Eg20KTOx3fsTNEB1t71O5MRC1HGy6kbHs6GNdyy461R3LBh+RtThgRvVoz87wLHg/UYvNmIU4lD9gmwuk57zADxZeeTzNV3f2o9GCEOqzJ/YndYeFTDYe59T3U+maStHAQe9hh1q+zI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3db13410adfso1400432b6e.2 for ; Fri, 09 Aug 2024 07:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723213381; x=1723818181; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DEB2vm0ETuyyUCHXYSveG0foCfBgEgV3kzyfEuCnTLI=; b=vDep7xG/k10j7CeBJETVZckjkq8ZXY8NWlc63HhUX2nRYyXM0o1UIquutUgAY5R5gC AOqAEDw06uWvmZKcbTQMmAV4KMq9dwUcCiSc1JCkyjrkImArtJ3cDKYCcVyB1Erqyqr8 niJGsPvlhvl0QNzKDELMg7FiN9tDYEjf3iyHgTqBj66EciztCU7Y86VP8HY//7tNPT1Z 5AyfnkxO0a7OkNhoQjUxPSN/pSTVmDUlpQPZZjuf97tg5FN2d9Qec7XuIKhkVhbyYYum 5x52h9UgLyD4Da+cC3QpPRmmQCMVrilbYALn1HiAxhCjPnA3W9UGwS/E4h5i6vox44Bz fJXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723213381; x=1723818181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DEB2vm0ETuyyUCHXYSveG0foCfBgEgV3kzyfEuCnTLI=; b=xTGF4MLD0qRDG/FaQYrctTDvCHXOo8sPxioamvMfUkwTJGhj6PXPbGWP6I/EvmB7ik TQPamTqPUaHNxetbmEUwdnermIQclY35ZAVXfWN2LM7eA/rESYPwsZiCIK+Le2So9ldM cPvCsvWFvZeVYyGVVFqPmO82IilzbhJUa8h/GKjiGfLupdAHb24RMS6tEwnrEdcGmHEx OL2M6MlEdMGMxn0I6nsN9sDU/SS4Ao5KvauHhR+5dVD/kAwszPM5Woc9BCYtGUUTovGE sA0dKE2l0HozCa4YWmi3RnXMSvlNYH1VfHmgcGtUFDYN6xKw+a1dH0GUEbPvQZT02YWT q3Nw== X-Gm-Message-State: AOJu0Yyf+87E6i11NVTKZhG19vD6ZRrbX4ZOb81gnZZwjVrL0H5ZPaal Z8/q9EHqOv8b5Z19CHVrJ83d+Wieu6OSpWaN3mJxN6atQCqEJpqpoyw1JvUdG8feASKtWzkYlyY +LjA= X-Google-Smtp-Source: AGHT+IEEyamgvXmJuGcobSK59EvRaNT8KQb3MTUrWnEVAl6J1WZUKoIIh0BI771SD0NRTgBxZgiSIg== X-Received: by 2002:a05:6808:3a17:b0:3da:e08d:888e with SMTP id 5614622812f47-3dc416dc941mr2186201b6e.38.1723213378537; Fri, 09 Aug 2024 07:22:58 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:347e:ece3:50dc:7701:b6f7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710cb20d8e1sm2668222b3a.39.2024.08.09.07.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 07:22:57 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Thorsten Kukuk , Paul Eggert , Florian Weimer Subject: [PATCH v2 2/2] login: Make user accounting database no-op Date: Fri, 9 Aug 2024 11:22:15 -0300 Message-ID: <20240809142248.929824-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240809142248.929824-1-adhemerval.zanella@linaro.org> References: <20240809142248.929824-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org The user accounting database functions are now deprecated and do not access or update the database files. Even though glibc 2.40 has change to use unsigned 32-bit types for seconds-since-epoch (commit 5361ad3910c257bc) and thus moving the issue to y2106, it still requires application migration and the implementation has some design flaws that is not easy fixable without a complete rewrite (BZ #24492). Recent system are moving away from utmp interface [1] and using alternatives instead. Even for non systemd system, alternative exists that are better than current status. It affects the obsolete functions login, logout, logwtmp, updwtmp, utmpname, getutent, setutent, endutent, getutid, getutline, pututline, getutent_r, getutid_r, and getutline_r along with POSIX defined setutxent, endutxent, getutxent, getutxid, getutxline, pututxline, and GNU extension utmpxname, updwtmpx, getutmp, and getutmpx. The function now are no-op and always returns an error or invalid result and set errno accordingly (when applicable). No compatibility support is provided, newer system deployments are moving to use different user accounting API where the old file are not guaranteed to exist. Checked on x86_64-linux-gnu and i686-linux-gnu. [1] https://www.thkukuk.de/blog/Y2038_glibc_utmp_64bit/ --- NEWS | 22 +- include/set-freeres.h | 3 - include/utmp.h | 29 - login/Makefile | 9 +- login/endutxent.c | 25 - login/getutent.c | 28 +- login/getutent_r.c | 45 +- login/getutid.c | 25 +- login/getutid_r.c | 34 +- login/getutline.c | 27 +- login/getutline_r.c | 21 +- login/getutmp.c | 12 +- login/getutmpx.c | 34 -- login/getutxent.c | 25 - login/getutxid.c | 25 - login/getutxline.c | 25 - login/login.c | 118 +--- login/logout.c | 44 +- login/logwtmp.c | 22 +- login/programs/utmpdump.c | 62 --- login/pututxline.c | 25 - login/setutxent.c | 25 - login/tst-pututxline-cache.c | 193 ------- login/tst-pututxline-lockfail.c | 176 ------ login/tst-updwtmpx.c | 112 ---- login/tst-utmp.c | 377 ------------- login/tst-utmpx.c | 2 - login/updwtmp.c | 13 +- login/updwtmpx.c | 25 - login/utmp-private.h | 44 -- login/utmp_file.c | 506 ------------------ login/utmpname.c | 57 +- login/utmpxname.c | 25 - malloc/set-freeres.c | 6 - manual/users.texi | 446 ++------------- sysdeps/generic/paths.h | 6 +- sysdeps/gnu/Makefile | 13 - sysdeps/gnu/getutmp.c | 34 -- sysdeps/gnu/getutmpx.c | 1 - sysdeps/gnu/updwtmp.c | 30 -- sysdeps/gnu/utmp_file.c | 30 -- sysdeps/unix/sysv/linux/paths.h | 4 +- sysdeps/unix/sysv/linux/s390/s390-32/Makefile | 5 - .../unix/sysv/linux/s390/s390-32/getutent.c | 19 +- .../unix/sysv/linux/s390/s390-32/getutent_r.c | 11 +- .../unix/sysv/linux/s390/s390-32/getutid.c | 4 +- .../unix/sysv/linux/s390/s390-32/getutid_r.c | 2 +- .../unix/sysv/linux/s390/s390-32/getutline.c | 4 +- .../sysv/linux/s390/s390-32/getutline_r.c | 2 +- .../unix/sysv/linux/s390/s390-32/getutmp.c | 20 +- .../unix/sysv/linux/s390/s390-32/getutxent.c | 29 - .../unix/sysv/linux/s390/s390-32/getutxid.c | 29 - .../unix/sysv/linux/s390/s390-32/getutxline.c | 29 - sysdeps/unix/sysv/linux/s390/s390-32/login.c | 1 + .../unix/sysv/linux/s390/s390-32/login32.c | 37 -- .../unix/sysv/linux/s390/s390-32/pututxline.c | 29 - .../unix/sysv/linux/s390/s390-32/updwtmp.c | 6 +- .../unix/sysv/linux/s390/s390-32/updwtmpx.c | 29 - .../sysv/linux/s390/s390-32/utmp-convert.h | 85 --- sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c | 183 ------- sysdeps/unix/sysv/linux/s390/s390-32/utmp32.h | 51 -- .../sysv/linux/s390/s390-32/utmpx-convert.h | 84 --- .../unix/sysv/linux/s390/s390-32/utmpx32.c | 138 ----- .../unix/sysv/linux/s390/s390-32/utmpx32.h | 59 -- sysdeps/unix/sysv/linux/utmp_file.c | 36 -- 65 files changed, 169 insertions(+), 3508 deletions(-) delete mode 100644 login/endutxent.c delete mode 100644 login/getutmpx.c delete mode 100644 login/getutxent.c delete mode 100644 login/getutxid.c delete mode 100644 login/getutxline.c delete mode 100644 login/programs/utmpdump.c delete mode 100644 login/pututxline.c delete mode 100644 login/setutxent.c delete mode 100644 login/tst-pututxline-cache.c delete mode 100644 login/tst-pututxline-lockfail.c delete mode 100644 login/tst-updwtmpx.c delete mode 100644 login/tst-utmp.c delete mode 100644 login/tst-utmpx.c delete mode 100644 login/updwtmpx.c delete mode 100644 login/utmp-private.h delete mode 100644 login/utmp_file.c delete mode 100644 login/utmpxname.c delete mode 100644 sysdeps/gnu/getutmp.c delete mode 100644 sysdeps/gnu/getutmpx.c delete mode 100644 sysdeps/gnu/updwtmp.c delete mode 100644 sysdeps/gnu/utmp_file.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/getutxent.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/getutxid.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/getutxline.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/login32.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/pututxline.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/updwtmpx.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/utmp-convert.h delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/utmp32.h delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/utmpx-convert.h delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.h delete mode 100644 sysdeps/unix/sysv/linux/utmp_file.c diff --git a/NEWS b/NEWS index d488874aba..45fe1ad4b6 100644 --- a/NEWS +++ b/NEWS @@ -27,7 +27,27 @@ Major new features: Deprecated and removed features, and other changes affecting compatibility: - [Add deprecations, removals and changes affecting compatibility here] +* The user accounting database functions are now deprecated and do not + access or update the database files. The interface was not updated to + support 64 bit time_t on all architectures, on legacy 32 bit time_t + architectures the database is also incompatible when 64 bit time_t is + used, and the implementation has some design flaws that is not easy + fixable without a complete rewrite (BZ #24492). + + It affects the obsolete functions login, logout, logwtmp, updwtmp, utmpname, + getutent, setutent, endutent, getutid, getutline, pututline, getutent_r, + getutid_r, and getutline_r along with POSIX defined setutxent, endutxent, + getutxent, getutxid, getutxline, pututxline, and GNU extension utmpxname, + updwtmpx, getutmp, and getutmpx. + + The function now are no-op and always returns an error or invalid result + and set errno accordingly (when applicable). No compatibility support + is provided, newer system deployments are moving to use different user + accounting API where the old file are not guaranteed to exist. + + More information of alternative solutions and how to adapt applications + on newer accounting database support can be found at + https://www.thkukuk.de/blog/Y2038_glibc_utmp_64bit/. Changes to build and runtime requirements: diff --git a/include/set-freeres.h b/include/set-freeres.h index 4177b453fa..0aadb4ea7f 100644 --- a/include/set-freeres.h +++ b/include/set-freeres.h @@ -100,9 +100,6 @@ extern struct netaddr * __libc_resolv_res_hconf_freemem_ptr attribute_hidden; extern char * __libc_fgetspent_freemem_ptr attribute_hidden; extern __time64_t * __libc_tzfile_freemem_ptr attribute_hidden; extern char * __libc_getnameinfo_freemem_ptr attribute_hidden; -extern struct utmp * __libc_getutent_freemem_ptr attribute_hidden; -extern struct utmp * __libc_getutid_freemem_ptr attribute_hidden; -extern struct utmp * __libc_getutline_freemem_ptr attribute_hidden; extern printf_arginfo_size_function ** __libc_reg_printf_freemem_ptr attribute_hidden; extern printf_va_arg_function ** __libc_reg_type_freemem_ptr diff --git a/include/utmp.h b/include/utmp.h index b7921e5fb8..b16c856357 100644 --- a/include/utmp.h +++ b/include/utmp.h @@ -3,36 +3,7 @@ # ifndef _ISOMAC -/* Now define the internal interfaces. */ -extern void __updwtmp (const char *__wtmp_file, const struct utmp *__utmp); -libc_hidden_proto (__updwtmp) -extern int __utmpname (const char *__file); -libc_hidden_proto (__utmpname) -extern struct utmp *__getutent (void); -libc_hidden_proto (__getutent) -extern void __setutent (void); -libc_hidden_proto (__setutent) -extern void __endutent (void); -libc_hidden_proto (__endutent) -extern struct utmp *__getutid (const struct utmp *__id); -libc_hidden_proto (__getutid) -extern struct utmp *__getutline (const struct utmp *__line); -libc_hidden_proto (__getutline) -extern struct utmp *__pututline (const struct utmp *__utmp_ptr); -libc_hidden_proto (__pututline) -extern int __getutent_r (struct utmp *__buffer, struct utmp **__result); -libc_hidden_proto (__getutent_r) -extern int __getutid_r (const struct utmp *__id, struct utmp *__buffer, - struct utmp **__result); -libc_hidden_proto (__getutid_r) -extern int __getutline_r (const struct utmp *__line, - struct utmp *__buffer, struct utmp **__result); -libc_hidden_proto (__getutline_r) - -libc_hidden_proto (login) libc_hidden_proto (login_tty) -libc_hidden_proto (logout) -libc_hidden_proto (logwtmp) # endif /* !_ISOMAC */ #endif diff --git a/login/Makefile b/login/Makefile index 679a69e4d9..963be0cedc 100644 --- a/login/Makefile +++ b/login/Makefile @@ -42,6 +42,7 @@ routines := \ getutid_r \ getutline \ getutline_r \ + getutmp \ grantpt \ login \ login_tty \ @@ -53,14 +54,11 @@ routines := \ setlogin \ unlockpt \ updwtmp \ - utmp_file \ utmpname \ # routines CFLAGS-grantpt.c += -DLIBEXECDIR='"$(libexecdir)"' -others = utmpdump - ifeq (yes,$(build-pt-chown)) others += \ pt_chown \ @@ -78,15 +76,10 @@ tests := \ tst-getlogin \ tst-grantpt \ tst-ptsname \ - tst-pututxline-cache \ - tst-pututxline-lockfail \ - tst-updwtmpx \ - tst-utmp \ tst-utmp-size \ tst-utmp-size-64 \ tst-utmp-unsigned \ tst-utmp-unsigned-64 \ - tst-utmpx \ # tests CFLAGS-tst-utmp-size-64.c += -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 diff --git a/login/endutxent.c b/login/endutxent.c deleted file mode 100644 index d104dc538c..0000000000 --- a/login/endutxent.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -void -endutxent (void) -{ - __endutent (); -} diff --git a/login/getutent.c b/login/getutent.c index 37f90d41c0..4f0afec7e8 100644 --- a/login/getutent.c +++ b/login/getutent.c @@ -15,33 +15,15 @@ License along with the GNU C Library; if not, see . */ -#include +#include #include -#include - - -/* Local buffer to store the result. */ -static struct utmp *buffer; - struct utmp * __getutent (void) { - struct utmp *result; - - if (buffer == NULL) - { - buffer = (struct utmp *) malloc (sizeof (struct utmp)); - if (buffer == NULL) - return NULL; - } - - if (__getutent_r (buffer, &result) < 0) - return NULL; - - return result; + return NULL; } -libc_hidden_def (__getutent) weak_alias (__getutent, getutent) - -weak_alias (buffer, __libc_getutent_freemem_ptr) +weak_alias (__getutent, getutxent) +stub_warning (getutent) +stub_warning (getutxent) diff --git a/login/getutent_r.c b/login/getutent_r.c index 38bed4f23d..2edaac969d 100644 --- a/login/getutent_r.c +++ b/login/getutent_r.c @@ -19,7 +19,6 @@ #include #include -#include "utmp-private.h" /* We need to protect the opening of the file. */ __libc_lock_define_initialized (, __libc_utmp_lock attribute_hidden) @@ -28,58 +27,38 @@ __libc_lock_define_initialized (, __libc_utmp_lock attribute_hidden) void __setutent (void) { - __libc_lock_lock (__libc_utmp_lock); - - __libc_setutent (); - - __libc_lock_unlock (__libc_utmp_lock); } -libc_hidden_def (__setutent) weak_alias (__setutent, setutent) +weak_alias (__setutent, setutxent) +stub_warning (setutent) +stub_warning (setutxent) int __getutent_r (struct utmp *buffer, struct utmp **result) { - int retval; - - __libc_lock_lock (__libc_utmp_lock); - - retval = __libc_getutent_r (buffer, result); - - __libc_lock_unlock (__libc_utmp_lock); - - return retval; + errno = ENOTSUP; + return -1; } -libc_hidden_def (__getutent_r) weak_alias (__getutent_r, getutent_r) +stub_warning (getutent_r) struct utmp * __pututline (const struct utmp *data) { - struct utmp *buffer; - - __libc_lock_lock (__libc_utmp_lock); - - buffer = __libc_pututline (data); - - __libc_lock_unlock (__libc_utmp_lock); - - return buffer; + return NULL; } -libc_hidden_def (__pututline) weak_alias (__pututline, pututline) +weak_alias (__pututline, pututxline) +stub_warning (pututline) +stub_warning (pututxline) void __endutent (void) { - __libc_lock_lock (__libc_utmp_lock); - - __libc_endutent (); - - __libc_lock_unlock (__libc_utmp_lock); } -libc_hidden_def (__endutent) weak_alias (__endutent, endutent) +weak_alias (__endutent, endutxent) +stub_warning (endutent) diff --git a/login/getutid.c b/login/getutid.c index b2c820d314..69b4b87c15 100644 --- a/login/getutid.c +++ b/login/getutid.c @@ -15,30 +15,15 @@ License along with the GNU C Library; if not, see . */ -#include +#include #include -#include - -/* Local buffer to store the result. */ -static struct utmp *buffer; struct utmp * __getutid (const struct utmp *id) { - struct utmp *result; - - if (buffer == NULL) - { - buffer = (struct utmp *) malloc (sizeof (struct utmp)); - if (buffer == NULL) - return NULL; - } - if (__getutid_r (id, buffer, &result) < 0) - return NULL; - - return result; + return NULL; } -libc_hidden_def (__getutid) weak_alias (__getutid, getutid) - -weak_alias (buffer, __libc_getutid_freemem_ptr) +weak_alias (__getutid, getutxid) +stub_warning (getutid) +stub_warning (getutxid) diff --git a/login/getutid_r.c b/login/getutid_r.c index 00c078537d..ff375ee373 100644 --- a/login/getutid_r.c +++ b/login/getutid_r.c @@ -15,42 +15,14 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include #include -#include "utmp-private.h" - - -/* We have to use the lock in getutent_r.c. */ -__libc_lock_define (extern, __libc_utmp_lock attribute_hidden) - - int __getutid_r (const struct utmp *id, struct utmp *buffer, struct utmp **result) { - int retval; - - /* Test whether ID has any of the legal types. */ - if (id->ut_type != RUN_LVL && id->ut_type != BOOT_TIME - && id->ut_type != OLD_TIME && id->ut_type != NEW_TIME - && id->ut_type != INIT_PROCESS && id->ut_type != LOGIN_PROCESS - && id->ut_type != USER_PROCESS && id->ut_type != DEAD_PROCESS) - /* No, using '<' and '>' for the test is not possible. */ - { - __set_errno (EINVAL); - *result = NULL; - return -1; - } - - __libc_lock_lock (__libc_utmp_lock); - - retval = __libc_getutid_r (id, buffer, result); - - __libc_lock_unlock (__libc_utmp_lock); - - return retval; + errno = ENOTSUP; + return -1; } -libc_hidden_def (__getutid_r) weak_alias (__getutid_r, getutid_r) +stub_warning (getutid_r) diff --git a/login/getutline.c b/login/getutline.c index caf19b184b..189b95f678 100644 --- a/login/getutline.c +++ b/login/getutline.c @@ -15,32 +15,15 @@ License along with the GNU C Library; if not, see . */ -#include +#include #include -#include - - -/* Local buffer to store the result. */ -static struct utmp *buffer; - struct utmp * __getutline (const struct utmp *line) { - struct utmp *result; - - if (buffer == NULL) - { - buffer = (struct utmp *) malloc (sizeof (struct utmp)); - if (buffer == NULL) - return NULL; - } - if (__getutline_r (line, buffer, &result) < 0) - return NULL; - - return result; + return NULL; } -libc_hidden_def (__getutline) weak_alias (__getutline, getutline) - -weak_alias (buffer, __libc_getutline_freemem_ptr) +weak_alias (__getutline, getutxline) +stub_warning (getutline) +stub_warning (getutxline) diff --git a/login/getutline_r.c b/login/getutline_r.c index 37fa82d730..d59a8e963a 100644 --- a/login/getutline_r.c +++ b/login/getutline_r.c @@ -16,29 +16,14 @@ . */ #include -#include #include -#include "utmp-private.h" - - -/* We have to use the lock in getutent_r.c. */ -__libc_lock_define (extern, __libc_utmp_lock attribute_hidden) - - int __getutline_r (const struct utmp *line, struct utmp *buffer, struct utmp **result) { - int retval; - - __libc_lock_lock (__libc_utmp_lock); - - retval = __libc_getutline_r (line, buffer, result); - - __libc_lock_unlock (__libc_utmp_lock); - - return retval; + errno = ENOTSUP; + return -1; } -libc_hidden_def (__getutline_r) weak_alias (__getutline_r, getutline_r) +stub_warning (getutline_r) diff --git a/login/getutmp.c b/login/getutmp.c index e7bed2f8ac..dccb8b401a 100644 --- a/login/getutmp.c +++ b/login/getutmp.c @@ -17,17 +17,15 @@ #include #include +#define getutmpx __redirect_getutmpx #include +#undef getutmpx /* Copy the information in UTMPX to UTMP. */ void getutmp (const struct utmpx *utmpx, struct utmp *utmp) { - utmp->ut_type = utmpx->ut_type; - utmp->ut_pid = utmpx->ut_pid; - memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line)); - memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user)); - memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id)); - memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host)); - utmp->ut_tv = utmpx->ut_tv; } +weak_alias (getutmp, getutmpx) +stub_warning (getutmp) +stub_warning (getutmpx) diff --git a/login/getutmpx.c b/login/getutmpx.c deleted file mode 100644 index 5e3fdcf825..0000000000 --- a/login/getutmpx.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1999-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -/* Copy the information in UTMP to UTMPX. */ -void -getutmpx (const struct utmp *utmp, struct utmpx *utmpx) -{ - memset (utmpx, 0, sizeof (struct utmpx)); - utmpx->ut_type = utmp->ut_type; - utmpx->ut_pid = utmp->ut_pid; - memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line)); - memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user)); - memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id)); - memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host)); - utmpx->ut_tv = utmp->ut_tv; -} diff --git a/login/getutxent.c b/login/getutxent.c deleted file mode 100644 index e928a8daeb..0000000000 --- a/login/getutxent.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -struct utmpx * -getutxent (void) -{ - return (struct utmpx *) __getutent (); -} diff --git a/login/getutxid.c b/login/getutxid.c deleted file mode 100644 index 2ea53e6218..0000000000 --- a/login/getutxid.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -struct utmpx * -getutxid (const struct utmpx *id) -{ - return (struct utmpx *) __getutid ((const struct utmp *) id); -} diff --git a/login/getutxline.c b/login/getutxline.c deleted file mode 100644 index ff667944bb..0000000000 --- a/login/getutxline.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -struct utmpx * -getutxline (const struct utmpx *line) -{ - return (struct utmpx *) __getutline ((const struct utmp *) line); -} diff --git a/login/login.c b/login/login.c index 6ded8f0a0c..ce63a0225b 100644 --- a/login/login.c +++ b/login/login.c @@ -15,129 +15,15 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include -#include -#include #include +#include -/* Return the result of ttyname in the buffer pointed to by TTY, which should - be of length BUF_LEN. If it is too long to fit in this buffer, a - sufficiently long buffer is allocated using malloc, and returned in TTY. - 0 is returned upon success, -1 otherwise. */ -static int -tty_name (int fd, char **tty, size_t buf_len) -{ - int rv; /* Return value. 0 = success. */ - char *buf = *tty; /* Buffer for ttyname, initially the user's. */ - - for (;;) - { - char *new_buf; - - if (buf_len) - { - rv = __ttyname_r (fd, buf, buf_len); - - if (rv != 0 || memchr (buf, '\0', buf_len)) - /* We either got an error, or we succeeded and the - returned name fit in the buffer. */ - break; - - /* Try again with a longer buffer. */ - buf_len += buf_len; /* Double it */ - } - else - /* No initial buffer; start out by mallocing one. */ - buf_len = 128; /* First time guess. */ - - if (buf != *tty) - /* We've already malloced another buffer at least once. */ - new_buf = realloc (buf, buf_len); - else - new_buf = malloc (buf_len); - if (! new_buf) - { - rv = -1; - __set_errno (ENOMEM); - break; - } - buf = new_buf; - } - - if (rv == 0) - *tty = buf; /* Return buffer to the user. */ - else if (buf != *tty) - free (buf); /* Free what we malloced when returning an error. */ - - return rv; -} - void __login (const struct utmp *ut) { -#ifdef PATH_MAX - char _tty[PATH_MAX + UT_LINESIZE]; -#else - char _tty[512 + UT_LINESIZE]; -#endif - char *tty = _tty; - int found_tty; - const char *ttyp; - struct utmp copy = *ut; - - /* Fill in those fields we supply. */ - copy.ut_type = USER_PROCESS; - copy.ut_pid = getpid (); - - /* Seek tty. */ - found_tty = tty_name (STDIN_FILENO, &tty, sizeof (_tty)); - if (found_tty < 0) - found_tty = tty_name (STDOUT_FILENO, &tty, sizeof (_tty)); - if (found_tty < 0) - found_tty = tty_name (STDERR_FILENO, &tty, sizeof (_tty)); - - if (found_tty >= 0) - { - /* We only want to insert the name of the tty without path. - But take care of name like /dev/pts/3. */ - if (strncmp (tty, "/dev/", 5) == 0) - ttyp = tty + 5; /* Skip the "/dev/". */ - else - ttyp = basename (tty); - - /* Position to record for this tty. */ - strncpy (copy.ut_line, ttyp, UT_LINESIZE); - - /* Tell that we want to use the UTMP file. */ - if (__utmpname (_PATH_UTMP) == 0) - { - /* Open UTMP file. */ - __setutent (); - - /* Write the entry. */ - __pututline (©); - - /* Close UTMP file. */ - __endutent (); - } - - if (tty != _tty) - free (tty); /* Free buffer malloced by tty_name. */ - } - else - /* We provide a default value so that the output does not contain - an random bytes in this field. */ - strncpy (copy.ut_line, "???", UT_LINESIZE); - - /* Update the WTMP file. Here we have to add a new entry. */ - __updwtmp (_PATH_WTMP, ©); } versioned_symbol (libc, __login, login, GLIBC_2_34); -libc_hidden_ver (__login, login) +stub_warning (login) #if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) compat_symbol (libutil, __login, login, GLIBC_2_0); diff --git a/login/logout.c b/login/logout.c index d839bb7ae8..1be186ad87 100644 --- a/login/logout.c +++ b/login/logout.c @@ -16,53 +16,17 @@ . */ #include -#include -#include -#include -#include #include +#include int __logout (const char *line) { - struct utmp tmp, utbuf; - struct utmp *ut; - int result = 0; - - /* Tell that we want to use the UTMP file. */ - if (__utmpname (_PATH_UTMP) == -1) - return 0; - - /* Open UTMP file. */ - __setutent (); - - /* Fill in search information. */ - tmp.ut_type = USER_PROCESS; - strncpy (tmp.ut_line, line, sizeof tmp.ut_line); - - /* Read the record. */ - if (__getutline_r (&tmp, &utbuf, &ut) >= 0) - { - /* Clear information about who & from where. */ - memset (ut->ut_name, '\0', sizeof ut->ut_name); - memset (ut->ut_host, '\0', sizeof ut->ut_host); - - struct __timespec64 ts; - __clock_gettime64 (CLOCK_REALTIME, &ts); - TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts); - ut->ut_type = DEAD_PROCESS; - - if (__pututline (ut) != NULL) - result = 1; - } - - /* Close UTMP file. */ - __endutent (); - - return result; + errno = ENOTSUP; + return -1; } versioned_symbol (libc, __logout, logout, GLIBC_2_34); -libc_hidden_ver (__logout, logout) +stub_warning (logout) #if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) compat_symbol (libutil, __logout, logout, GLIBC_2_0); diff --git a/login/logwtmp.c b/login/logwtmp.c index 6f9d7b0616..f77f7f54cf 100644 --- a/login/logwtmp.c +++ b/login/logwtmp.c @@ -15,35 +15,15 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include #include -#include #include void __logwtmp (const char *line, const char *name, const char *host) { - struct utmp ut; - - /* Set information in new entry. */ - memset (&ut, 0, sizeof (ut)); - ut.ut_pid = getpid (); - ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS; - strncpy (ut.ut_line, line, sizeof ut.ut_line); - strncpy (ut.ut_name, name, sizeof ut.ut_name); - strncpy (ut.ut_host, host, sizeof ut.ut_host); - - struct __timespec64 ts; - __clock_gettime64 (CLOCK_REALTIME, &ts); - TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts); - - __updwtmp (_PATH_WTMP, &ut); } versioned_symbol (libc, __logwtmp, logwtmp, GLIBC_2_34); -libc_hidden_ver (__logwtmp, logwtmp) +stub_warning (logwtmp) #if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) compat_symbol (libutil, __logwtmp, logwtmp, GLIBC_2_0); diff --git a/login/programs/utmpdump.c b/login/programs/utmpdump.c deleted file mode 100644 index 1a723f3b67..0000000000 --- a/login/programs/utmpdump.c +++ /dev/null @@ -1,62 +0,0 @@ -/* utmpdump - dump utmp-like files. - Copyright (C) 1997-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include - -static void -print_entry (struct utmp *up) -{ - /* Mixed 32-/64-bit systems may have timeval structs of different sixe - but need struct utmp to be the same size. So in 64-bit up->ut_tv may - not be a timeval but a struct of __int32_t's. This would cause a compile - time warning and a formatting error when 32-bit int is passed where - a 64-bit long is expected. So copy up->up_tv to a temporary timeval. - This is 32-/64-bit agnostic and expands the timeval fields to the - expected size as needed. */ - struct timeval temp_tv; - temp_tv.tv_sec = up->ut_tv.tv_sec; - temp_tv.tv_usec = up->ut_tv.tv_usec; - - printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-16.16s] [%-15.15s]" - " [%ld]\n", - up->ut_type, up->ut_pid, up->ut_id, up->ut_user, up->ut_line, - up->ut_host, 4 + ctime (&temp_tv.tv_sec), - (long int) temp_tv.tv_usec); -} - -int -main (int argc, char *argv[]) -{ - struct utmp *up; - - if (argc > 1) - utmpname (argv[1]); - - setutent (); - - while ((up = getutent ())) - print_entry (up); - - endutent (); - - return EXIT_SUCCESS; -} diff --git a/login/pututxline.c b/login/pututxline.c deleted file mode 100644 index c2f13def00..0000000000 --- a/login/pututxline.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -struct utmpx * -pututxline (const struct utmpx *utmpx) -{ - return (struct utmpx *) __pututline ((const struct utmp *) utmpx); -} diff --git a/login/setutxent.c b/login/setutxent.c deleted file mode 100644 index 68807d9e36..0000000000 --- a/login/setutxent.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -void -setutxent (void) -{ - return __setutent (); -} diff --git a/login/tst-pututxline-cache.c b/login/tst-pututxline-cache.c deleted file mode 100644 index cca068cfe0..0000000000 --- a/login/tst-pututxline-cache.c +++ /dev/null @@ -1,193 +0,0 @@ -/* Test case for cache invalidation after concurrent write (bug 24882). - Copyright (C) 2019-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; see the file COPYING.LIB. If - not, see . */ - -/* This test writes an entry to the utmpx file, reads it (so that it - is cached) in process1, and overwrites the same entry in process2 - with something that does not match the search criteria. At this - point, the cache of the first process is stale, and when process1 - attempts to write a new record which would have gone to the same - place (as indicated by the cache), it needs to realize that it has - to pick a different slot because the old slot is now used for - something else. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Set to the path of the utmp file. */ -static char *utmp_file; - -/* Used to synchronize the subprocesses. The barrier itself is - allocated in shared memory. */ -static pthread_barrier_t *barrier; - -/* setutxent with error checking. */ -static void -xsetutxent (void) -{ - errno = 0; - setutxent (); - TEST_COMPARE (errno, 0); -} - -/* getutxent with error checking. */ -static struct utmpx * -xgetutxent (void) -{ - errno = 0; - struct utmpx *result = getutxent (); - if (result == NULL) - FAIL_EXIT1 ("getutxent: %m"); - return result; -} - -static void -put_entry (const char *id, pid_t pid, const char *user, const char *line) -{ - struct utmpx ut = - { - .ut_type = LOGIN_PROCESS, - .ut_pid = pid, - .ut_host = "localhost", - }; - strcpy (ut.ut_id, id); - strncpy (ut.ut_user, user, sizeof (ut.ut_user)); - strncpy (ut.ut_line, line, sizeof (ut.ut_line)); - TEST_VERIFY (pututxline (&ut) != NULL); -} - -/* Use two cooperating subprocesses to avoid issues related to - unlock-on-close semantics of POSIX advisory locks. */ - -static __attribute__ ((noreturn)) void -process1 (void) -{ - TEST_COMPARE (utmpname (utmp_file), 0); - - /* Create an entry. */ - xsetutxent (); - put_entry ("1", 101, "root", "process1"); - - /* Retrieve the entry. This will fill the internal cache. */ - { - errno = 0; - setutxent (); - TEST_COMPARE (errno, 0); - struct utmpx ut = - { - .ut_type = LOGIN_PROCESS, - .ut_line = "process1", - }; - struct utmpx *result = getutxline (&ut); - if (result == NULL) - FAIL_EXIT1 ("getutxline (\"process1\"): %m"); - TEST_COMPARE (result->ut_pid, 101); - } - - /* Signal the other process to overwrite the entry. */ - xpthread_barrier_wait (barrier); - - /* Wait for the other process to complete the write operation. */ - xpthread_barrier_wait (barrier); - - /* Add another entry. Note: This time, there is no setutxent call. */ - put_entry ("1", 103, "root", "process1"); - - _exit (0); -} - -static void -process2 (void *closure) -{ - /* Wait for the first process to write its entry. */ - xpthread_barrier_wait (barrier); - - /* Truncate the file. The glibc interface does not support - re-purposing records, but an external expiration mechanism may - trigger this. */ - TEST_COMPARE (truncate64 (utmp_file, 0), 0); - - /* Write the replacement entry. */ - TEST_COMPARE (utmpname (utmp_file), 0); - xsetutxent (); - put_entry ("2", 102, "user", "process2"); - - /* Signal the other process that the entry has been replaced. */ - xpthread_barrier_wait (barrier); -} - -static int -do_test (void) -{ - xclose (create_temp_file ("tst-tumpx-cache-write-", &utmp_file)); - { - pthread_barrierattr_t attr; - xpthread_barrierattr_init (&attr); - xpthread_barrierattr_setpshared (&attr, PTHREAD_SCOPE_PROCESS); - barrier = support_shared_allocate (sizeof (*barrier)); - xpthread_barrier_init (barrier, &attr, 2); - } - - /* Run both subprocesses in parallel. */ - { - pid_t pid1 = xfork (); - if (pid1 == 0) - process1 (); - support_isolate_in_subprocess (process2, NULL); - int status; - xwaitpid (pid1, &status, 0); - TEST_COMPARE (status, 0); - } - - /* Check that the utmpx database contains the expected records. */ - { - TEST_COMPARE (utmpname (utmp_file), 0); - xsetutxent (); - - struct utmpx *ut = xgetutxent (); - TEST_COMPARE_STRING (ut->ut_id, "2"); - TEST_COMPARE (ut->ut_pid, 102); - TEST_COMPARE_STRING (ut->ut_user, "user"); - TEST_COMPARE_STRING (ut->ut_line, "process2"); - - ut = xgetutxent (); - TEST_COMPARE_STRING (ut->ut_id, "1"); - TEST_COMPARE (ut->ut_pid, 103); - TEST_COMPARE_STRING (ut->ut_user, "root"); - TEST_COMPARE_STRING (ut->ut_line, "process1"); - - if (getutxent () != NULL) - FAIL_EXIT1 ("additional utmpx entry"); - } - - xpthread_barrier_destroy (barrier); - support_shared_free (barrier); - free (utmp_file); - - return 0; -} - -#include diff --git a/login/tst-pututxline-lockfail.c b/login/tst-pututxline-lockfail.c deleted file mode 100644 index de230dd4fa..0000000000 --- a/login/tst-pututxline-lockfail.c +++ /dev/null @@ -1,176 +0,0 @@ -/* Test the lock upgrade path in tst-pututxline. - Copyright (C) 2019-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; see the file COPYING.LIB. If - not, see . */ - -/* pututxline upgrades the read lock on the file to a write lock. - This test verifies that if the lock upgrade fails, the utmp - subsystem remains in a consistent state, so that pututxline can be - called again. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Path to the temporary utmp file. */ -static char *path; - -/* Used to synchronize the subprocesses. The barrier itself is - allocated in shared memory. */ -static pthread_barrier_t *barrier; - -/* Use pututxline to write an entry for PID. */ -static struct utmpx * -write_entry (pid_t pid) -{ - struct utmpx ut = - { - .ut_type = LOGIN_PROCESS, - .ut_id = "1", - .ut_user = "root", - .ut_pid = pid, - .ut_line = "entry", - .ut_host = "localhost", - }; - return pututxline (&ut); -} - -/* Create the initial entry in a subprocess, so that the utmp - subsystem in the original process is not disturbed. */ -static void -subprocess_create_entry (void *closure) -{ - TEST_COMPARE (utmpname (path), 0); - TEST_VERIFY (write_entry (101) != NULL); -} - -/* Acquire an advisory read lock on PATH. */ -__attribute__ ((noreturn)) static void -subprocess_lock_file (void) -{ - int fd = xopen (path, O_RDONLY, 0); - - struct flock64 fl = - { - .l_type = F_RDLCK, - fl.l_whence = SEEK_SET, - }; - TEST_COMPARE (fcntl64 (fd, F_SETLKW, &fl), 0); - - /* Signal to the main process that the lock has been acquired. */ - xpthread_barrier_wait (barrier); - - /* Wait for the unlock request from the main process. */ - xpthread_barrier_wait (barrier); - - /* Implicitly unlock the file. */ - xclose (fd); - - /* Overwrite the existing entry. */ - TEST_COMPARE (utmpname (path), 0); - errno = 0; - setutxent (); - TEST_COMPARE (errno, 0); - TEST_VERIFY (write_entry (102) != NULL); - errno = 0; - endutxent (); - TEST_COMPARE (errno, 0); - - _exit (0); -} - -static int -do_test (void) -{ - xclose (create_temp_file ("tst-pututxline-lockfail-", &path)); - - { - pthread_barrierattr_t attr; - xpthread_barrierattr_init (&attr); - xpthread_barrierattr_setpshared (&attr, PTHREAD_SCOPE_PROCESS); - barrier = support_shared_allocate (sizeof (*barrier)); - xpthread_barrier_init (barrier, &attr, 2); - xpthread_barrierattr_destroy (&attr); - } - - /* Write the initial entry. */ - support_isolate_in_subprocess (subprocess_create_entry, NULL); - - pid_t locker_pid = xfork (); - if (locker_pid == 0) - subprocess_lock_file (); - - /* Wait for the file locking to complete. */ - xpthread_barrier_wait (barrier); - - /* Try to add another entry. This attempt will fail, with EINTR or - EAGAIN. */ - TEST_COMPARE (utmpname (path), 0); - TEST_VERIFY (write_entry (102) == NULL); - if (errno != EINTR) - TEST_COMPARE (errno, EAGAIN); - - /* Signal the subprocess to overwrite the entry. */ - xpthread_barrier_wait (barrier); - - /* Wait for write and unlock to complete. */ - { - int status; - xwaitpid (locker_pid, &status, 0); - TEST_COMPARE (status, 0); - } - - /* The file is no longer locked, so this operation will succeed. */ - TEST_VERIFY (write_entry (103) != NULL); - errno = 0; - endutxent (); - TEST_COMPARE (errno, 0); - - /* Check that there is just one entry with the expected contents. - If pututxline becomes desynchronized internally, the entry is not - overwritten (bug 24902). */ - errno = 0; - setutxent (); - TEST_COMPARE (errno, 0); - struct utmpx *ut = getutxent (); - TEST_VERIFY_EXIT (ut != NULL); - TEST_COMPARE (ut->ut_type, LOGIN_PROCESS); - TEST_COMPARE_STRING (ut->ut_id, "1"); - TEST_COMPARE_STRING (ut->ut_user, "root"); - TEST_COMPARE (ut->ut_pid, 103); - TEST_COMPARE_STRING (ut->ut_line, "entry"); - TEST_COMPARE_STRING (ut->ut_host, "localhost"); - TEST_VERIFY (getutxent () == NULL); - errno = 0; - endutxent (); - TEST_COMPARE (errno, 0); - - xpthread_barrier_destroy (barrier); - support_shared_free (barrier); - free (path); - return 0; -} - -#include diff --git a/login/tst-updwtmpx.c b/login/tst-updwtmpx.c deleted file mode 100644 index f8004bd33d..0000000000 --- a/login/tst-updwtmpx.c +++ /dev/null @@ -1,112 +0,0 @@ -/* Basic test coverage for updwtmpx. - Copyright (C) 2019-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; see the file COPYING.LIB. If - not, see . */ - -/* This program runs a series of tests. Each one calls updwtmpx - twice, to write two records, optionally with misalignment in the - file, and reads back the results. */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int -do_test (void) -{ - /* Two entries filled with an arbitrary bit pattern. */ - struct utmpx entries[2]; - unsigned char pad; - { - unsigned char *p = (unsigned char *) &entries[0]; - for (size_t i = 0; i < sizeof (entries); ++i) - { - p[i] = i; - } - /* Make sure that the first and second entry and the padding are - different. */ - p[sizeof (struct utmpx)] = p[0] + 1; - pad = p[0] + 2; - } - - char *path; - int fd = create_temp_file ("tst-updwtmpx-", &path); - - /* Used to check that updwtmpx does not leave an open file - descriptor around. */ - struct support_descriptors *descriptors = support_descriptors_list (); - - /* updwtmpx is expected to remove misalignment. Optionally insert - one byte of misalignment at the start and in the middle (after - the first entry). */ - for (int misaligned_start = 0; misaligned_start < 2; ++misaligned_start) - for (int misaligned_middle = 0; misaligned_middle < 2; ++misaligned_middle) - { - if (test_verbose > 0) - printf ("info: misaligned_start=%d misaligned_middle=%d\n", - misaligned_start, misaligned_middle); - - xftruncate (fd, 0); - TEST_COMPARE (pwrite64 (fd, &pad, misaligned_start, 0), - misaligned_start); - - /* Write first entry and check it. */ - errno = 0; - updwtmpx (path, &entries[0]); - TEST_COMPARE (errno, 0); - support_descriptors_check (descriptors); - TEST_COMPARE (xlseek (fd, 0, SEEK_END), sizeof (struct utmpx)); - struct utmpx buffer; - TEST_COMPARE (pread64 (fd, &buffer, sizeof (buffer), 0), - sizeof (buffer)); - TEST_COMPARE_BLOB (&entries[0], sizeof (entries[0]), - &buffer, sizeof (buffer)); - - /* Middle mis-alignmet. */ - TEST_COMPARE (pwrite64 (fd, &pad, misaligned_middle, - sizeof (struct utmpx)), misaligned_middle); - - /* Write second entry and check both entries. */ - errno = 0; - updwtmpx (path, &entries[1]); - TEST_COMPARE (errno, 0); - support_descriptors_check (descriptors); - TEST_COMPARE (xlseek (fd, 0, SEEK_END), 2 * sizeof (struct utmpx)); - TEST_COMPARE (pread64 (fd, &buffer, sizeof (buffer), 0), - sizeof (buffer)); - TEST_COMPARE_BLOB (&entries[0], sizeof (entries[0]), - &buffer, sizeof (buffer)); - TEST_COMPARE (pread64 (fd, &buffer, sizeof (buffer), sizeof (buffer)), - sizeof (buffer)); - TEST_COMPARE_BLOB (&entries[1], sizeof (entries[1]), - &buffer, sizeof (buffer)); - } - - support_descriptors_free (descriptors); - free (path); - xclose (fd); - - return 0; -} - -#include diff --git a/login/tst-utmp.c b/login/tst-utmp.c deleted file mode 100644 index d1b6d6af1b..0000000000 --- a/login/tst-utmp.c +++ /dev/null @@ -1,377 +0,0 @@ -/* Tests for UTMP functions. - Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include -#include - -#ifdef UTMPX -# include -# define utmp utmpx -# define utmpname utmpxname -# define setutent setutxent -# define getutent getutxent -# define endutent endutxent -# define getutline getutxline -# define getutid getutxid -# define pututline pututxline -#else -# include -#endif - - -/* Prototype for our test function. */ -static int do_test (int argc, char *argv[]); - -/* We have a preparation function. */ -static void do_prepare (int argc, char *argv[]); -#define PREPARE do_prepare - -/* This defines the `main' function and some more. */ -#include - - -/* These are for the temporary file we generate. */ -char *name; -int fd; - -static void -do_prepare (int argc, char *argv[]) -{ - size_t name_len; - - name_len = strlen (test_dir); - name = xmalloc (name_len + sizeof ("/utmpXXXXXX")); - mempcpy (mempcpy (name, test_dir, name_len), - "/utmpXXXXXX", sizeof ("/utmpXXXXXX")); - - /* Open our test file. */ - fd = mkstemp (name); - if (fd == -1) - error (EXIT_FAILURE, errno, "cannot open test file `%s'", name); - add_temp_file (name); -} - -struct utmp entry[] = -{ -#define UT(a) .ut_tv = { .tv_sec = (a)} - - { .ut_type = BOOT_TIME, .ut_pid = 1, UT(1000) }, - { .ut_type = RUN_LVL, .ut_pid = 1, UT(2000) }, - { .ut_type = INIT_PROCESS, .ut_pid = 5, .ut_id = "si", UT(3000) }, - { .ut_type = LOGIN_PROCESS, .ut_pid = 23, .ut_line = "tty1", .ut_id = "1", - .ut_user = "LOGIN", UT(4000) }, - { .ut_type = USER_PROCESS, .ut_pid = 24, .ut_line = "tty2", .ut_id = "2", - .ut_user = "albert", UT(8000) }, - { .ut_type = USER_PROCESS, .ut_pid = 196, .ut_line = "ttyp0", .ut_id = "p0", - .ut_user = "niels", UT(10000) }, - { .ut_type = DEAD_PROCESS, .ut_line = "ttyp1", .ut_id = "p1", UT(16000) }, - { .ut_type = EMPTY }, - { .ut_type = EMPTY } -}; -int num_entries = sizeof entry / sizeof (struct utmp); - -time_t entry_time = 20000; -pid_t entry_pid = 234; - -static int -do_init (void) -{ - int n; - - setutent (); - - for (n = 0; n < num_entries; n++) - { - if (pututline (&entry[n]) == NULL) - { - error (0, errno, "cannot write UTMP entry"); - return 1; - } - } - - endutent (); - - return 0; -} - - -static int -do_check (void) -{ - struct utmp *ut; - int n; - - setutent (); - - n = 0; - while ((ut = getutent ())) - { - if (n < num_entries - && memcmp (ut, &entry[n], sizeof (struct utmp))) - { - error (0, 0, "UTMP entry does not match"); - return 1; - } - - n++; - } - - if (n != num_entries) - { - error (0, 0, "number of UTMP entries is incorrect"); - return 1; - } - - endutent (); - - return 0; -} - -static int -simulate_login (const char *line, const char *user) -{ - int n; - - for (n = 0; n < num_entries; n++) - { - if (strcmp (line, entry[n].ut_line) == 0 - || entry[n].ut_type == DEAD_PROCESS) - { - if (entry[n].ut_pid == DEAD_PROCESS) - entry[n].ut_pid = (entry_pid += 27); - entry[n].ut_type = USER_PROCESS; - strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user)); - entry[n].ut_tv.tv_sec = (entry_time += 1000); - setutent (); - - if (pututline (&entry[n]) == NULL) - { - error (0, errno, "cannot write UTMP entry"); - return 1; - } - - endutent (); - - return 0; - } - } - - error (0, 0, "no entries available"); - return 1; -} - -static int -simulate_logout (const char *line) -{ - int n; - - for (n = 0; n < num_entries; n++) - { - if (strcmp (line, entry[n].ut_line) == 0) - { - entry[n].ut_type = DEAD_PROCESS; - strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user)); - entry[n].ut_tv.tv_sec = (entry_time += 1000); - setutent (); - - if (pututline (&entry[n]) == NULL) - { - error (0, errno, "cannot write UTMP entry"); - return 1; - } - - endutent (); - - return 0; - } - } - - error (0, 0, "no entry found for `%s'", line); - return 1; -} - -static int -check_login (const char *line) -{ - struct utmp *up; - struct utmp ut; - int n; - - setutent (); - - strcpy (ut.ut_line, line); - up = getutline (&ut); - if (up == NULL) - { - error (0, errno, "cannot get entry for line `%s'", line); - return 1; - } - - endutent (); - - for (n = 0; n < num_entries; n++) - { - if (strcmp (line, entry[n].ut_line) == 0) - { - if (memcmp (up, &entry[n], sizeof (struct utmp))) - { - error (0, 0, "UTMP entry does not match"); - return 1; - } - - return 0; - } - } - - error (0, 0, "bogus entry for line `%s'", line); - return 1; -} - -static int -check_logout (const char *line) -{ - struct utmp ut; - - setutent (); - - strcpy (ut.ut_line, line); - if (getutline (&ut) != NULL) - { - error (0, 0, "bogus login entry for `%s'", line); - return 1; - } - - endutent (); - - return 0; -} - -static int -check_id (const char *id) -{ - struct utmp *up; - struct utmp ut; - int n; - - setutent (); - - ut.ut_type = USER_PROCESS; - strcpy (ut.ut_id, id); - up = getutid (&ut); - if (up == NULL) - { - error (0, errno, "cannot get entry for ID `%s'", id); - return 1; - } - - endutent (); - - for (n = 0; n < num_entries; n++) - { - if (strcmp (id, entry[n].ut_id) == 0) - { - if (memcmp (up, &entry[n], sizeof (struct utmp))) - { - error (0, 0, "UTMP entry does not match"); - return 1; - } - - return 0; - } - } - - error (0, 0, "bogus entry for ID `%s'", id); - return 1; -} - -static int -check_type (int type) -{ - struct utmp *up; - struct utmp ut; - int n; - - setutent (); - - ut.ut_type = type; - up = getutid (&ut); - if (up == NULL) - { - error (0, errno, "cannot get entry for type `%d'", type); - return 1; - } - - endutent (); - - for (n = 0; n < num_entries; n++) - { - if (type == entry[n].ut_type) - { - if (memcmp (up, &entry[n], sizeof (struct utmp))) - { - error (0, 0, "UTMP entry does not match"); - return 1; - } - - return 0; - } - } - - error (0, 0, "bogus entry for type `%d'", type); - return 1; -} - -static int -do_test (int argc, char *argv[]) -{ - int result = 0; - - utmpname (name); - - result |= do_init (); - result |= do_check (); - - result |= simulate_login ("tty1", "erwin"); - result |= do_check (); - - result |= simulate_login ("ttyp1", "paul"); - result |= do_check (); - - result |= simulate_logout ("tty2"); - result |= do_check (); - - result |= simulate_logout ("ttyp0"); - result |= do_check (); - - result |= simulate_login ("ttyp2", "richard"); - result |= do_check (); - - result |= check_login ("tty1"); - result |= check_logout ("ttyp0"); - result |= check_id ("p1"); - result |= check_id ("2"); - result |= check_id ("si"); - result |= check_type (BOOT_TIME); - result |= check_type (RUN_LVL); - - return result; -} diff --git a/login/tst-utmpx.c b/login/tst-utmpx.c deleted file mode 100644 index edb5551d71..0000000000 --- a/login/tst-utmpx.c +++ /dev/null @@ -1,2 +0,0 @@ -#define UTMPX -#include "tst-utmp.c" diff --git a/login/updwtmp.c b/login/updwtmp.c index 4a28573077..0f6fa93818 100644 --- a/login/updwtmp.c +++ b/login/updwtmp.c @@ -17,18 +17,11 @@ #include -#include "utmp-private.h" - -#ifndef TRANSFORM_UTMP_FILE_NAME -# define TRANSFORM_UTMP_FILE_NAME(file_name) (file_name) -#endif - void __updwtmp (const char *wtmp_file, const struct utmp *utmp) { - const char *file_name = TRANSFORM_UTMP_FILE_NAME (wtmp_file); - - __libc_updwtmp (file_name, utmp); } -libc_hidden_def (__updwtmp) weak_alias (__updwtmp, updwtmp) +weak_alias (__updwtmp, updwtmpx) +stub_warning (updwtmp) +stub_warning (updwtmpx) diff --git a/login/updwtmpx.c b/login/updwtmpx.c deleted file mode 100644 index 099000e391..0000000000 --- a/login/updwtmpx.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -void -updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) -{ - __updwtmp (wtmpx_file, (const struct utmp *) utmpx); -} diff --git a/login/utmp-private.h b/login/utmp-private.h deleted file mode 100644 index 557f413ace..0000000000 --- a/login/utmp-private.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Internal definitions and declarations for UTMP functions. - Copyright (C) 1996-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _UTMP_PRIVATE_H -#define _UTMP_PRIVATE_H 1 - -#include -#include - -/* These functions check for initialization, but not perform any - locking. */ -int __libc_setutent (void) attribute_hidden; -int __libc_getutent_r (struct utmp *, struct utmp **) attribute_hidden; -int __libc_getutid_r (const struct utmp *, struct utmp *, struct utmp **) - attribute_hidden; -int __libc_getutline_r (const struct utmp *, struct utmp *, struct utmp **) - attribute_hidden; -struct utmp *__libc_pututline (const struct utmp *) attribute_hidden; -void __libc_endutent (void) attribute_hidden; -int __libc_updwtmp (const char *, const struct utmp *) attribute_hidden; - -/* Current file name. */ -extern const char *__libc_utmp_file_name attribute_hidden; - -/* Locks access to the global data. */ -__libc_lock_define (extern, __libc_utmp_lock attribute_hidden) - - -#endif /* utmp-private.h */ diff --git a/login/utmp_file.c b/login/utmp_file.c deleted file mode 100644 index 68a40831bc..0000000000 --- a/login/utmp_file.c +++ /dev/null @@ -1,506 +0,0 @@ -/* Copyright (C) 1996-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utmp-private.h" -#include "utmp-equal.h" - - -/* Descriptor for the file and position. */ -static int file_fd = -1; -static bool file_writable; -static off64_t file_offset; - -/* Cache for the last read entry. */ -static struct utmp last_entry; - -/* Returns true if *ENTRY matches last_entry, based on - data->ut_type. */ -static bool -matches_last_entry (const struct utmp *data) -{ - if (file_offset <= 0) - /* Nothing has been read. last_entry is stale and cannot match. */ - return false; - - if (data->ut_type == RUN_LVL - || data->ut_type == BOOT_TIME - || data->ut_type == OLD_TIME - || data->ut_type == NEW_TIME) - /* For some entry types, only a type match is required. */ - return data->ut_type == last_entry.ut_type; - else - /* For the process-related entries, a full match is needed. */ - return __utmp_equal (&last_entry, data); -} - -/* Locking timeout. */ -#ifndef TIMEOUT -# define TIMEOUT 10 -#endif - -/* Do-nothing handler for locking timeout. */ -static void timeout_handler (int signum) {}; - - -/* try_file_lock (LOCKING, FD, TYPE) returns true if the locking - operation failed and recovery needs to be performed. - - file_unlock (FD) removes the lock (which must have been - successfully acquired). */ - -static bool -try_file_lock (int fd, int type) -{ - /* Cancel any existing alarm. */ - int old_timeout = alarm (0); - - /* Establish signal handler. */ - struct sigaction old_action; - struct sigaction action; - action.sa_handler = timeout_handler; - __sigemptyset (&action.sa_mask); - action.sa_flags = 0; - __sigaction (SIGALRM, &action, &old_action); - - alarm (TIMEOUT); - - /* Try to get the lock. */ - struct flock64 fl = - { - .l_type = type, - .l_whence = SEEK_SET, - }; - - bool status = __fcntl64_nocancel (fd, F_SETLKW, &fl) < 0; - int saved_errno = errno; - - /* Reset the signal handler and alarm. We must reset the alarm - before resetting the handler so our alarm does not generate a - spurious SIGALRM seen by the user. However, we cannot just set - the user's old alarm before restoring the handler, because then - it's possible our handler could catch the user alarm's SIGARLM and - then the user would never see the signal he expected. */ - alarm (0); - __sigaction (SIGALRM, &old_action, NULL); - if (old_timeout != 0) - alarm (old_timeout); - - __set_errno (saved_errno); - return status; -} - -static void -file_unlock (int fd) -{ - struct flock64 fl = - { - .l_type = F_UNLCK, - }; - __fcntl64_nocancel (fd, F_SETLKW, &fl); -} - -#ifndef TRANSFORM_UTMP_FILE_NAME -# define TRANSFORM_UTMP_FILE_NAME(file_name) (file_name) -#endif - -int -__libc_setutent (void) -{ - if (file_fd < 0) - { - const char *file_name; - - file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name); - - file_writable = false; - file_fd = __open_nocancel - (file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC); - if (file_fd == -1) - return 0; - } - - __lseek64 (file_fd, 0, SEEK_SET); - file_offset = 0; - - return 1; -} - -/* Perform initialization if necessary. */ -static bool -maybe_setutent (void) -{ - return file_fd >= 0 || __libc_setutent (); -} - -/* Reads the entry at file_offset, storing it in last_entry and - updating file_offset on success. Returns -1 for a read error, 0 - for EOF, and 1 for a successful read. last_entry and file_offset - are only updated on a successful and complete read. */ -static ssize_t -read_last_entry (void) -{ - struct utmp buffer; - ssize_t nbytes = __pread64_nocancel (file_fd, &buffer, sizeof (buffer), - file_offset); - if (nbytes < 0) - return -1; - else if (nbytes != sizeof (buffer)) - /* Assume EOF. */ - return 0; - else - { - last_entry = buffer; - file_offset += sizeof (buffer); - return 1; - } -} - -int -__libc_getutent_r (struct utmp *buffer, struct utmp **result) -{ - int saved_errno = errno; - - if (!maybe_setutent ()) - { - /* Not available. */ - *result = NULL; - return -1; - } - - if (try_file_lock (file_fd, F_RDLCK)) - return -1; - - ssize_t nbytes = read_last_entry (); - file_unlock (file_fd); - - if (nbytes <= 0) /* Read error or EOF. */ - { - if (nbytes == 0) - /* errno should be unchanged to indicate success. A premature - EOF is treated like an EOF (missing complete record at the - end). */ - __set_errno (saved_errno); - *result = NULL; - return -1; - } - - memcpy (buffer, &last_entry, sizeof (struct utmp)); - *result = buffer; - - return 0; -} - - -/* Search for *ID, updating last_entry and file_offset. Return 0 on - success and -1 on failure. Does not perform locking; for that see - internal_getut_r below. */ -static int -internal_getut_nolock (const struct utmp *id) -{ - while (1) - { - ssize_t nbytes = read_last_entry (); - if (nbytes < 0) - return -1; - if (nbytes == 0) - { - /* End of file reached. */ - __set_errno (ESRCH); - return -1; - } - - if (matches_last_entry (id)) - break; - } - - return 0; -} - -/* Search for *ID, updating last_entry and file_offset. Return 0 on - success and -1 on failure. If the locking operation failed, write - true to *LOCK_FAILED. */ -static int -internal_getut_r (const struct utmp *id, bool *lock_failed) -{ - if (try_file_lock (file_fd, F_RDLCK)) - { - *lock_failed = true; - return -1; - } - - int result = internal_getut_nolock (id); - file_unlock (file_fd); - return result; -} - -/* For implementing this function we don't use the getutent_r function - because we can avoid the reposition on every new entry this way. */ -int -__libc_getutid_r (const struct utmp *id, struct utmp *buffer, - struct utmp **result) -{ - if (!maybe_setutent ()) - { - *result = NULL; - return -1; - } - - /* We don't have to distinguish whether we can lock the file or - whether there is no entry. */ - bool lock_failed = false; - if (internal_getut_r (id, &lock_failed) < 0) - { - *result = NULL; - return -1; - } - - memcpy (buffer, &last_entry, sizeof (struct utmp)); - *result = buffer; - - return 0; -} - -/* For implementing this function we don't use the getutent_r function - because we can avoid the reposition on every new entry this way. */ -int -__libc_getutline_r (const struct utmp *line, struct utmp *buffer, - struct utmp **result) -{ - if (!maybe_setutent ()) - { - *result = NULL; - return -1; - } - - if (try_file_lock (file_fd, F_RDLCK)) - { - *result = NULL; - return -1; - } - - while (1) - { - ssize_t nbytes = read_last_entry (); - if (nbytes < 0) - { - file_unlock (file_fd); - *result = NULL; - return -1; - } - if (nbytes == 0) - { - /* End of file reached. */ - file_unlock (file_fd); - __set_errno (ESRCH); - *result = NULL; - return -1; - } - - /* Stop if we found a user or login entry. */ - if ((last_entry.ut_type == USER_PROCESS - || last_entry.ut_type == LOGIN_PROCESS) - && (strncmp (line->ut_line, last_entry.ut_line, sizeof line->ut_line) - == 0)) - break; - } - - file_unlock (file_fd); - memcpy (buffer, &last_entry, sizeof (struct utmp)); - *result = buffer; - - return 0; -} - - -struct utmp * -__libc_pututline (const struct utmp *data) -{ - if (!maybe_setutent ()) - return NULL; - - struct utmp *pbuf; - - if (! file_writable) - { - /* We must make the file descriptor writable before going on. */ - const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name); - - int new_fd = __open_nocancel - (file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC); - if (new_fd == -1) - return NULL; - - if (__dup2 (new_fd, file_fd) < 0) - { - __close_nocancel_nostatus (new_fd); - return NULL; - } - __close_nocancel_nostatus (new_fd); - file_writable = true; - } - - /* Exclude other writers before validating the cache. */ - if (try_file_lock (file_fd, F_WRLCK)) - return NULL; - - /* Find the correct place to insert the data. */ - bool found = false; - if (matches_last_entry (data)) - { - /* Read back the entry under the write lock. */ - file_offset -= sizeof (last_entry); - ssize_t nbytes = read_last_entry (); - if (nbytes < 0) - { - file_unlock (file_fd); - return NULL; - } - - if (nbytes == 0) - /* End of file reached. */ - found = false; - else - found = matches_last_entry (data); - } - - if (!found) - /* Search forward for the entry. */ - found = internal_getut_nolock (data) >= 0; - - off64_t write_offset; - if (!found) - { - /* We append the next entry. */ - write_offset = __lseek64 (file_fd, 0, SEEK_END); - - /* Round down to the next multiple of the entry size. This - ensures any partially-written record is overwritten by the - new record. */ - write_offset = (write_offset / sizeof (struct utmp) - * sizeof (struct utmp)); - } - else - /* Overwrite last_entry. */ - write_offset = file_offset - sizeof (struct utmp); - - /* Write the new data. */ - ssize_t nbytes; - if (__lseek64 (file_fd, write_offset, SEEK_SET) < 0 - || (nbytes = __write_nocancel (file_fd, data, sizeof (struct utmp))) < 0) - { - /* There is no need to recover the file position because all - reads use pread64, and any future write is preceded by - another seek. */ - file_unlock (file_fd); - return NULL; - } - - if (nbytes != sizeof (struct utmp)) - { - /* If we appended a new record this is only partially written. - Remove it. */ - if (!found) - (void) __ftruncate64 (file_fd, write_offset); - file_unlock (file_fd); - /* Assume that the write failure was due to missing disk - space. */ - __set_errno (ENOSPC); - return NULL; - } - - file_unlock (file_fd); - file_offset = write_offset + sizeof (struct utmp); - pbuf = (struct utmp *) data; - - return pbuf; -} - - -void -__libc_endutent (void) -{ - if (file_fd >= 0) - { - __close_nocancel_nostatus (file_fd); - file_fd = -1; - } -} - - -int -__libc_updwtmp (const char *file, const struct utmp *utmp) -{ - int result = -1; - off64_t offset; - int fd; - - /* Open WTMP file. */ - fd = __open_nocancel (file, O_WRONLY | O_LARGEFILE | O_CLOEXEC); - if (fd < 0) - return -1; - - if (try_file_lock (fd, F_WRLCK)) - { - __close_nocancel_nostatus (fd); - return -1; - } - - /* Remember original size of log file. */ - offset = __lseek64 (fd, 0, SEEK_END); - if (offset % sizeof (struct utmp) != 0) - { - offset -= offset % sizeof (struct utmp); - __ftruncate64 (fd, offset); - - if (__lseek64 (fd, 0, SEEK_END) < 0) - goto unlock_return; - } - - /* Write the entry. If we can't write all the bytes, reset the file - size back to the original size. That way, no partial entries - will remain. */ - if (__write_nocancel (fd, utmp, sizeof (struct utmp)) - != sizeof (struct utmp)) - { - __ftruncate64 (fd, offset); - goto unlock_return; - } - - result = 0; - -unlock_return: - file_unlock (fd); - - /* Close WTMP file. */ - __close_nocancel_nostatus (fd); - - return result; -} diff --git a/login/utmpname.c b/login/utmpname.c index ca0870df37..0e91f696d5 100644 --- a/login/utmpname.c +++ b/login/utmpname.c @@ -15,61 +15,16 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include +#include #include -#include "utmp-private.h" - - -/* This is the default name. */ -static const char default_file_name[] = _PATH_UTMP; - -/* Current file name. */ -const char *__libc_utmp_file_name = (const char *) default_file_name; - -/* We have to use the lock in getutent_r.c. */ -__libc_lock_define (extern, __libc_utmp_lock attribute_hidden) - - int __utmpname (const char *file) { - int result = -1; - - __libc_lock_lock (__libc_utmp_lock); - - /* Close the old file. */ - __libc_endutent (); - - if (strcmp (file, __libc_utmp_file_name) != 0) - { - if (strcmp (file, default_file_name) == 0) - { - free ((char *) __libc_utmp_file_name); - - __libc_utmp_file_name = default_file_name; - } - else - { - char *file_name = __strdup (file); - if (file_name == NULL) - /* Out of memory. */ - goto done; - - if (__libc_utmp_file_name != default_file_name) - free ((char *) __libc_utmp_file_name); - - __libc_utmp_file_name = file_name; - } - } - - result = 0; - -done: - __libc_lock_unlock (__libc_utmp_lock); - return result; + errno = ENOTSUP; + return -1; } -libc_hidden_def (__utmpname) weak_alias (__utmpname, utmpname) +weak_alias (__utmpname, utmpxname) +stub_warning (utmpname) +stub_warning (utmpxname) diff --git a/login/utmpxname.c b/login/utmpxname.c deleted file mode 100644 index db6c327e1d..0000000000 --- a/login/utmpxname.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -int -utmpxname (const char *file) -{ - return __utmpname (file); -} diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c index 4976d55c19..f11f3f63d9 100644 --- a/malloc/set-freeres.c +++ b/malloc/set-freeres.c @@ -75,9 +75,6 @@ # pragma weak __libc_fgetspent_freemem_ptr # pragma weak __libc_tzfile_freemem_ptr # pragma weak __libc_getnameinfo_freemem_ptr -# pragma weak __libc_getutent_freemem_ptr -# pragma weak __libc_getutid_freemem_ptr -# pragma weak __libc_getutline_freemem_ptr # pragma weak __libc_reg_printf_freemem_ptr # pragma weak __libc_reg_type_freemem_ptr # pragma weak __libc_getgrgid_freemem_ptr @@ -201,9 +198,6 @@ __libc_freeres (void) call_free_static_weak (__libc_fgetspent_freemem_ptr); call_free_static_weak (__libc_tzfile_freemem_ptr); call_free_static_weak (__libc_getnameinfo_freemem_ptr); - call_free_static_weak (__libc_getutent_freemem_ptr); - call_free_static_weak (__libc_getutid_freemem_ptr); - call_free_static_weak (__libc_getutline_freemem_ptr); call_free_static_weak (__libc_reg_printf_freemem_ptr); call_free_static_weak (__libc_reg_type_freemem_ptr); diff --git a/manual/users.texi b/manual/users.texi index 4c83f12c42..b7874d8dba 100644 --- a/manual/users.texi +++ b/manual/users.texi @@ -867,17 +867,6 @@ The @code{getlogin} function is declared in @file{unistd.h}, while @standards{POSIX.1, unistd.h} @safety{@prelim{}@mtunsafe{@mtasurace{:getlogin} @mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{} @mtslocale{}}@asunsafe{@ascudlopen{} @ascuplugin{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsfd{} @acsmem{}}} @c getlogin (linux) @mtasurace:getlogin @mtasurace:utent @mtascusig:ALRM @mtascutimer @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem -@c getlogin_r_loginuid dup @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem -@c getlogin_fd0 (unix) @mtasurace:getlogin @mtasurace:utent @mtascusig:ALRM @mtascutimer @ascuheap @asulock @aculock @acsfd @acsmem -@c uses static buffer name => @mtasurace:getlogin -@c ttyname_r dup @ascuheap @acsmem @acsfd -@c strncpy dup ok -@c setutent dup @mtasurace:utent @asulock @aculock @acsfd -@c getutline_r dup @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c endutent dup @mtasurace:utent @asulock @aculock -@c libc_lock_unlock dup ok -@c strlen dup ok -@c memcpy dup ok @c @c getlogin_r (linux) @mtasurace:utent @mtascusig:ALRM @mtascutimer @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem @c getlogin_r_loginuid @mtslocale @ascudlopen @ascuplugin @ascuheap @asulock @acucorrupt @aculock @acsfd @acsmem @@ -956,11 +945,9 @@ ID of the user's login shell, etc., etc., but also stores information about the run level of the system, the time of the last system reboot, and possibly more. -The user accounting database typically lives in @file{/etc/utmp}, -@file{/var/adm/utmp} or @file{/var/run/utmp}. However, these files -should @strong{never} be accessed directly. For reading information -from and writing information to the user accounting database, the -functions described in this section should be used. +The user accounting database functions provided by @theglibc{} are +meant only for XPG2 compliance, all of them either are no-op operation +or return an invalid return along @code{ENOTSUP}. @menu @@ -1103,356 +1090,70 @@ compatibility only, @file{utmp.h} defines @code{ut_time} as an alias for @deftypefun void setutent (void) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} -@c Besides the static variables in utmp_file.c, there's the jump_table. -@c They're both modified while holding a lock, but other threads may -@c cause the variables to be modified between calling this function and -@c others that rely on the internal state it sets up. - -@c setutent @mtasurace:utent @asulock @aculock @acsfd -@c libc_lock_lock dup @asulock @aculock -@c __libc_setutent @mtasurace:utent @acsfd -@c setutent_unknown @mtasurace:utent @acsfd -@c *libc_utmp_file_functions.setutent = setutent_file @mtasurace:utent @acsfd -@c open_not_cancel_2 dup @acsfd -@c fcntl_not_cancel dup ok -@c close_not_cancel_no_status dup @acsfd -@c lseek64 dup ok -@c libc_lock_unlock dup ok -This function opens the user accounting database to begin scanning it. -You can then call @code{getutent}, @code{getutid} or @code{getutline} to -read entries and @code{pututline} to write entries. - -If the database is already open, it resets the input to the beginning of -the database. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op. @end deftypefun @deftypefun {struct utmp *} getutent (void) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtuinit{} @mtasurace{:utent} @mtasurace{:utentbuf} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}} -@c The static buffer that holds results is allocated with malloc at -@c the first call; the test is not thread-safe, so multiple concurrent -@c calls could malloc multiple buffers. - -@c getutent @mtuinit @mtasurace:utent @mtasurace:utentbuf @mtascusig:ALRM @mtascutimer @ascuheap @asulock @aculock @acsfd @acsmem -@c malloc @asulock @aculock @acsfd @acsmem -@c getutent_r dup @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -The @code{getutent} function reads the next entry from the user -accounting database. It returns a pointer to the entry, which is -statically allocated and may be overwritten by subsequent calls to -@code{getutent}. You must copy the contents of the structure if you -wish to save the information or you can use the @code{getutent_r} -function which stores the data in a user-provided buffer. - -A null pointer is returned in case no further entry is available. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return a null pointer. @end deftypefun @deftypefun void endutent (void) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} -@c endutent @mtasurace:utent @asulock @aculock @acsfd -@c libc_lock_lock dup @asulock @aculock -@c __libc_endutent @mtasurace:utent @acsfd -@c endutent_unknown ok -@c endutent_file @mtasurace:utent @acsfd -@c close_not_cancel_no_status dup @acsfd -@c libc_lock_unlock dup ok -This function closes the user accounting database. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op. @end deftypefun @deftypefun {struct utmp *} getutid (const struct utmp *@var{id}) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtuinit{} @mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{} @ascuheap{}}@acunsafe{@aculock{} @acsmem{} @acsfd{}}} -@c Same caveats as getutline. -@c -@c getutid @mtuinit @mtasurace:utent @mtascusig:ALRM @mtascutimer @ascuheap @asulock @aculock @acsmem @acsfd -@c uses a static buffer malloced on the first call -@c malloc dup @ascuheap @acsmem -@c getutid_r dup @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -This function searches forward from the current point in the database -for an entry that matches @var{id}. If the @code{ut_type} member of the -@var{id} structure is one of @code{RUN_LVL}, @code{BOOT_TIME}, -@code{OLD_TIME} or @code{NEW_TIME} the entries match if the -@code{ut_type} members are identical. If the @code{ut_type} member of -the @var{id} structure is @code{INIT_PROCESS}, @code{LOGIN_PROCESS}, -@code{USER_PROCESS} or @code{DEAD_PROCESS}, the entries match if the -@code{ut_type} member of the entry read from the database is one of -these four, and the @code{ut_id} members match. However if the -@code{ut_id} member of either the @var{id} structure or the entry read -from the database is empty it checks if the @code{ut_line} members match -instead. If a matching entry is found, @code{getutid} returns a pointer -to the entry, which is statically allocated, and may be overwritten by a -subsequent call to @code{getutent}, @code{getutid} or @code{getutline}. -You must copy the contents of the structure if you wish to save the -information. - -A null pointer is returned in case the end of the database is reached -without a match. - -The @code{getutid} function may cache the last read entry. Therefore, -if you are using @code{getutid} to search for multiple occurrences, it -is necessary to zero out the static data after each call. Otherwise -@code{getutid} could just return a pointer to the same entry over and -over again. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return a null pointer. @end deftypefun @deftypefun {struct utmp *} getutline (const struct utmp *@var{line}) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtuinit{} @mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}} -@c The static buffer that holds results is allocated with malloc at -@c the first call; the test is not thread-safe, so multiple concurrent -@c calls could malloc multiple buffers. - -@c getutline @mtuinit @mtasurace:utent @mtascusig:ALRM @mtascutimer @ascuheap @asulock @aculock @acsfd @acsmem -@c malloc @asulock @aculock @acsfd @acsmem -@c getutline_r dup @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -This function searches forward from the current point in the database -until it finds an entry whose @code{ut_type} value is -@code{LOGIN_PROCESS} or @code{USER_PROCESS}, and whose @code{ut_line} -member matches the @code{ut_line} member of the @var{line} structure. -If it finds such an entry, it returns a pointer to the entry which is -statically allocated, and may be overwritten by a subsequent call to -@code{getutent}, @code{getutid} or @code{getutline}. You must copy the -contents of the structure if you wish to save the information. - -A null pointer is returned in case the end of the database is reached -without a match. - -The @code{getutline} function may cache the last read entry. Therefore -if you are using @code{getutline} to search for multiple occurrences, it -is necessary to zero out the static data after each call. Otherwise -@code{getutline} could just return a pointer to the same entry over and -over again. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return a null pointer. @end deftypefun @deftypefun {struct utmp *} pututline (const struct utmp *@var{utmp}) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} -@c pututline @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c libc_lock_lock dup @asulock @aculock -@c __libc_pututline @mtasurace:utent @mtascusig:ALRM @mtascutimer @acsfd -@c pututline_unknown @mtasurace:utent @acsfd -@c setutent_unknown dup @mtasurace:utent @acsfd -@c pututline_file @mtascusig:ALRM @mtascutimer @acsfd -@c TRANSFORM_UTMP_FILE_NAME ok -@c strcmp dup ok -@c acesss dup ok -@c open_not_cancel_2 dup @acsfd -@c fcntl_not_cancel dup ok -@c close_not_cancel_no_status dup @acsfd -@c llseek dup ok -@c dup2 dup ok -@c utmp_equal dup ok -@c internal_getut_r dup @mtascusig:ALRM @mtascutimer -@c LOCK_FILE dup @mtascusig:ALRM @mtasctimer -@c LOCKING_FAILED dup ok -@c ftruncate64 dup ok -@c write_not_cancel dup ok -@c UNLOCK_FILE dup @mtasctimer -@c libc_lock_unlock dup @aculock -The @code{pututline} function inserts the entry @code{*@var{utmp}} at -the appropriate place in the user accounting database. If it finds that -it is not already at the correct place in the database, it uses -@code{getutid} to search for the position to insert the entry, however -this will not modify the static structure returned by @code{getutent}, -@code{getutid} and @code{getutline}. If this search fails, the entry -is appended to the database. - -The @code{pututline} function returns a pointer to a copy of the entry -inserted in the user accounting database, or a null pointer if the entry -could not be added. The following @code{errno} error conditions are -defined for this function: - -@table @code -@item EPERM -The process does not have the appropriate privileges; you cannot modify -the user accounting database. -@end table +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return a null pointer. @end deftypefun -All the @code{get*} functions mentioned before store the information -they return in a static buffer. This can be a problem in multi-threaded -programs since the data returned for the request is overwritten by the -return value data in another thread. Therefore @theglibc{} -provides as extensions three more functions which return the data in a -user-provided buffer. - @deftypefun int getutent_r (struct utmp *@var{buffer}, struct utmp **@var{result}) @standards{GNU, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} -@c getutent_r @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c libc_lock_lock dup @asulock @aculock -@c __libc_getutent_r @mtasurace:utent @mtascusig:ALRM @mtascutimer @acsfd -@c getutent_r_unknown @mtasurace:utent @acsfd -@c setutent_unknown dup @mtasurace:utent @acsfd -@c getutent_r_file @mtasurace:utent @mtascusig:ALRM @mtascutimer -@c LOCK_FILE @mtascusig:ALRM @mtascutimer -@c alarm dup @mtascutimer -@c sigemptyset dup ok -@c sigaction dup ok -@c memset dup ok -@c fcntl_not_cancel dup ok -@c LOCKING_FAILED ok -@c read_not_cancel dup ok -@c UNLOCK_FILE @mtascutimer -@c fcntl_not_cancel dup ok -@c alarm dup @mtascutimer -@c sigaction dup ok -@c memcpy dup ok -@c libc_lock_unlock dup ok -The @code{getutent_r} is equivalent to the @code{getutent} function. It -returns the next entry from the database. But instead of storing the -information in a static buffer it stores it in the buffer pointed to by -the parameter @var{buffer}. - -If the call was successful, the function returns @code{0} and the -pointer variable pointed to by the parameter @var{result} contains a -pointer to the buffer which contains the result (this is most probably -the same value as @var{buffer}). If something went wrong during the -execution of @code{getutent_r} the function returns @code{-1}. - -This function is a GNU extension. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return @code{-1} with @code{errno} set to @code{ENOTSUP}. @end deftypefun @deftypefun int getutid_r (const struct utmp *@var{id}, struct utmp *@var{buffer}, struct utmp **@var{result}) @standards{GNU, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} -@c getutid_r @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c libc_lock_lock dup @asulock @aculock -@c __libc_getutid_r @mtasurace:utent @mtascusig:ALRM @mtascutimer @acsfd -@c getutid_r_unknown @mtasurace:utent @acsfd -@c setutent_unknown dup @mtasurace:utent @acsfd -@c getutid_r_file @mtascusig:ALRM @mtascutimer -@c internal_getut_r @mtascusig:ALRM @mtascutimer -@c LOCK_FILE dup @mtascusig:ALRM @mtascutimer -@c LOCKING_FAILED dup ok -@c read_not_cancel dup ok -@c utmp_equal ok -@c strncmp dup ok -@c UNLOCK_FILE dup @mtascutimer -@c memcpy dup ok -@c libc_lock_unlock dup @aculock -This function retrieves just like @code{getutid} the next entry matching -the information stored in @var{id}. But the result is stored in the -buffer pointed to by the parameter @var{buffer}. - -If successful the function returns @code{0} and the pointer variable -pointed to by the parameter @var{result} contains a pointer to the -buffer with the result (probably the same as @var{result}. If not -successful the function return @code{-1}. - -This function is a GNU extension. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return @code{-1} with @code{errno} set to @code{ENOTSUP}. @end deftypefun @deftypefun int getutline_r (const struct utmp *@var{line}, struct utmp *@var{buffer}, struct utmp **@var{result}) @standards{GNU, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} -@c getutline_r @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c libc_lock_lock dup @asulock @aculock -@c __libc_getutline_r @mtasurace:utent @mtascusig:ALRM @mtascutimer @acsfd -@c getutline_r_unknown @mtasurace:utent @acsfd -@c setutent_unknown dup @mtasurace:utent @acsfd -@c getutline_r_file @mtasurace:utent @mtascusig:ALRM @mtascutimer -@c LOCK_FILE @mtascusig:ALRM @mtascutimer -@c alarm dup @mtascutimer -@c sigemptyset dup ok -@c sigaction dup ok -@c memset dup ok -@c fcntl_not_cancel dup ok -@c LOCKING_FAILED ok -@c read_not_cancel dup ok -@c strncmp dup ok -@c UNLOCK_FILE @mtascutimer -@c fcntl_not_cancel dup ok -@c alarm dup @mtascutimer -@c sigaction dup ok -@c memcpy dup ok -@c libc_lock_unlock dup ok -This function retrieves just like @code{getutline} the next entry -matching the information stored in @var{line}. But the result is stored -in the buffer pointed to by the parameter @var{buffer}. - -If successful the function returns @code{0} and the pointer variable -pointed to by the parameter @var{result} contains a pointer to the -buffer with the result (probably the same as @var{result}. If not -successful the function return @code{-1}. - -This function is a GNU extension. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return @code{-1} with @code{errno} set to @code{ENOTSUP}. @end deftypefun - -In addition to the user accounting database, most systems keep a number -of similar databases. For example most systems keep a log file with all -previous logins (usually in @file{/etc/wtmp} or @file{/var/log/wtmp}). - -For specifying which database to examine, the following function should -be used. - @deftypefun int utmpname (const char *@var{file}) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent}}@asunsafe{@asulock{} @ascuheap{}}@acunsafe{@aculock{} @acsmem{}}} -@c utmpname @mtasurace:utent @asulock @ascuheap @aculock @acsmem -@c libc_lock_lock dup @asulock @aculock -@c __libc_endutent dup @mtasurace:utent -@c strcmp dup ok -@c free dup @ascuheap @acsmem -@c strdup dup @ascuheap @acsmem -@c libc_lock_unlock dup @aculock -The @code{utmpname} function changes the name of the database to be -examined to @var{file}, and closes any previously opened database. By -default @code{getutent}, @code{getutid}, @code{getutline} and -@code{pututline} read from and write to the user accounting database. - -The following macros are defined for use as the @var{file} argument: - -@deftypevr Macro {char *} _PATH_UTMP -This macro is used to specify the user accounting database. -@end deftypevr - -@deftypevr Macro {char *} _PATH_WTMP -This macro is used to specify the user accounting log file. -@end deftypevr - -The @code{utmpname} function returns a value of @code{0} if the new name -was successfully stored, and a value of @code{-1} to indicate an error. -Note that @code{utmpname} does not try to open the database, and that -therefore the return value does not say anything about whether the -database can be successfully opened. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return @code{-1} with @code{errno} set to @code{ENOTSUP}. @end deftypefun -Specially for maintaining log-like databases @theglibc{} provides -the following function: - @deftypefun void updwtmp (const char *@var{wtmp_file}, const struct utmp *@var{utmp}) @standards{SVID, utmp.h} -@safety{@prelim{}@mtunsafe{@mtascusig{:ALRM} @mtascutimer{}}@asunsafe{}@acunsafe{@acsfd{}}} -@c updwtmp @mtascusig:ALRM @mtascutimer @acsfd -@c TRANSFORM_UTMP_FILE_NAME dup ok -@c *libc_utmp_file_functions->updwtmp = updwtmp_file @mtascusig:ALRM @mtascutimer @acsfd -@c open_not_cancel_2 dup @acsfd -@c LOCK_FILE dup @mtascusig:ALRM @mtascutimer -@c LOCKING_FAILED dup ok -@c lseek64 dup ok -@c ftruncate64 dup ok -@c write_not_cancel dup ok -@c UNLOCK_FILE dup @mtascutimer -@c close_not_cancel_no_status dup @acsfd -The @code{updwtmp} function appends the entry *@var{utmp} to the -database specified by @var{wtmp_file}. For possible values for the -@var{wtmp_file} argument see the @code{utmpname} function. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op. @end deftypefun -@strong{Portability Note:} Although many operating systems provide a -subset of these functions, they are not standardized. There are often -subtle differences in the return types, and there are considerable -differences between the various definitions of @code{struct utmp}. When -programming for @theglibc{}, it is probably best to stick -with the functions described in this section. If however, you want your -program to be portable, consider using the XPG functions described in -@ref{XPG Functions}, or take a look at the BSD compatible functions in -@ref{Logging In and Out}. - - @node XPG Functions @subsection XPG User Accounting Database Functions @@ -1540,14 +1241,14 @@ can be found using the @code{sizeof} operator. @deftypefun void setutxent (void) @standards{XPG4.2, utmpx.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} This function is similar to @code{setutent}. In @theglibc{} it is simply an alias for @code{setutent}. @end deftypefun @deftypefun {struct utmpx *} getutxent (void) @standards{XPG4.2, utmpx.h} -@safety{@prelim{}@mtunsafe{@mtuinit{} @mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} The @code{getutxent} function is similar to @code{getutent}, but returns a pointer to a @code{struct utmpx} instead of @code{struct utmp}. In @theglibc{} it simply is an alias for @code{getutent}. @@ -1555,14 +1256,14 @@ a pointer to a @code{struct utmpx} instead of @code{struct utmp}. In @deftypefun void endutxent (void) @standards{XPG4.2, utmpx.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent}}@asunsafe{@asulock{}}@acunsafe{@aculock{}}} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} This function is similar to @code{endutent}. In @theglibc{} it is simply an alias for @code{endutent}. @end deftypefun @deftypefun {struct utmpx *} getutxid (const struct utmpx *@var{id}) @standards{XPG4.2, utmpx.h} -@safety{@prelim{}@mtunsafe{@mtuinit{} @mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{} @ascuheap{}}@acunsafe{@aculock{} @acsmem{} @acsfd{}}} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} This function is similar to @code{getutid}, but uses @code{struct utmpx} instead of @code{struct utmp}. In @theglibc{} it is simply an alias for @code{getutid}. @@ -1570,7 +1271,7 @@ for @code{getutid}. @deftypefun {struct utmpx *} getutxline (const struct utmpx *@var{line}) @standards{XPG4.2, utmpx.h} -@safety{@prelim{}@mtunsafe{@mtuinit{} @mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} This function is similar to @code{getutid}, but uses @code{struct utmpx} instead of @code{struct utmp}. In @theglibc{} it is simply an alias for @code{getutline}. @@ -1578,7 +1279,7 @@ for @code{getutline}. @deftypefun {struct utmpx *} pututxline (const struct utmpx *@var{utmp}) @standards{XPG4.2, utmpx.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{}}} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} The @code{pututxline} function is functionally identical to @code{pututline}, but uses @code{struct utmpx} instead of @code{struct utmp}. In @theglibc{}, @code{pututxline} is simply an alias for @@ -1587,31 +1288,24 @@ utmp}. In @theglibc{}, @code{pututxline} is simply an alias for @deftypefun int utmpxname (const char *@var{file}) @standards{XPG4.2, utmpx.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent}}@asunsafe{@asulock{} @ascuheap{}}@acunsafe{@aculock{} @acsmem{}}} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} The @code{utmpxname} function is functionally identical to @code{utmpname}. In @theglibc{}, @code{utmpxname} is simply an alias for @code{utmpname}. @end deftypefun -You can translate between a traditional @code{struct utmp} and an XPG -@code{struct utmpx} with the following functions. In @theglibc{}, -these functions are merely copies, since the two structures are -identical. - -@deftypefun int getutmp (const struct utmpx *@var{utmpx}, struct utmp *@var{utmp}) +@deftypefun void getutmp (const struct utmpx *@var{utmpx}, struct utmp *@var{utmp}) @standards{GNU, utmp.h} @standards{GNU, utmpx.h} @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} -@code{getutmp} copies the information, insofar as the structures are -compatible, from @var{utmpx} to @var{utmp}. +This function is no-op. @end deftypefun -@deftypefun int getutmpx (const struct utmp *@var{utmp}, struct utmpx *@var{utmpx}) +@deftypefun void getutmpx (const struct utmp *@var{utmp}, struct utmpx *@var{utmpx}) @standards{GNU, utmp.h} @standards{GNU, utmpx.h} @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} -@code{getutmpx} copies the information, insofar as the structures are -compatible, from @var{utmp} to @var{utmpx}. +This function is no-op. @end deftypefun @@ -1619,7 +1313,7 @@ compatible, from @var{utmp} to @var{utmpx}. @subsection Logging In and Out These functions, derived from BSD, are available in the separate -@file{libutil} library, and declared in @file{utmp.h}. +@file{libutil} library (only for Hurd), and declared in @file{utmp.h}. @pindex utmp.h Note that the @code{ut_user} member of @code{struct utmp} is called @@ -1649,76 +1343,22 @@ on error. @deftypefun void login (const struct utmp *@var{entry}) @standards{BSD, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{} @ascuheap{}}@acunsafe{@aculock{} @acucorrupt{} @acsfd{} @acsmem{}}} -@c login @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @ascuheap @aculock @acucorrupt @acsfd @acsmem -@c getpid dup ok -@c tty_name @ascuheap @acucorrupt @acsmem @acsfd -@c ttyname_r dup @ascuheap @acsmem @acsfd -@c memchr dup ok -@c realloc dup @ascuheap @acsmem -@c malloc dup @ascuheap @acsmem -@c free dup @ascuheap @acsmem -@c strncmp dup ok -@c basename dup ok -@c strncpy dup ok -@c utmpname dup @mtasurace:utent @asulock @ascuheap @aculock @acsmem -@c setutent dup @mtasurace:utent @asulock @aculock @acsfd -@c pututline dup @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c endutent dup @mtasurace:utent @asulock @aculock -@c free dup @ascuheap @acsmem -@c updwtmp dup @mtascusig:ALRM @mtascutimer @acsfd -The @code{login} functions inserts an entry into the user accounting -database. The @code{ut_line} member is set to the name of the terminal -on standard input. If standard input is not a terminal @code{login} -uses standard output or standard error output to determine the name of -the terminal. If @code{struct utmp} has a @code{ut_type} member, -@code{login} sets it to @code{USER_PROCESS}, and if there is an -@code{ut_pid} member, it will be set to the process ID of the current -process. The remaining entries are copied from @var{entry}. - -A copy of the entry is written to the user accounting log file. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op. @end deftypefun @deftypefun int logout (const char *@var{ut_line}) @standards{BSD, utmp.h} -@safety{@prelim{}@mtunsafe{@mtasurace{:utent} @mtascusig{:ALRM} @mtascutimer{}}@asunsafe{@asulock{} @ascuheap{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}} -@c logout @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @ascuheap @aculock @acsfd @acsmem -@c utmpname dup @mtasurace:utent @asulock @ascuheap @aculock @acsmem -@c setutent dup @mtasurace:utent @asulock @aculock @acsfd -@c strncpy dup ok -@c getutline_r dup @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c bzero dup ok -@c gettimeofday dup ok -@c time dup ok -@c pututline dup @mtasurace:utent @mtascusig:ALRM @mtascutimer @asulock @aculock @acsfd -@c endutent dup @mtasurace:utent @asulock @aculock -This function modifies the user accounting database to indicate that the -user on @var{ut_line} has logged out. - -The @code{logout} function returns @code{1} if the entry was successfully -written to the database, or @code{0} on error. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op, it always return @code{-1} with @code{errno} set to @code{ENOTSUP}. @end deftypefun @deftypefun void logwtmp (const char *@var{ut_line}, const char *@var{ut_name}, const char *@var{ut_host}) @standards{BSD, utmp.h} -@safety{@prelim{}@mtunsafe{@mtascusig{:ALRM} @mtascutimer{}}@asunsafe{}@acunsafe{@acsfd{}}} -@c logwtmp @mtascusig:ALRM @mtascutimer @acsfd -@c memset dup ok -@c getpid dup ok -@c strncpy dup ok -@c gettimeofday dup ok -@c time dup ok -@c updwtmp dup @mtascusig:ALRM @mtascutimer @acsfd -The @code{logwtmp} function appends an entry to the user accounting log -file, for the current time and the information provided in the -@var{ut_line}, @var{ut_name} and @var{ut_host} arguments. +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function is no-op. @end deftypefun -@strong{Portability Note:} The BSD @code{struct utmp} only has the -@code{ut_line}, @code{ut_name}, @code{ut_host} and @code{ut_time} -members. Older systems do not even have the @code{ut_host} member. - - @node User Database @section User Database @cindex user database diff --git a/sysdeps/generic/paths.h b/sysdeps/generic/paths.h index 893b4c2286..a41fcf76f6 100644 --- a/sysdeps/generic/paths.h +++ b/sysdeps/generic/paths.h @@ -60,10 +60,10 @@ #define _PATH_SHELLS "/etc/shells" #define _PATH_TTY "/dev/tty" #define _PATH_UNIX "/vmunix" -#define _PATH_UTMP "/var/run/utmp" -#define _PATH_UTMP_DB "/var/run/utmp.db" +#define _PATH_UTMP "/dev/null/utmp" +#define _PATH_UTMP_DB "/dev/null/utmp.db" #define _PATH_VI "/usr/bin/vi" -#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_WTMP "/dev/null/wtmp" /* Provide trailing slash, since mostly used for building pathnames. */ #define _PATH_DEV "/dev/" diff --git a/sysdeps/gnu/Makefile b/sysdeps/gnu/Makefile index d23ded40a0..421e983500 100644 --- a/sysdeps/gnu/Makefile +++ b/sysdeps/gnu/Makefile @@ -16,19 +16,6 @@ # . ifeq ($(subdir),login) -sysdep_routines += \ - endutxent \ - getutmp \ - getutmpx \ - getutxent \ - getutxid \ - getutxline \ - pututxline \ - setutxent \ - updwtmpx \ - utmpxname \ - # sysdep_routines - sysdep_headers += \ bits/utmpx.h \ utmpx.h \ diff --git a/sysdeps/gnu/getutmp.c b/sysdeps/gnu/getutmp.c deleted file mode 100644 index 0aaaf47ba1..0000000000 --- a/sysdeps/gnu/getutmp.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1999-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#ifndef _UTMPX_H -/* This is an ugly hack but we must not see the getutmpx declaration. */ -# define getutmpx XXXgetutmpx -# include -# undef getutmpx -#endif - -void -getutmp (const struct utmpx *utmpx, struct utmp *utmp) -{ - assert (sizeof (struct utmp) == sizeof (struct utmpx)); - memcpy (utmp, utmpx, sizeof (struct utmp)); -} -strong_alias (getutmp, getutmpx) diff --git a/sysdeps/gnu/getutmpx.c b/sysdeps/gnu/getutmpx.c deleted file mode 100644 index f393734a63..0000000000 --- a/sysdeps/gnu/getutmpx.c +++ /dev/null @@ -1 +0,0 @@ -/* We don't need a separate version. it is the same as getutmp(). */ diff --git a/sysdeps/gnu/updwtmp.c b/sysdeps/gnu/updwtmp.c deleted file mode 100644 index 458df6a486..0000000000 --- a/sysdeps/gnu/updwtmp.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#define TRANSFORM_UTMP_FILE_NAME(file_name) \ - ((strcmp (file_name, _PATH_UTMP "x") == 0 \ - && __access (_PATH_UTMP "x", F_OK) != 0) \ - ? _PATH_UTMP \ - : ((strcmp (file_name, _PATH_WTMP "x") == 0 \ - && __access (_PATH_WTMP "x", F_OK) != 0) \ - ? _PATH_WTMP \ - : file_name)) - -#include diff --git a/sysdeps/gnu/utmp_file.c b/sysdeps/gnu/utmp_file.c deleted file mode 100644 index a4575ac454..0000000000 --- a/sysdeps/gnu/utmp_file.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#define TRANSFORM_UTMP_FILE_NAME(file_name) \ - ((strcmp (file_name, _PATH_UTMP "x") == 0 \ - && __access (_PATH_UTMP "x", F_OK) != 0) \ - ? _PATH_UTMP \ - : ((strcmp (file_name, _PATH_WTMP "x") == 0 \ - && __access (_PATH_WTMP "x", F_OK) != 0) \ - ? _PATH_WTMP \ - : file_name)) - -#include diff --git a/sysdeps/unix/sysv/linux/paths.h b/sysdeps/unix/sysv/linux/paths.h index 1342ab3a96..081dcdf523 100644 --- a/sysdeps/unix/sysv/linux/paths.h +++ b/sysdeps/unix/sysv/linux/paths.h @@ -61,9 +61,9 @@ #define _PATH_SHELLS "/etc/shells" #define _PATH_TTY "/dev/tty" #define _PATH_UNIX "/boot/vmlinux" -#define _PATH_UTMP "/var/run/utmp" +#define _PATH_UTMP "/dev/null/utmp" #define _PATH_VI "/usr/bin/vi" -#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_WTMP "/dev/null/wtmp" /* Provide trailing slash, since mostly used for building pathnames. */ #define _PATH_DEV "/dev/" diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile index 2a5b4fbb6f..fb3c4554bf 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/Makefile +++ b/sysdeps/unix/sysv/linux/s390/s390-32/Makefile @@ -1,11 +1,6 @@ # See Makeconfig regarding the use of default-abi. default-abi := 32 -ifeq ($(subdir),login) -sysdep_routines += utmp32 utmpx32 login32 -shared-only-routines += utmp32 utmpx32 login32 -endif - ifeq ($(subdir),misc) sysdep_headers += sys/elf.h endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c index fc32ae1e45..9c687e5efa 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutent.c @@ -20,13 +20,20 @@ #include "utmp-compat.h" -#if defined SHARED -# undef weak_alias -# define weak_alias(n,a) -#endif -#include "login/getutent.c" -_weak_alias (buffer, __libc_getutent_freemem_ptr) +struct utmp * +__getutent (void) +{ + return NULL; +} +symbol_version (__getutent, getutent, GLIBC_2.0); +symbol_version (__getutent, getutxent, GLIBC_2.1); #if defined SHARED default_symbol_version (__getutent, getutent, UTMP_COMPAT_BASE); +default_symbol_version (__getutent, getutxent, UTMP_COMPAT_BASE); +#else +weak_alias (__getutent, getutent) +weak_alias (__getutent, getutxent) #endif +stub_warning (getutent) +stub_warning (getutxent) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutent_r.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutent_r.c index 59be82684b..f1c02845d1 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutent_r.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutent_r.c @@ -15,23 +15,30 @@ License along with the GNU C Library; if not, see . */ -#include #include #include #include "utmp-compat.h" -#include "utmp-private.h" #if defined SHARED +extern void __setutent (void); +extern void __endutent (void); + weak_alias (__setutent, setutent) weak_alias (__endutent, endutent) +weak_alias (__endutent, endutxent) # undef weak_alias # define weak_alias(n,a) #endif #include "login/getutent_r.c" +symbol_version (__setutent, setutxent, GLIBC_2.1); +symbol_version (__getutent_r, getutent_r, GLIBC_2.0); +symbol_version (__pututline, pututline, GLIBC_2.0); +symbol_version (__pututline, pututxline, GLIBC_2.1); #if defined SHARED default_symbol_version (__getutent_r, getutent_r, UTMP_COMPAT_BASE); default_symbol_version (__pututline, pututline, UTMP_COMPAT_BASE); +default_symbol_version (__pututline, pututxline, UTMP_COMPAT_BASE); #endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c index 68c88fc9a6..915c8ade88 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutid.c @@ -25,8 +25,10 @@ # define weak_alias(n,a) #endif #include "login/getutid.c" -_weak_alias (buffer, __libc_getutid_freemem_ptr) +symbol_version (__getutid, getutid, GLIBC_2.0); +symbol_version (__getutid, getutxid, GLIBC_2.1); #if defined SHARED default_symbol_version (__getutid, getutid, UTMP_COMPAT_BASE); +default_symbol_version (__getutid, getutxid, UTMP_COMPAT_BASE); #endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutid_r.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutid_r.c index b202b4adff..be3aa5ccb6 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutid_r.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutid_r.c @@ -21,13 +21,13 @@ #include #include "utmp-compat.h" -#include "utmp-private.h" #if defined SHARED # undef weak_alias # define weak_alias(n,a) #endif #include "login/getutid_r.c" +symbol_version (__getutid_r, getutid_r, GLIBC_2.0); #if defined SHARED default_symbol_version (__getutid_r, getutid_r, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c index 4bb59a6205..e6a5ba84ed 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutline.c @@ -25,8 +25,10 @@ # define weak_alias(n,a) #endif #include "login/getutline.c" -_weak_alias (buffer, __libc_getutline_freemem_ptr) +symbol_version (__getutline, getutline, GLIBC_2.0); +symbol_version (__getutline, getutxline, GLIBC_2.1); #if defined SHARED default_symbol_version (__getutline, getutline, UTMP_COMPAT_BASE); +default_symbol_version (__getutline, getutxline, UTMP_COMPAT_BASE); #endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutline_r.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutline_r.c index 2f48010175..6b5f0f02a4 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutline_r.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutline_r.c @@ -20,13 +20,13 @@ #include #include "utmp-compat.h" -#include "utmp-private.h" #if defined SHARED # undef weak_alias # define weak_alias(n,a) #endif #include "login/getutline_r.c" +symbol_version (__getutline_r, getutline_r, GLIBC_2.0); #if defined SHARED default_symbol_version (__getutline_r, getutline_r, UTMP_COMPAT_BASE);; diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutmp.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutmp.c index dc9a1c6168..9059432e3d 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutmp.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutmp.c @@ -17,20 +17,20 @@ #include #include -/* This is an ugly hack but we must not see the getutmpx declaration. */ -#define getutmpx XXXgetutmpx +#define getutmpx __redirect_getutmpx #include #undef getutmpx #include "utmp-compat.h" -#undef weak_alias -#define weak_alias(n,a) -#define getutmp __getutmp -#define getutmpx __getutmpx -#include "sysdeps/gnu/getutmp.c" -#undef getutmp -#undef getutmpx +void +__getutmp (const struct utmpx *utmpx, struct utmp *utmp) +{ +} +symbol_version (__getutmp, getutmp, GLIBC_2.1.1); +symbol_version (__getutmp, getutmpx, GLIBC_2.1.1); default_symbol_version (__getutmp, getutmp, UTMP_COMPAT_BASE); -default_symbol_version (__getutmpx, getutmpx, UTMP_COMPAT_BASE); +default_symbol_version (__getutmp, getutmpx, UTMP_COMPAT_BASE); +stub_warning (getutmp) +stub_warning (getutmpx) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutxent.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutxent.c deleted file mode 100644 index 866c5b65e7..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutxent.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#include "utmp-compat.h" - -#undef weak_alias -#define weak_alias(n,a) -#define getutxent __getutxent -#include "login/getutxent.c" -#undef getutxent - -default_symbol_version (__getutxent, getutxent, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutxid.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutxid.c deleted file mode 100644 index 1fb355a74d..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutxid.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#include "utmp-compat.h" - -#undef weak_alias -#define weak_alias(n,a) -#define getutxid __getutxid -#include "login/getutxid.c" -#undef getutxid - -default_symbol_version (__getutxid, getutxid, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getutxline.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutxline.c deleted file mode 100644 index 541fc066c5..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutxline.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#include "utmp-compat.h" - -#undef weak_alias -#define weak_alias(n,a) -#define getutxline __getutxline -#include "login/getutxline.c" -#undef getutxline - -default_symbol_version (__getutxline, getutxline, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/login.c b/sysdeps/unix/sysv/linux/s390/s390-32/login.c index fe81bd8f2d..56015d2fe5 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/login.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/login.c @@ -29,6 +29,7 @@ #undef compat_symbol #define compat_symbol(...) #include "login/login.c" +symbol_version (__login, login, GLIBC_2.0); /* Compatibility symbol as formerly found in libutil. login@GLIBC_2.0 is supplied by login32.c. */ diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/login32.c b/sysdeps/unix/sysv/linux/s390/s390-32/login32.c deleted file mode 100644 index 8c4d5fe4db..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/login32.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifdef SHARED -# include -# include -# include - -# include "utmp32.h" -# include "utmp-convert.h" - -/* Write the given entry into utmp and wtmp. */ -void -login32 (const struct utmp32 *entry) -{ - struct utmp in64; - - utmp_convert32to64 (entry, &in64); - login (&in64); -} - -symbol_version (login32, login, GLIBC_2.0); -#endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/pututxline.c b/sysdeps/unix/sysv/linux/s390/s390-32/pututxline.c deleted file mode 100644 index 51f006294a..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/pututxline.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#include "utmp-compat.h" - -#undef weak_alias -#define weak_alias(n,a) -#define pututxline __pututxline -#include "login/pututxline.c" -#undef pututxline - -default_symbol_version (__pututxline, pututxline, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c b/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c index 9f8e9443af..3ba16959e7 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c @@ -18,14 +18,16 @@ #include #include "utmp-compat.h" -#include "utmp-private.h" #if defined SHARED # undef weak_alias # define weak_alias(n,a) #endif -#include "sysdeps/gnu/updwtmp.c" +#include "login/updwtmp.c" +symbol_version (__updwtmp, updwtmp, GLIBC_2.0); +symbol_version (__updwtmp, updwtmpx, GLIBC_2.1); #if defined SHARED default_symbol_version (__updwtmp, updwtmp, UTMP_COMPAT_BASE); +default_symbol_version (__updwtmp, updwtmpx, UTMP_COMPAT_BASE); #endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/updwtmpx.c b/sysdeps/unix/sysv/linux/s390/s390-32/updwtmpx.c deleted file mode 100644 index 5c5a8251b3..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/updwtmpx.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#include "utmp-compat.h" - -#undef weak_alias -#define weak_alias(n,a) -#define updwtmpx __updwtmpx -#include "login/updwtmpx.c" -#undef updwtmpx - -default_symbol_version (__updwtmpx, updwtmpx, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmp-convert.h b/sysdeps/unix/sysv/linux/s390/s390-32/utmp-convert.h deleted file mode 100644 index acf913769c..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/utmp-convert.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - - -/* This file provides functions converting between the 32 and 64 bit - struct utmp variants. */ - -#ifndef _UTMP_CONVERT_H -#define _UTMP_CONVERT_H 1 - -#include - -#include "utmp32.h" - -/* Convert the 64 bit struct utmp value in FROM to the 32 bit version - returned in TO. */ -static inline void -utmp_convert64to32 (const struct utmp *from, struct utmp32 *to) -{ -#if _HAVE_UT_TYPE - 0 - to->ut_type = from->ut_type; -#endif -#if _HAVE_UT_PID - 0 - to->ut_pid = from->ut_pid; -#endif - memcpy (to->ut_line, from->ut_line, UT_LINESIZE); - memcpy (to->ut_user, from->ut_user, UT_NAMESIZE); -#if _HAVE_UT_ID - 0 - memcpy (to->ut_id, from->ut_id, 4); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (to->ut_host, from->ut_host, UT_HOSTSIZE); -#endif - to->ut_exit = from->ut_exit; - to->ut_session = (int32_t) from->ut_session; -#if _HAVE_UT_TV - 0 - to->ut_tv.tv_sec = (int32_t) from->ut_tv.tv_sec; - to->ut_tv.tv_usec = (int32_t) from->ut_tv.tv_usec; -#endif - memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4); -} - -/* Convert the 32 bit struct utmp value in FROM to the 64 bit version - returned in TO. */ -static inline void -utmp_convert32to64 (const struct utmp32 *from, struct utmp *to) -{ -#if _HAVE_UT_TYPE - 0 - to->ut_type = from->ut_type; -#endif -#if _HAVE_UT_PID - 0 - to->ut_pid = from->ut_pid; -#endif - memcpy (to->ut_line, from->ut_line, UT_LINESIZE); - memcpy (to->ut_user, from->ut_user, UT_NAMESIZE); -#if _HAVE_UT_ID - 0 - memcpy (to->ut_id, from->ut_id, 4); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (to->ut_host, from->ut_host, UT_HOSTSIZE); -#endif - to->ut_exit = from->ut_exit; - to->ut_session = (int64_t) from->ut_session; -#if _HAVE_UT_TV - 0 - to->ut_tv.tv_sec = (int64_t) from->ut_tv.tv_sec; - to->ut_tv.tv_usec = (int64_t) from->ut_tv.tv_usec; -#endif - memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4); -} - -#endif /* utmp-convert.h */ diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c b/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c deleted file mode 100644 index 66b5a4cacf..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c +++ /dev/null @@ -1,183 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -#include "utmp32.h" -#include "utmp-convert.h" - -/* Allocate a static buffer to be returned to the caller. As well as - with the existing version of these functions the caller has to be - aware that the contents of this buffer will change with subsequent - calls. */ -#define ALLOCATE_UTMP32_OUT(OUT) \ - static struct utmp32 *OUT = NULL; \ - \ - if (OUT == NULL) \ - { \ - OUT = malloc (sizeof (struct utmp32)); \ - if (OUT == NULL) \ - return NULL; \ - } - -/* Perform a lookup for a utmp entry matching FIELD using function - FUNC. FIELD is converted to a 64 bit utmp and the result is - converted back to 32 bit utmp. */ -#define ACCESS_UTMP_ENTRY(FUNC, FIELD) \ - struct utmp in64; \ - struct utmp *out64; \ - ALLOCATE_UTMP32_OUT (out32); \ - \ - utmp_convert32to64 (FIELD, &in64); \ - out64 = FUNC (&in64); \ - \ - if (out64 == NULL) \ - return NULL; \ - \ - utmp_convert64to32 (out64, out32); \ - \ - return out32; - -/* Search forward from the current point in the utmp file until the - next entry with a ut_type matching ID->ut_type. */ -struct utmp32 * -getutid32 (const struct utmp32 *id) -{ - ACCESS_UTMP_ENTRY (__getutid, id) -} -symbol_version (getutid32, getutid, GLIBC_2.0); - -/* Search forward from the current point in the utmp file until the - next entry with a ut_line matching LINE->ut_line. */ -struct utmp32 * -getutline32 (const struct utmp32 *line) -{ - ACCESS_UTMP_ENTRY (__getutline, line) -} -symbol_version (getutline32, getutline, GLIBC_2.0); - -/* Write out entry pointed to by UTMP_PTR into the utmp file. */ -struct utmp32 * -pututline32 (const struct utmp32 *utmp_ptr) -{ - ACCESS_UTMP_ENTRY (__pututline, utmp_ptr) -} -symbol_version (pututline32, pututline, GLIBC_2.0); - -/* Read next entry from a utmp-like file. */ -struct utmp32 * -getutent32 (void) -{ - struct utmp *out64; - ALLOCATE_UTMP32_OUT (out32); - - out64 = __getutent (); - if (!out64) - return NULL; - - utmp_convert64to32 (out64, out32); - return out32; -} -symbol_version (getutent32, getutent, GLIBC_2.0); - -/* Reentrant versions of the file for handling utmp files. */ - -int -getutent32_r (struct utmp32 *buffer, struct utmp32 **result) -{ - struct utmp out64; - struct utmp *out64p; - int ret; - - ret = __getutent_r (&out64, &out64p); - if (ret == -1) - { - *result = NULL; - return -1; - } - - utmp_convert64to32 (out64p, buffer); - *result = buffer; - - return 0; -} -symbol_version (getutent32_r, getutent_r, GLIBC_2.0); - -int -getutid32_r (const struct utmp32 *id, struct utmp32 *buffer, - struct utmp32 **result) -{ - struct utmp in64; - struct utmp out64; - struct utmp *out64p; - int ret; - - utmp_convert32to64 (id, &in64); - - ret = __getutid_r (&in64, &out64, &out64p); - if (ret == -1) - { - *result = NULL; - return -1; - } - - utmp_convert64to32 (out64p, buffer); - *result = buffer; - - return 0; -} -symbol_version (getutid32_r, getutid_r, GLIBC_2.0); - -int -getutline32_r (const struct utmp32 *line, - struct utmp32 *buffer, struct utmp32 **result) -{ - struct utmp in64; - struct utmp out64; - struct utmp *out64p; - int ret; - - utmp_convert32to64 (line, &in64); - - ret = __getutline_r (&in64, &out64, &out64p); - if (ret == -1) - { - *result = NULL; - return -1; - } - - utmp_convert64to32 (out64p, buffer); - *result = buffer; - - return 0; - -} -symbol_version (getutline32_r, getutline_r, GLIBC_2.0); - -/* Append entry UTMP to the wtmp-like file WTMP_FILE. */ -void -updwtmp32 (const char *wtmp_file, const struct utmp32 *utmp) -{ - struct utmp in32; - - utmp_convert32to64 (utmp, &in32); - __updwtmp (wtmp_file, &in32); -} -symbol_version (updwtmp32, updwtmp, GLIBC_2.0); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.h b/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.h deleted file mode 100644 index 30037f2859..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/utmp32.h +++ /dev/null @@ -1,51 +0,0 @@ -/* The `struct utmp' type, describing entries in the utmp file. GNU version. - Copyright (C) 1993-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _UTMP32_H -#define _UTMP32_H 1 - -#include -#include -#include -#include -#include - -/* The structure describing an entry in the user accounting database. */ -struct utmp32 -{ - short int ut_type; /* Type of login. */ - pid_t ut_pid; /* Process ID of login process. */ - char ut_line[UT_LINESIZE]; /* Devicename. */ - char ut_id[4]; /* Inittab ID. */ - char ut_user[UT_NAMESIZE]; /* Username. */ - char ut_host[UT_HOSTSIZE]; /* Hostname for remote login. */ - struct exit_status ut_exit; /* Exit status of a process marked - as DEAD_PROCESS. */ - int32_t ut_session; /* Session ID, used for windowing. */ - struct - { - int32_t tv_sec; /* Seconds. */ - int32_t tv_usec; /* Microseconds. */ - } ut_tv; /* Time entry was made. */ - - int32_t ut_addr_v6[4]; /* Internet address of remote host. */ - char __glibc_reserved[20]; /* Reserved for future use. */ -}; - - -#endif /* utmp32.h */ diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx-convert.h b/sysdeps/unix/sysv/linux/s390/s390-32/utmpx-convert.h deleted file mode 100644 index 8fb5bd2548..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx-convert.h +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - - -/* This file provides functions converting between the 32 and 64 bit - struct utmp variants. */ - -#ifndef _UTMPX_CONVERT_H -#define _UTMPX_CONVERT_H 1 - -#include -#include "utmpx32.h" - -/* Convert the 64 bit struct utmpx value in FROM to the 32 bit version - returned in TO. */ -static inline void -utmpx_convert64to32 (const struct utmpx *from, struct utmpx32 *to) -{ -#if _HAVE_UT_TYPE - 0 - to->ut_type = from->ut_type; -#endif -#if _HAVE_UT_PID - 0 - to->ut_pid = from->ut_pid; -#endif - memcpy (to->ut_line, from->ut_line, __UT_LINESIZE); - memcpy (to->ut_user, from->ut_user, __UT_NAMESIZE); -#if _HAVE_UT_ID - 0 - memcpy (to->ut_id, from->ut_id, 4); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (to->ut_host, from->ut_host, __UT_HOSTSIZE); -#endif - to->ut_exit = from->ut_exit; - to->ut_session = (int32_t) from->ut_session; -#if _HAVE_UT_TV - 0 - to->ut_tv.tv_sec = (int32_t) from->ut_tv.tv_sec; - to->ut_tv.tv_usec = (int32_t) from->ut_tv.tv_usec; -#endif - memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4); -} - -/* Convert the 32 bit struct utmpx value in FROM to the 64 bit version - returned in TO. */ -static inline void -utmpx_convert32to64 (const struct utmpx32 *from, struct utmpx *to) -{ -#if _HAVE_UT_TYPE - 0 - to->ut_type = from->ut_type; -#endif -#if _HAVE_UT_PID - 0 - to->ut_pid = from->ut_pid; -#endif - memcpy (to->ut_line, from->ut_line, __UT_LINESIZE); - memcpy (to->ut_user, from->ut_user, __UT_NAMESIZE); -#if _HAVE_UT_ID - 0 - memcpy (to->ut_id, from->ut_id, 4); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (to->ut_host, from->ut_host, __UT_HOSTSIZE); -#endif - to->ut_exit = from->ut_exit; - to->ut_session = (int64_t) from->ut_session; -#if _HAVE_UT_TV - 0 - to->ut_tv.tv_sec = (int64_t) from->ut_tv.tv_sec; - to->ut_tv.tv_usec = (int64_t) from->ut_tv.tv_usec; -#endif - memcpy (to->ut_addr_v6, from->ut_addr_v6, 4 * 4); -} - -#endif /* utmpx-convert.h */ diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c b/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c deleted file mode 100644 index 39ee486e1e..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright (C) 2008-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -#include "utmp32.h" -#include "utmp-convert.h" - -#include "utmpx32.h" -#include "utmpx-convert.h" - -/* Allocate a static buffer to be returned to the caller. As well as - with the existing version of these functions the caller has to be - aware that the contents of this buffer will change with subsequent - calls. */ -#define ALLOCATE_UTMPX32_OUT(OUT) \ - static struct utmpx32 *OUT = NULL; \ - \ - if (OUT == NULL) \ - { \ - OUT = malloc (sizeof (struct utmpx32)); \ - if (OUT == NULL) \ - return NULL; \ - } - -/* Perform a lookup for a utmpx entry matching FIELD using function - FUNC. FIELD is converted to a 64 bit utmpx and the result is - converted back to 32 bit utmpx. */ -#define ACCESS_UTMPX_ENTRY(FUNC, FIELD) \ - struct utmpx in64; \ - struct utmpx *out64; \ - ALLOCATE_UTMPX32_OUT (out32); \ - \ - utmpx_convert32to64 (FIELD, &in64); \ - out64 = FUNC (&in64); \ - \ - if (out64 == NULL) \ - return NULL; \ - \ - utmpx_convert64to32 (out64, out32); \ - \ - return out32; - - -/* Get the next entry from the user accounting database. */ -struct utmpx32 * -getutxent32 (void) -{ - struct utmpx *out64; - ALLOCATE_UTMPX32_OUT (out32); - - out64 = __getutxent (); - if (!out64) - return NULL; - - utmpx_convert64to32 (out64, out32); - return out32; - -} -symbol_version (getutxent32, getutxent, GLIBC_2.1); - -/* Get the user accounting database entry corresponding to ID. */ -struct utmpx32 * -getutxid32 (const struct utmpx32 *id) -{ - ACCESS_UTMPX_ENTRY (__getutxid, id); -} -symbol_version (getutxid32, getutxid, GLIBC_2.1); - -/* Get the user accounting database entry corresponding to LINE. */ -struct utmpx32 * -getutxline32 (const struct utmpx32 *line) -{ - ACCESS_UTMPX_ENTRY (__getutxline, line); -} -symbol_version (getutxline32, getutxline, GLIBC_2.1); - -/* Write the entry UTMPX into the user accounting database. */ -struct utmpx32 * -pututxline32 (const struct utmpx32 *utmpx) -{ - ACCESS_UTMPX_ENTRY (__pututxline, utmpx); -} -symbol_version (pututxline32, pututxline, GLIBC_2.1); - -/* Append entry UTMP to the wtmpx-like file WTMPX_FILE. */ -void -updwtmpx32 (const char *wtmpx_file, const struct utmpx32 *utmpx) -{ - struct utmpx in64; - - utmpx_convert32to64 (utmpx, &in64); - __updwtmpx (wtmpx_file, &in64); -} -symbol_version (updwtmpx32, updwtmpx, GLIBC_2.1); - -/* Copy the information in UTMPX to UTMP. */ -void -getutmp32 (const struct utmpx32 *utmpx, struct utmp32 *utmp) -{ - struct utmpx in64; - struct utmp out64; - - utmpx_convert32to64 (utmpx, &in64); - __getutmp (&in64, &out64); - utmp_convert64to32 (&out64, utmp); -} -symbol_version (getutmp32, getutmp, GLIBC_2.1.1); - -/* Copy the information in UTMP to UTMPX. */ -void -getutmpx32 (const struct utmp32 *utmp, struct utmpx32 *utmpx) -{ - struct utmp in64; - struct utmpx out64; - - utmp_convert32to64 (utmp, &in64); - __getutmpx (&in64, &out64); - utmpx_convert64to32 (&out64, utmpx); -} -symbol_version (getutmpx32, getutmpx, GLIBC_2.1.1); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.h b/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.h deleted file mode 100644 index ff4786e387..0000000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.h +++ /dev/null @@ -1,59 +0,0 @@ -/* The `struct utmp' type, describing entries in the utmp file. GNU version. - Copyright (C) 1993-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _UTMPX32_H -#define _UTMPX32_H 1 - -#include -#include -#include -#include -#include - -/* The structure describing an entry in the user accounting database. */ -struct utmpx32 -{ - short int ut_type; /* Type of login. */ - __pid_t ut_pid; /* Process ID of login process. */ - char ut_line[__UT_LINESIZE]; /* Devicename. */ - char ut_id[4]; /* Inittab ID. */ - char ut_user[__UT_NAMESIZE]; /* Username. */ - char ut_host[__UT_HOSTSIZE]; /* Hostname for remote login. */ - struct __exit_status ut_exit; /* Exit status of a process marked - as DEAD_PROCESS. */ - __int64_t ut_session; /* Session ID, used for windowing. */ - struct - { - __int64_t tv_sec; /* Seconds. */ - __int64_t tv_usec; /* Microseconds. */ - } ut_tv; /* Time entry was made. */ - - __int32_t ut_addr_v6[4]; /* Internet address of remote host. */ - char __glibc_reserved[20]; /* Reserved for future use. */ -}; - -/* The internal interface needed by the compat wrapper functions. */ -extern struct utmpx *__getutxent (void); -extern struct utmpx *__getutxid (const struct utmpx *__id); -extern struct utmpx *__getutxline (const struct utmpx *__line); -extern struct utmpx *__pututxline (const struct utmpx *__utmpx); -extern void __updwtmpx (const char *__wtmpx_file, const struct utmpx *__utmpx); -extern void __getutmp (const struct utmpx *__utmpx, struct utmp *__utmp); -extern void __getutmpx (const struct utmp *__utmp, struct utmpx *__utmpx); - -#endif /* utmpx32.h */ diff --git a/sysdeps/unix/sysv/linux/utmp_file.c b/sysdeps/unix/sysv/linux/utmp_file.c deleted file mode 100644 index f2d23a50a2..0000000000 --- a/sysdeps/unix/sysv/linux/utmp_file.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 1998-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#define TRANSFORM_UTMP_FILE_NAME(file_name) \ - ((strcmp (file_name, _PATH_UTMP) == 0 \ - && __access (_PATH_UTMP "x", F_OK) == 0) \ - ? (_PATH_UTMP "x") \ - : ((strcmp (file_name, _PATH_WTMP) == 0 \ - && __access ( _PATH_WTMP "x", F_OK) == 0) \ - ? (_PATH_WTMP "x") \ - : ((strcmp (file_name, _PATH_UTMP "x") == 0 \ - && __access (_PATH_UTMP "x", F_OK) != 0) \ - ? _PATH_UTMP \ - : ((strcmp (file_name, _PATH_WTMP "x") == 0 \ - && __access (_PATH_WTMP "x", F_OK) != 0) \ - ? _PATH_WTMP \ - : file_name)))) - -#include