root/nntp/authinfo.cc

Revision 868b365c127bbf4f0b52f22da03e32a94a4f6653, 6.1 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 3 years ago)

Update the project blurb

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2009 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#include "connection.hh"
21
22#include "../db/db.hh"
23#include "../db/user.hh"
24#include "../logger/logline.hh"
25
26namespace nntp {
27
28        class authinfo : public connection::command
29        {
30        public:
31                authinfo(std::string s) {
32                        connection::register_command(s, this);
33                }
34
35                connection::continuation::ptr
36                perform(connection::cb, const std::string [],  size_t) const;
37
38                void write_capability_line(connection::cb c) const {
39                        if (c.authenticated()) return;
40                        if (c.tls_active())
41                        {
42                                c.send_line("AUTHINFO USER");
43                        }
44                        else
45                        {
46                                c.send_line("AUTHINFO");
47                        }
48                }
49        };
50
51
52        connection::continuation::ptr
53        authinfo::perform(connection::cb c,
54                          const std::string args[],
55                          size_t nargs)
56                const
57        {
58                if (c.authenticated())
59                {
60                        c.send_line("502 multiple authentication "
61                                    "not permitted");
62                        return c.dispatch();
63                }
64                std::string kw = args[0];
65                boost::to_upper(kw);
66                if (kw == "USER")
67                {
68                        if (nargs == 1)
69                        {
70                                c.send_line("501 Username missing");
71                                return c.dispatch();
72                        }
73                        if (nargs > 2)
74                        {
75                                c.send_line("503 spaces in username are "
76                                            "not supported");
77                                return c.dispatch();
78                        }
79                        c.identity() = c.dbase().lookup_user(args[1]);
80                        if (!c.tls_active() &&
81                            (!c.identity() ||
82                             !c.identity()->allow_cleartext_password()))
83                        {
84                                c.send_line("483 STARTTLS required");
85                                return c.dispatch();
86                        }
87                        if (!c.identity())
88                        {
89                                logger::logline ll;
90                                ll << c.loghead()
91                                   << "AUTHINFO USER with unknown user '"
92                                   << args[1]
93                                   << "'";
94                                ll.close();
95                        }
96                        c.identified() = true;
97                        c.send_line("381 AUTHINFO PASS required");
98                        return c.dispatch();
99                }
100                else if (kw == "PASS")
101                {
102                        if (nargs == 1)
103                        {
104                                c.send_line("501 password missing");
105                                return c.dispatch();
106                        }
107                        if (!c.identified())
108                        {
109                                c.send_line("482 AUTHINFO USER required");
110                                return c.dispatch();
111                        }
112                        /* The standard apparently requires us to
113                         * diagnose (503) spaces in the password if we
114                         * don't support them, but I think that would
115                         * be bad security practice, so we'll treat it
116                         * as failed password match. */
117                        if (c.identity() &&
118                            nargs == 2 &&
119                            c.identity()->verify_password(args[1]))
120                        {
121                                c.authenticated() = true;
122                                c.send_line("281 cool");
123                                return c.dispatch();
124                        }
125
126                        if (c.identity())
127                        {
128                                logger::logline ll;
129                                ll << c.loghead()
130                                   << "AUTHINFO PASS failed for user '"
131                                   << c.identity()->get_userid()
132                                   << "'";
133                                ll.close();
134                        }
135                        return c.delay_fail("481 password incorrect");
136                }
137                else if (kw == "SASL" ||
138                         kw == "SIMPLE" ||
139                         kw == "GENERIC")
140                {
141                        logger::logline ll;
142                        ll << c.loghead()
143                           << "AUTHINFO "
144                           << args[0]
145                           << " attempted (not supported)";
146                        ll.close();
147                        c.send_line("503 AUTHINFO " + args[0] +
148                                    " not supported");
149                        return c.dispatch();
150                }
151                else
152                {
153                        c.send_line("501 syntax error");
154                        return c.dispatch();
155                }
156        }
157};
158namespace {
159        nntp::authinfo authinfo("authinfo");
160}
Note: See TracBrowser for help on using the browser.