op.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"!",
  36. Req->prefix, Client_Mask(Client), Req->command);
  37. return IRC_WriteErrClient(from, ERR_NOPRIVILEGES_MSG,
  38. Client_ID(from));
  39. } else {
  40. Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"!",
  41. Client_Mask(Client), Req->command);
  42. return IRC_WriteErrClient(Client, ERR_NOPRIVILEGES_MSG,
  43. Client_ID(Client));
  44. }
  45. } /* Op_NoPrivileges */
  46. /**
  47. * Check that the originator of a request is an IRC operator and allowed
  48. * to administer this server.
  49. *
  50. * @param CLient Client from which the command has been received.
  51. * @param Req Request structure.
  52. * @return CLIENT structure of the client that initiated the command or
  53. * NULL if client is not allowed to execute operator commands.
  54. */
  55. GLOBAL CLIENT *
  56. Op_Check(CLIENT * Client, REQUEST * Req)
  57. {
  58. CLIENT *c;
  59. assert(Client != NULL);
  60. assert(Req != NULL);
  61. if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
  62. c = Client_Search(Req->prefix);
  63. else
  64. c = Client;
  65. if (!c)
  66. return NULL;
  67. if (Client_Type(Client) == CLIENT_SERVER
  68. && Client_Type(c) == CLIENT_SERVER)
  69. return c;
  70. if (!Client_HasMode(c, 'o'))
  71. return NULL;
  72. if (Client_Conn(c) <= NONE && !Conf_AllowRemoteOper)
  73. return NULL;
  74. /* The client is an local IRC operator, or this server is configured
  75. * to trust remote operators. */
  76. return c;
  77. } /* Op_Check */
  78. /* -eof- */