summaryrefslogtreecommitdiff
path: root/shadow
diff options
context:
space:
mode:
Diffstat (limited to 'shadow')
-rw-r--r--shadow/Makefile29
-rw-r--r--shadow/fgetspent.c31
-rw-r--r--shadow/fgetspent_r.c56
-rw-r--r--shadow/getspent.c30
-rw-r--r--shadow/getspent_r.c30
-rw-r--r--shadow/getspnam.c30
-rw-r--r--shadow/getspnam_r.c30
-rw-r--r--shadow/putspent.c80
-rw-r--r--shadow/sgetspent.c46
-rw-r--r--shadow/sgetspent_r.c72
-rw-r--r--shadow/shadow.h108
11 files changed, 542 insertions, 0 deletions
diff --git a/shadow/Makefile b/shadow/Makefile
new file mode 100644
index 0000000000..943881f1f1
--- /dev/null
+++ b/shadow/Makefile
@@ -0,0 +1,29 @@
+# Copyright (C) 1996 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 Library General Public License as
+# published by the Free Software Foundation; either version 2 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
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public
+# License along with the GNU C Library; see the file COPYING.LIB. If
+# not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#
+# Makefile for shadow.
+#
+subdir := shadow
+
+headers = shadow.h
+routines = getspent getspnam sgetspent fgetspent putspent \
+ getspent_r getspnam_r sgetspent_r fgetspent_r
+
+
+include ../Rules
diff --git a/shadow/fgetspent.c b/shadow/fgetspent.c
new file mode 100644
index 0000000000..d6c4e4fc05
--- /dev/null
+++ b/shadow/fgetspent.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <shadow.h>
+#include <stdio.h>
+
+
+/* Read one shadow entry from the given stream. */
+struct spwd *
+fgetspent (FILE *stream)
+{
+ static char buffer[BUFSIZ];
+ static struct spwd result;
+
+ return __fgetspent_r (stream, &result, buffer, sizeof buffer);
+}
diff --git a/shadow/fgetspent_r.c b/shadow/fgetspent_r.c
new file mode 100644
index 0000000000..6521517a6f
--- /dev/null
+++ b/shadow/fgetspent_r.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ctype.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. */
+struct spwd *
+__fgetspent_r (FILE *stream, struct spwd *result, char *buffer, int buflen)
+{
+ char *p;
+
+ do
+ {
+ p = fgets (buffer, buflen, stream);
+ if (p == NULL)
+ return NULL;
+
+ /* 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 *) result, NULL, 0));
+
+ return result;
+}
+weak_alias (__fgetspent_r, fgetspent_r)
diff --git a/shadow/getspent.c b/shadow/getspent.c
new file mode 100644
index 0000000000..4266959bc1
--- /dev/null
+++ b/shadow/getspent.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+#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
+
+#include "../nss/getXXent.c"
diff --git a/shadow/getspent_r.c b/shadow/getspent_r.c
new file mode 100644
index 0000000000..d5f1546a9e
--- /dev/null
+++ b/shadow/getspent_r.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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/tes
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+#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
+
+#include "../nss/getXXent_r.c"
diff --git a/shadow/getspnam.c b/shadow/getspnam.c
new file mode 100644
index 0000000000..6d82f28999
--- /dev/null
+++ b/shadow/getspnam.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+#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
+
+#include "../nss/getXXbyYY.c"
diff --git a/shadow/getspnam_r.c b/shadow/getspnam_r.c
new file mode 100644
index 0000000000..148c94011d
--- /dev/null
+++ b/shadow/getspnam_r.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+#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
+
+#include "../nss/getXXbyYY_r.c"
diff --git a/shadow/putspent.c b/shadow/putspent.c
new file mode 100644
index 0000000000..59dbfda172
--- /dev/null
+++ b/shadow/putspent.c
@@ -0,0 +1,80 @@
+/* Copyright (C) 1991, 1992, 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <shadow.h>
+
+
+/* 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 (fprintf (stream, "%s:%s", p->sp_namp, p->sp_pwdp) < 0)
+ ++errors;
+
+ if ((p->sp_lstchg != (time_t) -1
+ && fprintf (stream, "%ld", p->sp_lstchg) < 0)
+ || (p->sp_lstchg == (time_t) -1
+ && putc (':', stream) == EOF))
+ ++errors;
+
+ if ((p->sp_min != (time_t) -1
+ && fprintf (stream, "%ld", p->sp_min) < 0)
+ || (p->sp_min == (time_t) -1
+ && putc (':', stream) == EOF))
+ ++errors;
+
+ if ((p->sp_max != (time_t) -1
+ && fprintf (stream, "%ld", p->sp_max) < 0)
+ || (p->sp_max == (time_t) -1
+ && putc (':', stream) == EOF))
+ ++errors;
+
+ if ((p->sp_warn != (time_t) -1
+ && fprintf (stream, "%ld", p->sp_warn) < 0)
+ || (p->sp_warn == (time_t) -1
+ && putc (':', stream) == EOF))
+ ++errors;
+
+ if ((p->sp_inact != (time_t) -1
+ && fprintf (stream, "%ld", p->sp_inact) < 0)
+ || (p->sp_inact == (time_t) -1
+ && putc (':', stream) == EOF))
+ ++errors;
+
+ if ((p->sp_expire != (time_t) -1
+ && fprintf (stream, "%ld", p->sp_expire) < 0)
+ || (p->sp_expire == (time_t) -1
+ && putc (':', stream) == EOF))
+ ++errors;
+
+ if ((p->sp_flag != -1l
+ && fprintf (stream, "%ld", p->sp_flag) < 0)
+ || (p->sp_flag == -1l
+ && putc (':', stream) == EOF))
+ ++errors;
+
+ if (putc ('\n', stream) == EOF)
+ ++errors;
+
+ return errors ? -1 : 0;
+}
diff --git a/shadow/sgetspent.c b/shadow/sgetspent.c
new file mode 100644
index 0000000000..a3c61f9026
--- /dev/null
+++ b/shadow/sgetspent.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <shadow.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+/* Read one shadow entry from the given stream. */
+struct spwd *
+sgetspent (const char *string)
+{
+ static struct spwd result;
+ static int max_size = 0;
+ static char *buffer = NULL;
+ int len;
+
+ len = strlen (string) + 1;
+ if (len > max_size)
+ {
+ max_size = MAX (128, len + 32);
+ buffer = realloc (buffer, max_size);
+ if (buffer == NULL)
+ return NULL;
+ }
+
+ return __sgetspent_r (string, &result, buffer, max_size);
+}
diff --git a/shadow/sgetspent_r.c b/shadow/sgetspent_r.c
new file mode 100644
index 0000000000..3ad72f0c0a
--- /dev/null
+++ b/shadow/sgetspent_r.c
@@ -0,0 +1,72 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ctype.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 {};
+
+#include "../nss/nss_files/files-parse.c"
+LINE_PARSER
+(,
+ STRING_FIELD (result->sp_namp, ISCOLON, 0);
+ STRING_FIELD (result->sp_pwdp, ISCOLON, 0);
+ INT_FIELD (result->sp_lstchg, ISCOLON, 0, 10, (time_t));
+ INT_FIELD (result->sp_min, ISCOLON, 0, 10, (time_t));
+ INT_FIELD (result->sp_max, ISCOLON, 0, 10, (time_t));
+ while (isspace (*line))
+ ++line;
+ if (*line == '\0')
+ {
+ /* The old form. */
+ result->sp_warn = (time_t) -1;
+ result->sp_inact = (time_t) -1;
+ result->sp_expire = (time_t) -1;
+ result->sp_flag = (time_t) -1;
+ }
+ else
+ {
+ INT_FIELD (result->sp_warn, ISCOLON, 0, 10, (time_t));
+ INT_FIELD (result->sp_inact, ISCOLON, 0, 10, (time_t));
+ INT_FIELD (result->sp_expire, ISCOLON, 0, 10, (time_t));
+ while (isspace (*line))
+ ++line;
+ if (*line == '\0')
+ result->sp_flag = -1;
+ else
+ INT_FIELD (result->sp_flag, ISCOLON, 0, 10, );
+ }
+ )
+
+
+/* Read one shadow entry from the given stream. */
+struct spwd *
+__sgetspent_r (const char *string, struct spwd *result, char *buffer,
+ int buflen)
+{
+ return parse_line (strncpy (string, buffer, buflen), result, NULL, 0)
+ ? result : NULL;
+}
+weak_alias (__sgetspent_r, sgetspent_r)
diff --git a/shadow/shadow.h b/shadow/shadow.h
new file mode 100644
index 0000000000..88199a9856
--- /dev/null
+++ b/shadow/shadow.h
@@ -0,0 +1,108 @@
+/* Copyright (C) 1996 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 Library General Public License as
+published by the Free Software Foundation; either version 2 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+/* Declaration of types and functions for shadow password suite. */
+
+#ifndef _SHADOW_H
+
+#define _SHADOW_H 1
+#include <features.h>
+
+#define __need_FILE
+#include <stdio.h>
+#define __need_time_t
+#include <time.h>
+
+/* Paths to the userd files. */
+#define SHADOW "/etc/shadow"
+
+
+__BEGIN_DECLS
+
+/* Structure of the password file. */
+struct spwd
+{
+ char *sp_namp; /* Login name. */
+ char *sp_pwdp; /* Encrypted password. */
+ __time_t sp_lstchg; /* Date of last change. */
+ __time_t sp_min; /* Minimum number of days between changes. */
+ __time_t sp_max; /* Maximum number of days between changes. */
+ __time_t sp_warn; /* Number of days to warn user to change
+ the password. */
+ __time_t sp_inact; /* Number of days the account may be
+ inactive. */
+ __time_t sp_expire; /* Number of days since 700101 until account
+ expires. */
+ unsigned long int sp_flag; /* Reserved. */
+};
+
+
+/* Open database for reading. */
+extern void setspent __P ((void));
+
+/* Close database. */
+extern void endspent __P ((void));
+
+/* Get next entry from database, perhaps after opening the file. */
+extern struct spwd *getspent __P ((void));
+
+/* Get shadow entry matching NAME. */
+extern struct spwd *getspnam __P ((__const char *__name));
+
+/* Read shadow entry from STRING. */
+extern struct spwd *sgetspent __P ((__const char *__string));
+
+/* Read next shadow entry from STREAM. */
+extern struct spwd *fgetspent __P ((FILE *__stream));
+
+/* Write line containing shadow password entry to stream. */
+extern int putspent __P ((__const struct spwd *__p, FILE *__stream));
+
+
+#ifdef __USE_REENTRANT
+/* Reentrant versions of some of the functions above. */
+extern struct spwd *__getspent_r __P ((struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+extern struct spwd *getspent_r __P ((struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+
+extern struct spwd *__getspnam_r __P ((__const char *__name,
+ struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+extern struct spwd *getspnam_r __P ((__const char *__name,
+ struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+
+extern struct spwd *__sgetspent_r __P ((__const char *__string,
+ struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+extern struct spwd *sgetspent_r __P ((__const char *__string,
+ struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+
+extern struct spwd *__fgetspent_r __P ((FILE *__stream,
+ struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+extern struct spwd *fgetspent_r __P ((FILE *__stream,
+ struct spwd *__result_buf,
+ char *__buffer, int __buflen));
+#endif /* reentrant */
+
+__END_DECLS
+
+#endif /* shadow.h */