17 #include <sys/types.h> 
   26 static int do_replace_secret_params(
char *rsc_id, GHashTable *params, gboolean from_legacy_dir);
 
   27 static int is_magic_value(
char *p);
 
   28 static int check_md5_hash(
char *hash, 
char *value);
 
   29 static void add_secret_params(gpointer key, gpointer value, gpointer user_data);
 
   30 static char *read_local_file(
char *local_file);
 
   32 #define MAX_VALUE_LEN 255 
   33 #define MAGIC "lrm://" 
   36 is_magic_value(
char *p)
 
   38     return !strcmp(p, 
MAGIC);
 
   42 check_md5_hash(
char *hash, 
char *value)
 
   48     crm_debug(
"hash: %s, calculated hash: %s", hash, hash2);
 
   58 read_local_file(
char *local_file)
 
   60     FILE *fp = fopen(local_file, 
"r");
 
   65         if (errno != ENOENT) {
 
   66             crm_perror(LOG_ERR, 
"cannot open %s" , local_file);
 
   72         crm_perror(LOG_ERR, 
"cannot read %s", local_file);
 
   77     for (p = buf+strlen(buf)-1; p >= buf && isspace(*p); p--)
 
   91     if (do_replace_secret_params(rsc_id, params, FALSE) < 0
 
   92         && do_replace_secret_params(rsc_id, params, TRUE) < 0) {
 
  100 do_replace_secret_params(
char *rsc_id, GHashTable *params, gboolean from_legacy_dir)
 
  102     char local_file[FILENAME_MAX+1], *start_pname;
 
  103     char hash_file[FILENAME_MAX+1], *hash;
 
  104     GList *secret_params = NULL, *l;
 
  105     char *key, *pvalue, *secret_value;
 
  107     const char *dir_prefix = NULL;
 
  109     if (params == NULL) {
 
  113     if (from_legacy_dir) {
 
  114         dir_prefix = LRM_LEGACY_CIBSECRETS_DIR;
 
  117         dir_prefix = LRM_CIBSECRETS_DIR;
 
  124     g_hash_table_foreach(params, add_secret_params, &secret_params);
 
  125     if (!secret_params) { 
 
  129     crm_debug(
"replace secret parameters for resource %s", rsc_id);
 
  131     if (snprintf(local_file, FILENAME_MAX,
 
  132         "%s/%s/", dir_prefix, rsc_id) > FILENAME_MAX) {
 
  133         crm_err(
"filename size exceeded for resource %s", rsc_id);
 
  136     start_pname = local_file + strlen(local_file);
 
  138     for (l = g_list_first(secret_params); l; l = g_list_next(l)) {
 
  139         key = (
char *)(l->data);
 
  140         pvalue = g_hash_table_lookup(params, key);
 
  142             crm_err(
"odd, no parameter %s for rsc %s found now", key, rsc_id);
 
  146         if ((strlen(key) + strlen(local_file)) >= FILENAME_MAX-2) {
 
  147             crm_err(
"%d: parameter name %s too big", key);
 
  152         strcpy(start_pname, key);
 
  153         secret_value = read_local_file(local_file);
 
  155             if (from_legacy_dir == FALSE) {
 
  156                 crm_debug(
"secret for rsc %s parameter %s not found in %s. " 
  157                           "will try "LRM_LEGACY_CIBSECRETS_DIR, rsc_id, key, dir_prefix);
 
  160                 crm_err(
"secret for rsc %s parameter %s not found in %s",
 
  161                         rsc_id, key, dir_prefix);
 
  167         strcpy(hash_file, local_file);
 
  168         if (strlen(hash_file) + 5 > FILENAME_MAX) {
 
  169             crm_err(
"cannot build such a long name " 
  170                     "for the sign file: %s.sign", hash_file);
 
  176             strncat(hash_file, 
".sign", 5);
 
  177             hash = read_local_file(hash_file);
 
  179                 crm_err(
"md5 sum for rsc %s parameter %s " 
  180                         "cannot be read from %s", rsc_id, key, hash_file);
 
  185             } 
else if (!check_md5_hash(hash, secret_value)) {
 
  186                 crm_err(
"md5 sum for rsc %s parameter %s " 
  187                         "does not match", rsc_id, key);
 
  195         g_hash_table_replace(params, strdup(key), secret_value);
 
  197     g_list_free(secret_params);
 
  202 add_secret_params(gpointer key, gpointer value, gpointer user_data)
 
  204     GList **lp = (GList **)user_data;
 
  206     if (is_magic_value((
char *)value)) {
 
  207     *lp = g_list_append(*lp, (
char *)key);
 
int replace_secret_params(char *rsc_id, GHashTable *params)
 
#define crm_debug(fmt, args...)
 
#define crm_perror(level, fmt, args...)
Log a system error message. 
 
#define crm_err(fmt, args...)
 
char * crm_md5sum(const char *buffer)
 
#define safe_str_eq(a, b)