]> git.ipfire.org Git - thirdparty/glibc.git/blame - login/getutent_r.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / login / getutent_r.c
CommitLineData
f7a9f785 1/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
8a523922
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>
4 and Paul Janzen <pcj@primenet.com>, 1996.
b8fe19fa 5
8a523922 6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
b8fe19fa 10
8a523922
UD
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 14 Lesser General Public License for more details.
b8fe19fa 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
b8fe19fa 19
ec999b8e 20#include <libc-lock.h>
282cbdef 21#include <stdlib.h>
b8fe19fa
RM
22#include <utmp.h>
23
8a523922 24#include "utmp-private.h"
b8fe19fa 25
8a523922 26
0413b54c
UD
27/* Functions defined here. */
28static int setutent_unknown (void);
76b87c03 29static int getutent_r_unknown (struct utmp *buffer, struct utmp **result);
0413b54c
UD
30static int getutid_r_unknown (const struct utmp *line, struct utmp *buffer,
31 struct utmp **result);
32static int getutline_r_unknown (const struct utmp *id, struct utmp *buffer,
33 struct utmp **result);
76b87c03
UD
34static struct utmp *pututline_unknown (const struct utmp *data);
35static void endutent_unknown (void);
8a523922 36
76b87c03 37/* Initial Jump table. */
b2637a22 38const struct utfuncs __libc_utmp_unknown_functions =
8a523922 39{
76b87c03
UD
40 setutent_unknown,
41 getutent_r_unknown,
0413b54c
UD
42 getutid_r_unknown,
43 getutline_r_unknown,
76b87c03
UD
44 pututline_unknown,
45 endutent_unknown,
8a523922
UD
46 NULL
47};
48
49/* Currently selected backend. */
b2637a22 50const struct utfuncs *__libc_utmp_jump_table = &__libc_utmp_unknown_functions;
8a523922
UD
51
52/* We need to protect the opening of the file. */
ab26a24a 53__libc_lock_define_initialized (, __libc_utmp_lock attribute_hidden)
8a523922 54
5107cf1d 55
0413b54c
UD
56static int
57setutent_unknown (void)
8a523922 58{
0413b54c 59 int result;
8a523922 60
33c50f10 61 result = (*__libc_utmp_file_functions.setutent) ();
0413b54c 62 if (result)
33c50f10 63 __libc_utmp_jump_table = &__libc_utmp_file_functions;
8a523922 64
0413b54c 65 return result;
8a523922 66}
8a523922
UD
67
68
0413b54c
UD
69static int
70getutent_r_unknown (struct utmp *buffer, struct utmp **result)
8a523922 71{
0413b54c
UD
72 /* The backend was not yet initialized. */
73 if (setutent_unknown ())
74 return (*__libc_utmp_jump_table->getutent_r) (buffer, result);
8a523922 75
0413b54c
UD
76 /* Not available. */
77 *result = NULL;
78 return -1;
79}
b8fe19fa 80
0413b54c
UD
81
82static int
83getutid_r_unknown (const struct utmp *id, struct utmp *buffer,
84 struct utmp **result)
85{
86 /* The backend was not yet initialized. */
87 if (setutent_unknown ())
88 return (*__libc_utmp_jump_table->getutid_r) (id, buffer, result);
89
90 /* Not available. */
91 *result = NULL;
92 return -1;
8a523922 93}
b8fe19fa 94
b8fe19fa 95
55c14926 96static int
0413b54c
UD
97getutline_r_unknown (const struct utmp *line, struct utmp *buffer,
98 struct utmp **result)
8f2ece69 99{
0413b54c
UD
100 /* The backend was not yet initialized. */
101 if (setutent_unknown ())
102 return (*__libc_utmp_jump_table->getutline_r) (line, buffer, result);
55c14926 103
0413b54c
UD
104 /* Not available. */
105 *result = NULL;
106 return -1;
107}
55c14926 108
0413b54c
UD
109
110static struct utmp *
111pututline_unknown (const struct utmp *data)
112{
113 /* The backend was not yet initialized. */
114 if (setutent_unknown ())
115 return (*__libc_utmp_jump_table->pututline) (data);
116
117 /* Not available. */
118 return NULL;
8f2ece69
UD
119}
120
121
8a523922 122static void
76b87c03 123endutent_unknown (void)
8a523922 124{
0413b54c 125 /* Nothing to do. */
8a523922
UD
126}
127
128
0413b54c
UD
129void
130__setutent (void)
131{
132 __libc_lock_lock (__libc_utmp_lock);
133
134 (*__libc_utmp_jump_table->setutent) ();
135
136 __libc_lock_unlock (__libc_utmp_lock);
137}
138weak_alias (__setutent, setutent)
0413b54c
UD
139
140
8a523922
UD
141int
142__getutent_r (struct utmp *buffer, struct utmp **result)
143{
144 int retval;
145
146 __libc_lock_lock (__libc_utmp_lock);
147
148 retval = (*__libc_utmp_jump_table->getutent_r) (buffer, result);
149
150 __libc_lock_unlock (__libc_utmp_lock);
151
152 return retval;
b8fe19fa 153}
23396375 154weak_alias (__getutent_r, getutent_r)
8a523922
UD
155
156
a401eea9 157struct utmp *
8a523922
UD
158__pututline (const struct utmp *data)
159{
a401eea9
UD
160 struct utmp *buffer;
161
8a523922
UD
162 __libc_lock_lock (__libc_utmp_lock);
163
a401eea9 164 buffer = (*__libc_utmp_jump_table->pututline) (data);
8a523922
UD
165
166 __libc_lock_unlock (__libc_utmp_lock);
a401eea9
UD
167
168 return buffer;
8a523922 169}
a401eea9 170weak_alias (__pututline, pututline)
8a523922 171
8f2ece69 172
0413b54c
UD
173void
174__endutent (void)
8a523922 175{
0413b54c 176 __libc_lock_lock (__libc_utmp_lock);
8a523922 177
0413b54c
UD
178 (*__libc_utmp_jump_table->endutent) ();
179 __libc_utmp_jump_table = &__libc_utmp_unknown_functions;
180
181 __libc_lock_unlock (__libc_utmp_lock);
8a523922 182}
0413b54c 183weak_alias (__endutent, endutent)