19 #include <gnutls/crypto.h> 20 #include <gnutls/gnutls.h> 26 #define BEST_EFFORT_STATUS 0 61 dump_xml_for_digest(xmlNodePtr xml)
63 GString *buffer = g_string_sized_new(1024);
66 g_string_append_c(buffer,
' ');
68 g_string_append_c(buffer,
'\n');
84 calculate_xml_digest_v1(xmlNode *
input)
86 GString *buffer = dump_xml_for_digest(
input);
91 g_string_free(buffer, TRUE);
94 digest =
crm_md5sum((
const char *) buffer->str);
97 g_string_free(buffer, TRUE);
118 return calculate_xml_digest_v1(
input);
144 digest = calculate_xml_digest_v1(sorted);
166 GString *buf = g_string_sized_new(1024);
186 g_string_free(buf, TRUE);
202 char *calculated = NULL;
207 if (calculated == NULL) {
208 crm_perror(LOG_ERR,
"Could not calculate digest for comparison");
214 crm_trace(
"Digest comparison passed: %s", calculated);
216 crm_err(
"Digest comparison failed: expected %s, calculated %s",
217 expected, calculated);
234 static const char *filter[] = {
243 if (strcmp(
name, filter[i]) == 0) {
254 gchar *raw_digest = NULL;
256 if (buffer == NULL) {
260 raw_digest = g_compute_checksum_for_string(G_CHECKSUM_MD5, buffer, -1);
262 if (raw_digest == NULL) {
263 crm_err(
"Failed to calculate hash");
276 should_filter_for_digest(xmlAttrPtr a,
void *user_data)
278 if (strncmp((
const char *) a->name,
CRM_META "_",
303 guint interval_ms = 0;
305 if (param_set == NULL) {
318 if (interval_ms != 0) {
343 return calculate_xml_digest_v1(
input);
350 char *digest = calculate_xml_digest_v1(sorted);
358 gboolean do_filter,
const char *
version)
361 xmlNode *sorted = NULL;
370 crm_trace(
"Using v1 digest algorithm for %s",
371 pcmk__s(
version,
"unknown feature set"));
373 digest = calculate_xml_digest_v1(
input);
Deprecated Pacemaker XML element API.
#define CRM_CHECK(expr, failure_action)
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
#define pcmk__if_tracing(if_action, else_action)
#define PCMK_XA_UPDATE_ORIGIN
void save_xml_to_file(const xmlNode *xml, const char *desc, const char *filename)
void pcmk__xml_string(const xmlNode *data, uint32_t options, GString *buffer, int depth)
char * calculate_on_disk_digest(xmlNode *input)
char * pcmk__digest_xml(xmlNode *xml, bool filter)
Exclude certain XML attributes (for calculating digests)
#define PCMK_XA_NUM_UPDATES
char * pcmk__digest_operation(xmlNode *input)
void pcmk__xe_sort_attrs(xmlNode *xml)
#define PCMK_XA_CIB_LAST_WRITTEN
#define PCMK__META_ON_NODE
Deprecated Pacemaker XML API.
void pcmk__xml_free(xmlNode *xml)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
void pcmk__filter_op_for_digest(xmlNode *param_set)
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define PCMK__XA_OP_DIGEST
#define crm_trace(fmt, args...)
#define PCMK_XA_UPDATE_USER
#define PCMK__META_ON_NODE_UUID
Wrappers for and extensions to libxml2.
void xmlNode * sorted_xml(xmlNode *input, xmlNode *parent, gboolean recursive)
bool pcmk__xa_filterable(const char *name)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
#define pcmk__str_copy(str)
char * calculate_xml_versioned_digest(xmlNode *input, gboolean sort, gboolean do_filter, const char *version)
#define PCMK_META_TIMEOUT
char * pcmk__digest_on_disk_cib(xmlNode *input)
#define PCMK_XA_CRM_FEATURE_SET
const char * pcmk__get_tmpdir(void)
bool pcmk__verify_digest(xmlNode *input, const char *expected)
#define PCMK_META_INTERVAL
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define crm_err(fmt, args...)
int compare_version(const char *version1, const char *version2)
char * calculate_operation_digest(xmlNode *input, const char *version)
#define crm_log_xml_trace(xml, text)
char * crm_md5sum(const char *buffer)
#define PCMK_XA_ADMIN_EPOCH
#define PCMK_XA_CRM_DEBUG_ORIGIN
#define PCMK_XA_UPDATE_CLIENT
void pcmk__xe_remove_matching_attrs(xmlNode *element, bool(*match)(xmlAttrPtr, void *), void *user_data)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
char * crm_meta_name(const char *field)
Get the environment variable equivalent of a meta-attribute name.