569a3b8e59
lib/sgetpwent.c: Include "prototypes.h" to make sure the exported prototypes are the ones used for the definition of functions. * lib/prototypes.h: Added prototypes for __gr_del_entry(), __gr_get_db(), __gr_get_head(), __gr_set_changed(), __gr_dup(), __pw_del_entry(), __pw_get_db(), __pw_get_head(), __pw_dup(), sgetgrent(), sgetpwent(), __sgr_del_entry(), __sgr_dup(), __sgr_get_head(), __sgr_set_changed(), __spw_get_head(), __spw_del_entry(), __spw_dup(). * lib/prototypes.h: Removed prototype for is_listed(). * lib/prototypes.h: Added name of the check_su_auth()'s parameters. * lib/groupio.h: Removed prototypes for __gr_dup() and __gr_set_changed(). * lib/sgroupio.c: Removed prototypes for putsgent(), sgetsgent(), and __gr_get_db(). * lib/sgroupio.h: Removed prototypes for __sgr_dup() and __sgr_set_changed(). * lib/shadowio.c: Removed prototype for __pw_get_db(). * lib/pwio.c: Removed prototype for sgetpwent() and putpwent(). * lib/shadowio.h: Removed prototypes for __spw_dup() and __spw_set_changed(). * lib/pwio.h: Removed prototypes for __pw_dup() and __pw_set_changed(). * lib/commonio.h: Add protection against multiple inclusions. * lib/prototypes.h: Include commonio.h (needed for the __xx_del_entry() functions).
200 lines
3.4 KiB
C
200 lines
3.4 KiB
C
|
|
#include <config.h>
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
#ident "$Id$"
|
|
|
|
#include "prototypes.h"
|
|
#include "defines.h"
|
|
#include "commonio.h"
|
|
#include "sgroupio.h"
|
|
|
|
struct sgrp *__sgr_dup (const struct sgrp *sgent)
|
|
{
|
|
struct sgrp *sg;
|
|
int i;
|
|
|
|
if (!(sg = (struct sgrp *) malloc (sizeof *sg)))
|
|
return NULL;
|
|
*sg = *sgent;
|
|
if (!(sg->sg_name = strdup (sgent->sg_name)))
|
|
return NULL;
|
|
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 *));
|
|
if (!sg->sg_adm)
|
|
return NULL;
|
|
for (i = 0; sgent->sg_adm[i]; 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 *));
|
|
if (!sg->sg_mem)
|
|
return NULL;
|
|
for (i = 0; sgent->sg_mem[i]; i++) {
|
|
sg->sg_mem[i] = strdup (sgent->sg_mem[i]);
|
|
if (!sg->sg_mem[i])
|
|
return NULL;
|
|
}
|
|
sg->sg_mem[i] = NULL;
|
|
|
|
return sg;
|
|
}
|
|
|
|
static void *gshadow_dup (const void *ent)
|
|
{
|
|
const struct sgrp *sg = ent;
|
|
|
|
return __sgr_dup (sg);
|
|
}
|
|
|
|
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));
|
|
sg->sg_adm++;
|
|
}
|
|
while (*(sg->sg_mem)) {
|
|
free (*(sg->sg_mem));
|
|
sg->sg_mem++;
|
|
}
|
|
free (sg);
|
|
}
|
|
|
|
static const char *gshadow_getname (const void *ent)
|
|
{
|
|
const struct sgrp *gr = ent;
|
|
|
|
return gr->sg_name;
|
|
}
|
|
|
|
static void *gshadow_parse (const char *line)
|
|
{
|
|
return (void *) sgetsgent (line);
|
|
}
|
|
|
|
static int gshadow_put (const void *ent, FILE * file)
|
|
{
|
|
const struct sgrp *sg = ent;
|
|
|
|
return (putsgent (sg, file) == -1) ? -1 : 0;
|
|
}
|
|
|
|
static struct commonio_ops gshadow_ops = {
|
|
gshadow_dup,
|
|
gshadow_free,
|
|
gshadow_getname,
|
|
gshadow_parse,
|
|
gshadow_put,
|
|
fgetsx,
|
|
fputsx,
|
|
NULL, /* open_hook */
|
|
NULL /* close_hook */
|
|
};
|
|
|
|
static struct commonio_db gshadow_db = {
|
|
SGROUP_FILE, /* filename */
|
|
&gshadow_ops, /* ops */
|
|
NULL, /* fp */
|
|
#ifdef WITH_SELINUX
|
|
NULL, /* scontext */
|
|
#endif
|
|
NULL, /* head */
|
|
NULL, /* tail */
|
|
NULL, /* cursor */
|
|
0, /* changed */
|
|
0, /* isopen */
|
|
0, /* locked */
|
|
0 /* readonly */
|
|
};
|
|
|
|
int sgr_name (const char *filename)
|
|
{
|
|
return commonio_setname (&gshadow_db, filename);
|
|
}
|
|
|
|
int sgr_file_present (void)
|
|
{
|
|
return commonio_present (&gshadow_db);
|
|
}
|
|
|
|
int sgr_lock (void)
|
|
{
|
|
return commonio_lock (&gshadow_db);
|
|
}
|
|
|
|
int sgr_open (int mode)
|
|
{
|
|
return commonio_open (&gshadow_db, mode);
|
|
}
|
|
|
|
const struct sgrp *sgr_locate (const char *name)
|
|
{
|
|
return commonio_locate (&gshadow_db, name);
|
|
}
|
|
|
|
int sgr_update (const struct sgrp *sg)
|
|
{
|
|
return commonio_update (&gshadow_db, (const void *) sg);
|
|
}
|
|
|
|
int sgr_remove (const char *name)
|
|
{
|
|
return commonio_remove (&gshadow_db, name);
|
|
}
|
|
|
|
int sgr_rewind (void)
|
|
{
|
|
return commonio_rewind (&gshadow_db);
|
|
}
|
|
|
|
const struct sgrp *sgr_next (void)
|
|
{
|
|
return commonio_next (&gshadow_db);
|
|
}
|
|
|
|
int sgr_close (void)
|
|
{
|
|
return commonio_close (&gshadow_db);
|
|
}
|
|
|
|
int sgr_unlock (void)
|
|
{
|
|
return commonio_unlock (&gshadow_db);
|
|
}
|
|
|
|
void __sgr_set_changed (void)
|
|
{
|
|
gshadow_db.changed = 1;
|
|
}
|
|
|
|
struct commonio_entry *__sgr_get_head (void)
|
|
{
|
|
return gshadow_db.head;
|
|
}
|
|
|
|
void __sgr_del_entry (const struct commonio_entry *ent)
|
|
{
|
|
commonio_del_entry (&gshadow_db, ent);
|
|
}
|
|
|
|
/* Sort with respect to group ordering. */
|
|
int sgr_sort ()
|
|
{
|
|
return commonio_sort_wrt (&gshadow_db, __gr_get_db ());
|
|
}
|
|
#else
|
|
extern int errno; /* warning: ANSI C forbids an empty source file */
|
|
#endif
|