Anope IRC Services  Version 2.0
sasl.h
Go to the documentation of this file.
1 /*
2  *
3  * (C) 2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  */
8 
9 namespace SASL
10 {
11  struct Message
12  {
18  };
19 
20  class Mechanism;
21  struct Session;
22 
23  class Service : public ::Service
24  {
25  public:
26  Service(Module *o) : ::Service(o, "SASL::Service", "sasl") { }
27 
28  virtual void ProcessMessage(const Message &) = 0;
29 
30  virtual Anope::string GetAgent() = 0;
31 
32  virtual Session* GetSession(const Anope::string &uid) = 0;
33 
34  virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data) = 0;
35 
36  virtual void Succeed(Session *, NickCore *) = 0;
37  virtual void Fail(Session *) = 0;
38  virtual void SendMechs(Session *) = 0;
39  virtual void DeleteSessions(Mechanism *, bool = false) = 0;
40  virtual void RemoveSession(Session *) = 0;
41  };
42 
43  static ServiceReference<SASL::Service> sasl("SASL::Service", "sasl");
44 
45  struct Session
46  {
47  time_t created;
50 
51  Session(Mechanism *m, const Anope::string &u) : created(Anope::CurTime), uid(u), mech(m) { }
52  virtual ~Session()
53  {
54  if (sasl)
55  sasl->RemoveSession(this);
56  }
57  };
58 
59  /* PLAIN, EXTERNAL, etc */
60  class Mechanism : public ::Service
61  {
62  public:
63  Mechanism(Module *o, const Anope::string &sname) : Service(o, "SASL::Mechanism", sname) { }
64 
65  virtual Session* CreateSession(const Anope::string &uid) { return new Session(this, uid); }
66 
67  virtual void ProcessMessage(Session *session, const Message &) = 0;
68 
69  virtual ~Mechanism()
70  {
71  if (sasl)
72  sasl->DeleteSessions(this, true);
73  }
74  };
75 
77  {
79 
80  public:
81  IdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : ::IdentifyRequest(m, acc, pass), uid(id) { }
82 
84  {
85  if (!sasl)
86  return;
87 
89  if (!na || na->nc->HasExt("NS_SUSPENDED"))
90  return OnFail();
91 
92  Session *s = sasl->GetSession(uid);
93  if (s)
94  {
95  Log(Config->GetClient("NickServ")) << "A user identified to account " << this->GetAccount() << " using SASL";
96  sasl->Succeed(s, na->nc);
97  delete s;
98  }
99  }
100 
102  {
103  if (!sasl)
104  return;
105 
106  Session *s = sasl->GetSession(uid);
107  if (s)
108  {
109  sasl->Fail(s);
110  delete s;
111  }
112 
113  Anope::string accountstatus;
115  if (!na)
116  accountstatus = "nonexistent ";
117  else if (na->nc->HasExt("NS_SUSPENDED"))
118  accountstatus = "suspended ";
119 
120  Log(Config->GetClient("NickServ")) << "A user failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL";
121  }
122  };
123 }
Serialize::Reference< NickCore > nc
Definition: account.h:47
Anope::string target
Definition: sasl.h:14
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
Anope::string source
Definition: sasl.h:13
virtual ~Session()
Definition: sasl.h:52
Mechanism(Module *o, const Anope::string &sname)
Definition: sasl.h:63
Anope::string data
Definition: sasl.h:16
virtual void DeleteSessions(Mechanism *, bool=false)=0
virtual void Fail(Session *)=0
virtual void SendMechs(Session *)=0
Definition: base.h:49
CoreExport time_t CurTime
Definition: main.cpp:41
virtual ~Mechanism()
Definition: sasl.h:69
time_t created
Definition: sasl.h:47
virtual void Succeed(Session *, NickCore *)=0
Session(Mechanism *m, const Anope::string &u)
Definition: sasl.h:51
Definition: Config.cs:26
Anope::string type
Definition: service.h:86
static ServiceReference< SASL::Service > sasl("SASL::Service","sasl")
virtual Session * CreateSession(const Anope::string &uid)
Definition: sasl.h:65
Anope::string uid
Definition: sasl.h:48
#define anope_override
Definition: services.h:56
virtual void ProcessMessage(const Message &)=0
Anope::string ext
Definition: sasl.h:17
IdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass)
Definition: sasl.h:81
Anope::string type
Definition: sasl.h:15
Service(Module *o)
Definition: sasl.h:26
Reference< Mechanism > mech
Definition: sasl.h:49
Anope::string uid
Definition: sasl.h:78
virtual Session * GetSession(const Anope::string &uid)=0
virtual void ProcessMessage(Session *session, const Message &)=0
virtual Anope::string GetAgent()=0
Definition: logger.h:53
virtual void RemoveSession(Session *)=0
virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data)=0
void OnSuccess() anope_override
Definition: sasl.h:83
Definition: defs.h:55
void OnFail() anope_override
Definition: sasl.h:101
Definition: anope.h:20
const Anope::string & GetAccount() const
Definition: account.h:250