From 19da58be2d9359a9641381feb559be0b918ef710 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 22:46:53 +0200 Subject: Adding upstream version 1:4.13+dfsg1. Signed-off-by: Daniel Baumann --- lib/pwmem.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lib/pwmem.c (limited to 'lib/pwmem.c') diff --git a/lib/pwmem.c b/lib/pwmem.c new file mode 100644 index 0000000..867e3f7 --- /dev/null +++ b/lib/pwmem.c @@ -0,0 +1,85 @@ +/* + * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh + * SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz + * SPDX-FileCopyrightText: 2001 , Michał Moskal + * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko + * SPDX-FileCopyrightText: 2007 - 2013, Nicolas François + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#ident "$Id$" + +#include +#include "defines.h" +#include "prototypes.h" +#include "pwio.h" + +/*@null@*/ /*@only@*/struct passwd *__pw_dup (const struct passwd *pwent) +{ + struct passwd *pw; + + pw = (struct passwd *) malloc (sizeof *pw); + if (NULL == pw) { + return NULL; + } + /* The libc might define other fields. They won't be copied. */ + memset (pw, 0, sizeof *pw); + pw->pw_uid = pwent->pw_uid; + pw->pw_gid = pwent->pw_gid; + /*@-mustfreeonly@*/ + pw->pw_name = strdup (pwent->pw_name); + /*@=mustfreeonly@*/ + if (NULL == pw->pw_name) { + pw_free(pw); + return NULL; + } + /*@-mustfreeonly@*/ + pw->pw_passwd = strdup (pwent->pw_passwd); + /*@=mustfreeonly@*/ + if (NULL == pw->pw_passwd) { + pw_free(pw); + return NULL; + } + /*@-mustfreeonly@*/ + pw->pw_gecos = strdup (pwent->pw_gecos); + /*@=mustfreeonly@*/ + if (NULL == pw->pw_gecos) { + pw_free(pw); + return NULL; + } + /*@-mustfreeonly@*/ + pw->pw_dir = strdup (pwent->pw_dir); + /*@=mustfreeonly@*/ + if (NULL == pw->pw_dir) { + pw_free(pw); + return NULL; + } + /*@-mustfreeonly@*/ + pw->pw_shell = strdup (pwent->pw_shell); + /*@=mustfreeonly@*/ + if (NULL == pw->pw_shell) { + pw_free(pw); + return NULL; + } + + return pw; +} + +void pw_free (/*@out@*/ /*@only@*/struct passwd *pwent) +{ + if (pwent != NULL) { + free (pwent->pw_name); + if (pwent->pw_passwd) { + strzero (pwent->pw_passwd); + free (pwent->pw_passwd); + } + free (pwent->pw_gecos); + free (pwent->pw_dir); + free (pwent->pw_shell); + free (pwent); + } +} + -- cgit v1.2.3