Return accurate privilege information for remote opers.
authorMichael Poole <mdpoole@troilus.org>
Sat, 2 Apr 2005 02:50:15 +0000 (02:50 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sat, 2 Apr 2005 02:50:15 +0000 (02:50 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1347 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
include/handlers.h
include/msg.h
ircd/m_privs.c
ircd/parse.c

index 2a80a7721c5ebb5f5e280b7437e48ee64cd06ded..54604645eb486430aae9078ad0855963aed0051b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2005-04-01  Michael Poole <mdpoole@troilus.org>
+
+       * include/handlers.h (ms_privs): Declare.
+
+       * include/msg.h (TOK_PRIVS): Assign token.
+       (CMD_PRIVS): Define.
+
+       * ircd/m_privs.c: Add doxygen comments and replace the long
+       discussion of m_handler functions with an xref to it.
+       (mo_privs): Forward requests for non-local users
+       to their own server.
+       (ms_privs): Implement.
+
+       * ircd/parse.c (PRIVS): Dispatch to ms_privs when a server sends
+       the message.
+
 2005-03-30  Michael Poole <mdpoole@troilus.org>
 
        * include/client.h (struct Client): Explain where cli_username
index c9a40f2c612c54f007c7951e7af74366389b359f..6746a6d4a5b80bcfd42709bb168e657f0ab64ac3 100644 (file)
@@ -207,6 +207,7 @@ extern int ms_part(struct Client*, struct Client*, int, char*[]);
 extern int ms_ping(struct Client*, struct Client*, int, char*[]);
 extern int ms_pong(struct Client*, struct Client*, int, char*[]);
 extern int ms_privmsg(struct Client*, struct Client*, int, char*[]);
+extern int ms_privs(struct Client*, struct Client*, int, char*[]);
 extern int ms_quit(struct Client*, struct Client*, int, char*[]);
 extern int ms_rping(struct Client*, struct Client*, int, char*[]);
 extern int ms_rpong(struct Client*, struct Client*, int, char*[]);
index cbcda92cdcf3afe8d5b35b829c96b486348d54f3..c9ded3a113e7e6e2ce610441983b8e73f5f21197 100644 (file)
@@ -353,7 +353,8 @@ struct Client;
 #define TOK_GET                        "GET"
 
 #define MSG_PRIVS              "PRIVS"         /* PRIV */
-#define TOK_PRIVS              "PRIVS"
+#define TOK_PRIVS              "PR"
+#define CMD_PRIVS               MSG_PRIVS, TOK_PRIVS
 
 #define MSG_CAP                        "CAP"
 #define TOK_CAP                        "CAP"
index b36e8b87dfd96c647d8188d624ad41dde61d931e..ed4494b0eceb3260cfb7250d4c2ccbd00e236442 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
  */
-
-/*
- * m_functions execute protocol messages on this server:
- *
- *    cptr    is always NON-NULL, pointing to a *LOCAL* client
- *            structure (with an open socket connected!). This
- *            identifies the physical socket where the message
- *            originated (or which caused the m_function to be
- *            executed--some m_functions may call others...).
- *
- *    sptr    is the source of the message, defined by the
- *            prefix part of the message if present. If not
- *            or prefix not found, then sptr==cptr.
- *
- *            (!IsServer(cptr)) => (cptr == sptr), because
- *            prefixes are taken *only* from servers...
- *
- *            (IsServer(cptr))
- *                    (sptr == cptr) => the message didn't
- *                    have the prefix.
- *
- *                    (sptr != cptr && IsServer(sptr) means
- *                    the prefix specified servername. (?)
- *
- *                    (sptr != cptr && !IsServer(sptr) means
- *                    that message originated from a remote
- *                    user (not local).
- *
- *            combining
- *
- *            (!IsServer(sptr)) means that, sptr can safely
- *            taken as defining the target structure of the
- *            message in this server.
- *
- *    *Always* true (if 'parse' and others are working correct):
- *
- *    1)      sptr->from == cptr  (note: cptr->from == cptr)
- *
- *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
- *            *cannot* be a local connection, unless it's
- *            actually cptr!). [MyConnect(x) should probably
- *            be defined as (x == x->from) --msa ]
- *
- *    parc    number of variable parameter strings (if zero,
- *            parv is allowed to be NULL)
- *
- *    parv    a NULL terminated list of parameter pointers,
- *
- *                    parv[0], sender (prefix string), if not present
- *                            this points to an empty string.
- *                    parv[1]...parv[parc-1]
- *                            pointers to additional parameters
- *                    parv[parc] == NULL, *always*
- *
- *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
- *                    non-NULL pointers.
+/** @file
+ * @brief Report operators' privileges to others
+ * @version $Id$
  */
+
 #include "config.h"
 
 #include "client.h"
 #include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
+#include "msg.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "send.h"
 
-/* #include <assert.h> -- Now using assert in ircd_log.h */
-
-/*
- * mo_privs - report operator privileges
+/** Handle a local operator's privilege query.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
+ * @see \ref m_functions
  */
 int mo_privs(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
@@ -109,8 +58,43 @@ int mo_privs(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   for (i = 1; i < parc; i++) {
     for (name = ircd_strtok(&p, parv[i], " "); name;
         name = ircd_strtok(&p, 0, " ")) {
-      if ((acptr = FindUser(name)))
+      if (!(acptr = FindUser(name)))
+        continue;
+      else if (MyUser(acptr))
+       client_report_privs(sptr, acptr);
+      else
+        sendcmdto_one(cptr, CMD_PRIVS, acptr, "%s%s", NumNick(acptr));
+    }
+  }
+
+  return 0;
+}
+
+/** Handle a remote user's privilege query.
+ * @param[in] cptr Client that sent us the message.
+ * @param[in] sptr Original source of message.
+ * @param[in] parc Number of arguments.
+ * @param[in] parv Argument vector.
+ * @see \ref m_functions
+ */
+int ms_privs(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+{
+  struct Client *acptr;
+  char *numnick, *p = 0;
+  int i;
+
+  if (parc < 2)
+    return protocol_violation(cptr, "PRIVS with no arguments");
+
+  for (i = 1; i < parc; i++) {
+    for (numnick = ircd_strtok(&p, parv[i], " "); numnick;
+        numnick = ircd_strtok(&p, 0, " ")) {
+      if (!(acptr = findNUser(numnick)))
+        continue;
+      else if (MyUser(acptr))
        client_report_privs(sptr, acptr);
+      else
+        sendcmdto_one(cptr, CMD_PRIVS, acptr, "%s%s", NumNick(acptr));
     }
   }
 
index 87ee730b0bab30292a2ecf2b0dd8a8a22fa23c8b..16a062f89b5e78cb3d6b9b71f12f4b0f36f7656f 100644 (file)
@@ -600,7 +600,7 @@ struct Message msgtab[] = {
     TOK_PRIVS,
     0, MAXPARA, MFLG_SLOW, 0, NULL,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-    { m_unregistered, m_not_oper, m_ignore, mo_privs, m_ignore }
+    { m_unregistered, m_not_oper, ms_privs, mo_privs, m_ignore }
   },
   {
     MSG_ACCOUNT,