00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef USE_PCH
00017 #include "sys.h"
00018 #endif
00019
00020 #include "AuthState.h"
00021 #include "Matcher.h"
00022 #include "keys.h"
00023 #include "Identity.h"
00024 #include "Authentication.h"
00025
00026
00027
00028 AuthState::AuthState(ServerConnection& server_connection) : event_client_ct(), M_server_connection(server_connection)
00029 #ifdef CWDEBUG
00030 , M_auth_one_second_passed("AuthState::M_auth_one_second_passed"),
00031 M_auth_ping_argument("AuthState::M_auth_ping_argument"),
00032 M_doing_hostname_lookup("AuthState::M_doing_hostname_lookup"),
00033 M_finished_hostname_lookup("AuthState::M_finished_hostname_lookup"),
00034 M_doing_ident_lookup("AuthState::M_doing_ident_lookup"),
00035 M_finished_ident_lookup("AuthState::M_finished_ident_lookup")
00036 #endif
00037 {
00038 Dout(dc::objects, "Constructing AuthState(" << server_connection << ')');
00039
00040
00041
00042
00043
00044
00045 MatchRequest match_request1(M_server_connection.secondary_connection());
00046 match_request1(keys::NOTICE).exactmatch("AUTH", 0).exactmatch("*** Looking up your hostname", 1);
00047 M_server_connection.server_session().message_event_server()(match_request1, *this, &AuthState::auth_notice_looking_up_hostname);
00048
00049
00050 MatchRequest match_request2(M_server_connection.secondary_connection());
00051 match_request2(keys::NOTICE).exactmatch("AUTH", 0).exactmatch("*** Checking Ident", 1);
00052 M_server_connection.server_session().message_event_server()(match_request2, *this, &AuthState::auth_notice_looking_up_ident);
00053
00054
00055 timeval delay = { 1, 0 };
00056 timerRequest(delay, *this, &AuthState::auth_timeout);
00057
00058
00059 ON_TRUE(
00060 ((*M_auth_one_second_passed &&
00061 (!*M_doing_hostname_lookup || *M_finished_hostname_lookup) &&
00062 (!*M_doing_ident_lookup || *M_finished_ident_lookup)) ||
00063 (*M_finished_hostname_lookup &&
00064 *M_finished_ident_lookup)) &&
00065 *M_auth_ping_argument != ConstExpression<std::string>(""),
00066 *this, &AuthState::send_pong_and_mode);
00067
00068
00069 M_server_connection.identity().authentication().send_authentication(M_server_connection);
00070 }
00071
00072
00073
00074
00075 void AuthState::send_pong_and_mode(ExpressionEventType const& event_type)
00076 {
00077 M_server_connection.send_pong_and_mode(event_type);
00078 }
00079
00080
00081
00082
00083 AuthState::~AuthState()
00084 {
00085 Dout(dc::objects, "Destructing AuthState " << *this << ".");
00086 cancel_all_requests();
00087 }
00088
00089
00090
00091
00092
00093 void AuthState::auth_timeout(timer_event_type_ct const& LIBCW_UNUSED_UNLESS_DEBUG(expired_at))
00094 {
00095 DoutEntering(dc::debug, "AuthState::auth_timeout(" << expired_at.get_expire_time() << ")");
00096 M_auth_one_second_passed = true;
00097 }
00098
00099
00100
00101
00102
00103 void AuthState::auth_notice_looking_up_hostname(MatcherEventType const& event_type)
00104 {
00105 DoutEntering(dc::debug, "AuthState::auth_notice_looking_up_hostname(" << event_type << ")");
00106 M_doing_hostname_lookup = true;
00107 M_server_connection.successful_connection();
00108
00109 MatchRequest match_request(M_server_connection.secondary_connection());
00110 match_request(keys::NOTICE).exactmatch("AUTH", 0).wildcard("*your hostname*", 1);
00111 M_server_connection.server_session().message_event_server()(match_request, *this, &AuthState::auth_notice_fin_hostname);
00112 }
00113
00114
00115
00116
00117
00118 void AuthState::auth_notice_fin_hostname(MatcherEventType const& event_type)
00119 {
00120 DoutEntering(dc::debug, "AuthState::auth_notice_fin_hostname(" << event_type << ")");
00121 M_finished_hostname_lookup = true;
00122 }
00123
00124
00125
00126
00127
00128 void AuthState::auth_notice_looking_up_ident(MatcherEventType const& event_type)
00129 {
00130 DoutEntering(dc::debug, "AuthState::auth_notice_looking_up_ident(" << event_type << ")");
00131 M_doing_ident_lookup = true;
00132 M_server_connection.successful_connection();
00133
00134 MatchRequest match_request(M_server_connection.secondary_connection());
00135 match_request(keys::NOTICE).exactmatch("AUTH", 0).wildcard("*ident response*", 1);
00136 M_server_connection.server_session().message_event_server()(match_request, *this, &AuthState::auth_notice_fin_ident);
00137 }
00138
00139
00140
00141
00142
00143 void AuthState::auth_notice_fin_ident(MatcherEventType const& event_type)
00144 {
00145 DoutEntering(dc::debug, "AuthState::auth_notice_fin_ident(" << event_type << ")");
00146 M_finished_ident_lookup = true;
00147 }
00148