2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
|
|
|
|
#include "rcsid.h"
|
2007-10-07 17:16:07 +05:30
|
|
|
RCSID ("$Id: sgroupio.c,v 1.13 2005/03/31 05:14:49 kloczek Exp $")
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "commonio.h"
|
|
|
|
#include "sgroupio.h"
|
2007-10-07 17:16:07 +05:30
|
|
|
extern int putsgent (const struct sgrp *, FILE *);
|
|
|
|
extern struct sgrp *sgetsgent (const char *);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
struct sgrp *__sgr_dup (const struct sgrp *sgent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct sgrp *sg;
|
|
|
|
int i;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!(sg = (struct sgrp *) malloc (sizeof *sg)))
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
|
|
|
*sg = *sgent;
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!(sg->sg_name = strdup (sgent->sg_name)))
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!(sg->sg_passwd = strdup (sgent->sg_passwd)))
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 0; sgent->sg_adm[i]; i++);
|
|
|
|
sg->sg_adm = (char **) malloc ((i + 1) * sizeof (char *));
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!sg->sg_adm)
|
|
|
|
return NULL;
|
|
|
|
for (i = 0; sgent->sg_adm[i]; i++) {
|
2007-10-07 17:16:07 +05:30
|
|
|
sg->sg_adm[i] = strdup (sgent->sg_adm[i]);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!sg->sg_adm[i])
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sg->sg_adm[i] = NULL;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 0; sgent->sg_mem[i]; i++);
|
|
|
|
sg->sg_mem = (char **) malloc ((i + 1) * sizeof (char *));
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!sg->sg_mem)
|
|
|
|
return NULL;
|
|
|
|
for (i = 0; sgent->sg_mem[i]; i++) {
|
2007-10-07 17:16:07 +05:30
|
|
|
sg->sg_mem[i] = strdup (sgent->sg_mem[i]);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!sg->sg_mem[i])
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sg->sg_mem[i] = NULL;
|
|
|
|
|
|
|
|
return sg;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void *gshadow_dup (const void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct sgrp *sg = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
|
|
|
return __sgr_dup (sg);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void gshadow_free (void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct sgrp *sg = ent;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
free (sg->sg_name);
|
|
|
|
free (sg->sg_passwd);
|
|
|
|
while (*(sg->sg_adm)) {
|
|
|
|
free (*(sg->sg_adm));
|
2007-10-07 17:14:02 +05:30
|
|
|
sg->sg_adm++;
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
while (*(sg->sg_mem)) {
|
|
|
|
free (*(sg->sg_mem));
|
2007-10-07 17:14:02 +05:30
|
|
|
sg->sg_mem++;
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
free (sg);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static const char *gshadow_getname (const void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct sgrp *gr = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
return gr->sg_name;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void *gshadow_parse (const char *line)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return (void *) sgetsgent (line);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static int gshadow_put (const void *ent, FILE * file)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct sgrp *sg = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
|
|
|
return (putsgent (sg, file) == -1) ? -1 : 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static struct commonio_ops gshadow_ops = {
|
|
|
|
gshadow_dup,
|
|
|
|
gshadow_free,
|
|
|
|
gshadow_getname,
|
|
|
|
gshadow_parse,
|
|
|
|
gshadow_put,
|
|
|
|
fgetsx,
|
|
|
|
fputsx
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct commonio_db gshadow_db = {
|
2007-10-07 17:16:07 +05:30
|
|
|
SGROUP_FILE, /* filename */
|
|
|
|
&gshadow_ops, /* ops */
|
|
|
|
NULL, /* fp */
|
|
|
|
NULL, /* head */
|
|
|
|
NULL, /* tail */
|
|
|
|
NULL, /* cursor */
|
|
|
|
0, /* changed */
|
|
|
|
0, /* isopen */
|
|
|
|
0, /* locked */
|
|
|
|
0 /* readonly */
|
2007-10-07 17:14:02 +05:30
|
|
|
};
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_name (const char *filename)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_setname (&gshadow_db, filename);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_file_present (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_present (&gshadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_lock (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_lock (&gshadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_open (int mode)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_open (&gshadow_db, mode);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
const struct sgrp *sgr_locate (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_locate (&gshadow_db, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_update (const struct sgrp *sg)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_update (&gshadow_db, (const void *) sg);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_remove (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_remove (&gshadow_db, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_rewind (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_rewind (&gshadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
const struct sgrp *sgr_next (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_next (&gshadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_close (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_close (&gshadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_unlock (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_unlock (&gshadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void __sgr_set_changed (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
gshadow_db.changed = 1;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
struct commonio_entry *__sgr_get_head (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
return gshadow_db.head;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void __sgr_del_entry (const struct commonio_entry *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
commonio_del_entry (&gshadow_db, ent);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:51 +05:30
|
|
|
|
|
|
|
/* Sort with respect to group ordering. */
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_sort ()
|
2007-10-07 17:14:51 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
extern struct commonio_db *__gr_get_db ();
|
2007-10-07 17:14:51 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_sort_wrt (&gshadow_db, __gr_get_db ());
|
2007-10-07 17:14:51 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:16:07 +05:30
|
|
|
extern int errno; /* warning: ANSI C forbids an empty source file */
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|