summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-10-11 03:12:21 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-10-11 03:12:21 +0200
commit0fd0fc75c46b39a611c7f9a56081105714d73e36 (patch)
treeb93ef5e67e49a3aa49c37e13df3d6222b2df7095 /lib
parent69d38a95c29498c0266cb98b911faa3e7240c787 (diff)
parent47f7ef8f39ba482a7d6578ab82c9e0670381c4f8 (diff)
downloadsamba-0fd0fc75c46b39a611c7f9a56081105714d73e36.tar.gz
samba-0fd0fc75c46b39a611c7f9a56081105714d73e36.tar.bz2
samba-0fd0fc75c46b39a611c7f9a56081105714d73e36.zip
Merge branch 'master' of ssh://git.samba.org/data/git/samba into selftest
Conflicts: selftest/selftest.pl
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/arcfour.c91
-rw-r--r--lib/crypto/arcfour.h15
-rw-r--r--lib/crypto/config.mk18
-rw-r--r--lib/crypto/crc32.c103
-rw-r--r--lib/crypto/crc32.h1
-rw-r--r--lib/crypto/crypto.h28
-rw-r--r--lib/crypto/hmacmd5.c117
-rw-r--r--lib/crypto/hmacmd5.h41
-rw-r--r--lib/crypto/hmacmd5test.c98
-rw-r--r--lib/crypto/hmacsha256.c91
-rw-r--r--lib/crypto/hmacsha256.h38
-rw-r--r--lib/crypto/md4.c176
-rw-r--r--lib/crypto/md4.h1
-rw-r--r--lib/crypto/md4test.c83
-rw-r--r--lib/crypto/md5.c248
-rw-r--r--lib/crypto/md5.h19
-rw-r--r--lib/crypto/md5test.c93
-rw-r--r--lib/crypto/sha256.c253
-rw-r--r--lib/crypto/sha256.h91
-rw-r--r--lib/replace/Makefile.in15
-rw-r--r--lib/replace/build_macros.m414
-rw-r--r--lib/replace/configure.ac3
-rw-r--r--lib/replace/libreplace.m44
-rw-r--r--lib/replace/test/main.c37
-rw-r--r--lib/replace/test/testsuite.c10
-rw-r--r--lib/socket_wrapper/socket_wrapper.c38
-rwxr-xr-xlib/subunit/harness2subunit.pl36
-rw-r--r--lib/subunit/python/subunit/__init__.py388
-rw-r--r--lib/subunit/python/subunit/tests/TestUtil.py80
-rw-r--r--lib/subunit/python/subunit/tests/__init__.py25
-rwxr-xr-xlib/subunit/python/subunit/tests/sample-script.py11
-rwxr-xr-xlib/subunit/python/subunit/tests/sample-two-script.py7
-rw-r--r--lib/subunit/python/subunit/tests/test_test_protocol.py730
-rw-r--r--lib/talloc/Makefile.in10
-rw-r--r--lib/talloc/build_macros.m414
-rw-r--r--lib/talloc/configure.ac3
-rw-r--r--lib/talloc/talloc.mk10
-rw-r--r--lib/talloc/talloc_guide.txt43
-rw-r--r--lib/talloc/testsuite.c10
-rw-r--r--lib/talloc/testsuite_main.c37
-rw-r--r--lib/tdb/Makefile.in11
-rw-r--r--lib/tdb/build_macros.m414
-rw-r--r--lib/tdb/configure.ac6
-rw-r--r--lib/tdb/include/tdb.h1
-rw-r--r--lib/tdb/tdb.i5
-rw-r--r--lib/tdb/tdb.py5
-rw-r--r--lib/tdb/tdb_wrap.c59
47 files changed, 3135 insertions, 96 deletions
diff --git a/lib/crypto/arcfour.c b/lib/crypto/arcfour.c
new file mode 100644
index 0000000000..c57e05d0e9
--- /dev/null
+++ b/lib/crypto/arcfour.c
@@ -0,0 +1,91 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ An implementation of the arcfour algorithm
+
+ Copyright (C) Andrew Tridgell 1998
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "../lib/crypto/arcfour.h"
+
+/* initialise the arcfour sbox with key */
+_PUBLIC_ void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key)
+{
+ int ind;
+ uint8_t j = 0;
+ for (ind = 0; ind < sizeof(state->sbox); ind++) {
+ state->sbox[ind] = (uint8_t)ind;
+ }
+
+ for (ind = 0; ind < sizeof(state->sbox); ind++) {
+ uint8_t tc;
+
+ j += (state->sbox[ind] + key->data[ind%key->length]);
+
+ tc = state->sbox[ind];
+ state->sbox[ind] = state->sbox[j];
+ state->sbox[j] = tc;
+ }
+ state->index_i = 0;
+ state->index_j = 0;
+}
+
+/* crypt the data with arcfour */
+_PUBLIC_ void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len)
+{
+ int ind;
+
+ for (ind = 0; ind < len; ind++) {
+ uint8_t tc;
+ uint8_t t;
+
+ state->index_i++;
+ state->index_j += state->sbox[state->index_i];
+
+ tc = state->sbox[state->index_i];
+ state->sbox[state->index_i] = state->sbox[state->index_j];
+ state->sbox[state->index_j] = tc;
+
+ t = state->sbox[state->index_i] + state->sbox[state->index_j];
+ data[ind] = data[ind] ^ state->sbox[t];
+ }
+}
+
+/*
+ arcfour encryption with a blob key
+*/
+_PUBLIC_ void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key)
+{
+ struct arcfour_state state;
+ arcfour_init(&state, key);
+ arcfour_crypt_sbox(&state, data, len);
+}
+
+/*
+ a variant that assumes a 16 byte key. This should be removed
+ when the last user is gone
+*/
+_PUBLIC_ void arcfour_crypt(uint8_t *data, const uint8_t keystr[16], int len)
+{
+ DATA_BLOB key = data_blob(keystr, 16);
+
+ arcfour_crypt_blob(data, len, &key);
+
+ data_blob_free(&key);
+}
+
+
diff --git a/lib/crypto/arcfour.h b/lib/crypto/arcfour.h
new file mode 100644
index 0000000000..501b3f2fab
--- /dev/null
+++ b/lib/crypto/arcfour.h
@@ -0,0 +1,15 @@
+#ifndef ARCFOUR_HEADER_H
+#define ARCFOUR_HEADER_H
+
+struct arcfour_state {
+ uint8_t sbox[256];
+ uint8_t index_i;
+ uint8_t index_j;
+};
+
+void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key);
+void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len);
+void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key);
+void arcfour_crypt(uint8_t *data, const uint8_t keystr[16], int len);
+
+#endif /* ARCFOUR_HEADER_H */
diff --git a/lib/crypto/config.mk b/lib/crypto/config.mk
new file mode 100644
index 0000000000..ee111bd088
--- /dev/null
+++ b/lib/crypto/config.mk
@@ -0,0 +1,18 @@
+##############################
+# Start SUBSYSTEM LIBCRYPTO
+[SUBSYSTEM::LIBCRYPTO]
+# End SUBSYSTEM LIBCRYPTO
+##############################
+
+LIBCRYPTO_OBJ_FILES = $(addprefix $(libcryptosrcdir)/, \
+ crc32.o md5.o hmacmd5.o md4.o \
+ arcfour.o sha256.o hmacsha256.o)
+
+[MODULE::TORTURE_LIBCRYPTO]
+SUBSYSTEM = smbtorture
+PRIVATE_DEPENDENCIES = LIBCRYPTO
+
+TORTURE_LIBCRYPTO_OBJ_FILES = $(addprefix $(libcryptosrcdir)/, \
+ md4test.o md5test.o hmacmd5test.o)
+
+$(eval $(call proto_header_template,$(libcryptosrcdir)/test_proto.h,$(TORTURE_LIBCRYPTO_OBJ_FILES:.o=.c)))
diff --git a/lib/crypto/crc32.c b/lib/crypto/crc32.c
new file mode 100644
index 0000000000..5b9d9b108d
--- /dev/null
+++ b/lib/crypto/crc32.c
@@ -0,0 +1,103 @@
+/*-
+ * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
+ * code or tables extracted from it, as desired without restriction.
+ *
+ * First, the polynomial itself and its table of feedback terms. The
+ * polynomial is
+ * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
+ *
+ * Note that we take it "backwards" and put the highest-order term in
+ * the lowest-order bit. The X^32 term is "implied"; the LSB is the
+ * X^31 term, etc. The X^0 term (usually shown as "+1") results in
+ * the MSB being 1
+ *
+ * Note that the usual hardware shift register implementation, which
+ * is what we're using (we're merely optimizing it by doing eight-bit
+ * chunks at a time) shifts bits into the lowest-order term. In our
+ * implementation, that means shifting towards the right. Why do we
+ * do it this way? Because the calculated CRC must be transmitted in
+ * order from highest-order term to lowest-order term. UARTs transmit
+ * characters in order from LSB to MSB. By storing the CRC this way
+ * we hand it to the UART in the order low-byte to high-byte; the UART
+ * sends each low-bit to hight-bit; and the result is transmission bit
+ * by bit from highest- to lowest-order term without requiring any bit
+ * shuffling on our part. Reception works similarly
+ *
+ * The feedback terms table consists of 256, 32-bit entries. Notes
+ *
+ * The table can be generated at runtime if desired; code to do so
+ * is shown later. It might not be obvious, but the feedback
+ * terms simply represent the results of eight shift/xor opera
+ * tions for all combinations of data and CRC register values
+ *
+ * The values must be right-shifted by eight bits by the "updcrc
+ * logic; the shift must be unsigned (bring in zeroes). On some
+ * hardware you could probably optimize the shift in assembler by
+ * using byte-swap instructions
+ * polynomial $edb88320
+ *
+ *
+ * CRC32 code derived from work by Gary S. Brown.
+ */
+
+#include "includes.h"
+
+static const uint32_t crc32_tab[] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+};
+
+uint32_t crc32_calc_buffer(const uint8_t *buf, size_t size)
+{
+ const uint8_t *p;
+ uint32_t crc;
+
+ p = buf;
+ crc = ~0U;
+
+ while (size--)
+ crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
+
+ return crc ^ ~0U;
+}
diff --git a/lib/crypto/crc32.h b/lib/crypto/crc32.h
new file mode 100644
index 0000000000..7854abf865
--- /dev/null
+++ b/lib/crypto/crc32.h
@@ -0,0 +1 @@
+uint32_t crc32_calc_buffer(const uint8_t *buf, size_t size);
diff --git a/lib/crypto/crypto.h b/lib/crypto/crypto.h
new file mode 100644
index 0000000000..0a43cbe7d4
--- /dev/null
+++ b/lib/crypto/crypto.h
@@ -0,0 +1,28 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Copyright (C) Andrew Tridgell 2004
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "../lib/crypto/crc32.h"
+#include "../lib/crypto/md4.h"
+#include "../lib/crypto/md5.h"
+#include "../lib/crypto/hmacmd5.h"
+#include "../lib/crypto/sha256.h"
+#include "../lib/crypto/hmacsha256.h"
+#include "../lib/crypto/arcfour.h"
+
+
diff --git a/lib/crypto/hmacmd5.c b/lib/crypto/hmacmd5.c
new file mode 100644
index 0000000000..0c8d1ab598
--- /dev/null
+++ b/lib/crypto/hmacmd5.c
@@ -0,0 +1,117 @@
+/*
+ Unix SMB/CIFS implementation.
+ HMAC MD5 code for use in NTLMv2
+ Copyright (C) Luke Kenneth Casson Leighton 1996-2000
+ Copyright (C) Andrew Tridgell 1992-2000
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+/* taken direct from rfc2104 implementation and modified for suitable use
+ * for ntlmv2.
+ */
+
+#include "includes.h"
+#include "../lib/crypto/hmacmd5.h"
+
+/***********************************************************************
+ the rfc 2104 version of hmac_md5 initialisation.
+***********************************************************************/
+_PUBLIC_ void hmac_md5_init_rfc2104(const uint8_t *key, int key_len, HMACMD5Context *ctx)
+{
+ int i;
+ uint8_t tk[16];
+
+ /* if key is longer than 64 bytes reset it to key=MD5(key) */
+ if (key_len > 64)
+ {
+ struct MD5Context tctx;
+
+ MD5Init(&tctx);
+ MD5Update(&tctx, key, key_len);
+ MD5Final(tk, &tctx);
+
+ key = tk;
+ key_len = 16;
+ }
+
+ /* start out by storing key in pads */
+ ZERO_STRUCT(ctx->k_ipad);
+ ZERO_STRUCT(ctx->k_opad);
+ memcpy( ctx->k_ipad, key, key_len);
+ memcpy( ctx->k_opad, key, key_len);
+
+ /* XOR key with ipad and opad values */
+ for (i=0; i<64; i++)
+ {
+ ctx->k_ipad[i] ^= 0x36;
+ ctx->k_opad[i] ^= 0x5c;
+ }
+
+ MD5Init(&ctx->ctx);
+ MD5Update(&ctx->ctx, ctx->k_ipad, 64);
+}
+
+/***********************************************************************
+ the microsoft version of hmac_md5 initialisation.
+***********************************************************************/
+_PUBLIC_ void hmac_md5_init_limK_to_64(const uint8_t *key, int key_len,
+ HMACMD5Context *ctx)
+{
+ /* if key is longer than 64 bytes truncate it */
+ if (key_len > 64)
+ {
+ key_len = 64;
+ }
+
+ hmac_md5_init_rfc2104(key, key_len, ctx);
+}
+
+/***********************************************************************
+ update hmac_md5 "inner" buffer
+***********************************************************************/
+_PUBLIC_ void hmac_md5_update(const uint8_t *text, int text_len, HMACMD5Context *ctx)
+{
+ MD5Update(&ctx->ctx, text, text_len); /* then text of datagram */
+}
+
+/***********************************************************************
+ finish off hmac_md5 "inner" buffer and generate outer one.
+***********************************************************************/
+_PUBLIC_ void hmac_md5_final(uint8_t *digest, HMACMD5Context *ctx)
+{
+ struct MD5Context ctx_o;
+
+ MD5Final(digest, &ctx->ctx);
+
+ MD5Init(&ctx_o);
+ MD5Update(&ctx_o, ctx->k_opad, 64);
+ MD5Update(&ctx_o, digest, 16);
+ MD5Final(digest, &ctx_o);
+}
+
+/***********************************************************
+ single function to calculate an HMAC MD5 digest from data.
+ use the microsoft hmacmd5 init method because the key is 16 bytes.
+************************************************************/
+_PUBLIC_ void hmac_md5(const uint8_t key[16], const uint8_t *data, int data_len, uint8_t *digest)
+{
+ HMACMD5Context ctx;
+ hmac_md5_init_limK_to_64(key, 16, &ctx);
+ if (data_len != 0)
+ {
+ hmac_md5_update(data, data_len, &ctx);
+ }
+ hmac_md5_final(digest, &ctx);
+}
diff --git a/lib/crypto/hmacmd5.h b/lib/crypto/hmacmd5.h
new file mode 100644
index 0000000000..91b8ca586c
--- /dev/null
+++ b/lib/crypto/hmacmd5.h
@@ -0,0 +1,41 @@
+/*
+ Unix SMB/CIFS implementation.
+ Interface header: HMAC MD5 code
+ Copyright (C) Luke Kenneth Casson Leighton 1996-1999
+ Copyright (C) Andrew Tridgell 1992-1999
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _HMAC_MD5_H
+#define _HMAC_MD5_H
+
+#include "../lib/crypto/md5.h"
+
+typedef struct
+{
+ struct MD5Context ctx;
+ uint8_t k_ipad[65];
+ uint8_t k_opad[65];
+
+} HMACMD5Context;
+
+void hmac_md5_init_limK_to_64(const uint8_t *key, int key_len,
+ HMACMD5Context *ctx);
+void hmac_md5_update(const uint8_t *text, int text_len, HMACMD5Context *ctx);
+void hmac_md5_final(uint8_t *digest, HMACMD5Context *ctx);
+void hmac_md5(const uint8_t key[16], const uint8_t *data, int data_len, uint8_t *digest);
+void hmac_md5_init_rfc2104(const uint8_t *key, int key_len, HMACMD5Context *ctx);
+
+#endif /* _HMAC_MD5_H */
diff --git a/lib/crypto/hmacmd5test.c b/lib/crypto/hmacmd5test.c
new file mode 100644
index 0000000000..0a98404eda
--- /dev/null
+++ b/lib/crypto/hmacmd5test.c
@@ -0,0 +1,98 @@
+/*
+ Unix SMB/CIFS implementation.
+ HMAC MD5 tests
+ Copyright (C) Stefan Metzmacher 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+#include "includes.h"
+#include "../lib/crypto/crypto.h"
+
+struct torture_context;
+
+static DATA_BLOB data_blob_repeat_byte(uint8_t byte, size_t length)
+{
+ DATA_BLOB b = data_blob(NULL, length);
+ memset(b.data, byte, length);
+ return b;
+}
+
+/*
+ This uses the test values from rfc 2104, 2202
+*/
+bool torture_local_crypto_hmacmd5(struct torture_context *torture)
+{
+ bool ret = true;
+ uint32_t i;
+ struct {
+ DATA_BLOB key;
+ DATA_BLOB data;
+ DATA_BLOB md5;
+ } testarray[8];
+
+ testarray[0].key = data_blob_repeat_byte(0x0b, 16);
+ testarray[0].data = data_blob_string_const("Hi There");
+ testarray[0].md5 = strhex_to_data_blob("9294727a3638bb1c13f48ef8158bfc9d");
+
+ testarray[1].key = data_blob_string_const("Jefe");
+ testarray[1].data = data_blob_string_const("what do ya want for nothing?");
+ testarray[1].md5 = strhex_to_data_blob("750c783e6ab0b503eaa86e310a5db738");
+
+ testarray[2].key = data_blob_repeat_byte(0xaa, 16);
+ testarray[2].data = data_blob_repeat_byte(0xdd, 50);
+ testarray[2].md5 = strhex_to_data_blob("56be34521d144c88dbb8c733f0e8b3f6");
+
+ testarray[3].key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819");
+ testarray[3].data = data_blob_repeat_byte(0xcd, 50);
+ testarray[3].md5 = strhex_to_data_blob("697eaf0aca3a3aea3a75164746ffaa79");
+
+ testarray[4].key = data_blob_repeat_byte(0x0c, 16);
+ testarray[4].data = data_blob_string_const("Test With Truncation");
+ testarray[4].md5 = strhex_to_data_blob("56461ef2342edc00f9bab995690efd4c");
+
+ testarray[5].key = data_blob_repeat_byte(0xaa, 80);
+ testarray[5].data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First");
+ testarray[5].md5 = strhex_to_data_blob("6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd");
+
+ testarray[6].key = data_blob_repeat_byte(0xaa, 80);
+ testarray[6].data = data_blob_string_const("Test Using Larger Than Block-Size Key "
+ "and Larger Than One Block-Size Data");
+ testarray[6].md5 = strhex_to_data_blob("6f630fad67cda0ee1fb1f562db3aa53e");
+
+ testarray[7].key = data_blob(NULL, 0);
+
+ for (i=0; testarray[i].key.data; i++) {
+ HMACMD5Context ctx;
+ uint8_t md5[16];
+ int e;
+
+ hmac_md5_init_rfc2104(testarray[i].key.data, testarray[i].key.length, &ctx);
+ hmac_md5_update(testarray[i].data.data, testarray[i].data.length, &ctx);
+ hmac_md5_final(md5, &ctx);
+
+ e = memcmp(testarray[i].md5.data,
+ md5,
+ MIN(testarray[i].md5.length, sizeof(md5)));
+ if (e != 0) {
+ printf("hmacmd5 test[%u]: failed\n", i);
+ dump_data(0, testarray[i].key.data, testarray[i].key.length);
+ dump_data(0, testarray[i].data.data, testarray[i].data.length);
+ dump_data(0, testarray[i].md5.data, testarray[i].md5.length);
+ dump_data(0, md5, sizeof(md5));
+ ret = false;
+ }
+ }
+
+ return ret;
+}
diff --git a/lib/crypto/hmacsha256.c b/lib/crypto/hmacsha256.c
new file mode 100644
index 0000000000..53d4fe3883
--- /dev/null
+++ b/lib/crypto/hmacsha256.c
@@ -0,0 +1,91 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Interface header: HMAC SHA-256 code
+
+ Copyright (C) Andrew Tridgell 2008
+
+ based in hmacsha1.c which is:
+ Copyright (C) Stefan Metzmacher
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ taken direct from rfc2202 implementation and modified for suitable use
+ */
+
+#include "includes.h"
+#include "../lib/crypto/crypto.h"
+
+/***********************************************************************
+ the rfc 2104/2202 version of hmac_sha256 initialisation.
+***********************************************************************/
+_PUBLIC_ void hmac_sha256_init(const uint8_t *key, size_t key_len, struct HMACSHA256Context *ctx)
+{
+ int i;
+ uint8_t tk[SHA256_DIGEST_LENGTH];
+
+ /* if key is longer than 64 bytes reset it to key=HASH(key) */
+ if (key_len > 64)
+ {
+ SHA256_CTX tctx;
+
+ SHA256_Init(&tctx);
+ SHA256_Update(&tctx, key, key_len);
+ SHA256_Final(tk, &tctx);
+
+ key = tk;
+ key_len = SHA256_DIGEST_LENGTH;
+ }
+
+ /* start out by storing key in pads */
+ ZERO_STRUCT(ctx->k_ipad);
+ ZERO_STRUCT(ctx->k_opad);
+ memcpy( ctx->k_ipad, key, key_len);
+ memcpy( ctx->k_opad, key, key_len);
+
+ /* XOR key with ipad and opad values */
+ for (i=0; i<64; i++)
+ {
+ ctx->k_ipad[i] ^= 0x36;
+ ctx->k_opad[i] ^= 0x5c;
+ }
+
+ SHA256_Init(&ctx->ctx);
+ SHA256_Update(&ctx->ctx, ctx->k_ipad, 64);
+}
+
+/***********************************************************************
+ update hmac_sha256 "inner" buffer
+***********************************************************************/
+_PUBLIC_ void hmac_sha256_update(const uint8_t *data, size_t data_len, struct HMACSHA256Context *ctx)
+{
+ SHA256_Update(&ctx->ctx, data, data_len); /* then text of datagram */
+}
+
+/***********************************************************************
+ finish off hmac_sha256 "inner" buffer and generate outer one.
+***********************************************************************/
+_PUBLIC_ void hmac_sha256_final(uint8_t digest[SHA256_DIGEST_LENGTH], struct HMACSHA256Context *ctx)
+{
+ SHA256_CTX ctx_o;
+
+ SHA256_Final(digest, &ctx->ctx);
+
+ SHA256_Init(&ctx_o);
+ SHA256_Update(&ctx_o, ctx->k_opad, 64);
+ SHA256_Update(&ctx_o, digest, SHA256_DIGEST_LENGTH);
+ SHA256_Final(digest, &ctx_o);
+}
diff --git a/lib/crypto/hmacsha256.h b/lib/crypto/hmacsha256.h
new file mode 100644
index 0000000000..8960c636c1
--- /dev/null
+++ b/lib/crypto/hmacsha256.h
@@ -0,0 +1,38 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Interface header: HMAC SHA256 code
+
+ Copyright (C) Andrew Tridgell 2008
+
+ based on hmacsha1.h which is:
+
+ Copyright (C) Stefan Metzmacher 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _HMAC_SHA256_H
+
+struct HMACSHA256Context {
+ SHA256_CTX ctx;
+ uint8_t k_ipad[65];
+ uint8_t k_opad[65];
+};
+
+void hmac_sha256_init(const uint8_t *key, size_t key_len, struct HMACSHA256Context *ctx);
+void hmac_sha256_update(const uint8_t *data, size_t data_len, struct HMACSHA256Context *ctx);
+void hmac_sha256_final(uint8_t digest[20], struct HMACSHA256Context *ctx);
+
+#endif /* _HMAC_SHA256_H */
diff --git a/lib/crypto/md4.c b/lib/crypto/md4.c
new file mode 100644
index 0000000000..7ad93ce786
--- /dev/null
+++ b/lib/crypto/md4.c
@@ -0,0 +1,176 @@
+/*
+ Unix SMB/CIFS implementation.
+ a implementation of MD4 designed for use in the SMB authentication protocol
+ Copyright (C) Andrew Tridgell 1997-1998.
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+/* NOTE: This code makes no attempt to be fast!
+
+ It assumes that a int is at least 32 bits long
+*/
+
+struct mdfour_state {
+ uint32_t A, B, C, D;
+};
+
+static uint32_t F(uint32_t X, uint32_t Y, uint32_t Z)
+{
+ return (X&Y) | ((~X)&Z);
+}
+
+static uint32_t G(uint32_t X, uint32_t Y, uint32_t Z)
+{
+ return (X&Y) | (X&Z) | (Y&Z);
+}
+
+static uint32_t H(uint32_t X, uint32_t Y, uint32_t Z)
+{
+ return X^Y^Z;
+}
+
+static uint32_t lshift(uint32_t x, int s)
+{
+ x &= 0xFFFFFFFF;
+ return ((x<<s)&0xFFFFFFFF) | (x>>(32-s));
+}
+
+#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
+#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + (uint32_t)0x5A827999,s)
+#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32_t)0x6ED9EBA1,s)
+
+/* this applies md4 to 64 byte chunks */
+static void mdfour64(struct mdfour_state *s, uint32_t *M)
+{
+ int j;
+ uint32_t AA, BB, CC, DD;
+ uint32_t X[16];
+
+ for (j=0;j<16;j++)
+ X[j] = M[j];
+
+ AA = s->A; BB = s->B; CC = s->C; DD = s->D;
+
+ ROUND1(s->A,s->B,s->C,s->D, 0, 3); ROUND1(s->D,s->A,s->B,s->C, 1, 7);
+ ROUND1(s->C,s->D,s->A,s->B, 2, 11); ROUND1(s->B,s->C,s->D,s->A, 3, 19);
+ ROUND1(s->A,s->B,s->C,s->D, 4, 3); ROUND1(s->D,s->A,s->B,s->C, 5, 7);
+ ROUND1(s->C,s->D,s->A,s->B, 6, 11); ROUND1(s->B,s->C,s->D,s->A, 7, 19);
+ ROUND1(s->A,s->B,s->C,s->D, 8, 3); ROUND1(s->D,s->A,s->B,s->C, 9, 7);
+ ROUND1(s->C,s->D,s->A,s->B, 10, 11); ROUND1(s->B,s->C,s->D,s->A, 11, 19);
+ ROUND1(s->A,s->B,s->C,s->D, 12, 3); ROUND1(s->D,s->A,s->B,s->C, 13, 7);
+ ROUND1(s->C,s->D,s->A,s->B, 14, 11); ROUND1(s->B,s->C,s->D,s->A, 15, 19);
+
+ ROUND2(s->A,s->B,s->C,s->D, 0, 3); ROUND2(s->D,s->A,s->B,s->C, 4, 5);
+ ROUND2(s->C,s->D,s->A,s->B, 8, 9); ROUND2(s->B,s->C,s->D,s->A, 12, 13);
+ ROUND2(s->A,s->B,s->C,s->D, 1, 3); ROUND2(s->D,s->A,s->B,s->C, 5, 5);
+ ROUND2(s->C,s->D,s->A,s->B, 9, 9); ROUND2(s->B,s->C,s->D,s->A, 13, 13);
+ ROUND2(s->A,s->B,s->C,s->D, 2, 3); ROUND2(s->D,s->A,s->B,s->C, 6, 5);
+ ROUND2(s->C,s->D,s->A,s->B, 10, 9); ROUND2(s->B,s->C,s->D,s->A, 14, 13);
+ ROUND2(s->A,s->B,s->C,s->D, 3, 3); ROUND2(s->D,s->A,s->B,s->C, 7, 5);
+ ROUND2(s->C,s->D,s->A,s->B, 11, 9); ROUND2(s->B,s->C,s->D,s->A, 15, 13);
+
+ ROUND3(s->A,s->B,s->C,s->D, 0, 3); ROUND3(s->D,s->A,s->B,s->C, 8, 9);
+ ROUND3(s->C,s->D,s->A,s->B, 4, 11); ROUND3(s->B,s->C,s->D,s->A, 12, 15);
+ ROUND3(s->A,s->B,s->C,s->D, 2, 3); ROUND3(s->D,s->A,s->B,s->C, 10, 9);
+ ROUND3(s->C,s->D,s->A,s->B, 6, 11); ROUND3(s->B,s->C,s->D,s->A, 14, 15);
+ ROUND3(s->A,s->B,s->C,s->D, 1, 3); ROUND3(s->D,s->A,s->B,s->C, 9, 9);
+ ROUND3(s->C,s->D,s->A,s->B, 5, 11); ROUND3(s->B,s->C,s->D,s->A, 13, 15);
+ ROUND3(s->A,s->B,s->C,s->D, 3, 3); ROUND3(s->D,s->A,s->B,s->C, 11, 9);
+ ROUND3(s->C,s->D,s->A,s->B, 7, 11); ROUND3(s->B,s->C,s->D,s->A, 15, 15);
+
+ s->A += AA;
+ s->B += BB;
+ s->C += CC;
+ s->D += DD;
+
+ s->A &= 0xFFFFFFFF;
+ s->B &= 0xFFFFFFFF;
+ s->C &= 0xFFFFFFFF;
+ s->D &= 0xFFFFFFFF;
+
+ for (j=0;j<16;j++)
+ X[j] = 0;
+}
+
+static void copy64(uint32_t *M, const uint8_t *in)
+{
+ int i;
+
+ for (i=0;i<16;i++)
+ M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
+ (in[i*4+1]<<8) | (in[i*4+0]<<0);
+}
+
+static void copy4(uint8_t *out, uint32_t x)
+{
+ out[0] = x&0xFF;
+ out[1] = (x>>8)&0xFF;
+ out[2] = (x>>16)&0xFF;
+ out[3] = (x>>24)&0xFF;
+}
+
+/**
+ * produce a md4 message digest from data of length n bytes
+ */
+_PUBLIC_ void mdfour(uint8_t *out, const uint8_t *in, int n)
+{
+ uint8_t buf[128];
+ uint32_t M[16];
+ uint32_t b = n * 8;
+ int i;
+ struct mdfour_state state;
+
+ state.A = 0x67452301;
+ state.B = 0xefcdab89;
+ state.C = 0x98badcfe;
+ state.D = 0x10325476;
+
+ while (n > 64) {
+ copy64(M, in);
+ mdfour64(&state, M);
+ in += 64;
+ n -= 64;
+ }
+
+ for (i=0;i<128;i++)
+ buf[i] = 0;
+ memcpy(buf, in, n);
+ buf[n] = 0x80;
+
+ if (n <= 55) {
+ copy4(buf+56, b);
+ copy64(M, buf);
+ mdfour64(&state, M);
+ } else {
+ copy4(buf+120, b);
+ copy64(M, buf);
+ mdfour64(&state, M);
+ copy64(M, buf+64);
+ mdfour64(&state, M);
+ }
+
+ for (i=0;i<128;i++)
+ buf[i] = 0;
+ copy64(M, buf);
+
+ copy4(out, state.A);
+ copy4(out+4, state.B);
+ copy4(out+8, state.C);
+ copy4(out+12, state.D);
+}
+
+
diff --git a/lib/crypto/md4.h b/lib/crypto/md4.h
new file mode 100644
index 0000000000..234e488e4f
--- /dev/null
+++ b/lib/crypto/md4.h
@@ -0,0 +1 @@
+void mdfour(uint8_t *out, const uint8_t *in, int n);
diff --git a/lib/crypto/md4test.c b/lib/crypto/md4test.c
new file mode 100644
index 0000000000..dddf9e61a0
--- /dev/null
+++ b/lib/crypto/md4test.c
@@ -0,0 +1,83 @@
+/*
+ Unix SMB/CIFS implementation.
+ MD4 tests
+ Copyright (C) Stefan Metzmacher 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "../lib/crypto/crypto.h"
+
+struct torture_context;
+
+/*
+ This uses the test values from rfc1320
+*/
+bool torture_local_crypto_md4(struct torture_context *torture)
+{
+ bool ret = true;
+ uint32_t i;
+ struct {
+ const char *data;
+ const char *md4;
+ } testarray[] = {
+ {
+ .data = "",
+ .md4 = "31d6cfe0d16ae931b73c59d7e0c089c0"
+ },{
+ .data = "a",
+ .md4 = "bde52cb31de33e46245e05fbdbd6fb24"
+ },{
+ .data = "abc",
+ .md4 = "a448017aaf21d8525fc10ae87aa6729d"
+ },{
+ .data = "message digest",
+ .md4 = "d9130a8164549fe818874806e1c7014b"
+ },{
+ .data = "abcdefghijklmnopqrstuvwxyz",
+ .md4 = "d79e1c308aa5bbcdeea8ed63df412da9"
+ },{
+ .data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ .md4 = "043f8582f241db351ce627e153e7f0e4"
+ },{
+ .data = "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+ .md4 = "e33b4ddc9c38f2199c3e7b164fcc0536"
+ }
+ };
+
+ for (i=0; i < ARRAY_SIZE(testarray); i++) {
+ uint8_t md4[16];
+ int e;
+ DATA_BLOB data;
+ DATA_BLOB md4blob;
+
+ data = data_blob_string_const(testarray[i].data);
+ md4blob = strhex_to_data_blob(testarray[i].md4);
+
+ mdfour(md4, data.data, data.length);
+
+ e = memcmp(md4blob.data, md4, MIN(md4blob.length, sizeof(md4)));
+ if (e != 0) {
+ printf("md4 test[%u]: failed\n", i);
+ dump_data(0, data.data, data.length);
+ dump_data(0, md4blob.data, md4blob.length);
+ dump_data(0, md4, sizeof(md4));
+ ret = false;
+ }
+ talloc_free(md4blob.data);
+ }
+
+ return ret;
+}
diff --git a/lib/crypto/md5.c b/lib/crypto/md5.c
new file mode 100644
index 0000000000..584c46ef2d
--- /dev/null
+++ b/lib/crypto/md5.c
@@ -0,0 +1,248 @@
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+/* This code slightly modified to fit into Samba by
+ abartlet@samba.org Jun 2001 */
+
+#include "includes.h"
+
+#include "md5.h"
+
+
+static void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
+
+/*
+ * Note: this code is harmless on little-endian machines.
+ */
+static void byteReverse(uint8_t *buf, uint_t longs)
+{
+ uint32_t t;
+ do {
+ t = (uint32_t) ((uint_t) buf[3] << 8 | buf[2]) << 16 |
+ ((uint_t) buf[1] << 8 | buf[0]);
+ *(uint32_t *) buf = t;
+ buf += 4;
+ } while (--longs);
+}
+
+/*
+ * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+_PUBLIC_ void MD5Init(struct MD5Context *ctx)
+{
+ ctx->buf[0] = 0x67452301;
+ ctx->buf[1] = 0xefcdab89;
+ ctx->buf[2] = 0x98badcfe;
+ ctx->buf[3] = 0x10325476;
+
+ ctx->bits[0] = 0;
+ ctx->bits[1] = 0;
+}
+
+/*
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+_PUBLIC_ void MD5Update(struct MD5Context *ctx, const uint8_t *buf, size_t len)
+{
+ register uint32_t t;
+
+ /* Update bitcount */
+
+ t = ctx->bits[0];
+ if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
+ ctx->bits[1]++; /* Carry from low to high */
+ ctx->bits[1] += len >> 29;
+
+ t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
+
+ /* Handle any leading odd-sized chunks */
+
+ if (t) {
+ uint8_t *p = (uint8_t *) ctx->in + t;
+
+ t = 64 - t;
+ if (len < t) {
+ memmove(p, buf, len);
+ return;
+ }
+ memmove(p, buf, t);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ buf += t;
+ len -= t;
+ }
+ /* Process data in 64-byte chunks */
+
+ while (len >= 64) {
+ memmove(ctx->in, buf, 64);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ buf += 64;
+ len -= 64;
+ }
+
+ /* Handle any remaining bytes of data. */
+
+ memmove(ctx->in, buf, len);
+}
+
+/*
+ * Final wrapup - pad to 64-byte boundary with the bit pattern
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+_PUBLIC_ void MD5Final(uint8_t digest[16], struct MD5Context *ctx)
+{
+ uint_t count;
+ uint8_t *p;
+
+ /* Compute number of bytes mod 64 */
+ count = (ctx->bits[0] >> 3) & 0x3F;
+
+ /* Set the first char of padding to 0x80. This is safe since there is
+ always at least one byte free */
+ p = ctx->in + count;
+ *p++ = 0x80;
+
+ /* Bytes of padding needed to make 64 bytes */
+ count = 64 - 1 - count;
+
+ /* Pad out to 56 mod 64 */
+ if (count < 8) {
+ /* Two lots of padding: Pad the first block to 64 bytes */
+ memset(p, 0, count);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+
+ /* Now fill the next block with 56 bytes */
+ memset(ctx->in, 0, 56);
+ } else {
+ /* Pad block to 56 bytes */
+ memset(p, 0, count - 8);
+ }
+ byteReverse(ctx->in, 14);
+
+ /* Append length in bits and transform */
+ ((uint32_t *) ctx->in)[14] = ctx->bits[0];
+ ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ byteReverse((uint8_t *) ctx->buf, 4);
+ memmove(digest, ctx->buf, 16);
+ memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+}
+
+/* The four core functions - F1 is optimized somewhat */
+
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+ ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
+
+/*
+ * The core of the MD5 algorithm, this alters an existing MD5 hash to
+ * reflect the addition of 16 longwords of new data. MD5Update blocks
+ * the data and converts bytes into longwords for this routine.
+ */
+static void MD5Transform(uint32_t buf[4], uint32_t const in[16])
+{
+ register uint32_t a, b, c, d;
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
+ MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
+ MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
+ MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
+ MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
+ MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
+ MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
+ MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
+ MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
+ MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+ MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
+ MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+ MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
+ MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+ MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
+ MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+ MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
+ MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+ MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
+ MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+ MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
+ MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+ MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
+ MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
+ MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+ MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
+ MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
+ MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
+ MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+ MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
+
+ MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
+ MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+ MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+ MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+ MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
+ MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+ MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+ MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+ MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
+ MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
diff --git a/lib/crypto/md5.h b/lib/crypto/md5.h
new file mode 100644
index 0000000000..4064d6f003
--- /dev/null
+++ b/lib/crypto/md5.h
@@ -0,0 +1,19 @@
+#ifndef MD5_H
+#define MD5_H
+#ifndef HEADER_MD5_H
+/* Try to avoid clashes with OpenSSL */
+#define HEADER_MD5_H
+#endif
+
+struct MD5Context {
+ uint32_t buf[4];
+ uint32_t bits[2];
+ uint8_t in[64];
+};
+
+void MD5Init(struct MD5Context *context);
+void MD5Update(struct MD5Context *context, const uint8_t *buf,
+ size_t len);
+void MD5Final(uint8_t digest[16], struct MD5Context *context);
+
+#endif /* !MD5_H */
diff --git a/lib/crypto/md5test.c b/lib/crypto/md5test.c
new file mode 100644
index 0000000000..1244dca753
--- /dev/null
+++ b/lib/crypto/md5test.c
@@ -0,0 +1,93 @@
+/*
+ Unix SMB/CIFS implementation.
+ MD5 tests
+ Copyright (C) Stefan Metzmacher
+
+ 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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "../lib/crypto/crypto.h"
+
+struct torture_context;
+
+/*
+ This uses the test values from rfc1321
+*/
+bool torture_local_crypto_md5(struct torture_context *torture)
+{
+ bool ret = true;
+ uint32_t i;
+ struct {
+ const char *data;
+ const char *md5;
+ } testarray[] = {
+ {
+ .data = "",
+ .md5 = "d41d8cd98f00b204e9800998ecf8427e"
+ },{
+ .data = "a",
+ .md5 = "0cc175b9c0f1b6a831c399e269772661"
+ },{
+ .data = "abc",
+ .md5 = "900150983cd24fb0d6963f7d28e17f72"
+ },{
+ .data = "message digest",
+ .md5 = "f96b697d7cb7938d525a2f31aaf161d0"
+ },{
+ .data = "abcdefghijklmnopqrstuvwxyz",
+ .md5 = "c3fcd3d76192e4007dfb496cca67e13b"
+ },{
+ .data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789",
+ .md5 = "d174ab98d277d9f5a5611c2c9f419d9f"
+ },{
+ .data = "123456789012345678901234567890"
+ "123456789012345678901234567890"
+ "12345678901234567890",
+ .md5 = "57edf4a22be3c955ac49da2e2107b67a"
+ }
+ };
+
+ for (i=0; i < ARRAY_SIZE(testarray); i++) {
+ struct MD5Context ctx;
+ uint8_t md5[16];
+ int e;
+
+ DATA_BLOB data;
+ DATA_BLOB md5blob;
+
+ data = data_blob_string_const(testarray[i].data);
+ md5blob = strhex_to_data_blob(testarray[i].md5);
+
+ MD5Init(&ctx);
+ MD5Update(&ctx, data.data, data.length);
+ MD5Final(md5, &ctx);
+
+ e = memcmp(md5blob.data,
+ md5,
+ MIN(md5blob.length, sizeof(md5)));
+ if (e != 0) {
+ printf("md5 test[%u]: failed\n", i);
+ dump_data(0, data.data, data.length);
+ dump_data(0, md5blob.data, md5blob.length);
+ dump_data(0, md5, sizeof(md5));
+ ret = false;
+ }
+ talloc_free(md5blob.data);
+ }
+
+ return ret;
+}
diff --git a/lib/crypto/sha256.c b/lib/crypto/sha256.c
new file mode 100644
index 0000000000..a2def25814
--- /dev/null
+++ b/lib/crypto/sha256.c
@@ -0,0 +1,253 @@
+/*
+ based on heildal lib/hcrypto/sha256.c. Copied to lib/crypto to avoid a link
+ problem. Hopefully will be removed once we solve this link problem
+
+ (tridge)
+ */
+
+/*
+ * Copyright (c) 2006 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * 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. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
+ */
+
+#include "includes.h"
+#include "sha256.h"
+
+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+
+#define ROTR(x,n) (((x)>>(n)) | ((x) << (32 - (n))))
+
+#define Sigma0(x) (ROTR(x,2) ^ ROTR(x,13) ^ ROTR(x,22))
+#define Sigma1(x) (ROTR(x,6) ^ ROTR(x,11) ^ ROTR(x,25))
+#define sigma0(x) (ROTR(x,7) ^ ROTR(x,18) ^ ((x)>>3))
+#define sigma1(x) (ROTR(x,17) ^ ROTR(x,19) ^ ((x)>>10))
+
+#define A m->counter[0]
+#define B m->counter[1]
+#define C m->counter[2]
+#define D m->counter[3]
+#define E m->counter[4]
+#define F m->counter[5]
+#define G m->counter[6]
+#define H m->counter[7]
+
+static const uint32_t constant_256[64] = {
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
+};
+
+void
+SHA256_Init (SHA256_CTX *m)
+{
+ m->sz[0] = 0;
+ m->sz[1] = 0;
+ A = 0x6a09e667;
+ B = 0xbb67ae85;
+ C = 0x3c6ef372;
+ D = 0xa54ff53a;
+ E = 0x510e527f;
+ F = 0x9b05688c;
+ G = 0x1f83d9ab;
+ H = 0x5be0cd19;
+}
+
+static void
+calc (SHA256_CTX *m, uint32_t *in)
+{
+ uint32_t AA, BB, CC, DD, EE, FF, GG, HH;
+ uint32_t data[64];
+ int i;
+
+ AA = A;
+ BB = B;
+ CC = C;
+ DD = D;
+ EE = E;
+ FF = F;
+ GG = G;
+ HH = H;
+
+ for (i = 0; i < 16; ++i)
+ data[i] = in[i];
+ for (i = 16; i < 64; ++i)
+ data[i] = sigma1(data[i-2]) + data[i-7] +
+ sigma0(data[i-15]) + data[i - 16];
+
+ for (i = 0; i < 64; i++) {
+ uint32_t T1, T2;
+
+ T1 = HH + Sigma1(EE) + Ch(EE, FF, GG) + constant_256[i] + data[i];
+ T2 = Sigma0(AA) + Maj(AA,BB,CC);
+
+ HH = GG;
+ GG = FF;
+ FF = EE;
+ EE = DD + T1;
+ DD = CC;
+ CC = BB;
+ BB = AA;
+ AA = T1 + T2;
+ }
+
+ A += AA;
+ B += BB;
+ C += CC;
+ D += DD;
+ E += EE;
+ F += FF;
+ G += GG;
+ H += HH;
+}
+
+/*
+ * From `Performance analysis of MD5' by Joseph D. Touch <touch@isi.edu>
+ */
+
+#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
+/* Vector Crays doesn't have a good 32-bit type, or more precisely,
+ int32_t as defined by <bind/bitypes.h> isn't 32 bits, and we don't
+ want to depend in being able to redefine this type. To cope with
+ this we have to clamp the result in some places to [0,2^32); no
+ need to do this on other machines. Did I say this was a mess?
+ */
+
+#ifdef _CRAY
+#define CRAYFIX(X) ((X) & 0xffffffff)
+#else
+#define CRAYFIX(X) (X)
+#endif
+
+static inline uint32_t
+cshift (uint32_t x, unsigned int n)
+{
+ x = CRAYFIX(x);
+ return CRAYFIX((x << n) | (x >> (32 - n)));
+}
+
+static inline uint32_t
+swap_uint32_t (uint32_t t)
+{
+ uint32_t temp1, temp2;
+
+ temp1 = cshift(t, 16);
+ temp2 = temp1 >> 8;
+ temp1 &= 0x00ff00ff;
+ temp2 &= 0x00ff00ff;
+ temp1 <<= 8;
+ return temp1 | temp2;
+}
+#endif
+
+struct x32{
+ unsigned int a:32;
+ unsigned int b:32;
+};
+
+void
+SHA256_Update (SHA256_CTX *m, const void *v, size_t len)
+{
+ const unsigned char *p = v;
+ size_t old_sz = m->sz[0];
+ size_t offset;
+
+ m->sz[0] += len * 8;
+ if (m->sz[0] < old_sz)
+ ++m->sz[1];
+ offset = (old_sz / 8) % 64;
+ while(len > 0){
+ size_t l = MIN(len, 64 - offset);
+ memcpy(m->save + offset, p, l);
+ offset += l;
+ p += l;
+ len -= l;
+ if(offset == 64){
+#if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
+ int i;
+ uint32_t current[16];
+ struct x32 *u = (struct x32*)m->save;
+ for(i = 0; i < 8; i++){
+ current[2*i+0] = swap_uint32_t(u[i].a);
+ current[2*i+1] = swap_uint32_t(u[i].b);
+ }
+ calc(m, current);
+#else
+ calc(m, (uint32_t*)m->save);
+#endif
+ offset = 0;
+ }
+ }
+}
+
+void
+SHA256_Final (void *res, SHA256_CTX *m)
+{
+ unsigned char zeros[72];
+ unsigned offset = (m->sz[0] / 8) % 64;
+ unsigned int dstart = (120 - offset - 1) % 64 + 1;
+
+ *zeros = 0x80;
+ memset (zeros + 1, 0, sizeof(zeros) - 1);
+ zeros[dstart+7] = (m->sz[0] >> 0) & 0xff;
+ zeros[dstart+6] = (m->sz[0] >> 8) & 0xff;
+ zeros[dstart+5] = (m->sz[0] >> 16) & 0xff;
+ zeros[dstart+4] = (m->sz[0] >> 24) & 0xff;
+ zeros[dstart+3] = (m->sz[1] >> 0) & 0xff;
+ zeros[dstart+2] = (m->sz[1] >> 8) & 0xff;
+ zeros[dstart+1] = (m->sz[1] >> 16) & 0xff;
+ zeros[dstart+0] = (m->sz[1] >> 24) & 0xff;
+ SHA256_Update (m, zeros, dstart + 8);
+ {
+ int i;
+ unsigned char *r = (unsigned char*)res;
+
+ for (i = 0; i < 8; ++i) {
+ r[4*i+3] = m->counter[i] & 0xFF;
+ r[4*i+2] = (m->counter[i] >> 8) & 0xFF;
+ r[4*i+1] = (m->counter[i] >> 16) & 0xFF;
+ r[4*i] = (m->counter[i] >> 24) & 0xFF;
+ }
+ }
+}
diff --git a/lib/crypto/sha256.h b/lib/crypto/sha256.h
new file mode 100644
index 0000000000..4a5f2cbe94
--- /dev/null
+++ b/lib/crypto/sha256.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * 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. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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.
+ */
+
+/* $Id: sha.h 17450 2006-05-05 11:11:43Z lha $ */
+
+#ifndef HEIM_SHA_H
+/*
+ based on heildal lib/hcrypto/sha.h. Copied to lib/crypto to avoid a link
+ problem. Hopefully will be removed once we solve this link problem
+
+ (tridge)
+ */
+#define HEIM_SHA_H 1
+
+#if 0
+/* symbol renaming */
+#define SHA1_Init hc_SHA1_Init
+#define SHA1_Update hc_SHA1_Update
+#define SHA1_Final hc_SHA1_Final
+#define SHA256_Init hc_SHA256_Init
+#define SHA256_Update hc_SHA256_Update
+#define SHA256_Final hc_SHA256_Final
+#endif
+
+/*
+ * SHA-1
+ */
+
+#define SHA_DIGEST_LENGTH 20
+
+struct sha {
+ unsigned int sz[2];
+ uint32_t counter[5];
+ unsigned char save[64];
+};
+
+typedef struct sha SHA_CTX;
+
+void SHA1_Init (struct sha *m);
+void SHA1_Update (struct sha *m, const void *v, size_t len);
+void SHA1_Final (void *res, struct sha *m);
+
+/*
+ * SHA-2 256
+ */
+
+#define SHA256_DIGEST_LENGTH 32
+
+struct hc_sha256state {
+ unsigned int sz[2];
+ uint32_t counter[8];
+ unsigned char save[64];
+};
+
+typedef struct hc_sha256state SHA256_CTX;
+
+void SHA256_Init (SHA256_CTX *);
+void SHA256_Update (SHA256_CTX *, const void *, size_t);
+void SHA256_Final (void *, SHA256_CTX *);
+
+#endif /* HEIM_SHA_H */
diff --git a/lib/replace/Makefile.in b/lib/replace/Makefile.in
index c989835a8d..65f8125efd 100644
--- a/lib/replace/Makefile.in
+++ b/lib/replace/Makefile.in
@@ -9,7 +9,8 @@ libdir = @libdir@
VPATH = @libreplacedir@
srcdir = @srcdir@
builddir = @builddir@
-INSTALL = @INSTALL@
+sharedbuilddir = @sharedbuilddir@
+INSTALLCMD = @INSTALL@
LIBS = @LIBS@
.PHONY: test all showflags install installcheck clean distclean realdistclean
@@ -29,8 +30,14 @@ showflags:
@echo ' LIBS = $(LIBS)'
install: all
- mkdir -p $(libdir)
- $(INSTALL) libreplace.a $(libdir)
+ ${INSTALLCMD} -d $(libdir)
+ ${INSTALLCMD} -m 644 libreplace.a $(libdir)
+
+shared-build: all
+ ${INSTALLCMD} -d $(sharedbuilddir)/include
+ ${INSTALLCMD} -m 644 replace.h $(sharedbuilddir)/include
+ ${INSTALLCMD} -d $(sharedbuilddir)/lib
+ ${INSTALLCMD} -m 644 libreplace.a $(sharedbuilddir)/lib
libreplace.a: $(OBJS)
ar -rcsv $@ $(OBJS)
@@ -40,7 +47,7 @@ test: all
installcheck: install test
-TEST_OBJS = test/testsuite.o test/os2_delete.o test/strptime.o test/getifaddrs.o
+TEST_OBJS = test/main.o test/testsuite.o test/os2_delete.o test/strptime.o test/getifaddrs.o
testsuite: libreplace.a $(TEST_OBJS)
$(CC) -o testsuite $(TEST_OBJS) -L. -lreplace $(LDFLAGS) $(LIBS)
diff --git a/lib/replace/build_macros.m4 b/lib/replace/build_macros.m4
new file mode 100644
index 0000000000..c036668cd1
--- /dev/null
+++ b/lib/replace/build_macros.m4
@@ -0,0 +1,14 @@
+AC_DEFUN(BUILD_WITH_SHARED_BUILD_DIR,
+ [ AC_ARG_WITH([shared-build-dir],
+ [AC_HELP_STRING([--with-shared-build-dir=DIR],
+ [temporary build directory where libraries are installed [$srcdir/sharedbuild]])])
+
+ sharedbuilddir="$srcdir/sharedbuild"
+ if test x"$with_shared_build_dir" != x; then
+ sharedbuilddir=$with_shared_build_dir
+ CFLAGS="$CFLAGS -I$with_shared_build_dir/include"
+ LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib"
+ fi
+ AC_SUBST(sharedbuilddir)
+ ])
+
diff --git a/lib/replace/configure.ac b/lib/replace/configure.ac
index 81997e09b7..0361825a02 100644
--- a/lib/replace/configure.ac
+++ b/lib/replace/configure.ac
@@ -22,6 +22,9 @@ if test "$ac_cv_prog_gcc" = yes; then
CFLAGS="$CFLAGS -Wno-format-y2k"
fi
+m4_include(build_macros.m4)
+BUILD_WITH_SHARED_BUILD_DIR
+
LIBS="${LIBREPLACE_NETWORK_LIBS}"
AC_SUBST(LIBS)
diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4
index dc7d88e6e1..e563acfd79 100644
--- a/lib/replace/libreplace.m4
+++ b/lib/replace/libreplace.m4
@@ -5,7 +5,7 @@ echo "LIBREPLACE_LOCATION_CHECKS: START"
dnl find the libreplace sources. This is meant to work both for
dnl libreplace standalone builds, and builds of packages using libreplace
libreplacedir=""
-libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace"
+libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
for d in $libreplacepaths; do
if test -f "$d/replace.c"; then
libreplacedir="$d"
@@ -34,7 +34,7 @@ echo "LIBREPLACE_BROKEN_CHECKS: START"
dnl find the libreplace sources. This is meant to work both for
dnl libreplace standalone builds, and builds of packages using libreplace
libreplacedir=""
-libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace"
+libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
for d in $libreplacepaths; do
if test -f "$d/replace.c"; then
libreplacedir="$d"
diff --git a/lib/replace/test/main.c b/lib/replace/test/main.c
new file mode 100644
index 0000000000..9bd12840a5
--- /dev/null
+++ b/lib/replace/test/main.c
@@ -0,0 +1,37 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ libreplace tests
+
+ Copyright (C) Jelmer Vernooij 2006
+
+ ** NOTE! The following LGPL license applies to the talloc
+ ** 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"
+
+struct torture_context;
+bool torture_local_replace(struct torture_context *ctx);
+
+int main(void)
+{
+ bool ret = torture_local_replace(NULL);
+ if (ret)
+ return 0;
+ return -1;
+}
diff --git a/lib/replace/test/testsuite.c b/lib/replace/test/testsuite.c
index 1e8290906e..7929f11add 100644
--- a/lib/replace/test/testsuite.c
+++ b/lib/replace/test/testsuite.c
@@ -1068,13 +1068,3 @@ bool torture_local_replace(struct torture_context *ctx)
return ret;
}
-
-#if _SAMBA_BUILD_<4
-int main(void)
-{
- bool ret = torture_local_replace(NULL);
- if (ret)
- return 0;
- return -1;
-}
-#endif
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index e8d27adc37..9d61976950 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -750,7 +750,7 @@ static struct swrap_packet *swrap_packet_init(struct timeval *tval,
int socket_type,
const unsigned char *payload,
size_t payload_len,
- unsigned long tcp_seq,
+ unsigned long tcp_seqno,
unsigned long tcp_ack,
unsigned char tcp_ctl,
int unreachable,
@@ -852,7 +852,7 @@ static struct swrap_packet *swrap_packet_init(struct timeval *tval,
case SOCK_STREAM:
packet->ip.p.tcp.source_port = src_port;
packet->ip.p.tcp.dest_port = dest_port;
- packet->ip.p.tcp.seq_num = htonl(tcp_seq);
+ packet->ip.p.tcp.seq_num = htonl(tcp_seqno);
packet->ip.p.tcp.ack_num = htonl(tcp_ack);
packet->ip.p.tcp.hdr_length = 0x50; /* 5 * 32 bit words */
packet->ip.p.tcp.control = tcp_ctl;
@@ -916,7 +916,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
{
const struct sockaddr_in *src_addr;
const struct sockaddr_in *dest_addr;
- unsigned long tcp_seq = 0;
+ unsigned long tcp_seqno = 0;
unsigned long tcp_ack = 0;
unsigned char tcp_ctl = 0;
int unreachable = 0;
@@ -937,7 +937,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)addr;
- tcp_seq = si->io.pck_snd;
+ tcp_seqno = si->io.pck_snd;
tcp_ack = si->io.pck_rcv;
tcp_ctl = 0x02; /* SYN */
@@ -951,7 +951,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)addr;
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x12; /** SYN,ACK */
@@ -966,7 +966,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
src_addr = (const struct sockaddr_in *)addr;
/* Unreachable: resend the data of SWRAP_CONNECT_SEND */
- tcp_seq = si->io.pck_snd - 1;
+ tcp_seqno = si->io.pck_snd - 1;
tcp_ack = si->io.pck_rcv;
tcp_ctl = 0x02; /* SYN */
unreachable = 1;
@@ -979,7 +979,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)addr;
- tcp_seq = si->io.pck_snd;
+ tcp_seqno = si->io.pck_snd;
tcp_ack = si->io.pck_rcv;
tcp_ctl = 0x10; /* ACK */
@@ -991,7 +991,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)addr;
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x02; /* SYN */
@@ -1005,7 +1005,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)addr;
- tcp_seq = si->io.pck_snd;
+ tcp_seqno = si->io.pck_snd;
tcp_ack = si->io.pck_rcv;
tcp_ctl = 0x12; /* SYN,ACK */
@@ -1019,7 +1019,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)addr;
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x10; /* ACK */
@@ -1029,7 +1029,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)si->peername;
- tcp_seq = si->io.pck_snd;
+ tcp_seqno = si->io.pck_snd;
tcp_ack = si->io.pck_rcv;
tcp_ctl = 0x18; /* PSH,ACK */
@@ -1047,7 +1047,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
buf, len, packet_len);
}
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x14; /** RST,ACK */
@@ -1061,7 +1061,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
return NULL;
}
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x14; /* RST,ACK */
@@ -1071,7 +1071,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)si->peername;
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x18; /* PSH,ACK */
@@ -1087,7 +1087,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
return NULL;
}
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x14; /* RST,ACK */
@@ -1123,7 +1123,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)si->peername;
- tcp_seq = si->io.pck_snd;
+ tcp_seqno = si->io.pck_snd;
tcp_ack = si->io.pck_rcv;
tcp_ctl = 0x11; /* FIN, ACK */
@@ -1137,7 +1137,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
dest_addr = (const struct sockaddr_in *)si->myname;
src_addr = (const struct sockaddr_in *)si->peername;
- tcp_seq = si->io.pck_rcv;
+ tcp_seqno = si->io.pck_rcv;
tcp_ack = si->io.pck_snd;
tcp_ctl = 0x11; /* FIN,ACK */
@@ -1151,7 +1151,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
src_addr = (const struct sockaddr_in *)si->myname;
dest_addr = (const struct sockaddr_in *)si->peername;
- tcp_seq = si->io.pck_snd;
+ tcp_seqno = si->io.pck_snd;
tcp_ack = si->io.pck_rcv;
tcp_ctl = 0x10; /* ACK */
@@ -1164,7 +1164,7 @@ static struct swrap_packet *swrap_marshall_packet(struct socket_info *si,
return swrap_packet_init(&tv, src_addr, dest_addr, si->type,
(const unsigned char *)buf, len,
- tcp_seq, tcp_ack, tcp_ctl, unreachable,
+ tcp_seqno, tcp_ack, tcp_ctl, unreachable,
packet_len);
}
diff --git a/lib/subunit/harness2subunit.pl b/lib/subunit/harness2subunit.pl
new file mode 100755
index 0000000000..45f515540b
--- /dev/null
+++ b/lib/subunit/harness2subunit.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+# Simple script that converts Perl test harness output to
+# Subunit
+# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU GPL, v3 or later
+
+my $firstline = 1;
+my $error = 0;
+while(<STDIN>) {
+ if ($firstline) {
+ $firstline = 0;
+ next;
+ }
+ if (/^not ok (\d+) - (.*)$/) {
+ print "test: $2\n";
+ print "failure: $2\n";
+ $error = 1;
+ } elsif (/^ok (\d+) - (.*)$/) {
+ print "test: $2\n";
+ print "success: $2\n";
+ } elsif (/^ok (\d+)$/) {
+ print "test: $1\n";
+ print "success: $1\n";
+ } elsif (/^ok (\d+) # skip (.*)$/) {
+ print "test: $1\n";
+ print "skip: $1 [\n$2\n]\n";
+ } elsif (/^not ok (\d+)$/) {
+ print "test: $1\n";
+ print "failure: $1\n";
+ $error = 1;
+ } else {
+ print;
+ }
+}
+exit $error;
+
diff --git a/lib/subunit/python/subunit/__init__.py b/lib/subunit/python/subunit/__init__.py
new file mode 100644
index 0000000000..406cd8765b
--- /dev/null
+++ b/lib/subunit/python/subunit/__init__.py
@@ -0,0 +1,388 @@
+#
+# subunit: extensions to python unittest to get test results from subprocesses.
+# Copyright (C) 2005 Robert Collins <robertc@robertcollins.net>
+# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
+#
+# 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import os
+from StringIO import StringIO
+import sys
+import unittest
+
+def test_suite():
+ import subunit.tests
+ return subunit.tests.test_suite()
+
+
+def join_dir(base_path, path):
+ """
+ Returns an absolute path to C{path}, calculated relative to the parent
+ of C{base_path}.
+
+ @param base_path: A path to a file or directory.
+ @param path: An absolute path, or a path relative to the containing
+ directory of C{base_path}.
+
+ @return: An absolute path to C{path}.
+ """
+ return os.path.join(os.path.dirname(os.path.abspath(base_path)), path)
+
+
+class TestProtocolServer(object):
+ """A class for receiving results from a TestProtocol client."""
+
+ OUTSIDE_TEST = 0
+ TEST_STARTED = 1
+ READING_FAILURE = 2
+ READING_ERROR = 3
+
+ def __init__(self, client, stream=sys.stdout):
+ """Create a TestProtocol server instance.
+
+ client should be an object that provides
+ - startTest
+ - addSuccess
+ - addFailure
+ - addError
+ - stopTest
+ methods, i.e. a TestResult.
+ """
+ self.state = TestProtocolServer.OUTSIDE_TEST
+ self.client = client
+ self._stream = stream
+
+ def _addError(self, offset, line):
+ if (self.state == TestProtocolServer.TEST_STARTED and
+ self.current_test_description == line[offset:-1]):
+ self.state = TestProtocolServer.OUTSIDE_TEST
+ self.current_test_description = None
+ self.client.addError(self._current_test, RemoteError(""))
+ self.client.stopTest(self._current_test)
+ self._current_test = None
+ elif (self.state == TestProtocolServer.TEST_STARTED and
+ self.current_test_description + " [" == line[offset:-1]):
+ self.state = TestProtocolServer.READING_ERROR
+ self._message = ""
+ else:
+ self.stdOutLineReceived(line)
+
+ def _addFailure(self, offset, line):
+ if (self.state == TestProtocolServer.TEST_STARTED and
+ self.current_test_description == line[offset:-1]):
+ self.state = TestProtocolServer.OUTSIDE_TEST
+ self.current_test_description = None
+ self.client.addFailure(self._current_test, RemoteError())
+ self.client.stopTest(self._current_test)
+ elif (self.state == TestProtocolServer.TEST_STARTED and
+ self.current_test_description + " [" == line[offset:-1]):
+ self.state = TestProtocolServer.READING_FAILURE
+ self._message = ""
+ else:
+ self.stdOutLineReceived(line)
+
+ def _addSuccess(self, offset, line):
+ if (self.state == TestProtocolServer.TEST_STARTED and
+ self.current_test_description == line[offset:-1]):
+ self.client.addSuccess(self._current_test)
+ self.client.stopTest(self._current_test)
+ self.current_test_description = None
+ self._current_test = None
+ self.state = TestProtocolServer.OUTSIDE_TEST
+ else:
+ self.stdOutLineReceived(line)
+
+ def _appendMessage(self, line):
+ if line[0:2] == " ]":
+ # quoted ] start
+ self._message += line[1:]
+ else:
+ self._message += line
+
+ def endQuote(self, line):
+ if self.state == TestProtocolServer.READING_FAILURE:
+ self.state = TestProtocolServer.OUTSIDE_TEST
+ self.current_test_description = None
+ self.client.addFailure(self._current_test,
+ RemoteError(self._message))
+ self.client.stopTest(self._current_test)
+ elif self.state == TestProtocolServer.READING_ERROR:
+ self.state = TestProtocolServer.OUTSIDE_TEST
+ self.current_test_description = None
+ self.client.addError(self._current_test,
+ RemoteError(self._message))
+ self.client.stopTest(self._current_test)
+ else:
+ self.stdOutLineReceived(line)
+
+ def lineReceived(self, line):
+ """Call the appropriate local method for the received line."""
+ if line == "]\n":
+ self.endQuote(line)
+ elif (self.state == TestProtocolServer.READING_FAILURE or
+ self.state == TestProtocolServer.READING_ERROR):
+ self._appendMessage(line)
+ else:
+ parts = line.split(None, 1)
+ if len(parts) == 2:
+ cmd, rest = parts
+ offset = len(cmd) + 1
+ cmd = cmd.strip(':')
+ if cmd in ('test', 'testing'):
+ self._startTest(offset, line)
+ elif cmd == 'error':
+ self._addError(offset, line)
+ elif cmd == 'failure':
+ self._addFailure(offset, line)
+ elif cmd in ('success', 'successful'):
+ self._addSuccess(offset, line)
+ else:
+ self.stdOutLineReceived(line)
+ else:
+ self.stdOutLineReceived(line)
+
+ def lostConnection(self):
+ """The input connection has finished."""
+ if self.state == TestProtocolServer.TEST_STARTED:
+ self.client.addError(self._current_test,
+ RemoteError("lost connection during test '%s'"
+ % self.current_test_description))
+ self.client.stopTest(self._current_test)
+ elif self.state == TestProtocolServer.READING_ERROR:
+ self.client.addError(self._current_test,
+ RemoteError("lost connection during "
+ "error report of test "
+ "'%s'" %
+ self.current_test_description))
+ self.client.stopTest(self._current_test)
+ elif self.state == TestProtocolServer.READING_FAILURE:
+ self.client.addError(self._current_test,
+ RemoteError("lost connection during "
+ "failure report of test "
+ "'%s'" %
+ self.current_test_description))
+ self.client.stopTest(self._current_test)
+
+ def readFrom(self, pipe):
+ for line in pipe.readlines():
+ self.lineReceived(line)
+ self.lostConnection()
+
+ def _startTest(self, offset, line):
+ """Internal call to change state machine. Override startTest()."""
+ if self.state == TestProtocolServer.OUTSIDE_TEST:
+ self.state = TestProtocolServer.TEST_STARTED
+ self._current_test = RemotedTestCase(line[offset:-1])
+ self.current_test_description = line[offset:-1]
+ self.client.startTest(self._current_test)
+ else:
+ self.stdOutLineReceived(line)
+
+ def stdOutLineReceived(self, line):
+ self._stream.write(line)
+
+
+class RemoteException(Exception):
+ """An exception that occured remotely to python."""
+
+ def __eq__(self, other):
+ try:
+ return self.args == other.args
+ except AttributeError:
+ return False
+
+
+class TestProtocolClient(unittest.TestResult):
+ """A class that looks like a TestResult and informs a TestProtocolServer."""
+
+ def __init__(self, stream):
+ super(TestProtocolClient, self).__init__()
+ self._stream = stream
+
+ def addError(self, test, error):
+ """Report an error in test test."""
+ self._stream.write("error: %s [\n" % (test.shortDescription() or str(test)))
+ for line in self._exc_info_to_string(error, test).splitlines():
+ self._stream.write("%s\n" % line)
+ self._stream.write("]\n")
+ super(TestProtocolClient, self).addError(test, error)
+
+ def addFailure(self, test, error):
+ """Report a failure in test test."""
+ self._stream.write("failure: %s [\n" % (test.shortDescription() or str(test)))
+ for line in self._exc_info_to_string(error, test).splitlines():
+ self._stream.write("%s\n" % line)
+ self._stream.write("]\n")
+ super(TestProtocolClient, self).addFailure(test, error)
+
+ def addSuccess(self, test):
+ """Report a success in a test."""
+ self._stream.write("successful: %s\n" % (test.shortDescription() or str(test)))
+ super(TestProtocolClient, self).addSuccess(test)
+
+ def startTest(self, test):
+ """Mark a test as starting its test run."""
+ self._stream.write("test: %s\n" % (test.shortDescription() or str(test)))
+ super(TestProtocolClient, self).startTest(test)
+
+
+def RemoteError(description=""):
+ if description == "":
+ description = "\n"
+ return (RemoteException, RemoteException(description), None)
+
+
+class RemotedTestCase(unittest.TestCase):
+ """A class to represent test cases run in child processes."""
+
+ def __eq__ (self, other):
+ try:
+ return self.__description == other.__description
+ except AttributeError:
+ return False
+
+ def __init__(self, description):
+ """Create a psuedo test case with description description."""
+ self.__description = description
+
+ def error(self, label):
+ raise NotImplementedError("%s on RemotedTestCases is not permitted." %
+ label)
+
+ def setUp(self):
+ self.error("setUp")
+
+ def tearDown(self):
+ self.error("tearDown")
+
+ def shortDescription(self):
+ return self.__description
+
+ def id(self):
+ return "%s.%s" % (self._strclass(), self.__description)
+
+ def __str__(self):
+ return "%s (%s)" % (self.__description, self._strclass())
+
+ def __repr__(self):
+ return "<%s description='%s'>" % \
+ (self._strclass(), self.__description)
+
+ def run(self, result=None):
+ if result is None: result = self.defaultTestResult()
+ result.startTest(self)
+ result.addError(self, RemoteError("Cannot run RemotedTestCases.\n"))
+ result.stopTest(self)
+
+ def _strclass(self):
+ cls = self.__class__
+ return "%s.%s" % (cls.__module__, cls.__name__)
+
+
+class ExecTestCase(unittest.TestCase):
+ """A test case which runs external scripts for test fixtures."""
+
+ def __init__(self, methodName='runTest'):
+ """Create an instance of the class that will use the named test
+ method when executed. Raises a ValueError if the instance does
+ not have a method with the specified name.
+ """
+ unittest.TestCase.__init__(self, methodName)
+ testMethod = getattr(self, methodName)
+ self.script = join_dir(sys.modules[self.__class__.__module__].__file__,
+ testMethod.__doc__)
+
+ def countTestCases(self):
+ return 1
+
+ def run(self, result=None):
+ if result is None: result = self.defaultTestResult()
+ self._run(result)
+
+ def debug(self):
+ """Run the test without collecting errors in a TestResult"""
+ self._run(unittest.TestResult())
+
+ def _run(self, result):
+ protocol = TestProtocolServer(result)
+ output = os.popen(self.script, mode='r')
+ protocol.readFrom(output)
+
+
+class IsolatedTestCase(unittest.TestCase):
+ """A TestCase which runs its tests in a forked process."""
+
+ def run(self, result=None):
+ if result is None: result = self.defaultTestResult()
+ run_isolated(unittest.TestCase, self, result)
+
+
+class IsolatedTestSuite(unittest.TestSuite):
+ """A TestCase which runs its tests in a forked process."""
+
+ def run(self, result=None):
+ if result is None: result = unittest.TestResult()
+ run_isolated(unittest.TestSuite, self, result)
+
+
+def run_isolated(klass, self, result):
+ """Run a test suite or case in a subprocess, using the run method on klass.
+ """
+ c2pread, c2pwrite = os.pipe()
+ # fixme - error -> result
+ # now fork
+ pid = os.fork()
+ if pid == 0:
+ # Child
+ # Close parent's pipe ends
+ os.close(c2pread)
+ # Dup fds for child
+ os.dup2(c2pwrite, 1)
+ # Close pipe fds.
+ os.close(c2pwrite)
+
+ # at this point, sys.stdin is redirected, now we want
+ # to filter it to escape ]'s.
+ ### XXX: test and write that bit.
+
+ result = TestProtocolClient(sys.stdout)
+ klass.run(self, result)
+ sys.stdout.flush()
+ sys.stderr.flush()
+ # exit HARD, exit NOW.
+ os._exit(0)
+ else:
+ # Parent
+ # Close child pipe ends
+ os.close(c2pwrite)
+ # hookup a protocol engine
+ protocol = TestProtocolServer(result)
+ protocol.readFrom(os.fdopen(c2pread, 'rU'))
+ os.waitpid(pid, 0)
+ # TODO return code evaluation.
+ return result
+
+
+class SubunitTestRunner(object):
+ def __init__(self, stream=sys.stdout):
+ self.stream = stream
+
+ def run(self, test):
+ "Run the given test case or test suite."
+ result = TestProtocolClient(self.stream)
+ test(result)
+ return result
+
diff --git a/lib/subunit/python/subunit/tests/TestUtil.py b/lib/subunit/python/subunit/tests/TestUtil.py
new file mode 100644
index 0000000000..1b5ba9c293
--- /dev/null
+++ b/lib/subunit/python/subunit/tests/TestUtil.py
@@ -0,0 +1,80 @@
+# Copyright (c) 2004 Canonical Limited
+# Author: Robert Collins <robert.collins@canonical.com>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import sys
+import logging
+import unittest
+
+
+class LogCollector(logging.Handler):
+ def __init__(self):
+ logging.Handler.__init__(self)
+ self.records=[]
+ def emit(self, record):
+ self.records.append(record.getMessage())
+
+
+def makeCollectingLogger():
+ """I make a logger instance that collects its logs for programmatic analysis
+ -> (logger, collector)"""
+ logger=logging.Logger("collector")
+ handler=LogCollector()
+ handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
+ logger.addHandler(handler)
+ return logger, handler
+
+
+def visitTests(suite, visitor):
+ """A foreign method for visiting the tests in a test suite."""
+ for test in suite._tests:
+ #Abusing types to avoid monkey patching unittest.TestCase.
+ # Maybe that would be better?
+ try:
+ test.visit(visitor)
+ except AttributeError:
+ if isinstance(test, unittest.TestCase):
+ visitor.visitCase(test)
+ elif isinstance(test, unittest.TestSuite):
+ visitor.visitSuite(test)
+ visitTests(test, visitor)
+ else:
+ print "unvisitable non-unittest.TestCase element %r (%r)" % (test, test.__class__)
+
+
+class TestSuite(unittest.TestSuite):
+ """I am an extended TestSuite with a visitor interface.
+ This is primarily to allow filtering of tests - and suites or
+ more in the future. An iterator of just tests wouldn't scale..."""
+
+ def visit(self, visitor):
+ """visit the composite. Visiting is depth-first.
+ current callbacks are visitSuite and visitCase."""
+ visitor.visitSuite(self)
+ visitTests(self, visitor)
+
+
+class TestLoader(unittest.TestLoader):
+ """Custome TestLoader to set the right TestSuite class."""
+ suiteClass = TestSuite
+
+class TestVisitor(object):
+ """A visitor for Tests"""
+ def visitSuite(self, aTestSuite):
+ pass
+ def visitCase(self, aTestCase):
+ pass
diff --git a/lib/subunit/python/subunit/tests/__init__.py b/lib/subunit/python/subunit/tests/__init__.py
new file mode 100644
index 0000000000..544d0e704f
--- /dev/null
+++ b/lib/subunit/python/subunit/tests/__init__.py
@@ -0,0 +1,25 @@
+#
+# subunit: extensions to python unittest to get test results from subprocesses.
+# Copyright (C) 2005 Robert Collins <robertc@robertcollins.net>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+from subunit.tests import TestUtil, test_test_protocol
+
+def test_suite():
+ result = TestUtil.TestSuite()
+ result.addTest(test_test_protocol.test_suite())
+ return result
diff --git a/lib/subunit/python/subunit/tests/sample-script.py b/lib/subunit/python/subunit/tests/sample-script.py
new file mode 100755
index 0000000000..223d2f5d9f
--- /dev/null
+++ b/lib/subunit/python/subunit/tests/sample-script.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+import sys
+print "test old mcdonald"
+print "success old mcdonald"
+print "test bing crosby"
+print "failure bing crosby ["
+print "foo.c:53:ERROR invalid state"
+print "]"
+print "test an error"
+print "error an error"
+sys.exit(0)
diff --git a/lib/subunit/python/subunit/tests/sample-two-script.py b/lib/subunit/python/subunit/tests/sample-two-script.py
new file mode 100755
index 0000000000..d5550842bf
--- /dev/null
+++ b/lib/subunit/python/subunit/tests/sample-two-script.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+import sys
+print "test old mcdonald"
+print "success old mcdonald"
+print "test bing crosby"
+print "success bing crosby"
+sys.exit(0)
diff --git a/lib/subunit/python/subunit/tests/test_test_protocol.py b/lib/subunit/python/subunit/tests/test_test_protocol.py
new file mode 100644
index 0000000000..af31584a97
--- /dev/null
+++ b/lib/subunit/python/subunit/tests/test_test_protocol.py
@@ -0,0 +1,730 @@
+#
+# subunit: extensions to python unittest to get test results from subprocesses.
+# Copyright (C) 2005 Robert Collins <robertc@robertcollins.net>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import unittest
+from StringIO import StringIO
+import os
+import subunit
+import sys
+
+try:
+ class MockTestProtocolServerClient(object):
+ """A mock protocol server client to test callbacks."""
+
+ def __init__(self):
+ self.end_calls = []
+ self.error_calls = []
+ self.failure_calls = []
+ self.start_calls = []
+ self.success_calls = []
+ super(MockTestProtocolServerClient, self).__init__()
+
+ def addError(self, test, error):
+ self.error_calls.append((test, error))
+
+ def addFailure(self, test, error):
+ self.failure_calls.append((test, error))
+
+ def addSuccess(self, test):
+ self.success_calls.append(test)
+
+ def stopTest(self, test):
+ self.end_calls.append(test)
+
+ def startTest(self, test):
+ self.start_calls.append(test)
+
+except AttributeError:
+ MockTestProtocolServer = None
+
+
+class TestMockTestProtocolServer(unittest.TestCase):
+
+ def test_start_test(self):
+ protocol = MockTestProtocolServerClient()
+ protocol.startTest(subunit.RemotedTestCase("test old mcdonald"))
+ self.assertEqual(protocol.start_calls,
+ [subunit.RemotedTestCase("test old mcdonald")])
+ self.assertEqual(protocol.end_calls, [])
+ self.assertEqual(protocol.error_calls, [])
+ self.assertEqual(protocol.failure_calls, [])
+ self.assertEqual(protocol.success_calls, [])
+
+ def test_add_error(self):
+ protocol = MockTestProtocolServerClient()
+ protocol.addError(subunit.RemotedTestCase("old mcdonald"),
+ subunit.RemoteError("omg it works"))
+ self.assertEqual(protocol.start_calls, [])
+ self.assertEqual(protocol.end_calls, [])
+ self.assertEqual(protocol.error_calls, [(
+ subunit.RemotedTestCase("old mcdonald"),
+ subunit.RemoteError("omg it works"))])
+ self.assertEqual(protocol.failure_calls, [])
+ self.assertEqual(protocol.success_calls, [])
+
+ def test_add_failure(self):
+ protocol = MockTestProtocolServerClient()
+ protocol.addFailure(subunit.RemotedTestCase("old mcdonald"),
+ subunit.RemoteError("omg it works"))
+ self.assertEqual(protocol.start_calls, [])
+ self.assertEqual(protocol.end_calls, [])
+ self.assertEqual(protocol.error_calls, [])
+ self.assertEqual(protocol.failure_calls, [
+ (subunit.RemotedTestCase("old mcdonald"),
+ subunit.RemoteError("omg it works"))])
+ self.assertEqual(protocol.success_calls, [])
+
+ def test_add_success(self):
+ protocol = MockTestProtocolServerClient()
+ protocol.addSuccess(subunit.RemotedTestCase("test old mcdonald"))
+ self.assertEqual(protocol.start_calls, [])
+ self.assertEqual(protocol.end_calls, [])
+ self.assertEqual(protocol.error_calls, [])
+ self.assertEqual(protocol.failure_calls, [])
+ self.assertEqual(protocol.success_calls,
+ [subunit.RemotedTestCase("test old mcdonald")])
+
+ def test_end_test(self):
+ protocol = MockTestProtocolServerClient()
+ protocol.stopTest(subunit.RemotedTestCase("test old mcdonald"))
+ self.assertEqual(protocol.end_calls,
+ [subunit.RemotedTestCase("test old mcdonald")])
+ self.assertEqual(protocol.error_calls, [])
+ self.assertEqual(protocol.failure_calls, [])
+ self.assertEqual(protocol.success_calls, [])
+ self.assertEqual(protocol.start_calls, [])
+
+
+class TestTestImports(unittest.TestCase):
+
+ def test_imports(self):
+ from subunit import TestProtocolServer
+ from subunit import RemotedTestCase
+ from subunit import RemoteError
+ from subunit import ExecTestCase
+ from subunit import IsolatedTestCase
+ from subunit import TestProtocolClient
+
+
+class TestTestProtocolServerPipe(unittest.TestCase):
+
+ def test_story(self):
+ client = unittest.TestResult()
+ protocol = subunit.TestProtocolServer(client)
+ pipe = StringIO("test old mcdonald\n"
+ "success old mcdonald\n"
+ "test bing crosby\n"
+ "failure bing crosby [\n"
+ "foo.c:53:ERROR invalid state\n"
+ "]\n"
+ "test an error\n"
+ "error an error\n")
+ protocol.readFrom(pipe)
+ mcdonald = subunit.RemotedTestCase("old mcdonald")
+ bing = subunit.RemotedTestCase("bing crosby")
+ an_error = subunit.RemotedTestCase("an error")
+ self.assertEqual(client.errors,
+ [(an_error, 'RemoteException: \n\n')])
+ self.assertEqual(
+ client.failures,
+ [(bing, "RemoteException: foo.c:53:ERROR invalid state\n\n")])
+ self.assertEqual(client.testsRun, 3)
+
+
+class TestTestProtocolServerStartTest(unittest.TestCase):
+
+ def setUp(self):
+ self.client = MockTestProtocolServerClient()
+ self.protocol = subunit.TestProtocolServer(self.client)
+
+ def test_start_test(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.assertEqual(self.client.start_calls,
+ [subunit.RemotedTestCase("old mcdonald")])
+
+ def test_start_testing(self):
+ self.protocol.lineReceived("testing old mcdonald\n")
+ self.assertEqual(self.client.start_calls,
+ [subunit.RemotedTestCase("old mcdonald")])
+
+ def test_start_test_colon(self):
+ self.protocol.lineReceived("test: old mcdonald\n")
+ self.assertEqual(self.client.start_calls,
+ [subunit.RemotedTestCase("old mcdonald")])
+
+ def test_start_testing_colon(self):
+ self.protocol.lineReceived("testing: old mcdonald\n")
+ self.assertEqual(self.client.start_calls,
+ [subunit.RemotedTestCase("old mcdonald")])
+
+
+class TestTestProtocolServerPassThrough(unittest.TestCase):
+
+ def setUp(self):
+ from StringIO import StringIO
+ self.stdout = StringIO()
+ self.test = subunit.RemotedTestCase("old mcdonald")
+ self.client = MockTestProtocolServerClient()
+ self.protocol = subunit.TestProtocolServer(self.client, self.stdout)
+
+ def keywords_before_test(self):
+ self.protocol.lineReceived("failure a\n")
+ self.protocol.lineReceived("failure: a\n")
+ self.protocol.lineReceived("error a\n")
+ self.protocol.lineReceived("error: a\n")
+ self.protocol.lineReceived("success a\n")
+ self.protocol.lineReceived("success: a\n")
+ self.protocol.lineReceived("successful a\n")
+ self.protocol.lineReceived("successful: a\n")
+ self.protocol.lineReceived("]\n")
+ self.assertEqual(self.stdout.getvalue(), "failure a\n"
+ "failure: a\n"
+ "error a\n"
+ "error: a\n"
+ "success a\n"
+ "success: a\n"
+ "successful a\n"
+ "successful: a\n"
+ "]\n")
+
+ def test_keywords_before_test(self):
+ self.keywords_before_test()
+ self.assertEqual(self.client.start_calls, [])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_keywords_after_error(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("error old mcdonald\n")
+ self.keywords_before_test()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls,
+ [(self.test, subunit.RemoteError(""))])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_keywords_after_failure(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("failure old mcdonald\n")
+ self.keywords_before_test()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls,
+ [(self.test, subunit.RemoteError())])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_keywords_after_success(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("success old mcdonald\n")
+ self.keywords_before_test()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [self.test])
+
+ def test_keywords_after_test(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("failure a\n")
+ self.protocol.lineReceived("failure: a\n")
+ self.protocol.lineReceived("error a\n")
+ self.protocol.lineReceived("error: a\n")
+ self.protocol.lineReceived("success a\n")
+ self.protocol.lineReceived("success: a\n")
+ self.protocol.lineReceived("successful a\n")
+ self.protocol.lineReceived("successful: a\n")
+ self.protocol.lineReceived("]\n")
+ self.protocol.lineReceived("failure old mcdonald\n")
+ self.assertEqual(self.stdout.getvalue(), "test old mcdonald\n"
+ "failure a\n"
+ "failure: a\n"
+ "error a\n"
+ "error: a\n"
+ "success a\n"
+ "success: a\n"
+ "successful a\n"
+ "successful: a\n"
+ "]\n")
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.failure_calls,
+ [(self.test, subunit.RemoteError())])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_keywords_during_failure(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("failure: old mcdonald [\n")
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("failure a\n")
+ self.protocol.lineReceived("failure: a\n")
+ self.protocol.lineReceived("error a\n")
+ self.protocol.lineReceived("error: a\n")
+ self.protocol.lineReceived("success a\n")
+ self.protocol.lineReceived("success: a\n")
+ self.protocol.lineReceived("successful a\n")
+ self.protocol.lineReceived("successful: a\n")
+ self.protocol.lineReceived(" ]\n")
+ self.protocol.lineReceived("]\n")
+ self.assertEqual(self.stdout.getvalue(), "")
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.failure_calls,
+ [(self.test, subunit.RemoteError("test old mcdonald\n"
+ "failure a\n"
+ "failure: a\n"
+ "error a\n"
+ "error: a\n"
+ "success a\n"
+ "success: a\n"
+ "successful a\n"
+ "successful: a\n"
+ "]\n"))])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_stdout_passthrough(self):
+ """Lines received which cannot be interpreted as any protocol action
+ should be passed through to sys.stdout.
+ """
+ bytes = "randombytes\n"
+ self.protocol.lineReceived(bytes)
+ self.assertEqual(self.stdout.getvalue(), bytes)
+
+
+class TestTestProtocolServerLostConnection(unittest.TestCase):
+
+ def setUp(self):
+ self.client = MockTestProtocolServerClient()
+ self.protocol = subunit.TestProtocolServer(self.client)
+ self.test = subunit.RemotedTestCase("old mcdonald")
+
+ def test_lost_connection_no_input(self):
+ self.protocol.lostConnection()
+ self.assertEqual(self.client.start_calls, [])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_lost_connection_after_start(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lostConnection()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [
+ (self.test, subunit.RemoteError("lost connection during "
+ "test 'old mcdonald'"))])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_lost_connected_after_error(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("error old mcdonald\n")
+ self.protocol.lostConnection()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [
+ (self.test, subunit.RemoteError(""))])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_lost_connection_during_error(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("error old mcdonald [\n")
+ self.protocol.lostConnection()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [
+ (self.test, subunit.RemoteError("lost connection during error "
+ "report of test 'old mcdonald'"))])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_lost_connected_after_failure(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("failure old mcdonald\n")
+ self.protocol.lostConnection()
+ test = subunit.RemotedTestCase("old mcdonald")
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls,
+ [(self.test, subunit.RemoteError())])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_lost_connection_during_failure(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("failure old mcdonald [\n")
+ self.protocol.lostConnection()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls,
+ [(self.test,
+ subunit.RemoteError("lost connection during "
+ "failure report"
+ " of test 'old mcdonald'"))])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [])
+
+ def test_lost_connection_after_success(self):
+ self.protocol.lineReceived("test old mcdonald\n")
+ self.protocol.lineReceived("success old mcdonald\n")
+ self.protocol.lostConnection()
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls, [])
+ self.assertEqual(self.client.success_calls, [self.test])
+
+
+class TestTestProtocolServerAddError(unittest.TestCase):
+
+ def setUp(self):
+ self.client = MockTestProtocolServerClient()
+ self.protocol = subunit.TestProtocolServer(self.client)
+ self.protocol.lineReceived("test mcdonalds farm\n")
+ self.test = subunit.RemotedTestCase("mcdonalds farm")
+
+ def simple_error_keyword(self, keyword):
+ self.protocol.lineReceived("%s mcdonalds farm\n" % keyword)
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [
+ (self.test, subunit.RemoteError(""))])
+ self.assertEqual(self.client.failure_calls, [])
+
+ def test_simple_error(self):
+ self.simple_error_keyword("error")
+
+ def test_simple_error_colon(self):
+ self.simple_error_keyword("error:")
+
+ def test_error_empty_message(self):
+ self.protocol.lineReceived("error mcdonalds farm [\n")
+ self.protocol.lineReceived("]\n")
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [
+ (self.test, subunit.RemoteError(""))])
+ self.assertEqual(self.client.failure_calls, [])
+
+ def error_quoted_bracket(self, keyword):
+ self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword)
+ self.protocol.lineReceived(" ]\n")
+ self.protocol.lineReceived("]\n")
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [
+ (self.test, subunit.RemoteError("]\n"))])
+ self.assertEqual(self.client.failure_calls, [])
+
+ def test_error_quoted_bracket(self):
+ self.error_quoted_bracket("error")
+
+ def test_error_colon_quoted_bracket(self):
+ self.error_quoted_bracket("error:")
+
+
+class TestTestProtocolServerAddFailure(unittest.TestCase):
+
+ def setUp(self):
+ self.client = MockTestProtocolServerClient()
+ self.protocol = subunit.TestProtocolServer(self.client)
+ self.protocol.lineReceived("test mcdonalds farm\n")
+ self.test = subunit.RemotedTestCase("mcdonalds farm")
+
+ def simple_failure_keyword(self, keyword):
+ self.protocol.lineReceived("%s mcdonalds farm\n" % keyword)
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls,
+ [(self.test, subunit.RemoteError())])
+
+ def test_simple_failure(self):
+ self.simple_failure_keyword("failure")
+
+ def test_simple_failure_colon(self):
+ self.simple_failure_keyword("failure:")
+
+ def test_failure_empty_message(self):
+ self.protocol.lineReceived("failure mcdonalds farm [\n")
+ self.protocol.lineReceived("]\n")
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls,
+ [(self.test, subunit.RemoteError())])
+
+ def failure_quoted_bracket(self, keyword):
+ self.protocol.lineReceived("%s mcdonalds farm [\n" % keyword)
+ self.protocol.lineReceived(" ]\n")
+ self.protocol.lineReceived("]\n")
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.failure_calls,
+ [(self.test, subunit.RemoteError("]\n"))])
+
+ def test_failure_quoted_bracket(self):
+ self.failure_quoted_bracket("failure")
+
+ def test_failure_colon_quoted_bracket(self):
+ self.failure_quoted_bracket("failure:")
+
+
+class TestTestProtocolServerAddSuccess(unittest.TestCase):
+
+ def setUp(self):
+ self.client = MockTestProtocolServerClient()
+ self.protocol = subunit.TestProtocolServer(self.client)
+ self.protocol.lineReceived("test mcdonalds farm\n")
+ self.test = subunit.RemotedTestCase("mcdonalds farm")
+
+ def simple_success_keyword(self, keyword):
+ self.protocol.lineReceived("%s mcdonalds farm\n" % keyword)
+ self.assertEqual(self.client.start_calls, [self.test])
+ self.assertEqual(self.client.end_calls, [self.test])
+ self.assertEqual(self.client.error_calls, [])
+ self.assertEqual(self.client.success_calls, [self.test])
+
+ def test_simple_success(self):
+ self.simple_success_keyword("failure")
+
+ def test_simple_success_colon(self):
+ self.simple_success_keyword("failure:")
+
+ def test_simple_success(self):
+ self.simple_success_keyword("successful")
+
+ def test_simple_success_colon(self):
+ self.simple_success_keyword("successful:")
+
+
+class TestRemotedTestCase(unittest.TestCase):
+
+ def test_simple(self):
+ test = subunit.RemotedTestCase("A test description")
+ self.assertRaises(NotImplementedError, test.setUp)
+ self.assertRaises(NotImplementedError, test.tearDown)
+ self.assertEqual("A test description",
+ test.shortDescription())
+ self.assertEqual("subunit.RemotedTestCase.A test description",
+ test.id())
+ self.assertEqual("A test description (subunit.RemotedTestCase)", "%s" % test)
+ self.assertEqual("<subunit.RemotedTestCase description="
+ "'A test description'>", "%r" % test)
+ result = unittest.TestResult()
+ test.run(result)
+ self.assertEqual([(test, "RemoteException: "
+ "Cannot run RemotedTestCases.\n\n")],
+ result.errors)
+ self.assertEqual(1, result.testsRun)
+ another_test = subunit.RemotedTestCase("A test description")
+ self.assertEqual(test, another_test)
+ different_test = subunit.RemotedTestCase("ofo")
+ self.assertNotEqual(test, different_test)
+ self.assertNotEqual(another_test, different_test)
+
+
+class TestRemoteError(unittest.TestCase):
+
+ def test_eq(self):
+ error = subunit.RemoteError("Something went wrong")
+ another_error = subunit.RemoteError("Something went wrong")
+ different_error = subunit.RemoteError("boo!")
+ self.assertEqual(error, another_error)
+ self.assertNotEqual(error, different_error)
+ self.assertNotEqual(different_error, another_error)
+
+ def test_empty_constructor(self):
+ self.assertEqual(subunit.RemoteError(), subunit.RemoteError(""))
+
+
+class TestExecTestCase(unittest.TestCase):
+
+ class SampleExecTestCase(subunit.ExecTestCase):
+
+ def test_sample_method(self):
+ """sample-script.py"""
+ # the sample script runs three tests, one each
+ # that fails, errors and succeeds
+
+
+ def test_construct(self):
+ test = self.SampleExecTestCase("test_sample_method")
+ self.assertEqual(test.script,
+ subunit.join_dir(__file__, 'sample-script.py'))
+
+ def test_run(self):
+ runner = MockTestProtocolServerClient()
+ test = self.SampleExecTestCase("test_sample_method")
+ test.run(runner)
+ mcdonald = subunit.RemotedTestCase("old mcdonald")
+ bing = subunit.RemotedTestCase("bing crosby")
+ an_error = subunit.RemotedTestCase("an error")
+ self.assertEqual(runner.error_calls,
+ [(an_error, subunit.RemoteError())])
+ self.assertEqual(runner.failure_calls,
+ [(bing,
+ subunit.RemoteError(
+ "foo.c:53:ERROR invalid state\n"))])
+ self.assertEqual(runner.start_calls, [mcdonald, bing, an_error])
+ self.assertEqual(runner.end_calls, [mcdonald, bing, an_error])
+
+ def test_debug(self):
+ test = self.SampleExecTestCase("test_sample_method")
+ test.debug()
+
+ def test_count_test_cases(self):
+ """TODO run the child process and count responses to determine the count."""
+
+ def test_join_dir(self):
+ sibling = subunit.join_dir(__file__, 'foo')
+ expected = '%s/foo' % (os.path.split(__file__)[0],)
+ self.assertEqual(sibling, expected)
+
+
+class DoExecTestCase(subunit.ExecTestCase):
+
+ def test_working_script(self):
+ """sample-two-script.py"""
+
+
+class TestIsolatedTestCase(unittest.TestCase):
+
+ class SampleIsolatedTestCase(subunit.IsolatedTestCase):
+
+ SETUP = False
+ TEARDOWN = False
+ TEST = False
+
+ def setUp(self):
+ TestIsolatedTestCase.SampleIsolatedTestCase.SETUP = True
+
+ def tearDown(self):
+ TestIsolatedTestCase.SampleIsolatedTestCase.TEARDOWN = True
+
+ def test_sets_global_state(self):
+ TestIsolatedTestCase.SampleIsolatedTestCase.TEST = True
+
+
+ def test_construct(self):
+ test = self.SampleIsolatedTestCase("test_sets_global_state")
+
+ def test_run(self):
+ result = unittest.TestResult()
+ test = self.SampleIsolatedTestCase("test_sets_global_state")
+ test.run(result)
+ self.assertEqual(result.testsRun, 1)
+ self.assertEqual(self.SampleIsolatedTestCase.SETUP, False)
+ self.assertEqual(self.SampleIsolatedTestCase.TEARDOWN, False)
+ self.assertEqual(self.SampleIsolatedTestCase.TEST, False)
+
+ def test_debug(self):
+ pass
+ #test = self.SampleExecTestCase("test_sample_method")
+ #test.debug()
+
+
+class TestIsolatedTestSuite(unittest.TestCase):
+
+ class SampleTestToIsolate(unittest.TestCase):
+
+ SETUP = False
+ TEARDOWN = False
+ TEST = False
+
+ def setUp(self):
+ TestIsolatedTestSuite.SampleTestToIsolate.SETUP = True
+
+ def tearDown(self):
+ TestIsolatedTestSuite.SampleTestToIsolate.TEARDOWN = True
+
+ def test_sets_global_state(self):
+ TestIsolatedTestSuite.SampleTestToIsolate.TEST = True
+
+
+ def test_construct(self):
+ suite = subunit.IsolatedTestSuite()
+
+ def test_run(self):
+ result = unittest.TestResult()
+ suite = subunit.IsolatedTestSuite()
+ sub_suite = unittest.TestSuite()
+ sub_suite.addTest(self.SampleTestToIsolate("test_sets_global_state"))
+ sub_suite.addTest(self.SampleTestToIsolate("test_sets_global_state"))
+ suite.addTest(sub_suite)
+ suite.addTest(self.SampleTestToIsolate("test_sets_global_state"))
+ suite.run(result)
+ self.assertEqual(result.testsRun, 3)
+ self.assertEqual(self.SampleTestToIsolate.SETUP, False)
+ self.assertEqual(self.SampleTestToIsolate.TEARDOWN, False)
+ self.assertEqual(self.SampleTestToIsolate.TEST, False)
+
+
+class TestTestProtocolClient(unittest.TestCase):
+
+ def setUp(self):
+ self.io = StringIO()
+ self.protocol = subunit.TestProtocolClient(self.io)
+ self.test = TestTestProtocolClient("test_start_test")
+
+
+ def test_start_test(self):
+ """Test startTest on a TestProtocolClient."""
+ self.protocol.startTest(self.test)
+ self.assertEqual(self.io.getvalue(), "test: %s\n" % self.test.id())
+
+ def test_stop_test(self):
+ """Test stopTest on a TestProtocolClient."""
+ self.protocol.stopTest(self.test)
+ self.assertEqual(self.io.getvalue(), "")
+
+ def test_add_success(self):
+ """Test addSuccess on a TestProtocolClient."""
+ self.protocol.addSuccess(self.test)
+ self.assertEqual(
+ self.io.getvalue(), "successful: %s\n" % self.test.id())
+
+ def test_add_failure(self):
+ """Test addFailure on a TestProtocolClient."""
+ self.protocol.addFailure(self.test, subunit.RemoteError("boo"))
+ self.assertEqual(
+ self.io.getvalue(),
+ 'failure: %s [\nRemoteException: boo\n]\n' % self.test.id())
+
+ def test_add_error(self):
+ """Test stopTest on a TestProtocolClient."""
+ self.protocol.addError(self.test, subunit.RemoteError("phwoar"))
+ self.assertEqual(
+ self.io.getvalue(),
+ 'error: %s [\n'
+ "RemoteException: phwoar\n"
+ "]\n" % self.test.id())
+
+
+def test_suite():
+ loader = subunit.tests.TestUtil.TestLoader()
+ result = loader.loadTestsFromName(__name__)
+ return result
diff --git a/lib/talloc/Makefile.in b/lib/talloc/Makefile.in
index 07b8fd4ff0..c28693e2db 100644
--- a/lib/talloc/Makefile.in
+++ b/lib/talloc/Makefile.in
@@ -9,6 +9,7 @@ mandir = @mandir@
VPATH = @srcdir@:@libreplacedir@
srcdir = @srcdir@
builddir = @builddir@
+sharedbuilddir = @sharedbuilddir@
XSLTPROC = @XSLTPROC@
INSTALLCMD = @INSTALL@
CC = @CC@
@@ -31,6 +32,15 @@ include $(tallocdir)/talloc.mk
$(TALLOC_SOLIB): $(LIBOBJ)
$(SHLD) $(SHLD_FLAGS) -o $@ $(LIBOBJ) @SONAMEFLAG@$(TALLOC_SONAME)
+shared-build: all
+ ${INSTALLCMD} -d $(sharedbuilddir)/lib
+ ${INSTALLCMD} -m 644 libtalloc.a $(sharedbuilddir)/lib
+ ${INSTALLCMD} -m 755 $(TALLOC_SOLIB) $(sharedbuilddir)/lib
+ ln -sf $(TALLOC_SOLIB) $(sharedbuilddir)/lib/$(TALLOC_SONAME)
+ ln -sf $(TALLOC_SOLIB) $(sharedbuilddir)/lib/libtalloc.so
+ ${INSTALLCMD} -d $(sharedbuilddir)/include
+ ${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(sharedbuilddir)/include
+
check: test
installcheck:: test install
diff --git a/lib/talloc/build_macros.m4 b/lib/talloc/build_macros.m4
new file mode 100644
index 0000000000..c036668cd1
--- /dev/null
+++ b/lib/talloc/build_macros.m4
@@ -0,0 +1,14 @@
+AC_DEFUN(BUILD_WITH_SHARED_BUILD_DIR,
+ [ AC_ARG_WITH([shared-build-dir],
+ [AC_HELP_STRING([--with-shared-build-dir=DIR],
+ [temporary build directory where libraries are installed [$srcdir/sharedbuild]])])
+
+ sharedbuilddir="$srcdir/sharedbuild"
+ if test x"$with_shared_build_dir" != x; then
+ sharedbuilddir=$with_shared_build_dir
+ CFLAGS="$CFLAGS -I$with_shared_build_dir/include"
+ LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib"
+ fi
+ AC_SUBST(sharedbuilddir)
+ ])
+
diff --git a/lib/talloc/configure.ac b/lib/talloc/configure.ac
index 4719aa04b5..d2538f9222 100644
--- a/lib/talloc/configure.ac
+++ b/lib/talloc/configure.ac
@@ -21,4 +21,7 @@ AC_LD_SONAMEFLAG
AC_LIBREPLACE_SHLD
AC_LIBREPLACE_SHLD_FLAGS
+m4_include(build_macros.m4)
+BUILD_WITH_SHARED_BUILD_DIR
+
AC_OUTPUT(Makefile talloc.pc)
diff --git a/lib/talloc/talloc.mk b/lib/talloc/talloc.mk
index e1fe88c84b..f183cd57ef 100644
--- a/lib/talloc/talloc.mk
+++ b/lib/talloc/talloc.mk
@@ -5,8 +5,8 @@ TALLOC_SONAME = libtalloc.$(SHLIBEXT).1
all:: libtalloc.a $(TALLOC_SOLIB) testsuite
-testsuite:: $(LIBOBJ) testsuite.o
- $(CC) $(CFLAGS) -o testsuite testsuite.o $(LIBOBJ) $(LIBS)
+testsuite:: $(LIBOBJ) testsuite.o testsuite_main.o
+ $(CC) $(CFLAGS) -o testsuite testsuite.o testsuite_main.o $(LIBOBJ) $(LIBS)
libtalloc.a: $(LIBOBJ)
ar -rv $@ $(LIBOBJ)
@@ -22,13 +22,13 @@ install:: all
${INSTALLCMD} -m 644 talloc.pc $(DESTDIR)$(libdir)/pkgconfig
if [ -f talloc.3 ];then ${INSTALLCMD} -d $(DESTDIR)$(mandir)/man3; fi
if [ -f talloc.3 ];then ${INSTALLCMD} -m 644 talloc.3 $(DESTDIR)$(mandir)/man3; fi
- which swig >/dev/null 2>&1 && ${INSTALLCMD} -d $(DESTDIR)`swig -swiglib` || true
- which swig >/dev/null 2>&1 && ${INSTALLCMD} -m 644 talloc.i $(DESTDIR)`swig -swiglib` || true
+ which swig >/dev/null 2>&1 && ${INSTALLCMD} -d $(DESTDIR)$(prefix)`swig -swiglib` || true
+ which swig >/dev/null 2>&1 && ${INSTALLCMD} -m 644 talloc.i $(DESTDIR)$(prefix)`swig -swiglib` || true
doc:: talloc.3 talloc.3.html
clean::
- rm -f *~ $(LIBOBJ) $(TALLOC_SOLIB) libtalloc.a testsuite testsuite.o *.gc?? talloc.3 talloc.3.html
+ rm -f *~ $(LIBOBJ) $(TALLOC_SOLIB) libtalloc.a testsuite testsuite.o testsuite_main.o *.gc?? talloc.3 talloc.3.html
test:: testsuite
./testsuite
diff --git a/lib/talloc/talloc_guide.txt b/lib/talloc/talloc_guide.txt
index 18663b370d..3201fe6f0f 100644
--- a/lib/talloc/talloc_guide.txt
+++ b/lib/talloc/talloc_guide.txt
@@ -1,5 +1,7 @@
Using talloc in Samba4
-----------------------
+======================
+
+.. contents::
Andrew Tridgell
September 2004
@@ -18,7 +20,7 @@ get used to it.
Perhaps the biggest change from Samba3 is that there is no distinction
between a "talloc context" and a "talloc pointer". Any pointer
returned from talloc() is itself a valid talloc context. This means
-you can do this:
+you can do this::
struct foo *X = talloc(mem_ctx, struct foo);
X->name = talloc_strdup(X, "foo");
@@ -271,7 +273,7 @@ equivalent to:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void *talloc_named_const(const void *context, size_t size, const char *name);
-This is equivalent to:
+This is equivalent to::
ptr = talloc_size(context, size);
talloc_set_name_const(ptr, name);
@@ -288,7 +290,7 @@ talloc_set_name() for details.
void *talloc_init(const char *fmt, ...);
This function creates a zero length named talloc context as a top
-level context. It is equivalent to:
+level context. It is equivalent to::
talloc_named(NULL, 0, fmt, ...);
@@ -309,7 +311,7 @@ The talloc_realloc() macro changes the size of a talloc
pointer. The "count" argument is the number of elements of type "type"
that you want the resulting pointer to hold.
-talloc_realloc() has the following equivalences:
+talloc_realloc() has the following equivalences::
talloc_realloc(context, NULL, type, 1) ==> talloc(context, type);
talloc_realloc(context, NULL, type, N) ==> talloc_array(context, type, N);
@@ -490,7 +492,7 @@ This disables tracking of the NULL memory context.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(type *)talloc_zero(const void *ctx, type);
-The talloc_zero() macro is equivalent to:
+The talloc_zero() macro is equivalent to::
ptr = talloc(ctx, type);
if (ptr) memset(ptr, 0, sizeof(type));
@@ -505,7 +507,7 @@ The talloc_zero_size() function is useful when you don't have a known type
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void *talloc_memdup(const void *ctx, const void *p, size_t size);
-The talloc_memdup() function is equivalent to:
+The talloc_memdup() function is equivalent to::
ptr = talloc_size(ctx, size);
if (ptr) memcpy(ptr, p, size);
@@ -514,13 +516,14 @@ The talloc_memdup() function is equivalent to:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
char *talloc_strdup(const void *ctx, const char *p);
-The talloc_strdup() function is equivalent to:
+The talloc_strdup() function is equivalent to::
ptr = talloc_size(ctx, strlen(p)+1);
if (ptr) memcpy(ptr, p, strlen(p)+1);
This functions sets the name of the new pointer to the passed
-string. This is equivalent to:
+string. This is equivalent to::
+
talloc_set_name_const(ptr, ptr)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -540,7 +543,8 @@ The talloc_append_string() function appends the given formatted
string to the given string.
This function sets the name of the new pointer to the new
-string. This is equivalent to:
+string. This is equivalent to::
+
talloc_set_name_const(ptr, ptr)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@ -550,7 +554,8 @@ The talloc_vasprintf() function is the talloc equivalent of the C
library function vasprintf()
This functions sets the name of the new pointer to the new
-string. This is equivalent to:
+string. This is equivalent to::
+
talloc_set_name_const(ptr, ptr)
@@ -561,7 +566,8 @@ The talloc_asprintf() function is the talloc equivalent of the C
library function asprintf()
This functions sets the name of the new pointer to the new
-string. This is equivalent to:
+string. This is equivalent to::
+
talloc_set_name_const(ptr, ptr)
@@ -574,7 +580,8 @@ Use this varient when the string in the current talloc buffer may
have been truncated in length.
This functions sets the name of the new pointer to the new
-string. This is equivalent to:
+string. This is equivalent to::
+
talloc_set_name_const(ptr, ptr)
@@ -587,14 +594,15 @@ Use this varient when the string in the current talloc buffer has
not been changed.
This functions sets the name of the new pointer to the new
-string. This is equivalent to:
+string. This is equivalent to::
+
talloc_set_name_const(ptr, ptr)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
((type *)talloc_array(const void *ctx, type, uint_t count);
-The talloc_array() macro is equivalent to:
+The talloc_array() macro is equivalent to::
(type *)talloc_size(ctx, sizeof(type) * count);
@@ -648,7 +656,7 @@ then the pointer is returned. It it doesn't then NULL is returned.
This macro allows you to do type checking on talloc pointers. It is
particularly useful for void* private pointers. It is equivalent to
-this:
+this::
(type *)talloc_check_name(ptr, #type)
@@ -660,7 +668,8 @@ This macro allows you to force the name of a pointer to be a
particular type. This can be used in conjunction with
talloc_get_type() to do type checking on void* pointers.
-It is equivalent to this:
+It is equivalent to this::
+
talloc_set_name_const(ptr, #type)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c
index 3f06eee566..3d490ddf49 100644
--- a/lib/talloc/testsuite.c
+++ b/lib/talloc/testsuite.c
@@ -1140,13 +1140,3 @@ bool torture_local_talloc(struct torture_context *tctx)
return ret;
}
-
-#if _SAMBA_BUILD_ < 4
-int main(void)
-{
- bool ret = torture_local_talloc(NULL);
- if (!ret)
- return -1;
- return 0;
-}
-#endif
diff --git a/lib/talloc/testsuite_main.c b/lib/talloc/testsuite_main.c
new file mode 100644
index 0000000000..1b51333278
--- /dev/null
+++ b/lib/talloc/testsuite_main.c
@@ -0,0 +1,37 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ local testing of talloc routines.
+
+ Copyright (C) Andrew Tridgell 2004
+
+ ** NOTE! The following LGPL license applies to the talloc
+ ** 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"
+
+struct torture_context;
+bool torture_local_talloc(struct torture_context *tctx);
+
+int main(void)
+{
+ bool ret = torture_local_talloc(NULL);
+ if (!ret)
+ return -1;
+ return 0;
+}
diff --git a/lib/tdb/Makefile.in b/lib/tdb/Makefile.in
index 090bb6e2dc..9915d88264 100644
--- a/lib/tdb/Makefile.in
+++ b/lib/tdb/Makefile.in
@@ -12,6 +12,8 @@ libdir = @libdir@
VPATH = @srcdir@:@libreplacedir@
srcdir = @srcdir@
builddir = @builddir@
+sharedbuilddir = @sharedbuilddir@
+INSTALLCMD = @INSTALL@
CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/include -Iinclude
CFLAGS = $(CPPFLAGS) @CFLAGS@
LDFLAGS = @LDFLAGS@
@@ -43,6 +45,15 @@ install:: all
$(TDB_SOLIB): $(TDB_OBJ)
$(SHLD) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) @SONAMEFLAG@$(TDB_SONAME)
+shared-build: all
+ ${INSTALLCMD} -d $(sharedbuilddir)/lib
+ ${INSTALLCMD} -m 644 libtdb.a $(sharedbuilddir)/lib
+ ${INSTALLCMD} -m 755 $(TDB_SOLIB) $(sharedbuilddir)/lib
+ ln -sf $(TDB_SOLIB) $(sharedbuilddir)/lib/$(TDB_SONAME)
+ ln -sf $(TDB_SOLIB) $(sharedbuilddir)/lib/libtdb.so
+ ${INSTALLCMD} -d $(sharedbuilddir)/include
+ ${INSTALLCMD} -m 644 $(srcdir)/include/tdb.h $(sharedbuilddir)/include
+
check: test
test:: $(PYTHON_CHECK_TARGET)
diff --git a/lib/tdb/build_macros.m4 b/lib/tdb/build_macros.m4
new file mode 100644
index 0000000000..c036668cd1
--- /dev/null
+++ b/lib/tdb/build_macros.m4
@@ -0,0 +1,14 @@
+AC_DEFUN(BUILD_WITH_SHARED_BUILD_DIR,
+ [ AC_ARG_WITH([shared-build-dir],
+ [AC_HELP_STRING([--with-shared-build-dir=DIR],
+ [temporary build directory where libraries are installed [$srcdir/sharedbuild]])])
+
+ sharedbuilddir="$srcdir/sharedbuild"
+ if test x"$with_shared_build_dir" != x; then
+ sharedbuilddir=$with_shared_build_dir
+ CFLAGS="$CFLAGS -I$with_shared_build_dir/include"
+ LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib"
+ fi
+ AC_SUBST(sharedbuilddir)
+ ])
+
diff --git a/lib/tdb/configure.ac b/lib/tdb/configure.ac
index eaf70d30b4..2feaa6f5f5 100644
--- a/lib/tdb/configure.ac
+++ b/lib/tdb/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ(2.50)
AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""])
AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
AC_DEFUN([SMB_ENABLE], [echo -n ""])
-AC_INIT(tdb, 1.1.2)
+AC_INIT(tdb, 1.1.3)
AC_CONFIG_SRCDIR([common/tdb.c])
AC_CONFIG_HEADER(include/config.h)
AC_LIBREPLACE_ALL_CHECKS
@@ -27,4 +27,8 @@ if test -z "$PYTHON_CONFIG"; then
PYTHON_INSTALL_TARGET=""
PYTHON_CHECK_TARGET=""
fi
+
+m4_include(build_macros.m4)
+BUILD_WITH_SHARED_BUILD_DIR
+
AC_OUTPUT(Makefile tdb.pc)
diff --git a/lib/tdb/include/tdb.h b/lib/tdb/include/tdb.h
index 0008085de5..c41c9941f0 100644
--- a/lib/tdb/include/tdb.h
+++ b/lib/tdb/include/tdb.h
@@ -30,6 +30,7 @@
extern "C" {
#endif
+#include "signal.h"
/* flags to tdb_store() */
#define TDB_REPLACE 1 /* Unused */
diff --git a/lib/tdb/tdb.i b/lib/tdb/tdb.i
index 3d8b697732..4b529913d7 100644
--- a/lib/tdb/tdb.i
+++ b/lib/tdb/tdb.i
@@ -321,3 +321,8 @@ typedef struct tdb_context {
# TODO: any other missing methods for container types
}
} tdb;
+
+%pythoncode {
+__docformat__ = 'restructuredText'
+open = Tdb
+}
diff --git a/lib/tdb/tdb.py b/lib/tdb/tdb.py
index 9f306bab8c..42129d2091 100644
--- a/lib/tdb/tdb.py
+++ b/lib/tdb/tdb.py
@@ -1,5 +1,5 @@
# This file was automatically generated by SWIG (http://www.swig.org).
-# Version 1.3.35
+# Version 1.3.36
#
# Don't modify this file, modify the SWIG interface instead.
@@ -337,5 +337,8 @@ Tdb.name = new_instancemethod(_tdb.Tdb_name,None,Tdb)
Tdb_swigregister = _tdb.Tdb_swigregister
Tdb_swigregister(Tdb)
+__docformat__ = 'restructuredText'
+open = Tdb
+
diff --git a/lib/tdb/tdb_wrap.c b/lib/tdb/tdb_wrap.c
index 32665d79fd..e997e88572 100644
--- a/lib/tdb/tdb_wrap.c
+++ b/lib/tdb/tdb_wrap.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.35
+ * Version 1.3.36
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
@@ -52,6 +52,12 @@
# endif
#endif
+#ifndef SWIG_MSC_UNSUPPRESS_4505
+# if defined(_MSC_VER)
+# pragma warning(disable : 4505) /* unreferenced local function has been removed */
+# endif
+#endif
+
#ifndef SWIGUNUSEDPARM
# ifdef __cplusplus
# define SWIGUNUSEDPARM(p)
@@ -2518,7 +2524,7 @@ static swig_module_info swig_module = {swig_types, 11, 0, 0, 0, 0};
#define SWIG_name "_tdb"
-#define SWIGVERSION 0x010335
+#define SWIGVERSION 0x010336
#define SWIG_VERSION SWIGVERSION
@@ -2818,7 +2824,6 @@ SWIGINTERN PyObject *_wrap_new_Tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *arg
int arg3 ;
int arg4 ;
mode_t arg5 ;
- tdb *result = 0 ;
int res1 ;
char *buf1 = 0 ;
int alloc1 = 0 ;
@@ -2838,6 +2843,7 @@ SWIGINTERN PyObject *_wrap_new_Tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *arg
char * kwnames[] = {
(char *) "name",(char *) "hash_size",(char *) "tdb_flags",(char *) "flags",(char *) "mode", NULL
};
+ tdb *result = 0 ;
arg2 = 0;
arg3 = TDB_DEFAULT;
@@ -2895,10 +2901,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_error(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- enum TDB_ERROR result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ enum TDB_ERROR result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -2930,7 +2936,6 @@ SWIGINTERN PyObject *_wrap_delete_Tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *
}
arg1 = (tdb *)(argp1);
delete_tdb(arg1);
-
resultobj = SWIG_Py_Void();
return resultobj;
fail:
@@ -2941,10 +2946,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_close(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -2966,7 +2971,6 @@ SWIGINTERN PyObject *_wrap_Tdb_append(PyObject *SWIGUNUSEDPARM(self), PyObject *
tdb *arg1 = (tdb *) 0 ;
TDB_DATA arg2 ;
TDB_DATA arg3 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
@@ -2975,6 +2979,7 @@ SWIGINTERN PyObject *_wrap_Tdb_append(PyObject *SWIGUNUSEDPARM(self), PyObject *
char * kwnames[] = {
(char *) "self",(char *) "key",(char *) "new_dbuf", NULL
};
+ int result;
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:Tdb_append",kwnames,&obj0,&obj1,&obj2)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 );
@@ -3013,10 +3018,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_errorstr(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- char *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ char *result = 0 ;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3037,7 +3042,6 @@ SWIGINTERN PyObject *_wrap_Tdb_get(PyObject *SWIGUNUSEDPARM(self), PyObject *arg
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
TDB_DATA arg2 ;
- TDB_DATA result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
@@ -3045,6 +3049,7 @@ SWIGINTERN PyObject *_wrap_Tdb_get(PyObject *SWIGUNUSEDPARM(self), PyObject *arg
char * kwnames[] = {
(char *) "self",(char *) "key", NULL
};
+ TDB_DATA result;
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_get",kwnames,&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 );
@@ -3079,7 +3084,6 @@ SWIGINTERN PyObject *_wrap_Tdb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject *
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
TDB_DATA arg2 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
@@ -3087,6 +3091,7 @@ SWIGINTERN PyObject *_wrap_Tdb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject *
char * kwnames[] = {
(char *) "self",(char *) "key", NULL
};
+ int result;
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_delete",kwnames,&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 );
@@ -3118,7 +3123,6 @@ SWIGINTERN PyObject *_wrap_Tdb_store(PyObject *SWIGUNUSEDPARM(self), PyObject *a
TDB_DATA arg2 ;
TDB_DATA arg3 ;
int arg4 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
int val4 ;
@@ -3130,6 +3134,7 @@ SWIGINTERN PyObject *_wrap_Tdb_store(PyObject *SWIGUNUSEDPARM(self), PyObject *a
char * kwnames[] = {
(char *) "self",(char *) "key",(char *) "dbuf",(char *) "flag", NULL
};
+ int result;
arg4 = TDB_REPLACE;
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:Tdb_store",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
@@ -3177,7 +3182,6 @@ SWIGINTERN PyObject *_wrap_Tdb_exists(PyObject *SWIGUNUSEDPARM(self), PyObject *
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
TDB_DATA arg2 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
@@ -3185,6 +3189,7 @@ SWIGINTERN PyObject *_wrap_Tdb_exists(PyObject *SWIGUNUSEDPARM(self), PyObject *
char * kwnames[] = {
(char *) "self",(char *) "key", NULL
};
+ int result;
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_exists",kwnames,&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 );
@@ -3213,10 +3218,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_firstkey(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- TDB_DATA result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ TDB_DATA result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3242,7 +3247,6 @@ SWIGINTERN PyObject *_wrap_Tdb_nextkey(PyObject *SWIGUNUSEDPARM(self), PyObject
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
TDB_DATA arg2 ;
- TDB_DATA result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
@@ -3250,6 +3254,7 @@ SWIGINTERN PyObject *_wrap_Tdb_nextkey(PyObject *SWIGUNUSEDPARM(self), PyObject
char * kwnames[] = {
(char *) "self",(char *) "key", NULL
};
+ TDB_DATA result;
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_nextkey",kwnames,&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 );
@@ -3283,10 +3288,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3306,10 +3311,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3329,10 +3334,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_read_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3352,10 +3357,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_read_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3375,10 +3380,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_reopen(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3398,10 +3403,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_transaction_start(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3421,10 +3426,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_transaction_commit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3444,10 +3449,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3467,10 +3472,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_transaction_recover(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3490,10 +3495,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_hash_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3513,10 +3518,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_map_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- size_t result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ size_t result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3536,10 +3541,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_get_flags(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ int result;
if (!args) SWIG_fail;
swig_obj[0] = args;
@@ -3592,10 +3597,10 @@ fail:
SWIGINTERN PyObject *_wrap_Tdb_name(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
tdb *arg1 = (tdb *) 0 ;
- char *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject *swig_obj[1] ;
+ char *result = 0 ;
if (!args) SWIG_fail;
swig_obj[0] = args;