ircu2.10.12 pk910 fork
[ircu2.10.12-pk.git] / ircd / m_privs.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_privs.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 1, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23 /** @file
24  * @brief Report operators' privileges to others
25  * @version $Id: m_privs.c 1810 2007-05-20 14:15:58Z entrope $
26  */
27
28 #include "config.h"
29
30 #include "client.h"
31 #include "hash.h"
32 #include "ircd.h"
33 #include "ircd_log.h"
34 #include "ircd_reply.h"
35 #include "ircd_string.h"
36 #include "msg.h"
37 #include "numeric.h"
38 #include "numnicks.h"
39 #include "send.h"
40
41 /** Handle a local operator's privilege query.
42  * @param[in] cptr Client that sent us the message.
43  * @param[in] sptr Original source of message.
44  * @param[in] parc Number of arguments.
45  * @param[in] parv Argument vector.
46  * @see \ref m_functions
47  */
48 int m_privs(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
49 {
50   struct Client *acptr;
51   char *name;
52   char *p = 0;
53   int i;
54
55   if (parc < 2 || !IsAnOper(sptr))
56     return client_report_privs(sptr, sptr);
57
58   for (i = 1; i < parc; i++) {
59     for (name = ircd_strtok(&p, parv[i], " "); name;
60          name = ircd_strtok(&p, 0, " ")) {
61       if (!(acptr = FindUser(name)))
62         send_reply(sptr, ERR_NOSUCHNICK, name);
63       else if (MyUser(acptr))
64         client_report_privs(sptr, acptr);
65       else
66         sendcmdto_one(cptr, CMD_PRIVS, acptr, "%s%s", NumNick(acptr));
67     }
68   }
69
70   return 0;
71 }
72
73 /** Handle a remote user's privilege query.
74  * @param[in] cptr Client that sent us the message.
75  * @param[in] sptr Original source of message.
76  * @param[in] parc Number of arguments.
77  * @param[in] parv Argument vector.
78  * @see \ref m_functions
79  */
80 int ms_privs(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
81 {
82   struct Client *acptr;
83   char *numnick, *p = 0;
84   int i;
85
86   if (parc < 2)
87     return protocol_violation(cptr, "PRIVS with no arguments");
88
89   for (i = 1; i < parc; i++) {
90     for (numnick = ircd_strtok(&p, parv[i], " "); numnick;
91          numnick = ircd_strtok(&p, 0, " ")) {
92       if (!(acptr = findNUser(numnick)))
93         continue;
94       else if (MyUser(acptr))
95         client_report_privs(sptr, acptr);
96       else
97         sendcmdto_one(sptr, CMD_PRIVS, acptr, "%s%s", NumNick(acptr));
98     }
99   }
100
101   return 0;
102 }