auth.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef _AUTH_H
  2. # define _AUTH_H
  3. # include "crypt.h"
  4. #include <bdlib/src/String.h>
  5. #include <bdlib/src/HashTable.h>
  6. class RfcString;
  7. #define AUTHED 1
  8. #define AUTHING 2
  9. /* These are what we are expecting back from the user */
  10. #define AUTH_PASS 3
  11. #define AUTH_HASH 4
  12. #define AUTH_BDHASH 5
  13. class Auth {
  14. public:
  15. Auth(const RfcString&, const char *, struct userrec * = NULL);
  16. ~Auth();
  17. inline int Status(void) const noexcept __attribute__((pure)) {
  18. return status;
  19. }
  20. int Status(int newstat) noexcept {
  21. status = newstat;
  22. return Status();
  23. }
  24. void MakeHash() noexcept;
  25. bool Authed() const noexcept __attribute__((pure)) {
  26. return (status == AUTHED);
  27. }
  28. bool GetIdx(const char *) noexcept;
  29. void Done() noexcept;
  30. void NewNick(const RfcString&) noexcept;
  31. static Auth *Find(const char * host) noexcept __attribute__((pure));
  32. static void NullUsers(const RfcString&) noexcept;
  33. static void NullUsers(void) noexcept;
  34. static void FillUsers(void) noexcept;
  35. static void ExpireAuths() noexcept;
  36. static void InitTimer() noexcept;
  37. static void DeleteAll() noexcept;
  38. static void TellAuthed(int) noexcept;
  39. struct userrec *user;
  40. time_t authtime; /* what time they authed at */
  41. time_t atime; /* when they last were active */
  42. int idx; /* do they have an associated idx? */
  43. char hash[MD5_HASH_LENGTH + 1]; /* used for dcc authing */
  44. char rand[51];
  45. RfcString nick;
  46. char host[UHOSTLEN];
  47. static bd::HashTable<bd::String, Auth*> ht_host;
  48. static bd::HashTable<RfcString, Auth*> ht_nick;
  49. private:
  50. int status;
  51. };
  52. void makehash(struct userrec *u, const char *randstring, char *out, size_t out_size);
  53. int check_auth_dcc(Auth *, const char *, const char *);
  54. #endif /* !_AUTH_H */