]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/op.c
64c7e1e1fb2142e0bd6f3c5850220c669a422756
[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
12
13 #include "portab.h"
14
15 /**
16  * @file
17  * IRC operator functions
18  */
19
20 #include "imp.h"
21 #include <assert.h>
22 #include <string.h>
23
24 #include "conn.h"
25 #include "channel.h"
26 #include "conf.h"
27 #include "log.h"
28 #include "parse.h"
29 #include "messages.h"
30 #include "irc-write.h"
31
32 #include <exp.h>
33 #include "op.h"
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_WriteStrClient(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_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
55                                           Client_ID(Client));
56         }
57 } /* Op_NoPrivileges */
58
59
60 /**
61  * Check that the client is an IRC operator allowed to administer this server.
62  */
63 GLOBAL bool
64 Op_Check(CLIENT * Client, REQUEST * Req)
65 {
66         CLIENT *c;
67
68         assert(Client != NULL);
69         assert(Req != NULL);
70
71         if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
72                 c = Client_Search(Req->prefix);
73         else
74                 c = Client;
75         if (!c)
76                 return false;
77         if (!Client_HasMode(c, 'o'))
78                 return false;
79         if (!Client_OperByMe(c) && !Conf_AllowRemoteOper)
80                 return false;
81         /* The client is an local IRC operator, or this server is configured
82          * to trust remote operators. */
83         return true;
84 } /* Op_Check */