#include <signal.h>
#include <fnmatch.h>
#include <osl.h>
+#include <lopsub.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <netdb.h>
+#include <lopsub.h>
#include "server.cmdline.h"
#include "para.h"
/**
* A random number used to "authenticate" the connection.
*
- * para_server picks this number by random before forking the afs process. The
- * command handlers write this number together with the id of the shared memory
- * area containing the query. This way, a malicious local user has to know this
- * number to be able to cause the afs process to crash by sending fake queries.
+ * para_server picks this number by random before it forks the afs process. The
+ * command handlers know this number as well and write it to the afs socket,
+ * together with the id of the shared memory area which contains the payload of
+ * the afs command. A local process has to know this number to abuse the afs
+ * service provided by the local socket.
*/
extern uint32_t afs_socket_cookie;
{
struct msghdr msg = {.msg_iov = NULL};
struct cmsghdr *cmsg;
- char control[255];
+ char control[255] __a_aligned(8);
int ret;
struct iovec iov;
}
/* Never fails if arg == NULL */
-static int activate_mood_or_playlist(char *arg, int *num_admissible)
+static int activate_mood_or_playlist(const char *arg, int *num_admissible)
{
enum play_mode mode;
int ret;
- PARA_INFO_LOG("new playlist: %s\n", arg);
if (!arg) {
ret = change_current_mood(NULL); /* always successful */
mode = PLAY_MODE_MOOD;
static int com_select_callback(struct afs_callback_arg *aca)
{
- char *arg = aca->query.data;
+ const char *arg = aca->query.data;
int num_admissible, ret;
ret = clear_score_table();
if (ret >= 0)
goto out;
/* ignore subsequent errors (but log them) */
- para_printf(&aca->pbout, "could not activate %s: %s\n"
- "switching back to %s\n",
- arg, para_strerror(-ret), current_mop? current_mop : "dummy");
- ret = activate_mood_or_playlist(current_mop, &num_admissible);
- if (ret >= 0)
- goto out;
- para_printf(&aca->pbout, "could not activate %s: %s\nswitching to dummy\n",
- current_mop, para_strerror(-ret));
+ para_printf(&aca->pbout, "could not activate %s\n", arg);
+ if (current_mop) {
+ int ret2;
+ para_printf(&aca->pbout, "switching back to %s\n", current_mop);
+ ret2 = activate_mood_or_playlist(current_mop, &num_admissible);
+ if (ret2 >= 0)
+ goto out;
+ para_printf(&aca->pbout, "could not reactivate %s: %s\n",
+ current_mop, para_strerror(-ret2));
+ }
+ para_printf(&aca->pbout, "activating dummy mood\n");
activate_mood_or_playlist(NULL, &num_admissible);
out:
para_printf(&aca->pbout, "activated %s (%d admissible files)\n",
ret = create_local_socket(socket_name, 0);
if (ret < 0) {
ret = create_local_socket(socket_name,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IROTH);
if (ret < 0) {
PARA_EMERG_LOG("%s: %s\n", para_strerror(-ret),
socket_name);
int i, ret;
get_database_dir();
- PARA_NOTICE_LOG("opening %u osl tables in %s\n", NUM_AFS_TABLES,
+ PARA_NOTICE_LOG("opening %d osl tables in %s\n", NUM_AFS_TABLES,
database_dir);
for (i = 0; i < NUM_AFS_TABLES; i++) {
ret = afs_tables[i].open(database_dir);
return ret;
buf[n] = '\0';
if (strcmp(buf, "new"))
- return -E_BAD_CMD;
+ return -ERRNO_TO_PARA_ERROR(EINVAL);
return open_next_audio_file();
}
register_command_task(cookie, &s);
s.default_timeout.tv_sec = 0;
s.default_timeout.tv_usec = 999 * 1000;
+ ret = write(socket_fd, "\0", 1);
+ if (ret != 1) {
+ if (ret == 0)
+ errno = EINVAL;
+ ret = -ERRNO_TO_PARA_ERROR(errno);
+ goto out_close;
+ }
ret = schedule(&s);
sched_shutdown(&s);
out_close:
return ret;
}
-int com_init(struct command_context *cc)
+static int com_init(struct command_context *cc, struct lls_parse_result *lpr)
{
int i, j, ret;
uint32_t table_mask = (1 << (NUM_AFS_TABLES + 1)) - 1;
struct osl_object query = {.data = &table_mask,
.size = sizeof(table_mask)};
+ unsigned num_inputs = lls_num_inputs(lpr);
ret = make_database_dir();
if (ret < 0)
return ret;
- if (cc->argc != 1) {
+ if (num_inputs > 0) {
table_mask = 0;
- for (i = 1; i < cc->argc; i++) {
+ for (i = 0; i < num_inputs; i++) {
for (j = 0; j < NUM_AFS_TABLES; j++) {
struct afs_table *t = &afs_tables[j];
- if (strcmp(cc->argv[i], t->name))
+ if (strcmp(lls_input(i, lpr), t->name))
continue;
table_mask |= (1 << j);
break;
return send_callback_request(com_init_callback, &query,
afs_cb_result_handler, cc);
}
+EXPORT_SERVER_CMD_HANDLER(init);
/**
* Flags for the check command.
continue;
ret = t->event_handler(event, pb, data);
if (ret < 0) {
- PARA_CRIT_LOG("table %s, event %d: %s\n", t->name,
+ PARA_CRIT_LOG("table %s, event %u: %s\n", t->name,
event, para_strerror(-ret));
return ret;
}