hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame login/utmp_file.c

Packit 6c4009
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@cygnus.com>
Packit 6c4009
   and Paul Janzen <pcj@primenet.com>, 1996.
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 <assert.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <fcntl.h>
Packit 6c4009
#include <signal.h>
Packit 6c4009
#include <stdbool.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <utmp.h>
Packit 6c4009
#include <not-cancel.h>
Packit 6c4009
#include <kernel-features.h>
Packit 6c4009
#include <sigsetops.h>
Packit 6c4009
#include <not-cancel.h>
Packit 6c4009
Packit 6c4009
#include "utmp-private.h"
Packit 6c4009
#include "utmp-equal.h"
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Descriptor for the file and position.  */
Packit 6c4009
static int file_fd = -1;
Packit 6c4009
static bool file_writable;
Packit 6c4009
static off64_t file_offset;
Packit 6c4009
Packit 6c4009
/* Cache for the last read entry.  */
Packit 6c4009
static struct utmp last_entry;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Locking timeout.  */
Packit 6c4009
#ifndef TIMEOUT
Packit 6c4009
# define TIMEOUT 10
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Do-nothing handler for locking timeout.  */
Packit 6c4009
static void timeout_handler (int signum) {};
Packit 6c4009
Packit 6c4009
/* LOCK_FILE(fd, type) failure_statement
Packit 6c4009
     attempts to get a lock on the utmp file referenced by FD.  If it fails,
Packit 6c4009
     the failure_statement is executed, otherwise it is skipped.
Packit 6c4009
   LOCKING_FAILED()
Packit 6c4009
     jumps into the UNLOCK_FILE macro and ensures cleanup of LOCK_FILE.
Packit 6c4009
   UNLOCK_FILE(fd)
Packit 6c4009
     unlocks the utmp file referenced by FD and performs the cleanup of
Packit 6c4009
     LOCK_FILE.
Packit 6c4009
 */
Packit 6c4009
#define LOCK_FILE(fd, type) \
Packit 6c4009
{									      \
Packit 6c4009
  struct flock fl;							      \
Packit 6c4009
  struct sigaction action, old_action;					      \
Packit 6c4009
  unsigned int old_timeout;						      \
Packit 6c4009
									      \
Packit 6c4009
  /* Cancel any existing alarm.  */					      \
Packit 6c4009
  old_timeout = alarm (0);						      \
Packit 6c4009
									      \
Packit 6c4009
  /* Establish signal handler.  */					      \
Packit 6c4009
  action.sa_handler = timeout_handler;					      \
Packit 6c4009
  __sigemptyset (&action.sa_mask);					      \
Packit 6c4009
  action.sa_flags = 0;							      \
Packit 6c4009
  __sigaction (SIGALRM, &action, &old_action);				      \
Packit 6c4009
									      \
Packit 6c4009
  alarm (TIMEOUT);							      \
Packit 6c4009
									      \
Packit 6c4009
  /* Try to get the lock.  */						      \
Packit 6c4009
  memset (&fl, '\0', sizeof (struct flock));				      \
Packit 6c4009
  fl.l_type = (type);							      \
Packit 6c4009
  fl.l_whence = SEEK_SET;						      \
Packit 6c4009
  if (__fcntl64_nocancel ((fd), F_SETLKW, &fl) < 0)
Packit 6c4009
Packit 6c4009
#define LOCKING_FAILED() \
Packit 6c4009
  goto unalarm_return
Packit 6c4009
Packit 6c4009
#define UNLOCK_FILE(fd) \
Packit 6c4009
  /* Unlock the file.  */						      \
Packit 6c4009
  fl.l_type = F_UNLCK;							      \
Packit 6c4009
  __fcntl64_nocancel ((fd), F_SETLKW, &fl);				      \
Packit 6c4009
									      \
Packit 6c4009
 unalarm_return:							      \
Packit 6c4009
  /* Reset the signal handler and alarm.  We must reset the alarm	      \
Packit 6c4009
     before resetting the handler so our alarm does not generate a	      \
Packit 6c4009
     spurious SIGALRM seen by the user.  However, we cannot just set	      \
Packit 6c4009
     the user's old alarm before restoring the handler, because then	      \
Packit 6c4009
     it's possible our handler could catch the user alarm's SIGARLM	      \
Packit 6c4009
     and then the user would never see the signal he expected.  */	      \
Packit 6c4009
  alarm (0);								      \
Packit 6c4009
  __sigaction (SIGALRM, &old_action, NULL);				      \
Packit 6c4009
  if (old_timeout != 0)							      \
Packit 6c4009
    alarm (old_timeout);						      \
Packit 6c4009
} while (0)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Functions defined here.  */
Packit 6c4009
static int setutent_file (void);
Packit 6c4009
static int getutent_r_file (struct utmp *buffer, struct utmp **result);
Packit 6c4009
static int getutid_r_file (const struct utmp *key, struct utmp *buffer,
Packit 6c4009
			   struct utmp **result);
Packit 6c4009
static int getutline_r_file (const struct utmp *key, struct utmp *buffer,
Packit 6c4009
			     struct utmp **result);
Packit 6c4009
static struct utmp *pututline_file (const struct utmp *data);
Packit 6c4009
static void endutent_file (void);
Packit 6c4009
static int updwtmp_file (const char *file, const struct utmp *utmp);
Packit 6c4009
Packit 6c4009
/* Jump table for file functions.  */
Packit 6c4009
const struct utfuncs __libc_utmp_file_functions =
Packit 6c4009
{
Packit 6c4009
  setutent_file,
Packit 6c4009
  getutent_r_file,
Packit 6c4009
  getutid_r_file,
Packit 6c4009
  getutline_r_file,
Packit 6c4009
  pututline_file,
Packit 6c4009
  endutent_file,
Packit 6c4009
  updwtmp_file
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifndef TRANSFORM_UTMP_FILE_NAME
Packit 6c4009
# define TRANSFORM_UTMP_FILE_NAME(file_name) (file_name)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
setutent_file (void)
Packit 6c4009
{
Packit 6c4009
  if (file_fd < 0)
Packit 6c4009
    {
Packit 6c4009
      const char *file_name;
Packit 6c4009
Packit 6c4009
      file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
Packit 6c4009
Packit 6c4009
      file_writable = false;
Packit 6c4009
      file_fd = __open_nocancel
Packit 6c4009
	(file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
Packit 6c4009
      if (file_fd == -1)
Packit 6c4009
	return 0;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  __lseek64 (file_fd, 0, SEEK_SET);
Packit 6c4009
  file_offset = 0;
Packit 6c4009
Packit 6c4009
  /* Make sure the entry won't match.  */
Packit 6c4009
#if _HAVE_UT_TYPE - 0
Packit 6c4009
  last_entry.ut_type = -1;
Packit 6c4009
#else
Packit 6c4009
  last_entry.ut_line[0] = '\177';
Packit 6c4009
# if _HAVE_UT_ID - 0
Packit 6c4009
  last_entry.ut_id[0] = '\0';
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  return 1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
getutent_r_file (struct utmp *buffer, struct utmp **result)
Packit 6c4009
{
Packit 6c4009
  ssize_t nbytes;
Packit 6c4009
Packit 6c4009
  assert (file_fd >= 0);
Packit 6c4009
Packit 6c4009
  if (file_offset == -1l)
Packit 6c4009
    {
Packit 6c4009
      /* Not available.  */
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  LOCK_FILE (file_fd, F_RDLCK)
Packit 6c4009
    {
Packit 6c4009
      nbytes = 0;
Packit 6c4009
      LOCKING_FAILED ();
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Read the next entry.  */
Packit 6c4009
  nbytes = __read_nocancel (file_fd, &last_entry, sizeof (struct utmp));
Packit 6c4009
Packit 6c4009
  UNLOCK_FILE (file_fd);
Packit 6c4009
Packit 6c4009
  if (nbytes != sizeof (struct utmp))
Packit 6c4009
    {
Packit 6c4009
      if (nbytes != 0)
Packit 6c4009
	file_offset = -1l;
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Update position pointer.  */
Packit 6c4009
  file_offset += sizeof (struct utmp);
Packit 6c4009
Packit 6c4009
  memcpy (buffer, &last_entry, sizeof (struct utmp));
Packit 6c4009
  *result = buffer;
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
internal_getut_r (const struct utmp *id, struct utmp *buffer,
Packit 6c4009
		  bool *lock_failed)
Packit 6c4009
{
Packit 6c4009
  int result = -1;
Packit 6c4009
Packit 6c4009
  LOCK_FILE (file_fd, F_RDLCK)
Packit 6c4009
    {
Packit 6c4009
      *lock_failed = true;
Packit 6c4009
      LOCKING_FAILED ();
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
#if _HAVE_UT_TYPE - 0
Packit 6c4009
  if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
Packit 6c4009
      || id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
Packit 6c4009
    {
Packit 6c4009
      /* Search for next entry with type RUN_LVL, BOOT_TIME,
Packit 6c4009
	 OLD_TIME, or NEW_TIME.  */
Packit 6c4009
Packit 6c4009
      while (1)
Packit 6c4009
	{
Packit 6c4009
	  /* Read the next entry.  */
Packit 6c4009
	  if (__read_nocancel (file_fd, buffer, sizeof (struct utmp))
Packit 6c4009
	      != sizeof (struct utmp))
Packit 6c4009
	    {
Packit 6c4009
	      __set_errno (ESRCH);
Packit 6c4009
	      file_offset = -1l;
Packit 6c4009
	      goto unlock_return;
Packit 6c4009
	    }
Packit 6c4009
	  file_offset += sizeof (struct utmp);
Packit 6c4009
Packit 6c4009
	  if (id->ut_type == buffer->ut_type)
Packit 6c4009
	    break;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
#endif /* _HAVE_UT_TYPE */
Packit 6c4009
    {
Packit 6c4009
      /* Search for the next entry with the specified ID and with type
Packit 6c4009
	 INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS.  */
Packit 6c4009
Packit 6c4009
      while (1)
Packit 6c4009
	{
Packit 6c4009
	  /* Read the next entry.  */
Packit 6c4009
	  if (__read_nocancel (file_fd, buffer, sizeof (struct utmp))
Packit 6c4009
	      != sizeof (struct utmp))
Packit 6c4009
	    {
Packit 6c4009
	      __set_errno (ESRCH);
Packit 6c4009
	      file_offset = -1l;
Packit 6c4009
	      goto unlock_return;
Packit 6c4009
	    }
Packit 6c4009
	  file_offset += sizeof (struct utmp);
Packit 6c4009
Packit 6c4009
	  if (__utmp_equal (buffer, id))
Packit 6c4009
	    break;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  result = 0;
Packit 6c4009
Packit 6c4009
unlock_return:
Packit 6c4009
  UNLOCK_FILE (file_fd);
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* For implementing this function we don't use the getutent_r function
Packit 6c4009
   because we can avoid the reposition on every new entry this way.  */
Packit 6c4009
static int
Packit 6c4009
getutid_r_file (const struct utmp *id, struct utmp *buffer,
Packit 6c4009
		struct utmp **result)
Packit 6c4009
{
Packit 6c4009
  assert (file_fd >= 0);
Packit 6c4009
Packit 6c4009
  if (file_offset == -1l)
Packit 6c4009
    {
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* We don't have to distinguish whether we can lock the file or
Packit 6c4009
     whether there is no entry.  */
Packit 6c4009
  bool lock_failed = false;
Packit 6c4009
  if (internal_getut_r (id, &last_entry, &lock_failed) < 0)
Packit 6c4009
    {
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  memcpy (buffer, &last_entry, sizeof (struct utmp));
Packit 6c4009
  *result = buffer;
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* For implementing this function we don't use the getutent_r function
Packit 6c4009
   because we can avoid the reposition on every new entry this way.  */
Packit 6c4009
static int
Packit 6c4009
getutline_r_file (const struct utmp *line, struct utmp *buffer,
Packit 6c4009
		  struct utmp **result)
Packit 6c4009
{
Packit 6c4009
  assert (file_fd >= 0);
Packit 6c4009
Packit 6c4009
  if (file_offset == -1l)
Packit 6c4009
    {
Packit 6c4009
      *result = NULL;
Packit 6c4009
      return -1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  LOCK_FILE (file_fd, F_RDLCK)
Packit 6c4009
    {
Packit 6c4009
      *result = NULL;
Packit 6c4009
      LOCKING_FAILED ();
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  while (1)
Packit 6c4009
    {
Packit 6c4009
      /* Read the next entry.  */
Packit 6c4009
      if (__read_nocancel (file_fd, &last_entry, sizeof (struct utmp))
Packit 6c4009
	  != sizeof (struct utmp))
Packit 6c4009
	{
Packit 6c4009
	  __set_errno (ESRCH);
Packit 6c4009
	  file_offset = -1l;
Packit 6c4009
	  *result = NULL;
Packit 6c4009
	  goto unlock_return;
Packit 6c4009
	}
Packit 6c4009
      file_offset += sizeof (struct utmp);
Packit 6c4009
Packit 6c4009
      /* Stop if we found a user or login entry.  */
Packit 6c4009
      if (
Packit 6c4009
#if _HAVE_UT_TYPE - 0
Packit 6c4009
	  (last_entry.ut_type == USER_PROCESS
Packit 6c4009
	   || last_entry.ut_type == LOGIN_PROCESS)
Packit 6c4009
	  &&
Packit 6c4009
#endif
Packit 6c4009
	  !strncmp (line->ut_line, last_entry.ut_line, sizeof line->ut_line))
Packit 6c4009
	break;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  memcpy (buffer, &last_entry, sizeof (struct utmp));
Packit 6c4009
  *result = buffer;
Packit 6c4009
Packit 6c4009
unlock_return:
Packit 6c4009
  UNLOCK_FILE (file_fd);
Packit 6c4009
Packit 6c4009
  return ((*result == NULL) ? -1 : 0);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static struct utmp *
Packit 6c4009
pututline_file (const struct utmp *data)
Packit 6c4009
{
Packit 6c4009
  struct utmp buffer;
Packit 6c4009
  struct utmp *pbuf;
Packit 6c4009
  int found;
Packit 6c4009
Packit 6c4009
  assert (file_fd >= 0);
Packit 6c4009
Packit 6c4009
  if (! file_writable)
Packit 6c4009
    {
Packit 6c4009
      /* We must make the file descriptor writable before going on.  */
Packit 6c4009
      const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);
Packit 6c4009
Packit 6c4009
      int new_fd = __open_nocancel
Packit 6c4009
	(file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC);
Packit 6c4009
      if (new_fd == -1)
Packit 6c4009
	return NULL;
Packit 6c4009
Packit 6c4009
      if (__lseek64 (new_fd, __lseek64 (file_fd, 0, SEEK_CUR), SEEK_SET) == -1
Packit 6c4009
	  || __dup2 (new_fd, file_fd) < 0)
Packit 6c4009
	{
Packit 6c4009
	  __close_nocancel_nostatus (new_fd);
Packit 6c4009
	  return NULL;
Packit 6c4009
	}
Packit 6c4009
      __close_nocancel_nostatus (new_fd);
Packit 6c4009
      file_writable = true;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Find the correct place to insert the data.  */
Packit 6c4009
  if (file_offset > 0
Packit 6c4009
      && (
Packit 6c4009
#if _HAVE_UT_TYPE - 0
Packit 6c4009
	  (last_entry.ut_type == data->ut_type
Packit 6c4009
	   && (last_entry.ut_type == RUN_LVL
Packit 6c4009
	       || last_entry.ut_type == BOOT_TIME
Packit 6c4009
	       || last_entry.ut_type == OLD_TIME
Packit 6c4009
	       || last_entry.ut_type == NEW_TIME))
Packit 6c4009
	  ||
Packit 6c4009
#endif
Packit 6c4009
	  __utmp_equal (&last_entry, data)))
Packit 6c4009
    found = 1;
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      bool lock_failed = false;
Packit 6c4009
      found = internal_getut_r (data, &buffer, &lock_failed);
Packit 6c4009
Packit 6c4009
      if (__builtin_expect (lock_failed, false))
Packit 6c4009
	{
Packit 6c4009
	  __set_errno (EAGAIN);
Packit 6c4009
	  return NULL;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  LOCK_FILE (file_fd, F_WRLCK)
Packit 6c4009
    {
Packit 6c4009
      pbuf = NULL;
Packit 6c4009
      LOCKING_FAILED ();
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (found < 0)
Packit 6c4009
    {
Packit 6c4009
      /* We append the next entry.  */
Packit 6c4009
      file_offset = __lseek64 (file_fd, 0, SEEK_END);
Packit 6c4009
      if (file_offset % sizeof (struct utmp) != 0)
Packit 6c4009
	{
Packit 6c4009
	  file_offset -= file_offset % sizeof (struct utmp);
Packit 6c4009
	  __ftruncate64 (file_fd, file_offset);
Packit 6c4009
Packit 6c4009
	  if (__lseek64 (file_fd, 0, SEEK_END) < 0)
Packit 6c4009
	    {
Packit 6c4009
	      pbuf = NULL;
Packit 6c4009
	      goto unlock_return;
Packit 6c4009
	    }
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      /* We replace the just read entry.  */
Packit 6c4009
      file_offset -= sizeof (struct utmp);
Packit 6c4009
      __lseek64 (file_fd, file_offset, SEEK_SET);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Write the new data.  */
Packit 6c4009
  if (__write_nocancel (file_fd, data, sizeof (struct utmp))
Packit 6c4009
      != sizeof (struct utmp))
Packit 6c4009
    {
Packit 6c4009
      /* If we appended a new record this is only partially written.
Packit 6c4009
	 Remove it.  */
Packit 6c4009
      if (found < 0)
Packit 6c4009
	(void) __ftruncate64 (file_fd, file_offset);
Packit 6c4009
      pbuf = NULL;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      file_offset += sizeof (struct utmp);
Packit 6c4009
      pbuf = (struct utmp *) data;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
 unlock_return:
Packit 6c4009
  UNLOCK_FILE (file_fd);
Packit 6c4009
Packit 6c4009
  return pbuf;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
endutent_file (void)
Packit 6c4009
{
Packit 6c4009
  assert (file_fd >= 0);
Packit 6c4009
Packit 6c4009
  __close_nocancel_nostatus (file_fd);
Packit 6c4009
  file_fd = -1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
updwtmp_file (const char *file, const struct utmp *utmp)
Packit 6c4009
{
Packit 6c4009
  int result = -1;
Packit 6c4009
  off64_t offset;
Packit 6c4009
  int fd;
Packit 6c4009
Packit 6c4009
  /* Open WTMP file.  */
Packit 6c4009
  fd = __open_nocancel (file, O_WRONLY | O_LARGEFILE);
Packit 6c4009
  if (fd < 0)
Packit 6c4009
    return -1;
Packit 6c4009
Packit 6c4009
  LOCK_FILE (fd, F_WRLCK)
Packit 6c4009
    LOCKING_FAILED ();
Packit 6c4009
Packit 6c4009
  /* Remember original size of log file.  */
Packit 6c4009
  offset = __lseek64 (fd, 0, SEEK_END);
Packit 6c4009
  if (offset % sizeof (struct utmp) != 0)
Packit 6c4009
    {
Packit 6c4009
      offset -= offset % sizeof (struct utmp);
Packit 6c4009
      __ftruncate64 (fd, offset);
Packit 6c4009
Packit 6c4009
      if (__lseek64 (fd, 0, SEEK_END) < 0)
Packit 6c4009
	goto unlock_return;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Write the entry.  If we can't write all the bytes, reset the file
Packit 6c4009
     size back to the original size.  That way, no partial entries
Packit 6c4009
     will remain.  */
Packit 6c4009
  if (__write_nocancel (fd, utmp, sizeof (struct utmp))
Packit 6c4009
      != sizeof (struct utmp))
Packit 6c4009
    {
Packit 6c4009
      __ftruncate64 (fd, offset);
Packit 6c4009
      goto unlock_return;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  result = 0;
Packit 6c4009
Packit 6c4009
unlock_return:
Packit 6c4009
  UNLOCK_FILE (fd);
Packit 6c4009
Packit 6c4009
  /* Close WTMP file.  */
Packit 6c4009
  __close_nocancel_nostatus (fd);
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}