op.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "portab.h"
  12. /**
  13. * @file
  14. * IRC operator functions
  15. */
  16. #include "imp.h"
  17. #include <assert.h>
  18. #include <string.h>
  19. #include "conn.h"
  20. #include "channel.h"
  21. #include "conf.h"
  22. #include "log.h"
  23. #include "parse.h"
  24. #include "messages.h"
  25. #include "irc-write.h"
  26. #include <exp.h>
  27. #include "op.h"
  28. /**
  29. * Return and log a "no privileges" message.
  30. */
  31. GLOBAL bool
  32. Op_NoPrivileges(CLIENT * Client, REQUEST * Req)
  33. {
  34. CLIENT *from = NULL;
  35. if (Req->prefix)
  36. from = Client_Search(Req->prefix);
  37. if (from) {
  38. Log(LOG_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"",
  39. Req->prefix, Client_Mask(Client), Req->command);
  40. return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
  41. Client_ID(from));
  42. } else {
  43. Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"",
  44. Client_Mask(Client), Req->command);
  45. return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
  46. Client_ID(Client));
  47. }
  48. } /* Op_NoPrivileges */
  49. /**
  50. * Check that the originator of a request is an IRC operator and allowed
  51. * to administer this server.
  52. *
  53. * @param CLient Client from which the command has been received.
  54. * @param Req Request structure.
  55. * @return CLIENT structure of the client that initiated the command or
  56. * NULL if client is not allowed to execute operator commands.
  57. */
  58. GLOBAL CLIENT *
  59. Op_Check(CLIENT * Client, REQUEST * Req)
  60. {
  61. CLIENT *c;
  62. assert(Client != NULL);
  63. assert(Req != NULL);
  64. if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
  65. c = Client_Search(Req->prefix);
  66. else
  67. c = Client;
  68. if (!c)
  69. return NULL;
  70. if (Client_Type(Client) == CLIENT_SERVER
  71. && Client_Type(c) == CLIENT_SERVER)
  72. return c;
  73. if (!Client_HasMode(c, 'o'))
  74. return NULL;
  75. if (!Client_OperByMe(c) && !Conf_AllowRemoteOper)
  76. return NULL;
  77. /* The client is an local IRC operator, or this server is configured
  78. * to trust remote operators. */
  79. return c;
  80. } /* Op_Check */
  81. /* -eof- */