]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/op.c
New "module" op.c/op.h for IRC operator related functions
[ngircd-alex.git] / src / ngircd / op.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
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  * IRC operator functions
12  */
13
14
15 #include "portab.h"
16
17 #include "imp.h"
18 #include <assert.h>
19 #include <string.h>
20
21 #include "conn.h"
22 #include "client.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 <exp.h>
31 #include "op.h"
32
33 /**
34  * Return and log a "no privileges" message.
35  */
36 GLOBAL bool
37 Op_NoPrivileges(CLIENT * Client, REQUEST * Req)
38 {
39         CLIENT *from = NULL;
40
41         if (Req->prefix)
42                 from = Client_Search(Req->prefix);
43
44         if (from) {
45                 Log(LOG_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"",
46                     Req->prefix, Client_Mask(Client), Req->command);
47                 return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG,
48                                           Client_ID(from));
49         } else {
50                 Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"",
51                     Client_Mask(Client), Req->command);
52                 return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
53                                           Client_ID(Client));
54         }
55 } /* Op_NoPrivileges */
56
57
58 /**
59  * Check that the client is an IRC operator allowed to administer this server.
60  */
61 GLOBAL bool
62 Op_Check(CLIENT * Client, REQUEST * Req)
63 {
64         CLIENT *c;
65
66         assert(Client != NULL);
67         assert(Req != NULL);
68
69         if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
70                 c = Client_Search(Req->prefix);
71         else
72                 c = Client;
73         if (!c)
74                 return false;
75         if (!Client_HasMode(c, 'o'))
76                 return false;
77         if (!Client_OperByMe(c) && !Conf_AllowRemoteOper)
78                 return false;
79         /* The client is an local IRC operator, or this server is configured
80          * to trust remote operators. */
81         return true;
82 } /* Op_Check */