summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2020-07-03 08:11:20 +0200
committerJeremy Allison <jra@samba.org>2020-08-03 22:21:02 +0000
commit23274717563b19684c52f8a909f528f608dafd7c (patch)
treea4bce4303349b9598aeaeb62a8f67c462976f06d /lib
parent611e643d14659be8a63e9ca51d5d05659c4b8b6c (diff)
downloadsamba-23274717563b19684c52f8a909f528f608dafd7c.tar.gz
lib: relicense smb_strtoul(l) under LGPLv3
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Aug 3 22:21:04 UTC 2020 on sn-devel-184
Diffstat (limited to 'lib')
-rw-r--r--lib/ldb-samba/ldb_matching_rules.c1
-rw-r--r--lib/ldb-samba/ldif_handlers.c1
-rw-r--r--lib/messaging/messages_dgm.c1
-rw-r--r--lib/param/loadparm.c1
-rw-r--r--lib/util/access.c1
-rw-r--r--lib/util/asn1.c1
-rw-r--r--lib/util/smb_strtox.c177
-rw-r--r--lib/util/smb_strtox.h40
-rw-r--r--lib/util/tests/util.c1
-rw-r--r--lib/util/util.c152
-rw-r--r--lib/util/util.h13
-rw-r--r--lib/util/util_str.c1
-rw-r--r--lib/util/wscript_build7
13 files changed, 231 insertions, 166 deletions
diff --git a/lib/ldb-samba/ldb_matching_rules.c b/lib/ldb-samba/ldb_matching_rules.c
index 4b357bb706a..13edb51daaa 100644
--- a/lib/ldb-samba/ldb_matching_rules.c
+++ b/lib/ldb-samba/ldb_matching_rules.c
@@ -27,6 +27,7 @@
#include "libcli/security/security.h"
#include "dsdb/common/util.h"
#include "librpc/gen_ndr/ndr_dnsp.h"
+#include "lib/util/smb_strtox.h"
static int ldb_eval_transitive_filter_helper(TALLOC_CTX *mem_ctx,
struct ldb_context *ldb,
diff --git a/lib/ldb-samba/ldif_handlers.c b/lib/ldb-samba/ldif_handlers.c
index e74a7182ecf..78a433748bb 100644
--- a/lib/ldb-samba/ldif_handlers.c
+++ b/lib/ldb-samba/ldif_handlers.c
@@ -36,6 +36,7 @@
#include "libcli/security/security.h"
#include "param/param.h"
#include "../lib/util/asn1.h"
+#include "lib/util/smb_strtox.h"
/*
use ndr_print_* to convert a NDR formatted blob to a ldif formatted blob
diff --git a/lib/messaging/messages_dgm.c b/lib/messaging/messages_dgm.c
index b7126b9c8ca..7c9dd8eb42f 100644
--- a/lib/messaging/messages_dgm.c
+++ b/lib/messaging/messages_dgm.c
@@ -32,6 +32,7 @@
#include "lib/util/iov_buf.h"
#include "lib/util/blocking.h"
#include "lib/util/tevent_unix.h"
+#include "lib/util/smb_strtox.h"
#define MESSAGING_DGM_FRAGMENT_LENGTH 1024
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index da639a8b0ff..dc22f646b3e 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -73,6 +73,7 @@
#include "lib/util/samba_util.h"
#include "libcli/auth/ntlm_check.h"
#include "lib/crypto/gnutls_helpers.h"
+#include "lib/util/smb_strtox.h"
#ifdef HAVE_HTTPCONNECTENCRYPT
#include <cups/http.h>
diff --git a/lib/util/access.c b/lib/util/access.c
index 10a14771899..e02117fa23e 100644
--- a/lib/util/access.c
+++ b/lib/util/access.c
@@ -21,6 +21,7 @@
#include "lib/util/memory.h"
#include "lib/util/access.h"
#include "lib/util/unix_match.h"
+#include "lib/util/smb_strtox.h"
#if defined(HAVE_NETGROUP)
#include "system/nis.h"
diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index 88d96d4544b..0dfddc009c0 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -22,6 +22,7 @@
#include "lib/util/asn1.h"
#include "lib/util/debug.h"
#include "lib/util/samba_util.h"
+#include "lib/util/smb_strtox.h"
struct nesting {
off_t start;
diff --git a/lib/util/smb_strtox.c b/lib/util/smb_strtox.c
new file mode 100644
index 00000000000..2cace8b9aaf
--- /dev/null
+++ b/lib/util/smb_strtox.c
@@ -0,0 +1,177 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Copyright (C) Swen Schillig 2019
+ *
+ * ** NOTE! The following LGPL license applies to the tevent
+ * ** library. This does NOT imply that all of Samba is released
+ * ** under the LGPL
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "smb_strtox.h"
+
+/**
+ * Convert a string to an unsigned long integer
+ *
+ * @param nptr pointer to string which is to be converted
+ * @param endptr [optional] reference to remainder of the string
+ * @param base base of the numbering scheme
+ * @param err error occured during conversion
+ * @flags controlling conversion feature
+ * @result result of the conversion as provided by strtoul
+ *
+ * The following flags are supported
+ * SMB_STR_STANDARD # raise error if negative or non-numeric
+ * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
+ * SMB_STR_FULL_STR_CONV # entire string must be converted
+ * SMB_STR_ALLOW_NO_CONVERSION # allow empty strings or non-numeric
+ * SMB_STR_GLIBC_STANDARD # act exactly as the standard glibc strtoul
+ *
+ * The following errors are detected
+ * - wrong base
+ * - value overflow
+ * - string with a leading "-" indicating a negative number
+ * - no conversion due to empty string or not representing a number
+ */
+unsigned long int
+smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags)
+{
+ unsigned long int val;
+ int saved_errno = errno;
+ char *needle = NULL;
+ char *tmp_endptr = NULL;
+
+ errno = 0;
+ *err = 0;
+
+ val = strtoul(nptr, &tmp_endptr, base);
+
+ if (endptr != NULL) {
+ *endptr = tmp_endptr;
+ }
+
+ if (errno != 0) {
+ *err = errno;
+ errno = saved_errno;
+ return val;
+ }
+
+ if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) {
+ /* got an invalid number-string resulting in no conversion */
+ if (nptr == tmp_endptr) {
+ *err = EINVAL;
+ goto out;
+ }
+ }
+
+ if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {
+ /* did we convert a negative "number" ? */
+ needle = strchr(nptr, '-');
+ if (needle != NULL && needle < tmp_endptr) {
+ *err = EINVAL;
+ goto out;
+ }
+ }
+
+ if ((flags & SMB_STR_FULL_STR_CONV) != 0) {
+ /* did we convert the entire string ? */
+ if (tmp_endptr[0] != '\0') {
+ *err = EINVAL;
+ goto out;
+ }
+ }
+
+out:
+ errno = saved_errno;
+ return val;
+}
+
+/**
+ * Convert a string to an unsigned long long integer
+ *
+ * @param nptr pointer to string which is to be converted
+ * @param endptr [optional] reference to remainder of the string
+ * @param base base of the numbering scheme
+ * @param err error occured during conversion
+ * @flags controlling conversion feature
+ * @result result of the conversion as provided by strtoull
+ *
+ * The following flags are supported
+ * SMB_STR_STANDARD # raise error if negative or non-numeric
+ * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
+ * SMB_STR_FULL_STR_CONV # entire string must be converted
+ * SMB_STR_ALLOW_NO_CONVERSION # allow empty strings or non-numeric
+ * SMB_STR_GLIBC_STANDARD # act exactly as the standard glibc strtoul
+ *
+ * The following errors are detected
+ * - wrong base
+ * - value overflow
+ * - string with a leading "-" indicating a negative number
+ * - no conversion due to empty string or not representing a number
+ */
+unsigned long long int
+smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags)
+{
+ unsigned long long int val;
+ int saved_errno = errno;
+ char *needle = NULL;
+ char *tmp_endptr = NULL;
+
+ errno = 0;
+ *err = 0;
+
+ val = strtoull(nptr, &tmp_endptr, base);
+
+ if (endptr != NULL) {
+ *endptr = tmp_endptr;
+ }
+
+ if (errno != 0) {
+ *err = errno;
+ errno = saved_errno;
+ return val;
+ }
+
+ if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) {
+ /* got an invalid number-string resulting in no conversion */
+ if (nptr == tmp_endptr) {
+ *err = EINVAL;
+ goto out;
+ }
+ }
+
+ if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {
+ /* did we convert a negative "number" ? */
+ needle = strchr(nptr, '-');
+ if (needle != NULL && needle < tmp_endptr) {
+ *err = EINVAL;
+ goto out;
+ }
+ }
+
+ if ((flags & SMB_STR_FULL_STR_CONV) != 0) {
+ /* did we convert the entire string ? */
+ if (tmp_endptr[0] != '\0') {
+ *err = EINVAL;
+ goto out;
+ }
+ }
+
+out:
+ errno = saved_errno;
+ return val;
+}
diff --git a/lib/util/smb_strtox.h b/lib/util/smb_strtox.h
new file mode 100644
index 00000000000..f72bf123823
--- /dev/null
+++ b/lib/util/smb_strtox.h
@@ -0,0 +1,40 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Copyright (C) Swen Schillig 2019
+ *
+ * ** NOTE! The following LGPL license applies to the tevent
+ * ** library. This does NOT imply that all of Samba is released
+ * ** under the LGPL
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SMB_STRTOX_H
+#define SMB_STRTOX_H
+
+#define SMB_STR_STANDARD 0x00
+#define SMB_STR_ALLOW_NEGATIVE 0x01
+#define SMB_STR_FULL_STR_CONV 0x02
+#define SMB_STR_ALLOW_NO_CONVERSION 0x04
+#define SMB_STR_GLIBC_STANDARD (SMB_STR_ALLOW_NO_CONVERSION | \
+ SMB_STR_ALLOW_NEGATIVE)
+
+unsigned long int
+smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags);
+
+unsigned long long int
+smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags);
+
+#endif
diff --git a/lib/util/tests/util.c b/lib/util/tests/util.c
index 4876144bcdc..03f62974c3f 100644
--- a/lib/util/tests/util.c
+++ b/lib/util/tests/util.c
@@ -30,6 +30,7 @@
#include "torture/local/proto.h"
#include "lib/util/samba_util.h"
+#include "lib/util/smb_strtox.h"
#include "limits.h"
#include "string.h"
diff --git a/lib/util/util.c b/lib/util/util.c
index a90d48f6f1b..1f37688cbad 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -53,158 +53,6 @@
*/
/**
- * Convert a string to an unsigned long integer
- *
- * @param nptr pointer to string which is to be converted
- * @param endptr [optional] reference to remainder of the string
- * @param base base of the numbering scheme
- * @param err error occured during conversion
- * @flags controlling conversion feature
- * @result result of the conversion as provided by strtoul
- *
- * The following flags are supported
- * SMB_STR_STANDARD # raise error if negative or non-numeric
- * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
- * SMB_STR_FULL_STR_CONV # entire string must be converted
- * SMB_STR_ALLOW_NO_CONVERSION # allow empty strings or non-numeric
- * SMB_STR_GLIBC_STANDARD # act exactly as the standard glibc strtoul
- *
- * The following errors are detected
- * - wrong base
- * - value overflow
- * - string with a leading "-" indicating a negative number
- * - no conversion due to empty string or not representing a number
- */
-unsigned long int
-smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags)
-{
- unsigned long int val;
- int saved_errno = errno;
- char *needle = NULL;
- char *tmp_endptr = NULL;
-
- errno = 0;
- *err = 0;
-
- val = strtoul(nptr, &tmp_endptr, base);
-
- if (endptr != NULL) {
- *endptr = tmp_endptr;
- }
-
- if (errno != 0) {
- *err = errno;
- errno = saved_errno;
- return val;
- }
-
- if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) {
- /* got an invalid number-string resulting in no conversion */
- if (nptr == tmp_endptr) {
- *err = EINVAL;
- goto out;
- }
- }
-
- if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {
- /* did we convert a negative "number" ? */
- needle = strchr(nptr, '-');
- if (needle != NULL && needle < tmp_endptr) {
- *err = EINVAL;
- goto out;
- }
- }
-
- if ((flags & SMB_STR_FULL_STR_CONV) != 0) {
- /* did we convert the entire string ? */
- if (tmp_endptr[0] != '\0') {
- *err = EINVAL;
- goto out;
- }
- }
-
-out:
- errno = saved_errno;
- return val;
-}
-
-/**
- * Convert a string to an unsigned long long integer
- *
- * @param nptr pointer to string which is to be converted
- * @param endptr [optional] reference to remainder of the string
- * @param base base of the numbering scheme
- * @param err error occured during conversion
- * @flags controlling conversion feature
- * @result result of the conversion as provided by strtoull
- *
- * The following flags are supported
- * SMB_STR_STANDARD # raise error if negative or non-numeric
- * SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
- * SMB_STR_FULL_STR_CONV # entire string must be converted
- * SMB_STR_ALLOW_NO_CONVERSION # allow empty strings or non-numeric
- * SMB_STR_GLIBC_STANDARD # act exactly as the standard glibc strtoul
- *
- * The following errors are detected
- * - wrong base
- * - value overflow
- * - string with a leading "-" indicating a negative number
- * - no conversion due to empty string or not representing a number
- */
-unsigned long long int
-smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags)
-{
- unsigned long long int val;
- int saved_errno = errno;
- char *needle = NULL;
- char *tmp_endptr = NULL;
-
- errno = 0;
- *err = 0;
-
- val = strtoull(nptr, &tmp_endptr, base);
-
- if (endptr != NULL) {
- *endptr = tmp_endptr;
- }
-
- if (errno != 0) {
- *err = errno;
- errno = saved_errno;
- return val;
- }
-
- if ((flags & SMB_STR_ALLOW_NO_CONVERSION) == 0) {
- /* got an invalid number-string resulting in no conversion */
- if (nptr == tmp_endptr) {
- *err = EINVAL;
- goto out;
- }
- }
-
- if ((flags & SMB_STR_ALLOW_NEGATIVE ) == 0) {
- /* did we convert a negative "number" ? */
- needle = strchr(nptr, '-');
- if (needle != NULL && needle < tmp_endptr) {
- *err = EINVAL;
- goto out;
- }
- }
-
- if ((flags & SMB_STR_FULL_STR_CONV) != 0) {
- /* did we convert the entire string ? */
- if (tmp_endptr[0] != '\0') {
- *err = EINVAL;
- goto out;
- }
- }
-
-out:
- errno = saved_errno;
- return val;
-}
-
-/**
Find a suitable temporary directory. The result should be copied immediately
as it may be overwritten by a subsequent call.
**/
diff --git a/lib/util/util.h b/lib/util/util.h
index c89f4807d5b..a7acad56880 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -22,19 +22,6 @@
#ifndef __UTIL_SAMBA_UTIL_H__
#define __UTIL_SAMBA_UTIL_H__
-#define SMB_STR_STANDARD 0x00
-#define SMB_STR_ALLOW_NEGATIVE 0x01
-#define SMB_STR_FULL_STR_CONV 0x02
-#define SMB_STR_ALLOW_NO_CONVERSION 0x04
-#define SMB_STR_GLIBC_STANDARD (SMB_STR_ALLOW_NO_CONVERSION | \
- SMB_STR_ALLOW_NEGATIVE)
-
-unsigned long int
-smb_strtoul(const char *nptr, char **endptr, int base, int *err, int flags);
-
-unsigned long long int
-smb_strtoull(const char *nptr, char **endptr, int base, int *err, int flags);
-
/**
* Write dump of binary data to a callback
*/
diff --git a/lib/util/util_str.c b/lib/util/util_str.c
index 3356df34f04..c7773e0c927 100644
--- a/lib/util/util_str.c
+++ b/lib/util/util_str.c
@@ -23,6 +23,7 @@
#include "includes.h"
#include "system/locale.h"
+#include "smb_strtox.h"
#undef strncasecmp
#undef strcasemp
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 807c62636fd..afda713cb06 100644
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -81,10 +81,15 @@ bld.SAMBA_SUBSYSTEM('samba-util-core',
strv_util.c bitmap.c select.c pidfile.c
become_daemon.c mkdir_p.c''',
deps='''time-basic samba-debug socket-blocking talloc
- tevent execinfo pthread strv tini''',
+ tevent execinfo pthread strv tini smb_strtox''',
public_deps='systemd systemd-daemon sys_rw LIBUNWIND',
local_include=False)
+bld.SAMBA_SUBSYSTEM('smb_strtox',
+ source='smb_strtox.c',
+ local_include=False)
+
+
bld.SAMBA_LIBRARY('iov_buf',
source='iov_buf.c',
deps='talloc',