int main(int argc, char *argv[]) { char *plaintext, *encoded, *decoded; unsigned char *sha_plaintext, *sha_decoded; size_t len; int ret=0; unsigned int shalen; initialize_crypto(); plaintext = (argv[1]) ? argv[1] : "Hello. This is dog"; sha_plaintext = sha256(plaintext, strlen(plaintext), NULL, NULL); if (!(sha_plaintext)) { fprintf(stderr, "Could not generate sha256 of plaintext\n"); return 1; } encoded = base64_encode(plaintext, strlen(plaintext)); if (!(encoded)) { fprintf(stderr, "Could not base64 encode plaintest\n"); return 1; } fprintf(stderr, "Base64 encoded: %s\n", encoded); decoded = base64_decode(encoded, strlen(encoded), NULL, &len); if (!(decoded)) { fprintf(stderr, "Could not base64 decoded string\n"); return 1; } sha_decoded = sha256(decoded, len, NULL, &shalen); if (!(sha_decoded)) { fprintf(stderr, "Could not generate sha256 of decoded data\n"); return 1; } if (memcmp(sha_plaintext, sha_decoded, shalen)) { fprintf(stderr, "Decoded does not match plaintext: %s\n", decoded); ret = 1; } free(sha_decoded); free(sha_plaintext); free(encoded); free(decoded); cleanup_crypto(); return ret; }
/* Cleanup and then exit */ void terminate_dird(int sig) { static bool already_here = false; if (already_here) { /* avoid recursive temination problems */ bmicrosleep(2, 0); /* yield */ exit(1); } already_here = true; debug_level = 0; /* turn off debug */ stop_watchdog(); db_sql_pool_destroy(); db_flush_backends(); unload_dir_plugins(); write_state_file(me->working_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs)); delete_pid_file(me->pid_directory, "bareos-dir", get_first_port_host_order(me->DIRaddrs)); term_scheduler(); term_job_server(); if (runjob) { free(runjob); } if (configfile != NULL) { free(configfile); } if (debug_level > 5) { print_memory_pool_stats(); } if (my_config) { my_config->free_resources(); free(my_config); my_config = NULL; } stop_UA_server(); term_msg(); /* terminate message handler */ cleanup_crypto(); close_memory_pool(); /* release free memory in pool */ lmgr_cleanup_main(); sm_dump(false); exit(sig); }