MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / validate_cib_digest

Function validate_cib_digest

cib/io.c:81–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79extern void cib_cleanup(void);
80
81static gboolean
82validate_cib_digest(xmlNode * local_cib, const char *sigfile)
83{
84 char *digest = NULL;
85 char *expected = NULL;
86 gboolean passed = FALSE;
87 FILE *expected_strm = NULL;
88 int start = 0, length = 0, read_len = 0;
89
90 CRM_ASSERT(sigfile != NULL);
91
92 expected_strm = fopen(sigfile, "r");
93 if (expected_strm == NULL && errno == ENOENT) {
94 crm_warn("No on-disk digest present");
95 return TRUE;
96
97 } else if(expected_strm == NULL) {
98 crm_perror(LOG_ERR, "Could not open signature file %s for reading", sigfile);
99 goto bail;
100 }
101
102 if (local_cib != NULL) {
103 digest = calculate_on_disk_digest(local_cib);
104 }
105
106 start = ftell(expected_strm);
107 fseek(expected_strm, 0L, SEEK_END);
108 length = ftell(expected_strm);
109 fseek(expected_strm, 0L, start);
110
111 CRM_ASSERT(length >= 0);
112 CRM_ASSERT(start == ftell(expected_strm));
113
114 if (length > 0) {
115 crm_trace("Reading %d bytes from file", length);
116 expected = calloc(1, (length + 1));
117 read_len = fread(expected, 1, length, expected_strm); /* Coverity: False positive */
118 CRM_ASSERT(read_len == length);
119 }
120 fclose(expected_strm);
121
122 bail:
123 if (expected == NULL) {
124 crm_err("On-disk digest is empty");
125
126 } else if (safe_str_eq(expected, digest)) {
127 crm_trace("Digest comparision passed: %s", digest);
128 passed = TRUE;
129
130 } else {
131 crm_err("Digest comparision failed: expected %s (%s), calculated %s",
132 expected, sigfile, digest);
133 }
134
135 free(digest);
136 free(expected);
137 return passed;
138}

Callers 2

validate_on_disk_cibFunction · 0.85
retrieveCibFunction · 0.85

Calls 1

calculate_on_disk_digestFunction · 0.85

Tested by

no test coverage detected