]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/op.c
Streamline punctuation of log messages
[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 /**
61  * Check that the originator of a request is an IRC operator and allowed
62  * to administer this server.
63  *
64  * @param CLient Client from which the command has been received.
65  * @param Req Request structure.
66  * @return CLIENT structure of the client that initiated the command or
67  *         NULL if client is not allowed to execute operator commands.
68  */
69 GLOBAL CLIENT *
70 Op_Check(CLIENT * Client, REQUEST * Req)
71 {
72         CLIENT *c;
73
74         assert(Client != NULL);
75         assert(Req != NULL);
76
77         if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
78                 c = Client_Search(Req->prefix);
79         else
80                 c = Client;
81
82         if (!c)
83                 return NULL;
84         if (Client_Type(Client) == CLIENT_SERVER
85             && Client_Type(c) == CLIENT_SERVER)
86                 return c;
87         if (!Client_HasMode(c, 'o'))
88                 return NULL;
89         if (Client_Conn(c) <= NONE && !Conf_AllowRemoteOper)
90                 return NULL;
91
92         /* The client is an local IRC operator, or this server is configured
93          * to trust remote operators. */
94         return c;
95 } /* Op_Check */
96
97
98 /* -eof- */