op.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * Please read the file COPYING, README and AUTHORS for more information.
  10. *
  11. * IRC operator functions
  12. */
  13. #include "portab.h"
  14. #include "imp.h"
  15. #include <assert.h>
  16. #include <string.h>
  17. #include "conn.h"
  18. #include "client.h"
  19. #include "channel.h"
  20. #include "conf.h"
  21. #include "log.h"
  22. #include "parse.h"
  23. #include "messages.h"
  24. #include "irc-write.h"
  25. #include <exp.h>
  26. #include "op.h"
  27. /**
  28. * Return and log a "no privileges" message.
  29. */
  30. GLOBAL bool
  31. Op_NoPrivileges(CLIENT * Client, REQUEST * Req)
  32. {
  33. CLIENT *from = NULL;
  34. if (Req->prefix)
  35. from = Client_Search(Req->prefix);
  36. if (from) {
  37. Log(LOG_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"",
  38. Req->prefix, Client_Mask(Client), Req->command);
  39. return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
  40. Client_ID(from));
  41. } else {
  42. Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"",
  43. Client_Mask(Client), Req->command);
  44. return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
  45. Client_ID(Client));
  46. }
  47. } /* Op_NoPrivileges */
  48. /**
  49. * Check that the client is an IRC operator allowed to administer this server.
  50. */
  51. GLOBAL bool
  52. Op_Check(CLIENT * Client, REQUEST * Req)
  53. {
  54. CLIENT *c;
  55. assert(Client != NULL);
  56. assert(Req != NULL);
  57. if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
  58. c = Client_Search(Req->prefix);
  59. else
  60. c = Client;
  61. if (!c)
  62. return false;
  63. if (!Client_HasMode(c, 'o'))
  64. return false;
  65. if (!Client_OperByMe(c) && !Conf_AllowRemoteOper)
  66. return false;
  67. /* The client is an local IRC operator, or this server is configured
  68. * to trust remote operators. */
  69. return true;
  70. } /* Op_Check */