2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#ifdef HAVE_SHADOW_H
|
|
|
|
# include <shadow.h>
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "commonio.h"
|
|
|
|
#include "shadowio.h"
|
2007-10-07 17:16:07 +05:30
|
|
|
struct spwd *__spw_dup (const struct spwd *spent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct spwd *sp;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!(sp = (struct spwd *) malloc (sizeof *sp)))
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
|
|
|
*sp = *spent;
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!(sp->sp_namp = strdup (spent->sp_namp)))
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!(sp->sp_pwdp = strdup (spent->sp_pwdp)))
|
2007-10-07 17:14:02 +05:30
|
|
|
return NULL;
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void *shadow_dup (const void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct spwd *sp = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
|
|
|
return __spw_dup (sp);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void shadow_free (void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct spwd *sp = ent;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
free (sp->sp_namp);
|
|
|
|
free (sp->sp_pwdp);
|
|
|
|
free (sp);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static const char *shadow_getname (const void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct spwd *sp = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
return sp->sp_namp;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void *shadow_parse (const char *line)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return (void *) sgetspent (line);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static int shadow_put (const void *ent, FILE * file)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct spwd *sp = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
|
|
|
return (putspent (sp, file) == -1) ? -1 : 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static struct commonio_ops shadow_ops = {
|
|
|
|
shadow_dup,
|
|
|
|
shadow_free,
|
|
|
|
shadow_getname,
|
|
|
|
shadow_parse,
|
|
|
|
shadow_put,
|
|
|
|
fgets,
|
|
|
|
fputs
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct commonio_db shadow_db = {
|
2007-10-07 17:16:07 +05:30
|
|
|
SHADOW_FILE, /* filename */
|
|
|
|
&shadow_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 spw_name (const char *filename)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_setname (&shadow_db, filename);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_file_present (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_present (&shadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_lock (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_lock (&shadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_open (int mode)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_open (&shadow_db, mode);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
const struct spwd *spw_locate (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_locate (&shadow_db, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_update (const struct spwd *sp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_update (&shadow_db, (const void *) sp);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_remove (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_remove (&shadow_db, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_rewind (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_rewind (&shadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
const struct spwd *spw_next (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_next (&shadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_close (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_close (&shadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_unlock (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_unlock (&shadow_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
struct commonio_entry *__spw_get_head (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
return shadow_db.head;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void __spw_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 (&shadow_db, ent);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:51 +05:30
|
|
|
|
|
|
|
/* Sort with respect to passwd ordering. */
|
2007-10-07 17:16:07 +05:30
|
|
|
int spw_sort ()
|
2007-10-07 17:14:51 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
extern struct commonio_db *__pw_get_db ();
|
2007-10-07 17:14:51 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_sort_wrt (&shadow_db, __pw_get_db ());
|
2007-10-07 17:14:51 +05:30
|
|
|
}
|