]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Add ticketauth.
authorChris Porter <redacted>
Sun, 11 Feb 2007 17:37:00 +0000 (17:37 +0000)
committerChris Porter <redacted>
Sun, 11 Feb 2007 17:37:00 +0000 (17:37 +0000)
nterface/nterfacer_control.c
ticketauth/Makefile [new file with mode: 0644]
ticketauth/ticketauth.c [new file with mode: 0644]

index a790cd717028d8011642d1c26a748041a8b1d1e2..07dbca8ec45e14aec10534065106e97b8303725a 100644 (file)
@@ -1,26 +1,6 @@
 /*
   nterfacer newserv control module
-  Copyright (C) 2004-2005 Chris Porter.
-
-  v1.08
-    - added counthost, removed isaccounton (as it didn't do anything!)
-  v1.07
-    - added modes
-  v1.06
-    - seperated chanstats
-  v1.05
-    - modified whois to take into account channels with ','
-    - made ison take multiple arguments
-    - added isaccounton
-  v1.04
-    - added status/onchan/servicesonchan
-  v1.03
-    - added multiple targets for channel/nick notice/message commands
-  v1.02
-    - added channel message, nick message/notice commands
-    - generalised error messages
-  v1.01
-    - whois fixed to notice BUF_OVER
+  Copyright (C) 2004-2007 Chris Porter.
 */
 
 #include <string.h>
 #include "../lib/flags.h"
 #include "../lib/irc_string.h"
 #include "../lib/version.h"
+#include "../authhash/authhash.h"
 
 #include "library.h"
 #include "nterfacer_control.h"
 
-MODULE_VERSION("$Id: nterfacer_control.c 663 2006-05-16 17:27:36Z newserv $")
+MODULE_VERSION("$Id: nterfacer_control.c 745 2007-02-11 17:37:27Z newserv $")
 
 int handle_ison(struct rline *li, int argc, char **argv);
+int handle_isaccounton(struct rline *li, int argc, char **argv);
 int handle_whois(struct rline *li, int argc, char **argv);
 int handle_message(struct rline *li, int argc, char **argv);
 int handle_notice(struct rline *li, int argc, char **argv);
@@ -58,6 +40,7 @@ void _init(void) {
     return;
 
   register_handler(n_node, "ison", 1, handle_ison);
+  register_handler(n_node, "isaccounton", 1, handle_isaccounton);
   register_handler(n_node, "whois", 1, handle_whois);
   register_handler(n_node, "msg", 2, handle_message);
   register_handler(n_node, "notice", 2, handle_notice);
@@ -82,6 +65,15 @@ int handle_ison(struct rline *li, int argc, char **argv) {
   return ri_final(li);
 }
 
+int handle_isaccounton(struct rline *li, int argc, char **argv) {
+  int i;
+  for(i=0;i<argc;i++)
+    if(ri_append(li, "%d", getnickbyauth(argv[i])?1:0) == BF_OVER)
+      return ri_error(li, BF_OVER, "Buffer overflow");
+
+  return ri_final(li);
+}
+
 int handle_whois(struct rline *li, int argc, char **argv) {
   nick *np = getnickbynick(argv[0]);
   channel **channels;
diff --git a/ticketauth/Makefile b/ticketauth/Makefile
new file mode 100644 (file)
index 0000000..df1fd07
--- /dev/null
@@ -0,0 +1,6 @@
+
+.PHONY: all
+all: ticketauth.so
+
+ticketauth.so: ticketauth.o
+       ld -shared -Bdynamic -o $@ $^
diff --git a/ticketauth/ticketauth.c b/ticketauth/ticketauth.c
new file mode 100644 (file)
index 0000000..9902d04
--- /dev/null
@@ -0,0 +1,116 @@
+/* ticketauth.c */
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+
+#include "../control/control.h"
+#include "../core/config.h"
+#include "../nick/nick.h"
+#include "../core/error.h"
+#include "../lib/sha1.h"
+#include "../lib/version.h"
+
+#include "../core/hooks.h"
+#include "../irc/irc.h"
+
+#define WARN_CHANNEL "#fishcowcow"
+
+MODULE_VERSION("$Id")
+
+sstring *sharedsecret = NULL;
+
+/* here as we're not currently using TS, this should be REMOVED and the code updated to use localusersetaccount instead */
+void localusersetaccountnots(nick *np, char *accname) {
+  if (IsAccount(np)) {
+    Error("localuser",ERR_WARNING,"Tried to set account on user %s already authed", np->nick);
+    return;
+  }
+
+  SetAccount(np);
+  strncpy(np->authname, accname, ACCOUNTLEN);
+  np->authname[ACCOUNTLEN]='\0';
+
+  if (connected) {
+    irc_send("%s AC %s %s",mynumeric->content, longtonumeric(np->numeric,5), np->authname);
+  }
+
+  triggerhook(HOOK_NICK_ACCOUNT, np);
+}
+
+int ta_ticketauth(void *source, int cargc, char **cargv) {
+  nick *np = (nick *)source;
+  char buffer[1024], *hmac, *acc;
+  unsigned char shabuf[20];
+  int expiry, acclen;
+  SHA1_CTX context;
+
+  if(IsAccount(np)) {
+    controlreply(np, "You're already authed.");
+    return CMD_ERROR;
+  }
+
+  if(cargc != 3)
+    return CMD_USAGE;
+
+  hmac = cargv[0];
+  acc = cargv[1];
+  acclen = strlen(acc);
+  expiry = atoi(cargv[2]);
+  if((acclen <= 1) || (acclen > ACCOUNTLEN)) {
+    controlreply(np, "Bad account.");
+    return CMD_ERROR;
+  }
+
+  if(time(NULL) > expiry) {
+    controlwall(NO_OPER, NL_MISC, "%s!%s@%s attempted to TICKETAUTH as %s (expired)", np->nick, np->ident, np->host->name->content, acc);
+    controlreply(np, "Ticket time is bad or has expired.");
+    return CMD_ERROR;
+  }
+  
+  snprintf(buffer, sizeof(buffer), "%s %d", acc, expiry);
+
+  SHA1Init(&context);
+  SHA1Update(&context, (unsigned char *)buffer, strlen(buffer));
+  SHA1Final(shabuf, &context);
+  
+  /* ha! */
+  snprintf(buffer, sizeof(buffer), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", shabuf[0], shabuf[1],  shabuf[2], shabuf[3], shabuf[4], shabuf[5], shabuf[6], shabuf[7], shabuf[8], shabuf[9], shabuf[10], shabuf[11], shabuf[12], shabuf[13], shabuf[14], shabuf[15], shabuf[16], shabuf[17], shabuf[18], shabuf[19]);
+
+  if(strcasecmp(buffer, hmac)) {
+    controlwall(NO_OPER, NL_MISC, "%s!%s@%s attempted to TICKETAUTH as %s (bad HMAC)", np->nick, np->ident, np->host->name->content, acc);
+    controlreply(np, "Bad HMAC.");
+    return CMD_ERROR;
+  }
+
+  controlwall(NO_OPER, NL_MISC, "%s!%s@%s TICKETAUTH'ed as %s", np->nick, np->ident, np->host->name->content, acc);
+  controlreply(np, "Ticket valid, authing. . .");
+
+  localusersetaccountnots(np, acc);
+
+  return CMD_OK;
+}
+
+void _init() {  
+  sharedsecret = getcopyconfigitem("ticketauth", "sharedsecret", "", 512);
+  if(!sharedsecret || !sharedsecret->content || !sharedsecret->content[0]) {
+    Error("ticketauth", ERR_ERROR, "Shared secret not defined in config file.");
+    if(sharedsecret) {
+      freesstring(sharedsecret);
+      sharedsecret = NULL;
+    }
+
+    return;
+  }
+
+  registercontrolhelpcmd("ticketauth", NO_OPERED, 3, ta_ticketauth, "Usage: ticketauth <ticket>");
+}
+
+void _fini() {
+  if(!sharedsecret)
+    return;
+
+  deregistercontrolcmd("ticketauth", ta_ticketauth);
+
+  freesstring(sharedsecret);
+}