summaryrefslogtreecommitdiff
path: root/source3/lib/replace
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-01-15 19:10:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:17:09 -0500
commit2f66beb8adf679ed1e2e36f9c808c43f095e23cf (patch)
treeb7f486b40393da6ddc53a921d518160dbf9032f1 /source3/lib/replace
parent2ae539f5665ee9a849bad97cfb5ecc10cce3e766 (diff)
downloadsamba-2f66beb8adf679ed1e2e36f9c808c43f095e23cf.tar.gz
samba-2f66beb8adf679ed1e2e36f9c808c43f095e23cf.tar.bz2
samba-2f66beb8adf679ed1e2e36f9c808c43f095e23cf.zip
r20817: sync lib/replace with samba4
metze (This used to be commit 352ee730308bbc151a742938818c9b8b3a6e8014)
Diffstat (limited to 'source3/lib/replace')
-rw-r--r--source3/lib/replace/.checker_innocent4
-rw-r--r--source3/lib/replace/README1
-rw-r--r--source3/lib/replace/libreplace.m43
-rw-r--r--source3/lib/replace/libreplace_cc.m438
-rw-r--r--source3/lib/replace/replace.c21
-rw-r--r--source3/lib/replace/replace.h4
-rw-r--r--source3/lib/replace/snprintf.c2
-rw-r--r--source3/lib/replace/system/aio.h29
-rw-r--r--source3/lib/replace/system/kerberos.h1
-rw-r--r--source3/lib/replace/system/wait.h2
-rw-r--r--source3/lib/replace/test/os2_delete.c5
-rw-r--r--source3/lib/replace/test/testsuite.c79
12 files changed, 149 insertions, 40 deletions
diff --git a/source3/lib/replace/.checker_innocent b/source3/lib/replace/.checker_innocent
new file mode 100644
index 0000000000..e619176540
--- /dev/null
+++ b/source3/lib/replace/.checker_innocent
@@ -0,0 +1,4 @@
+>>>MISTAKE21_create_files_6a9e68ada99a97cb
+>>>MISTAKE21_os2_delete_9b2bfa7f38711d09
+>>>MISTAKE21_os2_delete_2fcc29aaa99a97cb
+>>>SECURITY2_os2_delete_9b2bfa7f1c9396ca
diff --git a/source3/lib/replace/README b/source3/lib/replace/README
index 182a276116..a313984c8e 100644
--- a/source3/lib/replace/README
+++ b/source3/lib/replace/README
@@ -52,6 +52,7 @@ readline (the library)
inet_ntoa
strtoll
strtoull
+socketpair
Types:
bool
diff --git a/source3/lib/replace/libreplace.m4 b/source3/lib/replace/libreplace.m4
index 1dfc823a68..3328dea95e 100644
--- a/source3/lib/replace/libreplace.m4
+++ b/source3/lib/replace/libreplace.m4
@@ -62,6 +62,7 @@ AC_FUNC_MEMCMP
AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
AC_CHECK_HEADERS(stdbool.h sys/select.h)
+AC_CHECK_HEADERS(setjmp.h)
AC_CHECK_TYPE(bool,
[AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
@@ -147,7 +148,7 @@ AC_TRY_COMPILE([
AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
-AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
+AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp socketpair)
AC_HAVE_DECL(setresuid, [#include <unistd.h>])
AC_HAVE_DECL(setresgid, [#include <unistd.h>])
AC_HAVE_DECL(errno, [#include <errno.h>])
diff --git a/source3/lib/replace/libreplace_cc.m4 b/source3/lib/replace/libreplace_cc.m4
index b8b74036e5..74c53cad99 100644
--- a/source3/lib/replace/libreplace_cc.m4
+++ b/source3/lib/replace/libreplace_cc.m4
@@ -140,23 +140,27 @@ fi
############################################
# check if the compiler can do immediate structures
-AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
- AC_TRY_COMPILE([
-#include <stdio.h>],
-[
- typedef struct {unsigned x;} FOOBAR;
- #define X_FOOBAR(x) ((FOOBAR) { x })
- #define FOO_ONE X_FOOBAR(1)
- FOOBAR f = FOO_ONE;
- static const struct {
- FOOBAR y;
- } f2[] = {
- {FOO_ONE}
- };
-],
- samba_cv_immediate_structures=yes,samba_cv_immediate_structures=no)])
-if test x"$samba_cv_immediate_structures" = x"yes"; then
- AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
+AC_SUBST(libreplace_cv_immediate_structures)
+AC_CACHE_CHECK([for immediate structures],libreplace_cv_immediate_structures,[
+ AC_TRY_COMPILE([
+ #include <stdio.h>
+ ],[
+ typedef struct {unsigned x;} FOOBAR;
+ #define X_FOOBAR(x) ((FOOBAR) { x })
+ #define FOO_ONE X_FOOBAR(1)
+ FOOBAR f = FOO_ONE;
+ static const struct {
+ FOOBAR y;
+ } f2[] = {
+ {FOO_ONE}
+ };
+ ],
+ libreplace_cv_immediate_structures=yes,
+ libreplace_cv_immediate_structures=no,
+ libreplace_cv_immediate_structures=cross)
+])
+if test x"$libreplace_cv_immediate_structures" = x"yes"; then
+ AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
fi
AC__LIBREPLACE_ONLY_CC_CHECKS_END
diff --git a/source3/lib/replace/replace.c b/source3/lib/replace/replace.c
index e7f47d7d52..9e6c75bd35 100644
--- a/source3/lib/replace/replace.c
+++ b/source3/lib/replace/replace.c
@@ -590,3 +590,24 @@ int rep_setenv(const char *name, const char *value, int overwrite)
}
#endif
+#ifndef HAVE_SOCKETPAIR
+int rep_socketpair(int d, int type, int protocol, int sv[2])
+{
+ if (d != AF_UNIX) {
+ errno = EAFNOSUPPORT;
+ return -1;
+ }
+
+ if (protocol != 0) {
+ errno = EPROTONOSUPPORT;
+ return -1;
+ }
+
+ if (type != SOCK_STREAM) {
+ errno = EOPNOTSUPP;
+ return -1;
+ }
+
+ return pipe(sv);
+}
+#endif
diff --git a/source3/lib/replace/replace.h b/source3/lib/replace/replace.h
index 7a79f335e2..d75394aa1f 100644
--- a/source3/lib/replace/replace.h
+++ b/source3/lib/replace/replace.h
@@ -209,6 +209,10 @@ void *rep_dlsym(void *handle, const char *symbol);
int rep_dlclose(void *handle);
#endif
+#ifndef HAVE_SOCKETPAIR
+#define socketpair rep_socketpair
+int rep_socketpair(int d, int type, int protocol, int sv[2]);
+#endif
#ifndef PRINTF_ATTRIBUTE
#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 )
diff --git a/source3/lib/replace/snprintf.c b/source3/lib/replace/snprintf.c
index fcbcdb17e9..b38d8dad34 100644
--- a/source3/lib/replace/snprintf.c
+++ b/source3/lib/replace/snprintf.c
@@ -540,7 +540,7 @@ static int dopr(char *buffer, size_t maxlen, const char *format, va_list args_in
printf("parameter at position %d not used\n", pnum+1);
#endif
/* eat the parameter */
- (void)va_arg (args, int);
+ va_arg (args, int);
continue;
}
for (i = 1; i < clist[pnum].num; i++) {
diff --git a/source3/lib/replace/system/aio.h b/source3/lib/replace/system/aio.h
new file mode 100644
index 0000000000..e1b9d836e7
--- /dev/null
+++ b/source3/lib/replace/system/aio.h
@@ -0,0 +1,29 @@
+#ifndef _system_aio_h
+#define _system_aio_h
+/*
+ Unix SMB/CIFS implementation.
+
+ AIO system include wrappers
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#if HAVE_LIBAIO_H
+#include <libaio.h>
+#endif
+
+#endif
diff --git a/source3/lib/replace/system/kerberos.h b/source3/lib/replace/system/kerberos.h
index b24196fc25..1617b96aad 100644
--- a/source3/lib/replace/system/kerberos.h
+++ b/source3/lib/replace/system/kerberos.h
@@ -126,7 +126,6 @@
#define KRB5_PRINC_REALM_RETURNS_REALM 1
#include "heimdal/lib/krb5/krb5.h"
-#include "heimdal/lib/gssapi/gssapi.h"
#include "heimdal/lib/com_err/com_err.h"
#endif
diff --git a/source3/lib/replace/system/wait.h b/source3/lib/replace/system/wait.h
index 47e3e84bb1..3855f7ae72 100644
--- a/source3/lib/replace/system/wait.h
+++ b/source3/lib/replace/system/wait.h
@@ -36,6 +36,8 @@
#define SIGNAL_CAST (RETSIGTYPE (*)(int))
#endif
+#ifdef HAVE_SETJMP_H
#include <setjmp.h>
+#endif
#endif
diff --git a/source3/lib/replace/test/os2_delete.c b/source3/lib/replace/test/os2_delete.c
index b2bce7e7ff..c8abfccff9 100644
--- a/source3/lib/replace/test/os2_delete.c
+++ b/source3/lib/replace/test/os2_delete.c
@@ -20,9 +20,8 @@
#define TESTDIR "test.dir"
static int test_readdir_os2_delete_ret;
-int test_readdir_os2_delete(void);
-#define FAILED(d) (fprintf(stderr, "Failed for %s - %d = %s\n", d, errno, strerror(errno)), test_readdir_os2_delete_ret = 1, 1)
+#define FAILED(d) (printf("failure: readdir [\nFailed for %s - %d = %s\n]\n", d, errno, strerror(errno)), test_readdir_os2_delete_ret = 1, 1)
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
@@ -108,7 +107,7 @@ int test_readdir_os2_delete(void)
}
closedir(d);
- printf("Deleted %d files of %d\n", total_deleted, NUM_FILES);
+ fprintf(stderr, "Deleted %d files of %d\n", total_deleted, NUM_FILES);
rmdir(TESTDIR) == 0 || FAILED("rmdir");
diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c
index c10a220d7b..8a9fb9ab87 100644
--- a/source3/lib/replace/test/testsuite.c
+++ b/source3/lib/replace/test/testsuite.c
@@ -57,26 +57,29 @@ static int test_ftruncate(void)
struct stat st;
int fd;
const int size = 1234;
- printf("testing ftruncate\n");
+ printf("test: ftruncate\n");
unlink(TESTFILE);
fd = open(TESTFILE, O_RDWR|O_CREAT, 0600);
if (fd == -1) {
- printf("creating '%s' failed - %s\n", TESTFILE, strerror(errno));
+ printf("failure: ftruncate [\n"
+ "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno));
return false;
}
if (ftruncate(fd, size) != 0) {
- printf("ftruncate failed - %s\n", strerror(errno));
+ printf("failure: ftruncate [\n%s\n]\n", strerror(errno));
return false;
}
if (fstat(fd, &st) != 0) {
- printf("fstat failed - %s\n", strerror(errno));
+ printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno));
return false;
}
if (st.st_size != size) {
- printf("ftruncate gave wrong size %d - expected %d\n",
+ printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n",
(int)st.st_size, size);
return false;
}
+ unlink(TESTFILE);
+ printf("success: ftruncate\n");
return true;
}
@@ -98,13 +101,14 @@ static int test_strlcpy(void)
{ NULL, 0 }
};
int i;
- printf("testing strlcpy\n");
+ printf("test: strlcpy\n");
for (i=0;tests[i].src;i++) {
if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
- printf("strlcpy test %d failed\n", i);
+ printf("failure: strlcpy [\ntest %d failed\n]\n", i);
return false;
}
}
+ printf("success: strlcpy\n");
return true;
}
@@ -146,8 +150,9 @@ static int test_strdup(void)
static int test_setlinebuf(void)
{
- printf("testing setlinebuf\n");
+ printf("test: setlinebuf\n");
setlinebuf(stdout);
+ printf("success: setlinebuf\n");
return true;
}
@@ -233,10 +238,11 @@ extern int test_readdir_os2_delete(void);
static int test_readdir(void)
{
- printf("testing readdir\n");
+ printf("test: readdir\n");
if (test_readdir_os2_delete() != 0) {
return false;
}
+ printf("success: readdir\n");
return true;
}
@@ -371,9 +377,48 @@ static int test_MAX(void)
return true;
}
-struct torture_context;
+static int test_socketpair(void)
+{
+ int sock[2];
+ char buf[20];
+
+ printf("test: socketpair\n");
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) {
+ printf("failure: socketpair [\n"
+ "socketpair() failed\n"
+ "]\n");
+ return false;
+ }
+
+ if (write(sock[1], "automatisch", 12) == -1) {
+ printf("failure: socketpair [\n"
+ "write() failed: %s\n"
+ "]\n", strerror(errno));
+ return false;
+ }
+
+ if (read(sock[0], buf, 12) == -1) {
+ printf("failure: socketpair [\n"
+ "read() failed: %s\n"
+ "]\n", strerror(errno));
+ return false;
+ }
+
+ if (strcmp(buf, "automatisch") != 0) {
+ printf("failure: socketpair [\n"
+ "expected: automatisch, got: %s\n"
+ "]\n", buf);
+ return false;
+ }
+
+ printf("success: socketpair\n");
-static bool torture_local_replace(struct torture_context *torture)
+ return true;
+}
+
+struct torture_context;
+bool torture_local_replace(struct torture_context *ctx)
{
bool ret = true;
ret &= test_ftruncate();
@@ -419,17 +464,17 @@ static bool torture_local_replace(struct torture_context *torture)
ret &= test_FUNCTION();
ret &= test_MIN();
ret &= test_MAX();
+ ret &= test_socketpair();
return ret;
}
#if _SAMBA_BUILD_<4
-int main(void)
+int main()
{
- if (!torture_local_replace(NULL)) {
- printf("ERROR: TESTSUITE FAILED\n");
- return -1;
- }
- return 0;
+ bool ret = torture_local_replace(NULL);
+ if (ret)
+ return 0;
+ return -1;
}
#endif