]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authlib.c
5 #include "../lib/irc_string.h"
12 regex_t remail
, raccount
;
15 int csa_initregex(void) {
19 if (regcomp(&remail
, VALID_EMAIL
, REG_EXTENDED
| REG_NOSUB
| REG_ICASE
))
22 if (regcomp(&raccount
, VALID_ACCOUNT_NAME
, REG_EXTENDED
| REG_NOSUB
| REG_ICASE
)) {
31 void csa_freeregex(void) {
41 * use regex matching to determine if it's a valid eboy or not
43 int csa_checkeboy(nick
*sender
, char *eboy
)
47 len
= (((strlen(eboy
)) < (EMAILLEN
)) ? (strlen(eboy
)) : (EMAILLEN
));
50 chanservstdmessage(sender
, QM_EMAILTOOSHORT
, eboy
);
54 if (strstr(&eboy
[1], "@") == NULL
) {
56 chanservstdmessage(sender
, QM_EMAILNOAT
, eboy
);
60 if (eboy
[len
- 1] == '@') {
62 chanservstdmessage(sender
, QM_EMAILATEND
, eboy
);
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
] == '-')) {
71 chanservstdmessage(sender
, QM_EMAILINVCHR
, eboy
);
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
)
80 || !ircd_strncmp("QBot@QuakeNet.org", eboy
, len
)) {
82 chanservstdmessage(sender
, QM_NOTYOUREMAIL
, eboy
);
86 if (regexec(&remail
, eboy
, (size_t) 0, NULL
, 0)) {
88 chanservstdmessage(sender
, QM_INVALIDEMAIL
, eboy
);
96 * use regex matching to determine if it's a valid account name or not
98 int csa_checkaccountname(nick
*sender
, char *accountname
) {
99 if (regexec(&raccount
, accountname
, (size_t) 0, NULL
, 0)) {
101 chanservstdmessage(sender
, QM_INVALIDACCOUNTNAME
);
109 * create a random pw. code stolen from fox's O
111 void csa_createrandompw(char *pw
, int n
)
114 char upwdchars
[] = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789-!";
116 for (i
= 0; i
< n
; i
++) {
117 pw
[i
] = upwdchars
[rand() % (sizeof(upwdchars
) - 1)];
123 * check if account is "throttled"
125 int csa_checkthrottled(nick
*sender
, reguser
*rup
, char *s
)
132 d
=MAX_RESEND_TIME
+rup
->lastemailchange
-now
;
134 if (d
>MAX_RESEND_TIME
)
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
);