]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authlib.c
Initial Import
[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
14 int csa_initregex() {
15 if (regcomp(&preg, VALID_EMAIL, REG_EXTENDED | REG_NOSUB | REG_ICASE))
16 return(1);
17 else
18 return(0);
19 }
20
21 void csa_freeregex() {
22 regfree(&preg);
23 }
24
25 /*
26 * use regex matching to determine if it's a valid eboy or not
27 */
28 int csa_checkeboy(nick *sender, char *eboy)
29 {
30 int i, len;
31
32 len = (((strlen(eboy)) < (EMAILLEN)) ? (strlen(eboy)) : (EMAILLEN));
33 if (len <= 4) {
34 if (sender)
35 chanservstdmessage(sender, QM_EMAILTOOSHORT, eboy);
36 return (1);
37 }
38
39 if (strstr(&eboy[1], "@") == NULL) {
40 if (sender)
41 chanservstdmessage(sender, QM_EMAILNOAT, eboy);
42 return (1);
43 }
44
45 if (eboy[len - 1] == '@') {
46 if (sender)
47 chanservstdmessage(sender, QM_EMAILATEND, eboy);
48 return (1);
49 }
50
51 for (i = 0; i < len; i++) {
52 if (!isalpha(eboy[i]) && !isdigit(eboy[i])
53 && !(eboy[i] == '@') && !(eboy[i] == '.')
54 && !(eboy[i] == '_') && !(eboy[i] == '-')) {
55 if (sender)
56 chanservstdmessage(sender, QM_EMAILINVCHR, eboy);
57 return (1);
58 }
59 }
60
61 /* catch some real lame attempts */
62 if (!ircd_strncmp("user@mymailhost.xx", eboy, len) || !ircd_strncmp("info@quakenet.org", eboy, len)
63 || !ircd_strncmp("user@mymail.xx", eboy, len) || !ircd_strncmp("user@mail.cc", eboy, len)
64 || !ircd_strncmp("user@host.com", eboy, len) || !ircd_strncmp("Jackie@your.isp.com", eboy, len)
65 || !ircd_strncmp("QBot@QuakeNet.org", eboy, len)) {
66 if (sender)
67 chanservstdmessage(sender, QM_NOTYOUREMAIL, eboy);
68 return (1);
69 }
70
71 if (regexec(&preg, eboy, (size_t) 0, NULL, 0)) {
72 if (sender)
73 chanservstdmessage(sender, QM_INVALIDEMAIL, eboy);
74 return (1);
75 }
76
77 return (0);
78 }
79
80 /*
81 * create a random pw. code stolen from fox's O
82 */
83 void csa_createrandompw(char *pw, int n)
84 {
85 int i;
86 char upwdchars[] = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789-!";
87
88 for (i = 0; i < n; i++) {
89 pw[i] = upwdchars[rand() % (sizeof(upwdchars) - 1)];
90 }
91 pw[n] = '\0';
92 }