[svn-upgrade] Integrating new upstream version, shadow (20000826)

This commit is contained in:
nekral-guest
2007-10-07 11:44:26 +00:00
parent 5cd76a407a
commit be1f391d2a
41 changed files with 720 additions and 910 deletions

View File

@@ -2,7 +2,7 @@
#include <config.h>
#include "rcsid.h"
RCSID("$Id: commonio.c,v 1.16 2000/09/02 18:40:42 marekm Exp $")
RCSID("$Id: commonio.c,v 1.15 2000/08/26 18:27:17 marekm Exp $")
#include "defines.h"
#include <sys/stat.h>
@@ -29,8 +29,9 @@ static int name_is_nis(const char *);
static int write_all(const struct commonio_db *);
static struct commonio_entry *find_entry_by_name(struct commonio_db *, const char *);
#ifdef HAVE_LCKPWDF
static int lock_count = 0;
static int nscd_need_reload = 0;
#endif
static int
check_link_count(const char *file)
@@ -235,7 +236,6 @@ commonio_lock_nowait(struct commonio_db *db)
snprintf(lock, sizeof lock, "%s.lock", db->filename);
if (do_lock_file(file, lock)) {
db->locked = 1;
lock_count++;
return 1;
}
return 0;
@@ -245,30 +245,31 @@ commonio_lock_nowait(struct commonio_db *db)
int
commonio_lock(struct commonio_db *db)
{
int i;
#ifdef HAVE_LCKPWDF
/*
* only if the system libc has a real lckpwdf() - the one from
* lockpw.c calls us and would cause infinite recursion!
*/
/*
* Call lckpwdf() on the first lock.
* If it succeeds, call *_lock() only once
* (no retries, it should always succeed).
*/
if (lock_count == 0) {
if (lckpwdf() == -1)
if (db->use_lckpwdf) {
/*
* Call lckpwdf() on the first lock.
* If it succeeds, call *_lock() only once
* (no retries, it should always succeed).
*/
if (lock_count == 0) {
if (lckpwdf() == -1)
return 0; /* failure */
}
if (!commonio_lock_nowait(db)) {
ulckpwdf();
return 0; /* failure */
}
if (commonio_lock_nowait(db))
}
lock_count++;
return 1; /* success */
ulckpwdf();
return 0; /* failure */
#else
int i;
}
#endif
/*
* lckpwdf() not used - do it the old way.
*/
@@ -289,53 +290,6 @@ commonio_lock(struct commonio_db *db)
return 0;
}
return 0; /* failure */
#endif
}
#ifndef NSCD_PID_FILE
#define NSCD_PID_FILE "/var/run/nscd.pid"
#endif
/*
reload_nscd() is called after updating all of the password files,
to tell the "nscd" caching daemon to clear its cache.
Very loosely based on a shadow-utils patch from Red Hat.
*/
static void
reload_nscd(void)
{
FILE *pidfile;
int pid;
pidfile = fopen(NSCD_PID_FILE, "r");
if (pidfile) {
pid = 0;
fscanf(pidfile, "%d", &pid);
if (pid > 0)
kill(pid, SIGHUP);
fclose(pidfile);
}
}
static void
dec_lock_count(void)
{
if (lock_count > 0) {
lock_count--;
if (lock_count == 0) {
/* Tell nscd when lock count goes to zero,
if any of the files were changed. */
if (nscd_need_reload) {
reload_nscd();
nscd_need_reload = 0;
}
#ifdef HAVE_LCKPWDF
ulckpwdf();
#endif
}
}
}
@@ -346,11 +300,8 @@ commonio_unlock(struct commonio_db *db)
if (db->isopen) {
db->readonly = 1;
if (!commonio_close(db)) {
if (db->locked)
dec_lock_count();
if (!commonio_close(db))
return 0;
}
}
if (db->locked) {
/*
@@ -360,7 +311,13 @@ commonio_unlock(struct commonio_db *db)
db->locked = 0;
snprintf(lock, sizeof lock, "%s.lock", db->filename);
unlink(lock);
dec_lock_count();
#ifdef HAVE_LCKPWDF
if (db->use_lckpwdf && lock_count > 0) {
lock_count--;
if (lock_count == 0)
ulckpwdf();
}
#endif
return 1;
}
return 0;
@@ -396,6 +353,7 @@ name_is_nis(const char *n)
#endif
#if KEEP_NIS_AT_END
/* prototype */
static void add_one_entry_nis(struct commonio_db *, struct commonio_entry *);
static void
@@ -419,20 +377,16 @@ add_one_entry_nis(struct commonio_db *db, struct commonio_entry *newp)
}
#endif /* KEEP_NIS_AT_END */
/* Initial buffer size, as well as increment if not sufficient
(for reading very long lines in group files). */
#define BUFLEN 4096
int
commonio_open(struct commonio_db *db, int mode)
{
char *buf;
char *cp;
char buf[8192];
char *cp;
char *line;
struct commonio_entry *p;
void *eptr;
int flags = mode;
int buflen;
mode &= ~O_CREAT;
@@ -463,25 +417,12 @@ commonio_open(struct commonio_db *db, int mode)
return 0;
}
buflen = BUFLEN;
buf = (char *) malloc(buflen);
if (!buf)
goto cleanup;
while (db->ops->fgets(buf, buflen, db->fp)) {
while (!(cp = strrchr(buf, '\n')) && !feof(db->fp)) {
buflen += BUFLEN;
cp = (char *) realloc(buf, buflen);
if (!cp)
goto cleanup_buf;
buf = cp;
db->ops->fgets(buf + buflen - BUFLEN, BUFLEN, db->fp);
}
while (db->ops->fgets(buf, sizeof buf, db->fp)) {
if ((cp = strrchr(buf, '\n')))
*cp = '\0';
if (!(line = strdup(buf)))
goto cleanup_buf;
goto cleanup;
if (name_is_nis(line)) {
eptr = NULL;
@@ -503,7 +444,6 @@ commonio_open(struct commonio_db *db, int mode)
}
db->isopen = 1;
free(buf);
return 1;
cleanup_entry:
@@ -511,8 +451,6 @@ cleanup_entry:
db->ops->free(eptr);
cleanup_line:
free(line);
cleanup_buf:
free(buf);
cleanup:
free_linked_list(db);
fclose(db->fp);
@@ -626,8 +564,6 @@ commonio_close(struct commonio_db *db)
if (rename(buf, db->filename))
goto fail;
nscd_need_reload = 1;
success:
free_linked_list(db);
return 1;

View File

@@ -1,4 +1,4 @@
/* $Id: commonio.h,v 1.6 2000/09/02 18:40:43 marekm Exp $ */
/* $Id: commonio.h,v 1.5 2000/08/26 18:27:17 marekm Exp $ */
/*
* Linked list entry.
@@ -82,6 +82,7 @@ struct commonio_db {
int isopen:1;
int locked:1;
int readonly:1;
int use_lckpwdf:1;
};
extern int commonio_setname(struct commonio_db *, const char *);

View File

@@ -1,4 +1,4 @@
/* $Id: defines.h,v 1.17 2000/09/02 18:40:43 marekm Exp $ */
/* $Id: defines.h,v 1.16 2000/08/26 18:27:17 marekm Exp $ */
/* some useful defines */
#ifndef _DEFINES_H_
@@ -138,24 +138,13 @@ char *strchr(), *strrchr(), *strtok();
#define LOG_WARN LOG_WARNING
#endif
/* LOG_NOWAIT is deprecated */
#ifndef LOG_NOWAIT
#define LOG_NOWAIT 0
#endif
/* LOG_AUTH is deprecated, use LOG_AUTHPRIV instead */
#ifndef LOG_AUTHPRIV
#define LOG_AUTHPRIV LOG_AUTH
#endif
/* cleaner than lots of #ifdefs everywhere - use this as follows:
SYSLOG((LOG_CRIT, "user %s cracked root", user)); */
#if HAVE_SETLOCALE
/* Temporarily set LC_TIME to "C" to avoid strange dates in syslog.
This is a workaround for a more general syslog(d) design problem -
syslogd should log the current system time for each event, and not
trust the formatted time received from the unix domain (or worse,
UDP) socket. -MM */
trust the formatted time received from the unix domain socket. -MM */
#define SYSLOG(x) \
do { \
char *saved_locale = setlocale(LC_ALL, NULL); \
@@ -181,20 +170,6 @@ char *strchr(), *strrchr(), *strtok();
#endif /* !USE_SYSLOG */
/* The default syslog settings can now be changed here,
in just one place. */
#ifndef SYSLOG_OPTIONS
/* #define SYSLOG_OPTIONS (LOG_PID | LOG_CONS | LOG_NOWAIT) */
#define SYSLOG_OPTIONS (LOG_PID)
#endif
#ifndef SYSLOG_FACILITY
#define SYSLOG_FACILITY LOG_AUTHPRIV
#endif
#define OPENLOG(progname) openlog(progname, SYSLOG_OPTIONS, SYSLOG_FACILITY)
#ifndef F_OK
# define F_OK 0
# define X_OK 1

View File

@@ -2,7 +2,7 @@
#include <config.h>
#include "rcsid.h"
RCSID("$Id: groupio.c,v 1.9 2000/09/02 18:40:43 marekm Exp $")
RCSID("$Id: groupio.c,v 1.8 2000/08/26 18:27:17 marekm Exp $")
#include "prototypes.h"
#include "defines.h"
@@ -102,7 +102,8 @@ static struct commonio_db group_db = {
0, /* changed */
0, /* isopen */
0, /* locked */
0 /* readonly */
0, /* readonly */
0 /* use_lckpwdf */
};
int

View File

@@ -2,7 +2,7 @@
#include <config.h>
#include "rcsid.h"
RCSID("$Id: pwio.c,v 1.11 2000/09/02 18:40:43 marekm Exp $")
RCSID("$Id: pwio.c,v 1.10 2000/08/26 18:27:17 marekm Exp $")
#include "prototypes.h"
#include "defines.h"
@@ -110,7 +110,8 @@ static struct commonio_db passwd_db = {
0, /* changed */
0, /* isopen */
0, /* locked */
0 /* readonly */
0, /* readonly */
1 /* use_lckpwdf */
};
int

View File

@@ -4,7 +4,7 @@
#ifdef SHADOWGRP
#include "rcsid.h"
RCSID("$Id: sgroupio.c,v 1.11 2000/09/02 18:40:43 marekm Exp $")
RCSID("$Id: sgroupio.c,v 1.10 2000/08/26 18:27:17 marekm Exp $")
#include "prototypes.h"
#include "defines.h"
@@ -121,7 +121,8 @@ static struct commonio_db gshadow_db = {
0, /* changed */
0, /* isopen */
0, /* locked */
0 /* readonly */
0, /* readonly */
0 /* use_lckpwdf */
};
int

View File

@@ -4,7 +4,7 @@
#ifdef SHADOWPWD
#include "rcsid.h"
RCSID("$Id: shadowio.c,v 1.12 2000/09/02 18:40:43 marekm Exp $")
RCSID("$Id: shadowio.c,v 1.11 1998/01/29 23:22:32 marekm Exp $")
#include "prototypes.h"
#include "defines.h"
@@ -88,7 +88,8 @@ static struct commonio_db shadow_db = {
0, /* changed */
0, /* isopen */
0, /* locked */
0 /* readonly */
0, /* readonly */
1 /* use_lckpwdf */
};
int