1 /* Copyright (C) 2008 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #include <sys/types.h>
23 #include <libc-symbols.h>
26 #include "utmp-convert.h"
28 /* Allocate a static buffer to be returned to the caller. As well as
29 with the existing version of these functions the caller has to be
30 aware that the contents of this buffer will change with subsequent
32 #define ALLOCATE_UTMP32_OUT(OUT) \
33 static struct utmp32 *OUT = NULL; \
37 OUT = malloc (sizeof (struct utmp32)); \
42 /* Perform a lookup for a utmp entry matching FIELD using function
43 FUNC. FIELD is converted to a 64 bit utmp and the result is
44 converted back to 32 bit utmp. */
45 #define ACCESS_UTMP_ENTRY(FUNC, FIELD) \
48 ALLOCATE_UTMP32_OUT (out32); \
50 utmp_convert32to64 (FIELD, &in64); \
51 out64 = FUNC (&in64); \
56 utmp_convert64to32 (out64, out32); \
60 /* Search forward from the current point in the utmp file until the
61 next entry with a ut_type matching ID->ut_type. */
63 getutid32 (const struct utmp32
*id
)
65 ACCESS_UTMP_ENTRY (getutid
, id
)
67 symbol_version (getutid32
, getutid
, GLIBC_2
.0
);
69 /* Search forward from the current point in the utmp file until the
70 next entry with a ut_line matching LINE->ut_line. */
72 getutline32 (const struct utmp32
*line
)
74 ACCESS_UTMP_ENTRY (getutline
, line
)
76 symbol_version (getutline32
, getutline
, GLIBC_2
.0
);
78 /* Write out entry pointed to by UTMP_PTR into the utmp file. */
80 pututline32 (const struct utmp32
*utmp_ptr
)
82 ACCESS_UTMP_ENTRY (pututline
, utmp_ptr
)
84 symbol_version (pututline32
, pututline
, GLIBC_2
.0
);
86 /* Read next entry from a utmp-like file. */
91 ALLOCATE_UTMP32_OUT (out32
);
97 utmp_convert64to32 (out64
, out32
);
100 symbol_version (getutent32
, getutent
, GLIBC_2
.0
);
102 /* Reentrant versions of the file for handling utmp files. */
105 getutent32_r (struct utmp32
*buffer
, struct utmp32
**result
)
111 ret
= getutent_r (&out64
, &out64p
);
118 utmp_convert64to32 (out64p
, buffer
);
123 symbol_version (getutent32_r
, getutent_r
, GLIBC_2
.0
);
126 getutid32_r (const struct utmp32
*id
, struct utmp32
*buffer
,
127 struct utmp32
**result
)
134 utmp_convert32to64 (id
, &in64
);
136 ret
= getutid_r (&in64
, &out64
, &out64p
);
143 utmp_convert64to32 (out64p
, buffer
);
148 symbol_version (getutid32_r
, getutid_r
, GLIBC_2
.0
);
151 getutline32_r (const struct utmp32
*line
,
152 struct utmp32
*buffer
, struct utmp32
**result
)
159 utmp_convert32to64 (line
, &in64
);
161 ret
= getutline_r (&in64
, &out64
, &out64p
);
168 utmp_convert64to32 (out64p
, buffer
);
174 symbol_version (getutline32_r
, getutline_r
, GLIBC_2
.0
);
176 /* Append entry UTMP to the wtmp-like file WTMP_FILE. */
178 updwtmp32 (const char *wtmp_file
, const struct utmp32
*utmp
)
182 utmp_convert32to64 (utmp
, &in32
);
183 updwtmp (wtmp_file
, &in32
);
185 symbol_version (updwtmp32
, updwtmp
, GLIBC_2
.0
);