1 /* Copyright (C) 2008-2020 Free Software Foundation, Inc.
2 Contributed by Andreas Krebbel <Andreas.Krebbel@de.ibm.com>.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #include <sys/types.h>
25 #include "utmp-convert.h"
28 #include "utmpx-convert.h"
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
34 #define ALLOCATE_UTMPX32_OUT(OUT) \
35 static struct utmpx32 *OUT = NULL; \
39 OUT = malloc (sizeof (struct utmpx32)); \
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) \
49 struct utmpx *out64; \
50 ALLOCATE_UTMPX32_OUT (out32); \
52 utmpx_convert32to64 (FIELD, &in64); \
53 out64 = FUNC (&in64); \
58 utmpx_convert64to32 (out64, out32); \
63 /* Get the next entry from the user accounting database. */
68 ALLOCATE_UTMPX32_OUT (out32
);
70 out64
= __getutxent ();
74 utmpx_convert64to32 (out64
, out32
);
78 symbol_version (getutxent32
, getutxent
, GLIBC_2
.1
);
80 /* Get the user accounting database entry corresponding to ID. */
82 getutxid32 (const struct utmpx32
*id
)
84 ACCESS_UTMPX_ENTRY (__getutxid
, id
);
86 symbol_version (getutxid32
, getutxid
, GLIBC_2
.1
);
88 /* Get the user accounting database entry corresponding to LINE. */
90 getutxline32 (const struct utmpx32
*line
)
92 ACCESS_UTMPX_ENTRY (__getutxline
, line
);
94 symbol_version (getutxline32
, getutxline
, GLIBC_2
.1
);
96 /* Write the entry UTMPX into the user accounting database. */
98 pututxline32 (const struct utmpx32
*utmpx
)
100 ACCESS_UTMPX_ENTRY (__pututxline
, utmpx
);
102 symbol_version (pututxline32
, pututxline
, GLIBC_2
.1
);
104 /* Append entry UTMP to the wtmpx-like file WTMPX_FILE. */
106 updwtmpx32 (const char *wtmpx_file
, const struct utmpx32
*utmpx
)
110 utmpx_convert32to64 (utmpx
, &in64
);
111 __updwtmpx (wtmpx_file
, &in64
);
113 symbol_version (updwtmpx32
, updwtmpx
, GLIBC_2
.1
);
115 /* Copy the information in UTMPX to UTMP. */
117 getutmp32 (const struct utmpx32
*utmpx
, struct utmp32
*utmp
)
122 utmpx_convert32to64 (utmpx
, &in64
);
123 __getutmp (&in64
, &out64
);
124 utmp_convert64to32 (&out64
, utmp
);
126 symbol_version (getutmp32
, getutmp
, GLIBC_2
.1
.1);
128 /* Copy the information in UTMP to UTMPX. */
130 getutmpx32 (const struct utmp32
*utmp
, struct utmpx32
*utmpx
)
135 utmp_convert32to64 (utmp
, &in64
);
136 __getutmpx (&in64
, &out64
);
137 utmpx_convert64to32 (&out64
, utmpx
);
139 symbol_version (getutmpx32
, getutmpx
, GLIBC_2
.1
.1);