26 #include <sys/param.h> 27 #include <sys/types.h> 30 #include <sys/utsname.h> 43 #include <qb/qbdefs.h> 56 #include <libxml2/libxml/relaxng.h> 67 # define PW_BUFFER_LEN 500 81 static struct crm_option *crm_long_options = NULL;
82 static const char *crm_app_description = NULL;
83 static char *crm_short_options = NULL;
84 static const char *crm_app_usage = NULL;
99 free(crm_short_options);
191 if(stat(value, &st) != 0) {
192 crm_err(
"Script %s does not exist", value);
196 if(S_ISREG(st.st_mode) == 0) {
197 crm_err(
"Script %s is not a regular file", value);
201 if( (st.st_mode & (S_IXUSR | S_IXGRP )) == 0) {
202 crm_err(
"Script %s is not executable", value);
213 long number = strtol(value, &end, 10);
215 if(end && end[0] !=
'%') {
217 }
else if(number < 0) {
290 const char *name,
const char *old_name,
const char *def_value)
292 const char *value = NULL;
296 if (options != NULL) {
297 value = g_hash_table_lookup(options, name);
300 if (value == NULL && old_name && options != NULL) {
301 value = g_hash_table_lookup(options, old_name);
304 " cluster option '%s'", old_name, name);
305 g_hash_table_insert(options, strdup(name), strdup(value));
306 value = g_hash_table_lookup(options, old_name);
311 crm_trace(
"Using default value '%s' for cluster option '%s'", def_value, name);
313 if (options == NULL) {
316 }
else if(def_value == NULL) {
320 g_hash_table_insert(options, strdup(name), strdup(def_value));
321 value = g_hash_table_lookup(options, name);
324 if (validate && validate(value) == FALSE) {
326 " Defaulting to %s", value, name, def_value);
327 g_hash_table_replace(options, strdup(name), strdup(def_value));
328 value = g_hash_table_lookup(options, name);
338 const char *value = NULL;
339 gboolean found = FALSE;
341 for (lpc = 0; lpc < len; lpc++) {
345 option_list[lpc].is_valid,
346 option_list[lpc].name,
347 option_list[lpc].alt_name, option_list[lpc].default_value);
360 fprintf(stdout,
"<?xml version=\"1.0\"?>" 361 "<!DOCTYPE resource-agent SYSTEM \"ra-api-1.dtd\">\n" 362 "<resource-agent name=\"%s\">\n" 363 " <version>%s</version>\n" 364 " <longdesc lang=\"en\">%s</longdesc>\n" 365 " <shortdesc lang=\"en\">%s</shortdesc>\n" 366 " <parameters>\n", name, version, desc_long, desc_short);
368 for (lpc = 0; lpc < len; lpc++) {
369 if (option_list[lpc].description_long == NULL && option_list[lpc].description_short == NULL) {
372 fprintf(stdout,
" <parameter name=\"%s\" unique=\"0\">\n" 373 " <shortdesc lang=\"en\">%s</shortdesc>\n" 374 " <content type=\"%s\" default=\"%s\"/>\n" 375 " <longdesc lang=\"en\">%s%s%s</longdesc>\n" 377 option_list[lpc].name,
378 option_list[lpc].description_short,
379 option_list[lpc].
type,
380 option_list[lpc].default_value,
381 option_list[lpc].description_long ? option_list[lpc].
382 description_long : option_list[lpc].description_short,
383 option_list[lpc].values ?
" Allowed values: " :
"",
384 option_list[lpc].values ? option_list[lpc].values :
"");
386 fprintf(stdout,
" </parameters>\n</resource-agent>\n");
394 for (lpc = 0; lpc < len; lpc++) {
396 option_list[lpc].is_valid,
397 option_list[lpc].name,
398 option_list[lpc].alt_name, option_list[lpc].default_value);
405 char *hash_key =
crm_concat(sys ? sys :
"none", crm_msg_reference,
'_');
407 crm_trace(
"created hash key: (%s)", hash_key);
418 struct passwd *pwentry = NULL;
425 *uid = pwentry->pw_uid;
428 *gid = pwentry->pw_gid;
430 crm_trace(
"Cluster user %s has uid=%d gid=%d", name, pwentry->pw_uid, pwentry->pw_gid);
433 crm_err(
"Cluster user %s does not exist", name);
441 crm_version_helper(
const char *text,
char **end_text)
443 int atoi_result = -1;
449 if (text != NULL && text[0] != 0) {
450 atoi_result = (int)strtol(text, end_text, 10);
452 if (errno == EINVAL) {
453 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
470 char *ver1_copy = NULL, *ver2_copy = NULL;
471 char *rest1 = NULL, *rest2 = NULL;
473 if (version1 == NULL && version2 == NULL) {
475 }
else if (version1 == NULL) {
477 }
else if (version2 == NULL) {
481 ver1_copy = strdup(version1);
482 ver2_copy = strdup(version2);
492 if (rest1 == rest2) {
497 digit1 = crm_version_helper(rest1, &rest1);
501 digit2 = crm_version_helper(rest2, &rest2);
504 if (digit1 < digit2) {
508 }
else if (digit1 > digit2) {
513 if (rest1 != NULL && rest1[0] ==
'.') {
516 if (rest1 != NULL && rest1[0] == 0) {
520 if (rest2 != NULL && rest2[0] ==
'.') {
523 if (rest2 != NULL && rest2[0] == 0) {
532 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
534 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
536 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
545 # define NUMCHARS "0123456789." 549 # define WHITESPACE " \t\n\r\f" 555 unsigned long long msec = 0;
560 }
else if (input[0] !=
'P') {
580 const char *cp = input;
582 long long multiplier = 1000;
583 long long divisor = 1;
585 char *end_text = NULL;
597 if (strchr(
NUMCHARS, *cp) == NULL) {
601 if (strncasecmp(units,
"ms", 2) == 0 || strncasecmp(units,
"msec", 4) == 0) {
604 }
else if (strncasecmp(units,
"us", 2) == 0 || strncasecmp(units,
"usec", 4) == 0) {
607 }
else if (strncasecmp(units,
"s", 1) == 0 || strncasecmp(units,
"sec", 3) == 0) {
610 }
else if (strncasecmp(units,
"m", 1) == 0 || strncasecmp(units,
"min", 3) == 0) {
611 multiplier = 60 * 1000;
613 }
else if (strncasecmp(units,
"h", 1) == 0 || strncasecmp(units,
"hr", 2) == 0) {
614 multiplier = 60 * 60 * 1000;
616 }
else if (*units !=
EOS && *units !=
'\n' && *units !=
'\r') {
621 if (msec > LLONG_MAX/multiplier) {
641 len += strlen(op_type);
642 len += strlen(rsc_id);
645 sprintf(op_id,
"%s_%s_%d", rsc_id, op_type, interval);
650 parse_op_key(
const char *key,
char **rsc_id,
char **op_type,
int *interval)
653 char *mutable_key = NULL;
654 char *mutable_key_ptr = NULL;
655 int len = 0, offset = 0, ch = 0;
665 while (offset > 0 && isdigit(key[offset])) {
666 int digits = len - offset;
668 ch = key[offset] -
'0';
680 CRM_CHECK(key[offset] ==
'_',
return FALSE);
682 mutable_key = strdup(key);
683 mutable_key[offset] = 0;
686 while (offset > 0 && key[offset] !=
'_') {
690 CRM_CHECK(key[offset] ==
'_', free(mutable_key);
693 mutable_key_ptr = mutable_key + offset + 1;
695 crm_trace(
" Action: %s", mutable_key_ptr);
697 *op_type = strdup(mutable_key_ptr);
699 mutable_key[offset] = 0;
702 CRM_CHECK(mutable_key != mutable_key_ptr, free(mutable_key);
705 notify = strstr(mutable_key,
"_post_notify");
706 if (notify &&
safe_str_eq(notify,
"_post_notify")) {
710 notify = strstr(mutable_key,
"_pre_notify");
711 if (notify &&
safe_str_eq(notify,
"_pre_notify")) {
716 *rsc_id = mutable_key;
729 CRM_CHECK(notify_type != NULL,
return NULL);
731 len += strlen(op_type);
732 len += strlen(rsc_id);
733 len += strlen(notify_type);
738 sprintf(op_id,
"%s_%s_notify_%s_0", rsc_id, notify_type, op_type);
747 char *fail_state = NULL;
749 CRM_CHECK(transition_key != NULL,
return NULL);
751 len += strlen(transition_key);
753 fail_state = malloc(len);
754 if (fail_state != NULL) {
755 snprintf(fail_state, len,
"%d:%s", op_status, transition_key);
764 char *fail_state = NULL;
766 CRM_CHECK(transition_key != NULL,
return NULL);
768 len += strlen(transition_key);
770 fail_state = malloc(len);
771 if (fail_state != NULL) {
772 snprintf(fail_state, len,
"%d:%d;%s", op_status, op_rc, transition_key);
779 int *
op_status,
int *op_rc,
int *target_rc)
783 gboolean result = TRUE;
787 CRM_CHECK(op_status != NULL,
return FALSE);
789 key = calloc(1, strlen(magic) + 1);
790 res = sscanf(magic,
"%d:%d;%s", op_status, op_rc, key);
792 crm_warn(
"Only found %d items in: '%s'", res, magic);
807 char *fail_state = NULL;
813 fail_state = malloc(len);
814 if (fail_state != NULL) {
815 snprintf(fail_state, len,
"%d:%d:%d:%-*s", action_id, transition_id, target_rc, 36, node);
825 gboolean done = FALSE;
828 CRM_CHECK(target_rc != NULL,
return FALSE);
829 CRM_CHECK(action_id != NULL,
return FALSE);
830 CRM_CHECK(transition_id != NULL,
return FALSE);
832 *uuid = calloc(1, 37);
833 res = sscanf(key,
"%d:%d:%d:%36s", action_id, transition_id, target_rc, *uuid);
846 res = sscanf(key,
"%d:%d:%36s", action_id, transition_id, *uuid);
849 res = sscanf(key,
"%d:%36s", transition_id, *uuid);
852 }
else if (res != 3) {
862 res = sscanf(key,
"%d:%36s", transition_id, *uuid);
866 crm_crit(
"Unhandled sscanf result (%d) for %s", res, key);
869 if (strlen(*uuid) != 36) {
870 crm_warn(
"Bad UUID (%s) in sscanf result (%d) for %s", *uuid, res, key);
874 crm_err(
"Cannot decode '%s' rc=%d", key, res);
890 char *timeout = NULL;
891 char *interval = NULL;
893 const char *attr_filter[] = {
899 gboolean do_delete = FALSE;
901 static int meta_len = 0;
907 if (param_set == NULL) {
911 for (lpc = 0; lpc <
DIMOF(attr_filter); lpc++) {
923 xmlAttrPtr xIter = param_set->properties;
926 const char *prop_name = (
const char *)xIter->name;
930 if (strncasecmp(prop_name,
CRM_META, meta_len) == 0) {
942 if (timeout != NULL) {
956 crm_abort(
const char *file,
const char *
function,
int line,
957 const char *assert_condition, gboolean do_core, gboolean do_fork)
966 if(crm_is_daemon == FALSE) {
974 if (do_core == FALSE) {
975 crm_err(
"%s: Triggered assert at %s:%d : %s",
function, file, line, assert_condition);
978 }
else if (do_fork) {
982 crm_err(
"%s: Triggered fatal assert at %s:%d : %s",
function, file, line, assert_condition);
986 crm_crit(
"%s: Cannot create core for non-fatal assert at %s:%d : %s",
987 function, file, line, assert_condition);
990 }
else if(pid == 0) {
997 crm_err(
"%s: Forked child %d to record non-fatal assert at %s:%d : %s",
998 function, pid, file, line, assert_condition);
1002 rc = waitpid(pid, &status, 0);
1007 }
while(errno == EINTR);
1009 if (errno == ECHILD) {
1011 crm_trace(
"Cannot wait on forked child %d - SIGCHLD is probably set to SIG_IGN", pid);
1014 crm_perror(LOG_ERR,
"Cannot wait on forked child %d", pid);
1020 static int have_proc_pid = 0;
1022 if(have_proc_pid == 0) {
1023 char proc_path[PATH_MAX], exe_path[PATH_MAX];
1026 snprintf(proc_path,
sizeof(proc_path),
"/proc/%lu/exe", (
long unsigned int)getpid());
1029 if(readlink(proc_path, exe_path, PATH_MAX - 1) < 0) {
1037 }
else if (kill(pid, 0) < 0 && errno == ESRCH) {
1040 }
else if(daemon == NULL || have_proc_pid == -1) {
1045 char proc_path[PATH_MAX], exe_path[PATH_MAX], myexe_path[PATH_MAX];
1048 snprintf(proc_path,
sizeof(proc_path),
"/proc/%lu/exe", pid);
1050 rc = readlink(proc_path, exe_path, PATH_MAX - 1);
1051 if (rc < 0 && errno == EACCES) {
1052 crm_perror(LOG_INFO,
"Could not read from %s", proc_path);
1054 }
else if (rc < 0) {
1055 crm_perror(LOG_ERR,
"Could not read from %s", proc_path);
1062 if(daemon[0] !=
'/') {
1063 rc = snprintf(myexe_path,
sizeof(proc_path),
CRM_DAEMON_DIR"/%s", daemon);
1066 rc = snprintf(myexe_path,
sizeof(proc_path),
"%s", daemon);
1070 if (strcmp(exe_path, myexe_path) == 0) {
1078 #define LOCKSTRLEN 11 1088 if ((fd = open(filename, O_RDONLY)) < 0) {
1092 if (fstat(fd, &sbuf) >= 0 && sbuf.st_size <
LOCKSTRLEN) {
1098 if (read(fd, buf,
sizeof(buf)) < 1) {
1102 if (sscanf(buf,
"%lu", &pid) > 0) {
1106 crm_trace(
"Got pid %lu from %s\n", pid, filename);
1127 }
else if (mypid && pid == mypid) {
1136 }
else if (mypid && pid != mypid) {
1145 crm_lock_pidfile(
const char *filename,
const char *name)
1151 mypid = (
unsigned long)getpid();
1154 if (rc == -ENOENT) {
1162 if ((fd = open(filename, O_CREAT | O_WRONLY | O_EXCL, 0644)) < 0) {
1167 snprintf(buf,
sizeof(buf),
"%*lu\n",
LOCKSTRLEN - 1, mypid);
1172 crm_perror(LOG_ERR,
"Incomplete write to %s", filename);
1184 const char *devnull =
"/dev/null";
1186 if (daemonize == FALSE) {
1192 if(rc <
pcmk_ok && rc != -ENOENT) {
1194 crm_err(
"%s: already running [pid %ld in %s]", name, pid, pidfile);
1195 printf(
"%s: already running [pid %ld in %s]\n", name, pid, pidfile);
1201 fprintf(stderr,
"%s: could not start daemon\n", name);
1205 }
else if (pid > 0) {
1209 rc = crm_lock_pidfile(pidfile, name);
1212 printf(
"Could not lock '%s' for %s: %s (%d)\n", pidfile, name,
pcmk_strerror(rc), rc);
1216 umask(S_IWGRP | S_IWOTH | S_IROTH);
1218 close(STDIN_FILENO);
1219 (void)open(devnull, O_RDONLY);
1220 close(STDOUT_FILENO);
1221 (void)open(devnull, O_WRONLY);
1222 close(STDERR_FILENO);
1223 (void)open(devnull, O_WRONLY);
1231 char *crm_name = NULL;
1237 max = strlen(crm_name);
1238 for (; lpc < max; lpc++) {
1239 switch (crm_name[lpc]) {
1241 crm_name[lpc] =
'_';
1252 const char *value = NULL;
1256 value = g_hash_table_lookup(hash, key);
1263 static struct option *
1264 crm_create_long_opts(
struct crm_option *long_options)
1266 struct option *long_opts = NULL;
1268 #ifdef HAVE_GETOPT_H 1269 int index = 0, lpc = 0;
1278 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1279 long_opts[index].name =
"__dummmy__";
1280 long_opts[index].has_arg = 0;
1281 long_opts[index].flag = 0;
1282 long_opts[index].val =
'_';
1285 for (lpc = 0; long_options[lpc].
name != NULL; lpc++) {
1286 if (long_options[lpc].name[0] ==
'-') {
1290 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1293 long_opts[index].name = long_options[lpc].
name;
1294 long_opts[index].has_arg = long_options[lpc].
has_arg;
1295 long_opts[index].flag = long_options[lpc].
flag;
1296 long_opts[index].val = long_options[lpc].
val;
1301 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1302 long_opts[index].name = NULL;
1303 long_opts[index].has_arg = 0;
1304 long_opts[index].flag = 0;
1305 long_opts[index].val = 0;
1313 const char *app_desc)
1315 if (short_options) {
1316 crm_short_options = strdup(short_options);
1318 }
else if (long_options) {
1320 int opt_string_len = 0;
1321 char *local_short_options = NULL;
1323 for (lpc = 0; long_options[lpc].
name != NULL; lpc++) {
1324 if (long_options[lpc].val && long_options[lpc].val !=
'-' && long_options[lpc].val < UCHAR_MAX) {
1325 local_short_options = realloc_safe(local_short_options, opt_string_len + 4);
1326 local_short_options[opt_string_len++] = long_options[lpc].
val;
1328 if (long_options[lpc].has_arg == optional_argument) {
1329 local_short_options[opt_string_len++] =
':';
1331 if (long_options[lpc].has_arg >= required_argument) {
1332 local_short_options[opt_string_len++] =
':';
1334 local_short_options[opt_string_len] = 0;
1337 crm_short_options = local_short_options;
1338 crm_trace(
"Generated short option string: '%s'", local_short_options);
1342 crm_long_options = long_options;
1345 crm_app_description = app_desc;
1348 crm_app_usage = app_usage;
1361 #ifdef HAVE_GETOPT_H 1362 static struct option *long_opts = NULL;
1364 if (long_opts == NULL && crm_long_options) {
1365 long_opts = crm_create_long_opts(crm_long_options);
1370 int flag = getopt_long(argc, argv, crm_short_options, long_opts, index);
1374 if (long_opts[*index].val) {
1375 return long_opts[*index].val;
1376 }
else if (longname) {
1377 *longname = long_opts[*index].name;
1379 crm_notice(
"Unhandled option --%s", long_opts[*index].name);
1396 if (crm_short_options) {
1397 return getopt(argc, argv, crm_short_options);
1407 FILE *stream = (exit_code ? stderr : stdout);
1409 if (cmd ==
'v' || cmd ==
'$') {
1411 fprintf(stream,
"Written by Andrew Beekhof\n");
1422 if (crm_app_usage) {
1426 if (crm_long_options) {
1427 fprintf(stream,
"Options:\n");
1428 for (i = 0; crm_long_options[i].
name != NULL; i++) {
1432 fprintf(stream,
"%s\n\n", crm_long_options[i].desc);
1435 fprintf(stream,
"\t#%s\n\n", crm_long_options[i].desc);
1437 }
else if (crm_long_options[i].val ==
'-' && crm_long_options[i].desc) {
1438 fprintf(stream,
"%s\n", crm_long_options[i].desc);
1442 if (crm_long_options[i].val && crm_long_options[i].val <= UCHAR_MAX) {
1443 fprintf(stream,
" -%c,", crm_long_options[i].val);
1447 fprintf(stream,
" --%s%s\t%s\n", crm_long_options[i].name,
1448 crm_long_options[i].has_arg == optional_argument ?
"[=value]" :
1449 crm_long_options[i].has_arg == required_argument ?
"=value" :
"",
1450 crm_long_options[i].desc ? crm_long_options[i].desc :
"");
1454 }
else if (crm_short_options) {
1455 fprintf(stream,
"Usage: %s - %s\n",
crm_system_name, crm_app_description);
1456 for (i = 0; crm_short_options[i] != 0; i++) {
1457 int has_arg = no_argument ;
1459 if (crm_short_options[i + 1] ==
':') {
1460 if (crm_short_options[i + 2] ==
':')
1461 has_arg = optional_argument ;
1463 has_arg = required_argument ;
1466 fprintf(stream,
" -%c %s\n", crm_short_options[i],
1467 has_arg == optional_argument ?
"[value]" :
1468 has_arg == required_argument ?
"{value}" :
"");
1480 qb_ipcs_service_t **ipcs_rw,
1481 qb_ipcs_service_t **ipcs_shm,
1482 struct qb_ipcs_service_handlers *ro_cb,
1483 struct qb_ipcs_service_handlers *rw_cb)
1489 if (*ipcs_ro == NULL || *ipcs_rw == NULL || *ipcs_shm == NULL) {
1490 crm_err(
"Failed to create cib servers: exiting and inhibiting respawn.");
1491 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1497 qb_ipcs_service_t *ipcs_rw,
1498 qb_ipcs_service_t *ipcs_shm)
1500 qb_ipcs_destroy(ipcs_ro);
1501 qb_ipcs_destroy(ipcs_rw);
1502 qb_ipcs_destroy(ipcs_shm);
1516 if (*ipcs == NULL) {
1517 crm_err(
"Failed to create attrd servers: exiting and inhibiting respawn.");
1518 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1528 if (*ipcs == NULL) {
1529 crm_err(
"Failed to create stonith-ng servers: exiting and inhibiting respawn.");
1530 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1537 const char *value,
const char *section,
const char *
set,
const char *dampen,
1538 const char *user_name,
int options)
1542 const char *task = NULL;
1543 const char *name_as = NULL;
1544 const char *display_host = (host ?
host :
"localhost");
1545 const char *display_command = NULL;
1548 static gboolean connected = TRUE;
1552 if (ipc == NULL && local_ipc == NULL) {
1573 if (name == NULL && command ==
'U') {
1590 display_command =
"refresh";
1606 display_command =
"purge";
1610 if (name_as != NULL) {
1633 if (connected == FALSE) {
1634 crm_info(
"Connecting to cluster... %d retries remaining", max);
1641 crm_perror(LOG_INFO,
"Connection to cluster attribute manager failed");
1644 if (ipc != local_ipc) {
1647 }
else if (rc > 0) {
1650 }
else if (rc == -EAGAIN || rc == -EALREADY) {
1668 if (display_command) {
1669 crm_debug(
"Asked attrd to %s %s: %s (%d)",
1672 crm_debug(
"Asked attrd to update %s=%s for %s: %s (%d)",
1678 #define FAKE_TE_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 1687 char *digest = NULL;
1688 xmlNode *args_xml = NULL;
1690 if (op->
params == NULL) {
1704 do_crm_log(level,
"Calculated digest %s for %s (%s). Source: %s\n",
1705 digest,
ID(update), magic, digest_source);
1706 free(digest_source);
1746 if (target_rc != op->
rc) {
1756 int target_rc,
const char * node,
const char * origin,
int level)
1761 char *op_id_additional = NULL;
1762 char *local_user_data = NULL;
1763 const char *exit_reason = NULL;
1765 xmlNode *xml_op = NULL;
1766 const char *task = NULL;
1767 gboolean dc_munges_migrate_ops = (
compare_version(caller_version,
"3.0.3") < 0);
1768 gboolean dc_needs_unique_ops = (
compare_version(caller_version,
"3.0.6") < 0);
1771 do_crm_log(level,
"%s: Updating resource %s after %s op %s (interval=%d)",
1775 crm_trace(
"DC version: %s", caller_version);
1796 }
else if (dc_munges_migrate_ops
1803 if (dc_needs_unique_ops && op->
interval > 0) {
1804 op_id = strdup(key);
1827 op_id = strdup(key);
1835 if (xml_op == NULL) {
1840 crm_debug(
"Generating fake transition key for:" 1841 " %s_%s_%d %d from %s",
1868 crm_trace(
"Timing data (%s_%s_%d): last=%u change=%u exec=%u queue=%u",
1904 append_digest(op, xml_op, caller_version, magic, LOG_DEBUG);
1906 if (op_id_additional) {
1908 op_id = op_id_additional;
1909 op_id_additional = NULL;
1913 if (local_user_data) {
1914 free(local_user_data);
1927 if(user == NULL || strlen(user) == 0) {
1934 }
else if (strcmp(user,
"root") == 0) {
1937 crm_trace(
"acls required for %s", user);
1949 struct passwd *pwent = getpwuid(uid);
1951 if (pwent == NULL) {
1952 crm_perror(LOG_ERR,
"Cannot get password entry of uid: %d", uid);
1956 return strdup(pwent->pw_name);
1964 static const char *effective_user = NULL;
1965 const char *requested_user = NULL;
1966 const char *user = NULL;
1968 if(effective_user == NULL) {
1973 if(requested_user == NULL) {
1977 if (is_privileged(effective_user) == FALSE) {
1979 user = effective_user;
1981 }
else if(peer_user == NULL && requested_user == NULL) {
1983 user = effective_user;
1985 }
else if(peer_user == NULL) {
1987 user = requested_user;
1989 }
else if (is_privileged(peer_user) == FALSE) {
1993 }
else if (requested_user == NULL) {
1999 user = requested_user;
2011 return requested_user;
2018 CRM_CHECK(user != NULL && request != NULL && field != NULL,
return);
2021 if (is_privileged(user) == FALSE) {
2042 if (*handle == NULL) {
2043 *handle = dlopen(lib, RTLD_LAZY);
2047 crm_err(
"%sCould not open %s: %s", fatal ?
"Fatal: " :
"", lib, dlerror());
2054 a_function = dlsym(*handle, fn);
2055 if (a_function == NULL) {
2057 crm_err(
"%sCould not find %s in %s: %s", fatal ?
"Fatal: " :
"", fn, lib, error);
2073 #ifdef HAVE_UUID_UUID_H 2074 # include <uuid/uuid.h> 2080 unsigned char uuid[16];
2081 char *buffer = malloc(37);
2083 uuid_generate(uuid);
2084 uuid_unparse(uuid, buffer);
2093 int lpc = 0, len = 0;
2094 char *digest = NULL;
2097 if (buffer == NULL) {
2100 len = strlen(buffer);
2102 crm_trace(
"Beginning digest of %d bytes", len);
2107 sprintf(digest + (2 * lpc),
"%02x", raw_digest[lpc]);
2113 crm_err(
"Could not create digest");
2118 #ifdef HAVE_GNUTLS_GNUTLS_H 2120 crm_gnutls_global_init(
void)
2122 signal(SIGPIPE, SIG_IGN);
2123 gnutls_global_init();
#define CRM_CHECK(expr, failure_action)
#define XML_RSC_OP_LAST_CHANGE
void * find_library_function(void **handle, const char *lib, const char *fn, gboolean fatal)
void verify_all_options(GHashTable *options, pe_cluster_option *option_list, int len)
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval)
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite)
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
long long crm_get_msec(const char *input)
int crm_get_option_long(int argc, char **argv, int *index, const char **longname)
#define crm_notice(fmt, args...)
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
#define CRMD_ACTION_MIGRATED
int attrd_update_delegate(crm_ipc_t *ipc, char command, const char *host, const char *name, const char *value, const char *section, const char *set, const char *dampen, const char *user_name, int options)
void crm_enable_stderr(int enable)
void * convert_const_pointer(const void *ptr)
#define crm_crit(fmt, args...)
gboolean check_utilization(const char *value)
const char * crm_meta_value(GHashTable *hash, const char *field)
#define XML_ATTR_TRANSITION_MAGIC
void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro, qb_ipcs_service_t *ipcs_rw, qb_ipcs_service_t *ipcs_shm)
void attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
struct crm_time_s crm_time_t
const char * pcmk_strerror(int rc)
gboolean check_time(const char *value)
#define crm_config_err(fmt...)
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
void crm_xml_cleanup(void)
gboolean decode_transition_key(const char *key, char **uuid, int *transition_id, int *action_id, int *target_rc)
long long crm_int_helper(const char *text, char **end_text)
#define CRMD_ACTION_NOTIFY
void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro, qb_ipcs_service_t **ipcs_rw, qb_ipcs_service_t **ipcs_shm, struct qb_ipcs_service_handlers *ro_cb, struct qb_ipcs_service_handlers *rw_cb)
char * crm_md5sum(const char *buffer)
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
#define XML_RSC_OP_T_EXEC
char * generate_transition_key(int transition_id, int action_id, int target_rc, const char *node)
#define XML_LRM_ATTR_INTERVAL
gboolean crm_config_warning
int crm_help(char cmd, int exit_code)
#define XML_LRM_ATTR_OP_DIGEST
void mainloop_cleanup(void)
int crm_parse_int(const char *text, const char *default_text)
char * crm_element_value_copy(xmlNode *data, const char *name)
crm_time_t * crm_time_parse_duration(const char *duration_str)
#define CRM_LOG_ASSERT(expr)
void crm_set_options(const char *short_options, const char *app_usage, struct crm_option *long_options, const char *app_desc)
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
#define XML_RSC_OP_T_QUEUE
#define XML_CIB_TAG_NODES
#define PACEMAKER_VERSION
#define attrd_opt_private
Wrappers for and extensions to glib mainloop.
void config_metadata(const char *name, const char *version, const char *desc_short, const char *desc_long, pe_cluster_option *option_list, int len)
long crm_read_pidfile(const char *filename)
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
#define ATTRD_OP_PEER_REMOVE
bool pcmk_acl_required(const char *user)
void stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
#define CRMD_ACTION_START
xmlNode * create_operation_update(xmlNode *parent, lrmd_event_data_t *op, const char *caller_version, int target_rc, const char *node, const char *origin, int level)
char * crm_meta_name(const char *field)
gboolean check_quorum(const char *value)
#define XML_LRM_ATTR_TASK_KEY
#define XML_LRM_ATTR_TASK
void hash2field(gpointer key, gpointer value, gpointer user_data)
char * calculate_operation_digest(xmlNode *local_cib, const char *version)
Calculate and return digest of XML operation.
#define crm_warn(fmt, args...)
int crm_pid_active(long pid, const char *daemon)
int daemon(int nochdir, int noclose)
#define F_ATTRD_ATTRIBUTE
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
#define ATTRD_OP_UPDATE_BOTH
#define crm_debug(fmt, args...)
void determine_request_user(const char *user, xmlNode *request, const char *field)
struct crm_ipc_s crm_ipc_t
#define F_ATTRD_IS_PRIVATE
char * score2char(int score)
#define pcmk_option_example
unsigned long long crm_get_interval(const char *input)
gboolean did_rsc_op_fail(lrmd_event_data_t *op, int target_rc)
#define crm_trace(fmt, args...)
#define do_crm_log(level, fmt, args...)
Log a message.
const char * cluster_option(GHashTable *options, gboolean(*validate)(const char *), const char *name, const char *old_name, const char *def_value)
#define pcmk_option_paragraph
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
const char * crm_element_value(xmlNode *data, const char *name)
#define F_ATTRD_IS_REMOTE
#define XML_LRM_ATTR_MIGRATE_TARGET
char * crm_generate_uuid(void)
#define XML_LRM_ATTR_EXIT_REASON
void free_xml(xmlNode *child)
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
char * crm_itoa_stack(int an_int, char *buf, size_t len)
void filter_action_parameters(xmlNode *param_set, const char *version)
CRM_TRACE_INIT_DATA(common)
gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
long long int crm_time_get_seconds(crm_time_t *dt)
#define DAEMON_RESPAWN_STOP
int compare_version(const char *version1, const char *version2)
gboolean check_script(const char *value)
#define crm_config_warn(fmt...)
#define XML_ATTR_TRANSITION_KEY
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
unsigned int get_crm_log_level(void)
int crm_str_to_boolean(const char *s, int *ret)
void crm_abort(const char *file, const char *function, int line, const char *assert_condition, gboolean do_core, gboolean do_fork)
char * generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
gboolean check_timer(const char *value)
long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon)
#define crm_perror(level, fmt, args...)
Log a system error message.
char * generate_transition_magic_v202(const char *transition_key, int op_status)
int char2score(const char *score)
#define crm_err(fmt, args...)
int crm_ipc_send(crm_ipc_t *client, xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
gboolean check_number(const char *value)
void xml_remove_prop(xmlNode *obj, const char *name)
int rsc_op_expected_rc(lrmd_event_data_t *op)
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
char * dump_xml_unformatted(xmlNode *msg)
#define XML_LRM_ATTR_CALLID
#define CRMD_ACTION_MIGRATE
#define XML_LRM_ATTR_OPSTATUS
#define XML_ATTR_CRM_VERSION
#define pcmk_option_hidden
int crm_get_option(int argc, char **argv, int *index)
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
void * md5_buffer(const char *buffer, size_t len, void *resblock)
Wrappers for and extensions to libqb IPC.
#define PACKAGE_BUGREPORT
#define XML_CIB_TAG_STATUS
char * generate_transition_magic(const char *transition_key, int op_status, int op_rc)
const char * crm_acl_get_set_user(xmlNode *request, const char *field, const char *peer_user)
gboolean crm_config_error
#define XML_LRM_ATTR_TARGET
#define XML_LRM_TAG_RSC_OP
#define XML_RSC_OP_LAST_RUN
char * crm_concat(const char *prefix, const char *suffix, char join)
char * crm_itoa(int an_int)
#define safe_str_eq(a, b)
qb_ipcs_service_t * mainloop_add_ipc_server(const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks)
#define XML_LRM_ATTR_MIGRATE_SOURCE
gboolean check_boolean(const char *value)
void crm_ipc_close(crm_ipc_t *client)
#define ATTRD_OP_UPDATE_DELAY
#define crm_info(fmt, args...)
char * uid2username(uid_t uid)
char * score2char_stack(int score, char *buf, size_t len)
qb_ipcs_service_t * crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb)
enum crm_ais_msg_types type
#define CRMD_ACTION_STATUS
void crm_time_free(crm_time_t *dt)