[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/libc/glibc/glibc-2.22/shadow/Makefile b/ap/libc/glibc/glibc-2.22/shadow/Makefile
new file mode 100644
index 0000000..8291c61
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/Makefile
@@ -0,0 +1,40 @@
+# Copyright (C) 1996-2015 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C 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.
+
+# The GNU C 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 the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+#
+#	Makefile for shadow.
+#
+subdir	:= shadow
+
+include ../Makeconfig
+
+headers		= shadow.h
+routines	= getspent getspnam sgetspent fgetspent putspent \
+		  getspent_r getspnam_r sgetspent_r fgetspent_r \
+		  lckpwdf
+
+tests = tst-shadow
+
+CFLAGS-getspent_r.c = -fexceptions
+CFLAGS-getspent.c = -fexceptions
+CFLAGS-fgetspent.c = -fexceptions
+CFLAGS-fgetspent_r.c = -fexceptions $(libio-mtsafe)
+CFLAGS-putspent.c = -fexceptions $(libio-mtsafe)
+CFLAGS-getspnam.c = -fexceptions
+CFLAGS-getspnam_r.c = -fexceptions
+
+include ../Rules
diff --git a/ap/libc/glibc/glibc-2.22/shadow/Versions b/ap/libc/glibc/glibc-2.22/shadow/Versions
new file mode 100644
index 0000000..38ab368
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/Versions
@@ -0,0 +1,31 @@
+libc {
+  GLIBC_2.0 {
+    # e*
+    endspent;
+
+    # f*
+    fgetspent; fgetspent_r;
+
+    # g*
+    getspent; getspent_r; getspnam; getspnam_r;
+
+    # l*
+    lckpwdf;
+
+    # p*
+    putspent;
+
+    # s*
+    setspent;
+
+    # s*
+    sgetspent; sgetspent_r;
+
+    # u*
+    ulckpwdf;
+  }
+  GLIBC_2.1.2 {
+    # g*
+    getspent_r; getspnam_r;
+  }
+}
diff --git a/ap/libc/glibc/glibc-2.22/shadow/fgetspent.c b/ap/libc/glibc/glibc-2.22/shadow/fgetspent.c
new file mode 100644
index 0000000..38977ea
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/fgetspent.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <bits/libc-lock.h>
+#include <shadow.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+/* A reasonable size for a buffer to start with.  */
+#define BUFLEN_SPWD 1024
+
+/* We need to protect the dynamic buffer handling.  */
+__libc_lock_define_initialized (static, lock);
+
+libc_freeres_ptr (static char *buffer);
+
+/* Read one shadow entry from the given stream.  */
+struct spwd *
+fgetspent (FILE *stream)
+{
+  static size_t buffer_size;
+  static struct spwd resbuf;
+  fpos_t pos;
+  struct spwd *result;
+  int save;
+
+  if (fgetpos (stream, &pos) != 0)
+    return NULL;
+
+  /* Get lock.  */
+  __libc_lock_lock (lock);
+
+  /* Allocate buffer if not yet available.  */
+  if (buffer == NULL)
+    {
+      buffer_size = BUFLEN_SPWD;
+      buffer = malloc (buffer_size);
+    }
+
+  while (buffer != NULL
+	 && (__fgetspent_r (stream, &resbuf, buffer, buffer_size, &result)
+	     == ERANGE))
+    {
+      char *new_buf;
+      buffer_size += BUFLEN_SPWD;
+      new_buf = realloc (buffer, buffer_size);
+      if (new_buf == NULL)
+	{
+	  /* We are out of memory.  Free the current buffer so that the
+	     process gets a chance for a normal termination.  */
+	  save = errno;
+	  free (buffer);
+	  __set_errno (save);
+	}
+      buffer = new_buf;
+
+      /* Reset the stream.  */
+      if (fsetpos (stream, &pos) != 0)
+	buffer = NULL;
+    }
+
+  if (buffer == NULL)
+    result = NULL;
+
+  /* Release lock.  Preserve error value.  */
+  save = errno;
+  __libc_lock_unlock (lock);
+  __set_errno (save);
+
+  return result;
+}
diff --git a/ap/libc/glibc/glibc-2.22/shadow/fgetspent_r.c b/ap/libc/glibc/glibc-2.22/shadow/fgetspent_r.c
new file mode 100644
index 0000000..de79653
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/fgetspent_r.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <ctype.h>
+#include <errno.h>
+#include <shadow.h>
+#include <stdio.h>
+
+#define flockfile(s) _IO_flockfile (s)
+#define funlockfile(s) _IO_funlockfile (s)
+
+/* Define a line parsing function using the common code
+   used in the nss_files module.  */
+
+#define STRUCTURE	spwd
+#define ENTNAME		spent
+#define	EXTERN_PARSER	1
+struct spent_data {};
+
+#include <nss/nss_files/files-parse.c>
+
+
+/* Read one shadow entry from the given stream.  */
+int
+__fgetspent_r (FILE *stream, struct spwd *resbuf, char *buffer, size_t buflen,
+	       struct spwd **result)
+{
+  char *p;
+
+  flockfile (stream);
+  do
+    {
+      buffer[buflen - 1] = '\xff';
+      p = fgets_unlocked (buffer, buflen, stream);
+      if (p == NULL && feof_unlocked (stream))
+	{
+	  funlockfile (stream);
+	  *result = NULL;
+	  __set_errno (ENOENT);
+	  return errno;
+	}
+      if (p == NULL || buffer[buflen - 1] != '\xff')
+	{
+	  funlockfile (stream);
+	  *result = NULL;
+	  __set_errno (ERANGE);
+	  return errno;
+	}
+
+      /* Skip leading blanks.  */
+      while (isspace (*p))
+	++p;
+    } while (*p == '\0' || *p == '#' ||	/* Ignore empty and comment lines.  */
+	     /* Parse the line.  If it is invalid, loop to
+		get the next line of the file to parse.  */
+	     ! parse_line (buffer, (void *) resbuf, NULL, 0, &errno));
+
+  funlockfile (stream);
+
+  *result = resbuf;
+  return 0;
+}
+weak_alias (__fgetspent_r, fgetspent_r)
diff --git a/ap/libc/glibc/glibc-2.22/shadow/getspent.c b/ap/libc/glibc/glibc-2.22/shadow/getspent.c
new file mode 100644
index 0000000..871c745
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/getspent.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <shadow.h>
+
+
+#define LOOKUP_TYPE	struct spwd
+#define SETFUNC_NAME	setspent
+#define	GETFUNC_NAME	getspent
+#define	ENDFUNC_NAME	endspent
+#define DATABASE_NAME	shadow
+#define BUFLEN		1024
+
+/* There is no nscd support for the shadow file.  */
+#undef	USE_NSCD
+
+#include "../nss/getXXent.c"
diff --git a/ap/libc/glibc/glibc-2.22/shadow/getspent_r.c b/ap/libc/glibc/glibc-2.22/shadow/getspent_r.c
new file mode 100644
index 0000000..e2951c3
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/getspent_r.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <shadow.h>
+
+
+#define LOOKUP_TYPE		struct spwd
+#define SETFUNC_NAME		setspent
+#define	GETFUNC_NAME		getspent
+#define	ENDFUNC_NAME		endspent
+#define DATABASE_NAME		shadow
+#define BUFLEN			1024
+
+/* There is no nscd support for the shadow file.  */
+#undef	USE_NSCD
+
+#include "../nss/getXXent_r.c"
diff --git a/ap/libc/glibc/glibc-2.22/shadow/getspnam.c b/ap/libc/glibc/glibc-2.22/shadow/getspnam.c
new file mode 100644
index 0000000..ecaca65
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/getspnam.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <shadow.h>
+
+
+#define LOOKUP_TYPE	struct spwd
+#define FUNCTION_NAME	getspnam
+#define DATABASE_NAME	shadow
+#define ADD_PARAMS	const char *name
+#define ADD_VARIABLES	name
+#define BUFLEN		1024
+
+/* There is no nscd support for the shadow file.  */
+#undef	USE_NSCD
+
+#include "../nss/getXXbyYY.c"
diff --git a/ap/libc/glibc/glibc-2.22/shadow/getspnam_r.c b/ap/libc/glibc/glibc-2.22/shadow/getspnam_r.c
new file mode 100644
index 0000000..3a27160
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/getspnam_r.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <shadow.h>
+
+
+#define LOOKUP_TYPE		struct spwd
+#define FUNCTION_NAME		getspnam
+#define DATABASE_NAME		shadow
+#define ADD_PARAMS		const char *name
+#define ADD_VARIABLES		name
+#define BUFLEN			1024
+
+/* There is no nscd support for the shadow file.  */
+#undef	USE_NSCD
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/ap/libc/glibc/glibc-2.22/shadow/lckpwdf.c b/ap/libc/glibc/glibc-2.22/shadow/lckpwdf.c
new file mode 100644
index 0000000..e435471
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/lckpwdf.c
@@ -0,0 +1,202 @@
+/* Handle locking of password file.
+   Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fcntl.h>
+#include <bits/libc-lock.h>
+#include <shadow.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/file.h>
+
+#include <kernel-features.h>
+
+
+/* Name of the lock file.  */
+#define PWD_LOCKFILE "/etc/.pwd.lock"
+
+/* How long to wait for getting the lock before returning with an
+   error.  */
+#define TIMEOUT 15 /* sec */
+
+
+/* File descriptor for lock file.  */
+static int lock_fd = -1;
+
+/* Prevent problems in multithreaded program by using mutex.  */
+__libc_lock_define_initialized (static, lock)
+
+
+/* Prototypes for local functions.  */
+static void noop_handler (int __sig);
+
+
+/* We cannot simply return in error cases.  We have to close the file
+   and perhaps restore the signal handler.  */
+#define RETURN_CLOSE_FD(code)						      \
+  do {									      \
+    if ((code) < 0 && lock_fd >= 0)					      \
+      {									      \
+	__close (lock_fd);						      \
+	lock_fd = -1;							      \
+      }									      \
+    __libc_lock_unlock (lock);						      \
+    return (code);							      \
+  } while (0)
+
+#define RETURN_RESTORE_HANDLER(code)					      \
+  do {									      \
+    /* Restore old action handler for alarm.  We don't need to know	      \
+       about the current one.  */					      \
+    __sigaction (SIGALRM, &saved_act, NULL);				      \
+    RETURN_CLOSE_FD (code);						      \
+  } while (0)
+
+#define RETURN_CLEAR_ALARM(code)					      \
+  do {									      \
+    /* Clear alarm.  */							      \
+    alarm (0);								      \
+    /* Restore old set of handled signals.  We don't need to know	      \
+       about the current one.*/						      \
+    __sigprocmask (SIG_SETMASK, &saved_set, NULL);			      \
+    RETURN_RESTORE_HANDLER (code);					      \
+  } while (0)
+
+
+int
+__lckpwdf (void)
+{
+  sigset_t saved_set;			/* Saved set of caught signals.  */
+  struct sigaction saved_act;		/* Saved signal action.  */
+  sigset_t new_set;			/* New set of caught signals.  */
+  struct sigaction new_act;		/* New signal action.  */
+  struct flock fl;			/* Information struct for locking.  */
+  int result;
+
+  if (lock_fd != -1)
+    /* Still locked by own process.  */
+    return -1;
+
+  /* Prevent problems caused by multiple threads.  */
+  __libc_lock_lock (lock);
+
+  int oflags = O_WRONLY | O_CREAT;
+#ifdef O_CLOEXEC
+  oflags |= O_CLOEXEC;
+#endif
+  lock_fd = __open (PWD_LOCKFILE, oflags, 0600);
+  if (lock_fd == -1)
+    /* Cannot create lock file.  */
+    RETURN_CLOSE_FD (-1);
+
+#ifndef __ASSUME_O_CLOEXEC
+# ifdef O_CLOEXEC
+  if (__have_o_cloexec <= 0)
+# endif
+    {
+      /* Make sure file gets correctly closed when process finished.  */
+      int flags = __fcntl (lock_fd, F_GETFD, 0);
+      if (flags == -1)
+	/* Cannot get file flags.  */
+	RETURN_CLOSE_FD (-1);
+# ifdef O_CLOEXEC
+      if (__have_o_cloexec == 0)
+	__have_o_cloexec = (flags & FD_CLOEXEC) == 0 ? -1 : 1;
+      if (__have_o_cloexec < 0)
+# endif
+	{
+	  flags |= FD_CLOEXEC;		/* Close on exit.  */
+	  if (__fcntl (lock_fd, F_SETFD, flags) < 0)
+	    /* Cannot set new flags.  */
+	    RETURN_CLOSE_FD (-1);
+	}
+    }
+#endif
+
+  /* Now we have to get exclusive write access.  Since multiple
+     process could try this we won't stop when it first fails.
+     Instead we set a timeout for the system call.  Once the timer
+     expires it is likely that there are some problems which cannot be
+     resolved by waiting.
+
+     It is important that we don't change the signal state.  We must
+     restore the old signal behaviour.  */
+  memset (&new_act, '\0', sizeof (struct sigaction));
+  new_act.sa_handler = noop_handler;
+  __sigfillset (&new_act.sa_mask);
+  new_act.sa_flags = 0ul;
+
+  /* Install new action handler for alarm and save old.  */
+  if (__sigaction (SIGALRM, &new_act, &saved_act) < 0)
+    /* Cannot install signal handler.  */
+    RETURN_CLOSE_FD (-1);
+
+  /* Now make sure the alarm signal is not blocked.  */
+  __sigemptyset (&new_set);
+  __sigaddset (&new_set, SIGALRM);
+  if (__sigprocmask (SIG_UNBLOCK, &new_set, &saved_set) < 0)
+    RETURN_RESTORE_HANDLER (-1);
+
+  /* Start timer.  If we cannot get the lock in the specified time we
+     get a signal.  */
+  alarm (TIMEOUT);
+
+  /* Try to get the lock.  */
+  memset (&fl, '\0', sizeof (struct flock));
+  fl.l_type = F_WRLCK;
+  fl.l_whence = SEEK_SET;
+  result = __fcntl (lock_fd, F_SETLKW, &fl);
+
+  RETURN_CLEAR_ALARM (result);
+}
+weak_alias (__lckpwdf, lckpwdf)
+
+
+int
+__ulckpwdf (void)
+{
+  int result;
+
+  if (lock_fd == -1)
+    /* There is no lock set.  */
+    result = -1;
+  else
+    {
+      /* Prevent problems caused by multiple threads.  */
+      __libc_lock_lock (lock);
+
+      result = __close (lock_fd);
+
+      /* Mark descriptor as unused.  */
+      lock_fd = -1;
+
+      /* Clear mutex.  */
+      __libc_lock_unlock (lock);
+    }
+
+  return result;
+}
+weak_alias (__ulckpwdf, ulckpwdf)
+
+
+static void
+noop_handler (int sig)
+{
+  /* We simply return which makes the `fcntl' call return with an error.  */
+}
diff --git a/ap/libc/glibc/glibc-2.22/shadow/putspent.c b/ap/libc/glibc/glibc-2.22/shadow/putspent.c
new file mode 100644
index 0000000..142e697
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/putspent.c
@@ -0,0 +1,85 @@
+/* Copyright (C) 1991-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <shadow.h>
+
+#define flockfile(s) _IO_flockfile (s)
+#define funlockfile(s) _IO_funlockfile (s)
+
+#define _S(x)	x ? x : ""
+
+
+/* Write an entry to the given stream.
+   This must know the format of the password file.  */
+int
+putspent (const struct spwd *p, FILE *stream)
+{
+  int errors = 0;
+
+  flockfile (stream);
+
+  if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
+    ++errors;
+
+  if ((p->sp_lstchg != (long int) -1
+       && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
+      || (p->sp_lstchg == (long int) -1
+	  && putc_unlocked (':', stream) == EOF))
+    ++errors;
+
+  if ((p->sp_min != (long int) -1
+       && fprintf (stream, "%ld:", p->sp_min) < 0)
+      || (p->sp_min == (long int) -1
+	  && putc_unlocked (':', stream) == EOF))
+    ++errors;
+
+  if ((p->sp_max != (long int) -1
+       && fprintf (stream, "%ld:", p->sp_max) < 0)
+      || (p->sp_max == (long int) -1
+	  && putc_unlocked (':', stream) == EOF))
+    ++errors;
+
+  if ((p->sp_warn != (long int) -1
+       && fprintf (stream, "%ld:", p->sp_warn) < 0)
+      || (p->sp_warn == (long int) -1
+	  && putc_unlocked (':', stream) == EOF))
+    ++errors;
+
+  if ((p->sp_inact != (long int) -1
+       && fprintf (stream, "%ld:", p->sp_inact) < 0)
+      || (p->sp_inact == (long int) -1
+	  && putc_unlocked (':', stream) == EOF))
+    ++errors;
+
+  if ((p->sp_expire != (long int) -1
+       && fprintf (stream, "%ld:", p->sp_expire) < 0)
+      || (p->sp_expire == (long int) -1
+	  && putc_unlocked (':', stream) == EOF))
+    ++errors;
+
+  if (p->sp_flag != ~0ul
+      && fprintf (stream, "%ld", p->sp_flag) < 0)
+    ++errors;
+
+  if (putc_unlocked ('\n', stream) == EOF)
+    ++errors;
+
+  funlockfile (stream);
+
+  return errors ? -1 : 0;
+}
diff --git a/ap/libc/glibc/glibc-2.22/shadow/sgetspent.c b/ap/libc/glibc/glibc-2.22/shadow/sgetspent.c
new file mode 100644
index 0000000..f16ff19
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/sgetspent.c
@@ -0,0 +1,77 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <bits/libc-lock.h>
+#include <shadow.h>
+#include <stdlib.h>
+
+
+/* A reasonable size for a buffer to start with.  */
+#define BUFLEN_SPWD 1024
+
+/* We need to protect the dynamic buffer handling.  */
+__libc_lock_define_initialized (static, lock);
+
+/* Read one shadow entry from the given stream.  */
+struct spwd *
+sgetspent (const char *string)
+{
+  static char *buffer;
+  static size_t buffer_size;
+  static struct spwd resbuf;
+  struct spwd *result;
+  int save;
+
+  /* Get lock.  */
+  __libc_lock_lock (lock);
+
+  /* Allocate buffer if not yet available.  */
+  if (buffer == NULL)
+    {
+      buffer_size = BUFLEN_SPWD;
+      buffer = malloc (buffer_size);
+    }
+
+  while (buffer != NULL
+	 && (__sgetspent_r (string, &resbuf, buffer, buffer_size, &result)
+	     == ERANGE))
+    {
+      char *new_buf;
+      buffer_size += BUFLEN_SPWD;
+      new_buf = realloc (buffer, buffer_size);
+      if (new_buf == NULL)
+	{
+	  /* We are out of memory.  Free the current buffer so that the
+	     process gets a chance for a normal termination.  */
+	  save = errno;
+	  free (buffer);
+	  __set_errno (save);
+	}
+      buffer = new_buf;
+    }
+
+  if (buffer == NULL)
+    result = NULL;
+
+  /* Release lock.  Preserve error value.  */
+  save = errno;
+  __libc_lock_unlock (lock);
+  __set_errno (save);
+
+  return result;
+}
diff --git a/ap/libc/glibc/glibc-2.22/shadow/sgetspent_r.c b/ap/libc/glibc/glibc-2.22/shadow/sgetspent_r.c
new file mode 100644
index 0000000..2b32e0f
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/sgetspent_r.c
@@ -0,0 +1,103 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <ctype.h>
+#include <errno.h>
+#include <shadow.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Define a line parsing function using the common code
+   used in the nss_files module.  */
+
+#define STRUCTURE	spwd
+#define ENTNAME		spent
+struct spent_data {};
+
+/* Predicate which always returns false, needed below.  */
+#define FALSEP(arg) 0
+
+
+#include <nss/nss_files/files-parse.c>
+LINE_PARSER
+(,
+ STRING_FIELD (result->sp_namp, ISCOLON, 0);
+ if (line[0] == '\0'
+     && (result->sp_namp[0] == '+' || result->sp_namp[0] == '-'))
+   {
+     result->sp_pwdp = NULL;
+     result->sp_lstchg = 0;
+     result->sp_min = 0;
+     result->sp_max = 0;
+     result->sp_warn = -1l;
+     result->sp_inact = -1l;
+     result->sp_expire = -1l;
+     result->sp_flag = ~0ul;
+   }
+ else
+   {
+     STRING_FIELD (result->sp_pwdp, ISCOLON, 0);
+     INT_FIELD_MAYBE_NULL (result->sp_lstchg, ISCOLON, 0, 10, (long int) (int),
+			   (long int) -1);
+     INT_FIELD_MAYBE_NULL (result->sp_min, ISCOLON, 0, 10, (long int) (int),
+			   (long int) -1);
+     INT_FIELD_MAYBE_NULL (result->sp_max, ISCOLON, 0, 10, (long int) (int),
+			   (long int) -1);
+     while (isspace (*line))
+       ++line;
+     if (*line == '\0')
+       {
+	 /* The old form.  */
+	 result->sp_warn = -1l;
+	 result->sp_inact = -1l;
+	 result->sp_expire = -1l;
+	 result->sp_flag = ~0ul;
+       }
+     else
+       {
+	 INT_FIELD_MAYBE_NULL (result->sp_warn, ISCOLON, 0, 10,
+			       (long int) (int), (long int) -1);
+	 INT_FIELD_MAYBE_NULL (result->sp_inact, ISCOLON, 0, 10,
+			       (long int) (int), (long int) -1);
+	 INT_FIELD_MAYBE_NULL (result->sp_expire, ISCOLON, 0, 10,
+			       (long int) (int), (long int) -1);
+	 if (*line != '\0')
+	   INT_FIELD_MAYBE_NULL (result->sp_flag, FALSEP, 0, 10,
+				 (unsigned long int), ~0ul)
+	 else
+	   result->sp_flag = ~0ul;
+       }
+   }
+ )
+
+
+/* Read one shadow entry from the given stream.  */
+int
+__sgetspent_r (const char *string, struct spwd *resbuf, char *buffer,
+	       size_t buflen, struct spwd **result)
+{
+  buffer[buflen - 1] = '\0';
+  char *sp = strncpy (buffer, string, buflen);
+  if (buffer[buflen - 1] != '\0')
+    return ERANGE;
+
+  int parse_result = parse_line (sp, resbuf, NULL, 0, &errno);
+  *result = parse_result > 0 ? resbuf : NULL;
+
+  return *result == NULL ? errno : 0;
+}
+weak_alias (__sgetspent_r, sgetspent_r)
diff --git a/ap/libc/glibc/glibc-2.22/shadow/shadow.h b/ap/libc/glibc/glibc-2.22/shadow/shadow.h
new file mode 100644
index 0000000..95095b1
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/shadow.h
@@ -0,0 +1,148 @@
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C 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.
+
+   The GNU C 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Declaration of types and functions for shadow password suite.  */
+
+#ifndef _SHADOW_H
+#define _SHADOW_H	1
+
+#include <features.h>
+
+#include <paths.h>
+
+#define	__need_FILE
+#include <stdio.h>
+#define __need_size_t
+#include <stddef.h>
+
+/* Paths to the user database files.  */
+#define	SHADOW _PATH_SHADOW
+
+
+__BEGIN_DECLS
+
+/* Structure of the password file.  */
+struct spwd
+  {
+    char *sp_namp;		/* Login name.  */
+    char *sp_pwdp;		/* Encrypted password.  */
+    long int sp_lstchg;		/* Date of last change.  */
+    long int sp_min;		/* Minimum number of days between changes.  */
+    long int sp_max;		/* Maximum number of days between changes.  */
+    long int sp_warn;		/* Number of days to warn user to change
+				   the password.  */
+    long int sp_inact;		/* Number of days the account may be
+				   inactive.  */
+    long int sp_expire;		/* Number of days since 1970-01-01 until
+				   account expires.  */
+    unsigned long int sp_flag;	/* Reserved.  */
+  };
+
+
+/* Open database for reading.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern void setspent (void);
+
+/* Close database.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern void endspent (void);
+
+/* Get next entry from database, perhaps after opening the file.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern struct spwd *getspent (void);
+
+/* Get shadow entry matching NAME.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern struct spwd *getspnam (const char *__name);
+
+/* Read shadow entry from STRING.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern struct spwd *sgetspent (const char *__string);
+
+/* Read next shadow entry from STREAM.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern struct spwd *fgetspent (FILE *__stream);
+
+/* Write line containing shadow password entry to stream.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern int putspent (const struct spwd *__p, FILE *__stream);
+
+
+#ifdef __USE_MISC
+/* Reentrant versions of some of the functions above.
+
+   These functions are not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation they are cancellation points and
+   therefore not marked with __THROW.  */
+extern int getspent_r (struct spwd *__result_buf, char *__buffer,
+		       size_t __buflen, struct spwd **__result);
+
+extern int getspnam_r (const char *__name, struct spwd *__result_buf,
+		       char *__buffer, size_t __buflen,
+		       struct spwd **__result);
+
+extern int sgetspent_r (const char *__string, struct spwd *__result_buf,
+			char *__buffer, size_t __buflen,
+			struct spwd **__result);
+
+extern int fgetspent_r (FILE *__stream, struct spwd *__result_buf,
+			char *__buffer, size_t __buflen,
+			struct spwd **__result);
+#endif	/* misc */
+
+
+/* The simple locking functionality provided here is not suitable for
+   multi-threaded applications.  */
+
+/* Protect password file against multi writers.  */
+extern int lckpwdf (void) __THROW;
+
+/* Unlock password file.  */
+extern int ulckpwdf (void) __THROW;
+
+__END_DECLS
+
+#endif /* shadow.h */
diff --git a/ap/libc/glibc/glibc-2.22/shadow/tst-shadow.c b/ap/libc/glibc/glibc-2.22/shadow/tst-shadow.c
new file mode 100644
index 0000000..48f7167
--- /dev/null
+++ b/ap/libc/glibc/glibc-2.22/shadow/tst-shadow.c
@@ -0,0 +1,84 @@
+#include <shadow.h>
+#include <stdio.h>
+#include <string.h>
+
+
+static const struct spwd data[] =
+  {
+    { (char *) "one", (char *) "pwdone", 1, 2, 3, 4, 5, 6, 7 },
+    { (char *) "two", (char *) "pwdtwo", 11, 12, 13, 14, 15, 16, 17 },
+    { (char *) "three", (char *) "pwdthree", -1, 22, 23, 24, 25, 26, 27 },
+    { (char *) "four", (char *) "pwdfour", 31, -1, 33, 34, 35, 36, 37 },
+    { (char *) "five", (char *) "pwdfive", 41, 42, -1, 44, 45, 46, 47 },
+    { (char *) "six", (char *) "pwdsix", 51, 52, 53, -1, 55, 56, 57 },
+    { (char *) "seven", (char *) "pwdseven", 61, 62, 63, 64, -1, 66, 67 },
+    { (char *) "eight", (char *) "pwdeigth", 71, 72, 73, 74, 75, -1, 77 },
+    { (char *) "nine", (char *) "pwdnine", 81, 82, 83, 84, 85, 86, ~0ul },
+  };
+#define ndata (sizeof (data) / sizeof (data[0]))
+
+
+static int
+do_test (void)
+{
+  FILE *fp = tmpfile ();
+  if (fp == NULL)
+    {
+      puts ("cannot open temporary file");
+      return 1;
+    }
+
+  for (size_t i = 0; i < ndata; ++i)
+    if (putspent (&data[i], fp) != 0)
+      {
+	printf ("putspent call %zu failed\n", i + 1);
+	return 1;
+      }
+
+  rewind (fp);
+
+  int result = 0;
+  int seen = -1;
+  struct spwd *p;
+  while ((p = fgetspent (fp)) != NULL)
+    {
+      ++seen;
+      if (strcmp (p->sp_namp, data[seen].sp_namp) != 0)
+	{
+	  printf ("sp_namp of entry %d does not match: %s vs %s\n",
+		  seen + 1, p->sp_namp, data[seen].sp_namp);
+	  result = 1;
+	}
+      if (strcmp (p->sp_pwdp, data[seen].sp_pwdp) != 0)
+	{
+	  printf ("sp_pwdp of entry %d does not match: %s vs %s\n",
+		  seen + 1, p->sp_pwdp, data[seen].sp_pwdp);
+	  result = 1;
+	}
+#define T(f) \
+      if (p->f != data[seen].f)						      \
+	{								      \
+	  printf ("%s of entry %d wrong: %ld vs %ld\n",			      \
+		  #f, seen + 1, p->f, data[seen].f);			      \
+	  result = 1;							      \
+	}
+      T (sp_lstchg);
+      T (sp_min);
+      T (sp_max);
+      T (sp_warn);
+      T (sp_expire);
+      if (p->sp_flag != data[seen].sp_flag)
+	{
+	  printf ("sp_flag of entry %d wrong: %lu vs %lu\n",
+		  seen + 1, p->sp_flag, data[seen].sp_flag);
+	  result = 1;
+	}
+    }
+
+  fclose (fp);
+
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"