summaryrefslogtreecommitdiff
path: root/src/auth/AuthClientHandler.h
blob: 24df969994a872de5ca13382e31257aeef96930b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */

#ifndef CEPH_AUTHCLIENTHANDLER_H
#define CEPH_AUTHCLIENTHANDLER_H


#include "auth/Auth.h"

#include "common/Mutex.h"
#include "common/Cond.h"

#include "common/Timer.h"

class CephContext;
class MAuthReply;
class AuthClientHandler;
class RotatingKeyRing;

class AuthClientHandler {
protected:
  CephContext *cct;
  EntityName name;
  uint64_t global_id;
  uint32_t want;
  uint32_t have;
  uint32_t need;

public:
  AuthClientHandler(CephContext *cct_) 
    : cct(cct_), global_id(0), want(CEPH_ENTITY_TYPE_AUTH), have(0), need(0) {}
  virtual ~AuthClientHandler() {}

  void init(EntityName& n) { name = n; }
  
  void set_want_keys(__u32 keys) {
    want = keys | CEPH_ENTITY_TYPE_AUTH;
    validate_tickets();
  }
  void add_want_keys(__u32 keys) {
    want |= keys;
    validate_tickets();
  }   

  bool have_keys(__u32 k) {
    validate_tickets();
    return (k & have) == have;
  }
  bool have_keys() {
    validate_tickets();
    return (want & have) == have;
  }


  virtual int get_protocol() = 0;

  virtual void reset() = 0;
  virtual int build_request(bufferlist& bl) = 0;
  virtual int handle_response(int ret, bufferlist::iterator& iter) = 0;
  virtual bool build_rotating_request(bufferlist& bl) = 0;

  virtual void tick() = 0;

  virtual AuthAuthorizer *build_authorizer(uint32_t service_id) = 0;

  virtual void validate_tickets() = 0;
  virtual bool need_tickets() = 0;

  virtual void set_global_id(uint64_t id) = 0;
  uint64_t get_global_id() { return global_id; }
};


extern AuthClientHandler *get_auth_client_handler(CephContext *cct,
				      int proto, RotatingKeyRing *rkeys);

#endif