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