diff --git a/ChangeLog b/ChangeLog index ee9f1d1f..8e081c4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-04-21 Nicolas François + + * lib/shadowmem.c: Added spw_free(). + * lib/shadowio.c: Use spw_free() for shadow_free(). + * lib/groupmem.c: Added gr_free(). + * lib/groupio.c: Use gr_free() for group_free(). + * lib/pwmem.c: Include define.h before prototypes.h + * lib/pwmem.c: Added pw_free(). + * lib/pwio.c: Use pw_free() for passwd_free(). + * lib/sgroupio.c: Added sgr_free(). + * lib/sgroupio.c: Use sgr_free() for gshadow_free(). + * lib/prototypes.h: Added gr_free(), pw_free(), sgr_free(), + spw_free(). + 2009-04-21 Nicolas François * libmisc/shell.c: Add brackets and parenthesis. diff --git a/lib/groupio.c b/lib/groupio.c index cdca7c9a..f821c591 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -59,14 +59,7 @@ static void group_free (void *ent) { struct group *gr = ent; - free (gr->gr_name); - memzero (gr->gr_passwd, strlen (gr->gr_passwd)); - free (gr->gr_passwd); - while (*(gr->gr_mem)) { - free (*(gr->gr_mem)); - gr->gr_mem++; - } - free (gr); + gr_free (gr); } static const char *group_getname (const void *ent) diff --git a/lib/groupmem.c b/lib/groupmem.c index 6bdcfd10..56f198e8 100644 --- a/lib/groupmem.c +++ b/lib/groupmem.c @@ -75,3 +75,15 @@ struct group *__gr_dup (const struct group *grent) return gr; } +void gr_free (struct group *grent) +{ + free (grent->gr_name); + memzero (grent->gr_passwd, strlen (grent->gr_passwd)); + free (grent->gr_passwd); + while (*(grent->gr_mem)) { + free (*(grent->gr_mem)); + grent->gr_mem++; + } + free (grent); +} + diff --git a/lib/prototypes.h b/lib/prototypes.h index 2eb292d8..56ab225c 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -173,6 +173,7 @@ extern void __gr_set_changed (void); /* groupmem.c */ extern struct group *__gr_dup (const struct group *grent); +extern void gr_free (struct group *grent); /* hushed.c */ extern bool hushed (const char *username); @@ -258,6 +259,7 @@ extern struct commonio_entry *__pw_get_head (void); /* pwmem.c */ extern struct passwd *__pw_dup (const struct passwd *pwent); +extern void pw_free (struct passwd *pwent); /* rlogin.c */ extern int do_rlogin (const char *remote_host, char *name, size_t namelen, @@ -295,6 +297,7 @@ extern struct spwd *sgetspent (const char *string) /* sgroupio.c */ extern void __sgr_del_entry (const struct commonio_entry *ent); extern struct sgrp *__sgr_dup (const struct sgrp *sgent); +extern void sgr_free (struct sgrp *sgent); extern struct commonio_entry *__sgr_get_head (void); extern void __sgr_set_changed (void); @@ -304,6 +307,7 @@ extern void __spw_del_entry (const struct commonio_entry *ent); /* shadowmem.c */ extern struct spwd *__spw_dup (const struct spwd *spent); +extern void spw_free (struct spwd *spent); /* shell.c */ extern int shell (const char *, const char *, char *const *); diff --git a/lib/pwio.c b/lib/pwio.c index 38eea9c2..f501e2cc 100644 --- a/lib/pwio.c +++ b/lib/pwio.c @@ -53,13 +53,7 @@ static void passwd_free (void *ent) { struct passwd *pw = ent; - free (pw->pw_name); - memzero (pw->pw_passwd, strlen (pw->pw_passwd)); - free (pw->pw_passwd); - free (pw->pw_gecos); - free (pw->pw_dir); - free (pw->pw_shell); - free (pw); + pw_free (pw); } static const char *passwd_getname (const void *ent) diff --git a/lib/pwmem.c b/lib/pwmem.c index addd0fba..d9bed3a2 100644 --- a/lib/pwmem.c +++ b/lib/pwmem.c @@ -36,8 +36,8 @@ #ident "$Id$" #include -#include "prototypes.h" #include "defines.h" +#include "prototypes.h" #include "pwio.h" struct passwd *__pw_dup (const struct passwd *pwent) @@ -73,3 +73,14 @@ struct passwd *__pw_dup (const struct passwd *pwent) return pw; } +void pw_free (struct passwd *pwent) +{ + free (pwent->pw_name); + memzero (pwent->pw_passwd, strlen (pwent->pw_passwd)); + free (pwent->pw_passwd); + free (pwent->pw_gecos); + free (pwent->pw_dir); + free (pwent->pw_shell); + free (pwent); +} + diff --git a/lib/sgroupio.c b/lib/sgroupio.c index bae2068f..1a859068 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -101,18 +101,23 @@ static void gshadow_free (void *ent) { struct sgrp *sg = ent; - free (sg->sg_name); - memzero (sg->sg_passwd, strlen (sg->sg_passwd)); - free (sg->sg_passwd); - while (NULL != *(sg->sg_adm)) { - free (*(sg->sg_adm)); - sg->sg_adm++; + sgr_free (sg); +} + +void sgr_free (struct sgrp *sgent) +{ + free (sgent->sg_name); + memzero (sgent->sg_passwd, strlen (sgent->sg_passwd)); + free (sgent->sg_passwd); + while (NULL != *(sgent->sg_adm)) { + free (*(sgent->sg_adm)); + sgent->sg_adm++; } - while (NULL != *(sg->sg_mem)) { - free (*(sg->sg_mem)); - sg->sg_mem++; + while (NULL != *(sgent->sg_mem)) { + free (*(sgent->sg_mem)); + sgent->sg_mem++; } - free (sg); + free (sgent); } static const char *gshadow_getname (const void *ent) diff --git a/lib/shadowio.c b/lib/shadowio.c index 9a8000c4..bd7554f5 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -53,10 +53,7 @@ static void shadow_free (void *ent) { struct spwd *sp = ent; - free (sp->sp_namp); - memzero (sp->sp_pwdp, strlen (sp->sp_pwdp)); - free (sp->sp_pwdp); - free (sp); + spw_free (sp); } static const char *shadow_getname (const void *ent) diff --git a/lib/shadowmem.c b/lib/shadowmem.c index d27fde74..d4abdf15 100644 --- a/lib/shadowmem.c +++ b/lib/shadowmem.c @@ -62,3 +62,11 @@ struct spwd *__spw_dup (const struct spwd *spent) return sp; } +void spw_free (struct spwd *spent) +{ + free (spent->sp_namp); + memzero (spent->sp_pwdp, strlen (spent->sp_pwdp)); + free (spent->sp_pwdp); + free (spent); +} +