CGI knows who it is today). The CGI then gets a new cookie so that
the user continues being logged in.
This is a bit of a change from the original design but does save the
user a bit of time.
Also improved some of the associated web page text.
* @return 0 on success, non-0 on error
*/
int disorder_confirm(disorder_client *c, const char *confirm) {
* @return 0 on success, non-0 on error
*/
int disorder_confirm(disorder_client *c, const char *confirm) {
- return disorder_simple(c, 0, "confirm", confirm, (char *)0);
+ char *u;
+ int rc;
+
+ if(!(rc = dequote(disorder_simple(c, &u, "confirm", confirm, (char *)0),
+ &u)))
+ c->user = u;
+ return rc;
}
/** @brief Make a cookie for this login
}
/** @brief Make a cookie for this login
+/** @brief Confirm a user registration
+ * @param user Username
+ * @param confirmation Confirmation string
+ * @param rightsp Where to put user rights
+ * @param tid Transaction ID
+ * @return 0 on success, non-0 on error
+ */
static int trackdb_confirm_tid(const char *user, const char *confirmation,
static int trackdb_confirm_tid(const char *user, const char *confirmation,
DB_TXN *tid) {
const char *stored_confirmation;
struct kvp *k;
int e;
DB_TXN *tid) {
const char *stored_confirmation;
struct kvp *k;
int e;
if((e = trackdb_getdata(trackdb_usersdb, user, &k, tid)))
return e;
if((e = trackdb_getdata(trackdb_usersdb, user, &k, tid)))
return e;
/* DB claims -30,800 to -30,999 so -1 should be a safe bet */
return -1;
}
/* DB claims -30,800 to -30,999 so -1 should be a safe bet */
return -1;
}
+ if(!(rights = kvp_get(k, "rights"))) {
+ error(0, "no rights for unconfirmed user '%s'", user);
+ return -1;
+ }
+ if(parse_rights(rights, rightsp, 1))
+ return -1;
if(strcmp(confirmation, stored_confirmation)) {
error(0, "wrong confirmation string for user '%s'", user);
return -1;
if(strcmp(confirmation, stored_confirmation)) {
error(0, "wrong confirmation string for user '%s'", user);
return -1;
/** @brief Confirm a user registration
* @param user Username
* @param confirmation Confirmation string
/** @brief Confirm a user registration
* @param user Username
* @param confirmation Confirmation string
+ * @param rightsp Where to put user rights
* @return 0 on success, non-0 on error
*/
* @return 0 on success, non-0 on error
*/
-int trackdb_confirm(const char *user, const char *confirmation) {
+int trackdb_confirm(const char *user, const char *confirmation,
+ rights_type *rightsp) {
- WITH_TRANSACTION(trackdb_confirm_tid(user, confirmation, tid));
+ WITH_TRANSACTION(trackdb_confirm_tid(user, confirmation, rightsp, tid));
switch(e) {
case 0:
info("registration confirmed for user '%s'", user);
switch(e) {
case 0:
info("registration confirmed for user '%s'", user);
int trackdb_edituserinfo(const char *user,
const char *key, const char *value);
char **trackdb_listusers(void);
int trackdb_edituserinfo(const char *user,
const char *key, const char *value);
char **trackdb_listusers(void);
-int trackdb_confirm(const char *user, const char *confirmation);
+int trackdb_confirm(const char *user, const char *confirmation,
+ rights_type *rightsp);
cgi_set_option("error", "noconfirm");
expand_template(ds, output, "login");
}
cgi_set_option("error", "noconfirm");
expand_template(ds, output, "login");
}
+ /* Confirm our registration */
if(disorder_confirm(ds->g->client, confirmation)) {
cgi_set_option("error", "badconfirm");
expand_template(ds, output, "login");
}
if(disorder_confirm(ds->g->client, confirmation)) {
cgi_set_option("error", "badconfirm");
expand_template(ds, output, "login");
}
+ /* Get a cookie */
+ if(disorder_make_cookie(ds->g->client, &login_cookie)) {
+ cgi_set_option("error", "cookiefailed");
+ expand_template(ds, output, "login");
+ return;
+ }
+ /* Discard any cached data JIC */
+ ds->g->flags = 0;
+ /* We have a new cookie */
+ header_cookie(output->sink);
cgi_set_option("status", "confirmed");
expand_template(ds, output, "login");
}
cgi_set_option("status", "confirmed");
expand_template(ds, output, "login");
}
c->who = vec[0];
c->rights = rights;
/* currently we only bother logging remote connections */
c->who = vec[0];
c->rights = rights;
/* currently we only bother logging remote connections */
- if(strcmp(host, "local")) {
+ if(strcmp(host, "local"))
info("S%x %s connected from %s", c->tag, vec[0], host);
info("S%x %s connected from %s", c->tag, vec[0], host);
c->rights |= RIGHT__LOCAL;
c->rights |= RIGHT__LOCAL;
sink_writes(ev_writer_sink(c->w), "230 OK\n");
return 1;
}
sink_writes(ev_writer_sink(c->w), "230 OK\n");
return 1;
}
c->who = user;
c->cookie = vec[0];
c->rights = rights;
c->who = user;
c->cookie = vec[0];
c->rights = rights;
- if(strcmp(host, "local")) {
+ if(strcmp(host, "local"))
info("S%x %s connected with cookie from %s", c->tag, user, host);
info("S%x %s connected with cookie from %s", c->tag, user, host);
c->rights |= RIGHT__LOCAL;
c->rights |= RIGHT__LOCAL;
/* Response contains username so client knows who they are acting as */
sink_printf(ev_writer_sink(c->w), "232 %s\n", quoteutf8(user));
return 1;
/* Response contains username so client knows who they are acting as */
sink_printf(ev_writer_sink(c->w), "232 %s\n", quoteutf8(user));
return 1;
int attribute((unused)) nvec) {
size_t nuser;
char *user, *sep;
int attribute((unused)) nvec) {
size_t nuser;
char *user, *sep;
+ rights_type rights;
+ const char *host;
+ /* Get some kind of peer identifcation */
+ if(!(host = connection_host(c))) {
+ sink_writes(ev_writer_sink(c->w), "530 Authentication failure\n");
+ return 1;
+ }
if(!(user = mime_base64(vec[0], &nuser))
|| !(sep = memchr(user, ';', nuser))) {
sink_writes(ev_writer_sink(c->w), "550 Malformed confirmation string\n");
return 1;
}
*sep = 0;
if(!(user = mime_base64(vec[0], &nuser))
|| !(sep = memchr(user, ';', nuser))) {
sink_writes(ev_writer_sink(c->w), "550 Malformed confirmation string\n");
return 1;
}
*sep = 0;
- if(trackdb_confirm(user, vec[0]))
+ if(trackdb_confirm(user, vec[0], &rights))
sink_writes(ev_writer_sink(c->w), "550 Incorrect confirmation string\n");
sink_writes(ev_writer_sink(c->w), "550 Incorrect confirmation string\n");
- else
- sink_writes(ev_writer_sink(c->w), "250 OK\n");
+ else {
+ c->who = user;
+ c->cookie = 0;
+ c->rights = rights;
+ if(strcmp(host, "local"))
+ info("S%x %s confirmed from %s", c->tag, user, host);
+ else
+ c->rights |= RIGHT__LOCAL;
+ /* Response contains username so client knows who they are acting as */
+ sink_printf(ev_writer_sink(c->w), "232 %s\n", quoteutf8(user));
+ }
label login.logout "Logout"
# Text for login page responses
label login.logout "Logout"
# Text for login page responses
-label login.loginok "Logged in OK"
-label login.logoutok "Logged out OK"
-label login.registered "Registered your new login"
-label login.confirmed "Confirmed your new login"
+label login.loginok "You are now logged in."
+label login.logoutok "You are now logged out."
+label login.registered "Registered your new login. Please check your email."
+label login.confirmed "Confirmed your new login. You are now logged in."
# <TITLE> for account page
label account.title "DisOrder User Details"
# <TITLE> for account page
label account.title "DisOrder User Details"