2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
/* Newer versions of Linux libc already have shadow support. */
|
2007-10-07 17:16:25 +05:30
|
|
|
#ifndef HAVE_GETSPNAM
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <sys/types.h>
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef USE_NIS
|
2010-03-23 14:26:52 +05:30
|
|
|
static bool nis_used;
|
|
|
|
static bool nis_ignore;
|
2007-10-07 17:16:07 +05:30
|
|
|
static enum { native, start, middle, native2 } nis_state;
|
2010-03-23 14:26:52 +05:30
|
|
|
static bool nis_bound;
|
2007-10-07 17:16:07 +05:30
|
|
|
static char *nis_domain;
|
|
|
|
static char *nis_key;
|
|
|
|
static int nis_keylen;
|
|
|
|
static char *nis_val;
|
|
|
|
static int nis_vallen;
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#define IS_NISCHAR(c) ((c)=='+')
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static FILE *shadow;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#define FIELDS 9
|
|
|
|
#define OFIELDS 5
|
|
|
|
|
|
|
|
#ifdef USE_NIS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* __setspNIS - turn on or off NIS searches
|
|
|
|
*/
|
|
|
|
|
2010-03-23 14:26:52 +05:30
|
|
|
void __setspNIS (bool flag)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
nis_ignore = !flag;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_ignore) {
|
2010-03-23 14:26:52 +05:30
|
|
|
nis_used = false;
|
2009-04-11 04:05:14 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bind_nis - bind to NIS server
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static int bind_nis (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2010-03-23 14:26:52 +05:30
|
|
|
if (yp_get_default_domain (&nis_domain)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2010-03-23 14:26:52 +05:30
|
|
|
nis_bound = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setspent - initialize access to shadow text and DBM files
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void setspent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2010-03-23 14:26:52 +05:30
|
|
|
if (NULL != shadow) {
|
2007-10-07 17:16:07 +05:30
|
|
|
rewind (shadow);
|
2010-03-23 14:26:52 +05:30
|
|
|
}else {
|
2007-10-07 17:16:07 +05:30
|
|
|
shadow = fopen (SHADOW_FILE, "r");
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef USE_NIS
|
|
|
|
nis_state = native;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* endspent - terminate access to shadow text and DBM files
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void endspent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2010-03-23 14:26:52 +05:30
|
|
|
if (NULL != shadow) {
|
2007-10-07 17:14:02 +05:30
|
|
|
(void) fclose (shadow);
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2023-02-01 07:20:14 +05:30
|
|
|
shadow = NULL;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* my_sgetspent - convert string in shadow file format to (struct spwd *)
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static struct spwd *my_sgetspent (const char *string)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2009-04-11 04:05:14 +05:30
|
|
|
static char spwbuf[BUFSIZ];
|
|
|
|
static struct spwd spwd;
|
2007-10-07 17:16:07 +05:30
|
|
|
char *fields[FIELDS];
|
|
|
|
char *cp;
|
|
|
|
int i;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy string to local buffer. It has to be tokenized and we
|
|
|
|
* have to do that to our private copy.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (strlen (string) >= sizeof spwbuf)
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2007-10-07 17:16:07 +05:30
|
|
|
strcpy (spwbuf, string);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-02 03:51:55 +05:30
|
|
|
cp = strrchr (spwbuf, '\n');
|
|
|
|
if (NULL != cp)
|
2007-10-07 17:14:02 +05:30
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tokenize the string into colon separated fields. Allow up to
|
|
|
|
* FIELDS different fields.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
fields[i] = cp;
|
|
|
|
while (*cp && *cp != ':')
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
if (*cp)
|
|
|
|
*cp++ = '\0';
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (i == (FIELDS - 1))
|
2007-10-07 17:14:02 +05:30
|
|
|
fields[i++] = cp;
|
|
|
|
|
|
|
|
if ((cp && *cp) || (i != FIELDS && i != OFIELDS))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start populating the structure. The fields are all in
|
|
|
|
* static storage, as is the structure we pass back. If we
|
|
|
|
* ever see a name with '+' as the first character, we try
|
|
|
|
* to turn on NIS processing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
spwd.sp_namp = fields[0];
|
|
|
|
#ifdef USE_NIS
|
2010-03-23 14:26:52 +05:30
|
|
|
if (IS_NISCHAR (fields[0][0])) {
|
|
|
|
nis_used = true;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
spwd.sp_pwdp = fields[1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the last changed date. For all of the integer fields,
|
|
|
|
* we check for proper format. It is an error to have an
|
|
|
|
* incorrectly formatted number, unless we are using NIS.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (fields[2][0] == '\0') {
|
|
|
|
spwd.sp_lstchg = -1;
|
|
|
|
} else {
|
|
|
|
if (getlong (fields[2], &spwd.sp_lstchg) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_used) {
|
|
|
|
spwd.sp_lstchg = -1;
|
|
|
|
} else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2009-04-11 04:05:14 +05:30
|
|
|
return 0;
|
|
|
|
} else if (spwd.sp_lstchg < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the minimum period between password changes.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (fields[3][0] == '\0') {
|
|
|
|
spwd.sp_min = -1;
|
|
|
|
} else {
|
|
|
|
if (getlong (fields[3], &spwd.sp_min) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_used) {
|
|
|
|
spwd.sp_min = -1;
|
|
|
|
} else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2010-03-23 14:26:52 +05:30
|
|
|
{
|
2009-04-11 04:05:14 +05:30
|
|
|
return 0;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2009-04-11 04:05:14 +05:30
|
|
|
} else if (spwd.sp_min < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the maximum number of days a password is valid.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (fields[4][0] == '\0') {
|
|
|
|
spwd.sp_max = -1;
|
|
|
|
} else {
|
|
|
|
if (getlong (fields[4], &spwd.sp_max) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_used) {
|
|
|
|
spwd.sp_max = -1;
|
|
|
|
} else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2009-04-11 04:05:14 +05:30
|
|
|
return 0;
|
|
|
|
} else if (spwd.sp_max < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
|
|
|
|
* formatted file), initialize the other field members to -1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (i == OFIELDS) {
|
2009-04-11 04:05:14 +05:30
|
|
|
spwd.sp_warn = -1;
|
|
|
|
spwd.sp_inact = -1;
|
|
|
|
spwd.sp_expire = -1;
|
|
|
|
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return &spwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the number of days of password expiry warning.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (fields[5][0] == '\0') {
|
|
|
|
spwd.sp_warn = -1;
|
|
|
|
} else {
|
|
|
|
if (getlong (fields[5], &spwd.sp_warn) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_used) {
|
|
|
|
spwd.sp_warn = -1;
|
|
|
|
} else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2010-03-23 14:26:52 +05:30
|
|
|
{
|
2009-04-11 04:05:14 +05:30
|
|
|
return 0;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2009-04-11 04:05:14 +05:30
|
|
|
} else if (spwd.sp_warn < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the number of days of inactivity before an account is
|
|
|
|
* disabled.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (fields[6][0] == '\0') {
|
|
|
|
spwd.sp_inact = -1;
|
|
|
|
} else {
|
|
|
|
if (getlong (fields[6], &spwd.sp_inact) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_used) {
|
|
|
|
spwd.sp_inact = -1;
|
|
|
|
} else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2010-03-23 14:26:52 +05:30
|
|
|
{
|
2009-04-11 04:05:14 +05:30
|
|
|
return 0;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2009-04-11 04:05:14 +05:30
|
|
|
} else if (spwd.sp_inact < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the number of days after the epoch before the account is
|
|
|
|
* set to expire.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (fields[7][0] == '\0') {
|
|
|
|
spwd.sp_expire = -1;
|
|
|
|
} else {
|
|
|
|
if (getlong (fields[7], &spwd.sp_expire) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_used) {
|
|
|
|
spwd.sp_expire = -1;
|
|
|
|
} else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2010-03-23 14:26:52 +05:30
|
|
|
{
|
2009-04-11 04:05:14 +05:30
|
|
|
return 0;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2009-04-11 04:05:14 +05:30
|
|
|
} else if (spwd.sp_expire < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-14 03:25:51 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* This field is reserved for future use. But it isn't supposed
|
|
|
|
* to have anything other than a valid integer in it.
|
|
|
|
*/
|
|
|
|
|
2009-04-11 04:05:14 +05:30
|
|
|
if (fields[8][0] == '\0') {
|
|
|
|
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
|
|
|
|
} else {
|
2022-05-10 18:31:21 +05:30
|
|
|
if (getulong (fields[8], &spwd.sp_flag) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2009-04-11 04:05:14 +05:30
|
|
|
if (nis_used) {
|
|
|
|
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
|
|
|
|
} else
|
|
|
|
#endif
|
2010-03-23 14:26:52 +05:30
|
|
|
{
|
2009-04-11 04:05:14 +05:30
|
|
|
return 0;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2009-04-11 04:05:14 +05:30
|
|
|
} else if (spwd.sp_flag < 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2008-06-14 03:25:51 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return (&spwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fgetspent - get an entry from a /etc/shadow formatted stream
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
struct spwd *fgetspent (FILE * fp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
char buf[BUFSIZ];
|
|
|
|
char *cp;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-14 03:25:51 +05:30
|
|
|
if (NULL == fp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return (0);
|
2008-06-14 03:25:51 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef USE_NIS
|
2023-02-01 07:20:14 +05:30
|
|
|
while (fgets (buf, (int) sizeof buf, fp) != NULL)
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2023-02-01 07:20:14 +05:30
|
|
|
if (fgets (buf, (int) sizeof buf, fp) != NULL)
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
{
|
2008-01-02 03:51:55 +05:30
|
|
|
cp = strchr (buf, '\n');
|
2008-06-14 03:25:51 +05:30
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
*cp = '\0';
|
2008-06-14 03:25:51 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2008-06-14 03:25:51 +05:30
|
|
|
if (nis_ignore && IS_NISCHAR (buf[0])) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-06-14 03:25:51 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:16:07 +05:30
|
|
|
return my_sgetspent (buf);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getspent - get a (struct spwd *) from the current shadow file
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
struct spwd *getspent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
#ifdef USE_NIS
|
2007-10-07 17:16:07 +05:30
|
|
|
int nis_1_user = 0;
|
|
|
|
struct spwd *val;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2010-03-23 14:26:52 +05:30
|
|
|
if (NULL == shadow) {
|
2007-10-07 17:14:02 +05:30
|
|
|
setspent ();
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef USE_NIS
|
2007-10-07 17:16:07 +05:30
|
|
|
again:
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* See if we are reading from the local file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nis_state == native || nis_state == native2) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the next entry from the shadow file. Return NULL
|
|
|
|
* right away if there is none.
|
|
|
|
*/
|
|
|
|
|
2008-01-02 03:51:55 +05:30
|
|
|
val = fgetspent (shadow);
|
|
|
|
if (NULL == val)
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this entry began with a NIS escape character, we have
|
|
|
|
* to see if this is just a single user, or if the entire
|
|
|
|
* map is being asked for.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (IS_NISCHAR (val->sp_namp[0])) {
|
|
|
|
if (val->sp_namp[1])
|
|
|
|
nis_1_user = 1;
|
|
|
|
else
|
|
|
|
nis_state = start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this isn't a NIS user and this isn't an escape to go
|
|
|
|
* use a NIS map, it must be a regular local user.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nis_1_user == 0 && nis_state != start)
|
|
|
|
return val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is an escape to use an NIS map, switch over to
|
|
|
|
* that bunch of code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nis_state == start)
|
|
|
|
goto again;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NEEDSWORK. Here we substitute pieces-parts of this entry.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else {
|
2010-03-23 14:26:52 +05:30
|
|
|
if (!nis_bound) {
|
2007-10-07 17:14:02 +05:30
|
|
|
if (bind_nis ()) {
|
|
|
|
nis_state = native2;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nis_state == start) {
|
|
|
|
if (yp_first (nis_domain, "shadow.bynam", &nis_key,
|
2010-03-23 14:26:52 +05:30
|
|
|
&nis_keylen, &nis_val, &nis_vallen)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
nis_state = native2;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
nis_state = middle;
|
|
|
|
} else if (nis_state == middle) {
|
|
|
|
if (yp_next (nis_domain, "shadow.bynam", nis_key,
|
2010-03-23 14:26:52 +05:30
|
|
|
nis_keylen, &nis_key, &nis_keylen,
|
|
|
|
&nis_val, &nis_vallen)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
nis_state = native2;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
return my_sgetspent (nis_val);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#else
|
|
|
|
return (fgetspent (shadow));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getspnam - get a shadow entry by name
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
struct spwd *getspnam (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
struct spwd *sp;
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_NIS
|
2007-10-07 17:16:07 +05:30
|
|
|
static char save_name[16];
|
2010-03-23 14:26:52 +05:30
|
|
|
bool nis_disabled = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
setspent ();
|
|
|
|
|
|
|
|
#ifdef USE_NIS
|
|
|
|
/*
|
|
|
|
* Search the shadow.byname map for this user.
|
|
|
|
*/
|
|
|
|
|
2010-03-23 14:26:52 +05:30
|
|
|
if (!nis_ignore && !nis_bound) {
|
2007-10-07 17:14:02 +05:30
|
|
|
bind_nis ();
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!nis_ignore && nis_bound) {
|
|
|
|
char *cp;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (yp_match (nis_domain, "shadow.byname", name,
|
2010-03-23 14:26:52 +05:30
|
|
|
strlen (name), &nis_val, &nis_vallen) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-02 03:51:55 +05:30
|
|
|
cp = strchr (nis_val, '\n');
|
2010-03-23 14:26:52 +05:30
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
*cp = '\0';
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
nis_state = middle;
|
2008-01-02 03:51:55 +05:30
|
|
|
sp = my_sgetspent (nis_val);
|
|
|
|
if (NULL != sp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
strcpy (save_name, sp->sp_namp);
|
|
|
|
nis_key = save_name;
|
|
|
|
nis_keylen = strlen (save_name);
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
endspent ();
|
2007-10-07 17:14:02 +05:30
|
|
|
return sp;
|
2010-03-23 14:26:52 +05:30
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
nis_state = native2;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_NIS
|
|
|
|
/*
|
|
|
|
* NEEDSWORK -- this is a mess, and it is the same mess in the
|
|
|
|
* other three files. I can't just blindly turn off NIS because
|
|
|
|
* this might be the first pass through the local files. In
|
|
|
|
* that case, I never discover that NIS is present.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nis_used) {
|
2010-03-23 14:26:52 +05:30
|
|
|
nis_ignore = true;
|
|
|
|
nis_disabled = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|
2023-02-01 07:20:14 +05:30
|
|
|
while ((sp = getspent ()) != NULL) {
|
2010-03-23 14:26:52 +05:30
|
|
|
if (strcmp (name, sp->sp_namp) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2010-03-23 14:26:52 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef USE_NIS
|
2010-03-23 14:26:52 +05:30
|
|
|
if (nis_disabled) {
|
|
|
|
nis_ignore = false;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:16:07 +05:30
|
|
|
endspent ();
|
2007-10-07 17:14:02 +05:30
|
|
|
return (sp);
|
|
|
|
}
|
|
|
|
#else
|
2022-12-21 23:32:25 +05:30
|
|
|
extern int ISO_C_forbids_an_empty_translation_unit;
|
2007-10-07 17:16:25 +05:30
|
|
|
#endif
|
2009-04-11 04:05:14 +05:30
|
|
|
|