op.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "channel.h"
  19. #include "conf.h"
  20. #include "log.h"
  21. #include "parse.h"
  22. #include "messages.h"
  23. #include "irc-write.h"
  24. #include <exp.h>
  25. #include "op.h"
  26. /**
  27. * Return and log a "no privileges" message.
  28. */
  29. GLOBAL bool
  30. Op_NoPrivileges(CLIENT * Client, REQUEST * Req)
  31. {
  32. CLIENT *from = NULL;
  33. if (Req->prefix)
  34. from = Client_Search(Req->prefix);
  35. if (from) {
  36. Log(LOG_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"",
  37. Req->prefix, Client_Mask(Client), Req->command);
  38. return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
  39. Client_ID(from));
  40. } else {
  41. Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"",
  42. Client_Mask(Client), Req->command);
  43. return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
  44. Client_ID(Client));
  45. }
  46. } /* Op_NoPrivileges */
  47. /**
  48. * Check that the client is an IRC operator allowed to administer this server.
  49. */
  50. GLOBAL bool
  51. Op_Check(CLIENT * Client, REQUEST * Req)
  52. {
  53. CLIENT *c;
  54. assert(Client != NULL);
  55. assert(Req != NULL);
  56. if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
  57. c = Client_Search(Req->prefix);
  58. else
  59. c = Client;
  60. if (!c)
  61. return false;
  62. if (!Client_HasMode(c, 'o'))
  63. return false;
  64. if (!Client_OperByMe(c) && !Conf_AllowRemoteOper)
  65. return false;
  66. /* The client is an local IRC operator, or this server is configured
  67. * to trust remote operators. */
  68. return true;
  69. } /* Op_Check */