[svn-upgrade] Integrating new upstream version, shadow (4.0.8)
This commit is contained in:
1
lib/.indent.pro
vendored
1
lib/.indent.pro
vendored
@@ -2,3 +2,4 @@
|
||||
-i8
|
||||
-bad
|
||||
-pcs
|
||||
-l80
|
||||
|
@@ -6,7 +6,7 @@ DEFS =
|
||||
lib_LTLIBRARIES = libshadow.la
|
||||
|
||||
libshadow_la_LDFLAGS = -version-info 0:0:0
|
||||
libshadow_la_LIBADD = $(INTLLIBS) $(LIBCRYPT) $(LIBSKEY) $(LIBMD) $(LIBSELINUX)
|
||||
libshadow_la_LIBADD = $(INTLLIBS) $(LIBCRYPT) $(LIBSELINUX)
|
||||
|
||||
libshadow_la_SOURCES = \
|
||||
commonio.c \
|
||||
@@ -32,7 +32,6 @@ libshadow_la_SOURCES = \
|
||||
pwauth.h \
|
||||
pwio.c \
|
||||
pwio.h \
|
||||
rad64.c \
|
||||
rcsid.h \
|
||||
sgetgrent.c \
|
||||
sgetpwent.c \
|
||||
@@ -50,6 +49,5 @@ libshadow_la_SOURCES = \
|
||||
|
||||
EXTRA_DIST = \
|
||||
.indent.pro \
|
||||
grdbm.c gsdbm.c pwdbm.c spdbm.c \
|
||||
grpack.c gspack.c pwpack.c sppack.c \
|
||||
gshadow_.h
|
||||
|
@@ -1,8 +1,8 @@
|
||||
# Makefile.in generated by automake 1.9.4 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.9.5 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004 Free Software Foundation, Inc.
|
||||
# 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -58,12 +58,11 @@ libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
am__DEPENDENCIES_1 =
|
||||
libshadow_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
|
||||
am_libshadow_la_OBJECTS = commonio.lo encrypt.lo fputsx.lo getdef.lo \
|
||||
getpass.lo groupio.lo gshadow.lo lockpw.lo nscd.lo port.lo \
|
||||
pwauth.lo pwio.lo rad64.lo sgetgrent.lo sgetpwent.lo \
|
||||
sgroupio.lo shadow.lo shadowio.lo utent.lo
|
||||
pwauth.lo pwio.lo sgetgrent.lo sgetpwent.lo sgroupio.lo \
|
||||
shadow.lo shadowio.lo utent.lo
|
||||
libshadow_la_OBJECTS = $(am_libshadow_la_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
@@ -116,17 +115,16 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
INTLLIBS = @INTLLIBS@
|
||||
INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBCRACK = @LIBCRACK@
|
||||
LIBCRYPT = @LIBCRYPT@
|
||||
LIBICONV = @LIBICONV@
|
||||
LIBINTL = @LIBINTL@
|
||||
LIBMD = @LIBMD@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBPAM = @LIBPAM@
|
||||
LIBS = @LIBS@
|
||||
LIBSELINUX = @LIBSELINUX@
|
||||
LIBSKEY = @LIBSKEY@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
LTLIBICONV = @LTLIBICONV@
|
||||
@@ -203,7 +201,7 @@ target_alias = @target_alias@
|
||||
AUTOMAKE_OPTIONS = 1.0 foreign
|
||||
lib_LTLIBRARIES = libshadow.la
|
||||
libshadow_la_LDFLAGS = -version-info 0:0:0
|
||||
libshadow_la_LIBADD = $(INTLLIBS) $(LIBCRYPT) $(LIBSKEY) $(LIBMD) $(LIBSELINUX)
|
||||
libshadow_la_LIBADD = $(INTLLIBS) $(LIBCRYPT) $(LIBSELINUX)
|
||||
libshadow_la_SOURCES = \
|
||||
commonio.c \
|
||||
commonio.h \
|
||||
@@ -228,7 +226,6 @@ libshadow_la_SOURCES = \
|
||||
pwauth.h \
|
||||
pwio.c \
|
||||
pwio.h \
|
||||
rad64.c \
|
||||
rcsid.h \
|
||||
sgetgrent.c \
|
||||
sgetpwent.c \
|
||||
@@ -246,7 +243,6 @@ libshadow_la_SOURCES = \
|
||||
# sources for dbm support (not yet used)
|
||||
EXTRA_DIST = \
|
||||
.indent.pro \
|
||||
grdbm.c gsdbm.c pwdbm.c spdbm.c \
|
||||
grpack.c gspack.c pwpack.c sppack.c \
|
||||
gshadow_.h
|
||||
|
||||
@@ -331,7 +327,6 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/port.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pwauth.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pwio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rad64.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sgetgrent.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sgetpwent.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sgroupio.Plo@am__quote@
|
||||
|
473
lib/commonio.c
473
lib/commonio.c
@@ -2,8 +2,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: commonio.c,v 1.27 2004/11/02 19:01:12 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: commonio.c,v 1.28 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include "defines.h"
|
||||
#include <sys/stat.h>
|
||||
#include <utime.h>
|
||||
@@ -18,30 +17,30 @@ RCSID("$Id: commonio.c,v 1.27 2004/11/02 19:01:12 kloczek Exp $")
|
||||
#endif
|
||||
#ifdef WITH_SELINUX
|
||||
#include <selinux/selinux.h>
|
||||
static security_context_t old_context=NULL;
|
||||
static security_context_t old_context = NULL;
|
||||
#endif
|
||||
#include "commonio.h"
|
||||
|
||||
/* local function prototypes */
|
||||
static int check_link_count(const char *);
|
||||
static int do_lock_file(const char *, const char *);
|
||||
static FILE *fopen_set_perms(const char *, const char *, const struct stat *);
|
||||
static int create_backup(const char *, FILE *);
|
||||
static void free_linked_list(struct commonio_db *);
|
||||
static void add_one_entry(struct commonio_db *, struct commonio_entry *);
|
||||
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 *);
|
||||
static int check_link_count (const char *);
|
||||
static int do_lock_file (const char *, const char *);
|
||||
static FILE *fopen_set_perms (const char *, const char *, const struct stat *);
|
||||
static int create_backup (const char *, FILE *);
|
||||
static void free_linked_list (struct commonio_db *);
|
||||
static void add_one_entry (struct commonio_db *, struct commonio_entry *);
|
||||
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 *);
|
||||
|
||||
static int lock_count = 0;
|
||||
static int nscd_need_reload = 0;
|
||||
|
||||
static int
|
||||
check_link_count(const char *file)
|
||||
static int check_link_count (const char *file)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (stat(file, &sb) != 0)
|
||||
if (stat (file, &sb) != 0)
|
||||
return 0;
|
||||
|
||||
if (sb.st_nlink != 2)
|
||||
@@ -51,8 +50,7 @@ check_link_count(const char *file)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
do_lock_file(const char *file, const char *lock)
|
||||
static int do_lock_file (const char *file, const char *lock)
|
||||
{
|
||||
int fd;
|
||||
int pid;
|
||||
@@ -60,100 +58,99 @@ do_lock_file(const char *file, const char *lock)
|
||||
int retval;
|
||||
char buf[32];
|
||||
|
||||
if ((fd = open(file, O_CREAT|O_EXCL|O_WRONLY, 0600)) == -1)
|
||||
if ((fd = open (file, O_CREAT | O_EXCL | O_WRONLY, 0600)) == -1)
|
||||
return 0;
|
||||
|
||||
pid = getpid();
|
||||
snprintf(buf, sizeof buf, "%d", pid);
|
||||
len = strlen(buf) + 1;
|
||||
if (write(fd, buf, len) != len) {
|
||||
close(fd);
|
||||
unlink(file);
|
||||
pid = getpid ();
|
||||
snprintf (buf, sizeof buf, "%d", pid);
|
||||
len = strlen (buf) + 1;
|
||||
if (write (fd, buf, len) != len) {
|
||||
close (fd);
|
||||
unlink (file);
|
||||
return 0;
|
||||
}
|
||||
close(fd);
|
||||
close (fd);
|
||||
|
||||
if (link(file, lock) == 0) {
|
||||
retval = check_link_count(file);
|
||||
unlink(file);
|
||||
if (link (file, lock) == 0) {
|
||||
retval = check_link_count (file);
|
||||
unlink (file);
|
||||
return retval;
|
||||
}
|
||||
|
||||
if ((fd = open(lock, O_RDWR)) == -1) {
|
||||
unlink(file);
|
||||
if ((fd = open (lock, O_RDWR)) == -1) {
|
||||
unlink (file);
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
len = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
len = read (fd, buf, sizeof (buf) - 1);
|
||||
close (fd);
|
||||
if (len <= 0) {
|
||||
unlink(file);
|
||||
unlink (file);
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
if ((pid = strtol(buf, (char **) 0, 10)) == 0) {
|
||||
unlink(file);
|
||||
if ((pid = strtol (buf, (char **) 0, 10)) == 0) {
|
||||
unlink (file);
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
if (kill(pid, 0) == 0) {
|
||||
unlink(file);
|
||||
if (kill (pid, 0) == 0) {
|
||||
unlink (file);
|
||||
errno = EEXIST;
|
||||
return 0;
|
||||
}
|
||||
if (unlink(lock) != 0) {
|
||||
unlink(file);
|
||||
if (unlink (lock) != 0) {
|
||||
unlink (file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
retval = 0;
|
||||
if (link(file, lock) == 0 && check_link_count(file))
|
||||
if (link (file, lock) == 0 && check_link_count (file))
|
||||
retval = 1;
|
||||
|
||||
unlink(file);
|
||||
unlink (file);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static FILE *
|
||||
fopen_set_perms(const char *name, const char *mode, const struct stat *sb)
|
||||
static FILE *fopen_set_perms (const char *name, const char *mode,
|
||||
const struct stat *sb)
|
||||
{
|
||||
FILE *fp;
|
||||
mode_t mask;
|
||||
|
||||
mask = umask(0777);
|
||||
fp = fopen(name, mode);
|
||||
umask(mask);
|
||||
mask = umask (0777);
|
||||
fp = fopen (name, mode);
|
||||
umask (mask);
|
||||
if (!fp)
|
||||
return NULL;
|
||||
|
||||
#ifdef HAVE_FCHOWN
|
||||
if (fchown(fileno(fp), sb->st_uid, sb->st_gid))
|
||||
if (fchown (fileno (fp), sb->st_uid, sb->st_gid))
|
||||
goto fail;
|
||||
#else
|
||||
if (chown(name, sb->st_mode))
|
||||
if (chown (name, sb->st_mode))
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FCHMOD
|
||||
if (fchmod(fileno(fp), sb->st_mode & 0664))
|
||||
if (fchmod (fileno (fp), sb->st_mode & 0664))
|
||||
goto fail;
|
||||
#else
|
||||
if (chmod(name, sb->st_mode & 0664))
|
||||
if (chmod (name, sb->st_mode & 0664))
|
||||
goto fail;
|
||||
#endif
|
||||
return fp;
|
||||
|
||||
fail:
|
||||
fclose(fp);
|
||||
unlink(name);
|
||||
fail:
|
||||
fclose (fp);
|
||||
unlink (name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
create_backup(const char *backup, FILE *fp)
|
||||
static int create_backup (const char *backup, FILE * fp)
|
||||
{
|
||||
struct stat sb;
|
||||
struct utimbuf ub;
|
||||
@@ -161,38 +158,37 @@ create_backup(const char *backup, FILE *fp)
|
||||
int c;
|
||||
mode_t mask;
|
||||
|
||||
if (fstat(fileno(fp), &sb))
|
||||
if (fstat (fileno (fp), &sb))
|
||||
return -1;
|
||||
|
||||
mask = umask(077);
|
||||
bkfp = fopen(backup, "w");
|
||||
umask(mask);
|
||||
mask = umask (077);
|
||||
bkfp = fopen (backup, "w");
|
||||
umask (mask);
|
||||
if (!bkfp)
|
||||
return -1;
|
||||
|
||||
/* TODO: faster copy, not one-char-at-a-time. --marekm */
|
||||
c = 0;
|
||||
if (fseek(fp, 0, SEEK_SET) == 0)
|
||||
while ((c = getc(fp)) != EOF) {
|
||||
if (putc(c, bkfp) == EOF)
|
||||
if (fseek (fp, 0, SEEK_SET) == 0)
|
||||
while ((c = getc (fp)) != EOF) {
|
||||
if (putc (c, bkfp) == EOF)
|
||||
break;
|
||||
}
|
||||
if (c != EOF || ferror(fp) || fflush(bkfp)) {
|
||||
fclose(bkfp);
|
||||
if (c != EOF || ferror (fp) || fflush (bkfp)) {
|
||||
fclose (bkfp);
|
||||
return -1;
|
||||
}
|
||||
if (fclose(bkfp))
|
||||
if (fclose (bkfp))
|
||||
return -1;
|
||||
|
||||
ub.actime = sb.st_atime;
|
||||
ub.modtime = sb.st_mtime;
|
||||
utime(backup, &ub);
|
||||
utime (backup, &ub);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
free_linked_list(struct commonio_db *db)
|
||||
static void free_linked_list (struct commonio_db *db)
|
||||
{
|
||||
struct commonio_entry *p;
|
||||
|
||||
@@ -201,34 +197,31 @@ free_linked_list(struct commonio_db *db)
|
||||
db->head = p->next;
|
||||
|
||||
if (p->line)
|
||||
free(p->line);
|
||||
free (p->line);
|
||||
|
||||
if (p->eptr)
|
||||
db->ops->free(p->eptr);
|
||||
db->ops->free (p->eptr);
|
||||
|
||||
free(p);
|
||||
free (p);
|
||||
}
|
||||
db->tail = NULL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_setname(struct commonio_db *db, const char *name)
|
||||
int commonio_setname (struct commonio_db *db, const char *name)
|
||||
{
|
||||
snprintf(db->filename, sizeof(db->filename), "%s", name);
|
||||
snprintf (db->filename, sizeof (db->filename), "%s", name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_present(const struct commonio_db *db)
|
||||
int commonio_present (const struct commonio_db *db)
|
||||
{
|
||||
return (access(db->filename, F_OK) == 0);
|
||||
return (access (db->filename, F_OK) == 0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_lock_nowait(struct commonio_db *db)
|
||||
int commonio_lock_nowait (struct commonio_db *db)
|
||||
{
|
||||
char file[1024];
|
||||
char lock[1024];
|
||||
@@ -236,9 +229,9 @@ commonio_lock_nowait(struct commonio_db *db)
|
||||
if (db->locked)
|
||||
return 1;
|
||||
|
||||
snprintf(file, sizeof file, "%s.%ld", db->filename, (long) getpid());
|
||||
snprintf(lock, sizeof lock, "%s.lock", db->filename);
|
||||
if (do_lock_file(file, lock)) {
|
||||
snprintf (file, sizeof file, "%s.%ld", db->filename, (long) getpid ());
|
||||
snprintf (lock, sizeof lock, "%s.lock", db->filename);
|
||||
if (do_lock_file (file, lock)) {
|
||||
db->locked = 1;
|
||||
lock_count++;
|
||||
return 1;
|
||||
@@ -247,8 +240,7 @@ commonio_lock_nowait(struct commonio_db *db)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_lock(struct commonio_db *db)
|
||||
int commonio_lock (struct commonio_db *db)
|
||||
{
|
||||
#ifdef HAVE_LCKPWDF
|
||||
/*
|
||||
@@ -262,15 +254,15 @@ commonio_lock(struct commonio_db *db)
|
||||
* (no retries, it should always succeed).
|
||||
*/
|
||||
if (lock_count == 0) {
|
||||
if (lckpwdf() == -1)
|
||||
return 0; /* failure */
|
||||
if (lckpwdf () == -1)
|
||||
return 0; /* failure */
|
||||
}
|
||||
|
||||
if (commonio_lock_nowait(db))
|
||||
return 1; /* success */
|
||||
if (commonio_lock_nowait (db))
|
||||
return 1; /* success */
|
||||
|
||||
ulckpwdf();
|
||||
return 0; /* failure */
|
||||
ulckpwdf ();
|
||||
return 0; /* failure */
|
||||
#else
|
||||
int i;
|
||||
|
||||
@@ -286,19 +278,18 @@ commonio_lock(struct commonio_db *db)
|
||||
#endif
|
||||
for (i = 0; i < LOCK_TRIES; i++) {
|
||||
if (i > 0)
|
||||
sleep(LOCK_SLEEP); /* delay between retries */
|
||||
if (commonio_lock_nowait(db))
|
||||
return 1; /* success */
|
||||
sleep (LOCK_SLEEP); /* delay between retries */
|
||||
if (commonio_lock_nowait (db))
|
||||
return 1; /* success */
|
||||
/* no unnecessary retries on "permission denied" errors */
|
||||
if (geteuid() != 0)
|
||||
if (geteuid () != 0)
|
||||
return 0;
|
||||
}
|
||||
return 0; /* failure */
|
||||
return 0; /* failure */
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
dec_lock_count(void)
|
||||
static void dec_lock_count (void)
|
||||
{
|
||||
if (lock_count > 0) {
|
||||
lock_count--;
|
||||
@@ -306,48 +297,46 @@ dec_lock_count(void)
|
||||
/* Tell nscd when lock count goes to zero,
|
||||
if any of the files were changed. */
|
||||
if (nscd_need_reload) {
|
||||
nscd_flush_cache("passwd");
|
||||
nscd_flush_cache("group");
|
||||
nscd_flush_cache ("passwd");
|
||||
nscd_flush_cache ("group");
|
||||
nscd_need_reload = 0;
|
||||
}
|
||||
#ifdef HAVE_LCKPWDF
|
||||
ulckpwdf();
|
||||
ulckpwdf ();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_unlock(struct commonio_db *db)
|
||||
int commonio_unlock (struct commonio_db *db)
|
||||
{
|
||||
char lock[1024];
|
||||
|
||||
if (db->isopen) {
|
||||
db->readonly = 1;
|
||||
if (!commonio_close(db)) {
|
||||
if (!commonio_close (db)) {
|
||||
if (db->locked)
|
||||
dec_lock_count();
|
||||
dec_lock_count ();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (db->locked) {
|
||||
if (db->locked) {
|
||||
/*
|
||||
* Unlock in reverse order: remove the lock file,
|
||||
* then call ulckpwdf() (if used) on last unlock.
|
||||
*/
|
||||
db->locked = 0;
|
||||
snprintf(lock, sizeof lock, "%s.lock", db->filename);
|
||||
unlink(lock);
|
||||
dec_lock_count();
|
||||
db->locked = 0;
|
||||
snprintf (lock, sizeof lock, "%s.lock", db->filename);
|
||||
unlink (lock);
|
||||
dec_lock_count ();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
add_one_entry(struct commonio_db *db, struct commonio_entry *p)
|
||||
static void add_one_entry (struct commonio_db *db, struct commonio_entry *p)
|
||||
{
|
||||
p->next = NULL;
|
||||
p->prev = db->tail;
|
||||
@@ -359,8 +348,7 @@ add_one_entry(struct commonio_db *db, struct commonio_entry *p)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
name_is_nis(const char *n)
|
||||
static int name_is_nis (const char *n)
|
||||
{
|
||||
return (n[0] == '+' || n[0] == '-');
|
||||
}
|
||||
@@ -375,15 +363,16 @@ name_is_nis(const char *n)
|
||||
#endif
|
||||
|
||||
#if KEEP_NIS_AT_END
|
||||
static void add_one_entry_nis(struct commonio_db *, struct commonio_entry *);
|
||||
static void add_one_entry_nis (struct commonio_db *, struct commonio_entry *);
|
||||
|
||||
static void
|
||||
add_one_entry_nis(struct commonio_db *db, struct commonio_entry *newp)
|
||||
add_one_entry_nis (struct commonio_db *db, struct commonio_entry *newp)
|
||||
{
|
||||
struct commonio_entry *p;
|
||||
|
||||
for (p = db->head; p; p = p->next) {
|
||||
if (name_is_nis(p->eptr ? db->ops->getname(p->eptr) : p->line)) {
|
||||
if (name_is_nis
|
||||
(p->eptr ? db->ops->getname (p->eptr) : p->line)) {
|
||||
newp->next = p;
|
||||
newp->prev = p->prev;
|
||||
if (p->prev)
|
||||
@@ -394,16 +383,15 @@ add_one_entry_nis(struct commonio_db *db, struct commonio_entry *newp)
|
||||
return;
|
||||
}
|
||||
}
|
||||
add_one_entry(db, newp);
|
||||
add_one_entry (db, newp);
|
||||
}
|
||||
#endif /* KEEP_NIS_AT_END */
|
||||
#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)
|
||||
int commonio_open (struct commonio_db *db, int mode)
|
||||
{
|
||||
char *buf;
|
||||
char *cp;
|
||||
@@ -429,7 +417,7 @@ commonio_open(struct commonio_db *db, int mode)
|
||||
db->head = db->tail = db->cursor = NULL;
|
||||
db->changed = 0;
|
||||
|
||||
db->fp = fopen(db->filename, db->readonly ? "r" : "r+");
|
||||
db->fp = fopen (db->filename, db->readonly ? "r" : "r+");
|
||||
|
||||
/*
|
||||
* If O_CREAT was specified and the file didn't exist, it will be
|
||||
@@ -442,48 +430,47 @@ commonio_open(struct commonio_db *db, int mode)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
db->scontext=NULL;
|
||||
if (is_selinux_enabled() && (! db->readonly)) {
|
||||
if (fgetfilecon(fileno(db->fp),&db->scontext) < 0) {
|
||||
goto cleanup_errno;
|
||||
}
|
||||
db->scontext = NULL;
|
||||
if (is_selinux_enabled () && (!db->readonly)) {
|
||||
if (fgetfilecon (fileno (db->fp), &db->scontext) < 0) {
|
||||
goto cleanup_errno;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
buflen = BUFLEN;
|
||||
buf = (char *) malloc(buflen);
|
||||
buf = (char *) malloc (buflen);
|
||||
if (!buf)
|
||||
goto cleanup_ENOMEM;
|
||||
|
||||
while (db->ops->fgets(buf, buflen, db->fp)) {
|
||||
while (!(cp = strrchr(buf, '\n')) && !feof(db->fp)) {
|
||||
while (db->ops->fgets (buf, buflen, db->fp)) {
|
||||
while (!(cp = strrchr (buf, '\n')) && !feof (db->fp)) {
|
||||
int len;
|
||||
|
||||
buflen += BUFLEN;
|
||||
cp = (char *) realloc(buf, buflen);
|
||||
cp = (char *) realloc (buf, buflen);
|
||||
if (!cp)
|
||||
goto cleanup_buf;
|
||||
buf = cp;
|
||||
len = strlen(buf);
|
||||
db->ops->fgets(buf + len, buflen - len, db->fp);
|
||||
len = strlen (buf);
|
||||
db->ops->fgets (buf + len, buflen - len, db->fp);
|
||||
}
|
||||
if ((cp = strrchr(buf, '\n')))
|
||||
if ((cp = strrchr (buf, '\n')))
|
||||
*cp = '\0';
|
||||
|
||||
if (!(line = strdup(buf)))
|
||||
if (!(line = strdup (buf)))
|
||||
goto cleanup_buf;
|
||||
|
||||
if (name_is_nis(line)) {
|
||||
if (name_is_nis (line)) {
|
||||
eptr = NULL;
|
||||
} else if ((eptr = db->ops->parse(line))) {
|
||||
eptr = db->ops->dup(eptr);
|
||||
} else if ((eptr = db->ops->parse (line))) {
|
||||
eptr = db->ops->dup (eptr);
|
||||
if (!eptr)
|
||||
goto cleanup_line;
|
||||
}
|
||||
|
||||
p = (struct commonio_entry *) malloc(sizeof *p);
|
||||
p = (struct commonio_entry *) malloc (sizeof *p);
|
||||
if (!p)
|
||||
goto cleanup_entry;
|
||||
|
||||
@@ -491,36 +478,36 @@ commonio_open(struct commonio_db *db, int mode)
|
||||
p->line = line;
|
||||
p->changed = 0;
|
||||
|
||||
add_one_entry(db, p);
|
||||
add_one_entry (db, p);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
free (buf);
|
||||
|
||||
if (ferror(db->fp))
|
||||
if (ferror (db->fp))
|
||||
goto cleanup_errno;
|
||||
|
||||
db->isopen = 1;
|
||||
return 1;
|
||||
|
||||
cleanup_entry:
|
||||
cleanup_entry:
|
||||
if (eptr)
|
||||
db->ops->free(eptr);
|
||||
cleanup_line:
|
||||
free(line);
|
||||
cleanup_buf:
|
||||
free(buf);
|
||||
cleanup_ENOMEM:
|
||||
db->ops->free (eptr);
|
||||
cleanup_line:
|
||||
free (line);
|
||||
cleanup_buf:
|
||||
free (buf);
|
||||
cleanup_ENOMEM:
|
||||
errno = ENOMEM;
|
||||
cleanup_errno:
|
||||
cleanup_errno:
|
||||
saved_errno = errno;
|
||||
free_linked_list(db);
|
||||
free_linked_list (db);
|
||||
#ifdef WITH_SELINUX
|
||||
if (db->scontext!= NULL) {
|
||||
freecon(db->scontext);
|
||||
db->scontext=NULL;
|
||||
if (db->scontext != NULL) {
|
||||
freecon (db->scontext);
|
||||
db->scontext = NULL;
|
||||
}
|
||||
#endif
|
||||
fclose(db->fp);
|
||||
fclose (db->fp);
|
||||
db->fp = NULL;
|
||||
errno = saved_errno;
|
||||
return 0;
|
||||
@@ -530,7 +517,7 @@ cleanup_errno:
|
||||
* Sort given db according to cmp function (usually compares uids)
|
||||
*/
|
||||
int
|
||||
commonio_sort(struct commonio_db *db, int (*cmp)(const void *, const void *))
|
||||
commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *))
|
||||
{
|
||||
struct commonio_entry **entries, *ptr;
|
||||
int n = 0, i;
|
||||
@@ -540,29 +527,29 @@ commonio_sort(struct commonio_db *db, int (*cmp)(const void *, const void *))
|
||||
|
||||
if (n <= 1)
|
||||
return 0;
|
||||
|
||||
entries = malloc(n * sizeof(struct commonio_entry*));
|
||||
|
||||
entries = malloc (n * sizeof (struct commonio_entry *));
|
||||
if (entries == NULL)
|
||||
return -1;
|
||||
|
||||
|
||||
n = 0;
|
||||
for (ptr = db->head; ptr; ptr = ptr->next)
|
||||
entries[n++] = ptr;
|
||||
qsort(entries, n, sizeof(struct commonio_entry*), cmp);
|
||||
|
||||
qsort (entries, n, sizeof (struct commonio_entry *), cmp);
|
||||
|
||||
db->head = entries[0];
|
||||
db->tail = entries[--n];
|
||||
db->head->prev = NULL;
|
||||
db->head->next = entries[1];
|
||||
db->tail->prev = entries[n-1];
|
||||
db->tail->prev = entries[n - 1];
|
||||
db->tail->next = NULL;
|
||||
|
||||
for (i = 1; i < n; i++) {
|
||||
entries[i]->prev = entries[i-1];
|
||||
entries[i]->next = entries[i+1];
|
||||
entries[i]->prev = entries[i - 1];
|
||||
entries[i]->next = entries[i + 1];
|
||||
}
|
||||
|
||||
free(entries);
|
||||
free (entries);
|
||||
db->changed = 1;
|
||||
|
||||
return 0;
|
||||
@@ -571,8 +558,7 @@ commonio_sort(struct commonio_db *db, int (*cmp)(const void *, const void *))
|
||||
/*
|
||||
* Sort entries in db according to order in another.
|
||||
*/
|
||||
int
|
||||
commonio_sort_wrt(struct commonio_db *shadow, struct commonio_db *passwd)
|
||||
int commonio_sort_wrt (struct commonio_db *shadow, struct commonio_db *passwd)
|
||||
{
|
||||
struct commonio_entry *head = NULL, *pw_ptr, *spw_ptr;
|
||||
const char *name;
|
||||
@@ -580,34 +566,34 @@ commonio_sort_wrt(struct commonio_db *shadow, struct commonio_db *passwd)
|
||||
for (pw_ptr = passwd->head; pw_ptr; pw_ptr = pw_ptr->next) {
|
||||
if (pw_ptr->eptr == NULL)
|
||||
continue;
|
||||
name = passwd->ops->getname(pw_ptr->eptr);
|
||||
name = passwd->ops->getname (pw_ptr->eptr);
|
||||
for (spw_ptr = shadow->head; spw_ptr; spw_ptr = spw_ptr->next)
|
||||
if (strcmp(name, shadow->ops->getname(spw_ptr->eptr)) == 0)
|
||||
if (strcmp (name, shadow->ops->getname (spw_ptr->eptr))
|
||||
== 0)
|
||||
break;
|
||||
if (spw_ptr == NULL)
|
||||
if (spw_ptr == NULL)
|
||||
continue;
|
||||
commonio_del_entry(shadow, spw_ptr);
|
||||
commonio_del_entry (shadow, spw_ptr);
|
||||
spw_ptr->next = head;
|
||||
head = spw_ptr;
|
||||
}
|
||||
|
||||
|
||||
for (spw_ptr = head; spw_ptr; spw_ptr = head) {
|
||||
head = head->next;
|
||||
|
||||
|
||||
if (shadow->head)
|
||||
shadow->head->prev = spw_ptr;
|
||||
spw_ptr->next = shadow->head;
|
||||
shadow->head = spw_ptr;
|
||||
}
|
||||
|
||||
|
||||
shadow->head->prev = NULL;
|
||||
shadow->changed = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
write_all(const struct commonio_db *db)
|
||||
static int write_all (const struct commonio_db *db)
|
||||
{
|
||||
const struct commonio_entry *p;
|
||||
void *eptr;
|
||||
@@ -615,12 +601,12 @@ write_all(const struct commonio_db *db)
|
||||
for (p = db->head; p; p = p->next) {
|
||||
if (p->changed) {
|
||||
eptr = p->eptr;
|
||||
if (db->ops->put(eptr, db->fp))
|
||||
if (db->ops->put (eptr, db->fp))
|
||||
return -1;
|
||||
} else if (p->line) {
|
||||
if (db->ops->fputs(p->line, db->fp) == EOF)
|
||||
if (db->ops->fputs (p->line, db->fp) == EOF)
|
||||
return -1;
|
||||
if (putc('\n', db->fp) == EOF)
|
||||
if (putc ('\n', db->fp) == EOF)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -628,8 +614,7 @@ write_all(const struct commonio_db *db)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_close(struct commonio_db *db)
|
||||
int commonio_close (struct commonio_db *db)
|
||||
{
|
||||
char buf[1024];
|
||||
int errors = 0;
|
||||
@@ -642,41 +627,41 @@ commonio_close(struct commonio_db *db)
|
||||
db->isopen = 0;
|
||||
|
||||
if (!db->changed || db->readonly) {
|
||||
fclose(db->fp);
|
||||
fclose (db->fp);
|
||||
db->fp = NULL;
|
||||
goto success;
|
||||
}
|
||||
|
||||
memzero(&sb, sizeof sb);
|
||||
memzero (&sb, sizeof sb);
|
||||
if (db->fp) {
|
||||
if (fstat(fileno(db->fp), &sb)) {
|
||||
fclose(db->fp);
|
||||
if (fstat (fileno (db->fp), &sb)) {
|
||||
fclose (db->fp);
|
||||
db->fp = NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
if (db->scontext != NULL) {
|
||||
int stat=getfscreatecon(&old_context);
|
||||
if (stat< 0) {
|
||||
errors++;
|
||||
goto fail;
|
||||
}
|
||||
if (setfscreatecon(db->scontext)<0) {
|
||||
errors++;
|
||||
goto fail;
|
||||
}
|
||||
int stat = getfscreatecon (&old_context);
|
||||
|
||||
if (stat < 0) {
|
||||
errors++;
|
||||
goto fail;
|
||||
}
|
||||
if (setfscreatecon (db->scontext) < 0) {
|
||||
errors++;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Create backup file.
|
||||
*/
|
||||
snprintf(buf, sizeof buf, "%s-", db->filename);
|
||||
snprintf (buf, sizeof buf, "%s-", db->filename);
|
||||
|
||||
if (create_backup(buf, db->fp))
|
||||
if (create_backup (buf, db->fp))
|
||||
errors++;
|
||||
|
||||
if (fclose(db->fp))
|
||||
if (fclose (db->fp))
|
||||
errors++;
|
||||
|
||||
if (errors) {
|
||||
@@ -693,77 +678,76 @@ commonio_close(struct commonio_db *db)
|
||||
sb.st_gid = 0;
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof buf, "%s+", db->filename);
|
||||
snprintf (buf, sizeof buf, "%s+", db->filename);
|
||||
|
||||
db->fp = fopen_set_perms(buf, "w", &sb);
|
||||
db->fp = fopen_set_perms (buf, "w", &sb);
|
||||
if (!db->fp)
|
||||
goto fail;
|
||||
|
||||
if (write_all(db))
|
||||
if (write_all (db))
|
||||
errors++;
|
||||
|
||||
if (fflush(db->fp))
|
||||
if (fflush (db->fp))
|
||||
errors++;
|
||||
#ifdef HAVE_FSYNC
|
||||
if (fsync(fileno(db->fp)))
|
||||
if (fsync (fileno (db->fp)))
|
||||
errors++;
|
||||
#else
|
||||
sync();
|
||||
sync ();
|
||||
#endif
|
||||
if (fclose(db->fp))
|
||||
if (fclose (db->fp))
|
||||
errors++;
|
||||
|
||||
db->fp = NULL;
|
||||
|
||||
if (errors) {
|
||||
unlink(buf);
|
||||
unlink (buf);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (rename(buf, db->filename))
|
||||
if (rename (buf, db->filename))
|
||||
goto fail;
|
||||
|
||||
nscd_need_reload = 1;
|
||||
goto success;
|
||||
fail:
|
||||
fail:
|
||||
errors++;
|
||||
success:
|
||||
success:
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
if (db->scontext != NULL) {
|
||||
if (setfscreatecon(old_context)<0) {
|
||||
errors++;
|
||||
}
|
||||
if (old_context != NULL) {
|
||||
freecon(old_context);
|
||||
old_context=NULL;
|
||||
}
|
||||
freecon(db->scontext);
|
||||
db->scontext=NULL;
|
||||
if (setfscreatecon (old_context) < 0) {
|
||||
errors++;
|
||||
}
|
||||
if (old_context != NULL) {
|
||||
freecon (old_context);
|
||||
old_context = NULL;
|
||||
}
|
||||
freecon (db->scontext);
|
||||
db->scontext = NULL;
|
||||
}
|
||||
#endif
|
||||
free_linked_list(db);
|
||||
return errors==0;
|
||||
free_linked_list (db);
|
||||
return errors == 0;
|
||||
}
|
||||
|
||||
|
||||
static struct commonio_entry *
|
||||
find_entry_by_name(struct commonio_db *db, const char *name)
|
||||
static struct commonio_entry *find_entry_by_name (struct commonio_db *db,
|
||||
const char *name)
|
||||
{
|
||||
struct commonio_entry *p;
|
||||
void *ep;
|
||||
|
||||
for (p = db->head; p; p = p->next) {
|
||||
ep = p->eptr;
|
||||
if (ep && strcmp(db->ops->getname(ep), name) == 0)
|
||||
if (ep && strcmp (db->ops->getname (ep), name) == 0)
|
||||
break;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_update(struct commonio_db *db, const void *eptr)
|
||||
int commonio_update (struct commonio_db *db, const void *eptr)
|
||||
{
|
||||
struct commonio_entry *p;
|
||||
void *nentry;
|
||||
@@ -772,13 +756,13 @@ commonio_update(struct commonio_db *db, const void *eptr)
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
if (!(nentry = db->ops->dup(eptr))) {
|
||||
if (!(nentry = db->ops->dup (eptr))) {
|
||||
errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
p = find_entry_by_name(db, db->ops->getname(eptr));
|
||||
p = find_entry_by_name (db, db->ops->getname (eptr));
|
||||
if (p) {
|
||||
db->ops->free(p->eptr);
|
||||
db->ops->free (p->eptr);
|
||||
p->eptr = nentry;
|
||||
p->changed = 1;
|
||||
db->cursor = p;
|
||||
@@ -787,9 +771,9 @@ commonio_update(struct commonio_db *db, const void *eptr)
|
||||
return 1;
|
||||
}
|
||||
/* not found, new entry */
|
||||
p = (struct commonio_entry *) malloc(sizeof *p);
|
||||
p = (struct commonio_entry *) malloc (sizeof *p);
|
||||
if (!p) {
|
||||
db->ops->free(nentry);
|
||||
db->ops->free (nentry);
|
||||
errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
@@ -799,9 +783,9 @@ commonio_update(struct commonio_db *db, const void *eptr)
|
||||
p->changed = 1;
|
||||
|
||||
#if KEEP_NIS_AT_END
|
||||
add_one_entry_nis(db, p);
|
||||
add_one_entry_nis (db, p);
|
||||
#else
|
||||
add_one_entry(db, p);
|
||||
add_one_entry (db, p);
|
||||
#endif
|
||||
|
||||
db->changed = 1;
|
||||
@@ -809,8 +793,7 @@ commonio_update(struct commonio_db *db, const void *eptr)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
commonio_del_entry(struct commonio_db *db, const struct commonio_entry *p)
|
||||
void commonio_del_entry (struct commonio_db *db, const struct commonio_entry *p)
|
||||
{
|
||||
if (p == db->cursor)
|
||||
db->cursor = p->next;
|
||||
@@ -829,8 +812,7 @@ commonio_del_entry(struct commonio_db *db, const struct commonio_entry *p)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_remove(struct commonio_db *db, const char *name)
|
||||
int commonio_remove (struct commonio_db *db, const char *name)
|
||||
{
|
||||
struct commonio_entry *p;
|
||||
|
||||
@@ -838,26 +820,25 @@ commonio_remove(struct commonio_db *db, const char *name)
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
p = find_entry_by_name(db, name);
|
||||
p = find_entry_by_name (db, name);
|
||||
if (!p) {
|
||||
errno = ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
commonio_del_entry(db, p);
|
||||
commonio_del_entry (db, p);
|
||||
|
||||
if (p->line)
|
||||
free(p->line);
|
||||
free (p->line);
|
||||
|
||||
if (p->eptr)
|
||||
db->ops->free(p->eptr);
|
||||
db->ops->free (p->eptr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
const void *
|
||||
commonio_locate(struct commonio_db *db, const char *name)
|
||||
const void *commonio_locate (struct commonio_db *db, const char *name)
|
||||
{
|
||||
struct commonio_entry *p;
|
||||
|
||||
@@ -865,7 +846,7 @@ commonio_locate(struct commonio_db *db, const char *name)
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
p = find_entry_by_name(db, name);
|
||||
p = find_entry_by_name (db, name);
|
||||
if (!p) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
@@ -875,8 +856,7 @@ commonio_locate(struct commonio_db *db, const char *name)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
commonio_rewind(struct commonio_db *db)
|
||||
int commonio_rewind (struct commonio_db *db)
|
||||
{
|
||||
if (!db->isopen) {
|
||||
errno = EINVAL;
|
||||
@@ -887,8 +867,7 @@ commonio_rewind(struct commonio_db *db)
|
||||
}
|
||||
|
||||
|
||||
const void *
|
||||
commonio_next(struct commonio_db *db)
|
||||
const void *commonio_next (struct commonio_db *db)
|
||||
{
|
||||
void *eptr;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $Id: commonio.h,v 1.8 2004/10/11 04:40:29 kloczek Exp $ */
|
||||
/* $Id: commonio.h,v 1.9 2005/03/31 05:14:49 kloczek Exp $ */
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
#include <selinux/selinux.h>
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
struct commonio_entry {
|
||||
char *line;
|
||||
void *eptr; /* struct passwd, struct spwd, ... */
|
||||
void *eptr; /* struct passwd, struct spwd, ... */
|
||||
struct commonio_entry *prev, *next;
|
||||
int changed:1;
|
||||
};
|
||||
@@ -21,37 +21,37 @@ struct commonio_ops {
|
||||
* Make a copy of the object (for example, struct passwd)
|
||||
* and all strings pointed by it, in malloced memory.
|
||||
*/
|
||||
void *(*dup)(const void *);
|
||||
void *(*dup) (const void *);
|
||||
|
||||
/*
|
||||
* free() the object including any strings pointed by it.
|
||||
*/
|
||||
void (*free)(void *);
|
||||
void (*free) (void *);
|
||||
|
||||
/*
|
||||
* Return the name of the object (for example, pw_name
|
||||
* for struct passwd).
|
||||
*/
|
||||
const char *(*getname)(const void *);
|
||||
const char *(*getname) (const void *);
|
||||
|
||||
/*
|
||||
* Parse a string, return object (in static area -
|
||||
* should be copied using the dup operation above).
|
||||
*/
|
||||
void *(*parse)(const char *);
|
||||
void *(*parse) (const char *);
|
||||
|
||||
/*
|
||||
* Write the object to the file (this calls putpwent()
|
||||
* for struct passwd, for example).
|
||||
*/
|
||||
int (*put)(const void *, FILE *);
|
||||
int (*put) (const void *, FILE *);
|
||||
|
||||
/*
|
||||
* fgets and fputs (can be replaced by versions that
|
||||
* understand line continuation conventions).
|
||||
*/
|
||||
char *(*fgets)(char *, int, FILE *);
|
||||
int (*fputs)(const char *, FILE *);
|
||||
char *(*fgets) (char *, int, FILE *);
|
||||
int (*fputs) (const char *, FILE *);
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -74,7 +74,7 @@ struct commonio_db {
|
||||
FILE *fp;
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
security_context_t scontext;
|
||||
security_context_t scontext;
|
||||
#endif
|
||||
/*
|
||||
* Head, tail, current position in linked list.
|
||||
@@ -90,19 +90,21 @@ struct commonio_db {
|
||||
int readonly:1;
|
||||
};
|
||||
|
||||
extern int commonio_setname(struct commonio_db *, const char *);
|
||||
extern int commonio_present(const struct commonio_db *);
|
||||
extern int commonio_lock(struct commonio_db *);
|
||||
extern int commonio_lock_nowait(struct commonio_db *);
|
||||
extern int commonio_open(struct commonio_db *, int);
|
||||
extern const void *commonio_locate(struct commonio_db *, const char *);
|
||||
extern int commonio_update(struct commonio_db *, const void *);
|
||||
extern int commonio_remove(struct commonio_db *, const char *);
|
||||
extern int commonio_rewind(struct commonio_db *);
|
||||
extern const void *commonio_next(struct commonio_db *);
|
||||
extern int commonio_close(struct commonio_db *);
|
||||
extern int commonio_unlock(struct commonio_db *);
|
||||
extern void commonio_del_entry(struct commonio_db *, const struct commonio_entry *);
|
||||
extern int commonio_sort_wrt(struct commonio_db *shadow, struct commonio_db *passwd);
|
||||
extern int commonio_sort(struct commonio_db *db, int (*cmp)(const void *, const void *));
|
||||
|
||||
extern int commonio_setname (struct commonio_db *, const char *);
|
||||
extern int commonio_present (const struct commonio_db *);
|
||||
extern int commonio_lock (struct commonio_db *);
|
||||
extern int commonio_lock_nowait (struct commonio_db *);
|
||||
extern int commonio_open (struct commonio_db *, int);
|
||||
extern const void *commonio_locate (struct commonio_db *, const char *);
|
||||
extern int commonio_update (struct commonio_db *, const void *);
|
||||
extern int commonio_remove (struct commonio_db *, const char *);
|
||||
extern int commonio_rewind (struct commonio_db *);
|
||||
extern const void *commonio_next (struct commonio_db *);
|
||||
extern int commonio_close (struct commonio_db *);
|
||||
extern int commonio_unlock (struct commonio_db *);
|
||||
extern void commonio_del_entry (struct commonio_db *,
|
||||
const struct commonio_entry *);
|
||||
extern int commonio_sort_wrt (struct commonio_db *shadow,
|
||||
struct commonio_db *passwd);
|
||||
extern int commonio_sort (struct commonio_db *db,
|
||||
int (*cmp) (const void *, const void *));
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $Id: defines.h,v 1.24 2005/01/17 19:03:34 kloczek Exp $ */
|
||||
/* $Id: defines.h,v 1.25 2005/03/31 05:14:49 kloczek Exp $ */
|
||||
/* some useful defines */
|
||||
|
||||
#ifndef _DEFINES_H_
|
||||
@@ -20,25 +20,26 @@
|
||||
# define _(Text) gettext (Text)
|
||||
#else
|
||||
# undef bindtextdomain
|
||||
# define bindtextdomain(Domain, Directory) /* empty */
|
||||
# define bindtextdomain(Domain, Directory) /* empty */
|
||||
# undef textdomain
|
||||
# define textdomain(Domain) /* empty */
|
||||
# define textdomain(Domain) /* empty */
|
||||
# define _(Text) Text
|
||||
#endif
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#else /* not STDC_HEADERS */
|
||||
#else /* not STDC_HEADERS */
|
||||
# ifndef HAVE_STRCHR
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
char *strchr(), *strrchr(), *strtok();
|
||||
char *strchr (), *strrchr (), *strtok ();
|
||||
|
||||
# ifndef HAVE_MEMCPY
|
||||
# define memcpy(d, s, n) bcopy((s), (d), (n))
|
||||
# endif
|
||||
#endif /* not STDC_HEADERS */
|
||||
#endif /* not STDC_HEADERS */
|
||||
|
||||
#if HAVE_ERRNO_H
|
||||
# include <errno.h>
|
||||
@@ -63,32 +64,32 @@ char *strchr(), *strrchr(), *strtok();
|
||||
#if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else /* not TIME_WITH_SYS_TIME */
|
||||
#else /* not TIME_WITH_SYS_TIME */
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif /* not TIME_WITH_SYS_TIME */
|
||||
#endif /* not TIME_WITH_SYS_TIME */
|
||||
|
||||
#ifdef HAVE_MEMSET
|
||||
# define memzero(ptr, size) memset((void *)(ptr), 0, (size))
|
||||
#else
|
||||
# define memzero(ptr, size) bzero((char *)(ptr), (size))
|
||||
#endif
|
||||
#define strzero(s) memzero(s, strlen(s)) /* warning: evaluates twice */
|
||||
#define strzero(s) memzero(s, strlen(s)) /* warning: evaluates twice */
|
||||
|
||||
#ifdef HAVE_DIRENT_H /* DIR_SYSV */
|
||||
#ifdef HAVE_DIRENT_H /* DIR_SYSV */
|
||||
# include <dirent.h>
|
||||
# define DIRECT dirent
|
||||
#else
|
||||
# ifdef HAVE_SYS_NDIR_H /* DIR_XENIX */
|
||||
# ifdef HAVE_SYS_NDIR_H /* DIR_XENIX */
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# ifdef HAVE_SYS_DIR_H /* DIR_??? */
|
||||
# ifdef HAVE_SYS_DIR_H /* DIR_??? */
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# ifdef HAVE_NDIR_H /* DIR_BSD */
|
||||
# ifdef HAVE_NDIR_H /* DIR_BSD */
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
# define DIRECT direct
|
||||
@@ -106,13 +107,13 @@ char *strchr(), *strrchr(), *strtok();
|
||||
#if defined(SHADOWGRP) && !defined(GSHADOW)
|
||||
#include "gshadow_.h"
|
||||
#endif
|
||||
#else /* not HAVE_SHADOW_H */
|
||||
#else /* not HAVE_SHADOW_H */
|
||||
#include "shadow_.h"
|
||||
#ifdef SHADOWGRP
|
||||
#include "gshadow_.h"
|
||||
#endif
|
||||
#endif /* not HAVE_SHADOW_H */
|
||||
#endif /* SHADOWPWD */
|
||||
#endif /* not HAVE_SHADOW_H */
|
||||
#endif /* SHADOWPWD */
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
@@ -162,17 +163,17 @@ char *strchr(), *strrchr(), *strtok();
|
||||
free(saved_locale); \
|
||||
} \
|
||||
} while (0)
|
||||
#else /* !ENABLE_NLS */
|
||||
#else /* !ENABLE_NLS */
|
||||
#define SYSLOG(x) syslog x
|
||||
#endif /* !ENABLE_NLS */
|
||||
#endif /* !ENABLE_NLS */
|
||||
|
||||
#else /* !USE_SYSLOG */
|
||||
#else /* !USE_SYSLOG */
|
||||
|
||||
#define SYSLOG(x) /* empty */
|
||||
#define openlog(a,b,c) /* empty */
|
||||
#define closelog() /* empty */
|
||||
#define SYSLOG(x) /* empty */
|
||||
#define openlog(a,b,c) /* empty */
|
||||
#define closelog() /* empty */
|
||||
|
||||
#endif /* !USE_SYSLOG */
|
||||
#endif /* !USE_SYSLOG */
|
||||
|
||||
/* The default syslog settings can now be changed here,
|
||||
in just one place. */
|
||||
@@ -231,7 +232,7 @@ char *strchr(), *strrchr(), *strtok();
|
||||
# define GTTY(fd, termio) tcgetattr(fd, termio)
|
||||
# define TERMIO struct termios
|
||||
# define USE_TERMIOS
|
||||
#else /* assumed HAVE_TERMIO_H */
|
||||
#else /* assumed HAVE_TERMIO_H */
|
||||
# include <sys/ioctl.h>
|
||||
# include <termio.h>
|
||||
# define STTY(fd, termio) ioctl(fd, TCSETA, termio)
|
||||
@@ -275,7 +276,7 @@ char *strchr(), *strrchr(), *strtok();
|
||||
#if defined(AIX) || defined(__linux__)
|
||||
#define SETXXENT_TYPE void
|
||||
#define SETXXENT_RET(x) return
|
||||
#define SETXXENT_TEST(x) x; if (0) /* compiler should optimize this away */
|
||||
#define SETXXENT_TEST(x) x; if (0) /* compiler should optimize this away */
|
||||
#else
|
||||
#define SETXXENT_TYPE int
|
||||
#define SETXXENT_RET(x) return(x)
|
||||
@@ -311,11 +312,11 @@ char *strchr(), *strrchr(), *strtok();
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
|
||||
#ifdef sun /* hacks for compiling on SunOS */
|
||||
#ifdef sun /* hacks for compiling on SunOS */
|
||||
# ifndef SOLARIS
|
||||
extern int fputs();
|
||||
extern char *strdup();
|
||||
extern char *strerror();
|
||||
extern int fputs ();
|
||||
extern char *strdup ();
|
||||
extern char *strerror ();
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -332,4 +333,4 @@ extern char *strerror();
|
||||
#define SHADOW_PASSWD_STRING "x"
|
||||
#endif
|
||||
|
||||
#endif /* _DEFINES_H_ */
|
||||
#endif /* _DEFINES_H_ */
|
||||
|
@@ -30,94 +30,29 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: encrypt.c,v 1.7 2000/08/26 18:27:17 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: encrypt.c,v 1.11 2005/04/06 02:59:22 kloczek Exp $")
|
||||
#include <unistd.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
extern char *crypt();
|
||||
extern char *libshadow_md5_crypt(const char *, const char *);
|
||||
|
||||
char *
|
||||
pw_encrypt(const char *clear, const char *salt)
|
||||
char *pw_encrypt (const char *clear, const char *salt)
|
||||
{
|
||||
static char cipher[128];
|
||||
char *cp;
|
||||
#ifdef SW_CRYPT
|
||||
static int count;
|
||||
#endif
|
||||
static char cipher[128];
|
||||
char *cp;
|
||||
|
||||
#ifdef MD5_CRYPT
|
||||
/*
|
||||
* If the salt string from the password file or from crypt_make_salt()
|
||||
* begins with the magic string, use the new algorithm.
|
||||
*/
|
||||
if (strncmp(salt, "$1$", 3) == 0)
|
||||
return libshadow_md5_crypt(clear, salt);
|
||||
#endif
|
||||
|
||||
#ifdef SW_CRYPT
|
||||
/*
|
||||
* Copy over the salt. It is always the first two
|
||||
* characters of the string.
|
||||
*/
|
||||
|
||||
cipher[0] = salt[0];
|
||||
cipher[1] = salt[1];
|
||||
cipher[2] = '\0';
|
||||
|
||||
/*
|
||||
* Loop up to ten times on the cleartext password.
|
||||
* This is because the input limit for passwords is
|
||||
* 80 characters.
|
||||
*
|
||||
* The initial salt is that provided by the user, or the
|
||||
* one generated above. The subsequent salts are gotten
|
||||
* from the first two characters of the previous encrypted
|
||||
* block of characters.
|
||||
*/
|
||||
|
||||
for (count = 0;count < 10;count++) {
|
||||
cp = crypt(clear, salt);
|
||||
if (!cp) {
|
||||
perror("crypt");
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(cp) != 13)
|
||||
return cp;
|
||||
strcat(cipher, cp + 2);
|
||||
salt = cipher + 11 * count + 2;
|
||||
|
||||
if (strlen(clear) > 8)
|
||||
clear += 8;
|
||||
else
|
||||
break;
|
||||
}
|
||||
#else
|
||||
cp = crypt(clear, salt);
|
||||
crypt (clear, salt);
|
||||
if (!cp) {
|
||||
/*
|
||||
* Single Unix Spec: crypt() may return a null pointer,
|
||||
* and set errno to indicate an error. The caller doesn't
|
||||
* expect us to return NULL, so...
|
||||
*/
|
||||
perror("crypt");
|
||||
exit(1);
|
||||
perror ("crypt");
|
||||
exit (1);
|
||||
}
|
||||
if (strlen(cp) != 13)
|
||||
return cp; /* nonstandard crypt() in libc, better bail out */
|
||||
strcpy(cipher, cp);
|
||||
if (strlen (cp) != 13)
|
||||
return cp; /* nonstandard crypt() in libc, better bail out */
|
||||
strcpy (cipher, cp);
|
||||
|
||||
#ifdef DOUBLESIZE
|
||||
if (strlen (clear) > 8) {
|
||||
cp = crypt(clear + 8, salt);
|
||||
if (!cp) {
|
||||
perror("crypt");
|
||||
exit(1);
|
||||
}
|
||||
strcat(cipher, cp + 2);
|
||||
}
|
||||
#endif /* DOUBLESIZE */
|
||||
#endif /* SW_CRYPT */
|
||||
return cipher;
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@
|
||||
/*
|
||||
* faillog.h - login failure logging file format
|
||||
*
|
||||
* $Id: faillog.h,v 1.3 1997/05/01 23:14:39 marekm Exp $
|
||||
* $Id: faillog.h,v 1.4 2005/03/31 05:14:49 kloczek Exp $
|
||||
*
|
||||
* The login failure file is maintained by login(1) and faillog(8)
|
||||
* Each record in the file represents a separate UID and the file
|
||||
@@ -40,16 +40,16 @@
|
||||
#ifndef _FAILLOG_H
|
||||
#define _FAILLOG_H
|
||||
|
||||
struct faillog {
|
||||
short fail_cnt; /* failures since last success */
|
||||
short fail_max; /* failures before turning account off */
|
||||
char fail_line[12]; /* last failure occured here */
|
||||
time_t fail_time; /* last failure occured then */
|
||||
struct faillog {
|
||||
short fail_cnt; /* failures since last success */
|
||||
short fail_max; /* failures before turning account off */
|
||||
char fail_line[12]; /* last failure occured here */
|
||||
time_t fail_time; /* last failure occured then */
|
||||
/*
|
||||
* If nonzero, the account will be re-enabled if there are no
|
||||
* failures for fail_locktime seconds since last failure.
|
||||
*/
|
||||
long fail_locktime;
|
||||
long fail_locktime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
14
lib/fputsx.c
14
lib/fputsx.c
@@ -33,10 +33,9 @@
|
||||
#include "defines.h"
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: fputsx.c,v 1.5 1999/06/07 16:40:44 marekm Exp $")
|
||||
RCSID ("$Id: fputsx.c,v 1.6 2005/03/31 05:14:49 kloczek Exp $")
|
||||
|
||||
char *
|
||||
fgetsx(char *buf, int cnt, FILE *f)
|
||||
char *fgetsx (char *buf, int cnt, FILE * f)
|
||||
{
|
||||
char *cp = buf;
|
||||
char *ep;
|
||||
@@ -57,17 +56,16 @@ fgetsx(char *buf, int cnt, FILE *f)
|
||||
return buf;
|
||||
}
|
||||
|
||||
int
|
||||
fputsx(const char *s, FILE *stream)
|
||||
int fputsx (const char *s, FILE * stream)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0;*s;i++, s++) {
|
||||
for (i = 0; *s; i++, s++) {
|
||||
if (putc (*s, stream) == EOF)
|
||||
return EOF;
|
||||
|
||||
#if 0 /* The standard getgr*() can't handle that. --marekm */
|
||||
if (i > (BUFSIZ/2)) {
|
||||
#if 0 /* The standard getgr*() can't handle that. --marekm */
|
||||
if (i > (BUFSIZ / 2)) {
|
||||
if (putc ('\\', stream) == EOF ||
|
||||
putc ('\n', stream) == EOF)
|
||||
return EOF;
|
||||
|
282
lib/getdef.c
282
lib/getdef.c
@@ -30,22 +30,19 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: getdef.c,v 1.20 2005/01/20 12:43:05 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: getdef.c,v 1.28 2005/04/01 22:52:03 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "getdef.h"
|
||||
|
||||
/*
|
||||
* A configuration item definition.
|
||||
*/
|
||||
|
||||
struct itemdef {
|
||||
const char *name; /* name of the item */
|
||||
char *value; /* value given, or NULL if no value */
|
||||
const char *name; /* name of the item */
|
||||
char *value; /* value given, or NULL if no value */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -54,85 +51,86 @@ struct itemdef {
|
||||
|
||||
#define NUMDEFS (sizeof(def_table)/sizeof(def_table[0]))
|
||||
static struct itemdef def_table[] = {
|
||||
{ "CHFN_AUTH", NULL },
|
||||
{ "CHFN_RESTRICT", NULL },
|
||||
{"CHFN_RESTRICT", NULL},
|
||||
{"DEFAULT_HOME", NULL},
|
||||
{"FAIL_DELAY", NULL},
|
||||
{"PASS_MAX_DAYS", NULL},
|
||||
{"PASS_MIN_DAYS", NULL},
|
||||
{"PASS_WARN_AGE", NULL},
|
||||
{"USERDEL_CMD", NULL},
|
||||
#ifdef USE_PAM
|
||||
{ "CLOSE_SESSIONS", NULL },
|
||||
{"CLOSE_SESSIONS", NULL},
|
||||
#else
|
||||
{"CHFN_AUTH", NULL},
|
||||
{"CHSH_AUTH", NULL},
|
||||
{"CRACKLIB_DICTPATH", NULL},
|
||||
{"ENV_HZ", NULL},
|
||||
{"ENV_PATH", NULL},
|
||||
{"ENV_ROOTPATH", NULL}, /* SuSE compatibility? */
|
||||
{"ENV_SUPATH", NULL},
|
||||
{"ENV_TZ", NULL},
|
||||
{"ENVIRON_FILE", NULL},
|
||||
{"FAILLOG_ENAB", NULL},
|
||||
{"FTMP_FILE", NULL},
|
||||
{"ISSUE_FILE", NULL},
|
||||
{"LASTLOG_ENAB", NULL},
|
||||
{"LOGIN_STRING", NULL},
|
||||
{"MAIL_CHECK_ENAB", NULL},
|
||||
{"MAIL_DIR", NULL},
|
||||
{"MAIL_FILE", NULL},
|
||||
{"MD5_CRYPT_ENAB", NULL},
|
||||
{"MOTD_FILE", NULL},
|
||||
{"NOLOGINS_FILE", NULL},
|
||||
{"OBSCURE_CHECKS_ENAB", NULL},
|
||||
{"PASS_ALWAYS_WARN", NULL},
|
||||
{"PASS_CHANGE_TRIES", NULL},
|
||||
{"PASS_MAX_LEN", NULL},
|
||||
{"PASS_MIN_LEN", NULL},
|
||||
{"PORTTIME_CHECKS_ENAB", NULL},
|
||||
{"SU_WHEEL_ONLY", NULL},
|
||||
{"QMAIL_DIR", NULL},
|
||||
{"QUOTAS_ENAB", NULL},
|
||||
{"ULIMIT", NULL},
|
||||
#endif
|
||||
{ "CONSOLE", NULL },
|
||||
{ "CONSOLE_GROUPS", NULL },
|
||||
{ "CRACKLIB_DICTPATH", NULL },
|
||||
{ "CREATE_HOME", NULL },
|
||||
{ "DEFAULT_HOME", NULL },
|
||||
{ "ENVIRON_FILE", NULL },
|
||||
{ "ENV_HZ", NULL },
|
||||
{ "ENV_PATH", NULL },
|
||||
{ "ENV_ROOTPATH", NULL }, /* SuSE compatibility? */
|
||||
{ "ENV_SUPATH", NULL },
|
||||
{ "ENV_TZ", NULL },
|
||||
{ "ERASECHAR", NULL },
|
||||
{ "FAILLOG_ENAB", NULL },
|
||||
{ "FAIL_DELAY", NULL },
|
||||
{ "FAKE_SHELL", NULL },
|
||||
{ "FTMP_FILE", NULL },
|
||||
{ "GETPASS_ASTERISKS", NULL },
|
||||
{ "GID_MAX", NULL },
|
||||
{ "GID_MIN", NULL },
|
||||
{ "HUSHLOGIN_FILE", NULL },
|
||||
{ "ISSUE_FILE", NULL },
|
||||
{ "KILLCHAR", NULL },
|
||||
{ "LASTLOG_ENAB", NULL },
|
||||
{ "LOGIN_RETRIES", NULL },
|
||||
{ "LOGIN_STRING", NULL },
|
||||
{ "LOGIN_TIMEOUT", NULL },
|
||||
{ "LOG_OK_LOGINS", NULL },
|
||||
{ "LOG_UNKFAIL_ENAB", NULL },
|
||||
{ "MAIL_CHECK_ENAB", NULL },
|
||||
{ "MAIL_DIR", NULL },
|
||||
{ "MAIL_FILE", NULL },
|
||||
{ "MD5_CRYPT_ENAB", NULL },
|
||||
{ "MOTD_FILE", NULL },
|
||||
{ "NOLOGINS_FILE", NULL },
|
||||
{ "NOLOGIN_STR", NULL },
|
||||
{ "OBSCURE_CHECKS_ENAB", NULL },
|
||||
{ "PASS_ALWAYS_WARN", NULL },
|
||||
{ "PASS_CHANGE_TRIES", NULL },
|
||||
{ "PASS_MAX_DAYS", NULL },
|
||||
{ "PASS_MAX_LEN", NULL },
|
||||
{ "PASS_MIN_DAYS", NULL },
|
||||
{ "PASS_MIN_LEN", NULL },
|
||||
{ "PASS_WARN_AGE", NULL },
|
||||
{ "PORTTIME_CHECKS_ENAB", NULL },
|
||||
{ "QMAIL_DIR", NULL },
|
||||
{ "QUOTAS_ENAB", NULL },
|
||||
{ "SULOG_FILE", NULL },
|
||||
{ "SU_NAME", NULL },
|
||||
{ "SU_WHEEL_ONLY", NULL },
|
||||
{"CONSOLE", NULL},
|
||||
{"CONSOLE_GROUPS", NULL},
|
||||
{"CREATE_HOME", NULL},
|
||||
{"ERASECHAR", NULL},
|
||||
{"FAKE_SHELL", NULL},
|
||||
{"GETPASS_ASTERISKS", NULL},
|
||||
{"GID_MAX", NULL},
|
||||
{"GID_MIN", NULL},
|
||||
{"HUSHLOGIN_FILE", NULL},
|
||||
{"KILLCHAR", NULL},
|
||||
{"LOGIN_RETRIES", NULL},
|
||||
{"LOGIN_TIMEOUT", NULL},
|
||||
{"LOG_OK_LOGINS", NULL},
|
||||
{"LOG_UNKFAIL_ENAB", NULL},
|
||||
{"SULOG_FILE", NULL},
|
||||
{"SU_NAME", NULL},
|
||||
#ifdef USE_SYSLOG
|
||||
{ "SYSLOG_SG_ENAB", NULL },
|
||||
{ "SYSLOG_SU_ENAB", NULL },
|
||||
{"SYSLOG_SG_ENAB", NULL},
|
||||
{"SYSLOG_SU_ENAB", NULL},
|
||||
#endif
|
||||
{ "TTYGROUP", NULL },
|
||||
{ "TTYPERM", NULL },
|
||||
{ "TTYTYPE_FILE", NULL },
|
||||
{ "UID_MAX", NULL },
|
||||
{ "UID_MIN", NULL },
|
||||
{ "ULIMIT", NULL },
|
||||
{ "UMASK", NULL },
|
||||
{ "USERDEL_CMD", NULL },
|
||||
{ "USERGROUPS_ENAB", NULL }
|
||||
{"TTYGROUP", NULL},
|
||||
{"TTYPERM", NULL},
|
||||
{"TTYTYPE_FILE", NULL},
|
||||
{"UID_MAX", NULL},
|
||||
{"UID_MIN", NULL},
|
||||
{"UMASK", NULL},
|
||||
{"USERGROUPS_ENAB", NULL}
|
||||
};
|
||||
|
||||
#ifndef LOGINDEFS
|
||||
#define LOGINDEFS "/etc/login.defs"
|
||||
#endif
|
||||
|
||||
static char def_fname[] = LOGINDEFS; /* login config defs file */
|
||||
static int def_loaded = 0; /* are defs already loaded? */
|
||||
static char def_fname[] = LOGINDEFS; /* login config defs file */
|
||||
static int def_loaded = 0; /* are defs already loaded? */
|
||||
|
||||
/* local function prototypes */
|
||||
static struct itemdef *def_find(const char *);
|
||||
static void def_load(void);
|
||||
static struct itemdef *def_find (const char *);
|
||||
static void def_load (void);
|
||||
|
||||
|
||||
/*
|
||||
@@ -142,15 +140,14 @@ static void def_load(void);
|
||||
* defined. First time invoked, will load definitions from the file.
|
||||
*/
|
||||
|
||||
char *
|
||||
getdef_str(const char *item)
|
||||
char *getdef_str (const char *item)
|
||||
{
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded)
|
||||
def_load();
|
||||
def_load ();
|
||||
|
||||
return ((d = def_find(item)) == NULL ? (char *)NULL : d->value);
|
||||
return ((d = def_find (item)) == NULL ? (char *) NULL : d->value);
|
||||
}
|
||||
|
||||
|
||||
@@ -160,18 +157,17 @@ getdef_str(const char *item)
|
||||
* Return TRUE if specified item is defined as "yes", else FALSE.
|
||||
*/
|
||||
|
||||
int
|
||||
getdef_bool(const char *item)
|
||||
int getdef_bool (const char *item)
|
||||
{
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded)
|
||||
def_load();
|
||||
def_load ();
|
||||
|
||||
if ((d = def_find(item)) == NULL || d->value == NULL)
|
||||
if ((d = def_find (item)) == NULL || d->value == NULL)
|
||||
return 0;
|
||||
|
||||
return (strcasecmp(d->value, "yes") == 0);
|
||||
return (strcasecmp (d->value, "yes") == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,18 +179,17 @@ getdef_bool(const char *item)
|
||||
* values are handled.
|
||||
*/
|
||||
|
||||
int
|
||||
getdef_num(const char *item, int dflt)
|
||||
int getdef_num (const char *item, int dflt)
|
||||
{
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded)
|
||||
def_load();
|
||||
def_load ();
|
||||
|
||||
if ((d = def_find(item)) == NULL || d->value == NULL)
|
||||
if ((d = def_find (item)) == NULL || d->value == NULL)
|
||||
return dflt;
|
||||
|
||||
return (int) strtol(d->value, (char **)NULL, 0);
|
||||
return (int) strtol (d->value, (char **) NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -206,18 +201,17 @@ getdef_num(const char *item, int dflt)
|
||||
* values are handled.
|
||||
*/
|
||||
|
||||
unsigned int
|
||||
getdef_unum(const char *item, unsigned int dflt)
|
||||
unsigned int getdef_unum (const char *item, unsigned int dflt)
|
||||
{
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded)
|
||||
def_load();
|
||||
def_load ();
|
||||
|
||||
if ((d = def_find(item)) == NULL || d->value == NULL)
|
||||
if ((d = def_find (item)) == NULL || d->value == NULL)
|
||||
return dflt;
|
||||
|
||||
return (unsigned int) strtoul(d->value, (char **)NULL, 0);
|
||||
return (unsigned int) strtoul (d->value, (char **) NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -229,18 +223,17 @@ getdef_unum(const char *item, unsigned int dflt)
|
||||
* values are handled.
|
||||
*/
|
||||
|
||||
long
|
||||
getdef_long(const char *item, long dflt)
|
||||
long getdef_long (const char *item, long dflt)
|
||||
{
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded)
|
||||
def_load();
|
||||
def_load ();
|
||||
|
||||
if ((d = def_find(item)) == NULL || d->value == NULL)
|
||||
if ((d = def_find (item)) == NULL || d->value == NULL)
|
||||
return dflt;
|
||||
|
||||
return strtol(d->value, (char **)NULL, 0);
|
||||
return strtol (d->value, (char **) NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,35 +242,33 @@ getdef_long(const char *item, long dflt)
|
||||
* (also used when loading the initial defaults)
|
||||
*/
|
||||
|
||||
int
|
||||
putdef_str(const char *name, const char *value)
|
||||
int putdef_str (const char *name, const char *value)
|
||||
{
|
||||
struct itemdef *d;
|
||||
char *cp;
|
||||
|
||||
if (!def_loaded)
|
||||
def_load();
|
||||
def_load ();
|
||||
|
||||
/*
|
||||
* Locate the slot to save the value. If this parameter
|
||||
* is unknown then "def_find" will print an err message.
|
||||
*/
|
||||
if ((d = def_find(name)) == NULL)
|
||||
if ((d = def_find (name)) == NULL)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* Save off the value.
|
||||
*/
|
||||
if ((cp = strdup(value)) == NULL) {
|
||||
fprintf(stderr,
|
||||
_("Could not allocate space for config info.\n"));
|
||||
SYSLOG((LOG_ERR,
|
||||
"could not allocate space for config info"));
|
||||
if ((cp = strdup (value)) == NULL) {
|
||||
fprintf (stderr,
|
||||
_("Could not allocate space for config info.\n"));
|
||||
SYSLOG ((LOG_ERR, "could not allocate space for config info"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (d->value)
|
||||
free(d->value);
|
||||
free (d->value);
|
||||
|
||||
d->value = cp;
|
||||
return 0;
|
||||
@@ -291,8 +282,7 @@ putdef_str(const char *name, const char *value)
|
||||
* specified configuration option.
|
||||
*/
|
||||
|
||||
static struct itemdef *
|
||||
def_find(const char *name)
|
||||
static struct itemdef *def_find (const char *name)
|
||||
{
|
||||
int min, max, curr, n;
|
||||
|
||||
@@ -301,7 +291,7 @@ def_find(const char *name)
|
||||
*/
|
||||
|
||||
min = 0;
|
||||
max = NUMDEFS-1;
|
||||
max = NUMDEFS - 1;
|
||||
|
||||
/*
|
||||
* Binary search into the table. Relies on the items being
|
||||
@@ -309,23 +299,26 @@ def_find(const char *name)
|
||||
*/
|
||||
|
||||
while (min <= max) {
|
||||
curr = (min+max)/2;
|
||||
curr = (min + max) / 2;
|
||||
|
||||
if (! (n = strcmp(def_table[curr].name, name)))
|
||||
if (!(n = strcmp (def_table[curr].name, name)))
|
||||
return &def_table[curr];
|
||||
|
||||
if (n < 0)
|
||||
min = curr+1;
|
||||
min = curr + 1;
|
||||
else
|
||||
max = curr-1;
|
||||
max = curr - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Item was never found.
|
||||
*/
|
||||
|
||||
fprintf(stderr, _("configuration error - unknown item '%s' (notify administrator)\n"), name);
|
||||
SYSLOG((LOG_CRIT, "unknown configuration item `%s'", name));
|
||||
fprintf (stderr,
|
||||
_
|
||||
("configuration error - unknown item '%s' (notify administrator)\n"),
|
||||
name);
|
||||
SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
|
||||
return (struct itemdef *) NULL;
|
||||
}
|
||||
|
||||
@@ -335,8 +328,7 @@ def_find(const char *name)
|
||||
* Loads the user-configured options from the default configuration file
|
||||
*/
|
||||
|
||||
static void
|
||||
def_load(void)
|
||||
static void def_load (void)
|
||||
{
|
||||
int i;
|
||||
FILE *fp;
|
||||
@@ -345,10 +337,10 @@ def_load(void)
|
||||
/*
|
||||
* Open the configuration definitions file.
|
||||
*/
|
||||
if ((fp = fopen(def_fname, "r")) == NULL) {
|
||||
SYSLOG((LOG_CRIT, "cannot open login definitions %s [%m]",
|
||||
def_fname));
|
||||
exit(1);
|
||||
if ((fp = fopen (def_fname, "r")) == NULL) {
|
||||
SYSLOG ((LOG_CRIT, "cannot open login definitions %s [%m]",
|
||||
def_fname));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -360,13 +352,13 @@ def_load(void)
|
||||
/*
|
||||
* Go through all of the lines in the file.
|
||||
*/
|
||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
||||
|
||||
/*
|
||||
* Trim trailing whitespace.
|
||||
*/
|
||||
for (i = strlen(buf)-1 ; i >= 0 ; --i) {
|
||||
if (!isspace(buf[i]))
|
||||
for (i = strlen (buf) - 1; i >= 0; --i) {
|
||||
if (!isspace (buf[i]))
|
||||
break;
|
||||
}
|
||||
buf[++i] = '\0';
|
||||
@@ -374,37 +366,36 @@ def_load(void)
|
||||
/*
|
||||
* Break the line into two fields.
|
||||
*/
|
||||
name = buf + strspn(buf, " \t"); /* first nonwhite */
|
||||
name = buf + strspn (buf, " \t"); /* first nonwhite */
|
||||
if (*name == '\0' || *name == '#')
|
||||
continue; /* comment or empty */
|
||||
continue; /* comment or empty */
|
||||
|
||||
s = name + strcspn(name, " \t"); /* end of field */
|
||||
s = name + strcspn (name, " \t"); /* end of field */
|
||||
if (*s == '\0')
|
||||
continue; /* only 1 field?? */
|
||||
continue; /* only 1 field?? */
|
||||
|
||||
*s++ = '\0';
|
||||
value = s + strspn(s, " \"\t"); /* next nonwhite */
|
||||
*(value + strcspn(value, "\"")) = '\0';
|
||||
value = s + strspn (s, " \"\t"); /* next nonwhite */
|
||||
*(value + strcspn (value, "\"")) = '\0';
|
||||
|
||||
/*
|
||||
* Store the value in def_table.
|
||||
*/
|
||||
putdef_str(name, value);
|
||||
putdef_str (name, value);
|
||||
}
|
||||
|
||||
if (ferror(fp)) {
|
||||
SYSLOG((LOG_CRIT, "cannot read login definitions %s [%m]",
|
||||
def_fname));
|
||||
exit(1);
|
||||
if (ferror (fp)) {
|
||||
SYSLOG ((LOG_CRIT, "cannot read login definitions %s [%m]",
|
||||
def_fname));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
(void) fclose(fp);
|
||||
(void) fclose (fp);
|
||||
}
|
||||
|
||||
|
||||
#ifdef CKDEFS
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *cp;
|
||||
@@ -412,18 +403,19 @@ main(int argc, char **argv)
|
||||
|
||||
def_load ();
|
||||
|
||||
for (i = 0 ; i < NUMDEFS ; ++i) {
|
||||
if ((d = def_find(def_table[i].name)) == NULL)
|
||||
printf("error - lookup '%s' failed\n", def_table[i].name);
|
||||
for (i = 0; i < NUMDEFS; ++i) {
|
||||
if ((d = def_find (def_table[i].name)) == NULL)
|
||||
printf ("error - lookup '%s' failed\n",
|
||||
def_table[i].name);
|
||||
else
|
||||
printf("%4d %-24s %s\n", i+1, d->name, d->value);
|
||||
printf ("%4d %-24s %s\n", i + 1, d->name, d->value);
|
||||
}
|
||||
for (i = 1;i < argc;i++) {
|
||||
for (i = 1; i < argc; i++) {
|
||||
if ((cp = getdef_str (argv[1])) != NULL)
|
||||
printf ("%s `%s'\n", argv[1], cp);
|
||||
else
|
||||
printf ("%s not found\n", argv[1]);
|
||||
}
|
||||
exit(0);
|
||||
exit (0);
|
||||
}
|
||||
#endif
|
||||
|
14
lib/getdef.h
14
lib/getdef.h
@@ -2,11 +2,11 @@
|
||||
#define _GETDEF_H
|
||||
|
||||
/* getdef.c */
|
||||
extern int getdef_bool(const char *);
|
||||
extern long getdef_long(const char *, long);
|
||||
extern int getdef_num(const char *, int);
|
||||
extern unsigned int getdef_unum(const char *, unsigned int);
|
||||
extern char *getdef_str(const char *);
|
||||
extern int putdef_str(const char *, const char *);
|
||||
extern int getdef_bool (const char *);
|
||||
extern long getdef_long (const char *, long);
|
||||
extern int getdef_num (const char *, int);
|
||||
extern unsigned int getdef_unum (const char *, unsigned int);
|
||||
extern char *getdef_str (const char *);
|
||||
extern int putdef_str (const char *, const char *);
|
||||
|
||||
#endif /* _GETDEF_H */
|
||||
#endif /* _GETDEF_H */
|
||||
|
120
lib/getpass.c
120
lib/getpass.c
@@ -31,44 +31,36 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: getpass.c,v 1.12 2003/05/05 21:44:12 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: getpass.c,v 1.13 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include "defines.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "getdef.h"
|
||||
|
||||
/* new code, #undef if there are any problems... */
|
||||
#define USE_SETJMP 1
|
||||
|
||||
#ifdef USE_SETJMP
|
||||
#include <setjmp.h>
|
||||
|
||||
static sigjmp_buf intr; /* where to jump on SIGINT */
|
||||
static sigjmp_buf intr; /* where to jump on SIGINT */
|
||||
#endif
|
||||
|
||||
static int sig_caught;
|
||||
static int sig_caught;
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
static struct sigaction sigact;
|
||||
static struct sigaction sigact;
|
||||
#endif
|
||||
|
||||
/*ARGSUSED*/
|
||||
static RETSIGTYPE
|
||||
sig_catch(int sig)
|
||||
/*ARGSUSED*/ static RETSIGTYPE sig_catch (int sig)
|
||||
{
|
||||
sig_caught = 1;
|
||||
#ifdef USE_SETJMP
|
||||
siglongjmp(intr, 1);
|
||||
siglongjmp (intr, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define MAXLEN 127
|
||||
|
||||
|
||||
static char *
|
||||
readpass(FILE *ifp, FILE *ofp, int with_echo, int max_asterisks)
|
||||
static char *readpass (FILE * ifp, FILE * ofp, int with_echo, int max_asterisks)
|
||||
{
|
||||
static char input[MAXLEN + 1], asterix[MAXLEN + 1];
|
||||
static char once;
|
||||
@@ -77,9 +69,9 @@ readpass(FILE *ifp, FILE *ofp, int with_echo, int max_asterisks)
|
||||
|
||||
if (max_asterisks < 0) {
|
||||
/* traditional code using fgets() */
|
||||
if (fgets(input, sizeof input, ifp) != input)
|
||||
if (fgets (input, sizeof input, ifp) != input)
|
||||
return NULL;
|
||||
cp = strrchr(input, '\n');
|
||||
cp = strrchr (input, '\n');
|
||||
if (cp)
|
||||
*cp = '\0';
|
||||
else
|
||||
@@ -87,12 +79,12 @@ readpass(FILE *ifp, FILE *ofp, int with_echo, int max_asterisks)
|
||||
return input;
|
||||
}
|
||||
if (!once) {
|
||||
srandom(time(0)*getpid());
|
||||
srandom (time (0) * getpid ());
|
||||
once = 1;
|
||||
}
|
||||
cp = input;
|
||||
ap = asterix;
|
||||
while (read(fileno(ifp), &c, 1)) {
|
||||
while (read (fileno (ifp), &c, 1)) {
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
@@ -103,67 +95,68 @@ readpass(FILE *ifp, FILE *ofp, int with_echo, int max_asterisks)
|
||||
cp--;
|
||||
ap--;
|
||||
for (i = *ap; i > 0; i--)
|
||||
fputs("\b \b", ofp);
|
||||
fputs ("\b \b", ofp);
|
||||
*cp = '\0';
|
||||
*ap = 0;
|
||||
} else {
|
||||
putc('\a', ofp); /* BEL */
|
||||
putc ('\a', ofp); /* BEL */
|
||||
}
|
||||
break;
|
||||
case '\025': /* Ctrl-U = erase everything typed so far */
|
||||
case '\025': /* Ctrl-U = erase everything typed so far */
|
||||
if (cp == input) {
|
||||
putc('\a', ofp); /* BEL */
|
||||
} else while (cp > input) {
|
||||
cp--;
|
||||
ap--;
|
||||
for (i = *ap; i > 0; i--)
|
||||
fputs("\b \b", ofp);
|
||||
*cp = '\0';
|
||||
*ap = 0;
|
||||
}
|
||||
putc ('\a', ofp); /* BEL */
|
||||
} else
|
||||
while (cp > input) {
|
||||
cp--;
|
||||
ap--;
|
||||
for (i = *ap; i > 0; i--)
|
||||
fputs ("\b \b", ofp);
|
||||
*cp = '\0';
|
||||
*ap = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
*cp++ = c;
|
||||
if (with_echo) {
|
||||
*ap = 1;
|
||||
putc(c, ofp);
|
||||
putc (c, ofp);
|
||||
} else if (max_asterisks > 0) {
|
||||
*ap = (random() % max_asterisks) + 1;
|
||||
*ap = (random () % max_asterisks) + 1;
|
||||
for (i = *ap; i > 0; i--)
|
||||
putc('*', ofp);
|
||||
putc ('*', ofp);
|
||||
} else {
|
||||
*ap = 0;
|
||||
}
|
||||
ap++;
|
||||
break;
|
||||
}
|
||||
fflush(ofp);
|
||||
fflush (ofp);
|
||||
if (cp >= input + MAXLEN) {
|
||||
putc('\a', ofp); /* BEL */
|
||||
putc ('\a', ofp); /* BEL */
|
||||
break;
|
||||
}
|
||||
}
|
||||
endwhile:
|
||||
endwhile:
|
||||
*cp = '\0';
|
||||
putc('\n', ofp);
|
||||
putc ('\n', ofp);
|
||||
return input;
|
||||
}
|
||||
|
||||
static char *
|
||||
prompt_password(const char *prompt, int with_echo)
|
||||
static char *prompt_password (const char *prompt, int with_echo)
|
||||
{
|
||||
static char nostring[1] = "";
|
||||
static char *return_value;
|
||||
volatile int tty_opened;
|
||||
static FILE *ifp, *ofp;
|
||||
volatile int is_tty;
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction old_sigact;
|
||||
#else
|
||||
RETSIGTYPE (*old_signal)();
|
||||
RETSIGTYPE (*old_signal) ();
|
||||
#endif
|
||||
TERMIO old_modes;
|
||||
int max_asterisks = getdef_num("GETPASS_ASTERISKS", -1);
|
||||
int max_asterisks = getdef_num ("GETPASS_ASTERISKS", -1);
|
||||
|
||||
/*
|
||||
* set a flag so the SIGINT signal can be re-sent if it
|
||||
@@ -179,14 +172,14 @@ prompt_password(const char *prompt, int with_echo)
|
||||
* from stdin and write to stderr instead.
|
||||
*/
|
||||
|
||||
if (!(ifp = fopen("/dev/tty", "r+"))) {
|
||||
if (!(ifp = fopen ("/dev/tty", "r+"))) {
|
||||
ifp = stdin;
|
||||
ofp = stderr;
|
||||
} else {
|
||||
ofp = ifp;
|
||||
tty_opened = 1;
|
||||
}
|
||||
setbuf(ifp, (char *) 0);
|
||||
setbuf (ifp, (char *) 0);
|
||||
|
||||
/*
|
||||
* the current tty modes must be saved so they can be
|
||||
@@ -195,26 +188,25 @@ prompt_password(const char *prompt, int with_echo)
|
||||
*/
|
||||
|
||||
is_tty = 1;
|
||||
if (GTTY(fileno(ifp), &old_modes)) {
|
||||
if (GTTY (fileno (ifp), &old_modes)) {
|
||||
is_tty = 0;
|
||||
}
|
||||
|
||||
#ifdef USE_SETJMP
|
||||
/*
|
||||
* If we get a SIGINT, sig_catch() will jump here -
|
||||
* no need to press Enter after Ctrl-C.
|
||||
*/
|
||||
if (sigsetjmp(intr, 1))
|
||||
if (sigsetjmp (intr, 1))
|
||||
goto out;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigact.sa_handler = sig_catch;
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigemptyset (&sigact.sa_mask);
|
||||
sigact.sa_flags = 0;
|
||||
sigaction(SIGINT, &sigact, &old_sigact);
|
||||
sigaction (SIGINT, &sigact, &old_sigact);
|
||||
#else
|
||||
old_signal = signal(SIGINT, sig_catch);
|
||||
old_signal = signal (SIGINT, sig_catch);
|
||||
#endif
|
||||
|
||||
if (is_tty) {
|
||||
@@ -232,7 +224,7 @@ prompt_password(const char *prompt, int with_echo)
|
||||
|
||||
new_modes.c_lflag |= ECHONL;
|
||||
|
||||
if (STTY(fileno(ifp), &new_modes))
|
||||
if (STTY (fileno (ifp), &new_modes))
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -243,9 +235,9 @@ prompt_password(const char *prompt, int with_echo)
|
||||
* returned.
|
||||
*/
|
||||
|
||||
if ((fputs(prompt, ofp) != EOF) && (fflush(ofp) != EOF))
|
||||
return_value = readpass(ifp, ofp, with_echo, max_asterisks);
|
||||
out:
|
||||
if ((fputs (prompt, ofp) != EOF) && (fflush (ofp) != EOF))
|
||||
return_value = readpass (ifp, ofp, with_echo, max_asterisks);
|
||||
out:
|
||||
/*
|
||||
* the old SIGINT handler is restored after the tty
|
||||
* modes. then /dev/tty is closed if it was opened in
|
||||
@@ -254,20 +246,19 @@ out:
|
||||
*/
|
||||
|
||||
if (is_tty) {
|
||||
if (STTY(fileno(ifp), &old_modes))
|
||||
if (STTY (fileno (ifp), &old_modes))
|
||||
return_value = NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
(void) sigaction (SIGINT, &old_sigact, NULL);
|
||||
#else
|
||||
(void) signal (SIGINT, old_signal);
|
||||
#endif
|
||||
if (tty_opened)
|
||||
(void) fclose(ifp);
|
||||
(void) fclose (ifp);
|
||||
|
||||
if (sig_caught) {
|
||||
kill(getpid(), SIGINT);
|
||||
kill (getpid (), SIGINT);
|
||||
return_value = NULL;
|
||||
}
|
||||
if (!return_value) {
|
||||
@@ -277,15 +268,12 @@ out:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
char *
|
||||
libshadow_getpass(const char *prompt)
|
||||
char *libshadow_getpass (const char *prompt)
|
||||
{
|
||||
return prompt_password(prompt, 0);
|
||||
return prompt_password (prompt, 0);
|
||||
}
|
||||
|
||||
char *
|
||||
getpass_with_echo(const char *prompt)
|
||||
char *getpass_with_echo (const char *prompt)
|
||||
{
|
||||
return prompt_password(prompt, 1);
|
||||
return prompt_password (prompt, 1);
|
||||
}
|
||||
|
||||
|
211
lib/grdbm.c
211
lib/grdbm.c
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright 1990 - 1994, Julianne Frances Haugh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef NDBM
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: grdbm.c,v 1.3 1997/12/07 23:26:52 marekm Exp $")
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include "prototypes.h"
|
||||
|
||||
#include <ndbm.h>
|
||||
extern DBM *gr_dbm;
|
||||
|
||||
#define GRP_FRAG 256
|
||||
|
||||
/*
|
||||
* gr_dbm_update
|
||||
*
|
||||
* Updates the DBM password files, if they exist.
|
||||
*/
|
||||
|
||||
int
|
||||
gr_dbm_update(const struct group *gr)
|
||||
{
|
||||
datum key;
|
||||
datum content;
|
||||
char data[BUFSIZ*8];
|
||||
char grpkey[60];
|
||||
char *cp;
|
||||
int len;
|
||||
int i;
|
||||
int cnt;
|
||||
static int once;
|
||||
|
||||
if (! once) {
|
||||
if (! gr_dbm)
|
||||
setgrent ();
|
||||
|
||||
once++;
|
||||
}
|
||||
if (! gr_dbm)
|
||||
return 0;
|
||||
|
||||
len = gr_pack (gr, data);
|
||||
|
||||
if (len <= GRP_FRAG) {
|
||||
content.dsize = len;
|
||||
content.dptr = data;
|
||||
|
||||
key.dsize = strlen (gr->gr_name);
|
||||
key.dptr = gr->gr_name;
|
||||
if (dbm_store (gr_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
key.dsize = sizeof gr->gr_gid;
|
||||
key.dptr = (char *) &gr->gr_gid;
|
||||
if (dbm_store (gr_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
content.dsize = sizeof cnt;
|
||||
content.dptr = (char *) &cnt;
|
||||
cnt = (len + (GRP_FRAG-1)) / GRP_FRAG;
|
||||
|
||||
key.dsize = strlen (gr->gr_name);
|
||||
key.dptr = gr->gr_name;
|
||||
if (dbm_store (gr_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
key.dsize = sizeof gr->gr_gid;
|
||||
key.dptr = (char *) &gr->gr_gid;
|
||||
if (dbm_store (gr_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
for (cp = data, i = 0;i < cnt;i++) {
|
||||
content.dsize = len > GRP_FRAG ? GRP_FRAG:len;
|
||||
len -= content.dsize;
|
||||
content.dptr = cp;
|
||||
cp += content.dsize;
|
||||
|
||||
key.dsize = sizeof i + strlen (gr->gr_name);
|
||||
key.dptr = grpkey;
|
||||
memcpy (grpkey, (char *) &i, sizeof i);
|
||||
strcpy (grpkey + sizeof i, gr->gr_name);
|
||||
if (dbm_store (gr_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
key.dsize = sizeof i + sizeof gr->gr_gid;
|
||||
key.dptr = grpkey;
|
||||
memcpy (grpkey, (char *) &i, sizeof i);
|
||||
memcpy (grpkey + sizeof i, (char *) &gr->gr_gid,
|
||||
sizeof gr->gr_gid);
|
||||
if (dbm_store (gr_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* gr_dbm_remove
|
||||
*
|
||||
* Deletes the DBM group file entries, if they exist.
|
||||
*/
|
||||
|
||||
int
|
||||
gr_dbm_remove(const struct group *gr)
|
||||
{
|
||||
datum key;
|
||||
datum content;
|
||||
char grpkey[60];
|
||||
int i;
|
||||
int cnt;
|
||||
int errors = 0;
|
||||
static int once;
|
||||
|
||||
if (! once) {
|
||||
if (! gr_dbm)
|
||||
setgrent ();
|
||||
|
||||
once++;
|
||||
}
|
||||
if (! gr_dbm)
|
||||
return 0;
|
||||
|
||||
key.dsize = strlen (gr->gr_name);
|
||||
key.dptr = (char *) gr->gr_name;
|
||||
content = dbm_fetch (gr_dbm, key);
|
||||
if (content.dptr == 0)
|
||||
++errors;
|
||||
else {
|
||||
if (content.dsize == sizeof (int)) {
|
||||
memcpy ((char *) &cnt, content.dptr, sizeof cnt);
|
||||
|
||||
for (i = 0;i < cnt;i++) {
|
||||
key.dsize = sizeof i + strlen (gr->gr_name);
|
||||
key.dptr = grpkey;
|
||||
memcpy (grpkey, (char *) &i, sizeof i);
|
||||
strcpy (grpkey + sizeof i, gr->gr_name);
|
||||
if (dbm_delete (gr_dbm, key))
|
||||
++errors;
|
||||
}
|
||||
} else {
|
||||
if (dbm_delete (gr_dbm, key))
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
key.dsize = sizeof gr->gr_gid;
|
||||
key.dptr = (char *) &gr->gr_gid;
|
||||
content = dbm_fetch (gr_dbm, key);
|
||||
if (content.dptr == 0)
|
||||
++errors;
|
||||
else {
|
||||
if (content.dsize == sizeof (int)) {
|
||||
memcpy ((char *) &cnt, content.dptr, sizeof cnt);
|
||||
|
||||
for (i = 0;i < cnt;i++) {
|
||||
key.dsize = sizeof i + sizeof gr->gr_gid;
|
||||
key.dptr = grpkey;
|
||||
memcpy (grpkey, (char *) &i, sizeof i);
|
||||
memcpy (grpkey + sizeof i, (char *) &gr->gr_gid,
|
||||
sizeof gr->gr_gid);
|
||||
|
||||
if (dbm_delete (gr_dbm, key))
|
||||
++errors;
|
||||
}
|
||||
} else {
|
||||
if (dbm_delete (gr_dbm, key))
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
return errors ? 0:1;
|
||||
}
|
||||
|
||||
int
|
||||
gr_dbm_present(void)
|
||||
{
|
||||
return (access(GROUP_PAG_FILE, F_OK) == 0);
|
||||
}
|
||||
#endif
|
161
lib/groupio.c
161
lib/groupio.c
@@ -2,38 +2,33 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: groupio.c,v 1.10 2001/08/14 21:10:36 malekith Exp $")
|
||||
|
||||
RCSID ("$Id: groupio.c,v 1.11 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include "commonio.h"
|
||||
#include "groupio.h"
|
||||
extern int putgrent (const struct group *, FILE *);
|
||||
extern struct group *sgetgrent (const char *);
|
||||
|
||||
extern int putgrent(const struct group *, FILE *);
|
||||
extern struct group *sgetgrent(const char *);
|
||||
|
||||
struct group *
|
||||
__gr_dup(const struct group *grent)
|
||||
struct group *__gr_dup (const struct group *grent)
|
||||
{
|
||||
struct group *gr;
|
||||
int i;
|
||||
|
||||
if (!(gr = (struct group *) malloc(sizeof *gr)))
|
||||
if (!(gr = (struct group *) malloc (sizeof *gr)))
|
||||
return NULL;
|
||||
*gr = *grent;
|
||||
if (!(gr->gr_name = strdup(grent->gr_name)))
|
||||
if (!(gr->gr_name = strdup (grent->gr_name)))
|
||||
return NULL;
|
||||
if (!(gr->gr_passwd = strdup(grent->gr_passwd)))
|
||||
if (!(gr->gr_passwd = strdup (grent->gr_passwd)))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; grent->gr_mem[i]; i++)
|
||||
;
|
||||
gr->gr_mem = (char **) malloc((i + 1) * sizeof(char *));
|
||||
for (i = 0; grent->gr_mem[i]; i++);
|
||||
gr->gr_mem = (char **) malloc ((i + 1) * sizeof (char *));
|
||||
if (!gr->gr_mem)
|
||||
return NULL;
|
||||
for (i = 0; grent->gr_mem[i]; i++) {
|
||||
gr->gr_mem[i] = strdup(grent->gr_mem[i]);
|
||||
gr->gr_mem[i] = strdup (grent->gr_mem[i]);
|
||||
if (!gr->gr_mem[i])
|
||||
return NULL;
|
||||
}
|
||||
@@ -41,45 +36,43 @@ __gr_dup(const struct group *grent)
|
||||
return gr;
|
||||
}
|
||||
|
||||
static void *
|
||||
group_dup(const void *ent)
|
||||
static void *group_dup (const void *ent)
|
||||
{
|
||||
const struct group *gr = ent;
|
||||
return __gr_dup(gr);
|
||||
|
||||
return __gr_dup (gr);
|
||||
}
|
||||
|
||||
static void
|
||||
group_free(void *ent)
|
||||
static void group_free (void *ent)
|
||||
{
|
||||
struct group *gr = ent;
|
||||
|
||||
free(gr->gr_name);
|
||||
free(gr->gr_passwd);
|
||||
while(*(gr->gr_mem)) {
|
||||
free(*(gr->gr_mem));
|
||||
free (gr->gr_name);
|
||||
free (gr->gr_passwd);
|
||||
while (*(gr->gr_mem)) {
|
||||
free (*(gr->gr_mem));
|
||||
gr->gr_mem++;
|
||||
}
|
||||
free(gr);
|
||||
free (gr);
|
||||
}
|
||||
|
||||
static const char *
|
||||
group_getname(const void *ent)
|
||||
static const char *group_getname (const void *ent)
|
||||
{
|
||||
const struct group *gr = ent;
|
||||
|
||||
return gr->gr_name;
|
||||
}
|
||||
|
||||
static void *
|
||||
group_parse(const char *line)
|
||||
static void *group_parse (const char *line)
|
||||
{
|
||||
return (void *) sgetgrent(line);
|
||||
return (void *) sgetgrent (line);
|
||||
}
|
||||
|
||||
static int
|
||||
group_put(const void *ent, FILE *file)
|
||||
static int group_put (const void *ent, FILE * file)
|
||||
{
|
||||
const struct group *gr = ent;
|
||||
return (putgrent(gr, file) == -1) ? -1 : 0;
|
||||
|
||||
return (putgrent (gr, file) == -1) ? -1 : 0;
|
||||
}
|
||||
|
||||
static struct commonio_ops group_ops = {
|
||||
@@ -93,114 +86,99 @@ static struct commonio_ops group_ops = {
|
||||
};
|
||||
|
||||
static struct commonio_db group_db = {
|
||||
GROUP_FILE, /* filename */
|
||||
&group_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
GROUP_FILE, /* filename */
|
||||
&group_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
};
|
||||
|
||||
int
|
||||
gr_name(const char *filename)
|
||||
int gr_name (const char *filename)
|
||||
{
|
||||
return commonio_setname(&group_db, filename);
|
||||
return commonio_setname (&group_db, filename);
|
||||
}
|
||||
|
||||
int
|
||||
gr_lock(void)
|
||||
int gr_lock (void)
|
||||
{
|
||||
return commonio_lock(&group_db);
|
||||
return commonio_lock (&group_db);
|
||||
}
|
||||
|
||||
int
|
||||
gr_open(int mode)
|
||||
int gr_open (int mode)
|
||||
{
|
||||
return commonio_open(&group_db, mode);
|
||||
return commonio_open (&group_db, mode);
|
||||
}
|
||||
|
||||
const struct group *
|
||||
gr_locate(const char *name)
|
||||
const struct group *gr_locate (const char *name)
|
||||
{
|
||||
return commonio_locate(&group_db, name);
|
||||
return commonio_locate (&group_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
gr_update(const struct group *gr)
|
||||
int gr_update (const struct group *gr)
|
||||
{
|
||||
return commonio_update(&group_db, (const void *) gr);
|
||||
return commonio_update (&group_db, (const void *) gr);
|
||||
}
|
||||
|
||||
int
|
||||
gr_remove(const char *name)
|
||||
int gr_remove (const char *name)
|
||||
{
|
||||
return commonio_remove(&group_db, name);
|
||||
return commonio_remove (&group_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
gr_rewind(void)
|
||||
int gr_rewind (void)
|
||||
{
|
||||
return commonio_rewind(&group_db);
|
||||
return commonio_rewind (&group_db);
|
||||
}
|
||||
|
||||
const struct group *
|
||||
gr_next(void)
|
||||
const struct group *gr_next (void)
|
||||
{
|
||||
return commonio_next(&group_db);
|
||||
return commonio_next (&group_db);
|
||||
}
|
||||
|
||||
int
|
||||
gr_close(void)
|
||||
int gr_close (void)
|
||||
{
|
||||
return commonio_close(&group_db);
|
||||
return commonio_close (&group_db);
|
||||
}
|
||||
|
||||
int
|
||||
gr_unlock(void)
|
||||
int gr_unlock (void)
|
||||
{
|
||||
return commonio_unlock(&group_db);
|
||||
return commonio_unlock (&group_db);
|
||||
}
|
||||
|
||||
void
|
||||
__gr_set_changed(void)
|
||||
void __gr_set_changed (void)
|
||||
{
|
||||
group_db.changed = 1;
|
||||
}
|
||||
|
||||
struct commonio_entry *
|
||||
__gr_get_head(void)
|
||||
struct commonio_entry *__gr_get_head (void)
|
||||
{
|
||||
return group_db.head;
|
||||
}
|
||||
|
||||
struct commonio_db *
|
||||
__gr_get_db(void)
|
||||
struct commonio_db *__gr_get_db (void)
|
||||
{
|
||||
return &group_db;
|
||||
}
|
||||
|
||||
void
|
||||
__gr_del_entry(const struct commonio_entry *ent)
|
||||
void __gr_del_entry (const struct commonio_entry *ent)
|
||||
{
|
||||
commonio_del_entry(&group_db, ent);
|
||||
commonio_del_entry (&group_db, ent);
|
||||
}
|
||||
|
||||
static int
|
||||
gr_cmp(const void *p1, const void *p2)
|
||||
static int gr_cmp (const void *p1, const void *p2)
|
||||
{
|
||||
gid_t u1, u2;
|
||||
|
||||
if ((*(struct commonio_entry**)p1)->eptr == NULL)
|
||||
if ((*(struct commonio_entry **) p1)->eptr == NULL)
|
||||
return 1;
|
||||
if ((*(struct commonio_entry**)p2)->eptr == NULL)
|
||||
if ((*(struct commonio_entry **) p2)->eptr == NULL)
|
||||
return -1;
|
||||
|
||||
u1 = ((struct group *)(*(struct commonio_entry**)p1)->eptr)->gr_gid;
|
||||
u2 = ((struct group *)(*(struct commonio_entry**)p2)->eptr)->gr_gid;
|
||||
|
||||
u1 = ((struct group *) (*(struct commonio_entry **) p1)->eptr)->gr_gid;
|
||||
u2 = ((struct group *) (*(struct commonio_entry **) p2)->eptr)->gr_gid;
|
||||
|
||||
if (u1 < u2)
|
||||
return -1;
|
||||
@@ -211,8 +189,7 @@ gr_cmp(const void *p1, const void *p2)
|
||||
}
|
||||
|
||||
/* Sort entries by gid */
|
||||
int
|
||||
gr_sort()
|
||||
int gr_sort ()
|
||||
{
|
||||
return commonio_sort(&group_db, gr_cmp);
|
||||
return commonio_sort (&group_db, gr_cmp);
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
extern struct group *__gr_dup(const struct group *);
|
||||
extern void __gr_set_changed(void);
|
||||
extern int gr_close(void);
|
||||
extern const struct group *gr_locate(const char *);
|
||||
extern int gr_lock(void);
|
||||
extern int gr_name(const char *);
|
||||
extern const struct group *gr_next(void);
|
||||
extern int gr_open(int);
|
||||
extern int gr_remove(const char *);
|
||||
extern int gr_rewind(void);
|
||||
extern int gr_unlock(void);
|
||||
extern int gr_update(const struct group *);
|
||||
extern int gr_sort(void);
|
||||
extern struct group *__gr_dup (const struct group *);
|
||||
extern void __gr_set_changed (void);
|
||||
extern int gr_close (void);
|
||||
extern const struct group *gr_locate (const char *);
|
||||
extern int gr_lock (void);
|
||||
extern int gr_name (const char *);
|
||||
extern const struct group *gr_next (void);
|
||||
extern int gr_open (int);
|
||||
extern int gr_remove (const char *);
|
||||
extern int gr_rewind (void);
|
||||
extern int gr_unlock (void);
|
||||
extern int gr_update (const struct group *);
|
||||
extern int gr_sort (void);
|
||||
|
23
lib/grpack.c
23
lib/grpack.c
@@ -30,18 +30,14 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: grpack.c,v 1.3 1997/12/07 23:26:52 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: grpack.c,v 1.4 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
int
|
||||
gr_pack(const struct group *group, char *buf)
|
||||
int gr_pack (const struct group *group, char *buf)
|
||||
{
|
||||
char *cp;
|
||||
int i;
|
||||
char *cp;
|
||||
int i;
|
||||
|
||||
cp = buf;
|
||||
strcpy (cp, group->gr_name);
|
||||
@@ -53,7 +49,7 @@ gr_pack(const struct group *group, char *buf)
|
||||
memcpy (cp, (const char *) &group->gr_gid, sizeof group->gr_gid);
|
||||
cp += sizeof group->gr_gid;
|
||||
|
||||
for (i = 0;group->gr_mem[i];i++) {
|
||||
for (i = 0; group->gr_mem[i]; i++) {
|
||||
strcpy (cp, group->gr_mem[i]);
|
||||
cp += strlen (cp) + 1;
|
||||
}
|
||||
@@ -62,11 +58,10 @@ gr_pack(const struct group *group, char *buf)
|
||||
return cp - buf;
|
||||
}
|
||||
|
||||
int
|
||||
gr_unpack(char *buf, int len, struct group *group)
|
||||
int gr_unpack (char *buf, int len, struct group *group)
|
||||
{
|
||||
char *org = buf;
|
||||
int i;
|
||||
char *org = buf;
|
||||
int i;
|
||||
|
||||
group->gr_name = buf;
|
||||
buf += strlen (buf) + 1;
|
||||
@@ -83,7 +78,7 @@ gr_unpack(char *buf, int len, struct group *group)
|
||||
if (buf - org > len)
|
||||
return -1;
|
||||
|
||||
for (i = 0;*buf && i < 1024;i++) {
|
||||
for (i = 0; *buf && i < 1024; i++) {
|
||||
group->gr_mem[i] = buf;
|
||||
buf += strlen (buf) + 1;
|
||||
|
||||
|
167
lib/gsdbm.c
167
lib/gsdbm.c
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* Copyright 1990 - 1994, Julianne Frances Haugh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined(NDBM) && defined(SHADOWGRP) /*{*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "prototypes.h"
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: gsdbm.c,v 1.3 1997/12/07 23:26:53 marekm Exp $")
|
||||
|
||||
#include <ndbm.h>
|
||||
extern DBM *sg_dbm;
|
||||
|
||||
#define GRP_FRAG 256
|
||||
|
||||
/*
|
||||
* sg_dbm_update
|
||||
*
|
||||
* Updates the DBM password files, if they exist.
|
||||
*/
|
||||
|
||||
int
|
||||
sg_dbm_update(const struct sgrp *sgr)
|
||||
{
|
||||
datum key;
|
||||
datum content;
|
||||
char data[BUFSIZ*8];
|
||||
char sgrpkey[60];
|
||||
char *cp;
|
||||
int len;
|
||||
int i;
|
||||
int cnt;
|
||||
static int once;
|
||||
|
||||
if (! once) {
|
||||
if (! sg_dbm)
|
||||
setsgent ();
|
||||
|
||||
once++;
|
||||
}
|
||||
if (! sg_dbm)
|
||||
return 0;
|
||||
|
||||
len = sgr_pack (sgr, data);
|
||||
|
||||
if (len <= GRP_FRAG) {
|
||||
content.dsize = len;
|
||||
content.dptr = data;
|
||||
|
||||
key.dsize = strlen (sgr->sg_name);
|
||||
key.dptr = sgr->sg_name;
|
||||
if (dbm_store (sg_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
} else {
|
||||
content.dsize = sizeof cnt;
|
||||
content.dptr = (char *) &cnt;
|
||||
cnt = (len + (GRP_FRAG-1)) / GRP_FRAG;
|
||||
|
||||
key.dsize = strlen (sgr->sg_name);
|
||||
key.dptr = sgr->sg_name;
|
||||
if (dbm_store (sg_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
for (cp = data, i = 0;i < cnt;i++) {
|
||||
content.dsize = len > GRP_FRAG ? GRP_FRAG:len;
|
||||
len -= content.dsize;
|
||||
content.dptr = cp;
|
||||
cp += content.dsize;
|
||||
|
||||
key.dsize = sizeof i + strlen (sgr->sg_name);
|
||||
key.dptr = sgrpkey;
|
||||
memcpy (sgrpkey, (char *) &i, sizeof i);
|
||||
strcpy (sgrpkey + sizeof i, sgr->sg_name);
|
||||
if (dbm_store (sg_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* sg_dbm_remove
|
||||
*
|
||||
* Deletes the DBM shadow group file entries, if they exist.
|
||||
*/
|
||||
|
||||
int
|
||||
sg_dbm_remove(const char *name)
|
||||
{
|
||||
datum key;
|
||||
datum content;
|
||||
char grpkey[60];
|
||||
int i;
|
||||
int cnt;
|
||||
int errors = 0;
|
||||
static int once;
|
||||
|
||||
if (! once) {
|
||||
if (! sg_dbm)
|
||||
setsgent ();
|
||||
|
||||
once++;
|
||||
}
|
||||
if (! sg_dbm)
|
||||
return 0;
|
||||
|
||||
key.dsize = strlen (name);
|
||||
key.dptr = name;
|
||||
content = dbm_fetch (sg_dbm, key);
|
||||
if (content.dptr == 0)
|
||||
++errors;
|
||||
else {
|
||||
if (content.dsize == sizeof (int)) {
|
||||
memcpy ((char *) &cnt, content.dptr, sizeof cnt);
|
||||
|
||||
for (i = 0;i < cnt;i++) {
|
||||
key.dsize = sizeof i + strlen (name);
|
||||
key.dptr = grpkey;
|
||||
memcpy (grpkey, (char *) &i, sizeof i);
|
||||
strcpy (grpkey + sizeof i, name);
|
||||
if (dbm_delete (sg_dbm, key))
|
||||
++errors;
|
||||
}
|
||||
} else {
|
||||
if (dbm_delete (sg_dbm, key))
|
||||
++errors;
|
||||
}
|
||||
}
|
||||
return errors ? 0:1;
|
||||
}
|
||||
|
||||
int
|
||||
sg_dbm_present(void)
|
||||
{
|
||||
return (access(SGROUP_PAG_FILE, F_OK) == 0);
|
||||
}
|
||||
#endif /*} SHADOWGRP && NDBM */
|
261
lib/gshadow.c
261
lib/gshadow.c
@@ -30,47 +30,38 @@
|
||||
#include <config.h>
|
||||
|
||||
/* Newer versions of Linux libc already have shadow support. */
|
||||
#if defined(SHADOWGRP) && !defined(HAVE_SHADOWGRP) /*{*/
|
||||
#if defined(SHADOWGRP) && !defined(HAVE_SHADOWGRP) /*{ */
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: gshadow.c,v 1.6 1998/04/02 21:51:43 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: gshadow.c,v 1.9 2005/04/06 04:26:05 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#ifdef NDBM
|
||||
#include <ndbm.h>
|
||||
#include <fcntl.h>
|
||||
DBM *sg_dbm;
|
||||
int sg_dbm_mode = -1;
|
||||
static int dbmopened;
|
||||
static int dbmerror;
|
||||
#endif
|
||||
static FILE *shadow;
|
||||
static char sgrbuf[BUFSIZ * 4];
|
||||
static char **members = NULL;
|
||||
static size_t nmembers = 0;
|
||||
static char **admins = NULL;
|
||||
static size_t nadmins = 0;
|
||||
static struct sgrp sgroup;
|
||||
|
||||
#define MAXMEM 1024
|
||||
|
||||
static FILE *shadow;
|
||||
static char sgrbuf[BUFSIZ*4];
|
||||
static char *members[MAXMEM+1];
|
||||
static char *admins[MAXMEM+1];
|
||||
static struct sgrp sgroup;
|
||||
|
||||
extern char *fgetsx();
|
||||
extern int fputsx();
|
||||
extern char *fgetsx ();
|
||||
extern int fputsx ();
|
||||
|
||||
#define FIELDS 4
|
||||
|
||||
#ifdef USE_NIS
|
||||
static int nis_used;
|
||||
static int nis_ignore;
|
||||
static enum { native, start, middle, native2 } nis_state;
|
||||
static int nis_bound;
|
||||
static char *nis_domain;
|
||||
static char *nis_key;
|
||||
static int nis_keylen;
|
||||
static char *nis_val;
|
||||
static int nis_vallen;
|
||||
static int nis_used;
|
||||
static int nis_ignore;
|
||||
static enum { native, start, middle, native2 } nis_state;
|
||||
static int nis_bound;
|
||||
static char *nis_domain;
|
||||
static char *nis_key;
|
||||
static int nis_keylen;
|
||||
static char *nis_val;
|
||||
static int nis_vallen;
|
||||
|
||||
#define IS_NISCHAR(c) ((c)=='+')
|
||||
#endif
|
||||
|
||||
@@ -80,10 +71,9 @@ static int nis_vallen;
|
||||
* __setsgNIS - turn on or off NIS searches
|
||||
*/
|
||||
|
||||
void
|
||||
__setsgNIS(int flag)
|
||||
void __setsgNIS (int flag)
|
||||
{
|
||||
nis_ignore = ! flag;
|
||||
nis_ignore = !flag;
|
||||
|
||||
if (nis_ignore)
|
||||
nis_used = 0;
|
||||
@@ -93,8 +83,7 @@ __setsgNIS(int flag)
|
||||
* bind_nis - bind to NIS server
|
||||
*/
|
||||
|
||||
static int
|
||||
bind_nis(void)
|
||||
static int bind_nis (void)
|
||||
{
|
||||
if (yp_get_default_domain (&nis_domain))
|
||||
return -1;
|
||||
@@ -104,82 +93,53 @@ bind_nis(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static char **
|
||||
list(char *s, char **l)
|
||||
static char **list (char *s, char **list[], size_t * nlist)
|
||||
{
|
||||
int nmembers = 0;
|
||||
char **ptr = *list;
|
||||
size_t nelem = *nlist, size;
|
||||
|
||||
while (s && *s) {
|
||||
l[nmembers++] = s;
|
||||
if ((s = strchr (s, ',')))
|
||||
*s++ = '\0';
|
||||
while (s != NULL && *s != '\0') {
|
||||
size = (nelem + 1) * sizeof (ptr);
|
||||
if ((ptr = realloc (*list, size)) != NULL) {
|
||||
ptr[nelem++] = s;
|
||||
*list = ptr;
|
||||
*nlist = nelem;
|
||||
if ((s = strchr (s, ',')))
|
||||
*s++ = '\0';
|
||||
}
|
||||
}
|
||||
l[nmembers] = (char *) 0;
|
||||
return l;
|
||||
size = (nelem + 1) * sizeof (ptr);
|
||||
if ((ptr = realloc (*list, size)) != NULL) {
|
||||
ptr[nelem] = '\0';
|
||||
*list = ptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void
|
||||
setsgent(void)
|
||||
void setsgent (void)
|
||||
{
|
||||
#ifdef NDBM
|
||||
int mode;
|
||||
#endif /* NDBM */
|
||||
|
||||
#ifdef USE_NIS
|
||||
nis_state = native;
|
||||
#endif
|
||||
if (shadow)
|
||||
rewind (shadow);
|
||||
else
|
||||
shadow = fopen(SGROUP_FILE, "r");
|
||||
|
||||
/*
|
||||
* Attempt to open the DBM files if they have never been opened
|
||||
* and an error has never been returned.
|
||||
*/
|
||||
|
||||
#ifdef NDBM
|
||||
if (! dbmerror && ! dbmopened) {
|
||||
char dbmfiles[BUFSIZ];
|
||||
|
||||
strcpy (dbmfiles, SGROUP_PAG_FILE);
|
||||
|
||||
if (sg_dbm_mode == -1)
|
||||
mode = O_RDWR;
|
||||
else
|
||||
mode = (sg_dbm_mode == O_RDWR) ? O_RDWR:O_RDONLY;
|
||||
|
||||
if (access(dbmfiles, F_OK) ||
|
||||
(! (sg_dbm = dbm_open(SGROUP_FILE, mode, 0))))
|
||||
dbmerror = 1;
|
||||
else
|
||||
dbmopened = 1;
|
||||
}
|
||||
#endif /* NDBM */
|
||||
shadow = fopen (SGROUP_FILE, "r");
|
||||
}
|
||||
|
||||
void
|
||||
endsgent(void)
|
||||
void endsgent (void)
|
||||
{
|
||||
if (shadow)
|
||||
(void) fclose (shadow);
|
||||
|
||||
shadow = (FILE *) 0;
|
||||
#ifdef NDBM
|
||||
if (dbmopened && sg_dbm) {
|
||||
dbm_close (sg_dbm);
|
||||
dbmopened = 0;
|
||||
sg_dbm = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
struct sgrp *
|
||||
sgetsgent(const char *string)
|
||||
struct sgrp *sgetsgent (const char *string)
|
||||
{
|
||||
char *fields[FIELDS];
|
||||
char *cp;
|
||||
int i;
|
||||
char *fields[FIELDS];
|
||||
char *cp;
|
||||
int i;
|
||||
|
||||
strncpy (sgrbuf, string, (int) sizeof sgrbuf - 1);
|
||||
sgrbuf[sizeof sgrbuf - 1] = '\0';
|
||||
@@ -192,7 +152,7 @@ sgetsgent(const char *string)
|
||||
* all 4 of them and save the starting addresses in fields[].
|
||||
*/
|
||||
|
||||
for (cp = sgrbuf, i = 0;i < FIELDS && cp;i++) {
|
||||
for (cp = sgrbuf, i = 0; i < FIELDS && cp; i++) {
|
||||
fields[i] = cp;
|
||||
if ((cp = strchr (cp, ':')))
|
||||
*cp++ = '\0';
|
||||
@@ -205,7 +165,7 @@ sgetsgent(const char *string)
|
||||
|
||||
if (cp || i != FIELDS)
|
||||
#ifdef USE_NIS
|
||||
if (! IS_NISCHAR (fields[0][0]))
|
||||
if (!IS_NISCHAR (fields[0][0]))
|
||||
return 0;
|
||||
else
|
||||
nis_used = 1;
|
||||
@@ -215,8 +175,18 @@ sgetsgent(const char *string)
|
||||
|
||||
sgroup.sg_name = fields[0];
|
||||
sgroup.sg_passwd = fields[1];
|
||||
sgroup.sg_adm = list (fields[2], admins);
|
||||
sgroup.sg_mem = list (fields[3], members);
|
||||
if (nadmins) {
|
||||
nadmins = 0;
|
||||
free (admins);
|
||||
admins = NULL;
|
||||
}
|
||||
if (nmembers) {
|
||||
nmembers = 0;
|
||||
free (members);
|
||||
members = NULL;
|
||||
}
|
||||
sgroup.sg_adm = list (fields[2], &admins, &nadmins);
|
||||
sgroup.sg_mem = list (fields[3], &members, &nmembers);
|
||||
|
||||
return &sgroup;
|
||||
}
|
||||
@@ -228,13 +198,12 @@ sgetsgent(const char *string)
|
||||
* converts it to a (struct sgrp). NULL is returned on EOF.
|
||||
*/
|
||||
|
||||
struct sgrp *
|
||||
fgetsgent(FILE *fp)
|
||||
struct sgrp *fgetsgent (FILE * fp)
|
||||
{
|
||||
char buf[sizeof sgrbuf];
|
||||
char *cp;
|
||||
char buf[sizeof sgrbuf];
|
||||
char *cp;
|
||||
|
||||
if (! fp)
|
||||
if (!fp)
|
||||
return (0);
|
||||
|
||||
#ifdef USE_NIS
|
||||
@@ -258,19 +227,18 @@ fgetsgent(FILE *fp)
|
||||
* getsgent - get a single shadow group entry
|
||||
*/
|
||||
|
||||
struct sgrp *
|
||||
getsgent(void)
|
||||
struct sgrp *getsgent (void)
|
||||
{
|
||||
#ifdef USE_NIS
|
||||
int nis_1_group = 0;
|
||||
struct sgrp *val;
|
||||
char buf[BUFSIZ];
|
||||
int nis_1_group = 0;
|
||||
struct sgrp *val;
|
||||
char buf[BUFSIZ];
|
||||
#endif
|
||||
if (! shadow)
|
||||
if (!shadow)
|
||||
setsgent ();
|
||||
|
||||
#ifdef USE_NIS
|
||||
again:
|
||||
again:
|
||||
/*
|
||||
* See if we are reading from the local file.
|
||||
*/
|
||||
@@ -282,7 +250,7 @@ again:
|
||||
* NULL right away if there is none.
|
||||
*/
|
||||
|
||||
if (! (val = fgetsgent (shadow)))
|
||||
if (!(val = fgetsgent (shadow)))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
@@ -328,15 +296,15 @@ again:
|
||||
}
|
||||
if (nis_state == start) {
|
||||
if (yp_first (nis_domain, "gshadow.byname", &nis_key,
|
||||
&nis_keylen, &nis_val, &nis_vallen)) {
|
||||
&nis_keylen, &nis_val, &nis_vallen)) {
|
||||
nis_state = native2;
|
||||
goto again;
|
||||
}
|
||||
nis_state = middle;
|
||||
} else if (nis_state == middle) {
|
||||
if (yp_next (nis_domain, "gshadow.byname", nis_key,
|
||||
nis_keylen, &nis_key, &nis_keylen,
|
||||
&nis_val, &nis_vallen)) {
|
||||
nis_keylen, &nis_key, &nis_keylen,
|
||||
&nis_val, &nis_vallen)) {
|
||||
nis_state = native2;
|
||||
goto again;
|
||||
}
|
||||
@@ -352,61 +320,35 @@ again:
|
||||
* getsgnam - get a shadow group entry by name
|
||||
*/
|
||||
|
||||
struct sgrp *
|
||||
getsgnam(const char *name)
|
||||
struct sgrp *getsgnam (const char *name)
|
||||
{
|
||||
struct sgrp *sgrp;
|
||||
#ifdef NDBM
|
||||
datum key;
|
||||
datum content;
|
||||
#endif
|
||||
struct sgrp *sgrp;
|
||||
|
||||
#ifdef USE_NIS
|
||||
char buf[BUFSIZ];
|
||||
static char save_name[16];
|
||||
int nis_disabled = 0;
|
||||
char buf[BUFSIZ];
|
||||
static char save_name[16];
|
||||
int nis_disabled = 0;
|
||||
#endif
|
||||
|
||||
setsgent ();
|
||||
|
||||
#ifdef NDBM
|
||||
|
||||
/*
|
||||
* If the DBM file are now open, create a key for this group and
|
||||
* try to fetch the entry from the database. A matching record
|
||||
* will be unpacked into a static structure and returned to
|
||||
* the user.
|
||||
*/
|
||||
|
||||
if (dbmopened) {
|
||||
key.dsize = strlen (name);
|
||||
key.dptr = (void *) name;
|
||||
|
||||
content = dbm_fetch (sg_dbm, key);
|
||||
if (content.dptr != 0) {
|
||||
memcpy (sgrbuf, content.dptr, content.dsize);
|
||||
sgroup.sg_mem = members;
|
||||
sgroup.sg_adm = admins;
|
||||
sgr_unpack (sgrbuf, content.dsize, &sgroup);
|
||||
return &sgroup;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_NIS
|
||||
if (nis_used) {
|
||||
again:
|
||||
again:
|
||||
|
||||
/*
|
||||
* Search the gshadow.byname map for this group.
|
||||
*/
|
||||
|
||||
if (! nis_bound)
|
||||
if (!nis_bound)
|
||||
bind_nis ();
|
||||
|
||||
if (nis_bound) {
|
||||
char *cp;
|
||||
char *cp;
|
||||
|
||||
if (yp_match (nis_domain, "gshadow.byname", name,
|
||||
strlen (name), &nis_val, &nis_vallen) == 0) {
|
||||
strlen (name), &nis_val,
|
||||
&nis_vallen) == 0) {
|
||||
if (cp = strchr (nis_val, '\n'))
|
||||
*cp = '\0';
|
||||
|
||||
@@ -448,24 +390,23 @@ again:
|
||||
* opposite of fgetsgent.
|
||||
*/
|
||||
|
||||
int
|
||||
putsgent(const struct sgrp *sgrp, FILE *fp)
|
||||
int putsgent (const struct sgrp *sgrp, FILE * fp)
|
||||
{
|
||||
char *buf, *cp;
|
||||
int i;
|
||||
size_t size;
|
||||
|
||||
if (! fp || ! sgrp)
|
||||
if (!fp || !sgrp)
|
||||
return -1;
|
||||
|
||||
/* calculate the required buffer size */
|
||||
size = strlen(sgrp->sg_name) + strlen(sgrp->sg_passwd) + 10;
|
||||
size = strlen (sgrp->sg_name) + strlen (sgrp->sg_passwd) + 10;
|
||||
for (i = 0; sgrp->sg_adm && sgrp->sg_adm[i]; i++)
|
||||
size += strlen(sgrp->sg_adm[i]) + 1;
|
||||
size += strlen (sgrp->sg_adm[i]) + 1;
|
||||
for (i = 0; sgrp->sg_mem && sgrp->sg_mem[i]; i++)
|
||||
size += strlen(sgrp->sg_mem[i]) + 1;
|
||||
size += strlen (sgrp->sg_mem[i]) + 1;
|
||||
|
||||
buf = malloc(size);
|
||||
buf = malloc (size);
|
||||
if (!buf)
|
||||
return -1;
|
||||
cp = buf;
|
||||
@@ -487,7 +428,7 @@ putsgent(const struct sgrp *sgrp, FILE *fp)
|
||||
* with a ",".
|
||||
*/
|
||||
|
||||
for (i = 0;sgrp->sg_adm[i];i++) {
|
||||
for (i = 0; sgrp->sg_adm[i]; i++) {
|
||||
if (i > 0)
|
||||
*cp++ = ',';
|
||||
|
||||
@@ -500,7 +441,7 @@ putsgent(const struct sgrp *sgrp, FILE *fp)
|
||||
* Now do likewise with the group members.
|
||||
*/
|
||||
|
||||
for (i = 0;sgrp->sg_mem[i];i++) {
|
||||
for (i = 0; sgrp->sg_mem[i]; i++) {
|
||||
if (i > 0)
|
||||
*cp++ = ',';
|
||||
|
||||
@@ -515,14 +456,14 @@ putsgent(const struct sgrp *sgrp, FILE *fp)
|
||||
* continuation conventions.
|
||||
*/
|
||||
|
||||
if (fputsx(buf, fp) == EOF) {
|
||||
free(buf);
|
||||
if (fputsx (buf, fp) == EOF) {
|
||||
free (buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
free (buf);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
#endif /*} SHADOWGRP */
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
#endif /*} SHADOWGRP */
|
||||
|
@@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: gshadow_.h,v 1.2 1997/05/01 23:14:41 marekm Exp $
|
||||
* $Id: gshadow_.h,v 1.3 2005/03/31 05:14:49 kloczek Exp $
|
||||
*/
|
||||
|
||||
#ifndef _H_GSHADOW
|
||||
@@ -36,36 +36,36 @@
|
||||
* Shadow group security file structure
|
||||
*/
|
||||
|
||||
struct sgrp {
|
||||
char *sg_name; /* group name */
|
||||
char *sg_passwd; /* group password */
|
||||
char **sg_adm; /* group administator list */
|
||||
char **sg_mem; /* group membership list */
|
||||
struct sgrp {
|
||||
char *sg_name; /* group name */
|
||||
char *sg_passwd; /* group password */
|
||||
char **sg_adm; /* group administator list */
|
||||
char **sg_mem; /* group membership list */
|
||||
};
|
||||
|
||||
/*
|
||||
* Shadow group security file functions.
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
#include <stdio.h> /* for FILE */
|
||||
|
||||
#if __STDC__
|
||||
struct sgrp *getsgent (void);
|
||||
struct sgrp *getsgnam (const char *);
|
||||
struct sgrp *sgetsgent (const char *);
|
||||
struct sgrp *fgetsgent (FILE *);
|
||||
void setsgent (void);
|
||||
void endsgent (void);
|
||||
int putsgent (const struct sgrp *, FILE *);
|
||||
struct sgrp *getsgent (void);
|
||||
struct sgrp *getsgnam (const char *);
|
||||
struct sgrp *sgetsgent (const char *);
|
||||
struct sgrp *fgetsgent (FILE *);
|
||||
void setsgent (void);
|
||||
void endsgent (void);
|
||||
int putsgent (const struct sgrp *, FILE *);
|
||||
#else
|
||||
struct sgrp *getsgent ();
|
||||
struct sgrp *getsgnam ();
|
||||
struct sgrp *sgetsgent ();
|
||||
struct sgrp *fgetsgent ();
|
||||
void setsgent ();
|
||||
void endsgent ();
|
||||
int putsgent ();
|
||||
struct sgrp *getsgent ();
|
||||
struct sgrp *getsgnam ();
|
||||
struct sgrp *sgetsgent ();
|
||||
struct sgrp *fgetsgent ();
|
||||
void setsgent ();
|
||||
void endsgent ();
|
||||
int putsgent ();
|
||||
#endif
|
||||
|
||||
#define GSHADOW "/etc/gshadow"
|
||||
#endif /* ifndef _H_GSHADOW */
|
||||
#endif /* ifndef _H_GSHADOW */
|
||||
|
33
lib/gspack.c
33
lib/gspack.c
@@ -29,14 +29,12 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef SHADOWGRP /*{*/
|
||||
#ifdef SHADOWGRP /*{ */
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: gspack.c,v 1.3 1997/12/07 23:26:53 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: gspack.c,v 1.4 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include "defines.h"
|
||||
|
||||
/*
|
||||
* sgr_pack - convert a shadow group structure to a packed
|
||||
* shadow group record
|
||||
@@ -45,12 +43,10 @@ RCSID("$Id: gspack.c,v 1.3 1997/12/07 23:26:53 marekm Exp $")
|
||||
* the components in a record. this record will be
|
||||
* unpacked later by sgr_unpack.
|
||||
*/
|
||||
|
||||
int
|
||||
sgr_pack(const struct sgrp *sgrp, char *buf)
|
||||
int sgr_pack (const struct sgrp *sgrp, char *buf)
|
||||
{
|
||||
char *cp;
|
||||
int i;
|
||||
char *cp;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* The name and password are both easy - append each string
|
||||
@@ -74,13 +70,13 @@ sgr_pack(const struct sgrp *sgrp, char *buf)
|
||||
* find the start of the members.
|
||||
*/
|
||||
|
||||
for (i = 0;sgrp->sg_adm[i];i++) {
|
||||
for (i = 0; sgrp->sg_adm[i]; i++) {
|
||||
strcpy (cp, sgrp->sg_adm[i]);
|
||||
cp += strlen (cp) + 1;
|
||||
}
|
||||
*cp++ = '\0';
|
||||
|
||||
for (i = 0;sgrp->sg_mem[i];i++) {
|
||||
for (i = 0; sgrp->sg_mem[i]; i++) {
|
||||
strcpy (cp, sgrp->sg_mem[i]);
|
||||
cp += strlen (cp) + 1;
|
||||
}
|
||||
@@ -97,11 +93,10 @@ sgr_pack(const struct sgrp *sgrp, char *buf)
|
||||
* into the normal shadow group structure format.
|
||||
*/
|
||||
|
||||
int
|
||||
sgr_unpack(char *buf, int len, struct sgrp *sgrp)
|
||||
int sgr_unpack (char *buf, int len, struct sgrp *sgrp)
|
||||
{
|
||||
char *org = buf;
|
||||
int i;
|
||||
char *org = buf;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* The name and password are both easy - they are the first
|
||||
@@ -125,7 +120,7 @@ sgr_unpack(char *buf, int len, struct sgrp *sgrp)
|
||||
* looking for an initial character of '\0'.
|
||||
*/
|
||||
|
||||
for (i = 0;*buf && i < 1024;i++) {
|
||||
for (i = 0; *buf && i < 1024; i++) {
|
||||
sgrp->sg_adm[i] = buf;
|
||||
buf += strlen (buf) + 1;
|
||||
|
||||
@@ -133,10 +128,10 @@ sgr_unpack(char *buf, int len, struct sgrp *sgrp)
|
||||
return -1;
|
||||
}
|
||||
sgrp->sg_adm[i] = (char *) 0;
|
||||
if (! *buf)
|
||||
if (!*buf)
|
||||
buf++;
|
||||
|
||||
for (i = 0;*buf && i < 1024;i++) {
|
||||
for (i = 0; *buf && i < 1024; i++) {
|
||||
sgrp->sg_mem[i] = buf;
|
||||
buf += strlen (buf) + 1;
|
||||
|
||||
@@ -147,4 +142,4 @@ sgr_unpack(char *buf, int len, struct sgrp *sgrp)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /*}*/
|
||||
#endif /*} */
|
||||
|
22
lib/lockpw.c
22
lib/lockpw.c
@@ -32,30 +32,25 @@
|
||||
#ifndef HAVE_LCKPWDF
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: lockpw.c,v 1.4 1998/01/29 23:22:28 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: lockpw.c,v 1.5 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include "pwio.h"
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* lckpwdf - lock the password files
|
||||
*/
|
||||
|
||||
int
|
||||
lckpwdf(void)
|
||||
int lckpwdf (void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* We have 15 seconds to lock the whole mess
|
||||
*/
|
||||
|
||||
for (i = 0;i < 15;i++)
|
||||
for (i = 0; i < 15; i++)
|
||||
if (pw_lock ())
|
||||
break;
|
||||
else
|
||||
@@ -73,7 +68,7 @@ lckpwdf(void)
|
||||
* file.
|
||||
*/
|
||||
|
||||
for (;i < 15;i++)
|
||||
for (; i < 15; i++)
|
||||
if (spw_lock ())
|
||||
break;
|
||||
else
|
||||
@@ -99,16 +94,15 @@ lckpwdf(void)
|
||||
* ulckpwdf - unlock the password files
|
||||
*/
|
||||
|
||||
int
|
||||
ulckpwdf(void)
|
||||
int ulckpwdf (void)
|
||||
{
|
||||
|
||||
/*
|
||||
* Unlock both files.
|
||||
*/
|
||||
|
||||
return (pw_unlock () && spw_unlock ()) ? 0:-1;
|
||||
return (pw_unlock () && spw_unlock ())? 0 : -1;
|
||||
}
|
||||
#else
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
#endif
|
||||
|
173
lib/port.c
173
lib/port.c
@@ -30,17 +30,15 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: port.c,v 1.3 1997/12/07 23:26:54 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: port.c,v 1.4 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include "defines.h"
|
||||
#include "port.h"
|
||||
extern int errno;
|
||||
|
||||
extern int errno;
|
||||
|
||||
static FILE *ports;
|
||||
static FILE *ports;
|
||||
|
||||
/*
|
||||
* portcmp - compare the name of a port to a /etc/porttime entry
|
||||
@@ -52,8 +50,7 @@ static FILE *ports;
|
||||
* A match returns 0, failure returns non-zero.
|
||||
*/
|
||||
|
||||
static int
|
||||
portcmp(const char *pattern, const char *port)
|
||||
static int portcmp (const char *pattern, const char *port)
|
||||
{
|
||||
const char *orig = port;
|
||||
|
||||
@@ -65,7 +62,7 @@ portcmp(const char *pattern, const char *port)
|
||||
if (orig[0] == 'S' && orig[1] == 'U' && orig[2] == '\0')
|
||||
return 1;
|
||||
|
||||
return *pattern == '*' ? 0:1;
|
||||
return *pattern == '*' ? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -75,12 +72,11 @@ portcmp(const char *pattern, const char *port)
|
||||
* opened for reading.
|
||||
*/
|
||||
|
||||
static void
|
||||
setportent(void)
|
||||
static void setportent (void)
|
||||
{
|
||||
if (ports)
|
||||
rewind (ports);
|
||||
else
|
||||
else
|
||||
ports = fopen (PORTS, "r");
|
||||
}
|
||||
|
||||
@@ -92,8 +88,7 @@ setportent(void)
|
||||
* open.
|
||||
*/
|
||||
|
||||
static void
|
||||
endportent(void)
|
||||
static void endportent (void)
|
||||
{
|
||||
if (ports)
|
||||
fclose (ports);
|
||||
@@ -110,28 +105,27 @@ endportent(void)
|
||||
* set to EINVAL on error to distinguish the two conditions.
|
||||
*/
|
||||
|
||||
static struct port *
|
||||
getportent(void)
|
||||
static struct port *getportent (void)
|
||||
{
|
||||
static struct port port; /* static struct to point to */
|
||||
static char buf[BUFSIZ]; /* some space for stuff */
|
||||
static char *ttys[PORT_TTY+1]; /* some pointers to tty names */
|
||||
static char *users[PORT_IDS+1]; /* some pointers to user ids */
|
||||
static struct pt_time ptimes[PORT_TIMES+1]; /* time ranges */
|
||||
char *cp; /* pointer into line */
|
||||
int dtime; /* scratch time of day */
|
||||
int i, j;
|
||||
int saveerr = errno; /* errno value on entry */
|
||||
static struct port port; /* static struct to point to */
|
||||
static char buf[BUFSIZ]; /* some space for stuff */
|
||||
static char *ttys[PORT_TTY + 1]; /* some pointers to tty names */
|
||||
static char *users[PORT_IDS + 1]; /* some pointers to user ids */
|
||||
static struct pt_time ptimes[PORT_TIMES + 1]; /* time ranges */
|
||||
char *cp; /* pointer into line */
|
||||
int dtime; /* scratch time of day */
|
||||
int i, j;
|
||||
int saveerr = errno; /* errno value on entry */
|
||||
|
||||
/*
|
||||
* If the ports file is not open, open the file. Do not rewind
|
||||
* since we want to search from the beginning each time.
|
||||
*/
|
||||
|
||||
if (! ports)
|
||||
if (!ports)
|
||||
setportent ();
|
||||
|
||||
if (! ports) {
|
||||
if (!ports) {
|
||||
errno = saveerr;
|
||||
return 0;
|
||||
}
|
||||
@@ -139,14 +133,14 @@ getportent(void)
|
||||
/*
|
||||
* Common point for beginning a new line -
|
||||
*
|
||||
* - read a line, and NUL terminate
|
||||
* - skip lines which begin with '#'
|
||||
* - parse off the tty names
|
||||
* - parse off a list of user names
|
||||
* - parse off a list of days and times
|
||||
* - read a line, and NUL terminate
|
||||
* - skip lines which begin with '#'
|
||||
* - parse off the tty names
|
||||
* - parse off a list of user names
|
||||
* - parse off a list of days and times
|
||||
*/
|
||||
|
||||
again:
|
||||
again:
|
||||
|
||||
/*
|
||||
* Get the next line and remove the last character, which
|
||||
@@ -170,18 +164,18 @@ again:
|
||||
buf[strlen (buf) - 1] = 0;
|
||||
|
||||
port.pt_names = ttys;
|
||||
for (cp = buf, j = 0;j < PORT_TTY;j++) {
|
||||
for (cp = buf, j = 0; j < PORT_TTY; j++) {
|
||||
port.pt_names[j] = cp;
|
||||
while (*cp && *cp != ':' && *cp != ',')
|
||||
cp++;
|
||||
|
||||
if (! *cp)
|
||||
if (!*cp)
|
||||
goto again; /* line format error */
|
||||
|
||||
if (*cp == ':') /* end of tty name list */
|
||||
if (*cp == ':') /* end of tty name list */
|
||||
break;
|
||||
|
||||
if (*cp == ',') /* end of current tty name */
|
||||
if (*cp == ',') /* end of current tty name */
|
||||
*cp++ = '\0';
|
||||
}
|
||||
*cp++ = 0;
|
||||
@@ -198,7 +192,7 @@ again:
|
||||
port.pt_users = users;
|
||||
port.pt_users[0] = cp;
|
||||
|
||||
for (j = 1;*cp != ':';cp++) {
|
||||
for (j = 1; *cp != ':'; cp++) {
|
||||
if (*cp == ',' && j < PORT_IDS) {
|
||||
*cp++ = 0;
|
||||
port.pt_users[j++] = cp;
|
||||
@@ -237,7 +231,7 @@ again:
|
||||
* Get the next comma separated entry
|
||||
*/
|
||||
|
||||
for (j = 0;*cp && j < PORT_TIMES;j++) {
|
||||
for (j = 0; *cp && j < PORT_TIMES; j++) {
|
||||
|
||||
/*
|
||||
* Start off with no days of the week
|
||||
@@ -251,38 +245,38 @@ again:
|
||||
* week or the other two values.
|
||||
*/
|
||||
|
||||
for (i = 0;cp[i] && cp[i + 1] && isalpha (cp[i]);i += 2) {
|
||||
for (i = 0; cp[i] && cp[i + 1] && isalpha (cp[i]); i += 2) {
|
||||
switch ((cp[i] << 8) | (cp[i + 1])) {
|
||||
case ('S' << 8) | 'u':
|
||||
port.pt_times[j].t_days |= 01;
|
||||
break;
|
||||
case ('M' << 8) | 'o':
|
||||
port.pt_times[j].t_days |= 02;
|
||||
break;
|
||||
case ('T' << 8) | 'u':
|
||||
port.pt_times[j].t_days |= 04;
|
||||
break;
|
||||
case ('W' << 8) | 'e':
|
||||
port.pt_times[j].t_days |= 010;
|
||||
break;
|
||||
case ('T' << 8) | 'h':
|
||||
port.pt_times[j].t_days |= 020;
|
||||
break;
|
||||
case ('F' << 8) | 'r':
|
||||
port.pt_times[j].t_days |= 040;
|
||||
break;
|
||||
case ('S' << 8) | 'a':
|
||||
port.pt_times[j].t_days |= 0100;
|
||||
break;
|
||||
case ('W' << 8) | 'k':
|
||||
port.pt_times[j].t_days |= 076;
|
||||
break;
|
||||
case ('A' << 8) | 'l':
|
||||
port.pt_times[j].t_days |= 0177;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
case ('S' << 8) | 'u':
|
||||
port.pt_times[j].t_days |= 01;
|
||||
break;
|
||||
case ('M' << 8) | 'o':
|
||||
port.pt_times[j].t_days |= 02;
|
||||
break;
|
||||
case ('T' << 8) | 'u':
|
||||
port.pt_times[j].t_days |= 04;
|
||||
break;
|
||||
case ('W' << 8) | 'e':
|
||||
port.pt_times[j].t_days |= 010;
|
||||
break;
|
||||
case ('T' << 8) | 'h':
|
||||
port.pt_times[j].t_days |= 020;
|
||||
break;
|
||||
case ('F' << 8) | 'r':
|
||||
port.pt_times[j].t_days |= 040;
|
||||
break;
|
||||
case ('S' << 8) | 'a':
|
||||
port.pt_times[j].t_days |= 0100;
|
||||
break;
|
||||
case ('W' << 8) | 'k':
|
||||
port.pt_times[j].t_days |= 076;
|
||||
break;
|
||||
case ('A' << 8) | 'l':
|
||||
port.pt_times[j].t_days |= 0177;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +293,7 @@ again:
|
||||
* representing the times of day.
|
||||
*/
|
||||
|
||||
for (dtime = 0;cp[i] && isdigit (cp[i]);i++)
|
||||
for (dtime = 0; cp[i] && isdigit (cp[i]); i++)
|
||||
dtime = dtime * 10 + cp[i] - '0';
|
||||
|
||||
if (cp[i] != '-' || dtime > 2400 || dtime % 100 > 59)
|
||||
@@ -307,11 +301,10 @@ again:
|
||||
port.pt_times[j].t_start = dtime;
|
||||
cp = cp + i + 1;
|
||||
|
||||
for (dtime = i = 0;cp[i] && isdigit (cp[i]);i++)
|
||||
for (dtime = i = 0; cp[i] && isdigit (cp[i]); i++)
|
||||
dtime = dtime * 10 + cp[i] - '0';
|
||||
|
||||
if ((cp[i] != ',' && cp[i]) ||
|
||||
dtime > 2400 || dtime % 100 > 59)
|
||||
if ((cp[i] != ',' && cp[i]) || dtime > 2400 || dtime % 100 > 59)
|
||||
goto again;
|
||||
|
||||
port.pt_times[j].t_end = dtime;
|
||||
@@ -337,11 +330,10 @@ again:
|
||||
* entries are treated as an ordered list.
|
||||
*/
|
||||
|
||||
static struct port *
|
||||
getttyuser(const char *tty, const char *user)
|
||||
static struct port *getttyuser (const char *tty, const char *user)
|
||||
{
|
||||
int i, j;
|
||||
struct port *port;
|
||||
int i, j;
|
||||
struct port *port;
|
||||
|
||||
setportent ();
|
||||
|
||||
@@ -349,16 +341,16 @@ getttyuser(const char *tty, const char *user)
|
||||
if (port->pt_names == 0 || port->pt_users == 0)
|
||||
continue;
|
||||
|
||||
for (i = 0;port->pt_names[i];i++)
|
||||
for (i = 0; port->pt_names[i]; i++)
|
||||
if (portcmp (port->pt_names[i], tty) == 0)
|
||||
break;
|
||||
|
||||
if (port->pt_names[i] == 0)
|
||||
continue;
|
||||
|
||||
for (j = 0;port->pt_users[j];j++)
|
||||
for (j = 0; port->pt_users[j]; j++)
|
||||
if (strcmp (user, port->pt_users[j]) == 0 ||
|
||||
strcmp (port->pt_users[j], "*") == 0)
|
||||
strcmp (port->pt_users[j], "*") == 0)
|
||||
break;
|
||||
|
||||
if (port->pt_users[j] != 0)
|
||||
@@ -375,13 +367,12 @@ getttyuser(const char *tty, const char *user)
|
||||
* the user name and TTY given.
|
||||
*/
|
||||
|
||||
int
|
||||
isttytime(const char *id, const char *port, time_t when)
|
||||
int isttytime (const char *id, const char *port, time_t when)
|
||||
{
|
||||
int i;
|
||||
int dtime;
|
||||
struct port *pp;
|
||||
struct tm *tm;
|
||||
int i;
|
||||
int dtime;
|
||||
struct port *pp;
|
||||
struct tm *tm;
|
||||
|
||||
/*
|
||||
* Try to find a matching entry for this user. Default to
|
||||
@@ -389,7 +380,7 @@ isttytime(const char *id, const char *port, time_t when)
|
||||
* entry to match all users.
|
||||
*/
|
||||
|
||||
if (! (pp = getttyuser (port, id)))
|
||||
if (!(pp = getttyuser (port, id)))
|
||||
return 1;
|
||||
|
||||
/*
|
||||
@@ -415,17 +406,17 @@ isttytime(const char *id, const char *port, time_t when)
|
||||
* midnight and either the start or end time.
|
||||
*/
|
||||
|
||||
for (i = 0;pp->pt_times[i].t_start != -1;i++) {
|
||||
if (! (pp->pt_times[i].t_days & PORT_DAY(tm->tm_wday)))
|
||||
for (i = 0; pp->pt_times[i].t_start != -1; i++) {
|
||||
if (!(pp->pt_times[i].t_days & PORT_DAY (tm->tm_wday)))
|
||||
continue;
|
||||
|
||||
if (pp->pt_times[i].t_start <= pp->pt_times[i].t_end) {
|
||||
if (dtime >= pp->pt_times[i].t_start &&
|
||||
dtime <= pp->pt_times[i].t_end)
|
||||
dtime <= pp->pt_times[i].t_end)
|
||||
return 1;
|
||||
} else {
|
||||
if (dtime >= pp->pt_times[i].t_start ||
|
||||
dtime <= pp->pt_times[i].t_end)
|
||||
dtime <= pp->pt_times[i].t_end)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
18
lib/port.h
18
lib/port.h
@@ -30,7 +30,7 @@
|
||||
/*
|
||||
* port.h - structure of /etc/porttime
|
||||
*
|
||||
* $Id: port.h,v 1.2 1997/05/01 23:14:43 marekm Exp $
|
||||
* $Id: port.h,v 1.3 2005/03/31 05:14:49 kloczek Exp $
|
||||
*
|
||||
* Each entry in /etc/porttime consists of a TTY device
|
||||
* name or "*" to indicate all TTY devices, followed by
|
||||
@@ -62,10 +62,10 @@
|
||||
* pt_times - pointer to list of allowable time periods.
|
||||
*/
|
||||
|
||||
struct port {
|
||||
char **pt_names;
|
||||
char **pt_users;
|
||||
struct pt_time *pt_times;
|
||||
struct port {
|
||||
char **pt_names;
|
||||
char **pt_users;
|
||||
struct pt_time *pt_times;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -74,8 +74,8 @@ struct port {
|
||||
* t_end - ending time for this entry
|
||||
*/
|
||||
|
||||
struct pt_time {
|
||||
short t_days;
|
||||
short t_start;
|
||||
short t_end;
|
||||
struct pt_time {
|
||||
short t_days;
|
||||
short t_start;
|
||||
short t_end;
|
||||
};
|
||||
|
179
lib/prototypes.h
179
lib/prototypes.h
@@ -6,7 +6,7 @@
|
||||
* Juha Virtanen, <jiivee@hut.fi>; November 1995
|
||||
*/
|
||||
/*
|
||||
* $Id: prototypes.h,v 1.15 2003/04/25 21:33:47 kloczek Exp $
|
||||
* $Id: prototypes.h,v 1.18 2005/04/06 03:01:07 kloczek Exp $
|
||||
*
|
||||
* Added a macro to work around ancient (non-ANSI) compilers, just in case
|
||||
* someone ever tries to compile this with SunOS cc... --marekm
|
||||
@@ -27,206 +27,199 @@
|
||||
#include "defines.h"
|
||||
|
||||
/* addgrps.c */
|
||||
extern int add_groups(const char *);
|
||||
extern void add_cons_grps(void);
|
||||
extern int add_groups (const char *);
|
||||
extern void add_cons_grps (void);
|
||||
|
||||
/* age.c */
|
||||
#ifdef SHADOWPWD
|
||||
extern void agecheck(const struct passwd *, const struct spwd *);
|
||||
extern int expire(const struct passwd *, const struct spwd *);
|
||||
extern int isexpired(const struct passwd *, const struct spwd *);
|
||||
extern void agecheck (const struct passwd *, const struct spwd *);
|
||||
extern int expire (const struct passwd *, const struct spwd *);
|
||||
extern int isexpired (const struct passwd *, const struct spwd *);
|
||||
#else
|
||||
extern void agecheck(const struct passwd *);
|
||||
extern int expire(const struct passwd *);
|
||||
extern int isexpired(const struct passwd *);
|
||||
extern void agecheck (const struct passwd *);
|
||||
extern int expire (const struct passwd *);
|
||||
extern int isexpired (const struct passwd *);
|
||||
#endif
|
||||
|
||||
/* basename() renamed to Basename() to avoid libc name space confusion */
|
||||
/* basename.c */
|
||||
extern char *Basename(char *str);
|
||||
extern char *Basename (char *str);
|
||||
|
||||
/* chkshell.c */
|
||||
extern int check_shell(const char *);
|
||||
extern int check_shell (const char *);
|
||||
|
||||
/* chowndir.c */
|
||||
extern int chown_tree(const char *, uid_t, uid_t, gid_t, gid_t);
|
||||
extern int chown_tree (const char *, uid_t, uid_t, gid_t, gid_t);
|
||||
|
||||
/* chowntty.c */
|
||||
extern void chown_tty(const char *, const struct passwd *);
|
||||
extern void chown_tty (const char *, const struct passwd *);
|
||||
|
||||
/* console.c */
|
||||
extern int console(const char *);
|
||||
extern int is_listed(const char *, const char *, int);
|
||||
extern int console (const char *);
|
||||
extern int is_listed (const char *, const char *, int);
|
||||
|
||||
/* copydir.c */
|
||||
extern int copy_tree(const char *, const char *, uid_t, gid_t);
|
||||
extern int remove_tree(const char *);
|
||||
extern int copy_tree (const char *, const char *, uid_t, gid_t);
|
||||
extern int remove_tree (const char *);
|
||||
|
||||
/* encrypt.c */
|
||||
extern char *pw_encrypt(const char *, const char *);
|
||||
extern char *pw_encrypt (const char *, const char *);
|
||||
|
||||
/* entry.c */
|
||||
extern void pw_entry(const char *, struct passwd *);
|
||||
extern void pw_entry (const char *, struct passwd *);
|
||||
|
||||
/* env.c */
|
||||
extern void addenv(const char *, const char *);
|
||||
extern void initenv(void);
|
||||
extern void set_env(int, char * const *);
|
||||
extern void sanitize_env(void);
|
||||
extern void addenv (const char *, const char *);
|
||||
extern void initenv (void);
|
||||
extern void set_env (int, char *const *);
|
||||
extern void sanitize_env (void);
|
||||
|
||||
/* fields.c */
|
||||
extern void change_field(char *, size_t, const char *);
|
||||
extern int valid_field(const char *, const char *);
|
||||
extern void change_field (char *, size_t, const char *);
|
||||
extern int valid_field (const char *, const char *);
|
||||
|
||||
/* fputsx.c */
|
||||
extern char *fgetsx(char *, int, FILE *);
|
||||
extern int fputsx(const char *, FILE *);
|
||||
extern char *fgetsx (char *, int, FILE *);
|
||||
extern int fputsx (const char *, FILE *);
|
||||
|
||||
/* grdbm.c */
|
||||
extern int gr_dbm_remove(const struct group *);
|
||||
extern int gr_dbm_update(const struct group *);
|
||||
extern int gr_dbm_present(void);
|
||||
extern int gr_dbm_remove (const struct group *);
|
||||
extern int gr_dbm_update (const struct group *);
|
||||
extern int gr_dbm_present (void);
|
||||
|
||||
/* grent.c */
|
||||
extern int putgrent(const struct group *, FILE *);
|
||||
extern int putgrent (const struct group *, FILE *);
|
||||
|
||||
/* grpack.c */
|
||||
extern int gr_pack(const struct group *, char *);
|
||||
extern int gr_unpack(char *, int, struct group *);
|
||||
extern int gr_pack (const struct group *, char *);
|
||||
extern int gr_unpack (char *, int, struct group *);
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
/* gsdbm.c */
|
||||
extern int sg_dbm_remove(const char *);
|
||||
extern int sg_dbm_update(const struct sgrp *);
|
||||
extern int sg_dbm_present(void);
|
||||
extern int sg_dbm_remove (const char *);
|
||||
extern int sg_dbm_update (const struct sgrp *);
|
||||
extern int sg_dbm_present (void);
|
||||
|
||||
/* gspack.c */
|
||||
extern int sgr_pack(const struct sgrp *, char *);
|
||||
extern int sgr_unpack(char *, int, struct sgrp *);
|
||||
extern int sgr_pack (const struct sgrp *, char *);
|
||||
extern int sgr_unpack (char *, int, struct sgrp *);
|
||||
#endif
|
||||
|
||||
/* hushed.c */
|
||||
extern int hushed(const struct passwd *);
|
||||
extern int hushed (const struct passwd *);
|
||||
|
||||
/* limits.c */
|
||||
extern void setup_limits(const struct passwd *);
|
||||
extern void setup_limits (const struct passwd *);
|
||||
|
||||
/* list.c */
|
||||
extern char **add_list(char **, const char *);
|
||||
extern char **del_list(char **, const char *);
|
||||
extern char **dup_list(char * const *);
|
||||
extern int is_on_list(char * const *, const char *);
|
||||
extern char **comma_to_list(const char *);
|
||||
extern char **add_list (char **, const char *);
|
||||
extern char **del_list (char **, const char *);
|
||||
extern char **dup_list (char *const *);
|
||||
extern int is_on_list (char *const *, const char *);
|
||||
extern char **comma_to_list (const char *);
|
||||
|
||||
/* login.c */
|
||||
extern void login_prompt(const char *, char *, int);
|
||||
|
||||
/* login_desrpc.c */
|
||||
extern int login_desrpc(const char *);
|
||||
extern void login_prompt (const char *, char *, int);
|
||||
|
||||
/* mail.c */
|
||||
extern void mailcheck(void);
|
||||
extern void mailcheck (void);
|
||||
|
||||
/* motd.c */
|
||||
extern void motd(void);
|
||||
extern void motd (void);
|
||||
|
||||
/* myname.c */
|
||||
extern struct passwd *get_my_pwent(void);
|
||||
extern struct passwd *get_my_pwent (void);
|
||||
|
||||
/* obscure.c */
|
||||
extern int obscure(const char *, const char *, const struct passwd *);
|
||||
extern int obscure (const char *, const char *, const struct passwd *);
|
||||
|
||||
/* pam_pass.c */
|
||||
extern int do_pam_passwd(const char *, int, int);
|
||||
extern int do_pam_passwd (const char *, int, int);
|
||||
|
||||
/* port.c */
|
||||
extern int isttytime(const char *, const char *, time_t);
|
||||
extern int isttytime (const char *, const char *, time_t);
|
||||
|
||||
/* pwd2spwd.c */
|
||||
#ifdef SHADOWPWD
|
||||
extern struct spwd *pwd_to_spwd(const struct passwd *);
|
||||
extern struct spwd *pwd_to_spwd (const struct passwd *);
|
||||
#endif
|
||||
|
||||
/* pwdcheck.c */
|
||||
extern void passwd_check(const char *, const char *, const char *);
|
||||
extern void passwd_check (const char *, const char *, const char *);
|
||||
|
||||
/* pwd_init.c */
|
||||
extern void pwd_init(void);
|
||||
extern void pwd_init (void);
|
||||
|
||||
/* pwdbm.c */
|
||||
extern int pw_dbm_remove(const struct passwd *);
|
||||
extern int pw_dbm_update(const struct passwd *);
|
||||
extern int pw_dbm_present(void);
|
||||
extern int pw_dbm_remove (const struct passwd *);
|
||||
extern int pw_dbm_update (const struct passwd *);
|
||||
extern int pw_dbm_present (void);
|
||||
|
||||
/* pwpack.c */
|
||||
extern int pw_pack(const struct passwd *, char *);
|
||||
extern int pw_unpack(char *, int, struct passwd *);
|
||||
|
||||
/* rad64.c */
|
||||
extern int c64i(int);
|
||||
extern int i64c(int);
|
||||
extern int pw_pack (const struct passwd *, char *);
|
||||
extern int pw_unpack (char *, int, struct passwd *);
|
||||
|
||||
/* rlogin.c */
|
||||
extern int do_rlogin(const char *, char *, int, char *, int);
|
||||
extern int do_rlogin (const char *, char *, int, char *, int);
|
||||
|
||||
/* salt.c */
|
||||
extern char *crypt_make_salt(void);
|
||||
extern char *crypt_make_salt (void);
|
||||
|
||||
/* setugid.c */
|
||||
extern int setup_groups(const struct passwd *);
|
||||
extern int change_uid(const struct passwd *);
|
||||
extern int setup_uid_gid(const struct passwd *, int);
|
||||
extern int setup_groups (const struct passwd *);
|
||||
extern int change_uid (const struct passwd *);
|
||||
extern int setup_uid_gid (const struct passwd *, int);
|
||||
|
||||
/* setup.c */
|
||||
extern void setup(struct passwd *);
|
||||
extern void setup (struct passwd *);
|
||||
|
||||
/* setupenv.c */
|
||||
extern void setup_env(struct passwd *);
|
||||
extern void setup_env (struct passwd *);
|
||||
|
||||
/* shell.c */
|
||||
extern void shell(const char *, const char *);
|
||||
extern void shell (const char *, const char *);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
/* spdbm.c */
|
||||
extern int sp_dbm_remove(const char *);
|
||||
extern int sp_dbm_update(const struct spwd *);
|
||||
extern int sp_dbm_present(void);
|
||||
extern int sp_dbm_remove (const char *);
|
||||
extern int sp_dbm_update (const struct spwd *);
|
||||
extern int sp_dbm_present (void);
|
||||
|
||||
/* sppack.c */
|
||||
extern int spw_pack(const struct spwd *, char *);
|
||||
extern int spw_unpack(char *, int, struct spwd *);
|
||||
extern int spw_pack (const struct spwd *, char *);
|
||||
extern int spw_unpack (char *, int, struct spwd *);
|
||||
#endif
|
||||
|
||||
/* strtoday.c */
|
||||
extern long strtoday(const char *);
|
||||
extern long strtoday (const char *);
|
||||
|
||||
/* suauth.c */
|
||||
extern int check_su_auth(const char *, const char *);
|
||||
extern int check_su_auth (const char *, const char *);
|
||||
|
||||
/* sulog.c */
|
||||
extern void sulog(const char *, int, const char *, const char *);
|
||||
extern void sulog (const char *, int, const char *, const char *);
|
||||
|
||||
/* sub.c */
|
||||
extern void subsystem(const struct passwd *);
|
||||
extern void subsystem (const struct passwd *);
|
||||
|
||||
/* ttytype.c */
|
||||
extern void ttytype(const char *);
|
||||
extern void ttytype (const char *);
|
||||
|
||||
/* tz.c */
|
||||
extern char *tz(const char *);
|
||||
extern char *tz (const char *);
|
||||
|
||||
/* ulimit.c */
|
||||
extern void set_filesize_limit(int);
|
||||
extern void set_filesize_limit (int);
|
||||
|
||||
/* utmp.c */
|
||||
extern void checkutmp(int);
|
||||
extern void setutmp(const char *, const char *, const char *);
|
||||
extern void checkutmp (int);
|
||||
extern void setutmp (const char *, const char *, const char *);
|
||||
|
||||
/* valid.c */
|
||||
extern int valid(const char *, const struct passwd *);
|
||||
extern int valid (const char *, const struct passwd *);
|
||||
|
||||
/* xmalloc.c */
|
||||
extern char *xmalloc(size_t);
|
||||
extern char *xstrdup(const char *);
|
||||
extern char *xmalloc (size_t);
|
||||
extern char *xstrdup (const char *);
|
||||
|
||||
#endif /* _PROTOTYPES_H */
|
||||
#endif /* _PROTOTYPES_H */
|
||||
|
183
lib/pwauth.c
183
lib/pwauth.c
@@ -29,9 +29,9 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifndef USE_PAM
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: pwauth.c,v 1.14 2003/05/12 04:58:56 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: pwauth.c,v 1.17 2005/04/17 15:21:42 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
@@ -41,23 +41,14 @@ RCSID("$Id: pwauth.c,v 1.14 2003/05/12 04:58:56 kloczek Exp $")
|
||||
#include "defines.h"
|
||||
#include "pwauth.h"
|
||||
#include "getdef.h"
|
||||
|
||||
#ifdef SKEY
|
||||
#include <skey.h>
|
||||
#endif
|
||||
|
||||
#ifdef OPIE
|
||||
#include <opie.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__ /* standard password prompt by default */
|
||||
static const char *PROMPT = gettext_noop("Password: ");
|
||||
#ifdef __linux__ /* standard password prompt by default */
|
||||
static const char *PROMPT = gettext_noop ("Password: ");
|
||||
#else
|
||||
static const char *PROMPT = gettext_noop("%s's Password: ");
|
||||
static const char *PROMPT = gettext_noop ("%s's Password: ");
|
||||
#endif
|
||||
|
||||
extern char *getpass();
|
||||
extern char *getpass_with_echo();
|
||||
extern char *getpass ();
|
||||
extern char *getpass_with_echo ();
|
||||
|
||||
int wipe_clear_pass = 1;
|
||||
char *clear_pass = NULL;
|
||||
@@ -71,41 +62,12 @@ char *clear_pass = NULL;
|
||||
*/
|
||||
|
||||
int
|
||||
pw_auth(const char *cipher, const char *user, int reason, const char *input)
|
||||
pw_auth (const char *cipher, const char *user, int reason, const char *input)
|
||||
{
|
||||
char prompt[1024];
|
||||
char *clear = NULL;
|
||||
char prompt[1024];
|
||||
char *clear = NULL;
|
||||
const char *cp;
|
||||
int retval;
|
||||
#ifdef SKEY
|
||||
int use_skey = 0;
|
||||
char challenge_info[40];
|
||||
struct skey skey;
|
||||
#endif
|
||||
|
||||
#ifdef OPIE
|
||||
int use_opie = 0;
|
||||
char o_challenge_info[OPIE_CHALLENGE_MAX + 1];
|
||||
struct opie opie;
|
||||
/*
|
||||
* This implementation is based almost entirely on the SKEY code
|
||||
* above. Thus the opie struct is called skey, etc. I am unaware
|
||||
* if the system works at the same time, but I cannot imagine why
|
||||
* anyone would want to do this....
|
||||
* -- A.R.
|
||||
* Mod: 5/14/98 A.R.
|
||||
* Made the OPIE code separate from the S/Key code. Now
|
||||
* (conceivably) both can be compiled in and function apart from
|
||||
* one another (assuming a sysadmin really wants to maintain OPIE
|
||||
* and an S/Key databases....).
|
||||
*
|
||||
* Also cleaned up the code a bit. Will be adding second-prompt
|
||||
* support (the traditional Echo-on S/Key/OPIE-only prompts to let
|
||||
* the users see the one-time passwords they are typing/pasting
|
||||
* in....
|
||||
* -- A.R.
|
||||
*/
|
||||
#endif
|
||||
int retval;
|
||||
|
||||
/*
|
||||
* There are programs for adding and deleting authentication data.
|
||||
@@ -117,7 +79,6 @@ pw_auth(const char *cipher, const char *user, int reason, const char *input)
|
||||
/*
|
||||
* There are even programs for changing the user name ...
|
||||
*/
|
||||
|
||||
if (reason == PW_CHANGE && input != (char *) 0)
|
||||
return 0;
|
||||
|
||||
@@ -129,7 +90,6 @@ pw_auth(const char *cipher, const char *user, int reason, const char *input)
|
||||
* know it. This is a policy decision that might have to be
|
||||
* revisited.
|
||||
*/
|
||||
|
||||
if (reason == PW_CHANGE && getuid () == 0)
|
||||
return 0;
|
||||
|
||||
@@ -141,65 +101,21 @@ pw_auth(const char *cipher, const char *user, int reason, const char *input)
|
||||
* the user could just hit <ENTER>, so it doesn't really
|
||||
* matter.
|
||||
*/
|
||||
|
||||
if (cipher == (char *) 0 || *cipher == '\0')
|
||||
return 0;
|
||||
|
||||
#ifdef SKEY
|
||||
/*
|
||||
* If the user has an S/KEY entry show them the pertinent info
|
||||
* and then we can try validating the created cyphertext and the SKEY.
|
||||
* If there is no SKEY information we default to not using SKEY.
|
||||
*/
|
||||
|
||||
if (skeychallenge (&skey, user, challenge_info) == 0)
|
||||
use_skey = 1;
|
||||
#endif
|
||||
|
||||
#ifdef OPIE
|
||||
/*
|
||||
* Ditto above, for OPIE passwords.
|
||||
* -- AR
|
||||
*/
|
||||
|
||||
o_challenge_info[0] = '\0';
|
||||
if (opiechallenge(&opie, user, o_challenge_info) == 0)
|
||||
use_opie = 1;
|
||||
|
||||
if (use_opie == 0)
|
||||
opieverify(&opie, (char *)NULL);
|
||||
/*
|
||||
* This call to opieverify is necessary within OPIE's interface:
|
||||
* Every call to opiechallenge(), which checks to see if the user
|
||||
* has an OPIE password, and if so get the challenge, must be
|
||||
* accompanied by exactly one call to opieverify, which clears
|
||||
* any outstanding locks, and otherwise cleans up.
|
||||
* -- AR
|
||||
*/
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Prompt for the password as required. FTPD and REXECD both
|
||||
* get the cleartext password for us.
|
||||
*/
|
||||
|
||||
if (reason != PW_FTP && reason != PW_REXEC && !input) {
|
||||
if (! (cp = getdef_str ("LOGIN_STRING")))
|
||||
if (!(cp = getdef_str ("LOGIN_STRING")))
|
||||
cp = _(PROMPT);
|
||||
#ifdef SKEY
|
||||
if (use_skey)
|
||||
printf ("[%s]\n", challenge_info);
|
||||
#endif
|
||||
|
||||
#ifdef OPIE
|
||||
if (use_opie)
|
||||
printf("[ %s ]\n", o_challenge_info);
|
||||
#endif
|
||||
|
||||
snprintf(prompt, sizeof prompt, cp, user);
|
||||
clear = getpass(prompt);
|
||||
snprintf (prompt, sizeof prompt, cp, user);
|
||||
clear = getpass (prompt);
|
||||
if (!clear) {
|
||||
static char c[1];
|
||||
|
||||
c[0] = '\0';
|
||||
clear = c;
|
||||
}
|
||||
@@ -209,70 +125,9 @@ pw_auth(const char *cipher, const char *user, int reason, const char *input)
|
||||
/*
|
||||
* Convert the cleartext password into a ciphertext string.
|
||||
* If the two match, the return value will be zero, which is
|
||||
* SUCCESS. Otherwise we see if SKEY is being used and check
|
||||
* the results there as well.
|
||||
* SUCCESS.
|
||||
*/
|
||||
|
||||
retval = strcmp(pw_encrypt(input, cipher), cipher);
|
||||
|
||||
#ifdef OPIE
|
||||
/*
|
||||
* This is required because using OPIE, opieverify() MUST be called
|
||||
* opiechallenge() above even if OPIE isn't being used in this case,
|
||||
* so locks get released, etc.
|
||||
* -- AR
|
||||
*/
|
||||
|
||||
if ((retval == 0) && use_opie)
|
||||
opieverify(&opie, (char *)NULL);
|
||||
#endif
|
||||
|
||||
#if (defined(SKEY) || defined(OPIE))
|
||||
/*
|
||||
* If (1) The password fails to match, and
|
||||
* (2) The password is empty and
|
||||
* (3) We are using OPIE or S/Key, then
|
||||
* ...Re-prompt, with echo on.
|
||||
* -- AR 8/22/1999
|
||||
*/
|
||||
if (retval && !input[0] &&
|
||||
(0
|
||||
#ifdef SKEY
|
||||
|| use_skey
|
||||
#endif
|
||||
#ifdef OPIE
|
||||
|| use_opie
|
||||
#endif
|
||||
)) {
|
||||
strncat(prompt, _("(Echo on) "),
|
||||
(sizeof(prompt) - strlen(prompt)));
|
||||
clear = getpass_with_echo(prompt);
|
||||
if (!clear) {
|
||||
static char c[1];
|
||||
c[0] = '\0';
|
||||
clear = c;
|
||||
}
|
||||
input = clear;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SKEY
|
||||
if (retval && use_skey) {
|
||||
int passcheck = -1;
|
||||
|
||||
if (skeyverify(&skey, input) == 0)
|
||||
passcheck = skey.n;
|
||||
if (passcheck > 0)
|
||||
retval = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef OPIE
|
||||
if (retval && use_opie) {
|
||||
if (opieverify(&opie, input) == 0)
|
||||
retval = 0;
|
||||
}
|
||||
#endif /* OPIE */
|
||||
retval = strcmp (pw_encrypt (input, cipher), cipher);
|
||||
|
||||
/*
|
||||
* Things like RADIUS authentication may need the password -
|
||||
@@ -280,9 +135,9 @@ pw_auth(const char *cipher, const char *user, int reason, const char *input)
|
||||
* not wipe it (the caller should wipe clear_pass when it is
|
||||
* no longer needed). --marekm
|
||||
*/
|
||||
|
||||
clear_pass = clear;
|
||||
if (wipe_clear_pass && clear && *clear)
|
||||
strzero(clear);
|
||||
strzero (clear);
|
||||
return retval;
|
||||
}
|
||||
#endif /* !USE_PAM */
|
||||
|
@@ -26,10 +26,12 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: pwauth.h,v 1.3 2003/05/12 06:08:31 kloczek Exp $
|
||||
* $Id: pwauth.h,v 1.5 2005/03/31 06:24:27 kloczek Exp $
|
||||
*/
|
||||
|
||||
int pw_auth(const char *cipher,const char *user,int flag,const char *input);
|
||||
#ifndef USE_PAM
|
||||
int pw_auth (const char *cipher, const char *user, int flag, const char *input);
|
||||
#endif /* !USE_PAM */
|
||||
|
||||
/*
|
||||
* Local access
|
||||
|
143
lib/pwdbm.c
143
lib/pwdbm.c
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright 1990 - 1994, Julianne Frances Haugh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef NDBM /*{*/
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: pwdbm.c,v 1.4 1997/12/14 20:07:19 marekm Exp $")
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include <ndbm.h>
|
||||
extern DBM *pw_dbm;
|
||||
|
||||
/*
|
||||
* pw_dbm_update
|
||||
*
|
||||
* Updates the DBM password files, if they exist.
|
||||
*/
|
||||
|
||||
int
|
||||
pw_dbm_update(const struct passwd *pw)
|
||||
{
|
||||
datum key;
|
||||
datum content;
|
||||
char data[BUFSIZ];
|
||||
int len;
|
||||
static int once;
|
||||
|
||||
if (! once) {
|
||||
if (! pw_dbm)
|
||||
setpwent ();
|
||||
once++;
|
||||
}
|
||||
if (! pw_dbm)
|
||||
return 0;
|
||||
|
||||
len = pw_pack (pw, data);
|
||||
content.dsize = len;
|
||||
content.dptr = data;
|
||||
|
||||
key.dsize = strlen (pw->pw_name);
|
||||
key.dptr = pw->pw_name;
|
||||
|
||||
if (dbm_store(pw_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* XXX - on systems with 16-bit UIDs (such as Linux/x86)
|
||||
* name "aa" and UID 24929 will give the same key. This
|
||||
* happens only rarely, but code which only "works most
|
||||
* of the time" is not good enough...
|
||||
*
|
||||
* This needs to be fixed in several places (pwdbm.c,
|
||||
* grdbm.c, pwent.c, grent.c). Fixing it will cause
|
||||
* incompatibility with existing dbm files.
|
||||
*
|
||||
* Summary: don't use this stuff for now. --marekm
|
||||
*/
|
||||
|
||||
key.dsize = sizeof pw->pw_uid;
|
||||
key.dptr = (char *) &pw->pw_uid;
|
||||
|
||||
if (dbm_store(pw_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* pw_dbm_remove
|
||||
*
|
||||
* Removes the DBM password entry, if it exists.
|
||||
*/
|
||||
|
||||
int
|
||||
pw_dbm_remove(const struct passwd *pw)
|
||||
{
|
||||
datum key;
|
||||
static int once;
|
||||
char data[BUFSIZ];
|
||||
|
||||
if (! once) {
|
||||
if (! pw_dbm)
|
||||
setpwent ();
|
||||
once++;
|
||||
}
|
||||
if (! pw_dbm)
|
||||
return 0;
|
||||
|
||||
key.dsize = strlen (pw->pw_name);
|
||||
key.dptr = pw->pw_name;
|
||||
|
||||
if (dbm_delete (pw_dbm, key))
|
||||
return 0;
|
||||
|
||||
key.dsize = sizeof pw->pw_uid;
|
||||
key.dptr = (char *) &pw->pw_uid;
|
||||
|
||||
if (dbm_delete (pw_dbm, key))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pw_dbm_present(void)
|
||||
{
|
||||
return (access(PASSWD_PAG_FILE, F_OK) == 0);
|
||||
}
|
||||
#endif /* NDBM */
|
159
lib/pwio.c
159
lib/pwio.c
@@ -2,78 +2,72 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: pwio.c,v 1.13 2003/05/03 16:14:23 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: pwio.c,v 1.14 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "commonio.h"
|
||||
#include "pwio.h"
|
||||
extern struct passwd *sgetpwent (const char *);
|
||||
extern int putpwent (const struct passwd *, FILE *);
|
||||
|
||||
extern struct passwd *sgetpwent(const char *);
|
||||
extern int putpwent(const struct passwd *, FILE *);
|
||||
|
||||
struct passwd *
|
||||
__pw_dup(const struct passwd *pwent)
|
||||
struct passwd *__pw_dup (const struct passwd *pwent)
|
||||
{
|
||||
struct passwd *pw;
|
||||
|
||||
if (!(pw = (struct passwd *) malloc(sizeof *pw)))
|
||||
if (!(pw = (struct passwd *) malloc (sizeof *pw)))
|
||||
return NULL;
|
||||
*pw = *pwent;
|
||||
if (!(pw->pw_name = strdup(pwent->pw_name)))
|
||||
if (!(pw->pw_name = strdup (pwent->pw_name)))
|
||||
return NULL;
|
||||
if (!(pw->pw_passwd = strdup(pwent->pw_passwd)))
|
||||
if (!(pw->pw_passwd = strdup (pwent->pw_passwd)))
|
||||
return NULL;
|
||||
if (!(pw->pw_gecos = strdup(pwent->pw_gecos)))
|
||||
if (!(pw->pw_gecos = strdup (pwent->pw_gecos)))
|
||||
return NULL;
|
||||
if (!(pw->pw_dir = strdup(pwent->pw_dir)))
|
||||
if (!(pw->pw_dir = strdup (pwent->pw_dir)))
|
||||
return NULL;
|
||||
if (!(pw->pw_shell = strdup(pwent->pw_shell)))
|
||||
if (!(pw->pw_shell = strdup (pwent->pw_shell)))
|
||||
return NULL;
|
||||
return pw;
|
||||
}
|
||||
|
||||
static void *
|
||||
passwd_dup(const void *ent)
|
||||
static void *passwd_dup (const void *ent)
|
||||
{
|
||||
const struct passwd *pw = ent;
|
||||
return __pw_dup(pw);
|
||||
|
||||
return __pw_dup (pw);
|
||||
}
|
||||
|
||||
static void
|
||||
passwd_free(void *ent)
|
||||
static void passwd_free (void *ent)
|
||||
{
|
||||
struct passwd *pw = ent;
|
||||
|
||||
free(pw->pw_name);
|
||||
free(pw->pw_passwd);
|
||||
free(pw->pw_gecos);
|
||||
free(pw->pw_dir);
|
||||
free(pw->pw_shell);
|
||||
free(pw);
|
||||
free (pw->pw_name);
|
||||
free (pw->pw_passwd);
|
||||
free (pw->pw_gecos);
|
||||
free (pw->pw_dir);
|
||||
free (pw->pw_shell);
|
||||
free (pw);
|
||||
}
|
||||
|
||||
static const char *
|
||||
passwd_getname(const void *ent)
|
||||
static const char *passwd_getname (const void *ent)
|
||||
{
|
||||
const struct passwd *pw = ent;
|
||||
|
||||
return pw->pw_name;
|
||||
}
|
||||
|
||||
static void *
|
||||
passwd_parse(const char *line)
|
||||
static void *passwd_parse (const char *line)
|
||||
{
|
||||
return (void *) sgetpwent(line);
|
||||
return (void *) sgetpwent (line);
|
||||
}
|
||||
|
||||
static int
|
||||
passwd_put(const void *ent, FILE *file)
|
||||
static int passwd_put (const void *ent, FILE * file)
|
||||
{
|
||||
const struct passwd *pw = ent;
|
||||
return (putpwent(pw, file) == -1) ? -1 : 0;
|
||||
|
||||
return (putpwent (pw, file) == -1) ? -1 : 0;
|
||||
}
|
||||
|
||||
static struct commonio_ops passwd_ops = {
|
||||
@@ -87,108 +81,94 @@ static struct commonio_ops passwd_ops = {
|
||||
};
|
||||
|
||||
static struct commonio_db passwd_db = {
|
||||
PASSWD_FILE, /* filename */
|
||||
&passwd_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
PASSWD_FILE, /* filename */
|
||||
&passwd_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
};
|
||||
|
||||
int
|
||||
pw_name(const char *filename)
|
||||
int pw_name (const char *filename)
|
||||
{
|
||||
return commonio_setname(&passwd_db, filename);
|
||||
return commonio_setname (&passwd_db, filename);
|
||||
}
|
||||
|
||||
int
|
||||
pw_lock(void)
|
||||
int pw_lock (void)
|
||||
{
|
||||
return commonio_lock(&passwd_db);
|
||||
return commonio_lock (&passwd_db);
|
||||
}
|
||||
|
||||
int
|
||||
pw_open(int mode)
|
||||
int pw_open (int mode)
|
||||
{
|
||||
return commonio_open(&passwd_db, mode);
|
||||
return commonio_open (&passwd_db, mode);
|
||||
}
|
||||
|
||||
const struct passwd *
|
||||
pw_locate(const char *name)
|
||||
const struct passwd *pw_locate (const char *name)
|
||||
{
|
||||
return commonio_locate(&passwd_db, name);
|
||||
return commonio_locate (&passwd_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
pw_update(const struct passwd *pw)
|
||||
int pw_update (const struct passwd *pw)
|
||||
{
|
||||
return commonio_update(&passwd_db, (const void *) pw);
|
||||
return commonio_update (&passwd_db, (const void *) pw);
|
||||
}
|
||||
|
||||
int
|
||||
pw_remove(const char *name)
|
||||
int pw_remove (const char *name)
|
||||
{
|
||||
return commonio_remove(&passwd_db, name);
|
||||
return commonio_remove (&passwd_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
pw_rewind(void)
|
||||
int pw_rewind (void)
|
||||
{
|
||||
return commonio_rewind(&passwd_db);
|
||||
return commonio_rewind (&passwd_db);
|
||||
}
|
||||
|
||||
const struct passwd *
|
||||
pw_next(void)
|
||||
const struct passwd *pw_next (void)
|
||||
{
|
||||
return commonio_next(&passwd_db);
|
||||
return commonio_next (&passwd_db);
|
||||
}
|
||||
|
||||
int
|
||||
pw_close(void)
|
||||
int pw_close (void)
|
||||
{
|
||||
return commonio_close(&passwd_db);
|
||||
return commonio_close (&passwd_db);
|
||||
}
|
||||
|
||||
int
|
||||
pw_unlock(void)
|
||||
int pw_unlock (void)
|
||||
{
|
||||
return commonio_unlock(&passwd_db);
|
||||
return commonio_unlock (&passwd_db);
|
||||
}
|
||||
|
||||
struct commonio_entry *
|
||||
__pw_get_head(void)
|
||||
struct commonio_entry *__pw_get_head (void)
|
||||
{
|
||||
return passwd_db.head;
|
||||
}
|
||||
|
||||
void
|
||||
__pw_del_entry(const struct commonio_entry *ent)
|
||||
void __pw_del_entry (const struct commonio_entry *ent)
|
||||
{
|
||||
commonio_del_entry(&passwd_db, ent);
|
||||
commonio_del_entry (&passwd_db, ent);
|
||||
}
|
||||
|
||||
struct commonio_db *
|
||||
__pw_get_db(void)
|
||||
struct commonio_db *__pw_get_db (void)
|
||||
{
|
||||
return &passwd_db;
|
||||
}
|
||||
|
||||
static int
|
||||
pw_cmp(const void *p1, const void *p2)
|
||||
static int pw_cmp (const void *p1, const void *p2)
|
||||
{
|
||||
uid_t u1, u2;
|
||||
|
||||
if ((*(struct commonio_entry**)p1)->eptr == NULL)
|
||||
if ((*(struct commonio_entry **) p1)->eptr == NULL)
|
||||
return 1;
|
||||
if ((*(struct commonio_entry**)p2)->eptr == NULL)
|
||||
if ((*(struct commonio_entry **) p2)->eptr == NULL)
|
||||
return -1;
|
||||
|
||||
u1 = ((struct passwd *)(*(struct commonio_entry**)p1)->eptr)->pw_uid;
|
||||
u2 = ((struct passwd *)(*(struct commonio_entry**)p2)->eptr)->pw_uid;
|
||||
|
||||
u1 = ((struct passwd *) (*(struct commonio_entry **) p1)->eptr)->pw_uid;
|
||||
u2 = ((struct passwd *) (*(struct commonio_entry **) p2)->eptr)->pw_uid;
|
||||
|
||||
if (u1 < u2)
|
||||
return -1;
|
||||
@@ -199,8 +179,7 @@ pw_cmp(const void *p1, const void *p2)
|
||||
}
|
||||
|
||||
/* Sort entries by uid */
|
||||
int
|
||||
pw_sort()
|
||||
int pw_sort ()
|
||||
{
|
||||
return commonio_sort(&passwd_db, pw_cmp);
|
||||
return commonio_sort (&passwd_db, pw_cmp);
|
||||
}
|
||||
|
26
lib/pwio.h
26
lib/pwio.h
@@ -1,13 +1,13 @@
|
||||
extern struct passwd *__pw_dup(const struct passwd *);
|
||||
extern void __pw_set_changed(void);
|
||||
extern int pw_close(void);
|
||||
extern const struct passwd *pw_locate(const char *);
|
||||
extern int pw_lock(void);
|
||||
extern int pw_name(const char *);
|
||||
extern const struct passwd *pw_next(void);
|
||||
extern int pw_open(int);
|
||||
extern int pw_remove(const char *);
|
||||
extern int pw_rewind(void);
|
||||
extern int pw_unlock(void);
|
||||
extern int pw_update(const struct passwd *);
|
||||
extern int pw_sort(void);
|
||||
extern struct passwd *__pw_dup (const struct passwd *);
|
||||
extern void __pw_set_changed (void);
|
||||
extern int pw_close (void);
|
||||
extern const struct passwd *pw_locate (const char *);
|
||||
extern int pw_lock (void);
|
||||
extern int pw_name (const char *);
|
||||
extern const struct passwd *pw_next (void);
|
||||
extern int pw_open (int);
|
||||
extern int pw_remove (const char *);
|
||||
extern int pw_rewind (void);
|
||||
extern int pw_unlock (void);
|
||||
extern int pw_update (const struct passwd *);
|
||||
extern int pw_sort (void);
|
||||
|
20
lib/pwpack.c
20
lib/pwpack.c
@@ -30,23 +30,18 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: pwpack.c,v 1.6 2003/12/17 01:33:28 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: pwpack.c,v 1.7 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
||||
|
||||
/*
|
||||
* pw_pack - convert a (struct pwd) to a packed record
|
||||
* WARNING: buf must be large enough, no check for overrun!
|
||||
*/
|
||||
|
||||
int
|
||||
pw_pack(const struct passwd *passwd, char *buf)
|
||||
int pw_pack (const struct passwd *passwd, char *buf)
|
||||
{
|
||||
char *cp;
|
||||
char *cp;
|
||||
|
||||
cp = buf;
|
||||
strcpy (cp, passwd->pw_name);
|
||||
@@ -68,7 +63,7 @@ pw_pack(const struct passwd *passwd, char *buf)
|
||||
cp += strlen (cp) + 1;
|
||||
|
||||
strcpy (cp, passwd->pw_shell);
|
||||
cp += strlen (cp) + 1;
|
||||
cp += strlen (cp) + 1;
|
||||
|
||||
return cp - buf;
|
||||
}
|
||||
@@ -77,12 +72,11 @@ pw_pack(const struct passwd *passwd, char *buf)
|
||||
* pw_unpack - convert a packed (struct pwd) record to a (struct pwd)
|
||||
*/
|
||||
|
||||
int
|
||||
pw_unpack(char *buf, int len, struct passwd *passwd)
|
||||
int pw_unpack (char *buf, int len, struct passwd *passwd)
|
||||
{
|
||||
char *org = buf;
|
||||
char *org = buf;
|
||||
|
||||
memzero(passwd, sizeof *passwd);
|
||||
memzero (passwd, sizeof *passwd);
|
||||
|
||||
passwd->pw_name = buf;
|
||||
buf += strlen (buf) + 1;
|
||||
|
126
lib/rad64.c
126
lib/rad64.c
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright 1989 - 1992, Julianne Frances Haugh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: rad64.c,v 1.5 2000/08/26 18:27:17 marekm Exp $")
|
||||
|
||||
/*
|
||||
* c64i - convert a radix 64 character to an integer
|
||||
*/
|
||||
|
||||
int
|
||||
c64i(int c)
|
||||
{
|
||||
if (c == '.')
|
||||
return (0);
|
||||
|
||||
if (c == '/')
|
||||
return (1);
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
return (c - '0' + 2);
|
||||
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c - 'A' + 12);
|
||||
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 'a' + 38);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* i64c - convert an integer to a radix 64 character
|
||||
*/
|
||||
|
||||
int
|
||||
i64c(int i)
|
||||
{
|
||||
if (i <= 0)
|
||||
return ('.');
|
||||
|
||||
if (i == 1)
|
||||
return ('/');
|
||||
|
||||
if (i >= 2 && i < 12)
|
||||
return ('0' - 2 + i);
|
||||
|
||||
if (i >= 12 && i < 38)
|
||||
return ('A' - 12 + i);
|
||||
|
||||
if (i >= 38 && i < 63)
|
||||
return ('a' - 38 + i);
|
||||
|
||||
return ('z');
|
||||
}
|
||||
|
||||
#ifndef HAVE_A64L
|
||||
|
||||
/*
|
||||
* l64a - convert a long to a string of radix 64 characters
|
||||
*/
|
||||
|
||||
char *
|
||||
l64a(long l)
|
||||
{
|
||||
static char buf[8];
|
||||
int i = 0;
|
||||
|
||||
if (l < 0L)
|
||||
return ((char *) 0);
|
||||
|
||||
do {
|
||||
buf[i++] = i64c ((int) (l % 64));
|
||||
buf[i] = '\0';
|
||||
} while (l /= 64L, l > 0 && i < 6);
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* a64l - convert a radix 64 string to a long integer
|
||||
*/
|
||||
|
||||
long
|
||||
a64l(const char *s)
|
||||
{
|
||||
int i;
|
||||
long value;
|
||||
long shift = 0;
|
||||
|
||||
for (i = 0, value = 0L;i < 6 && *s;s++) {
|
||||
value += (c64i ((int) *s) << shift);
|
||||
shift += 6;
|
||||
}
|
||||
return (value);
|
||||
}
|
||||
|
||||
#endif /* !HAVE_A64L */
|
11
lib/rcsid.h
11
lib/rcsid.h
@@ -1,22 +1,23 @@
|
||||
/*
|
||||
* $Id: rcsid.h,v 1.2 1999/06/07 16:40:44 marekm Exp $
|
||||
* $Id: rcsid.h,v 1.3 2005/03/31 05:14:49 kloczek Exp $
|
||||
*/
|
||||
#define PKG_VER " $Package: " PACKAGE " $ $Version: " VERSION " $ "
|
||||
#if defined(NO_RCSID) || defined(lint)
|
||||
#define RCSID(x) /* empty */
|
||||
#define RCSID(x) /* empty */
|
||||
#else
|
||||
#if __STDC__
|
||||
/*
|
||||
* This function is never called from anywhere, but it calls itself
|
||||
* recursively only to fool gcc to not generate warnings :-).
|
||||
*/
|
||||
static const char *rcsid(const char *);
|
||||
static const char *rcsid (const char *);
|
||||
|
||||
#define RCSID(x) \
|
||||
static const char *rcsid(const char *s) { \
|
||||
return rcsid(x); }
|
||||
#else /* ! __STDC__ */
|
||||
#else /* ! __STDC__ */
|
||||
#define RCSID(x) \
|
||||
static char *rcsid(s) char *s; { \
|
||||
return rcsid(x); }
|
||||
#endif /* ! __STDC__ */
|
||||
#endif /* ! __STDC__ */
|
||||
#endif
|
||||
|
@@ -30,14 +30,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: sgetgrent.c,v 1.4 1998/04/02 21:51:45 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: sgetgrent.c,v 1.5 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include "defines.h"
|
||||
|
||||
#define NFIELDS 4
|
||||
|
||||
/*
|
||||
* list - turn a comma-separated string into an array of (char *)'s
|
||||
*
|
||||
@@ -51,12 +48,10 @@ RCSID("$Id: sgetgrent.c,v 1.4 1998/04/02 21:51:45 marekm Exp $")
|
||||
* FINALLY added dynamic allocation. Still need to fix sgetsgent().
|
||||
* --marekm
|
||||
*/
|
||||
|
||||
static char **
|
||||
list(char *s)
|
||||
static char **list (char *s)
|
||||
{
|
||||
static char **members = 0;
|
||||
static int size = 0; /* max members + 1 */
|
||||
static int size = 0; /* max members + 1 */
|
||||
int i;
|
||||
char **rbuf;
|
||||
|
||||
@@ -65,17 +60,18 @@ list(char *s)
|
||||
/* check if there is room for another pointer (to a group
|
||||
member name, or terminating NULL). */
|
||||
if (i >= size) {
|
||||
size = i + 100; /* at least: i + 1 */
|
||||
size = i + 100; /* at least: i + 1 */
|
||||
if (members) {
|
||||
rbuf = realloc(members, size * sizeof(char *));
|
||||
rbuf =
|
||||
realloc (members, size * sizeof (char *));
|
||||
} else {
|
||||
/* for old (before ANSI C) implementations of
|
||||
realloc() that don't handle NULL properly */
|
||||
rbuf = malloc(size * sizeof(char *));
|
||||
rbuf = malloc (size * sizeof (char *));
|
||||
}
|
||||
if (!rbuf) {
|
||||
if (members)
|
||||
free(members);
|
||||
free (members);
|
||||
members = 0;
|
||||
size = 0;
|
||||
return (char **) 0;
|
||||
@@ -95,46 +91,45 @@ list(char *s)
|
||||
}
|
||||
|
||||
|
||||
struct group *
|
||||
sgetgrent(const char *buf)
|
||||
struct group *sgetgrent (const char *buf)
|
||||
{
|
||||
static char *grpbuf = 0;
|
||||
static size_t size = 0;
|
||||
static char *grpfields[NFIELDS];
|
||||
static struct group grent;
|
||||
int i;
|
||||
char *cp;
|
||||
int i;
|
||||
char *cp;
|
||||
|
||||
if (strlen(buf) + 1 > size) {
|
||||
if (strlen (buf) + 1 > size) {
|
||||
/* no need to use realloc() here - just free it and
|
||||
allocate a larger block */
|
||||
if (grpbuf)
|
||||
free(grpbuf);
|
||||
size = strlen(buf) + 1000; /* at least: strlen(buf) + 1 */
|
||||
grpbuf = malloc(size);
|
||||
free (grpbuf);
|
||||
size = strlen (buf) + 1000; /* at least: strlen(buf) + 1 */
|
||||
grpbuf = malloc (size);
|
||||
if (!grpbuf) {
|
||||
size = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
strcpy(grpbuf, buf);
|
||||
strcpy (grpbuf, buf);
|
||||
|
||||
if ((cp = strrchr(grpbuf, '\n')))
|
||||
if ((cp = strrchr (grpbuf, '\n')))
|
||||
*cp = '\0';
|
||||
|
||||
for (cp = grpbuf, i = 0; i < NFIELDS && cp; i++) {
|
||||
grpfields[i] = cp;
|
||||
if ((cp = strchr(cp, ':')))
|
||||
if ((cp = strchr (cp, ':')))
|
||||
*cp++ = 0;
|
||||
}
|
||||
if (i < (NFIELDS-1) || *grpfields[2] == '\0')
|
||||
if (i < (NFIELDS - 1) || *grpfields[2] == '\0')
|
||||
return 0;
|
||||
grent.gr_name = grpfields[0];
|
||||
grent.gr_passwd = grpfields[1];
|
||||
grent.gr_gid = atoi(grpfields[2]);
|
||||
grent.gr_mem = list(grpfields[3]);
|
||||
grent.gr_gid = atoi (grpfields[2]);
|
||||
grent.gr_mem = list (grpfields[3]);
|
||||
if (!grent.gr_mem)
|
||||
return (struct group *) 0; /* out of memory */
|
||||
return (struct group *) 0; /* out of memory */
|
||||
|
||||
return &grent;
|
||||
}
|
||||
|
@@ -30,15 +30,12 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: sgetpwent.c,v 1.6 2003/05/03 16:14:23 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: sgetpwent.c,v 1.7 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#define NFIELDS 7
|
||||
|
||||
/*
|
||||
* sgetpwent - convert a string to a (struct passwd)
|
||||
*
|
||||
@@ -51,15 +48,13 @@ RCSID("$Id: sgetpwent.c,v 1.6 2003/05/03 16:14:23 kloczek Exp $")
|
||||
* performance reasons. I am going to come up with some conditional
|
||||
* compilation glarp to improve on this in the future.
|
||||
*/
|
||||
|
||||
struct passwd *
|
||||
sgetpwent(const char *buf)
|
||||
struct passwd *sgetpwent (const char *buf)
|
||||
{
|
||||
static struct passwd pwent;
|
||||
static char pwdbuf[1024];
|
||||
register int i;
|
||||
register char *cp;
|
||||
char *ep;
|
||||
register int i;
|
||||
register char *cp;
|
||||
char *ep;
|
||||
char *fields[NFIELDS];
|
||||
|
||||
/*
|
||||
@@ -67,20 +62,20 @@ sgetpwent(const char *buf)
|
||||
* the password structure remain valid.
|
||||
*/
|
||||
|
||||
if (strlen(buf) >= sizeof pwdbuf)
|
||||
return 0; /* fail if too long */
|
||||
strcpy(pwdbuf, buf);
|
||||
if (strlen (buf) >= sizeof pwdbuf)
|
||||
return 0; /* fail if too long */
|
||||
strcpy (pwdbuf, buf);
|
||||
|
||||
/*
|
||||
* Save a pointer to the start of each colon separated
|
||||
* field. The fields are converted into NUL terminated strings.
|
||||
*/
|
||||
|
||||
for (cp = pwdbuf, i = 0;i < NFIELDS && cp;i++) {
|
||||
for (cp = pwdbuf, i = 0; i < NFIELDS && cp; i++) {
|
||||
fields[i] = cp;
|
||||
while (*cp && *cp != ':')
|
||||
++cp;
|
||||
|
||||
|
||||
if (*cp)
|
||||
*cp++ = '\0';
|
||||
else
|
||||
@@ -105,11 +100,11 @@ sgetpwent(const char *buf)
|
||||
pwent.pw_name = fields[0];
|
||||
pwent.pw_passwd = fields[1];
|
||||
if (fields[2][0] == '\0' ||
|
||||
((pwent.pw_uid = strtol (fields[2], &ep, 10)) == 0 && *ep)) {
|
||||
((pwent.pw_uid = strtol (fields[2], &ep, 10)) == 0 && *ep)) {
|
||||
return 0;
|
||||
}
|
||||
if (fields[3][0] == '\0' ||
|
||||
((pwent.pw_gid = strtol (fields[3], &ep, 10)) == 0 && *ep)) {
|
||||
((pwent.pw_gid = strtol (fields[3], &ep, 10)) == 0 && *ep)) {
|
||||
return 0;
|
||||
}
|
||||
pwent.pw_gecos = fields[4];
|
||||
|
165
lib/sgroupio.c
165
lib/sgroupio.c
@@ -4,50 +4,44 @@
|
||||
#ifdef SHADOWGRP
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: sgroupio.c,v 1.12 2001/08/14 21:10:36 malekith Exp $")
|
||||
|
||||
RCSID ("$Id: sgroupio.c,v 1.13 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include "commonio.h"
|
||||
#include "sgroupio.h"
|
||||
extern int putsgent (const struct sgrp *, FILE *);
|
||||
extern struct sgrp *sgetsgent (const char *);
|
||||
|
||||
extern int putsgent(const struct sgrp *, FILE *);
|
||||
extern struct sgrp *sgetsgent(const char *);
|
||||
|
||||
struct sgrp *
|
||||
__sgr_dup(const struct sgrp *sgent)
|
||||
struct sgrp *__sgr_dup (const struct sgrp *sgent)
|
||||
{
|
||||
struct sgrp *sg;
|
||||
int i;
|
||||
|
||||
if (!(sg = (struct sgrp *) malloc(sizeof *sg)))
|
||||
if (!(sg = (struct sgrp *) malloc (sizeof *sg)))
|
||||
return NULL;
|
||||
*sg = *sgent;
|
||||
if (!(sg->sg_name = strdup(sgent->sg_name)))
|
||||
if (!(sg->sg_name = strdup (sgent->sg_name)))
|
||||
return NULL;
|
||||
if (!(sg->sg_passwd = strdup(sgent->sg_passwd)))
|
||||
if (!(sg->sg_passwd = strdup (sgent->sg_passwd)))
|
||||
return NULL;
|
||||
|
||||
for (i = 0; sgent->sg_adm[i]; i++)
|
||||
;
|
||||
sg->sg_adm = (char **) malloc((i + 1) * sizeof(char *));
|
||||
for (i = 0; sgent->sg_adm[i]; i++);
|
||||
sg->sg_adm = (char **) malloc ((i + 1) * sizeof (char *));
|
||||
if (!sg->sg_adm)
|
||||
return NULL;
|
||||
for (i = 0; sgent->sg_adm[i]; i++) {
|
||||
sg->sg_adm[i] = strdup(sgent->sg_adm[i]);
|
||||
sg->sg_adm[i] = strdup (sgent->sg_adm[i]);
|
||||
if (!sg->sg_adm[i])
|
||||
return NULL;
|
||||
}
|
||||
sg->sg_adm[i] = NULL;
|
||||
|
||||
for (i = 0; sgent->sg_mem[i]; i++)
|
||||
;
|
||||
sg->sg_mem = (char **) malloc((i + 1) * sizeof(char *));
|
||||
for (i = 0; sgent->sg_mem[i]; i++);
|
||||
sg->sg_mem = (char **) malloc ((i + 1) * sizeof (char *));
|
||||
if (!sg->sg_mem)
|
||||
return NULL;
|
||||
for (i = 0; sgent->sg_mem[i]; i++) {
|
||||
sg->sg_mem[i] = strdup(sgent->sg_mem[i]);
|
||||
sg->sg_mem[i] = strdup (sgent->sg_mem[i]);
|
||||
if (!sg->sg_mem[i])
|
||||
return NULL;
|
||||
}
|
||||
@@ -56,49 +50,47 @@ __sgr_dup(const struct sgrp *sgent)
|
||||
return sg;
|
||||
}
|
||||
|
||||
static void *
|
||||
gshadow_dup(const void *ent)
|
||||
static void *gshadow_dup (const void *ent)
|
||||
{
|
||||
const struct sgrp *sg = ent;
|
||||
return __sgr_dup(sg);
|
||||
|
||||
return __sgr_dup (sg);
|
||||
}
|
||||
|
||||
static void
|
||||
gshadow_free(void *ent)
|
||||
static void gshadow_free (void *ent)
|
||||
{
|
||||
struct sgrp *sg = ent;
|
||||
|
||||
free(sg->sg_name);
|
||||
free(sg->sg_passwd);
|
||||
while(*(sg->sg_adm)) {
|
||||
free(*(sg->sg_adm));
|
||||
free (sg->sg_name);
|
||||
free (sg->sg_passwd);
|
||||
while (*(sg->sg_adm)) {
|
||||
free (*(sg->sg_adm));
|
||||
sg->sg_adm++;
|
||||
}
|
||||
while(*(sg->sg_mem)) {
|
||||
free(*(sg->sg_mem));
|
||||
while (*(sg->sg_mem)) {
|
||||
free (*(sg->sg_mem));
|
||||
sg->sg_mem++;
|
||||
}
|
||||
free(sg);
|
||||
free (sg);
|
||||
}
|
||||
|
||||
static const char *
|
||||
gshadow_getname(const void *ent)
|
||||
static const char *gshadow_getname (const void *ent)
|
||||
{
|
||||
const struct sgrp *gr = ent;
|
||||
|
||||
return gr->sg_name;
|
||||
}
|
||||
|
||||
static void *
|
||||
gshadow_parse(const char *line)
|
||||
static void *gshadow_parse (const char *line)
|
||||
{
|
||||
return (void *) sgetsgent(line);
|
||||
return (void *) sgetsgent (line);
|
||||
}
|
||||
|
||||
static int
|
||||
gshadow_put(const void *ent, FILE *file)
|
||||
static int gshadow_put (const void *ent, FILE * file)
|
||||
{
|
||||
const struct sgrp *sg = ent;
|
||||
return (putsgent(sg, file) == -1) ? -1 : 0;
|
||||
|
||||
return (putsgent (sg, file) == -1) ? -1 : 0;
|
||||
}
|
||||
|
||||
static struct commonio_ops gshadow_ops = {
|
||||
@@ -112,110 +104,95 @@ static struct commonio_ops gshadow_ops = {
|
||||
};
|
||||
|
||||
static struct commonio_db gshadow_db = {
|
||||
SGROUP_FILE, /* filename */
|
||||
&gshadow_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
SGROUP_FILE, /* filename */
|
||||
&gshadow_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
};
|
||||
|
||||
int
|
||||
sgr_name(const char *filename)
|
||||
int sgr_name (const char *filename)
|
||||
{
|
||||
return commonio_setname(&gshadow_db, filename);
|
||||
return commonio_setname (&gshadow_db, filename);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_file_present(void)
|
||||
int sgr_file_present (void)
|
||||
{
|
||||
return commonio_present(&gshadow_db);
|
||||
return commonio_present (&gshadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_lock(void)
|
||||
int sgr_lock (void)
|
||||
{
|
||||
return commonio_lock(&gshadow_db);
|
||||
return commonio_lock (&gshadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_open(int mode)
|
||||
int sgr_open (int mode)
|
||||
{
|
||||
return commonio_open(&gshadow_db, mode);
|
||||
return commonio_open (&gshadow_db, mode);
|
||||
}
|
||||
|
||||
const struct sgrp *
|
||||
sgr_locate(const char *name)
|
||||
const struct sgrp *sgr_locate (const char *name)
|
||||
{
|
||||
return commonio_locate(&gshadow_db, name);
|
||||
return commonio_locate (&gshadow_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_update(const struct sgrp *sg)
|
||||
int sgr_update (const struct sgrp *sg)
|
||||
{
|
||||
return commonio_update(&gshadow_db, (const void *) sg);
|
||||
return commonio_update (&gshadow_db, (const void *) sg);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_remove(const char *name)
|
||||
int sgr_remove (const char *name)
|
||||
{
|
||||
return commonio_remove(&gshadow_db, name);
|
||||
return commonio_remove (&gshadow_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_rewind(void)
|
||||
int sgr_rewind (void)
|
||||
{
|
||||
return commonio_rewind(&gshadow_db);
|
||||
return commonio_rewind (&gshadow_db);
|
||||
}
|
||||
|
||||
const struct sgrp *
|
||||
sgr_next(void)
|
||||
const struct sgrp *sgr_next (void)
|
||||
{
|
||||
return commonio_next(&gshadow_db);
|
||||
return commonio_next (&gshadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_close(void)
|
||||
int sgr_close (void)
|
||||
{
|
||||
return commonio_close(&gshadow_db);
|
||||
return commonio_close (&gshadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
sgr_unlock(void)
|
||||
int sgr_unlock (void)
|
||||
{
|
||||
return commonio_unlock(&gshadow_db);
|
||||
return commonio_unlock (&gshadow_db);
|
||||
}
|
||||
|
||||
void
|
||||
__sgr_set_changed(void)
|
||||
void __sgr_set_changed (void)
|
||||
{
|
||||
gshadow_db.changed = 1;
|
||||
}
|
||||
|
||||
struct commonio_entry *
|
||||
__sgr_get_head(void)
|
||||
struct commonio_entry *__sgr_get_head (void)
|
||||
{
|
||||
return gshadow_db.head;
|
||||
}
|
||||
|
||||
void
|
||||
__sgr_del_entry(const struct commonio_entry *ent)
|
||||
void __sgr_del_entry (const struct commonio_entry *ent)
|
||||
{
|
||||
commonio_del_entry(&gshadow_db, ent);
|
||||
commonio_del_entry (&gshadow_db, ent);
|
||||
}
|
||||
|
||||
/* Sort with respect to group ordering. */
|
||||
int
|
||||
sgr_sort()
|
||||
int sgr_sort ()
|
||||
{
|
||||
extern struct commonio_db *__gr_get_db();
|
||||
extern struct commonio_db *__gr_get_db ();
|
||||
|
||||
return commonio_sort_wrt(&gshadow_db, __gr_get_db());
|
||||
return commonio_sort_wrt (&gshadow_db, __gr_get_db ());
|
||||
}
|
||||
#else
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
#endif
|
||||
|
@@ -1,14 +1,14 @@
|
||||
extern struct sgrp *__sgr_dup(const struct sgrp *);
|
||||
extern void __sgr_set_changed(void);
|
||||
extern int sgr_close(void);
|
||||
extern int sgr_file_present(void);
|
||||
extern const struct sgrp *sgr_locate(const char *);
|
||||
extern int sgr_lock(void);
|
||||
extern int sgr_name(const char *);
|
||||
extern const struct sgrp *sgr_next(void);
|
||||
extern int sgr_open(int);
|
||||
extern int sgr_remove(const char *);
|
||||
extern int sgr_rewind(void);
|
||||
extern int sgr_unlock(void);
|
||||
extern int sgr_update(const struct sgrp *);
|
||||
extern int sgr_sort(void);
|
||||
extern struct sgrp *__sgr_dup (const struct sgrp *);
|
||||
extern void __sgr_set_changed (void);
|
||||
extern int sgr_close (void);
|
||||
extern int sgr_file_present (void);
|
||||
extern const struct sgrp *sgr_locate (const char *);
|
||||
extern int sgr_lock (void);
|
||||
extern int sgr_name (const char *);
|
||||
extern const struct sgrp *sgr_next (void);
|
||||
extern int sgr_open (int);
|
||||
extern int sgr_remove (const char *);
|
||||
extern int sgr_rewind (void);
|
||||
extern int sgr_unlock (void);
|
||||
extern int sgr_update (const struct sgrp *);
|
||||
extern int sgr_sort (void);
|
||||
|
214
lib/shadow.c
214
lib/shadow.c
@@ -30,41 +30,32 @@
|
||||
#include <config.h>
|
||||
|
||||
/* Newer versions of Linux libc already have shadow support. */
|
||||
#if defined(SHADOWPWD) && !defined(HAVE_GETSPNAM) /*{*/
|
||||
#if defined(SHADOWPWD) && !defined(HAVE_GETSPNAM) /*{ */
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: shadow.c,v 1.7 2003/05/03 16:14:24 kloczek Exp $")
|
||||
|
||||
RCSID ("$Id: shadow.c,v 1.9 2005/04/06 04:26:05 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef NDBM
|
||||
#include <ndbm.h>
|
||||
#include <fcntl.h>
|
||||
DBM *sp_dbm;
|
||||
int sp_dbm_mode = -1;
|
||||
static int dbmopened;
|
||||
static int dbmerror;
|
||||
#endif
|
||||
|
||||
#ifdef USE_NIS
|
||||
static int nis_used;
|
||||
static int nis_ignore;
|
||||
static enum { native, start, middle, native2 } nis_state;
|
||||
static int nis_bound;
|
||||
static char *nis_domain;
|
||||
static char *nis_key;
|
||||
static int nis_keylen;
|
||||
static char *nis_val;
|
||||
static int nis_vallen;
|
||||
static int nis_used;
|
||||
static int nis_ignore;
|
||||
static enum { native, start, middle, native2 } nis_state;
|
||||
static int nis_bound;
|
||||
static char *nis_domain;
|
||||
static char *nis_key;
|
||||
static int nis_keylen;
|
||||
static char *nis_val;
|
||||
static int nis_vallen;
|
||||
|
||||
#define IS_NISCHAR(c) ((c)=='+')
|
||||
#endif
|
||||
|
||||
static FILE *shadow;
|
||||
static char spwbuf[BUFSIZ];
|
||||
static struct spwd spwd;
|
||||
static FILE *shadow;
|
||||
static char spwbuf[BUFSIZ];
|
||||
static struct spwd spwd;
|
||||
|
||||
#define FIELDS 9
|
||||
#define OFIELDS 5
|
||||
@@ -75,10 +66,9 @@ static struct spwd spwd;
|
||||
* __setspNIS - turn on or off NIS searches
|
||||
*/
|
||||
|
||||
void
|
||||
__setspNIS(int flag)
|
||||
void __setspNIS (int flag)
|
||||
{
|
||||
nis_ignore = ! flag;
|
||||
nis_ignore = !flag;
|
||||
|
||||
if (nis_ignore)
|
||||
nis_used = 0;
|
||||
@@ -88,8 +78,7 @@ __setspNIS(int flag)
|
||||
* bind_nis - bind to NIS server
|
||||
*/
|
||||
|
||||
static int
|
||||
bind_nis(void)
|
||||
static int bind_nis (void)
|
||||
{
|
||||
if (yp_get_default_domain (&nis_domain))
|
||||
return -1;
|
||||
@@ -103,84 +92,49 @@ bind_nis(void)
|
||||
* setspent - initialize access to shadow text and DBM files
|
||||
*/
|
||||
|
||||
void
|
||||
setspent(void)
|
||||
void setspent (void)
|
||||
{
|
||||
if (shadow)
|
||||
rewind(shadow);
|
||||
rewind (shadow);
|
||||
else
|
||||
shadow = fopen(SHADOW_FILE, "r");
|
||||
shadow = fopen (SHADOW_FILE, "r");
|
||||
|
||||
#ifdef USE_NIS
|
||||
nis_state = native;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Attempt to open the DBM files if they have never been opened
|
||||
* and an error has never been returned.
|
||||
*/
|
||||
|
||||
#ifdef NDBM
|
||||
if (! dbmerror && ! dbmopened) {
|
||||
int mode;
|
||||
char dbmfiles[BUFSIZ];
|
||||
|
||||
strcpy (dbmfiles, SHADOW_PAG_FILE);
|
||||
|
||||
if (sp_dbm_mode == -1)
|
||||
mode = O_RDWR;
|
||||
else
|
||||
mode = (sp_dbm_mode == O_RDWR) ? O_RDWR:O_RDONLY;
|
||||
|
||||
if (! (sp_dbm = dbm_open (SHADOW_FILE, mode, 0)))
|
||||
dbmerror = 1;
|
||||
else
|
||||
dbmopened = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* endspent - terminate access to shadow text and DBM files
|
||||
*/
|
||||
|
||||
void
|
||||
endspent(void)
|
||||
void endspent (void)
|
||||
{
|
||||
if (shadow)
|
||||
(void) fclose (shadow);
|
||||
|
||||
shadow = (FILE *) 0;
|
||||
#ifdef NDBM
|
||||
if (dbmopened && sp_dbm) {
|
||||
dbm_close (sp_dbm);
|
||||
sp_dbm = 0;
|
||||
}
|
||||
dbmopened = 0;
|
||||
dbmerror = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* my_sgetspent - convert string in shadow file format to (struct spwd *)
|
||||
*/
|
||||
|
||||
static struct spwd *
|
||||
my_sgetspent(const char *string)
|
||||
static struct spwd *my_sgetspent (const char *string)
|
||||
{
|
||||
char *fields[FIELDS];
|
||||
char *cp;
|
||||
char *cpp;
|
||||
int i;
|
||||
char *fields[FIELDS];
|
||||
char *cp;
|
||||
char *cpp;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Copy string to local buffer. It has to be tokenized and we
|
||||
* have to do that to our private copy.
|
||||
*/
|
||||
|
||||
if (strlen(string) >= sizeof spwbuf)
|
||||
if (strlen (string) >= sizeof spwbuf)
|
||||
return 0;
|
||||
strcpy(spwbuf, string);
|
||||
strcpy (spwbuf, string);
|
||||
|
||||
if ((cp = strrchr (spwbuf, '\n')))
|
||||
*cp = '\0';
|
||||
@@ -190,7 +144,7 @@ my_sgetspent(const char *string)
|
||||
* FIELDS different fields.
|
||||
*/
|
||||
|
||||
for (cp = spwbuf, i = 0;*cp && i < FIELDS;i++) {
|
||||
for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
|
||||
fields[i] = cp;
|
||||
while (*cp && *cp != ':')
|
||||
cp++;
|
||||
@@ -199,7 +153,7 @@ my_sgetspent(const char *string)
|
||||
*cp++ = '\0';
|
||||
}
|
||||
|
||||
if (i == (FIELDS-1))
|
||||
if (i == (FIELDS - 1))
|
||||
fields[i++] = cp;
|
||||
|
||||
if ((cp && *cp) || (i != FIELDS && i != OFIELDS))
|
||||
@@ -227,7 +181,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if ((spwd.sp_lstchg = strtol (fields[2], &cpp, 10)) == 0 && *cpp) {
|
||||
#ifdef USE_NIS
|
||||
if (! nis_used)
|
||||
if (!nis_used)
|
||||
return 0;
|
||||
else
|
||||
spwd.sp_lstchg = -1;
|
||||
@@ -243,7 +197,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if ((spwd.sp_min = strtol (fields[3], &cpp, 10)) == 0 && *cpp) {
|
||||
#ifdef USE_NIS
|
||||
if (! nis_used)
|
||||
if (!nis_used)
|
||||
return 0;
|
||||
else
|
||||
spwd.sp_min = -1;
|
||||
@@ -259,7 +213,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if ((spwd.sp_max = strtol (fields[4], &cpp, 10)) == 0 && *cpp) {
|
||||
#ifdef USE_NIS
|
||||
if (! nis_used)
|
||||
if (!nis_used)
|
||||
return 0;
|
||||
else
|
||||
spwd.sp_max = -1;
|
||||
@@ -276,7 +230,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if (i == OFIELDS) {
|
||||
spwd.sp_warn = spwd.sp_inact = spwd.sp_expire =
|
||||
spwd.sp_flag = -1;
|
||||
spwd.sp_flag = -1;
|
||||
|
||||
return &spwd;
|
||||
}
|
||||
@@ -287,7 +241,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if ((spwd.sp_warn = strtol (fields[5], &cpp, 10)) == 0 && *cpp) {
|
||||
#ifdef USE_NIS
|
||||
if (! nis_used)
|
||||
if (!nis_used)
|
||||
return 0;
|
||||
else
|
||||
spwd.sp_warn = -1;
|
||||
@@ -304,7 +258,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if ((spwd.sp_inact = strtol (fields[6], &cpp, 10)) == 0 && *cpp) {
|
||||
#ifdef USE_NIS
|
||||
if (! nis_used)
|
||||
if (!nis_used)
|
||||
return 0;
|
||||
else
|
||||
spwd.sp_inact = -1;
|
||||
@@ -321,7 +275,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if ((spwd.sp_expire = strtol (fields[7], &cpp, 10)) == 0 && *cpp) {
|
||||
#ifdef USE_NIS
|
||||
if (! nis_used)
|
||||
if (!nis_used)
|
||||
return 0;
|
||||
else
|
||||
spwd.sp_expire = -1;
|
||||
@@ -338,7 +292,7 @@ my_sgetspent(const char *string)
|
||||
|
||||
if ((spwd.sp_flag = strtol (fields[8], &cpp, 10)) == 0 && *cpp) {
|
||||
#ifdef USE_NIS
|
||||
if (! nis_used)
|
||||
if (!nis_used)
|
||||
return 0;
|
||||
else
|
||||
spwd.sp_flag = -1;
|
||||
@@ -355,13 +309,12 @@ my_sgetspent(const char *string)
|
||||
* fgetspent - get an entry from a /etc/shadow formatted stream
|
||||
*/
|
||||
|
||||
struct spwd *
|
||||
fgetspent(FILE *fp)
|
||||
struct spwd *fgetspent (FILE * fp)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
char *cp;
|
||||
char buf[BUFSIZ];
|
||||
char *cp;
|
||||
|
||||
if (! fp)
|
||||
if (!fp)
|
||||
return (0);
|
||||
|
||||
#ifdef USE_NIS
|
||||
@@ -376,7 +329,7 @@ fgetspent(FILE *fp)
|
||||
if (nis_ignore && IS_NISCHAR (buf[0]))
|
||||
continue;
|
||||
#endif
|
||||
return my_sgetspent(buf);
|
||||
return my_sgetspent (buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -385,19 +338,18 @@ fgetspent(FILE *fp)
|
||||
* getspent - get a (struct spwd *) from the current shadow file
|
||||
*/
|
||||
|
||||
struct spwd *
|
||||
getspent(void)
|
||||
struct spwd *getspent (void)
|
||||
{
|
||||
#ifdef USE_NIS
|
||||
int nis_1_user = 0;
|
||||
struct spwd *val;
|
||||
char buf[BUFSIZ];
|
||||
int nis_1_user = 0;
|
||||
struct spwd *val;
|
||||
char buf[BUFSIZ];
|
||||
#endif
|
||||
if (! shadow)
|
||||
if (!shadow)
|
||||
setspent ();
|
||||
|
||||
#ifdef USE_NIS
|
||||
again:
|
||||
again:
|
||||
/*
|
||||
* See if we are reading from the local file.
|
||||
*/
|
||||
@@ -409,7 +361,7 @@ again:
|
||||
* right away if there is none.
|
||||
*/
|
||||
|
||||
if (! (val = fgetspent (shadow)))
|
||||
if (!(val = fgetspent (shadow)))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
@@ -455,20 +407,20 @@ again:
|
||||
}
|
||||
if (nis_state == start) {
|
||||
if (yp_first (nis_domain, "shadow.bynam", &nis_key,
|
||||
&nis_keylen, &nis_val, &nis_vallen)) {
|
||||
&nis_keylen, &nis_val, &nis_vallen)) {
|
||||
nis_state = native2;
|
||||
goto again;
|
||||
}
|
||||
nis_state = middle;
|
||||
} else if (nis_state == middle) {
|
||||
if (yp_next (nis_domain, "shadow.bynam", nis_key,
|
||||
nis_keylen, &nis_key, &nis_keylen,
|
||||
&nis_val, &nis_vallen)) {
|
||||
nis_keylen, &nis_key, &nis_keylen,
|
||||
&nis_val, &nis_vallen)) {
|
||||
nis_state = native2;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
return my_sgetspent(nis_val);
|
||||
return my_sgetspent (nis_val);
|
||||
}
|
||||
#else
|
||||
return (fgetspent (shadow));
|
||||
@@ -479,68 +431,42 @@ again:
|
||||
* getspnam - get a shadow entry by name
|
||||
*/
|
||||
|
||||
struct spwd *
|
||||
getspnam(const char *name)
|
||||
struct spwd *getspnam (const char *name)
|
||||
{
|
||||
struct spwd *sp;
|
||||
#ifdef NDBM
|
||||
datum key;
|
||||
datum content;
|
||||
#endif
|
||||
struct spwd *sp;
|
||||
|
||||
#ifdef USE_NIS
|
||||
char buf[BUFSIZ];
|
||||
static char save_name[16];
|
||||
int nis_disabled = 0;
|
||||
char buf[BUFSIZ];
|
||||
static char save_name[16];
|
||||
int nis_disabled = 0;
|
||||
#endif
|
||||
|
||||
setspent ();
|
||||
|
||||
#ifdef NDBM
|
||||
|
||||
/*
|
||||
* If the DBM file are now open, create a key for this UID and
|
||||
* try to fetch the entry from the database. A matching record
|
||||
* will be unpacked into a static structure and returned to
|
||||
* the user.
|
||||
*/
|
||||
|
||||
if (dbmopened) {
|
||||
key.dsize = strlen (name);
|
||||
key.dptr = (char *) name;
|
||||
|
||||
content = dbm_fetch (sp_dbm, key);
|
||||
if (content.dptr != 0) {
|
||||
memcpy (spwbuf, content.dptr, content.dsize);
|
||||
spw_unpack (spwbuf, content.dsize, &spwd);
|
||||
endspent();
|
||||
return &spwd;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_NIS
|
||||
/*
|
||||
* Search the shadow.byname map for this user.
|
||||
*/
|
||||
|
||||
if (! nis_ignore && ! nis_bound)
|
||||
if (!nis_ignore && !nis_bound)
|
||||
bind_nis ();
|
||||
|
||||
if (! nis_ignore && nis_bound) {
|
||||
char *cp;
|
||||
if (!nis_ignore && nis_bound) {
|
||||
char *cp;
|
||||
|
||||
if (yp_match (nis_domain, "shadow.byname", name,
|
||||
strlen (name), &nis_val, &nis_vallen) == 0) {
|
||||
strlen (name), &nis_val, &nis_vallen) == 0) {
|
||||
|
||||
if (cp = strchr (nis_val, '\n'))
|
||||
*cp = '\0';
|
||||
|
||||
nis_state = middle;
|
||||
if ((sp = my_sgetspent(nis_val))) {
|
||||
if ((sp = my_sgetspent (nis_val))) {
|
||||
strcpy (save_name, sp->sp_namp);
|
||||
nis_key = save_name;
|
||||
nis_keylen = strlen (save_name);
|
||||
}
|
||||
endspent();
|
||||
endspent ();
|
||||
return sp;
|
||||
} else
|
||||
nis_state = native2;
|
||||
@@ -567,9 +493,9 @@ getspnam(const char *name)
|
||||
if (nis_disabled)
|
||||
nis_ignore--;
|
||||
#endif
|
||||
endspent();
|
||||
endspent ();
|
||||
return (sp);
|
||||
}
|
||||
#else
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
#endif /*}*/
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
#endif /*} */
|
||||
|
134
lib/shadowio.c
134
lib/shadowio.c
@@ -4,68 +4,62 @@
|
||||
#ifdef SHADOWPWD
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: shadowio.c,v 1.13 2001/08/14 21:10:36 malekith Exp $")
|
||||
|
||||
RCSID ("$Id: shadowio.c,v 1.14 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#ifdef HAVE_SHADOW_H
|
||||
# include <shadow.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include "commonio.h"
|
||||
#include "shadowio.h"
|
||||
|
||||
struct spwd *
|
||||
__spw_dup(const struct spwd *spent)
|
||||
struct spwd *__spw_dup (const struct spwd *spent)
|
||||
{
|
||||
struct spwd *sp;
|
||||
|
||||
if (!(sp = (struct spwd *) malloc(sizeof *sp)))
|
||||
if (!(sp = (struct spwd *) malloc (sizeof *sp)))
|
||||
return NULL;
|
||||
*sp = *spent;
|
||||
if (!(sp->sp_namp = strdup(spent->sp_namp)))
|
||||
if (!(sp->sp_namp = strdup (spent->sp_namp)))
|
||||
return NULL;
|
||||
if (!(sp->sp_pwdp = strdup(spent->sp_pwdp)))
|
||||
if (!(sp->sp_pwdp = strdup (spent->sp_pwdp)))
|
||||
return NULL;
|
||||
return sp;
|
||||
}
|
||||
|
||||
static void *
|
||||
shadow_dup(const void *ent)
|
||||
static void *shadow_dup (const void *ent)
|
||||
{
|
||||
const struct spwd *sp = ent;
|
||||
return __spw_dup(sp);
|
||||
|
||||
return __spw_dup (sp);
|
||||
}
|
||||
|
||||
static void
|
||||
shadow_free(void *ent)
|
||||
static void shadow_free (void *ent)
|
||||
{
|
||||
struct spwd *sp = ent;
|
||||
|
||||
free(sp->sp_namp);
|
||||
free(sp->sp_pwdp);
|
||||
free(sp);
|
||||
free (sp->sp_namp);
|
||||
free (sp->sp_pwdp);
|
||||
free (sp);
|
||||
}
|
||||
|
||||
static const char *
|
||||
shadow_getname(const void *ent)
|
||||
static const char *shadow_getname (const void *ent)
|
||||
{
|
||||
const struct spwd *sp = ent;
|
||||
|
||||
return sp->sp_namp;
|
||||
}
|
||||
|
||||
static void *
|
||||
shadow_parse(const char *line)
|
||||
static void *shadow_parse (const char *line)
|
||||
{
|
||||
return (void *) sgetspent(line);
|
||||
return (void *) sgetspent (line);
|
||||
}
|
||||
|
||||
static int
|
||||
shadow_put(const void *ent, FILE *file)
|
||||
static int shadow_put (const void *ent, FILE * file)
|
||||
{
|
||||
const struct spwd *sp = ent;
|
||||
return (putspent(sp, file) == -1) ? -1 : 0;
|
||||
|
||||
return (putspent (sp, file) == -1) ? -1 : 0;
|
||||
}
|
||||
|
||||
static struct commonio_ops shadow_ops = {
|
||||
@@ -79,102 +73,88 @@ static struct commonio_ops shadow_ops = {
|
||||
};
|
||||
|
||||
static struct commonio_db shadow_db = {
|
||||
SHADOW_FILE, /* filename */
|
||||
&shadow_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
SHADOW_FILE, /* filename */
|
||||
&shadow_ops, /* ops */
|
||||
NULL, /* fp */
|
||||
NULL, /* head */
|
||||
NULL, /* tail */
|
||||
NULL, /* cursor */
|
||||
0, /* changed */
|
||||
0, /* isopen */
|
||||
0, /* locked */
|
||||
0 /* readonly */
|
||||
};
|
||||
|
||||
int
|
||||
spw_name(const char *filename)
|
||||
int spw_name (const char *filename)
|
||||
{
|
||||
return commonio_setname(&shadow_db, filename);
|
||||
return commonio_setname (&shadow_db, filename);
|
||||
}
|
||||
|
||||
int
|
||||
spw_file_present(void)
|
||||
int spw_file_present (void)
|
||||
{
|
||||
return commonio_present(&shadow_db);
|
||||
return commonio_present (&shadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
spw_lock(void)
|
||||
int spw_lock (void)
|
||||
{
|
||||
return commonio_lock(&shadow_db);
|
||||
return commonio_lock (&shadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
spw_open(int mode)
|
||||
int spw_open (int mode)
|
||||
{
|
||||
return commonio_open(&shadow_db, mode);
|
||||
return commonio_open (&shadow_db, mode);
|
||||
}
|
||||
|
||||
const struct spwd *
|
||||
spw_locate(const char *name)
|
||||
const struct spwd *spw_locate (const char *name)
|
||||
{
|
||||
return commonio_locate(&shadow_db, name);
|
||||
return commonio_locate (&shadow_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
spw_update(const struct spwd *sp)
|
||||
int spw_update (const struct spwd *sp)
|
||||
{
|
||||
return commonio_update(&shadow_db, (const void *) sp);
|
||||
return commonio_update (&shadow_db, (const void *) sp);
|
||||
}
|
||||
|
||||
int
|
||||
spw_remove(const char *name)
|
||||
int spw_remove (const char *name)
|
||||
{
|
||||
return commonio_remove(&shadow_db, name);
|
||||
return commonio_remove (&shadow_db, name);
|
||||
}
|
||||
|
||||
int
|
||||
spw_rewind(void)
|
||||
int spw_rewind (void)
|
||||
{
|
||||
return commonio_rewind(&shadow_db);
|
||||
return commonio_rewind (&shadow_db);
|
||||
}
|
||||
|
||||
const struct spwd *
|
||||
spw_next(void)
|
||||
const struct spwd *spw_next (void)
|
||||
{
|
||||
return commonio_next(&shadow_db);
|
||||
return commonio_next (&shadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
spw_close(void)
|
||||
int spw_close (void)
|
||||
{
|
||||
return commonio_close(&shadow_db);
|
||||
return commonio_close (&shadow_db);
|
||||
}
|
||||
|
||||
int
|
||||
spw_unlock(void)
|
||||
int spw_unlock (void)
|
||||
{
|
||||
return commonio_unlock(&shadow_db);
|
||||
return commonio_unlock (&shadow_db);
|
||||
}
|
||||
|
||||
struct commonio_entry *
|
||||
__spw_get_head(void)
|
||||
struct commonio_entry *__spw_get_head (void)
|
||||
{
|
||||
return shadow_db.head;
|
||||
}
|
||||
|
||||
void
|
||||
__spw_del_entry(const struct commonio_entry *ent)
|
||||
void __spw_del_entry (const struct commonio_entry *ent)
|
||||
{
|
||||
commonio_del_entry(&shadow_db, ent);
|
||||
commonio_del_entry (&shadow_db, ent);
|
||||
}
|
||||
|
||||
/* Sort with respect to passwd ordering. */
|
||||
int
|
||||
spw_sort()
|
||||
int spw_sort ()
|
||||
{
|
||||
extern struct commonio_db *__pw_get_db();
|
||||
extern struct commonio_db *__pw_get_db ();
|
||||
|
||||
return commonio_sort_wrt(&shadow_db, __pw_get_db());
|
||||
return commonio_sort_wrt (&shadow_db, __pw_get_db ());
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,14 +1,14 @@
|
||||
extern struct spwd *__spw_dup(const struct spwd *);
|
||||
extern void __spw_set_changed(void);
|
||||
extern int spw_close(void);
|
||||
extern int spw_file_present(void);
|
||||
extern const struct spwd *spw_locate(const char *);
|
||||
extern int spw_lock(void);
|
||||
extern int spw_name(const char *);
|
||||
extern const struct spwd *spw_next(void);
|
||||
extern int spw_open(int);
|
||||
extern int spw_remove(const char *);
|
||||
extern int spw_rewind(void);
|
||||
extern int spw_unlock(void);
|
||||
extern int spw_update(const struct spwd *);
|
||||
extern int spw_sort(void);
|
||||
extern struct spwd *__spw_dup (const struct spwd *);
|
||||
extern void __spw_set_changed (void);
|
||||
extern int spw_close (void);
|
||||
extern int spw_file_present (void);
|
||||
extern const struct spwd *spw_locate (const char *);
|
||||
extern int spw_lock (void);
|
||||
extern int spw_name (const char *);
|
||||
extern const struct spwd *spw_next (void);
|
||||
extern int spw_open (int);
|
||||
extern int spw_remove (const char *);
|
||||
extern int spw_rewind (void);
|
||||
extern int spw_unlock (void);
|
||||
extern int spw_update (const struct spwd *);
|
||||
extern int spw_sort (void);
|
||||
|
116
lib/spdbm.c
116
lib/spdbm.c
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright 1990 - 1994, Julianne Frances Haugh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined(SHADOWPWD) && defined(NDBM) /*{*/
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: spdbm.c,v 1.3 1997/12/07 23:26:58 marekm Exp $")
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include <ndbm.h>
|
||||
extern DBM *sp_dbm;
|
||||
|
||||
/*
|
||||
* sp_dbm_update
|
||||
*
|
||||
* Updates the DBM password files, if they exist.
|
||||
*/
|
||||
|
||||
int
|
||||
sp_dbm_update(struct spwd *sp)
|
||||
{
|
||||
datum key;
|
||||
datum content;
|
||||
char data[BUFSIZ];
|
||||
int len;
|
||||
static int once;
|
||||
|
||||
if (! once) {
|
||||
if (! sp_dbm)
|
||||
setspent ();
|
||||
|
||||
once++;
|
||||
}
|
||||
if (! sp_dbm)
|
||||
return 0;
|
||||
|
||||
len = spw_pack (sp, data);
|
||||
|
||||
content.dsize = len;
|
||||
content.dptr = data;
|
||||
|
||||
key.dsize = strlen (sp->sp_namp);
|
||||
key.dptr = sp->sp_namp;
|
||||
if (dbm_store (sp_dbm, key, content, DBM_REPLACE))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* sp_dbm_remove
|
||||
*
|
||||
* Updates the DBM password files, if they exist.
|
||||
*/
|
||||
|
||||
int
|
||||
sp_dbm_remove(char *user)
|
||||
{
|
||||
datum key;
|
||||
static int once;
|
||||
|
||||
if (! once) {
|
||||
if (! sp_dbm)
|
||||
setspent ();
|
||||
|
||||
once++;
|
||||
}
|
||||
if (! sp_dbm)
|
||||
return 0;
|
||||
|
||||
key.dsize = strlen (user);
|
||||
key.dptr = user;
|
||||
if (dbm_delete (sp_dbm, key))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
sp_dbm_present(void)
|
||||
{
|
||||
return (access(SHADOW_PAG_FILE, F_OK) == 0);
|
||||
}
|
||||
#endif /*} SHADOWPWD && NDBM */
|
18
lib/sppack.c
18
lib/sppack.c
@@ -28,19 +28,16 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#ifdef SHADOWPWD /*{*/
|
||||
#ifdef SHADOWPWD /*{ */
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID("$Id: sppack.c,v 1.3 1997/12/07 23:26:58 marekm Exp $")
|
||||
|
||||
RCSID ("$Id: sppack.c,v 1.4 2005/03/31 05:14:49 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "defines.h"
|
||||
|
||||
int
|
||||
spw_pack(const struct spwd *spwd, char *buf)
|
||||
int spw_pack (const struct spwd *spwd, char *buf)
|
||||
{
|
||||
char *cp;
|
||||
char *cp;
|
||||
|
||||
cp = buf;
|
||||
strcpy (cp, spwd->sp_namp);
|
||||
@@ -73,10 +70,9 @@ spw_pack(const struct spwd *spwd, char *buf)
|
||||
return cp - buf;
|
||||
}
|
||||
|
||||
int
|
||||
spw_unpack(char *buf, int len, struct spwd *spwd)
|
||||
int spw_unpack (char *buf, int len, struct spwd *spwd)
|
||||
{
|
||||
char *org = buf;
|
||||
char *org = buf;
|
||||
|
||||
spwd->sp_namp = buf;
|
||||
buf += strlen (buf) + 1;
|
||||
@@ -110,4 +106,4 @@ spw_unpack(char *buf, int len, struct spwd *spwd)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /*}*/
|
||||
#endif /*} */
|
||||
|
24
lib/utent.c
24
lib/utent.c
@@ -37,18 +37,17 @@
|
||||
#include <utmp.h>
|
||||
|
||||
#ifndef lint
|
||||
static char rcsid[] = "$Id: utent.c,v 1.4 1998/01/29 23:22:32 marekm Exp $";
|
||||
static char rcsid[] = "$Id: utent.c,v 1.5 2005/03/31 05:14:49 kloczek Exp $";
|
||||
#endif
|
||||
|
||||
static int utmp_fd = -1;
|
||||
static struct utmp utmp_buf;
|
||||
static int utmp_fd = -1;
|
||||
static struct utmp utmp_buf;
|
||||
|
||||
/*
|
||||
* setutent - open or rewind the utmp file
|
||||
*/
|
||||
|
||||
void
|
||||
setutent(void)
|
||||
void setutent (void)
|
||||
{
|
||||
if (utmp_fd == -1)
|
||||
if ((utmp_fd = open (_UTMP_FILE, O_RDWR)) == -1)
|
||||
@@ -62,8 +61,7 @@ setutent(void)
|
||||
* endutent - close the utmp file
|
||||
*/
|
||||
|
||||
void
|
||||
endutent(void)
|
||||
void endutent (void)
|
||||
{
|
||||
if (utmp_fd != -1)
|
||||
close (utmp_fd);
|
||||
@@ -75,8 +73,7 @@ endutent(void)
|
||||
* getutent - get the next record from the utmp file
|
||||
*/
|
||||
|
||||
struct utmp *
|
||||
getutent(void)
|
||||
struct utmp *getutent (void)
|
||||
{
|
||||
if (utmp_fd == -1)
|
||||
setutent ();
|
||||
@@ -94,11 +91,10 @@ getutent(void)
|
||||
* getutline - get the utmp entry matching ut_line
|
||||
*/
|
||||
|
||||
struct utmp *
|
||||
getutline(const struct utmp *utent)
|
||||
struct utmp *getutline (const struct utmp *utent)
|
||||
{
|
||||
struct utmp save;
|
||||
struct utmp *new;
|
||||
struct utmp save;
|
||||
struct utmp *new;
|
||||
|
||||
save = *utent;
|
||||
while (new = getutent ())
|
||||
@@ -110,5 +106,5 @@ getutline(const struct utmp *utent)
|
||||
return (struct utmp *) 0;
|
||||
}
|
||||
#else
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
extern int errno; /* warning: ANSI C forbids an empty source file */
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user