Fix bug #167 - Build errors on OpenBSD.
- Don't link with -ldl, as it is not needed in most cases - Don't compile plugins if USE_PLUGINS=NO - Fix warning about missing newline at end of getopt.h - Removed the O_NOATIME open() flag from the logging plugin. - Removed the O_LARGEFILE open() flag. _FILE_OFFSET_BITS is 64. - Use fsync() if fdatasync() is not available for log file writing. - Replaced some sprintf() with snprintf() due to compiler warnings (though, they were length limited otherwise). - Replaced two occurences of strcpy() with memcpy().
This commit is contained in:
@@ -328,7 +328,7 @@ static int command_help(struct hub_info* hub, struct hub_user* user, struct hub_
|
||||
|
||||
if (!found)
|
||||
{
|
||||
sprintf(msg, "Command \"%s\" not found.\n", command);
|
||||
snprintf(msg, sizeof(msg), "Command \"%s\" not found.\n", command);
|
||||
}
|
||||
}
|
||||
return command_status(hub, user, cmd, msg);
|
||||
@@ -676,11 +676,11 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c
|
||||
|
||||
if (search_len)
|
||||
{
|
||||
sprintf(tmp, "Logged entries: " PRINTF_SIZE_T ", searching for \"%s\"", list_size(messages), search);
|
||||
snprintf(tmp, sizeof(tmp), "Logged entries: " PRINTF_SIZE_T ", searching for \"%s\"", list_size(messages), search);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(tmp, "Logged entries: " PRINTF_SIZE_T, list_size(messages));
|
||||
snprintf(tmp, sizeof(tmp), "Logged entries: " PRINTF_SIZE_T, list_size(messages));
|
||||
}
|
||||
command_status(hub, user, cmd, tmp);
|
||||
|
||||
@@ -705,7 +705,7 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c
|
||||
|
||||
if (show)
|
||||
{
|
||||
sprintf(tmp, "* %s %s, %s [%s] - %s", get_timestamp(log->time), log->cid, log->nick, ip_convert_to_string(&log->addr), user_get_quit_reason_string(log->reason));
|
||||
snprintf(tmp, sizeof(tmp), "* %s %s, %s [%s] - %s", get_timestamp(log->time), log->cid, log->nick, ip_convert_to_string(&log->addr), user_get_quit_reason_string(log->reason));
|
||||
send_message(hub, user, tmp);
|
||||
}
|
||||
log = (struct hub_logout_info*) list_get_next(messages);
|
||||
@@ -713,7 +713,7 @@ static int command_log(struct hub_info* hub, struct hub_user* user, struct hub_c
|
||||
|
||||
if (search_len)
|
||||
{
|
||||
sprintf(tmp, PRINTF_SIZE_T " entries shown.", search_hits);
|
||||
snprintf(tmp, sizeof(tmp), PRINTF_SIZE_T " entries shown.", search_hits);
|
||||
command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
|
||||
@@ -736,12 +736,12 @@ static int command_register(struct hub_info* hub, struct hub_user* user, struct
|
||||
{
|
||||
if (acl_register_user(hub, &data))
|
||||
{
|
||||
sprintf(tmp, "User \"%s\" registered.", user->id.nick);
|
||||
snprintf(tmp, sizeof(tmp), "User \"%s\" registered.", user->id.nick);
|
||||
return command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(tmp, "Unable to register user \"%s\".", user->id.nick);
|
||||
snprintf(tmp, sizeof(tmp), "Unable to register user \"%s\".", user->id.nick);
|
||||
return command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
}
|
||||
@@ -769,7 +769,7 @@ static int command_password(struct hub_info* hub, struct hub_user* user, struct
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(tmp, "Unable to change password for user \"%s\".", user->id.nick);
|
||||
snprintf(tmp, sizeof(tmp), "Unable to change password for user \"%s\".", user->id.nick);
|
||||
return command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
}
|
||||
@@ -796,12 +796,12 @@ static int command_useradd(struct hub_info* hub, struct hub_user* user, struct h
|
||||
|
||||
if (acl_register_user(hub, &data))
|
||||
{
|
||||
sprintf(tmp, "User \"%s\" registered.", nick);
|
||||
snprintf(tmp, sizeof(tmp), "User \"%s\" registered.", nick);
|
||||
return command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(tmp, "Unable to register user \"%s\".", nick);
|
||||
snprintf(tmp, sizeof(tmp), "Unable to register user \"%s\".", nick);
|
||||
return command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
}
|
||||
@@ -813,12 +813,12 @@ static int command_userdel(struct hub_info* hub, struct hub_user* user, struct h
|
||||
|
||||
if (acl_delete_user(hub, nick))
|
||||
{
|
||||
sprintf(tmp, "User \"%s\" is deleted.", nick);
|
||||
snprintf(tmp, sizeof(tmp), "User \"%s\" is deleted.", nick);
|
||||
return command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(tmp, "Unable to delete user \"%s\".", nick);
|
||||
snprintf(tmp, sizeof(tmp), "Unable to delete user \"%s\".", nick);
|
||||
return command_status(hub, user, cmd, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,8 +337,10 @@ void hub_chat_history_add(struct hub_info* hub, struct hub_user* user, struct ad
|
||||
{
|
||||
char* msg_esc = adc_msg_get_argument(cmd, 0);
|
||||
char* message = adc_msg_unescape(msg_esc);
|
||||
char* log = hub_malloc(strlen(message) + strlen(user->id.nick) + 14);
|
||||
sprintf(log, "%s <%s> %s\n", get_timestamp(time(NULL)), user->id.nick, message);
|
||||
size_t loglen = strlen(message) + strlen(user->id.nick) + 13;
|
||||
char* log = hub_malloc(loglen + 1);
|
||||
snprintf(log, loglen, "%s <%s> %s\n", get_timestamp(time(NULL)), user->id.nick, message);
|
||||
log[loglen] = '\0';
|
||||
list_append(hub->chat_history, log);
|
||||
while (list_size(hub->chat_history) > (size_t) hub->config->max_chat_history)
|
||||
{
|
||||
@@ -1331,8 +1333,8 @@ void hub_logout_log(struct hub_info* hub, struct hub_user* user)
|
||||
struct hub_logout_info* loginfo = hub_malloc_zero(sizeof(struct hub_logout_info));
|
||||
if (!loginfo) return;
|
||||
loginfo->time = time(NULL);
|
||||
strcpy(loginfo->cid, user->id.cid);
|
||||
strcpy(loginfo->nick, user->id.nick);
|
||||
memcpy(loginfo->cid, user->id.cid, sizeof(loginfo->cid));
|
||||
memcpy(loginfo->nick, user->id.nick, sizeof(loginfo->nick));
|
||||
memcpy(&loginfo->addr, &user->id.addr, sizeof(struct ip_addr_encap));
|
||||
loginfo->reason = user->quit_reason;
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ static void set_error_message(struct plugin_handle* plugin, const char* msg)
|
||||
|
||||
static int log_open_file(struct plugin_handle* plugin, struct log_data* data)
|
||||
{
|
||||
data->fd = open(data->logfile, O_CREAT | O_APPEND | O_NOATIME | O_LARGEFILE | O_WRONLY, 0664);
|
||||
int flags = O_CREAT | O_APPEND | O_WRONLY;
|
||||
data->fd = open(data->logfile, flags, 0664);
|
||||
return (data->fd != -1);
|
||||
}
|
||||
|
||||
@@ -163,7 +164,12 @@ static void log_message(struct log_data* data, const char *format, ...)
|
||||
va_end(args);
|
||||
|
||||
write(data->fd, logmsg, size + 20);
|
||||
|
||||
#ifdef _POSIX_SYNCHRONIZED_IO
|
||||
fdatasync(data->fd);
|
||||
#else
|
||||
fsync(data->fd);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -26,4 +26,5 @@ extern int optind;
|
||||
|
||||
extern int getopt(int argc, char* const argv[], const char *optstring);
|
||||
|
||||
#endif
|
||||
#endif /* NEED_GETOPT */
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ const char* get_timestamp(time_t now)
|
||||
{
|
||||
static char ts[32] = {0, };
|
||||
struct tm* t = localtime(&now);
|
||||
sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min);
|
||||
snprintf(ts, sizeof(ts), "[%02d:%02d]", t->tm_hour, t->tm_min);
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user