op.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
  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. #include "portab.h"
  12. /**
  13. * @file
  14. * IRC operator functions
  15. */
  16. #include <assert.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 "op.h"
  25. /**
  26. * Return and log a "no privileges" message.
  27. */
  28. GLOBAL bool
  29. Op_NoPrivileges(CLIENT * Client, REQUEST * Req)
  30. {
  31. CLIENT *from = NULL;
  32. if (Req->prefix)
  33. from = Client_Search(Req->prefix);
  34. if (from) {
  35. Log(LOG_ERR|LOG_snotice,
  36. "No privileges: client \"%s\" (%s), command \"%s\"!",
  37. Req->prefix, Client_Mask(Client), Req->command);
  38. return IRC_WriteErrClient(from, ERR_NOPRIVILEGES_MSG,
  39. Client_ID(from));
  40. } else {
  41. Log(LOG_ERR|LOG_snotice,
  42. "No privileges: client \"%s\", command \"%s\"!",
  43. Client_Mask(Client), Req->command);
  44. return IRC_WriteErrClient(Client, ERR_NOPRIVILEGES_MSG,
  45. Client_ID(Client));
  46. }
  47. } /* Op_NoPrivileges */
  48. /**
  49. * Check that the originator of a request is an IRC operator and allowed
  50. * to administer this server.
  51. *
  52. * @param CLient Client from which the command has been received.
  53. * @param Req Request structure.
  54. * @return CLIENT structure of the client that initiated the command or
  55. * NULL if client is not allowed to execute operator commands.
  56. */
  57. GLOBAL CLIENT *
  58. Op_Check(CLIENT * Client, REQUEST * Req)
  59. {
  60. CLIENT *c;
  61. assert(Client != NULL);
  62. assert(Req != NULL);
  63. if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
  64. c = Client_Search(Req->prefix);
  65. else
  66. c = Client;
  67. if (!c)
  68. return NULL;
  69. if (Client_Type(Client) == CLIENT_SERVER
  70. && Client_Type(c) == CLIENT_SERVER)
  71. return c;
  72. if (!Client_HasMode(c, 'o'))
  73. return NULL;
  74. if (Client_Conn(c) <= NONE && !Conf_AllowRemoteOper)
  75. return NULL;
  76. /* The client is an local IRC operator, or this server is configured
  77. * to trust remote operators. */
  78. return c;
  79. } /* Op_Check */
  80. /* -eof- */