]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
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 | ||
dc9548f4 | 12 | regex_t remail, raccount; |
e2340b39 | 13 | static int regexinit; |
c86edd1d | 14 | |
dc9548f4 | 15 | int csa_initregex(void) { |
e2340b39 CP |
16 | if (regexinit) |
17 | return 1; | |
18 | ||
dc9548f4 | 19 | if (regcomp(&remail, VALID_EMAIL, REG_EXTENDED | REG_NOSUB | REG_ICASE)) |
e2340b39 CP |
20 | return 0; |
21 | ||
dc9548f4 CP |
22 | if (regcomp(&raccount, VALID_ACCOUNT_NAME, REG_EXTENDED | REG_NOSUB | REG_ICASE)) { |
23 | regfree(&remail); | |
24 | return 0; | |
25 | } | |
26 | ||
e2340b39 CP |
27 | regexinit = 1; |
28 | return 1; | |
c86edd1d Q |
29 | } |
30 | ||
dc9548f4 CP |
31 | void csa_freeregex(void) { |
32 | if(!regexinit) | |
33 | return; | |
34 | ||
35 | regfree(&remail); | |
36 | regfree(&raccount); | |
37 | regexinit = 0; | |
c86edd1d Q |
38 | } |
39 | ||
40 | /* | |
41 | * use regex matching to determine if it's a valid eboy or not | |
42 | */ | |
43 | int csa_checkeboy(nick *sender, char *eboy) | |
44 | { | |
45 | int i, len; | |
46 | ||
47 | len = (((strlen(eboy)) < (EMAILLEN)) ? (strlen(eboy)) : (EMAILLEN)); | |
48 | if (len <= 4) { | |
49 | if (sender) | |
50 | chanservstdmessage(sender, QM_EMAILTOOSHORT, eboy); | |
51 | return (1); | |
52 | } | |
53 | ||
54 | if (strstr(&eboy[1], "@") == NULL) { | |
55 | if (sender) | |
56 | chanservstdmessage(sender, QM_EMAILNOAT, eboy); | |
57 | return (1); | |
58 | } | |
59 | ||
60 | if (eboy[len - 1] == '@') { | |
61 | if (sender) | |
62 | chanservstdmessage(sender, QM_EMAILATEND, eboy); | |
63 | return (1); | |
64 | } | |
65 | ||
66 | for (i = 0; i < len; i++) { | |
67 | if (!isalpha(eboy[i]) && !isdigit(eboy[i]) | |
68 | && !(eboy[i] == '@') && !(eboy[i] == '.') | |
69 | && !(eboy[i] == '_') && !(eboy[i] == '-')) { | |
70 | if (sender) | |
71 | chanservstdmessage(sender, QM_EMAILINVCHR, eboy); | |
72 | return (1); | |
73 | } | |
74 | } | |
75 | ||
76 | /* catch some real lame attempts */ | |
77 | if (!ircd_strncmp("user@mymailhost.xx", eboy, len) || !ircd_strncmp("info@quakenet.org", eboy, len) | |
78 | || !ircd_strncmp("user@mymail.xx", eboy, len) || !ircd_strncmp("user@mail.cc", eboy, len) | |
79 | || !ircd_strncmp("user@host.com", eboy, len) || !ircd_strncmp("Jackie@your.isp.com", eboy, len) | |
dfefe4a4 | 80 | || !ircd_strncmp("QBot@QuakeNet.org", eboy, len) || !ircd_strncmp("Q@CServe.quakenet.org", eboy, len)) { |
c86edd1d Q |
81 | if (sender) |
82 | chanservstdmessage(sender, QM_NOTYOUREMAIL, eboy); | |
83 | return (1); | |
84 | } | |
85 | ||
dc9548f4 | 86 | if (regexec(&remail, eboy, (size_t) 0, NULL, 0)) { |
c86edd1d Q |
87 | if (sender) |
88 | chanservstdmessage(sender, QM_INVALIDEMAIL, eboy); | |
89 | return (1); | |
90 | } | |
91 | ||
92 | return (0); | |
93 | } | |
94 | ||
dc9548f4 CP |
95 | /* |
96 | * use regex matching to determine if it's a valid account name or not | |
97 | */ | |
98 | int csa_checkaccountname(nick *sender, char *accountname) { | |
99 | if (regexec(&raccount, accountname, (size_t) 0, NULL, 0)) { | |
100 | if (sender) | |
101 | chanservstdmessage(sender, QM_INVALIDACCOUNTNAME); | |
102 | return (1); | |
103 | } | |
104 | return (0); | |
105 | } | |
106 | ||
107 | ||
c86edd1d Q |
108 | /* |
109 | * create a random pw. code stolen from fox's O | |
110 | */ | |
111 | void csa_createrandompw(char *pw, int n) | |
112 | { | |
113 | int i; | |
114 | char upwdchars[] = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789-!"; | |
115 | ||
116 | for (i = 0; i < n; i++) { | |
117 | pw[i] = upwdchars[rand() % (sizeof(upwdchars) - 1)]; | |
118 | } | |
119 | pw[n] = '\0'; | |
120 | } | |
1dd6d55d | 121 | |
122 | /* | |
123 | * check if account is "throttled" | |
124 | */ | |
125 | int csa_checkthrottled(nick *sender, reguser *rup, char *s) | |
126 | { | |
127 | time_t now; | |
128 | long d; | |
129 | float t; | |
130 | ||
131 | now=time(NULL); | |
132 | d=MAX_RESEND_TIME+rup->lastemailchange-now; | |
133 | ||
134 | if (d>MAX_RESEND_TIME) | |
135 | d=MAX_RESEND_TIME; | |
136 | ||
137 | if (d>0L) { | |
138 | t = ((float) d) / ((float) 3600); | |
139 | chanservstdmessage(sender, QM_MAILTHROTTLED, t); | |
140 | cs_log(sender,"%s FAIL username %s, new request throttled for %.1f hours",s,rup->username,t); | |
141 | return 1; | |
142 | } | |
143 | return 0; | |
144 | } |