]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/s390/s390-32/utmpx32.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / utmpx32.c
CommitLineData
2b778ceb 1/* Copyright (C) 2008-2021 Free Software Foundation, Inc.
4057dc45
UD
2 Contributed by Andreas Krebbel <Andreas.Krebbel@de.ibm.com>.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
4057dc45
UD
18
19#include <sys/types.h>
20#include <utmp.h>
21#include <errno.h>
01bd6251 22#include <stdlib.h>
4057dc45
UD
23
24#include "utmp32.h"
25#include "utmp-convert.h"
26
27#include "utmpx32.h"
28#include "utmpx-convert.h"
29
30/* Allocate a static buffer to be returned to the caller. As well as
31 with the existing version of these functions the caller has to be
32 aware that the contents of this buffer will change with subsequent
33 calls. */
34#define ALLOCATE_UTMPX32_OUT(OUT) \
35 static struct utmpx32 *OUT = NULL; \
0cbcca89 36 \
4057dc45
UD
37 if (OUT == NULL) \
38 { \
39 OUT = malloc (sizeof (struct utmpx32)); \
40 if (OUT == NULL) \
41 return NULL; \
42 }
43
44/* Perform a lookup for a utmpx entry matching FIELD using function
45 FUNC. FIELD is converted to a 64 bit utmpx and the result is
46 converted back to 32 bit utmpx. */
47#define ACCESS_UTMPX_ENTRY(FUNC, FIELD) \
48 struct utmpx in64; \
49 struct utmpx *out64; \
50 ALLOCATE_UTMPX32_OUT (out32); \
51 \
52 utmpx_convert32to64 (FIELD, &in64); \
53 out64 = FUNC (&in64); \
54 \
55 if (out64 == NULL) \
56 return NULL; \
57 \
58 utmpx_convert64to32 (out64, out32); \
59 \
60 return out32;
61
62
63/* Get the next entry from the user accounting database. */
64struct utmpx32 *
65getutxent32 (void)
66{
67 struct utmpx *out64;
68 ALLOCATE_UTMPX32_OUT (out32);
69
03849910 70 out64 = __getutxent ();
4057dc45
UD
71 if (!out64)
72 return NULL;
73
74 utmpx_convert64to32 (out64, out32);
75 return out32;
76
77}
78symbol_version (getutxent32, getutxent, GLIBC_2.1);
79
80/* Get the user accounting database entry corresponding to ID. */
81struct utmpx32 *
82getutxid32 (const struct utmpx32 *id)
83{
03849910 84 ACCESS_UTMPX_ENTRY (__getutxid, id);
4057dc45
UD
85}
86symbol_version (getutxid32, getutxid, GLIBC_2.1);
87
88/* Get the user accounting database entry corresponding to LINE. */
89struct utmpx32 *
90getutxline32 (const struct utmpx32 *line)
91{
03849910 92 ACCESS_UTMPX_ENTRY (__getutxline, line);
4057dc45
UD
93}
94symbol_version (getutxline32, getutxline, GLIBC_2.1);
95
96/* Write the entry UTMPX into the user accounting database. */
97struct utmpx32 *
98pututxline32 (const struct utmpx32 *utmpx)
99{
03849910 100 ACCESS_UTMPX_ENTRY (__pututxline, utmpx);
4057dc45
UD
101}
102symbol_version (pututxline32, pututxline, GLIBC_2.1);
103
104/* Append entry UTMP to the wtmpx-like file WTMPX_FILE. */
105void
106updwtmpx32 (const char *wtmpx_file, const struct utmpx32 *utmpx)
107{
108 struct utmpx in64;
109
110 utmpx_convert32to64 (utmpx, &in64);
03849910 111 __updwtmpx (wtmpx_file, &in64);
4057dc45
UD
112}
113symbol_version (updwtmpx32, updwtmpx, GLIBC_2.1);
114
115/* Copy the information in UTMPX to UTMP. */
116void
117getutmp32 (const struct utmpx32 *utmpx, struct utmp32 *utmp)
118{
119 struct utmpx in64;
120 struct utmp out64;
121
122 utmpx_convert32to64 (utmpx, &in64);
03849910 123 __getutmp (&in64, &out64);
4057dc45
UD
124 utmp_convert64to32 (&out64, utmp);
125}
126symbol_version (getutmp32, getutmp, GLIBC_2.1.1);
127
128/* Copy the information in UTMP to UTMPX. */
129void
130getutmpx32 (const struct utmp32 *utmp, struct utmpx32 *utmpx)
131{
132 struct utmp in64;
133 struct utmpx out64;
134
135 utmp_convert32to64 (utmp, &in64);
03849910 136 __getutmpx (&in64, &out64);
4057dc45
UD
137 utmpx_convert64to32 (&out64, utmpx);
138}
139symbol_version (getutmpx32, getutmpx, GLIBC_2.1.1);