]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / utmp32.c
1 /* Copyright (C) 2008-2021 Free Software Foundation, Inc.
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
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <sys/types.h>
20 #include <utmp.h>
21 #include <errno.h>
22 #include <stdlib.h>
23
24 #include "utmp32.h"
25 #include "utmp-convert.h"
26
27 /* Allocate a static buffer to be returned to the caller. As well as
28 with the existing version of these functions the caller has to be
29 aware that the contents of this buffer will change with subsequent
30 calls. */
31 #define ALLOCATE_UTMP32_OUT(OUT) \
32 static struct utmp32 *OUT = NULL; \
33 \
34 if (OUT == NULL) \
35 { \
36 OUT = malloc (sizeof (struct utmp32)); \
37 if (OUT == NULL) \
38 return NULL; \
39 }
40
41 /* Perform a lookup for a utmp entry matching FIELD using function
42 FUNC. FIELD is converted to a 64 bit utmp and the result is
43 converted back to 32 bit utmp. */
44 #define ACCESS_UTMP_ENTRY(FUNC, FIELD) \
45 struct utmp in64; \
46 struct utmp *out64; \
47 ALLOCATE_UTMP32_OUT (out32); \
48 \
49 utmp_convert32to64 (FIELD, &in64); \
50 out64 = FUNC (&in64); \
51 \
52 if (out64 == NULL) \
53 return NULL; \
54 \
55 utmp_convert64to32 (out64, out32); \
56 \
57 return out32;
58
59 /* Search forward from the current point in the utmp file until the
60 next entry with a ut_type matching ID->ut_type. */
61 struct utmp32 *
62 getutid32 (const struct utmp32 *id)
63 {
64 ACCESS_UTMP_ENTRY (__getutid, id)
65 }
66 symbol_version (getutid32, getutid, GLIBC_2.0);
67
68 /* Search forward from the current point in the utmp file until the
69 next entry with a ut_line matching LINE->ut_line. */
70 struct utmp32 *
71 getutline32 (const struct utmp32 *line)
72 {
73 ACCESS_UTMP_ENTRY (__getutline, line)
74 }
75 symbol_version (getutline32, getutline, GLIBC_2.0);
76
77 /* Write out entry pointed to by UTMP_PTR into the utmp file. */
78 struct utmp32 *
79 pututline32 (const struct utmp32 *utmp_ptr)
80 {
81 ACCESS_UTMP_ENTRY (__pututline, utmp_ptr)
82 }
83 symbol_version (pututline32, pututline, GLIBC_2.0);
84
85 /* Read next entry from a utmp-like file. */
86 struct utmp32 *
87 getutent32 (void)
88 {
89 struct utmp *out64;
90 ALLOCATE_UTMP32_OUT (out32);
91
92 out64 = __getutent ();
93 if (!out64)
94 return NULL;
95
96 utmp_convert64to32 (out64, out32);
97 return out32;
98 }
99 symbol_version (getutent32, getutent, GLIBC_2.0);
100
101 /* Reentrant versions of the file for handling utmp files. */
102
103 int
104 getutent32_r (struct utmp32 *buffer, struct utmp32 **result)
105 {
106 struct utmp out64;
107 struct utmp *out64p;
108 int ret;
109
110 ret = __getutent_r (&out64, &out64p);
111 if (ret == -1)
112 {
113 *result = NULL;
114 return -1;
115 }
116
117 utmp_convert64to32 (out64p, buffer);
118 *result = buffer;
119
120 return 0;
121 }
122 symbol_version (getutent32_r, getutent_r, GLIBC_2.0);
123
124 int
125 getutid32_r (const struct utmp32 *id, struct utmp32 *buffer,
126 struct utmp32 **result)
127 {
128 struct utmp in64;
129 struct utmp out64;
130 struct utmp *out64p;
131 int ret;
132
133 utmp_convert32to64 (id, &in64);
134
135 ret = __getutid_r (&in64, &out64, &out64p);
136 if (ret == -1)
137 {
138 *result = NULL;
139 return -1;
140 }
141
142 utmp_convert64to32 (out64p, buffer);
143 *result = buffer;
144
145 return 0;
146 }
147 symbol_version (getutid32_r, getutid_r, GLIBC_2.0);
148
149 int
150 getutline32_r (const struct utmp32 *line,
151 struct utmp32 *buffer, struct utmp32 **result)
152 {
153 struct utmp in64;
154 struct utmp out64;
155 struct utmp *out64p;
156 int ret;
157
158 utmp_convert32to64 (line, &in64);
159
160 ret = __getutline_r (&in64, &out64, &out64p);
161 if (ret == -1)
162 {
163 *result = NULL;
164 return -1;
165 }
166
167 utmp_convert64to32 (out64p, buffer);
168 *result = buffer;
169
170 return 0;
171
172 }
173 symbol_version (getutline32_r, getutline_r, GLIBC_2.0);
174
175 /* Append entry UTMP to the wtmp-like file WTMP_FILE. */
176 void
177 updwtmp32 (const char *wtmp_file, const struct utmp32 *utmp)
178 {
179 struct utmp in32;
180
181 utmp_convert32to64 (utmp, &in32);
182 __updwtmp (wtmp_file, &in32);
183 }
184 symbol_version (updwtmp32, updwtmp, GLIBC_2.0);