Blame pwd/getpw.c

Packit Service 82fcde
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <alloca.h>
Packit Service 82fcde
#include <errno.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <unistd.h>
Packit Service 82fcde
#include <pwd.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Re-construct the password-file line for the given uid
Packit Service 82fcde
   in the given buffer.  This knows the format that the caller
Packit Service 82fcde
   will expect, but this need not be the format of the password file.  */
Packit Service 82fcde
Packit Service 82fcde
int __getpw (__uid_t uid, char *buf);
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
__getpw (__uid_t uid, char *buf)
Packit Service 82fcde
{
Packit Service 82fcde
  size_t buflen;
Packit Service 82fcde
  char *tmpbuf;
Packit Service 82fcde
  struct passwd resbuf, *p;
Packit Service 82fcde
Packit Service 82fcde
  if (buf == NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      __set_errno (EINVAL);
Packit Service 82fcde
      return -1;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  buflen = __sysconf (_SC_GETPW_R_SIZE_MAX);
Packit Service 82fcde
  tmpbuf = alloca (buflen);
Packit Service 82fcde
Packit Service 82fcde
  if (__getpwuid_r (uid, &resbuf, tmpbuf, buflen, &p) != 0)
Packit Service 82fcde
    return -1;
Packit Service 82fcde
Packit Service 82fcde
  if (p == NULL)
Packit Service 82fcde
    return -1;
Packit Service 82fcde
Packit Service 82fcde
  if (sprintf (buf, "%s:%s:%lu:%lu:%s:%s:%s", p->pw_name, p->pw_passwd,
Packit Service 82fcde
	       (unsigned long int) p->pw_uid, (unsigned long int) p->pw_gid,
Packit Service 82fcde
	       p->pw_gecos, p->pw_dir, p->pw_shell) < 0)
Packit Service 82fcde
    return -1;
Packit Service 82fcde
Packit Service 82fcde
  return 0;
Packit Service 82fcde
}
Packit Service 82fcde
weak_alias (__getpw, getpw)
Packit Service 82fcde
Packit Service 82fcde
link_warning (getpw, "the `getpw' function is dangerous and should not be used.")