]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/op.c
6cb914353e72984a26f8c772c4aab066f6cb3216
[ngircd-alex.git] / src / ngircd / op.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2013 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 /**
30  * Return and log a "no privileges" message.
31  */
32 GLOBAL bool
33 Op_NoPrivileges(CLIENT * Client, REQUEST * Req)
34 {
35         CLIENT *from = NULL;
36
37         if (Req->prefix)
38                 from = Client_Search(Req->prefix);
39
40         if (from) {
41                 Log(LOG_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"!",
42                     Req->prefix, Client_Mask(Client), Req->command);
43                 return IRC_WriteErrClient(from, ERR_NOPRIVILEGES_MSG,
44                                           Client_ID(from));
45         } else {
46                 Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"!",
47                     Client_Mask(Client), Req->command);
48                 return IRC_WriteErrClient(Client, ERR_NOPRIVILEGES_MSG,
49                                           Client_ID(Client));
50         }
51 } /* Op_NoPrivileges */
52
53 /**
54  * Check that the originator of a request is an IRC operator and allowed
55  * to administer this server.
56  *
57  * @param CLient Client from which the command has been received.
58  * @param Req Request structure.
59  * @return CLIENT structure of the client that initiated the command or
60  *         NULL if client is not allowed to execute operator commands.
61  */
62 GLOBAL CLIENT *
63 Op_Check(CLIENT * Client, REQUEST * Req)
64 {
65         CLIENT *c;
66
67         assert(Client != NULL);
68         assert(Req != NULL);
69
70         if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
71                 c = Client_Search(Req->prefix);
72         else
73                 c = Client;
74
75         if (!c)
76                 return NULL;
77         if (Client_Type(Client) == CLIENT_SERVER
78             && Client_Type(c) == CLIENT_SERVER)
79                 return c;
80         if (!Client_HasMode(c, 'o'))
81                 return NULL;
82         if (Client_Conn(c) <= NONE && !Conf_AllowRemoteOper)
83                 return NULL;
84
85         /* The client is an local IRC operator, or this server is configured
86          * to trust remote operators. */
87         return c;
88 } /* Op_Check */
89
90 /* -eof- */