1/* GLIB - Library of useful routines for C programming
2 *
3 * Copyright (C) 2020 Red Hat, Inc.
4 *
5 * Author: Jakub Jelen <jjelen@redhat.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <dlfcn.h>
22#include <pwd.h>
23#include <sys/types.h>
24#include <unistd.h>
25
26static struct passwd my_pw;
27
28/* This is used in gutils.c used to make sure utility functions
29 * handling user information do not crash on bad data (for example
30 * caused by getpwuid returning some NULL elements.
31 */
32struct passwd *
33getpwuid (uid_t uid)
34{
35 static struct passwd *(*real_getpwuid) (uid_t);
36 struct passwd *pw;
37
38 if (real_getpwuid == NULL)
39 real_getpwuid = dlsym (RTLD_NEXT, name: "getpwuid");
40
41 pw = real_getpwuid (uid);
42 my_pw = *pw;
43 my_pw.pw_name = NULL;
44 return &my_pw;
45}
46

source code of gtk/subprojects/glib/glib/tests/getpwuid-preload.c