]> jfr.im git - irc/evilnet/x3.git/commitdiff
better email validity checking
authorrubin <redacted>
Thu, 16 Feb 2006 02:54:40 +0000 (02:54 +0000)
committerrubin <redacted>
Thu, 16 Feb 2006 02:54:40 +0000 (02:54 +0000)
ChangeLog.X3
src/common.h
src/nickserv.c
src/sendmail.c
src/tools.c

index d422d6e1434889229d13b3bb64d8b55e7618a9fe..aaa08d43cab020f0370ad103a06cfa7615b78952 100644 (file)
@@ -1,6 +1,14 @@
 /***********************************************************************
  X3 ChangeLog
 
+2006-01-16  Alex Schumann  <rubin@afternet.org>
+
+       * src/tools.c: created an email valididty function
+
+       * src/nickserv.c: check valididty of email better
+
+       * src/sendmail.c: check validity of email better
+
 2006-01-06  Alex Schumann  <rubin@afternet.org>
 
        * src/opserv.c: fix gtrace, trace, csearch and alerts to work when aliased
index d0949755965b7681a545a6578e69ea46b7853501..b20969bd3338c2b32f86fcfd83bfe8ee8429be52 100644 (file)
@@ -170,6 +170,8 @@ int split_ircmask(char *text, char **nick, char **ident, char **host);
 char *unsplit_string(char *set[], unsigned int max, char *dest);
 extern char* x3_strtok(char** save, char* str, char* fs);
 
+int valid_email(const char *email);
+
 #define DECLARE_LIST(STRUCTNAME,ITEMTYPE) struct STRUCTNAME {\
   unsigned int used, size;\
   ITEMTYPE *list;\
index ade655da7eb09d114f4831de024d212911a50c1c..a6efa53159f6edc1572c04ea8304467b8ceac4d5 100644 (file)
@@ -718,6 +718,7 @@ is_registerable_nick(const char *nick)
     }
     return 1;
 }
+/*  this has been replaced with one in tools.c
 
 static int
 is_valid_email_addr(const char *email)
@@ -725,6 +726,8 @@ is_valid_email_addr(const char *email)
     return strchr(email, '@') != NULL;
 }
 
+*/ 
+
 static const char *
 visible_email_addr(struct userNode *user, struct handle_info *hi)
 {
@@ -1295,7 +1298,7 @@ static NICKSERV_FUNC(cmd_register)
         email_addr = argv[3];
 
         /* Check that the email address looks valid.. */
-        if (!is_valid_email_addr(email_addr)) {
+        if (!valid_email(email_addr)) {
             reply("NSMSG_BAD_EMAIL_ADDR");
             return 0;
         }
@@ -1394,7 +1397,7 @@ static NICKSERV_FUNC(cmd_oregister)
     }
 
     if (nickserv_conf.email_required) {
-        if (!is_valid_email_addr(argv[4])) {
+        if (!valid_email(argv[4])) {
             reply("NSMSG_BAD_EMAIL_ADDR");
             return 0;
         }
@@ -2654,7 +2657,7 @@ static OPTION_FUNC(opt_email)
 {
     if (argc > 1) {
         const char *str;
-        if (!is_valid_email_addr(argv[1])) {
+        if (!valid_email(argv[1])) {
             send_message(user, nickserv, "NSMSG_BAD_EMAIL_ADDR");
             return 0;
         }
index 06612814b45a5f9b77d2e83233db7d3d2cdcb978..8c211e7e6fd9ea01163e3ff5860a8de74fc0a7f8 100644 (file)
@@ -100,6 +100,24 @@ send_flowed_text(FILE *where, const char *para)
     }
 }
 
+/* moved to tools.c 
+int 
+valid_email(email)
+{
+    for (i=0;i<strlen(email);i++)
+    {
+        if(!isalnum(to->email_addr[i]) &&
+               to->email_addr[i] != '.' &&
+               to->email_addr[i] != '@' &&
+               to->email_addr[i] != '-' &&
+               to->email_addr[i] != '+' &&
+               to->email_addr[i] != '_' )
+            return false;
+    }
+    return true;
+}
+*/
+
 void
 sendmail(struct userNode *from, struct handle_info *to, const char *subject, const char *body, int first_time)
 {
@@ -227,6 +245,12 @@ sendmail(struct userNode *from, struct handle_info *to, const char *subject, con
             argv[argc++] = "-f";
             argv[argc++] = fromaddr;
         }
+        if(!valid_email(to->email_addr))
+        {
+                log_module(MAIN_LOG, LOG_ERROR, "email address contained illegal chars. Refusing to execv() sendmail.");
+                _exit(1);
+        }
+
         argv[argc++] = to->email_addr;
         argv[argc++] = NULL;
         if (execv(mpath, (char**)argv) < 0) {
index 7a6020ed8a4e5f4f9437024df492505b2146f04d..a46ed50d000bc63954b84841a3321a905e066ea1 100644 (file)
@@ -1010,3 +1010,21 @@ char* x3_strtok(char **save, char *str, char *fs)
   return (tmp);
 }
 
+int valid_email(const char *email)
+{
+    unsigned int i;
+    for (i=0;i<strlen(email);i++)
+    {
+        if(!isalnum(email[i]) &&
+               email[i] != '.' &&
+               email[i] != '@' &&
+               email[i] != '-' &&
+               email[i] != '+' &&
+               email[i] != '_' )
+            return false;
+    }
+    if(strchr(email, '@') == NULL)
+        return false;
+    return true;
+}
+