/*
* These functions handle authentication of users to a Citadel server.
*
- * Copyright (c) 1996-2010 by the citadel.org team
+ * Copyright (c) 1996-2011 by the citadel.org team
*
* This program is open source software. You can redistribute it and/or
* modify it under the terms of the GNU General Public License as
extern uint32_t hashlittle( const void *key, size_t length, uint32_t initval);
-void display_reg(int during_login);
-
/*
* Access level definitions. This is initialized from a function rather than a
* static array so that the strings may be localized.
-/*
- * Display the openid-enabled login screen
- * mesg = the error message if last attempt failed.
- */
-void display_openid_login(char *mesg)
-{
- begin_burst();
- output_headers(1, 0, 0, 0, 1, 0);
- do_template("openid_login", NULL);
- end_burst();
-}
-
-
-
/* Initialize the session
*
}
-/*
- * Perform authentication using a user name and password
- */
-void do_login(void)
-{
- wcsession *WCC = WC;
- StrBuf *Buf;
- long ret, rc;
-
- if (havebstr("language")) {
- set_selected_language(bstr("language"));
- go_selected_language();
- }
-
- if (havebstr("exit_action")) {
- do_logout();
- return;
- }
- Buf = NewStrBuf();
- if (havebstr("login_action")) {
- serv_printf("USER %s", bstr("name"));
- StrBuf_ServGetln(Buf);
- rc = GetServerStatus(Buf, &ret);
- StrBufCutLeft(Buf, 4);
- switch (rc) {
- case 3:
- serv_printf("PASS %s", bstr("pass"));
- StrBuf_ServGetln(Buf);
- if (GetServerStatus(Buf, NULL) == 2) {
- become_logged_in(sbstr("name"), sbstr("pass"), Buf);
- } else {
- StrBufCutLeft(Buf, 4);
- AppendImportantMessage(SKEY(Buf));
- display_login();
- FreeStrBuf(&Buf);
- return;
- }
- break;
- case 5:
- if (ret == 541)
- {
- AppendImportantMessage(SKEY(Buf));
- display_main_menu();
- return;
- }
- default:
- AppendImportantMessage(SKEY(Buf));
- display_login();
- FreeStrBuf(&Buf);
- return;
- }
- }
- if (havebstr("newuser_action")) {
- if (!havebstr("pass")) {
- AppendImportantMessage(_("Blank passwords are not allowed."), -1);
- display_login();
- FreeStrBuf(&Buf);
- return;
- }
- serv_printf("NEWU %s", bstr("name"));
- StrBuf_ServGetln(Buf);
- if (GetServerStatus(Buf, NULL) == 2) {
- become_logged_in(sbstr("name"), sbstr("pass"), Buf);
- serv_printf("SETP %s", bstr("pass"));
- StrBuf_ServGetln(Buf); /* Don't care? */
- } else {
- StrBufCutLeft(Buf, 4);
- AppendImportantMessage(SKEY(Buf));
- display_login();
- FreeStrBuf(&Buf);
- return;
- }
- }
- if (WCC->logged_in) {
- if (WCC->need_regi) {
- display_reg(1);
- } else if (WCC->need_vali) {
- validate();
- } else {
- do_welcome();
- }
- } else {
- AppendImportantMessage(_("Your password was not accepted."), -1);
- display_login();
- }
- FreeStrBuf(&Buf);
-}
-
-
-
/*
* modal/ajax version of 'login' (username and password)
*/
+/*
+ * modal/ajax version of 'new user' (username and password)
+ */
+void ajax_login_newuser(void) {
+ StrBuf *NBuf = NewStrBuf();
+ StrBuf *SBuf = NewStrBuf();
+
+ serv_printf("NEWU %s", bstr("name"));
+ StrBuf_ServGetln(NBuf);
+ if (GetServerStatus(NBuf, NULL) == 2) {
+ become_logged_in(sbstr("name"), sbstr("pass"), NBuf);
+ serv_printf("SETP %s", bstr("pass"));
+ StrBuf_ServGetln(SBuf);
+ }
+
+ /* The client is expecting to read back a citadel protocol response */
+ wc_printf("%s", ChrPtr(NBuf));
+ FreeStrBuf(&NBuf);
+ FreeStrBuf(&SBuf);
+}
+
+
+
/*
* Try to create an account manually after an OpenID was verified
*/
{
char buf[4096];
- if (havebstr("language")) {
- set_selected_language(bstr("language"));
- go_selected_language();
- }
+ snprintf(buf, sizeof buf,
+ "OIDS %s|%s/finalize_openid_login|%s",
+ bstr("openid_url"),
+ ChrPtr(site_prefix),
+ ChrPtr(site_prefix)
+ );
- if (havebstr("exit_action")) {
- do_logout();
+ serv_puts(buf);
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '2') {
+ syslog(LOG_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
+ http_redirect(&buf[4]);
return;
}
- if (havebstr("login_action")) {
- snprintf(buf, sizeof buf,
- "OIDS %s|%s/finalize_openid_login|%s",
- bstr("openid_url"),
- ChrPtr(site_prefix),
- ChrPtr(site_prefix)
- );
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '2') {
- syslog(LOG_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
- http_redirect(&buf[4]);
- return;
- }
- else {
- display_openid_login(&buf[4]);
- return;
- }
- }
-
- /* If we get to this point then something failed. */
- display_openid_login(_("Your password was not accepted."));
+ begin_burst();
+ output_headers(1, 0, 0, 0, 1, 0);
+ wc_printf("<html><body>");
+ escputs(&buf[4]);
+ wc_printf("</body></html>");
+ end_burst();
}
+
/*
* Complete the authentication using OpenID
* This function handles the positive or negative assertion from the user's Identity Provider
}
}
- /* If we were already logged in, this was an attempt to associate an OpenID account */
+ /* If we were already logged in, this was an attempt to associate an OpenID account
+ FIXME put this back in
if (already_logged_in) {
display_openids();
FreeStrBuf(&result);
FreeStrBuf(&logged_in_response);
return;
}
+ */
/* If this operation logged us in, either by connecting with an existing account or by
* auto-creating one using Simple Registration Extension, we're already on our way.
* or conflicts with an existing user. Either way the user will need to specify a new name.
*/
+/*
+ * FIXME make this work again!!!!
+ *
else if (!strcasecmp(ChrPtr(result), "verify_only")) {
putbstr("__claimed_id", claimed_id);
claimed_id = NULL;
do_template("openid_manual_create", NULL);
end_burst();
}
+*/
+
+
/* Did we manage to log in? If so, continue with the normal flow... */
- else if (WC->logged_in) {
- if (WC->need_regi) {
- display_reg(1);
- } else {
- do_welcome();
- }
+ if (WC->logged_in) {
+ begin_burst();
+ output_headers(1, 0, 0, 0, 1, 0);
+ do_template("authpopup_finished", NULL);
+ end_burst();
} else {
- display_openid_login(_("Your password was not accepted."));
+ begin_burst();
+ output_headers(1, 0, 0, 0, 1, 0);
+ wc_printf("<html><body>");
+ wc_printf(_("An error has occurred.")); /* FIXME do something prettier here */
+ wc_printf("</body></html>");
+ end_burst();
}
FreeStrBuf(&result);
if (StrLength(Buf) == 0) {
StrBufAppendBufPlain(Buf, "dotgoto?room=_BASEROOM_", -1, 0);
}
- lprintf(9, "Redirecting to user's start page: %s\n", ChrPtr(Buf));
+ syslog(9, "Redirecting to user's start page: %s\n", ChrPtr(Buf));
http_redirect(ChrPtr(Buf));
}
Buf = NewStrBuf();
memset(&Room, 0, sizeof(folder));
if (goto_config_room(Buf, &Room) != 0) {
- lprintf(9, "display_reg() exiting because goto_config_room() failed\n");
+ syslog(9, "display_reg() exiting because goto_config_room() failed\n");
if (during_login) {
- do_welcome();
+ pop_destination();
}
else {
display_main_menu();
FreeStrBuf(&Buf);
vcard_msgnum = locate_user_vcard_in_this_room(&VCMsg, &VCAtt);
if (vcard_msgnum < 0L) {
- lprintf(9, "display_reg() exiting because locate_user_vcard_in_this_room() failed\n");
+ syslog(9, "display_reg() exiting because locate_user_vcard_in_this_room() failed\n");
if (during_login) {
- do_welcome();
+ pop_destination();
}
else {
display_main_menu();
}
if (during_login) {
- do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "do_welcome", USERCONFIGROOM);
+ do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "pop", USERCONFIGROOM);
}
else {
StrBuf *ReturnTo;
- ReturnTo = NewStrBufPlain(HKEY("display_main_menu?gotofirst="));
+ ReturnTo = NewStrBufPlain(HKEY("display_main_menu?go="));
StrBufAppendBuf(ReturnTo, WC->CurRoom.name, 0);
do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, ChrPtr(ReturnTo), USERCONFIGROOM);
FreeStrBuf(&ReturnTo);
int ConditionalAide(StrBuf *Target, WCTemplputParams *TP)
{
wcsession *WCC = WC;
- return (WCC != NULL)? (WC->is_aide == 0) : 0;
+ return (WCC != NULL) ? ((WCC->logged_in == 0)||(WC->is_aide == 0)) : 0;
}
int ConditionalIsLoggedIn(StrBuf *Target, WCTemplputParams *TP)
{
wcsession *WCC = WC;
- return (WCC != NULL)? (WCC->logged_in == 0) : 0;
-}
-
+ return (WCC != NULL) ? (WCC->logged_in == 0) : 0;
-void _display_openid_login(void) {
- display_openid_login(NULL);
}
+
void _display_reg(void) {
display_reg(0);
}
hdr->HR.got_auth = AUTH_BASIC;
}
else
- lprintf(1, "Authentication scheme not supported! [%s]\n", ChrPtr(Line));
+ syslog(1, "Authentication scheme not supported! [%s]\n", ChrPtr(Line));
}
}
StrBufAppendBuf(hdr->HR.plainauth, hdr->HR.user_agent, 0);
hdr->HR.SessionKey = hashlittle(SKEY(hdr->HR.plainauth), 89479832);
/*
- lprintf(1, "CheckAuthBasic: calculated sessionkey %ld\n",
+ syslog(1, "CheckAuthBasic: calculated sessionkey %ld\n",
hdr->HR.SessionKey);
*/
}
RegisterHeaderHandler(HKEY("COOKIE"), Header_HandleCookie);
RegisterHeaderHandler(HKEY("AUTHORIZATION"), Header_HandleAuth);
- WebcitAddUrlHandler(HKEY(""), "", 0, do_welcome, ANONYMOUS|COOKIEUNNEEDED); /* no url pattern at all? Show login. */
+ /* no url pattern at all? Show login. */
+ WebcitAddUrlHandler(HKEY(""), "", 0, do_welcome, ANONYMOUS|COOKIEUNNEEDED);
+
+ /* some of these will be removed soon */
WebcitAddUrlHandler(HKEY("do_welcome"), "", 0, do_welcome, ANONYMOUS|COOKIEUNNEEDED);
- WebcitAddUrlHandler(HKEY("login"), "", 0, do_login, ANONYMOUS|COOKIEUNNEEDED);
- WebcitAddUrlHandler(HKEY("display_openid_login"), "", 0, _display_openid_login, ANONYMOUS);
WebcitAddUrlHandler(HKEY("openid_login"), "", 0, do_openid_login, ANONYMOUS);
WebcitAddUrlHandler(HKEY("finalize_openid_login"), "", 0, finalize_openid_login, ANONYMOUS);
WebcitAddUrlHandler(HKEY("openid_manual_create"), "", 0, openid_manual_create, ANONYMOUS);
- WebcitAddUrlHandler(HKEY("do_logout"), "", 0, do_logout, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
- WebcitAddUrlHandler(HKEY("ajax_login_username_password"), "", 0, ajax_login_username_password, AJAX);
WebcitAddUrlHandler(HKEY("validate"), "", 0, validate, 0);
WebcitAddUrlHandler(HKEY("do_welcome"), "", 0, do_welcome, 0);
WebcitAddUrlHandler(HKEY("display_reg"), "", 0, _display_reg, 0);
WebcitAddUrlHandler(HKEY("display_changepw"), "", 0, display_changepw, 0);
WebcitAddUrlHandler(HKEY("changepw"), "", 0, changepw, 0);
WebcitAddUrlHandler(HKEY("termquit"), "", 0, do_logout, 0);
-
-
+ WebcitAddUrlHandler(HKEY("do_logout"), "", 0, do_logout, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
+ WebcitAddUrlHandler(HKEY("ajax_login_username_password"), "", 0, ajax_login_username_password, AJAX|ANONYMOUS);
+ WebcitAddUrlHandler(HKEY("ajax_login_newuser"), "", 0, ajax_login_newuser, AJAX|ANONYMOUS);
RegisterConditional(HKEY("COND:AIDE"), 2, ConditionalAide, CTX_NONE);
RegisterConditional(HKEY("COND:LOGGEDIN"), 2, ConditionalIsLoggedIn, CTX_NONE);
RegisterConditional(HKEY("COND:MAY_CREATE_ROOM"), 2, ConditionalHaveAccessCreateRoom, CTX_NONE);