]> code.citadel.org Git - citadel.git/blob - webcit/auth.c
Got lots of goto, ungoto, skip, etc. working
[citadel.git] / webcit / auth.c
1 /*
2  * auth.c
3  *
4  * This file contains code which relates to authentication of users to Citadel.
5  *
6  */
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <string.h>
13 #include <errno.h>
14 #include "webcit.h"
15
16
17 /*
18  * This function needs to get called whenever a PASS or NEWU succeeds
19  */
20 void become_logged_in(char *user, char *pass, char *serv_response) {
21         logged_in = 1;
22         extract(wc_username, &serv_response[4], 0);
23         strcpy(wc_password, pass);
24         axlevel = extract_int(&serv_response[4], 1);
25         if (axlevel >=6) is_aide = 1;
26         }
27
28
29 void do_login() {
30         char buf[256];
31         char actual_username[256];
32
33         if (!strcasecmp(bstr("action"), "Login")) {
34                 serv_printf("USER %s", bstr("name"));
35                 serv_gets(buf);
36                 if (buf[0]=='3') {
37                         serv_printf("PASS %s", bstr("pass"));
38                         serv_gets(buf);
39                         if (buf[0]=='2') {
40                                 become_logged_in(bstr("name"),
41                                         bstr("pass"), buf);
42                                 }
43                         }
44                 }
45
46         if (logged_in) {
47                 output_static("frameset.html");
48                 }
49         else {
50                 printf("HTTP/1.0 200 OK\n");
51                 output_headers();
52                 wprintf("<HTML><HEAD><TITLE>Nope</TITLE></HEAD><BODY>\n");
53                 wprintf("Your password was not accepted.\n");
54                 wprintf("<HR><A HREF=\"/\">Try again</A>\n");
55                 wprintf("</BODY></HTML>\n");
56                 wDumpContent();
57                 }
58
59         }
60
61 void do_welcome() {
62         printf("HTTP/1.0 200 OK\n");
63         output_headers();
64         wprintf("<HTML><BODY>\n");
65         wprintf("<CENTER><H1>");
66         escputs(wc_username);
67         wprintf("</H1>\n");
68         /* other stuff here */
69         wprintf("</BODY></HTML>\n");
70         wDumpContent();
71         }