]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
libmisc: add freezero source code
authorIker Pedrosa <ipedrosa@redhat.com>
Thu, 10 Aug 2023 07:45:32 +0000 (09:45 +0200)
committerSerge Hallyn <serge@hallyn.com>
Thu, 10 Aug 2023 14:29:17 +0000 (09:29 -0500)
If shadow is built without libbsd support, then freezero() needs to be
provided from the project.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
libmisc/Makefile.am
libmisc/freezero.c [new file with mode: 0644]
libmisc/freezero.h [new file with mode: 0644]

index 1540f3c44f8b42bfd62340f6cca6ec7e6bb11bc0..10bf1537f2f0ea961433f7589d3666a303610efc 100644 (file)
@@ -107,6 +107,8 @@ endif
 
 if !WITH_LIBBSD
 libmisc_la_SOURCES += \
+       freezero.h \
+       freezero.c \
        readpassphrase.h \
        readpassphrase.c
 endif
diff --git a/libmisc/freezero.c b/libmisc/freezero.c
new file mode 100644 (file)
index 0000000..c565f43
--- /dev/null
@@ -0,0 +1,30 @@
+/*     $OpenBSD: malloc.c,v 1.267 2020/11/23 15:42:11 otto Exp $       */
+/*
+ * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+void
+freezero(void *ptr, size_t sz)
+{
+       /* This is legal. */
+       if (ptr == NULL)
+               return;
+
+       explicit_bzero(ptr, sz);
+       free(ptr);
+}
diff --git a/libmisc/freezero.h b/libmisc/freezero.h
new file mode 100644 (file)
index 0000000..8dbcd7c
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2005 Aurelien Jarno
+ * Copyright © 2006 Robert Millan
+ * Copyright © 2008-2011 Guillem Jover <guillem@hadrons.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LIBBSD_FREEZERO_H
+#define LIBBSD_FREEZERO_H
+
+void freezero(void *ptr, size_t size);
+
+#endif