extras.c   extras.c 
skipping to change at line 41 skipping to change at line 41
char path[256]; char path[256];
char host_only[128]; char host_only[128];
char *str; char *str;
char *p; char *p;
int error; int error;
int ret; int ret;
unsigned int i; unsigned int i;
size_t nodename_len; size_t nodename_len;
struct addrinfo hints; struct addrinfo hints;
if (nodename == NULL) if (nodename == NULL) {
return (-1); errno = EINVAL;
return -1;
}
nodename_len = strlen(nodename); nodename_len = strlen(nodename);
ret = snprintf(path, sizeof(path), ret = snprintf(path, sizeof(path),
"/cluster/clusternodes/clusternode[@name=\"%s\"]/@nam e", "/cluster/clusternodes/clusternode[@name=\"%s\"]/@nam e",
nodename); nodename);
if (ret < 0 || (size_t) ret >= sizeof(path)) { if (ret < 0 || (size_t) ret >= sizeof(path)) {
errno = E2BIG; errno = E2BIG;
return (-E2BIG); return -1;
} }
str = NULL; str = NULL;
error = ccs_get(cd, path, &str); error = ccs_get(cd, path, &str);
if (!error) { if (!error) {
*retval = str; *retval = str;
return (0); return 0;
} }
if (nodename_len >= sizeof(host_only)) { if (nodename_len >= sizeof(host_only)) {
errno = E2BIG; errno = E2BIG;
return (-E2BIG); return -1;
} }
/* Try just the hostname */ /* Try just the hostname */
strcpy(host_only, nodename); strncpy(host_only, nodename, sizeof(host_only) - 1);
p = strchr(host_only, '.'); p = strchr(host_only, '.');
if (p != NULL) { if (p != NULL) {
*p = '\0'; *p = '\0';
ret = snprintf(path, sizeof(path), ret = snprintf(path, sizeof(path),
"/cluster/clusternodes/clusternode[@name=\"%s \"]/@name", "/cluster/clusternodes/clusternode[@name=\"%s \"]/@name",
host_only); host_only);
if (ret < 0 || (size_t) ret >= sizeof(path)) if (ret < 0 || (size_t) ret >= sizeof(path)) {
return (-E2BIG); errno = E2BIG;
return -1;
}
str = NULL; str = NULL;
error = ccs_get(cd, path, &str); error = ccs_get(cd, path, &str);
if (!error) { if (!error) {
*retval = str; *retval = str;
return (0); return 0;
} }
} }
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
if (strchr(nodename, ':') != NULL) if (strchr(nodename, ':') != NULL)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
else if (isdigit(nodename[nodename_len - 1])) else if (isdigit(nodename[nodename_len - 1]))
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
else else
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
skipping to change at line 131 skipping to change at line 135
if (error || !str) { if (error || !str) {
if (altcnt == 0) if (altcnt == 0)
goto out_fail; goto out_fail;
break; break;
} }
if (altcnt == 0) { if (altcnt == 0) {
if (strlen(str) >= sizeof(canonical_name)) { if (strlen(str) >= sizeof(canonical_name)) {
free(str); free(str);
errno = E2BIG; errno = E2BIG;
return (-E2BIG); return -1;
} }
strcpy(canonical_name, str); strncpy(canonical_name, str, sizeof(canonica l_name) - 1);
} }
if (strlen(str) >= sizeof(cur_node)) { if (strlen(str) >= sizeof(cur_node)) {
free(str); free(str);
errno = E2BIG; errno = E2BIG;
return (-E2BIG); return -1;
} }
strcpy(cur_node, str); strncpy(cur_node, str, sizeof(cur_node) - 1);
p = strchr(cur_node, '.'); p = strchr(cur_node, '.');
if (p != NULL) if (p != NULL)
len = p - cur_node; len = p - cur_node;
else else
len = strlen(cur_node); len = strlen(cur_node);
if (strlen(host_only) == len && if (strlen(host_only) == len &&
!strncasecmp(host_only, cur_node, len)) { !strncasecmp(host_only, cur_node, len)) {
free(str); free(str);
*retval = strdup(canonical_name); *retval = strdup(canonical_name);
if (*retval == NULL) { if (*retval == NULL) {
errno = ENOMEM; errno = ENOMEM;
return (-ENOMEM); return -1;
} }
return (0); return 0;
} }
if (getaddrinfo(str, NULL, &hints, &ai) == 0) { if (getaddrinfo(str, NULL, &hints, &ai) == 0) {
struct addrinfo *cur; struct addrinfo *cur;
for (cur = ai; cur != NULL; cur = cur->ai_ne xt) { for (cur = ai; cur != NULL; cur = cur->ai_ne xt) {
char hostbuf[512]; char hostbuf[512];
if (getnameinfo if (getnameinfo
(cur->ai_addr, cur->ai_addrlen, (cur->ai_addr, cur->ai_addrlen,
hostbuf, sizeof(hostbuf), NULL, 0, hostbuf, sizeof(hostbuf), NULL, 0,
skipping to change at line 181 skipping to change at line 185
continue; continue;
} }
if (!strcasecmp(hostbuf, nodename)) { if (!strcasecmp(hostbuf, nodename)) {
freeaddrinfo(ai); freeaddrinfo(ai);
free(str); free(str);
*retval = *retval =
strdup(canonical_name); strdup(canonical_name);
if (*retval == NULL) { if (*retval == NULL) {
errno = ENOMEM; errno = ENOMEM;
return (-ENOMEM); return -1;
} }
return (0); return 0;
} }
} }
freeaddrinfo(ai); freeaddrinfo(ai);
} }
free(str); free(str);
/* Now try any altnames */ /* Now try any altnames */
} }
} }
out_fail: out_fail:
errno = EINVAL; errno = EINVAL;
*retval = NULL; *retval = NULL;
return (-1); return -1;
} }
static int facility_id_get(char *name) static int facility_id_get(char *name)
{ {
unsigned int i; unsigned int i;
for (i = 0; facilitynames[i].c_name != NULL; i++) { for (i = 0; facilitynames[i].c_name != NULL; i++) {
if (strcasecmp(name, facilitynames[i].c_name) == 0) { if (strcasecmp(name, facilitynames[i].c_name) == 0) {
return (facilitynames[i].c_val); return (facilitynames[i].c_val);
} }
skipping to change at line 226 skipping to change at line 230
for (i = 0; prioritynames[i].c_name != NULL; i++) { for (i = 0; prioritynames[i].c_name != NULL; i++) {
if (strcasecmp(name, prioritynames[i].c_name) == 0) { if (strcasecmp(name, prioritynames[i].c_name) == 0) {
return (prioritynames[i].c_val); return (prioritynames[i].c_val);
} }
} }
return (-1); return (-1);
} }
/* requires string buffer to be PATH_MAX */ /* requires string buffer to be PATH_MAX */
static void read_string(int fd, const char *path, char *string) static void read_string(int fd, const char *path, char *string, size_t stri ng_s)
{ {
char *str; char *str;
int error; int error;
memset(string, 0, PATH_MAX); memset(string, 0, PATH_MAX);
error = ccs_get(fd, path, &str); error = ccs_get(fd, path, &str);
if (error || !str) if (error || !str)
return; return;
strcpy(string, str); strncpy(string, str, string_s - 1);
free(str); free(str);
} }
static void read_yesno(int fd, const char *path, int *yes, int *no) static void read_yesno(int fd, const char *path, int *yes, int *no)
{ {
char *str; char *str;
int error; int error;
*yes = 0; *yes = 0;
skipping to change at line 344 skipping to change at line 348
if (y) if (y)
*mode |= LOG_MODE_OUTPUT_FILE; *mode |= LOG_MODE_OUTPUT_FILE;
if (n) if (n)
*mode &= ~LOG_MODE_OUTPUT_FILE; *mode &= ~LOG_MODE_OUTPUT_FILE;
/* /*
* syslog_facility * syslog_facility
*/ */
create_daemon_path(name, "syslog_facility", path); create_daemon_path(name, "syslog_facility", path);
read_string(fd, "/cluster/logging/@syslog_facility", string); read_string(fd, "/cluster/logging/@syslog_facility",
string, sizeof(string));
if (string[0]) { if (string[0]) {
val = facility_id_get(string); val = facility_id_get(string);
if (val >= 0) if (val >= 0)
*syslog_facility = val; *syslog_facility = val;
} }
read_string(fd, path, string); read_string(fd, path, string, sizeof(string));
if (string[0]) { if (string[0]) {
val = facility_id_get(string); val = facility_id_get(string);
if (val >= 0) if (val >= 0)
*syslog_facility = val; *syslog_facility = val;
} }
/* /*
* syslog_priority * syslog_priority
*/ */
create_daemon_path(name, "syslog_priority", path); create_daemon_path(name, "syslog_priority", path);
read_string(fd, "/cluster/logging/@syslog_priority", string); read_string(fd, "/cluster/logging/@syslog_priority",
string, sizeof(string));
if (string[0]) { if (string[0]) {
val = priority_id_get(string); val = priority_id_get(string);
if (val >= 0) if (val >= 0)
*syslog_priority = val; *syslog_priority = val;
} }
read_string(fd, path, string); read_string(fd, path, string, sizeof(string));
if (string[0]) { if (string[0]) {
val = priority_id_get(string); val = priority_id_get(string);
if (val >= 0) if (val >= 0)
*syslog_priority = val; *syslog_priority = val;
} }
/* /*
* logfile * logfile
*/ */
create_daemon_path(name, "logfile", path); create_daemon_path(name, "logfile", path);
read_string(fd, "/cluster/logging/@logfile", string); read_string(fd, "/cluster/logging/@logfile", string, sizeof(string)) ;
if (string[0]) if (string[0])
strcpy(logfile, string); strcpy(logfile, string);
read_string(fd, path, string); read_string(fd, path, string, sizeof(string));
if (string[0]) if (string[0])
strcpy(logfile, string); strcpy(logfile, string);
/* /*
* debug is only ever turned on, not off, so if it's already on * debug is only ever turned on, not off, so if it's already on
* (from the daemon), then just skip the debug lookups. * (from the daemon), then just skip the debug lookups.
*/ */
if (*debug) { if (*debug) {
*logfile_priority = LOG_DEBUG; *logfile_priority = LOG_DEBUG;
skipping to change at line 431 skipping to change at line 437
if (*debug) { if (*debug) {
*logfile_priority = LOG_DEBUG; *logfile_priority = LOG_DEBUG;
return; return;
} }
/* /*
* logfile_priority * logfile_priority
*/ */
create_daemon_path(name, "logfile_priority", path); create_daemon_path(name, "logfile_priority", path);
read_string(fd, "/cluster/logging/@logfile_priority", string); read_string(fd, "/cluster/logging/@logfile_priority",
string, sizeof(string));
if (string[0]) { if (string[0]) {
val = priority_id_get(string); val = priority_id_get(string);
if (val >= 0) if (val >= 0)
*logfile_priority = val; *logfile_priority = val;
} }
read_string(fd, path, string); read_string(fd, path, string, sizeof(string));
if (string[0]) { if (string[0]) {
val = priority_id_get(string); val = priority_id_get(string);
if (val >= 0) if (val >= 0)
*logfile_priority = val; *logfile_priority = val;
} }
} }
 End of changes. 26 change blocks. 
28 lines changed or deleted 35 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/