[svn-upgrade] Integrating new upstream version, shadow (4.0.8)
This commit is contained in:
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
|
||||
|
Reference in New Issue
Block a user