#include "lib/lib.h"
#include "lib/mempool.h"
-#include "lib/stkstring.h"
#include "sherlock/object.h"
#include "sherlock/objread.h"
-#include <sys/stat.h>
-
#include "submitd.h"
/*** REQUESTS AND REPLIES ***/
static void
write_reply(struct conn *c)
{
+ if (!obj_find_attr(c->reply, '-') && !obj_find_attr(c->reply, '+'))
+ obj_set_attr(c->reply, '+', "OK");
if (trace_commands)
{
byte *msg;
bflush(&c->tx_fb);
}
+static void
+err(struct conn *c, byte *msg)
+{
+ obj_set_attr(c->reply, '-', msg);
+}
+
+/*** SUBMIT ***/
+
+static void
+cmd_submit(struct conn *c)
+{
+ byte *tname = obj_find_aval(c->request, 'T');
+ if (!tname)
+ {
+ err(c, "No task specified");
+ return;
+ }
+ struct task *task = task_find(tname);
+ if (!task)
+ {
+ err(c, "No such task");
+ return;
+ }
+}
+
/*** COMMAND MUX ***/
static void
byte *cmd = obj_find_aval(c->request, '!');
if (!cmd)
{
- obj_set_attr(c->reply, '-', "Missing command");
+ err(c, "Missing command");
return;
}
if (trace_commands)
log(L_DEBUG, "<< %s", cmd);
- obj_set_attr(c->reply, '-', "Unknown command");
+ if (!strcasecmp(cmd, "SUBMIT"))
+ cmd_submit(c);
+ else
+ err(c, "Unknown command");
}
int
/*** INITIAL HANDSHAKE ***/
-static int
-user_exists_p(byte *user)
-{
- byte *fn = stk_printf("solutions/%s/status", user);
- struct stat st;
- return !stat(fn, &st) && S_ISREG(st.st_mode);
-}
-
static void
execute_init(struct conn *c)
{
byte *user = obj_find_aval(c->request, 'U');
if (!user)
{
- obj_set_attr(c->reply, '-', "Missing user");
+ err(c, "Missing user");
return;
}
if (!c->cert_name ||
{
if (!user_exists_p(user))
{
- obj_set_attr(c->reply, '-', "Unknown user");
+ err(c, "Unknown user");
return;
}
log(L_INFO, "Logged in %s", user);
}
else
{
- obj_set_attr(c->reply, '-', "Permission denied");
+ err(c, "Permission denied");
log(L_ERROR, "Unauthorized attempt to log in as %s", user);
return;
}
- obj_set_attr(c->reply, '+', "OK");
c->user = xstrdup(user);
}
return 0;
execute_init(c);
write_reply(c);
- return !!obj_find_attr(c->reply, '+');
+ return !obj_find_attr(c->reply, '-');
}
--- /dev/null
+/*
+ * The Submit Daemon: Tasks
+ *
+ * (c) 2007 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+#include "lib/conf.h"
+#include "lib/stkstring.h"
+
+#include <sys/stat.h>
+
+#include "submitd.h"
+
+clist task_list;
+
+static byte *
+tasks_conf_init(void)
+{
+ clist_init(&task_list);
+ return NULL;
+}
+
+static struct cf_section task_conf = {
+ CF_TYPE(struct task),
+ CF_ITEMS {
+ CF_STRING("Name", PTR_TO(struct task, name)),
+ CF_END
+ }
+};
+
+struct cf_section tasks_conf = {
+ CF_INIT(tasks_conf_init),
+ CF_ITEMS {
+ CF_LIST("Task", &task_list, &task_conf),
+ CF_END
+ }
+};
+
+struct task *
+task_find(byte *name)
+{
+ CLIST_FOR_EACH(struct task *, t, task_list)
+ if (!strcasecmp(t->name, name))
+ return t;
+ return NULL;
+}
+
+int
+user_exists_p(byte *user)
+{
+ byte *fn = stk_printf("solutions/%s/status", user);
+ struct stat st;
+ return !stat(fn, &st) && S_ISREG(st.st_mode);
+}