Blame sysdeps/unix/sysv/linux/s390/s390-32/utmp32.c

Packit 6c4009
/* Copyright (C) 2008-2018 Free Software Foundation, Inc.
Packit 6c4009
   Contributed by Andreas Krebbel <Andreas.Krebbel@de.ibm.com>.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
#include <utmp.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <libc-symbols.h>
Packit 6c4009
Packit 6c4009
#include "utmp32.h"
Packit 6c4009
#include "utmp-convert.h"
Packit 6c4009
Packit 6c4009
/* Allocate a static buffer to be returned to the caller.  As well as
Packit 6c4009
   with the existing version of these functions the caller has to be
Packit 6c4009
   aware that the contents of this buffer will change with subsequent
Packit 6c4009
   calls.  */
Packit 6c4009
#define ALLOCATE_UTMP32_OUT(OUT)			\
Packit 6c4009
  static struct utmp32 *OUT = NULL;			\
Packit 6c4009
							\
Packit 6c4009
  if (OUT == NULL)					\
Packit 6c4009
    {							\
Packit 6c4009
      OUT = malloc (sizeof (struct utmp32));		\
Packit 6c4009
      if (OUT == NULL)					\
Packit 6c4009
	return NULL;					\
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
/* Perform a lookup for a utmp entry matching FIELD using function
Packit 6c4009
   FUNC.  FIELD is converted to a 64 bit utmp and the result is
Packit 6c4009
   converted back to 32 bit utmp.  */
Packit 6c4009
#define ACCESS_UTMP_ENTRY(FUNC, FIELD)			\
Packit 6c4009
  struct utmp in64;					\
Packit 6c4009
  struct utmp *out64;					\
Packit 6c4009
  ALLOCATE_UTMP32_OUT (out32);				\
Packit 6c4009
							\
Packit 6c4009
  utmp_convert32to64 (FIELD, &in64);			\
Packit 6c4009
  out64 = FUNC (&in64);					\
Packit 6c4009
							\
Packit 6c4009
  if (out64 == NULL)					\
Packit 6c4009
    return NULL;					\
Packit 6c4009
							\
Packit 6c4009
  utmp_convert64to32 (out64, out32);			\
Packit 6c4009
							\
Packit 6c4009
  return out32;
Packit 6c4009
Packit 6c4009
/* Search forward from the current point in the utmp file until the
Packit 6c4009
   next entry with a ut_type matching ID->ut_type.  */
Packit 6c4009
struct utmp32 *
Packit 6c4009
getutid32 (const struct utmp32 *id)
Packit 6c4009
{
Packit 6c4009
  ACCESS_UTMP_ENTRY (__getutid, id)
Packit 6c4009
}
Packit 6c4009
symbol_version (getutid32, getutid, GLIBC_2.0);
Packit 6c4009
Packit 6c4009
/* Search forward from the current point in the utmp file until the
Packit 6c4009
   next entry with a ut_line matching LINE->ut_line.  */
Packit 6c4009
struct utmp32 *
Packit 6c4009
getutline32 (const struct utmp32 *line)
Packit 6c4009
{
Packit 6c4009
  ACCESS_UTMP_ENTRY (__getutline, line)
Packit 6c4009
}
Packit 6c4009
symbol_version (getutline32, getutline, GLIBC_2.0);
Packit 6c4009
Packit 6c4009
/* Write out entry pointed to by UTMP_PTR into the utmp file.  */
Packit 6c4009
struct utmp32 *
Packit 6c4009
pututline32 (const struct utmp32 *utmp_ptr)
Packit 6c4009
{
Packit 6c4009
  ACCESS_UTMP_ENTRY (__pututline, utmp_ptr)
Packit 6c4009
}
Packit 6c4009
symbol_version (pututline32, pututline, GLIBC_2.0);
Packit 6c4009
Packit 6c4009
/* Read next entry from a utmp-like file.  */
Packit 6c4009
struct utmp32 *
Packit 6c4009
getutent32 (void)
Packit 6c4009
{
Packit 6c4009
  struct utmp *out64;
Packit 6c4009
  ALLOCATE_UTMP32_OUT (out32);
Packit 6c4009
Packit 6c4009
  out64 = __getutent ();
Packit 6c4009
  if (!out64)
Packit 6c4009
    return NULL;
Packit 6c4009
Packit 6c4009
  utmp_convert64to32 (out64, out32);
Packit 6c4009
  return out32;
Packit 6c4009
}
Packit 6c4009
symbol_version (getutent32, getutent, GLIBC_2.0);
Packit 6c4009
Packit 6c4009
/* Reentrant versions of the file for handling utmp files.  */
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
getutent32_r (struct utmp32 *buffer, struct utmp32 **result)
Packit 6c4009
{
Packit 6c4009
  struct utmp out64;
Packit 6c4009
  struct utmp *out64p;
Packit 6c4009
  int ret;
Packit 6c4009
Packit 6c4009
  ret = __getutent_r (&out64, &out64p);
Packit 6c4009
  if (ret == -1)
Packit 6c4009
    {
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  utmp_convert64to32 (out64p, buffer);
Packit 6c4009
  *result = buffer;
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
symbol_version (getutent32_r, getutent_r, GLIBC_2.0);
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
getutid32_r (const struct utmp32 *id, struct utmp32 *buffer,
Packit 6c4009
	       struct utmp32 **result)
Packit 6c4009
{
Packit 6c4009
  struct utmp in64;
Packit 6c4009
  struct utmp out64;
Packit 6c4009
  struct utmp *out64p;
Packit 6c4009
  int ret;
Packit 6c4009
Packit 6c4009
  utmp_convert32to64 (id, &in64);
Packit 6c4009
Packit 6c4009
  ret = __getutid_r (&in64, &out64, &out64p);
Packit 6c4009
  if (ret == -1)
Packit 6c4009
    {
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  utmp_convert64to32 (out64p, buffer);
Packit 6c4009
  *result = buffer;
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
symbol_version (getutid32_r, getutid_r, GLIBC_2.0);
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
getutline32_r (const struct utmp32 *line,
Packit 6c4009
		 struct utmp32 *buffer, struct utmp32 **result)
Packit 6c4009
{
Packit 6c4009
  struct utmp in64;
Packit 6c4009
  struct utmp out64;
Packit 6c4009
  struct utmp *out64p;
Packit 6c4009
  int ret;
Packit 6c4009
Packit 6c4009
  utmp_convert32to64 (line, &in64);
Packit 6c4009
Packit 6c4009
  ret = __getutline_r (&in64, &out64, &out64p);
Packit 6c4009
  if (ret == -1)
Packit 6c4009
    {
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  utmp_convert64to32 (out64p, buffer);
Packit 6c4009
  *result = buffer;
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
Packit 6c4009
}
Packit 6c4009
symbol_version (getutline32_r, getutline_r, GLIBC_2.0);
Packit 6c4009
Packit 6c4009
/* Append entry UTMP to the wtmp-like file WTMP_FILE.  */
Packit 6c4009
void
Packit 6c4009
updwtmp32 (const char *wtmp_file, const struct utmp32 *utmp)
Packit 6c4009
{
Packit 6c4009
  struct utmp in32;
Packit 6c4009
Packit 6c4009
  utmp_convert32to64 (utmp, &in32);
Packit 6c4009
  __updwtmp (wtmp_file, &in32);
Packit 6c4009
}
Packit 6c4009
symbol_version (updwtmp32, updwtmp, GLIBC_2.0);