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