Annotation of sbbs/src/sbbs3/login.cpp, revision 1.1.1.2

1.1       root        1: /* login.cpp */
                      2: 
                      3: /* Synchronet user login routine */
                      4: 
1.1.1.2 ! root        5: /* $Id: login.cpp,v 1.21 2011/09/21 03:16:11 rswindell Exp $ */
1.1       root        6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       12:  *                                                                                                                                                     *
                     13:  * This program is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU General Public License                         *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU General Public License for more details: gpl.txt or                     *
                     18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #include "sbbs.h"
                     39: #include "cmdshell.h"
                     40: 
                     41: int sbbs_t::login(char *username, char *pw)
                     42: {
                     43:        char    str[128];
                     44:        char    tmp[512];
                     45:        long    useron_misc=useron.misc;
                     46: 
                     47:        useron.number=0;
                     48: #if 0
                     49:        if(cfg.node_dollars_per_call && noyes(text[AreYouSureQ]))
                     50:                return(LOGIC_FALSE);
                     51: #endif
                     52: 
                     53:        SAFECOPY(str,username);
                     54: 
                     55:        if(str[0]=='*') {
                     56:                memmove(str,str+1,strlen(str));
1.1.1.2 ! root       57:                qwklogon=1; 
        !            58:        }
1.1       root       59:        else
                     60:                qwklogon=0;
                     61: 
1.1.1.2 ! root       62:        if(!(cfg.node_misc&NM_NO_NUM) && isdigit((uchar)str[0])) {
1.1       root       63:                useron.number=atoi(str);
                     64:                getuserdat(&cfg,&useron);
                     65:                if(useron.number && useron.misc&(DELETED|INACTIVE))
1.1.1.2 ! root       66:                        useron.number=0; 
        !            67:        }
1.1       root       68: 
                     69:        if(!useron.number) {
                     70:                useron.number=matchuser(&cfg,str,FALSE);
                     71:                if(!useron.number && (uchar)str[0]<0x7f && str[1]
                     72:                        && isalpha(str[0]) && strchr(str,' ') && cfg.node_misc&NM_LOGON_R)
1.1.1.2 ! root       73:                        useron.number=userdatdupe(0,U_NAME,LEN_NAME,str);
1.1       root       74:                if(useron.number) {
                     75:                        getuserdat(&cfg,&useron);
                     76:                        if(useron.number && useron.misc&(DELETED|INACTIVE))
1.1.1.2 ! root       77:                                useron.number=0; } 
        !            78:        }
1.1       root       79: 
                     80:        if(!useron.number) {
                     81:                if(cfg.node_misc&NM_LOGON_P) {
1.1.1.2 ! root       82:                        SAFECOPY(useron.alias,str);
1.1       root       83:                        bputs(pw);
                     84:                        console|=CON_R_ECHOX;
                     85:                        getstr(str,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB);
                     86:                        console&=~(CON_R_ECHOX|CON_L_ECHOX);
1.1.1.2 ! root       87:                        badlogin(useron.alias, str);
1.1       root       88:                        bputs(text[InvalidLogon]);      /* why does this always fail? */
                     89:                        if(cfg.sys_misc&SM_ECHO_PW) 
                     90:                                sprintf(tmp,"(%04u)  %-25s  FAILED Password attempt: '%s'"
                     91:                                        ,0,useron.alias,str);
                     92:                        else
                     93:                                sprintf(tmp,"(%04u)  %-25s  FAILED Password attempt"
                     94:                                        ,0,useron.alias);
1.1.1.2 ! root       95:                        logline(LOG_NOTICE,"+!",tmp); 
1.1       root       96:                } else {
                     97:                        bputs(text[UnknownUser]);
                     98:                        sprintf(tmp,"Unknown User '%s'",str);
1.1.1.2 ! root       99:                        logline(LOG_NOTICE,"+!",tmp); 
        !           100:                }
1.1       root      101:                useron.misc=useron_misc;
1.1.1.2 ! root      102:                return(LOGIC_FALSE); 
        !           103:        }
1.1       root      104: 
                    105:        if(!online) {
                    106:                useron.number=0;
1.1.1.2 ! root      107:                return(LOGIC_FALSE); 
        !           108:        }
1.1       root      109: 
                    110:        if(useron.pass[0] || REALSYSOP) {
                    111:                bputs(pw);
                    112:                console|=CON_R_ECHOX;
                    113:                getstr(str,LEN_PASS*2,K_UPPER|K_LOWPRIO|K_TAB);
                    114:                console&=~(CON_R_ECHOX|CON_L_ECHOX);
                    115:                if(!online) {
                    116:                        useron.number=0;
1.1.1.2 ! root      117:                        return(LOGIC_FALSE); 
        !           118:                }
1.1       root      119:                if(stricmp(useron.pass,str)) {
1.1.1.2 ! root      120:                        badlogin(useron.alias, str);
1.1       root      121:                        bputs(text[InvalidLogon]);
                    122:                        if(cfg.sys_misc&SM_ECHO_PW) 
                    123:                                sprintf(tmp,"(%04u)  %-25s  FAILED Password: '%s' Attempt: '%s'"
                    124:                                        ,useron.number,useron.alias,useron.pass,str);
                    125:                        else
                    126:                                sprintf(tmp,"(%04u)  %-25s  FAILED Password attempt"
                    127:                                        ,useron.number,useron.alias);
1.1.1.2 ! root      128:                        logline(LOG_NOTICE,"+!",tmp);
1.1       root      129:                        useron.number=0;
                    130:                        useron.misc=useron_misc;
1.1.1.2 ! root      131:                        return(LOGIC_FALSE); 
        !           132:                }
1.1       root      133:                if(REALSYSOP && !chksyspass()) {
                    134:                        bputs(text[InvalidLogon]);
                    135:                        useron.number=0;
                    136:                        useron.misc=useron_misc;
1.1.1.2 ! root      137:                        return(LOGIC_FALSE); 
        !           138:                } 
        !           139:        }
1.1       root      140: 
                    141:        return(LOGIC_TRUE);
                    142: }
1.1.1.2 ! root      143: 
        !           144: void sbbs_t::badlogin(char* user, char* passwd)
        !           145: {
        !           146:        char reason[128];
        !           147:        ulong count;
        !           148: 
        !           149:        SAFEPRINTF(reason,"%s LOGIN", connection);
        !           150:        count=loginFailure(startup->login_attempt_list, &client_addr, connection, user, passwd);
        !           151:        if(startup->login_attempt_hack_threshold && count>=startup->login_attempt_hack_threshold)
        !           152:                ::hacklog(&cfg, reason, user, passwd, client_name, &client_addr);
        !           153:        if(startup->login_attempt_filter_threshold && count>=startup->login_attempt_filter_threshold)
        !           154:                filter_ip(&cfg, connection, "- TOO MANY CONSECUTIVE FAILED LOGIN ATTEMPTS"
        !           155:                        ,client_name, inet_ntoa(client_addr.sin_addr), user, /* fname: */NULL);
        !           156: 
        !           157:        mswait(startup->login_attempt_delay);
        !           158: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.