]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authlib.c
4 #include "../lib/irc_string.h"
10 #include <sys/types.h>
13 regex_t remail
, raccount
;
16 int csa_initregex(void) {
20 if (regcomp(&remail
, VALID_EMAIL
, REG_EXTENDED
| REG_NOSUB
| REG_ICASE
))
23 if (regcomp(&raccount
, VALID_ACCOUNT_NAME
, REG_EXTENDED
| REG_NOSUB
| REG_ICASE
)) {
32 void csa_freeregex(void) {
42 * use regex matching to determine if it's a valid eboy or not
44 int csa_checkeboy_r(char *eboy
)
48 len
= (((strlen(eboy
)) < (EMAILLEN
)) ? (strlen(eboy
)) : (EMAILLEN
));
50 return QM_EMAILTOOSHORT
;
53 if (strstr(&eboy
[1], "@") == NULL
) {
57 if (eboy
[len
- 1] == '@') {
61 for (i
= 0; i
< len
; i
++) {
62 if (!isalpha(eboy
[i
]) && !isdigit(eboy
[i
])
63 && !(eboy
[i
] == '@') && !(eboy
[i
] == '.')
64 && !(eboy
[i
] == '_') && !(eboy
[i
] == '-')) {
65 return QM_EMAILINVCHR
;
69 /* catch some real lame attempts */
70 if (!ircd_strncmp("user@mymailhost.xx", eboy
, len
) || !ircd_strncmp("info@quakenet.org", eboy
, len
)
71 || !ircd_strncmp("user@mymail.xx", eboy
, len
) || !ircd_strncmp("user@mail.cc", eboy
, len
)
72 || !ircd_strncmp("user@host.com", eboy
, len
) || !ircd_strncmp("Jackie@your.isp.com", eboy
, len
)
73 || !ircd_strncmp("QBot@QuakeNet.org", eboy
, len
) || !ircd_strncmp("Q@CServe.quakenet.org", eboy
, len
)
74 || !ircd_strncmp("badger@example.com", eboy
, len
)) {
75 return QM_NOTYOUREMAIL
;
78 if (regexec(&remail
, eboy
, (size_t) 0, NULL
, 0)) {
79 return QM_INVALIDEMAIL
;
85 int csa_checkeboy(nick
*sender
, char *eboy
)
87 int r
= csa_checkeboy_r(eboy
);
92 chanservstdmessage(sender
, r
, eboy
);
98 * use regex matching to determine if it's a valid account name or not
100 int csa_checkaccountname_r(char *accountname
) {
101 if (regexec(&raccount
, accountname
, (size_t) 0, NULL
, 0)) {
107 int csa_checkaccountname(nick
*sender
, char *accountname
) {
108 int r
= csa_checkaccountname_r(accountname
);
110 chanservstdmessage(sender
, QM_INVALIDACCOUNTNAME
);
116 * create a random pw. code stolen from fox's O
118 void csa_createrandompw(char *pw
, int n
)
121 char upwdchars
[] = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789-!";
123 for (i
= 0; i
< n
; i
++) {
124 pw
[i
] = upwdchars
[rand() % (sizeof(upwdchars
) - 1)];
130 * check if account is "throttled"
132 int csa_checkthrottled(nick
*sender
, reguser
*rup
, char *s
)
139 d
=MAX_RESEND_TIME
+rup
->lastemailchange
-now
;
141 if (d
>MAX_RESEND_TIME
)
145 t
= ((float) d
) / ((float) 3600);
146 chanservstdmessage(sender
, QM_MAILTHROTTLED
, t
);
147 cs_log(sender
,"%s FAIL username %s, new request throttled for %.1f hours",s
,rup
->username
,t
);
153 int csa_checkpasswordquality(char *password
) {
154 int i
, cntweak
= 0, cntdigits
= 0, cntletters
= 0;
155 if (strlen(password
) < 6)
158 if (strlen(password
) > 10)
161 for ( i
= 0; password
[i
] && i
< PASSLEN
; i
++ ) {
162 if ( password
[i
] == password
[i
+1] || password
[i
] + 1 == password
[i
+1] || password
[i
] - 1 == password
[i
+1] )
164 if(isdigit(password
[i
]))
166 if(islower(password
[i
]) || isupper(password
[i
]))
170 if( cntweak
> 3 || !cntdigits
|| !cntletters
)
176 reguser
*csa_createaccount(char *username
, char *password
, char *email
) {
177 time_t t
= time(NULL
);
178 char *local
, *dupemail
;
180 dupemail
= strdup(email
);
181 local
=strchr(dupemail
, '@');
188 reguser
*rup
=getreguser();
190 rup
->ID
=++lastuserID
;
191 strncpy(rup
->username
,username
,NICKLEN
); rup
->username
[NICKLEN
]='\0';
194 rup
->lastemailchange
=t
;
195 rup
->lastpasschange
=t
;
196 rup
->flags
=QUFLAG_NOTICE
;
202 strncpy(rup
->password
,password
,PASSLEN
); rup
->password
[PASSLEN
]='\0';
203 rup
->email
=getsstring(email
,EMAILLEN
);
206 rup
->localpart
=getsstring(dupemail
,EMAILLEN
);
209 rup
->domain
=findorcreatemaildomain(email
);
210 addregusertomaildomain(rup
, rup
->domain
);
212 rup
->lastuserhost
=NULL
;
213 rup
->suspendreason
=NULL
;
219 addregusertohash(rup
);