]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authlib.c
Email regular expression was not being compiled.
[irc/quakenet/newserv.git] / chanserv / authlib.c
1 /* authlib.c */
2
3 #include "authlib.h"
4 #include "chanserv.h"
5 #include "../lib/irc_string.h"
6
7 #include <string.h>
8 #include <ctype.h>
9 #include <sys/types.h>
10 #include <regex.h>
11
12 regex_t preg;
13 static int regexinit;
14
15 int csa_initregex() {
16 if (regexinit)
17 return 1;
18
19 if (!regcomp(&preg, VALID_EMAIL, REG_EXTENDED | REG_NOSUB | REG_ICASE))
20 return 0;
21
22 regexinit = 1;
23 return 1;
24 }
25
26 void csa_freeregex() {
27 regfree(&preg);
28 }
29
30 /*
31 * use regex matching to determine if it's a valid eboy or not
32 */
33 int csa_checkeboy(nick *sender, char *eboy)
34 {
35 int i, len;
36
37 len = (((strlen(eboy)) < (EMAILLEN)) ? (strlen(eboy)) : (EMAILLEN));
38 if (len <= 4) {
39 if (sender)
40 chanservstdmessage(sender, QM_EMAILTOOSHORT, eboy);
41 return (1);
42 }
43
44 if (strstr(&eboy[1], "@") == NULL) {
45 if (sender)
46 chanservstdmessage(sender, QM_EMAILNOAT, eboy);
47 return (1);
48 }
49
50 if (eboy[len - 1] == '@') {
51 if (sender)
52 chanservstdmessage(sender, QM_EMAILATEND, eboy);
53 return (1);
54 }
55
56 for (i = 0; i < len; i++) {
57 if (!isalpha(eboy[i]) && !isdigit(eboy[i])
58 && !(eboy[i] == '@') && !(eboy[i] == '.')
59 && !(eboy[i] == '_') && !(eboy[i] == '-')) {
60 if (sender)
61 chanservstdmessage(sender, QM_EMAILINVCHR, eboy);
62 return (1);
63 }
64 }
65
66 /* catch some real lame attempts */
67 if (!ircd_strncmp("user@mymailhost.xx", eboy, len) || !ircd_strncmp("info@quakenet.org", eboy, len)
68 || !ircd_strncmp("user@mymail.xx", eboy, len) || !ircd_strncmp("user@mail.cc", eboy, len)
69 || !ircd_strncmp("user@host.com", eboy, len) || !ircd_strncmp("Jackie@your.isp.com", eboy, len)
70 || !ircd_strncmp("QBot@QuakeNet.org", eboy, len)) {
71 if (sender)
72 chanservstdmessage(sender, QM_NOTYOUREMAIL, eboy);
73 return (1);
74 }
75
76 csa_initregex();
77 if (regexec(&preg, eboy, (size_t) 0, NULL, 0)) {
78 if (sender)
79 chanservstdmessage(sender, QM_INVALIDEMAIL, eboy);
80 return (1);
81 }
82
83 return (0);
84 }
85
86 /*
87 * create a random pw. code stolen from fox's O
88 */
89 void csa_createrandompw(char *pw, int n)
90 {
91 int i;
92 char upwdchars[] = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789-!";
93
94 for (i = 0; i < n; i++) {
95 pw[i] = upwdchars[rand() % (sizeof(upwdchars) - 1)];
96 }
97 pw[n] = '\0';
98 }
99
100 /*
101 * check if account is "throttled"
102 */
103 int csa_checkthrottled(nick *sender, reguser *rup, char *s)
104 {
105 time_t now;
106 long d;
107 float t;
108
109 now=time(NULL);
110 d=MAX_RESEND_TIME+rup->lastemailchange-now;
111
112 if (d>MAX_RESEND_TIME)
113 d=MAX_RESEND_TIME;
114
115 if (d>0L) {
116 t = ((float) d) / ((float) 3600);
117 chanservstdmessage(sender, QM_MAILTHROTTLED, t);
118 cs_log(sender,"%s FAIL username %s, new request throttled for %.1f hours",s,rup->username,t);
119 return 1;
120 }
121 return 0;
122 }