198
196
/* Find the "CMAN" logger_subsys object. Or create one if it does not
201
static unsigned int find_cman_logger(struct objdb_iface_ver0 *objdb, unsigned int object_handle)
199
static hdb_handle_t find_cman_logger(struct objdb_iface_ver0 *objdb, hdb_handle_t object_handle)
203
unsigned int subsys_handle;
204
unsigned int find_handle;
201
hdb_handle_t subsys_handle;
202
hdb_handle_t find_handle;
207
205
objdb->object_find_create(object_handle, "logger_subsys", strlen("logger_subsys"), &find_handle);
208
while (!objdb->object_find_next(object_handle, &subsys_handle)) {
210
if (objdb_get_string(objdb, subsys_handle, "subsys", &str)) {
206
while (!objdb->object_find_next(find_handle, &subsys_handle)) {
207
if (!objdb_get_string(objdb, subsys_handle, "subsys", &str)) {
208
if (strncmp(str, CMAN_NAME, 4) == 0) {
209
objdb->object_find_destroy(find_handle);
210
return subsys_handle;
213
if (strcmp(str, CMAN_NAME) == 0)
214
return subsys_handle;
216
214
objdb->object_find_destroy(find_handle);
218
/* We can't find it ... create one */
219
if (objdb->object_create(object_handle, &subsys_handle,
220
"logger_subsys", strlen("logger_subsys")) == 0) {
222
objdb->object_key_create(subsys_handle, "subsys", strlen("subsys"),
223
CMAN_NAME, strlen(CMAN_NAME)+1);
226
return subsys_handle;
231
static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr, int portnum)
221
static int add_ifaddr(struct objdb_iface_ver0 *objdb, char *mcast, char *ifaddr, int port, int broadcast)
233
unsigned int totem_object_handle;
234
unsigned int find_handle;
235
unsigned int interface_object_handle;
223
hdb_handle_t totem_object_handle;
224
hdb_handle_t find_handle;
225
hdb_handle_t interface_object_handle;
236
226
struct sockaddr_storage if_addr, localhost, mcast_addr;
325
319
freeaddrinfo(ainfo);
327
321
if (family == AF_INET) {
328
snprintf(addr, sizeof(addr), "239.192.%d.%d", cluster_id >> 8, cluster_id % 0xFF);
322
snprintf(addr, sizeof(addr), "239.192.%d.%d", clusterid >> 8, clusterid % 0xFF);
331
325
if (family == AF_INET6) {
332
snprintf(addr, sizeof(addr), "ff15::%x", cluster_id);
326
snprintf(addr, sizeof(addr), "ff15::%x", clusterid);
339
static int verify_nodename(struct objdb_iface_ver0 *objdb, char *nodename)
333
static int verify_nodename(struct objdb_iface_ver0 *objdb, char *node)
341
335
char nodename2[MAX_CLUSTER_MEMBER_NAME_LEN+1];
342
336
char nodename3[MAX_CLUSTER_MEMBER_NAME_LEN+1];
343
337
char *str, *dot = NULL;
344
338
struct ifaddrs *ifa, *ifa_list;
345
339
struct sockaddr *sa;
346
unsigned int nodes_handle;
347
unsigned int find_handle = 0;
340
hdb_handle_t nodes_handle;
341
hdb_handle_t find_handle = 0;
350
344
/* nodename is either from commandline or from uname */
351
if (nodelist_byname(objdb, cluster_parent_handle, nodename))
345
if (nodelist_byname(objdb, cluster_parent_handle, node))
354
348
/* If nodename was from uname, try a domain-less version of it */
355
strcpy(nodename2, nodename);
349
strcpy(nodename2, node);
356
350
dot = strchr(nodename2, '.');
360
354
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
361
strcpy(nodename, nodename2);
355
strcpy(node, nodename2);
402
396
for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
403
399
/* Restore this */
404
strcpy(nodename2, nodename);
400
strcpy(nodename2, node);
405
401
sa = ifa->ifa_addr;
406
if (!sa || sa->sa_family != AF_INET)
409
error = getnameinfo(sa, sizeof(*sa), nodename2,
404
if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6)
407
if (sa->sa_family == AF_INET)
408
salen = sizeof(struct sockaddr_in);
409
if (sa->sa_family == AF_INET6)
410
salen = sizeof(struct sockaddr_in6);
412
error = getnameinfo(sa, salen, nodename2,
410
413
sizeof(nodename2), NULL, 0, 0);
414
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
415
strcpy(nodename, nodename2);
419
/* truncate this name and try again */
421
dot = strchr(nodename2, '.');
426
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
427
strcpy(nodename, nodename2);
416
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
417
strcpy(node, nodename2);
421
/* Truncate this name and try again */
422
dot = strchr(nodename2, '.');
426
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
427
strcpy(node, nodename2);
431
433
/* See if it's the IP address that's in cluster.conf */
432
434
error = getnameinfo(sa, sizeof(*sa), nodename2,
433
435
sizeof(nodename2), NULL, 0, NI_NUMERICHOST);
437
439
if (nodelist_byname(objdb, cluster_parent_handle, nodename2)) {
438
strcpy(nodename, nodename2);
440
strcpy(node, nodename2);
603
614
objdb_get_int(objdb, object_handle, "port", &portnum, DEFAULT_PORT);
606
if (add_ifaddr(objdb, mcast_name, nodename, portnum))
617
/* Check for broadcast */
618
if (!objdb_get_string(objdb, object_handle, "broadcast", &str)) {
619
if (strcmp(str, "yes") == 0) {
620
mcast_name = strdup("255.255.255.255");
628
if (add_ifaddr(objdb, mcast_name, nodename, portnum, broadcast)) {
629
write_cman_pipe(error_reason);
609
633
/* Get all alternative node names */
610
634
num_nodenames = 1;
611
635
objdb->object_find_create(node_object_handle,"altname", strlen("altname"), &find_handle);
612
636
while (objdb->object_find_next(find_handle, &alt_object) == 0) {
613
637
unsigned int port;
617
if (objdb_get_string(objdb, alt_object, "name", &nodename)) {
641
if (objdb_get_string(objdb, alt_object, "name", &node)) {
739
765
objdb->object_find_destroy(find_handle);
741
767
logfacility = facility_name_get(SYSLOGFACILITY);
743
logger_object_handle = find_cman_logger(objdb, object_handle);
768
loglevel = priority_name_get(SYSLOGLEVEL);
770
/* enable timestamps on logging */
771
if (objdb_get_string(objdb, object_handle, "timestamp", &logstr)) {
772
objdb->object_key_create(object_handle, "timestamp", strlen("timestamp"),
773
"on", strlen("on")+1);
776
/* configure logfile */
777
if (objdb_get_string(objdb, object_handle, "to_logfile", &logstr)) {
778
objdb->object_key_create(object_handle, "to_logfile", strlen("to_logfile"),
779
"yes", strlen("yes")+1);
782
if (objdb_get_string(objdb, object_handle, "logfile", &logstr)) {
783
objdb->object_key_create(object_handle, "logfile", strlen("logfile"),
784
LOGDIR "/corosync.log", strlen(LOGDIR "/corosync.log")+1);
787
if (objdb_get_string(objdb, object_handle, "logfile_priority", &logstr)) {
788
objdb->object_key_create(object_handle, "logfile_priority", strlen("logfile_priority"),
789
loglevel, strlen(loglevel)+1);
793
if (objdb_get_string(objdb, object_handle, "to_syslog", &logstr)) {
794
objdb->object_key_create(object_handle, "to_syslog", strlen("to_syslog"),
795
"yes", strlen("yes")+1);
745
798
if (objdb_get_string(objdb, object_handle, "syslog_facility", &logstr)) {
746
799
objdb->object_key_create(object_handle, "syslog_facility", strlen("syslog_facility"),
747
800
logfacility, strlen(logfacility)+1);
750
if (objdb_get_string(objdb, object_handle, "to_file", &logstr)) {
751
objdb->object_key_create(object_handle, "to_file", strlen("to_file"),
752
"yes", strlen("yes")+1);
755
if (objdb_get_string(objdb, object_handle, "logfile", &logstr)) {
756
objdb->object_key_create(object_handle, "logfile", strlen("logfile"),
757
LOGDIR "/cman.log", strlen(LOGDIR "/cman.log")+1);
803
if (objdb_get_string(objdb, object_handle, "syslog_priority", &logstr)) {
804
objdb->object_key_create(object_handle, "syslog_priority", strlen("syslog_priority"),
805
loglevel, strlen(loglevel)+1);
809
hdb_handle_t logger_object_handle;
811
if (!objdb_get_string(objdb, object_handle, "debug", &logstr)) {
812
if (!strncmp(logstr, "on", 2)) {
817
logger_object_handle = find_cman_logger(objdb, object_handle);
818
if (logger_object_handle > -1) {
819
if (!objdb_get_string(objdb, logger_object_handle, "debug", &logstr)) {
820
if (!strncmp(logstr, "on", 2)) {
823
if (!strncmp(logstr, "off", 3)) {
761
831
objdb->object_key_create(object_handle, "to_stderr", strlen("to_stderr"),
762
832
"yes", strlen("yes")+1);
763
objdb->object_key_create(logger_object_handle, "debug", strlen("debug"),
764
"on", strlen("on")+1);
765
objdb->object_key_create(logger_object_handle, "syslog_level", strlen("syslog_level"),
766
"debug", strlen("debug")+1);
771
loglevel = priority_name_get(SYSLOGLEVEL);
772
objdb->object_key_create(logger_object_handle, "syslog_level", strlen("syslog_level"),
773
loglevel, strlen(loglevel)+1);
777
/* Don't run under user "ais" */
835
/* Make sure we allow connections from user/group "ais" */
778
836
objdb->object_find_create(OBJECT_PARENT_HANDLE, "aisexec", strlen("aisexec"), &find_handle);
779
837
if (objdb->object_find_next(find_handle, &object_handle) != 0) {
780
838
objdb->object_create(OBJECT_PARENT_HANDLE, &object_handle,
781
839
"aisexec", strlen("aisexec"));
784
841
objdb->object_find_destroy(find_handle);
785
842
objdb->object_key_create(object_handle, "user", strlen("user"),
786
"root", strlen("root") + 1);
843
"ais", strlen("ais") + 1);
787
844
objdb->object_key_create(object_handle, "group", strlen("group"),
788
"root", strlen("root") + 1);
845
"ais", strlen("ais") + 1);
790
847
objdb->object_find_create(cluster_parent_handle, "cman", strlen("cman"), &find_handle);
791
848
if (objdb->object_find_next(find_handle, &object_handle) == 0)
950
1013
/* Move an object/key tree */
951
static int copy_config_tree(struct objdb_iface_ver0 *objdb, unsigned int source_object, unsigned int target_parent_object, int always_create)
1014
static int copy_config_tree(struct objdb_iface_ver0 *objdb, hdb_handle_t source_object, hdb_handle_t target_parent_object, int always_create)
953
unsigned int object_handle;
954
unsigned int new_object;
955
unsigned int find_handle;
1016
hdb_handle_t object_handle;
1017
hdb_handle_t new_object;
1018
hdb_handle_t find_handle;
956
1019
char object_name[1024];
1020
size_t object_name_len;
1022
size_t key_name_len;
960
1023
void *key_value;
1024
size_t key_value_len;
964
1027
/* Create new parent object if necessary */
965
1028
objdb->object_name_get(source_object, object_name, &object_name_len);
967
1030
objdb->object_find_create(target_parent_object, object_name, strlen(object_name), &find_handle);
968
if (always_create || objdb->object_find_next(find_handle, &object_handle))
1031
if (always_create || objdb->object_find_next(find_handle, &new_object))
969
1032
objdb->object_create(target_parent_object, &new_object, object_name, object_name_len);
970
1033
objdb->object_find_destroy(find_handle);
1102
static int cmanpre_readconfig(struct objdb_iface_ver0 *objdb, char **error_string)
1166
static hdb_handle_t find_or_create_object(struct objdb_iface_ver0 *objdb, const char *name, hdb_handle_t parent_handle)
1168
hdb_handle_t find_handle;
1169
hdb_handle_t ret_handle = 0;
1171
objdb->object_find_create(parent_handle, name, strlen(name), &find_handle);
1172
objdb->object_find_next(find_handle, &ret_handle);
1173
objdb->object_find_destroy(find_handle);
1176
objdb->object_create(parent_handle, &ret_handle, name, strlen(name));
1182
static const char *groupd_compat="groupd_compat";
1183
static const char *clvmd_interface="interface";
1184
static const char *cman_disallowed="disallowed";
1185
static const char *totem_crypto="crypto_accept";
1194
static void setup_old_compat(struct objdb_iface_ver0 *objdb, hdb_handle_t cluster_handle)
1196
hdb_handle_t groupd_handle;
1197
hdb_handle_t clvmd_handle;
1198
hdb_handle_t cman_handle;
1199
hdb_handle_t totem_handle;
1202
/* Set groupd to backwards compatibility mode */
1203
groupd_handle = find_or_create_object(objdb, "group", cluster_handle);
1204
if (objdb->object_key_get(groupd_handle, groupd_compat, strlen(groupd_compat),
1205
(void *)&value, NULL) ||
1207
objdb->object_key_create(groupd_handle, groupd_compat, strlen(groupd_compat),
1211
/* Make clvmd use cman */
1212
clvmd_handle = find_or_create_object(objdb, "clvmd", cluster_handle);
1213
if (objdb->object_key_get(clvmd_handle, clvmd_interface, strlen(clvmd_interface),
1214
(void *)&value, NULL) ||
1216
objdb->object_key_create(clvmd_handle, clvmd_interface, strlen(clvmd_interface),
1220
/* Make cman use disallowed mode */
1221
cman_handle = find_or_create_object(objdb, "cman", cluster_handle);
1222
if (objdb->object_key_get(cman_handle, cman_disallowed, strlen(cman_disallowed),
1223
(void *)&value, NULL) ||
1225
objdb->object_key_create(cman_handle, cman_disallowed, strlen(cman_disallowed),
1229
/* Make totem use the old communications method */
1230
totem_handle = find_or_create_object(objdb, "totem", OBJECT_PARENT_HANDLE);
1231
if (objdb->object_key_get(totem_handle, totem_crypto, strlen(totem_crypto),
1232
(void *)&value, NULL) ||
1234
objdb->object_key_create(totem_handle, totem_crypto, strlen(totem_crypto),
1239
static int cmanpre_readconfig(struct objdb_iface_ver0 *objdb, const char **error_string)
1105
unsigned int object_handle;
1106
unsigned int find_handle;
1242
hdb_handle_t object_handle;
1243
hdb_handle_t find_handle;
1108
1246
if (getenv("CMAN_PIPE"))
1109
1247
startup_pipe = atoi(getenv("CMAN_PIPE"));