aboutsummaryrefslogtreecommitdiff
path: root/shadow
diff options
context:
space:
mode:
Diffstat (limited to 'shadow')
-rw-r--r--shadow/Makefile40
-rw-r--r--shadow/Versions31
-rw-r--r--shadow/fgetspent.c90
-rw-r--r--shadow/fgetspent_r.c46
-rw-r--r--shadow/getspent.c31
-rw-r--r--shadow/getspent_r.c31
-rw-r--r--shadow/getspnam.c31
-rw-r--r--shadow/getspnam_r.c31
-rw-r--r--shadow/lckpwdf.c175
-rw-r--r--shadow/putspent.c94
-rw-r--r--shadow/sgetspent.c77
-rw-r--r--shadow/sgetspent_r.c103
-rw-r--r--shadow/shadow.h156
-rw-r--r--shadow/tst-putspent.c164
-rw-r--r--shadow/tst-shadow.c84
15 files changed, 0 insertions, 1184 deletions
diff --git a/shadow/Makefile b/shadow/Makefile
deleted file mode 100644
index 0102a4d0e3..0000000000
--- a/shadow/Makefile
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 1996-2023 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
-# <https://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 tst-putspent
-
-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/shadow/Versions b/shadow/Versions
deleted file mode 100644
index 38ab368fff..0000000000
--- a/shadow/Versions
+++ /dev/null
@@ -1,31 +0,0 @@
-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/shadow/fgetspent.c b/shadow/fgetspent.c
deleted file mode 100644
index 541947bad6..0000000000
--- a/shadow/fgetspent.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* Copyright (C) 1996-2023 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
- <https://www.gnu.org/licenses/>. */
-
-#include <errno.h>
-#include <libc-lock.h>
-#include <shadow.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <set-freeres.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);
-
-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;
-}
-
-weak_alias (buffer, __libc_fgetspent_freemem_ptr);
diff --git a/shadow/fgetspent_r.c b/shadow/fgetspent_r.c
deleted file mode 100644
index 5323914175..0000000000
--- a/shadow/fgetspent_r.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* Copyright (C) 1996-2023 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
- <https://www.gnu.org/licenses/>. */
-
-#include <ctype.h>
-#include <errno.h>
-#include <shadow.h>
-#include <stdio.h>
-
-/* 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)
-{
- int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line);
- if (ret == 0)
- *result = resbuf;
- else
- *result = NULL;
- return ret;
-}
-weak_alias (__fgetspent_r, fgetspent_r)
diff --git a/shadow/getspent.c b/shadow/getspent.c
deleted file mode 100644
index d2109f8b16..0000000000
--- a/shadow/getspent.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Copyright (C) 1996-2023 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
- <https://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/shadow/getspent_r.c b/shadow/getspent_r.c
deleted file mode 100644
index f63e44f49b..0000000000
--- a/shadow/getspent_r.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Copyright (C) 1996-2023 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
- <https://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/shadow/getspnam.c b/shadow/getspnam.c
deleted file mode 100644
index 889e11c95b..0000000000
--- a/shadow/getspnam.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Copyright (C) 1996-2023 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
- <https://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/shadow/getspnam_r.c b/shadow/getspnam_r.c
deleted file mode 100644
index 381362f41e..0000000000
--- a/shadow/getspnam_r.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Copyright (C) 1996-2023 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
- <https://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/shadow/lckpwdf.c b/shadow/lckpwdf.c
deleted file mode 100644
index 3b36b2ebca..0000000000
--- a/shadow/lckpwdf.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/* Handle locking of password file.
- Copyright (C) 1996-2023 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
- <https://www.gnu.org/licenses/>. */
-
-#include <fcntl.h>
-#include <libc-lock.h>
-#include <shadow.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/file.h>
-#include <sigsetops.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 | O_CLOEXEC;
- lock_fd = __open (PWD_LOCKFILE, oflags, 0600);
- if (lock_fd == -1)
- /* Cannot create lock file. */
- RETURN_CLOSE_FD (-1);
-
- /* 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/shadow/putspent.c b/shadow/putspent.c
deleted file mode 100644
index a80711d0b6..0000000000
--- a/shadow/putspent.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/* Copyright (C) 1991-2023 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
- <https://www.gnu.org/licenses/>. */
-
-#include <errno.h>
-#include <nss.h>
-#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;
-
- if (p->sp_namp == NULL || !__nss_valid_field (p->sp_namp)
- || !__nss_valid_field (p->sp_pwdp))
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- 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/shadow/sgetspent.c b/shadow/sgetspent.c
deleted file mode 100644
index 99c0973fdd..0000000000
--- a/