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