File: getpwuid-preload.c

package info (click to toggle)
glib2.0 2.66.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, bullseye-backports
  • size: 49,488 kB
  • sloc: ansic: 482,057; xml: 17,293; python: 7,705; sh: 1,310; perl: 1,140; makefile: 194; cpp: 9
file content (45 lines) | stat: -rw-r--r-- 1,390 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* GLIB - Library of useful routines for C programming
 *
 * Copyright (C) 2020 Red Hat, Inc.
 *
 * Author: Jakub Jelen <jjelen@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#include <dlfcn.h>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>

static struct passwd my_pw;

/* This is used in gutils.c used to make sure utility functions
 * handling user information do not crash on bad data (for example
 * caused by getpwuid returning some NULL elements.
 */
struct passwd *
getpwuid (uid_t uid)
{
  static struct passwd *(*real_getpwuid) (uid_t);
  struct passwd *pw;

  if (real_getpwuid == NULL)
    real_getpwuid = dlsym (RTLD_NEXT, "getpwuid");

  pw = real_getpwuid (uid);
  my_pw = *pw;
  my_pw.pw_name = NULL;
  return &my_pw;
}