Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement feature for getting quotes from an external process #15

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Makefile
#
# qotd - A simple QOTD daemon.
# Copyright (c) 2015-2016 Emmie Smith
# Copyright (c) 2015-2024 Emmie Smith
#
# qotd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion man/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Makefile
#
# qotd - A simple QOTD daemon.
# Copyright (c) 2015-2016 Emmie Smith
# Copyright (c) 2015-2024 Emmie Smith
#
# qotd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion man/qotd.conf.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH QOTD.CONF 5 2016-01-29 "qotd 0.12.0" "System Manager's Manual"
.TH QOTD.CONF 5 2024-01-29 "qotd 0.12.0" "System Manager's Manual"
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
Expand Down
2 changes: 1 addition & 1 deletion man/qotdd.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH QOTDD 8 2016-01-29 "qotd 0.12.0" "System Manager's Manual"
.TH QOTDD 8 2024-01-29 "qotd 0.12.0" "System Manager's Manual"
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
Expand Down
1 change: 0 additions & 1 deletion misc/local-bg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ PadQuotes yes

DailyQuotes yes
AllowBigQuotes no

1 change: 0 additions & 1 deletion misc/local-file.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ PadQuotes yes

DailyQuotes yes
AllowBigQuotes no

1 change: 0 additions & 1 deletion misc/local.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ PadQuotes yes

DailyQuotes yes
AllowBigQuotes no

1 change: 0 additions & 1 deletion misc/qotd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ DailyQuotes yes
# option is set to 'yes', this limit is ignored. Otherwise, quotes are
# automatically truncated to meet the byte limit.
AllowBigQuotes no

2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Makefile
#
# qotd - A simple QOTD daemon.
# Copyright (c) 2015-2016 Emmie Smith
# Copyright (c) 2015-2024 Emmie Smith
#
# qotd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
8 changes: 5 additions & 3 deletions src/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* arguments.c
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -189,8 +189,9 @@ static void parse_short_options(const char *argument,
{
size_t i;

if (DEBUG)
if (DEBUG) {
journal("Parsing options in \"-%s\":\n", argument);
}

for (i = 0; argument[i]; i++) {
#if DEBUG
Expand Down Expand Up @@ -429,8 +430,9 @@ void parse_args(struct options *const opt,
opt->strict = flags.strict;

if (flags.conf_file) {
if (flags.conf_file[0] != '/')
if (flags.conf_file[0] != '/') {
opt->chdir_root = 0;
}
parse_config(opt, flags.conf_file);
}
if (flags.pid_file) {
Expand Down
2 changes: 1 addition & 1 deletion src/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* arguments.h
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
51 changes: 33 additions & 18 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* configuration.c
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -57,8 +57,9 @@ static int caseless_eq(const struct string *x,
size_t i;
char c1, c2;

if (x->length != y_len)
if (x->length != y_len) {
return 0;
}
for (i = 0; i < y_len; i++) {
c1 = tolower(x->ptr[i]);
c2 = tolower(y[i]);
Expand All @@ -72,8 +73,9 @@ static void print_str(FILE *out, const struct string *s)
{
size_t i;

for (i = 0; i < s->length; i++)
for (i = 0; i < s->length; i++) {
putc(s->ptr[i], out);
}
putc('\n', out);
}

Expand All @@ -82,8 +84,9 @@ static char *dup_str(const struct string *s)
char *buf;

buf = malloc(s->length + 1);
if (unlikely(!buf))
if (unlikely(!buf)) {
return NULL;
}

memcpy(buf, s->ptr, s->length);
buf[s->length] = '\0';
Expand Down Expand Up @@ -193,12 +196,13 @@ static int str_to_bool(const struct string *s,
{
if (caseless_eq(s, "yes", 3) ||
caseless_eq(s, "true", 4) ||
caseless_eq(s, "1", 1))
caseless_eq(s, "1", 1)) {
return 1;
else if (caseless_eq(s, "no", 2) ||
} else if (caseless_eq(s, "no", 2) ||
caseless_eq(s, "false", 5) ||
caseless_eq(s, "0", 1))
caseless_eq(s, "0", 1)) {
return 0;
}

fprintf(stderr, "%s:%u: not a boolean value: ",
filename, lineno);
Expand Down Expand Up @@ -236,8 +240,9 @@ static int process_line(struct options *opt,
struct string key, val;
int n;

if (read_kv(conf_file, lineno, line, &key, &val))
if (read_kv(conf_file, lineno, line, &key, &val)) {
return key.ptr != NULL;
}

if (DEBUG) {
fputs("\tKey: ", stdout);
Expand All @@ -249,8 +254,9 @@ static int process_line(struct options *opt,
/* Check each possible option */
if (caseless_eq(&key, "Daemonize", 9)) {
n = str_to_bool(&val, conf_file, lineno);
if (unlikely(NOT_BOOL(n)))
if (unlikely(NOT_BOOL(n))) {
return -1;
}
opt->daemonize = n;
} else if (caseless_eq(&key, "TransportProtocol", 17)) {
if (caseless_eq(&val, "tcp", 3)) {
Expand Down Expand Up @@ -278,18 +284,21 @@ static int process_line(struct options *opt,
}
} else if (caseless_eq(&key, "Port", 4)) {
n = get_port(&val, conf_file, lineno);
if (unlikely(n < 0))
if (unlikely(n < 0)) {
return -1;
}
opt->port = n;
} else if (caseless_eq(&key, "StrictChecking", 14)) {
n = str_to_bool(&val, conf_file, lineno);
if (unlikely(NOT_BOOL(n)))
if (unlikely(NOT_BOOL(n))) {
return -1;
}
opt->strict = n;
} else if (caseless_eq(&key, "DropPrivileges", 14)) {
n = str_to_bool(&val, conf_file, lineno);
if (unlikely(NOT_BOOL(n)))
if (unlikely(NOT_BOOL(n))) {
return -1;
}
opt->drop_privileges = n;
} else if (caseless_eq(&key, "PidFile", 7)) {
if (caseless_eq(&val, "none", 4)) {
Expand All @@ -304,8 +313,9 @@ static int process_line(struct options *opt,
}
} else if (caseless_eq(&key, "RequirePidFile", 14)) {
n = str_to_bool(&val, conf_file, lineno);
if (unlikely(NOT_BOOL(n)))
if (unlikely(NOT_BOOL(n))) {
return -1;
}
opt->require_pidfile = n;
} else if (caseless_eq(&key, "JournalFile", 11)) {
if (caseless_eq(&val, "-", 1)) {
Expand Down Expand Up @@ -338,18 +348,21 @@ static int process_line(struct options *opt,
}
} else if (caseless_eq(&key, "PadQuotes", 9)) {
n = str_to_bool(&val, conf_file, lineno);
if (unlikely(NOT_BOOL(n)))
if (unlikely(NOT_BOOL(n))) {
return -1;
}
opt->pad_quotes = n;
} else if (caseless_eq(&key, "DailyQuotes", 11)) {
n = str_to_bool(&val, conf_file, lineno);
if (unlikely(NOT_BOOL(n)))
if (unlikely(NOT_BOOL(n))) {
return -1;
}
opt->is_daily = n;
} else if (caseless_eq(&key, "AllowBigQuotes", 14)) {
n = str_to_bool(&val, conf_file, lineno);
if (unlikely(NOT_BOOL(n)))
if (unlikely(NOT_BOOL(n))) {
return -1;
}
opt->allow_big = n;
} else {
fprintf(stderr, "%s:%u: unknown config option: ",
Expand All @@ -369,8 +382,9 @@ void parse_config(struct options *opt, const char *conf_file)
/* Journal hasn't been opened yet */
printf("Reading configuration file at \"%s\"...\n", conf_file);

if (opt->strict)
if (opt->strict) {
security_conf_file_check(conf_file);
}

fh = fopen(conf_file, "r");
if (!fh) {
Expand All @@ -385,8 +399,9 @@ void parse_config(struct options *opt, const char *conf_file)
lineno = 1;
errors = 0;
while (!read_line(fh, conf_file, &lineno, &line)) {
if (process_line(opt, conf_file, lineno, &line))
if (process_line(opt, conf_file, lineno, &line)) {
errors++;
}
lineno++;
}
fclose(fh);
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* config.h
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* core.h
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
6 changes: 5 additions & 1 deletion src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* core.h
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -125,6 +125,10 @@
# define NORETURN
#endif /* __GNUC__ || __clang__ */

/* Constants */

#define QUOTE_SIZE 512 /* Set by RFC 865 */

/* Functions */

void print_version(void);
Expand Down
23 changes: 14 additions & 9 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* daemon.c
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -32,9 +32,9 @@
#include "journal.h"
#include "network.h"
#include "pid_file.h"
#include "quotes.h"
#include "quotes_file.h"
#include "security.h"
#include "signal_hndl.h"
#include "signal_handler.h"

static struct options opt;

Expand Down Expand Up @@ -70,8 +70,9 @@ static int main_loop(void)
cleanup(EXIT_INTERNAL, 1);
}

if (opt.drop_privileges)
if (opt.drop_privileges) {
drop_privileges();
}

switch (opt.tproto) {
case PROTOCOL_TCP:
Expand All @@ -88,8 +89,9 @@ static int main_loop(void)
return -1;
}

for (;;)
for (;;) {
accept_connection();
}
}

static int daemonize(void)
Expand Down Expand Up @@ -121,24 +123,27 @@ static int daemonize(void)

int main(const int argc, const char *const argv[])
{
if (DEBUG)
if (DEBUG) {
printf("(Running in debug mode)\n");
}

signal_hndl_init();
signal_handler_init();
load_config(argc, argv);
open_journal(opt.journal_file);

/* Check security settings */
if (opt.strict)
if (opt.strict) {
security_options_check(&opt);
}

return opt.daemonize ? daemonize() : main_loop();
}

void cleanup(int ret, int quiet)
{
if (!quiet)
if (!quiet) {
journal("Quitting with exit code %d.\n", ret);
}

pidfile_remove(&opt);
destroy_quote_buffers();
Expand Down
2 changes: 1 addition & 1 deletion src/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* daemon.h
*
* qotd - A simple QOTD daemon.
* Copyright (c) 2015-2016 Emmie Smith
* Copyright (c) 2015-2024 Emmie Smith
*
* qotd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
Loading