~registry/ngircd/testing

« back to all changes in this revision

Viewing changes to src/ngircd/irc-oper.c

  • Committer: DNS
  • Date: 2013-08-27 14:48:36 UTC
  • mfrom: (2671.5.8)
  • Revision ID: git-v1:bdb2850b399a7fac6a70fe24bd1f58dbd78cc307
Merge branch 'master' into testing

· Remove Conf_PreventLocalChans and Conf_PreventMLChans, obsolete now
· Remove RPL_HELP_MSG

Fixed conflicts with:
        doc/sample-ngircd.conf.tmpl
        man/ngircd.conf.5.tmpl
        src/ngircd/conf.c
        src/ngircd/irc-channel.c
        src/ngircd/irc-info.c
        src/ngircd/messages.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * ngIRCd -- The Next Generation IRC Daemon
3
 
 * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
 
3
 * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License as published by
28
28
#include "conf.h"
29
29
#include "channel.h"
30
30
#include "class.h"
 
31
#include "irc-macros.h"
31
32
#include "irc-write.h"
32
33
#include "log.h"
33
34
#include "match.h"
47
48
{
48
49
        Log(LOG_WARNING, "Got invalid OPER from \"%s\": \"%s\" -- %s",
49
50
            Client_Mask(Client), errtoken, errmsg);
50
 
        IRC_SetPenalty(Client, 3);
51
 
        return IRC_WriteStrClient(Client, ERR_PASSWDMISMATCH_MSG,
 
51
        return IRC_WriteErrClient(Client, ERR_PASSWDMISMATCH_MSG,
52
52
                                  Client_ID(Client));
53
53
} /* Bad_OperPass */
54
54
 
55
55
/**
56
56
 * Handler for the IRC "OPER" command.
57
57
 *
58
 
 * See RFC 2812, 3.1.4 "Oper message".
59
 
 *
60
58
 * @param Client The client from which this command has been received.
61
59
 * @param Req Request structure with prefix and all parameters.
62
60
 * @return CONNECTED or DISCONNECTED.
70
68
        assert( Client != NULL );
71
69
        assert( Req != NULL );
72
70
 
73
 
        if (Req->argc != 2)
74
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
75
 
                                          Client_ID(Client), Req->command);
 
71
        _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 2)
76
72
 
77
73
        len = array_length(&Conf_Opers, sizeof(*op));
78
74
        op = array_start(&Conf_Opers);
98
94
 
99
95
        if (!Client_OperByMe(Client))
100
96
                Log(LOG_NOTICE|LOG_snotice,
101
 
                    "Got valid OPER from \"%s\", user is an IRC operator now.",
102
 
                    Client_Mask(Client));
 
97
                    "Got valid OPER for \"%s\" from \"%s\", user is an IRC operator now.",
 
98
                    Req->argv[0], Client_Mask(Client));
103
99
 
104
100
        Client_SetOperByMe(Client, true);
105
101
        return IRC_WriteStrClient(Client, RPL_YOUREOPER_MSG, Client_ID(Client));
108
104
/**
109
105
 * Handler for the IRC "DIE" command.
110
106
 *
111
 
 * See RFC 2812, 4.3 "Die message".
112
 
 *
113
107
 * @param Client The client from which this command has been received.
114
108
 * @param Req Request structure with prefix and all parameters.
115
109
 * @return CONNECTED or DISCONNECTED.
128
122
        if (!Op_Check(Client, Req))
129
123
                return Op_NoPrivileges(Client, Req);
130
124
 
131
 
        /* Bad number of parameters? */
132
125
#ifdef STRICT_RFC
133
 
        if (Req->argc != 0)
 
126
        _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 0)
134
127
#else
135
 
        if (Req->argc > 1)
 
128
        _IRC_ARGC_LE_OR_RETURN_(Client, Req, 1)
136
129
#endif
137
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
138
 
                                          Client_ID(Client), Req->command);
139
130
 
140
131
        /* Is a message given? */
141
132
        if (Req->argc > 0) {
159
150
/**
160
151
 * Handler for the IRC "REHASH" command.
161
152
 *
162
 
 * See RFC 2812, 4.2 "Rehash message".
163
 
 *
164
153
 * @param Client The client from which this command has been received.
165
154
 * @param Req Request structure with prefix and all parameters.
166
155
 * @return CONNECTED or DISCONNECTED.
176
165
        if (!Op_Check(Client, Req))
177
166
                return Op_NoPrivileges(Client, Req);
178
167
 
179
 
        /* Bad number of parameters? */
180
 
        if (Req->argc != 0)
181
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
182
 
                                          Client_ID(Client), Req->command );
 
168
        _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 0)
183
169
 
184
170
        Log(LOG_NOTICE|LOG_snotice, "Got REHASH command from \"%s\" ...",
185
171
            Client_Mask(Client));
193
179
/**
194
180
 * Handler for the IRC "RESTART" command.
195
181
 *
196
 
 * See RFC 2812, 4.4 "Restart message".
197
 
 *
198
182
 * @param Client The client from which this command has been received.
199
183
 * @param Req Request structure with prefix and all parameters.
200
184
 * @return CONNECTED or DISCONNECTED.
212
196
 
213
197
        /* Bad number of parameters? */
214
198
        if (Req->argc != 0)
215
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
 
199
                return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
216
200
                                          Client_ID(Client), Req->command);
217
201
 
218
202
        Log(LOG_NOTICE|LOG_snotice, "Got RESTART command from \"%s\" ...",
225
209
/**
226
210
 * Handler for the IRC "CONNECT" command.
227
211
 *
228
 
 * See RFC 2812, 3.4.7 "Connect message".
229
 
 *
230
212
 * @param Client The client from which this command has been received.
231
213
 * @param Req Request structure with prefix and all parameters.
232
214
 * @return CONNECTED or DISCONNECTED.
246
228
        /* Bad number of parameters? */
247
229
        if (Req->argc != 1 && Req->argc != 2 && Req->argc != 3 &&
248
230
            Req->argc != 5 && Req->argc != 6)
249
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
 
231
                return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
250
232
                                          Client_ID(Client), Req->command);
251
233
 
252
234
        /* Invalid port number? */
253
235
        if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
254
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
 
236
                return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
255
237
                                          Client_ID(Client), Req->command);
256
238
 
257
239
        from = Client;
262
244
                if (Client_Type(Client) == CLIENT_SERVER && Req->prefix)
263
245
                        from = Client_Search(Req->prefix);
264
246
                if (! from)
265
 
                        return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
266
 
                                        Client_ID(Client), Req->prefix);
 
247
                        return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
 
248
                                                  Client_ID(Client), Req->prefix);
267
249
 
268
250
                target = (Req->argc == 3) ? Client_Search(Req->argv[2])
269
251
                                          : Client_Search(Req->argv[5]);
270
252
                if (! target || Client_Type(target) != CLIENT_SERVER)
271
 
                        return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
272
 
                                        Client_ID(from), Req->argv[0]);
 
253
                        return IRC_WriteErrClient(from, ERR_NOSUCHSERVER_MSG,
 
254
                                                  Client_ID(from), Req->argv[0]);
273
255
        }
274
256
 
275
257
        if (target != Client_ThisServer()) {
292
274
        switch (Req->argc) {
293
275
        case 1:
294
276
                if (!Conf_EnablePassiveServer(Req->argv[0]))
295
 
                        return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
 
277
                        return IRC_WriteErrClient(from, ERR_NOSUCHSERVER_MSG,
296
278
                                                  Client_ID(from),
297
279
                                                  Req->argv[0]);
298
280
                break;
301
283
                /* Connect configured server */
302
284
                if (!Conf_EnableServer
303
285
                    (Req->argv[0], (UINT16) atoi(Req->argv[1])))
304
 
                        return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
 
286
                        return IRC_WriteErrClient(from, ERR_NOSUCHSERVER_MSG,
305
287
                                                  Client_ID(from),
306
288
                                                  Req->argv[0]);
307
289
                break;
310
292
                if (!Conf_AddServer
311
293
                    (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
312
294
                     Req->argv[3], Req->argv[4]))
313
 
                        return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
 
295
                        return IRC_WriteErrClient(from, ERR_NOSUCHSERVER_MSG,
314
296
                                                  Client_ID(from),
315
297
                                                  Req->argv[0]);
316
298
        }
348
330
 
349
331
        /* Bad number of parameters? */
350
332
        if (Req->argc != 1)
351
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
 
333
                return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
352
334
                                          Client_ID(Client), Req->command);
353
335
 
354
336
        IRC_SendWallops(Client_ThisServer(), Client_ThisServer(),
364
346
 
365
347
        /* Disconnect configured server */
366
348
        if (!Conf_DisableServer(Req->argv[0]))
367
 
                return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
 
349
                return IRC_WriteErrClient(Client, ERR_NOSUCHSERVER_MSG,
368
350
                                          Client_ID(Client), Req->argv[0]);
369
351
 
370
352
        /* Are we still connected or were we killed, too? */
377
359
/**
378
360
 * Handler for the IRC "WALLOPS" command.
379
361
 *
380
 
 * See RFC 2812, 4.7 "Operwall message".
381
 
 *
382
362
 * @param Client The client from which this command has been received.
383
363
 * @param Req Request structure with prefix and all parameters.
384
364
 * @return CONNECTED or DISCONNECTED.
391
371
        assert( Client != NULL );
392
372
        assert( Req != NULL );
393
373
 
394
 
        if (Req->argc != 1)
395
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
396
 
                                          Client_ID(Client), Req->command);
 
374
        _IRC_ARGC_EQ_OR_RETURN_(Client, Req, 1)
397
375
 
398
376
        switch (Client_Type(Client)) {
399
377
        case CLIENT_USER:
400
378
                if (!Client_OperByMe(Client))
401
 
                        return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG,
 
379
                        return IRC_WriteErrClient(Client, ERR_NOPRIVILEGES_MSG,
402
380
                                                  Client_ID(Client));
403
381
                from = Client;
404
382
                break;
410
388
        }
411
389
 
412
390
        if (!from)
413
 
                return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
 
391
                return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
414
392
                                          Client_ID(Client), Req->prefix);
415
393
 
416
394
        IRC_SendWallops(Client, from, "%s", Req->argv[0]);
440
418
 
441
419
        /* Bad number of parameters? */
442
420
        if (Req->argc != 1 && Req->argc != 3)
443
 
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
 
421
                return IRC_WriteErrClient(Client, ERR_NEEDMOREPARAMS_MSG,
444
422
                                          Client_ID(Client), Req->command);
445
423
 
446
424
        switch(Req->command[0]) {