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