]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authlib.c
4 #include "../lib/irc_string.h"
10 #include <sys/types.h>
13 static pcre
*remail
, *raccount
;
15 void csa_initregex(void) {
19 if (!(remail
=pcre_compile(VALID_EMAIL
, PCRE_CASELESS
, &errptr
, &erroffset
, NULL
)))
20 Error("chanserv", ERR_STOP
, "Unable to compile email regex (error: %s, position: %d).", errptr
, erroffset
);
22 if (!(raccount
=pcre_compile(VALID_ACCOUNT_NAME
, PCRE_CASELESS
, &errptr
, &erroffset
, NULL
)))
23 Error("chanserv", ERR_STOP
, "Unable to compile account name regex (error: %s, position: %d).", errptr
, erroffset
);
26 void csa_freeregex(void) {
32 * use regex matching to determine if it's a valid eboy or not
34 int csa_checkeboy_r(char *eboy
)
38 len
= (((strlen(eboy
)) < (EMAILLEN
)) ? (strlen(eboy
)) : (EMAILLEN
));
40 return QM_EMAILTOOSHORT
;
43 /* catch some real lame attempts */
44 if (!ircd_strncmp("user@mymailhost.xx", eboy
, len
) || !ircd_strncmp("info@quakenet.org", eboy
, len
)
45 || !ircd_strncmp("user@mymail.xx", eboy
, len
) || !ircd_strncmp("user@mail.cc", eboy
, len
)
46 || !ircd_strncmp("user@host.com", eboy
, len
) || !ircd_strncmp("Jackie@your.isp.com", eboy
, len
)
47 || !ircd_strncmp("QBot@QuakeNet.org", eboy
, len
) || !ircd_strncmp("Q@CServe.quakenet.org", eboy
, len
)
48 || !ircd_strncmp("badger@example.com", eboy
, len
)) {
49 return QM_NOTYOUREMAIL
;
52 if (pcre_exec(remail
, NULL
, eboy
, strlen(eboy
), 0, 0, NULL
, 0) < 0) {
53 return QM_INVALIDEMAIL
;
59 int csa_checkeboy(nick
*sender
, char *eboy
)
61 int r
= csa_checkeboy_r(eboy
);
66 chanservstdmessage(sender
, r
, eboy
);
72 * use regex matching to determine if it's a valid account name or not
73 * returns 1 if bad, 0 if good
75 int csa_checkaccountname_r(char *accountname
) {
76 if (pcre_exec(raccount
, NULL
, accountname
, strlen(accountname
), 0, 0, NULL
, 0) < 0) {
82 int csa_checkaccountname(nick
*sender
, char *accountname
) {
83 int r
= csa_checkaccountname_r(accountname
);
85 chanservstdmessage(sender
, QM_INVALIDACCOUNTNAME
);
91 * create a random pw. code stolen from fox's O
93 void csa_createrandompw(char *pw
, int n
)
96 char upwdchars
[] = "ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789-!";
98 for (i
= 0; i
< n
; i
++) {
99 pw
[i
] = upwdchars
[rand() % (sizeof(upwdchars
) - 1)];
105 * check if account is "throttled"
107 int csa_checkthrottled(nick
*sender
, reguser
*rup
, char *s
)
114 d
=MAX_RESEND_TIME
+rup
->lastemailchange
-now
;
116 if (d
>MAX_RESEND_TIME
)
120 t
= ((float) d
) / ((float) 3600);
121 chanservstdmessage(sender
, QM_MAILTHROTTLED
, t
);
122 cs_log(sender
,"%s FAIL username %s, new request throttled for %.1f hours",s
,rup
->username
,t
);
128 int csa_checkpasswordquality(char *password
) {
129 int i
, cntweak
= 0, cntdigits
= 0, cntletters
= 0;
130 if (strlen(password
) < 6)
133 if (strlen(password
) > 10)
136 for ( i
= 0; password
[i
] && i
< PASSLEN
; i
++ ) {
137 if ( password
[i
] == password
[i
+1] || password
[i
] + 1 == password
[i
+1] || password
[i
] - 1 == password
[i
+1] )
139 if(isdigit(password
[i
]))
141 if(islower(password
[i
]) || isupper(password
[i
]))
143 if(password
[i
] < 32 || password
[i
] > 127)
147 if( cntweak
> 3 || !cntdigits
|| !cntletters
)
153 reguser
*csa_createaccount(char *username
, char *password
, char *email
) {
154 time_t t
= time(NULL
);
155 char *local
, *dupemail
;
157 dupemail
= strdup(email
);
158 local
=strchr(dupemail
, '@');
165 reguser
*rup
=getreguser();
167 rup
->ID
=++lastuserID
;
168 strncpy(rup
->username
,username
,NICKLEN
); rup
->username
[NICKLEN
]='\0';
171 rup
->lastemailchange
=t
;
172 rup
->lastpasschange
=t
;
173 rup
->flags
=QUFLAG_NOTICE
;
179 strncpy(rup
->password
,password
,PASSLEN
); rup
->password
[PASSLEN
]='\0';
180 rup
->email
=getsstring(email
,EMAILLEN
);
183 rup
->localpart
=getsstring(dupemail
,EMAILLEN
);
186 rup
->domain
=findorcreatemaildomain(email
);
187 addregusertomaildomain(rup
, rup
->domain
);
189 rup
->lastuserhost
=NULL
;
190 rup
->suspendreason
=NULL
;
196 addregusertohash(rup
);
201 int csa_completeauth2(reguser
*rup
, char *nickname
, char *ident
, char *hostname
, char *authtype
, void (*reply
)(nick
*, int, ...), nick
*reply_to
) {
204 char userhost
[USERLEN
+HOSTLEN
+2];
208 /* This should never fail but do something other than crashing if it does. */
209 if (!(anp
=findauthname(rup
->ID
))) {
210 reply(reply_to
, QM_AUTHFAIL
);
214 /* Check for too many auths. Don't return immediately, since we will still warn
215 * other users on the acct in this case. */
216 if (!UHasStaffPriv(rup
) && !UIsNoAuthLimit(rup
)) {
217 if (anp
->usercount
>= MAXAUTHCOUNT
) {
218 reply(reply_to
, QM_TOOMANYAUTHS
);
223 for (onp
=anp
->nicks
;onp
;onp
=onp
->nextbyauthname
) {
225 chanservstdmessage(onp
, QM_OTHERUSERAUTHEDLIMIT
, nickname
, ident
, hostname
, MAXAUTHCOUNT
);
227 chanservstdmessage(onp
, QM_OTHERUSERAUTHED
, nickname
, ident
, hostname
);
236 if (UHasSuspension(rup
) && rup
->suspendexp
&& (now
>= rup
->suspendexp
)) {
237 /* suspension has expired, remove it */
238 rup
->flags
&=(~(QUFLAG_SUSPENDED
|QUFLAG_GLINE
|QUFLAG_DELAYEDGLINE
));
241 freesstring(rup
->suspendreason
);
242 rup
->suspendreason
=0;
243 csdb_updateuser(rup
);
246 if (UIsSuspended(rup
)) {
248 reply(reply_to
, QM_AUTHSUSPENDED
);
249 if(rup
->suspendreason
)
250 reply(reply_to
, QM_REASON
, rup
->suspendreason
->content
);
252 reply(reply_to
, QM_EXPIRES
, rup
->suspendexp
);
255 if (UIsInactive(rup
)) {
256 reply(reply_to
, QM_INACTIVEACCOUNT
);
260 /* Guarantee a unique auth timestamp for each account */
261 if (rup
->lastauth
< now
)
266 sprintf(userhost
,"%s@%s",ident
,hostname
);
267 if (rup
->lastuserhost
)
268 freesstring(rup
->lastuserhost
);
269 rup
->lastuserhost
=getsstring(userhost
,USERLEN
+HOSTLEN
+1);
271 csdb_updateuser(rup
);
273 cs_log(NULL
,"%s!%s@%s [noauth] %s OK username %s",nickname
,ident
,hostname
,authtype
,rup
->username
);