File indexing completed on 2024-04-28 16:59:41

0001 /*
0002    Copyright (C) 2013 Andreas Hartmetz <ahartmetz@gmail.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LGPL.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 
0019    Alternatively, this file is available under the Mozilla Public License
0020    Version 1.1.  You may obtain a copy of the License at
0021    http://www.mozilla.org/MPL/
0022 */
0023 
0024 #ifndef AUTHCLIENT_H
0025 #define AUTHCLIENT_H
0026 
0027 #include "itransportlistener.h"
0028 
0029 #include "iovaluetypes.h"
0030 
0031 #include <string>
0032 
0033 // TODO we are currently handling all authentication from here; later this class should only
0034 //      enumerate client and server auth mechanisms and then instantiate and pass control to
0035 //      the right IAuthMechanism implementation (with or without staying around as an intermediate).
0036 
0037 class ICompletionListener;
0038 
0039 class AuthClient : public ITransportListener
0040 {
0041 public:
0042     explicit AuthClient(ITransport *transport);
0043 
0044     // reimplemented from ITransportListener
0045     IO::Status handleTransportCanRead() override;
0046 
0047     bool isFinished() const;
0048     bool isAuthenticated() const;
0049     bool isUnixFdPassingEnabled() const;
0050 
0051     void setCompletionListener(ICompletionListener *);
0052 
0053 private:
0054     bool readLine();
0055     bool isEndOfLine() const;
0056     void sendNextAuthMethod();
0057     void advanceState();
0058 
0059     enum State {
0060         InitialState,
0061         ExpectOkState,
0062         ExpectUnixFdResponseState,
0063         AuthenticationFailedState,
0064         AuthenticatedState
0065     };
0066 
0067     enum AuthMethods {
0068         AuthExternal,
0069         AuthAnonymous,
0070         LastAuthMethod // keep this last!
0071     };
0072 
0073     State m_state;
0074     int m_nextAuthMethod;
0075     bool m_fdPassingEnabled;
0076     std::string m_line;
0077     ICompletionListener *m_completionListener;
0078 };
0079 
0080 #endif