summaryrefslogtreecommitdiff
path: root/src/auth/AuthClientHandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth/AuthClientHandler.h')
-rw-r--r--src/auth/AuthClientHandler.h106
1 files changed, 27 insertions, 79 deletions
diff --git a/src/auth/AuthClientHandler.h b/src/auth/AuthClientHandler.h
index daad37c64ec..6aaeb542c09 100644
--- a/src/auth/AuthClientHandler.h
+++ b/src/auth/AuthClientHandler.h
@@ -24,90 +24,29 @@
#include "common/Timer.h"
-class Message;
+class MAuthReply;
class AuthClient;
-
class AuthClientHandler;
class AuthClientProtocolHandler {
protected:
- AuthClientHandler *client;
- Message *msg;
- bool got_response;
- uint32_t id;
- Mutex lock;
AuthAuthorizer authorizer;
-
- // session state
- int status;
-
- virtual void _reset() {}
-
- Cond cond;
-
- virtual int _handle_response(int ret, bufferlist::iterator& iter) = 0;
- virtual int _build_request() = 0;
- virtual Message *_get_new_msg() = 0;
- virtual bufferlist& _get_msg_bl(Message *m) = 0;
+ AuthClientHandler *client;
public:
- AuthClientProtocolHandler(AuthClientHandler *ch);
- virtual ~AuthClientProtocolHandler();
- int build_request();
+ AuthClientProtocolHandler(AuthClientHandler *c) : client(c) {}
+ virtual ~AuthClientProtocolHandler() {}
- int handle_response(int ret, bufferlist::iterator& iter);
-
- void reset() {
- status = 0;
- _reset();
- }
+ virtual int get_protocol() = 0;
- int do_async_request();
+ virtual void reset() = 0;
+ virtual int build_request(bufferlist& bl) = 0;
+ virtual int handle_response(int ret, bufferlist::iterator& iter) = 0;
};
-class AuthClientAuthenticateHandler : public AuthClientProtocolHandler {
- int request_state;
- int response_state;
-
- /* envelope protocol parameters */
- uint64_t server_challenge;
-
- int generate_authenticate_request(bufferlist& bl);
- uint32_t want;
- uint32_t have;
-protected:
- void _reset() {
- request_state = 0;
- response_state = 0;
- }
-
- int _build_request();
- int _handle_response(int ret, bufferlist::iterator& iter);
- Message *_get_new_msg();
- bufferlist& _get_msg_bl(Message *m);
-public:
- AuthClientAuthenticateHandler(AuthClientHandler *client, uint32_t _want, uint32_t _have) :
- AuthClientProtocolHandler(client), want(_want), have(_have) { reset(); }
- void set_want_keys(__u32 keys) {
- want = keys;
- }
- void add_want_keys(__u32 keys) {
- want |= keys;
- }
-};
-
-class AuthClientAuthorizeHandler : public AuthClientProtocolHandler {
- uint32_t service_id;
-protected:
- int _build_request();
- int _handle_response(int ret, bufferlist::iterator& iter);
- Message *_get_new_msg();
- bufferlist& _get_msg_bl(Message *m);
-public:
- AuthClientAuthorizeHandler(AuthClientHandler *client, uint32_t sid) : AuthClientProtocolHandler(client), service_id(sid) {}
-};
+// ----------------------------------------
class AuthClientHandler {
friend class AuthClientProtocolHandler;
@@ -115,12 +54,9 @@ class AuthClientHandler {
Mutex lock;
AuthClient *client;
+ AuthClientProtocolHandler *proto;
- uint32_t max_proto_handlers;
- map<uint32_t, AuthClientProtocolHandler *> handlers_map;
-
- AuthClientProtocolHandler *_get_proto_handler(uint32_t id);
- uint32_t _add_proto_handler(AuthClientProtocolHandler *handler);
+ AuthClientProtocolHandler *get_protocol_handler(int id);
public:
EntityName name;
@@ -129,14 +65,21 @@ public:
AuthTicketManager tickets;
- AuthClientHandler() : lock("AuthClientHandler::lock"),
- client(NULL), max_proto_handlers(0) { }
+ AuthClientHandler(AuthClient *c) : lock("AuthClientHandler::lock"),
+ client(c), proto(NULL),
+ want(0), have(0) { }
+
void init(EntityName& n) { name = n; }
void set_want_keys(__u32 keys) {
Mutex::Locker l(lock);
want = keys;
}
+ void add_want_keys(__u32 keys) {
+ Mutex::Locker l(lock);
+ want |= keys;
+ }
+
bool have_keys(__u32 k) {
Mutex::Locker l(lock);
return (k & have) == have;
@@ -145,9 +88,14 @@ public:
Mutex::Locker l(lock);
return (want & have) == have;
}
- int handle_response(int trans_id, Message *response);
- int send_session_request(AuthClient *client, AuthClientProtocolHandler *handler);
+ void reset() {
+ if (proto)
+ proto->reset();
+ }
+ int send_request();
+ int handle_response(MAuthReply *m);
+
void tick();
bool build_authorizer(uint32_t service_id, AuthAuthorizer& authorizer);