Skip to content

Commit ea91962

Browse files
committed
Low: Core: Obtain md5sum functionality from gnulib
1 parent d8dc6db commit ea91962

26 files changed

+3327
-36
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ doc/Clusters_from_Scratch/en-US/Ch-Tools.xml
122122
doc/Clusters_from_Scratch/en-US/Ch-Verification.xml
123123
doc/Pacemaker_Explained/en-US/Ch-Basics.xml
124124
doc/Pacemaker_Explained/en-US/Ch-Options.xml
125-
125+
lib/gnu/libgnu.a
126+
lib/gnu/stdalign.h
126127

127128
#Other
128129
mock

GNUmakefile

+10
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,13 @@ clang:
223223
test -e $(ccc_analyzer) || echo "CLang Analyiser not available. Install the clang-analyzer package"
224224
test -e $(ccc_analyzer) || false
225225
make CC=$(ccc_analyzer) check
226+
227+
# Not available: strlcat
228+
# V3 = scandir unsetenv alphasort
229+
# V2 = setenv strerror strchrnul strndup
230+
# http://www.gnu.org/software/gnulib/manual/html_node/Initial-import.html#Initial-import
231+
GNU_MODS = crypto/md5
232+
gnulib-update:
233+
-test ! -e gnulib && git clone git://git.savannah.gnu.org/gnulib.git
234+
cd gnulib && git pull
235+
gnulib/gnulib-tool --source-base=lib/gnu --lgpl=2 --no-vc-files --import $(GNU_MODS)

Makefile.am

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1919
#
2020

21-
EXTRA_DIST = autogen.sh ConfigureMe README.in libltdl.tar
21+
EXTRA_DIST = autogen.sh ConfigureMe README.in libltdl.tar m4/gnulib-cache.m4
2222

2323
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure DRF/config-h.in \
2424
DRF/stamp-h.in libtool.m4 ltdl.m4 libltdl.tar
@@ -28,8 +28,8 @@ SUBDIRS = $(CORE) cts extra doc
2828

2929
doc_DATA = AUTHORS COPYING COPYING.LIB
3030

31-
AUTOMAKE_OPTIONS = foreign
32-
##ACLOCAL = aclocal -I $(auxdir)
31+
AUTOMAKE_OPTIONS = foreign
32+
ACLOCAL_AMFLAGS = -I m4
3333

3434
core:
3535
@echo "Building only core components: $(CORE)"

configure.ac

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dnl License: GNU General Public License (GPL)
66
dnl ===============================================
77
dnl Bootstrap
88
dnl ===============================================
9-
AC_PREREQ(2.53)
9+
AC_PREREQ(2.59)
1010

1111
dnl Suggested structure:
1212
dnl information on the package
@@ -82,6 +82,8 @@ dnl ========================================================================
8282
AC_PROG_CC dnl Can force other with environment variable "CC".
8383
AM_PROG_CC_C_O
8484
AC_PROG_CC_STDC
85+
gl_EARLY
86+
gl_INIT
8587

8688
AC_LIBTOOL_DLOPEN dnl Enable dlopen support...
8789
AC_LIBLTDL_CONVENIENCE dnl make libltdl a convenience lib
@@ -1690,6 +1692,7 @@ tools/Makefile \
16901692
tools/hb2openais.sh \
16911693
tools/crm_primitive.py \
16921694
xml/Makefile \
1695+
lib/gnu/Makefile \
16931696
)
16941697

16951698
dnl Now process the entire list of files added by previous

include/crm/common/util.h

+2
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,6 @@ extern void *convert_const_pointer(const void *ptr);
371371

372372
extern char *crm_generate_uuid(void);
373373

374+
char *crm_md5sum(const char *buffer);
375+
374376
#endif

lib/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ clean-local:
3939
rm -f *.pc
4040

4141
## Subdirectories...
42-
SUBDIRS = common pengine transition cib fencing cluster plugins
42+
SUBDIRS = gnu common pengine transition cib fencing cluster plugins
4343
DIST_SUBDIRS = $(SUBDIRS) ais
4444

4545
if BUILD_CS_PLUGIN

lib/common/Makefile.am

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
MAINTAINERCLEANFILES = Makefile.in
1919

2020
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
21-
-I$(top_builddir)/libltdl -I$(top_srcdir)/libltdl
21+
-I$(top_builddir)/libltdl -I$(top_srcdir)/libltdl \
22+
-I$(top_builddir)/lib/gnu -I$(top_srcdir)/lib/gnu
2223

2324
## libraries
2425
lib_LTLIBRARIES = libcrmcommon.la
@@ -35,6 +36,7 @@ libcrmcommon_la_SOURCES = ipc.c utils.c xml.c iso8601.c iso8601_fields.c remote.
3536

3637
libcrmcommon_la_LDFLAGS = -version-info 2:0:0
3738
libcrmcommon_la_LIBADD = -ldl $(GNUTLSLIBS)
39+
libcrmcommon_la_SOURCES += $(top_builddir)/lib/gnu/md5.c
3840

3941
if BUILD_HEARTBEAT_SUPPORT
4042
libcrmcommon_la_SOURCES += heartbeat.c

lib/common/utils.c

+19
Original file line numberDiff line numberDiff line change
@@ -2787,3 +2787,22 @@ char *crm_generate_uuid(void)
27872787
uuid_unparse(uuid, buffer);
27882788
return buffer;
27892789
}
2790+
2791+
#include <md5.h>
2792+
2793+
char *
2794+
crm_md5sum(const char *buffer)
2795+
{
2796+
int lpc = 0;
2797+
char *digest = NULL;
2798+
unsigned char raw_digest[MD5_DIGEST_SIZE];
2799+
2800+
digest = malloc(2*MD5_DIGEST_SIZE + 1);
2801+
md5_buffer(buffer, strlen(buffer), raw_digest);
2802+
for(lpc = 0; lpc < MD5_DIGEST_SIZE; lpc++) {
2803+
sprintf(digest+(2*lpc), "%02x", raw_digest[lpc]);
2804+
}
2805+
digest[(2*MD5_DIGEST_SIZE)] = 0;
2806+
crm_trace("Digest %s\n", digest);
2807+
return digest;
2808+
}

lib/common/xml.c

+6-29
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <crm/common/xml.h>
3535
#include <libxml/xmlreader.h>
3636

37-
#include <clplumbing/md5.h>
3837
#if HAVE_BZLIB_H
3938
# include <bzlib.h>
4039
#endif
@@ -1926,13 +1925,9 @@ filter_xml(xmlNode *data, filter_t *filter, int filter_len, gboolean recursive)
19261925
static char *
19271926
calculate_xml_digest_v1(xmlNode *input, gboolean sort, gboolean do_filter)
19281927
{
1929-
int i = 0;
1930-
int digest_len = 16;
19311928
char *digest = NULL;
1932-
unsigned char *raw_digest = NULL;
19331929
xmlNode *copy = NULL;
19341930
char *buffer = NULL;
1935-
size_t buffer_len = 0;
19361931

19371932
if(sort || do_filter) {
19381933
copy = sorted_xml(input, NULL, TRUE);
@@ -1944,34 +1939,24 @@ calculate_xml_digest_v1(xmlNode *input, gboolean sort, gboolean do_filter)
19441939
}
19451940

19461941
buffer = dump_xml(input, FALSE, TRUE);
1947-
buffer_len = strlen(buffer);
1948-
1949-
CRM_CHECK(buffer != NULL && buffer_len > 0, free_xml(copy); crm_free(buffer); return NULL);
1942+
CRM_CHECK(buffer != NULL && strlen(buffer) > 0, free_xml(copy); crm_free(buffer); return NULL);
19501943

1951-
crm_malloc(digest, (2 * digest_len + 1));
1952-
crm_malloc(raw_digest, (digest_len + 1));
1953-
MD5((unsigned char *)buffer, buffer_len, raw_digest);
1954-
for(i = 0; i < digest_len; i++) {
1955-
sprintf(digest+(2*i), "%02x", raw_digest[i]);
1956-
}
1957-
digest[(2*digest_len)] = 0;
1944+
digest = crm_md5sum(buffer);
19581945
crm_trace("Digest %s: %s\n", digest, buffer);
19591946
crm_log_xml_trace(copy, "digest:source");
1947+
19601948
crm_free(buffer);
1961-
crm_free(raw_digest);
19621949
free_xml(copy);
19631950
return digest;
19641951
}
19651952

19661953
static char *
19671954
calculate_xml_digest_v2(xmlNode *input, gboolean do_filter)
19681955
{
1969-
int i = 0;
1970-
int digest_len = 16;
19711956
char *digest = NULL;
1972-
size_t buffer_len = 0;
1957+
1958+
int buffer_len = 0;
19731959
int filter_size = DIMOF(filter);
1974-
unsigned char *raw_digest = NULL;
19751960

19761961
xmlDoc *doc = NULL;
19771962
xmlNode *copy = NULL;
@@ -2019,16 +2004,9 @@ calculate_xml_digest_v2(xmlNode *input, gboolean do_filter)
20192004
CRM_CHECK(doc != NULL, return NULL); /* doc will only be NULL if an_xml_node is */
20202005

20212006
buffer_len = xmlNodeDump(xml_buffer, doc, input, 0, FALSE);
2022-
20232007
CRM_CHECK(xml_buffer->content != NULL && buffer_len > 0, goto done);
20242008

2025-
crm_malloc(digest, (2 * digest_len + 1));
2026-
crm_malloc(raw_digest, (digest_len + 1));
2027-
MD5((unsigned char *)xml_buffer->content, buffer_len, raw_digest);
2028-
for(i = 0; i < digest_len; i++) {
2029-
sprintf(digest+(2*i), "%02x", raw_digest[i]);
2030-
}
2031-
digest[(2*digest_len)] = 0;
2009+
digest = crm_md5sum((char *)xml_buffer->content);
20322010
crm_trace("Digest %s\n", digest);
20332011

20342012
if(digest_cs == NULL) {
@@ -2054,7 +2032,6 @@ calculate_xml_digest_v2(xmlNode *input, gboolean do_filter)
20542032

20552033
done:
20562034
xmlBufferFree(xml_buffer);
2057-
crm_free(raw_digest);
20582035
free_xml(copy);
20592036

20602037
return digest;

lib/gnu/Makefile.am

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
## DO NOT EDIT! GENERATED AUTOMATICALLY!
2+
## Process this file with automake to produce Makefile.in.
3+
# Copyright (C) 2002-2012 Free Software Foundation, Inc.
4+
#
5+
# This file is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This file is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this file. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
# As a special exception to the GNU General Public License,
19+
# this file may be distributed as part of a program that
20+
# contains a configuration script generated by Autoconf, under
21+
# the same distribution terms as the rest of that program.
22+
#
23+
# Generated by gnulib-tool.
24+
# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib/gnu --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --lgpl=2 --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files crypto/md5
25+
26+
AUTOMAKE_OPTIONS = 1.5 gnits
27+
28+
SUBDIRS =
29+
noinst_HEADERS =
30+
noinst_LIBRARIES =
31+
noinst_LTLIBRARIES =
32+
EXTRA_DIST =
33+
BUILT_SOURCES =
34+
SUFFIXES =
35+
MOSTLYCLEANFILES = core *.stackdump
36+
MOSTLYCLEANDIRS =
37+
CLEANFILES =
38+
DISTCLEANFILES =
39+
MAINTAINERCLEANFILES =
40+
41+
AM_CPPFLAGS =
42+
AM_CFLAGS =
43+
44+
noinst_LIBRARIES += libgnu.a
45+
46+
libgnu_a_SOURCES =
47+
libgnu_a_LIBADD = $(gl_LIBOBJS)
48+
libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
49+
EXTRA_libgnu_a_SOURCES =
50+
51+
## begin gnulib module crypto/md5
52+
53+
libgnu_a_SOURCES += md5.c
54+
55+
EXTRA_DIST += md5.h
56+
57+
## end gnulib module crypto/md5
58+
59+
## begin gnulib module stdalign
60+
61+
BUILT_SOURCES += $(STDALIGN_H)
62+
63+
# We need the following in order to create <stdalign.h> when the system
64+
# doesn't have one that works.
65+
if GL_GENERATE_STDALIGN_H
66+
stdalign.h: stdalign.in.h $(top_builddir)/config.status
67+
$(AM_V_GEN)rm -f $@-t $@ && \
68+
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
69+
cat $(srcdir)/stdalign.in.h; \
70+
} > $@-t && \
71+
mv $@-t $@
72+
else
73+
stdalign.h: $(top_builddir)/config.status
74+
rm -f $@
75+
endif
76+
MOSTLYCLEANFILES += stdalign.h stdalign.h-t
77+
78+
EXTRA_DIST += stdalign.in.h
79+
80+
## end gnulib module stdalign
81+
82+
## begin gnulib module stdint
83+
84+
BUILT_SOURCES += $(STDINT_H)
85+
86+
# We need the following in order to create <stdint.h> when the system
87+
# doesn't have one that works with the given compiler.
88+
if GL_GENERATE_STDINT_H
89+
stdint.h: stdint.in.h $(top_builddir)/config.status
90+
$(AM_V_GEN)rm -f $@-t $@ && \
91+
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
92+
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
93+
-e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \
94+
-e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
95+
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
96+
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
97+
-e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \
98+
-e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
99+
-e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
100+
-e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
101+
-e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
102+
-e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
103+
-e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \
104+
-e 's/@''HAVE_UNSIGNED_LONG_LONG_INT''@/$(HAVE_UNSIGNED_LONG_LONG_INT)/g' \
105+
-e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
106+
-e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \
107+
-e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \
108+
-e 's/@''BITSIZEOF_SIG_ATOMIC_T''@/$(BITSIZEOF_SIG_ATOMIC_T)/g' \
109+
-e 's/@''HAVE_SIGNED_SIG_ATOMIC_T''@/$(HAVE_SIGNED_SIG_ATOMIC_T)/g' \
110+
-e 's/@''SIG_ATOMIC_T_SUFFIX''@/$(SIG_ATOMIC_T_SUFFIX)/g' \
111+
-e 's/@''BITSIZEOF_SIZE_T''@/$(BITSIZEOF_SIZE_T)/g' \
112+
-e 's/@''SIZE_T_SUFFIX''@/$(SIZE_T_SUFFIX)/g' \
113+
-e 's/@''BITSIZEOF_WCHAR_T''@/$(BITSIZEOF_WCHAR_T)/g' \
114+
-e 's/@''HAVE_SIGNED_WCHAR_T''@/$(HAVE_SIGNED_WCHAR_T)/g' \
115+
-e 's/@''WCHAR_T_SUFFIX''@/$(WCHAR_T_SUFFIX)/g' \
116+
-e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \
117+
-e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
118+
-e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \
119+
< $(srcdir)/stdint.in.h; \
120+
} > $@-t && \
121+
mv $@-t $@
122+
else
123+
stdint.h: $(top_builddir)/config.status
124+
rm -f $@
125+
endif
126+
MOSTLYCLEANFILES += stdint.h stdint.h-t
127+
128+
EXTRA_DIST += stdint.in.h
129+
130+
## end gnulib module stdint
131+
132+
133+
mostlyclean-local: mostlyclean-generic
134+
@for dir in '' $(MOSTLYCLEANDIRS); do \
135+
if test -n "$$dir" && test -d $$dir; then \
136+
echo "rmdir $$dir"; rmdir $$dir; \
137+
fi; \
138+
done; \
139+
:

0 commit comments

Comments
 (0)