home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / LOGIN.C < prev    next >
Text File  |  1998-05-17  |  29KB  |  1,071 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <io.h>
  22. #include <time.h>
  23. #include <fcntl.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <alloc.h>
  27. #include <sys\stat.h>
  28.  
  29. #include <cxl\cxlstr.h>
  30. #include <cxl\cxlvid.h>
  31.  
  32. #include "lsetup.h"
  33. #include "sched.h"
  34. #include "msgapi.h"
  35. #include "externs.h"
  36. #include "prototyp.h"
  37. #include "zmodem.h"
  38.  
  39. extern short tcpip;
  40. extern int iemsi;
  41. extern char usr_rip;
  42.  
  43. #define MAX_INDEX    200
  44.  
  45. void f1_special_status(char *, char *, char *);
  46. int get_user_age (void);
  47. int ask_random_birth (void);
  48. void ask_birthdate (void);
  49. void ask_default_protocol (void);
  50. void ask_default_archiver (void);
  51. int iemsi_login (void);
  52. void update_sysinfo_calls (void);
  53. char *tcpip_name (char *);
  54.  
  55. static int is_trashpwd (char *);
  56. static int is_trashcan (char *);
  57.  
  58. int login_user (void)
  59. {
  60.    int fd, fflag, posit, m, original_time, i, xmq;
  61.    char stringa[36], filename[80], c, mayberip;
  62.    long crc;
  63.    struct _usr tusr;
  64.    struct _usridx usridx[MAX_INDEX];
  65.  
  66.     usr_rip = 0;
  67.     tagged_kb=0;
  68.     cmd_string[0] = '\0';
  69.    memset((char *)&lorainfo,0,sizeof(struct _lorainfo));
  70.  
  71.    start_time = time(NULL);
  72.    set_useron_record (LOGIN, 0, 0);
  73.  
  74.    xmq = allowed;
  75.    if (!allowed)
  76.       allowed = time_to_next (1);
  77.    if (config->login_timeout == 0)
  78.       config->login_timeout = 255;
  79.    if (allowed > config->login_timeout)
  80.       allowed = config->login_timeout;
  81.    usr_class = get_class(config->logon_level);
  82.    user_status = 0;
  83.  
  84.    CLEAR_INBOUND();
  85.  
  86.    if (!iemsi && config->ansilogon) {
  87.       if (config->ansilogon == 3)
  88.          usr.ibmset = usr.ansi = usr.color = usr.formfeed = 1;
  89.       else if (local_mode || config->ansilogon == 2) {
  90.          m_print (bbstxt[B_ANSI_LOGON]);
  91.          if (yesno_question (DEF_YES) == DEF_YES)
  92.             usr.ibmset = usr.ansi = usr.color = usr.formfeed = 1;
  93.       }
  94.       else if (config->ansilogon == 1) {
  95.          // Riconoscimento del RIPSCRIPT
  96.          SENDBYTE (0x1B);
  97.          SENDBYTE ('[');
  98.          SENDBYTE ('!');
  99.  
  100.          // Riconoscimento dell'ANSI (posizione del cursore).
  101.          SENDBYTE (0x1B);
  102.          SENDBYTE ('[');
  103.          SENDBYTE ('6');
  104.          SENDBYTE ('n');
  105.  
  106.          mayberip = 0;
  107.          i = 0;
  108.  
  109.          while ((m = TIMED_READ (2)) != -1) {
  110.             if (!mayberip) {
  111.                if (i == 0 && m == 'R') {
  112.                   mayberip = 1;
  113.                   i++;
  114.                }
  115.                else if (i == 0 && m != 0x1B)
  116.                   i = 0;
  117.                else if (i == 1 && m != '[')
  118.                   i = 0;
  119.                else if (i == 2 && m == 'R')
  120.                   break;
  121.                else if (i == 2 && !isdigit(m) && m != ';')
  122.                   i = 0;
  123.                else if (i < 2)
  124.                   i++;
  125.             }
  126.             else {
  127.                if (i == 0 && m != 'R') {
  128.                   i = 0;
  129.                   mayberip = 0;
  130.                }
  131.                else if (i == 1 && m != 'I') {
  132.                   i = 0;
  133.                   mayberip = 0;
  134.                }
  135.                else if (i == 2 && m == 'P')
  136.                   break;
  137.                else if (i < 2)
  138.                   i++;
  139.             }
  140.          }
  141.  
  142.          if (i == 2 && m == 'R')
  143.             usr.ibmset = usr.ansi = usr.color = usr.formfeed = 1;
  144.  
  145.          if (mayberip && i == 2 && m == 'P') {
  146.             usr.ibmset = usr.ansi = usr.color = usr.formfeed = 1;
  147.             usr_rip = 1;
  148.          }
  149.       }
  150.    }
  151.  
  152.    read_system_file ("LOGO");
  153.  
  154.    if (iemsi) {
  155.       posit = iemsi_login ();
  156.       if (posit >= 0)
  157.          goto loginok;
  158.       if (posit == -2)
  159.          return (0);
  160.    }
  161.  
  162. new_login:
  163.    stringa[0] = 0;
  164.  
  165.    m_print ("\n%s%s login.\n", VERSION, registered ? "" : NOREG);
  166.    CLEAR_INBOUND ();
  167.  
  168.    if (!usr.name[0])
  169.       do {
  170.          m_print (bbstxt[B_FULLNAME]);
  171.          chars_input (stringa, 35, INPUT_FANCY|INPUT_FIELD);
  172.          if (!CARRIER || time_remain () <= 0)
  173.             return (0);
  174.       } while (strlen(stringa) < 3);
  175.    else {
  176.       m_print (bbstxt[B_FULLNAME]);
  177.       m_print ("%-35.35s\n", usr.name);
  178.       strcpy (stringa, usr.name);
  179.    }
  180.  
  181.    fancy_str(stringa);
  182.  
  183.    if (is_trashcan (stringa)) {
  184.       status_line ("!Trashcan user `%s'", stringa);
  185.       read_system_file ("TRASHCAN");
  186.       return (0);
  187.    }
  188.  
  189.    status_line(msgtxt[M_USER_CALLING], stringa);
  190.    crc = crc_name (stringa);
  191.  
  192.    sprintf (filename, "%s.IDX", config->user_file);
  193.    fd = sh_open (filename, SH_DENYWR, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE);
  194.  
  195.    fflag = 0;
  196.    posit = 0;
  197.  
  198.    do {
  199.       i = read(fd,(char *)&usridx,sizeof(struct _usridx) * MAX_INDEX);
  200.       m = i / sizeof (struct _usridx);
  201.  
  202.       for (i=0; i < m; i++)
  203.          if (usridx[i].id == crc) {
  204.             m = 0;
  205.             posit += i;
  206.             fflag = 1;
  207.             break;
  208.          }
  209.  
  210.       if (!fflag)
  211.          posit += m;
  212.    } while (m == MAX_INDEX && !fflag);
  213.  
  214.    if (!fflag) {
  215.       lseek (fd, 0L, SEEK_SET);
  216.       posit = 0;
  217.  
  218.       do {
  219.          i = read(fd,(char *)&usridx,sizeof(struct _usridx) * MAX_INDEX);
  220.          m = i / sizeof (struct _usridx);
  221.  
  222.          for (i=0; i < m; i++)
  223.             if (usridx[i].alias_id == crc) {
  224.                m = 0;
  225.                posit += i;
  226.                fflag = 1;
  227.                break;
  228.             }
  229.  
  230.          if (!fflag)
  231.             posit += m;
  232.       } while (m == MAX_INDEX && !fflag);
  233.    }
  234.  
  235.    close (fd);
  236.  
  237.    sprintf (filename, "%s.BBS", config->user_file);
  238.  
  239.    fd = sh_open (filename, SH_DENYWR, O_RDWR|O_BINARY, S_IREAD|S_IWRITE);
  240.    lseek (fd, (long)posit * sizeof (struct _usr), SEEK_SET);
  241.    read(fd, (char *)&tusr, sizeof(struct _usr));
  242.    close (fd);
  243.  
  244.    if (!fflag) {
  245.       status_line(msgtxt[M_NOT_IN_LIST],stringa);
  246.  
  247.       m_print(bbstxt[B_TWO_CR]);
  248.  
  249.       if (check_multilogon(stringa)) {
  250.          read_system_file("1ATATIME");
  251.          return (0);
  252.       }
  253.  
  254.       m_print(bbstxt[B_NAME_NOT_FOUND]);
  255.       m_print(bbstxt[B_NAME_ENTERED], stringa);
  256.  
  257.       do {
  258.          m_print(bbstxt[B_NEW_USER]);
  259.          c = yesno_question (DEF_NO|QUESTION);
  260.          if (c == QUESTION)
  261.             read_system_file("WHY_NEW");
  262.             if (!CARRIER)
  263.                return (1);
  264.       } while(c != DEF_NO && c != DEF_YES);
  265.  
  266.       if (c == DEF_NO)
  267.          goto new_login;
  268.  
  269.       if (config->logon_level == HIDDEN) {
  270.          read_system_file ("PREREG");
  271.          return (0);
  272.       }
  273.  
  274.       if (!new_user(stringa))
  275.          goto new_login;
  276.       if (!CARRIER)
  277.          return (0);
  278.    }
  279.    else {
  280.       m = 1;
  281.  
  282.       free (bbstxt);
  283.       if (!load_language (tusr.language)) {
  284.          tusr.language = 0;
  285.          load_language (tusr.language);
  286.       }
  287.       if (config->language[tusr.language].txt_path[0])
  288.          text_path = config->language[tusr.language].txt_path;
  289.       else
  290.          text_path = config->language[0].txt_path;
  291.       usr.ansi = tusr.ansi;
  292.       usr.avatar = tusr.avatar;
  293.       usr.color = tusr.color;
  294.  
  295.       if (config->check_city) {
  296.          m_print (bbstxt[B_ASK_CORRECT_CITY], tusr.name, tusr.city);
  297.          if (yesno_question (DEF_YES) == DEF_NO) {
  298.             usr.name[0] = '\0';
  299.             goto new_login;
  300.          }
  301.       }
  302.  
  303.       for(;;) {
  304.          m_print(bbstxt[B_PASSWORD]);
  305.          chars_input(stringa,15,INPUT_PWD|INPUT_FIELD);
  306.          if (!CARRIER)
  307.             return (0);
  308.  
  309.          if(!stricmp(tusr.pwd,strcode(strupr(stringa),tusr.name)))
  310.             break;
  311.  
  312.          m_print(bbstxt[B_BAD_PASSWORD]);
  313.          status_line(msgtxt[M_BAD_PASSWORD],strcode(stringa,tusr.name));
  314.  
  315.          if(++m > 4) {
  316.             if (!read_system_file("BADPWD"))
  317.                m_print (bbstxt[B_DENIED]);
  318.             status_line(msgtxt[M_INVALID_PASSWORD]);
  319.  
  320.             if (registered) {
  321.                tusr.badpwd = 1;
  322.                memcpy((char *)&usr,(char *)&tusr,sizeof(struct _usr));
  323.             }
  324.  
  325.             return (0);
  326.          }
  327.       }
  328.  
  329.       if (check_multilogon(tusr.name)) {
  330.          read_system_file("1ATATIME");
  331.          return (0);
  332.       }
  333.  
  334.       memcpy((char *)&usr,(char *)&tusr,sizeof(struct _usr));
  335.    }
  336.  
  337. loginok:
  338.    // Se data di oggi e' diversa da quella dell'ultimo collegamento, azzera
  339.    // tutti i parametri dei limiti giornalieri.
  340.    data (stringa);
  341.    if (strncmp (stringa, usr.ldate, 9)) {
  342.       usr.time = 0;
  343.       usr.dnldl = 0;
  344.       usr.chat_minutes = 0;
  345.    }
  346.  
  347. #if defined (__OCC__) || defined (__TCPIP__)
  348.    if (tcpip)
  349.       strcpy (usr.comment, tcpip_name (usr.comment));
  350. #endif
  351.  
  352.    if (!usr.priv) {
  353.       read_system_file ("LOCKOUT");
  354.       return (0);
  355.    }
  356.  
  357.    usr_class = get_class (usr.priv);
  358.  
  359.    if (usr.ovr_class.max_time)
  360.       config->class[usr_class].max_time = usr.ovr_class.max_time;
  361.    if (usr.ovr_class.max_call)
  362.       config->class[usr_class].max_call = usr.ovr_class.max_call;
  363.    if (usr.ovr_class.max_dl)
  364.       config->class[usr_class].max_dl = usr.ovr_class.max_dl;
  365.    else {
  366.       switch (rate) {
  367.          case 300:
  368.             if (config->class[usr_class].dl_300)
  369.                config->class[usr_class].max_dl = config->class[usr_class].dl_300;
  370.             break;
  371.  
  372.          case 1200:
  373.             if (config->class[usr_class].dl_1200)
  374.                config->class[usr_class].max_dl = config->class[usr_class].dl_1200;
  375.             break;
  376.  
  377.          case 2400:
  378.          case 4800:
  379.          case 7200:
  380.             if (config->class[usr_class].dl_2400)
  381.                config->class[usr_class].max_dl = config->class[usr_class].dl_2400;
  382.             break;
  383.  
  384.          default:
  385.             if (config->class[usr_class].dl_9600)
  386.                config->class[usr_class].max_dl = config->class[usr_class].dl_9600;
  387.             break;
  388.       }
  389.    }
  390.  
  391.    if (usr.ovr_class.ratio)
  392.       config->class[usr_class].ratio = usr.ovr_class.ratio;
  393.    if (usr.ovr_class.min_baud)
  394.       config->class[usr_class].min_baud = usr.ovr_class.min_baud;
  395.    if (usr.ovr_class.min_file_baud)
  396.       config->class[usr_class].min_file_baud = usr.ovr_class.min_file_baud;
  397.    if (usr.ovr_class.start_ratio)
  398.       config->class[usr_class].start_ratio = usr.ovr_class.start_ratio;
  399.  
  400.    original_time = config->class[usr_class].max_call;
  401.    if ((usr.time + original_time) > config->class[usr_class].max_time)
  402.       original_time = config->class[usr_class].max_time - usr.time;
  403.  
  404.    if (usr.times)
  405.       status_line (msgtxt[M_USER_LAST_TIME], usr.ldate);
  406.  
  407.    if (strncmp (stringa, usr.ldate, 9))
  408.       status_line (msgtxt[M_TIMEDL_ZEROED]);
  409.  
  410.    f1_status ();
  411.    update_sysinfo_calls ();
  412.    status_line (":System call #%ld", sysinfo.total_calls);
  413.  
  414.    strcpy (lorainfo.logindate, stringa);
  415.    usr.times++;
  416.  
  417.    if (original_time <= 0) {
  418.       read_system_file ("DAYLIMIT");
  419.       FLUSH_OUTPUT ();
  420.       modem_hangup ();
  421.       return (0);
  422.    }
  423.  
  424.    allowed = xmq ? xmq : time_to_next (1);
  425.  
  426.    if (original_time < allowed)
  427.       allowed = original_time;
  428.    else
  429.       read_system_file ("TIMEWARN");
  430.  
  431.    status_line (msgtxt[M_GIVEN_LEVEL], time_remain (), get_priv_text (usr.priv));
  432.  
  433.    if (config->min_login_level && usr.priv < config->min_login_level) {
  434.       status_line ("!Level too low to login");
  435.       read_system_file ("LOGONSEC");
  436.       return (0);
  437.    }
  438.  
  439.    if (config->min_login_flags && ((usr.flags & config->min_login_flags) != config->min_login_flags)) {
  440.       status_line ("!Incorrect login flags");
  441.       read_system_file ("LOGONFLA");
  442.       return (0);
  443.    }
  444.  
  445.    if (config->min_login_age && get_user_age () && get_user_age () < config->min_login_age) {
  446.       status_line ("!User too young to login");
  447.       read_system_file ("LOGONAGE");
  448.       return (0);
  449.    }
  450.  
  451.    if ((config->birthdate || config->random_birth) && !usr.birthdate[0])
  452.       ask_birthdate ();
  453.    else if (config->random_birth) {
  454.       if (!ask_random_birth ()) {
  455.          usr.security = 1;
  456.          return (0);
  457.       }
  458.       usr.security = 0;
  459.    }
  460.  
  461.    if (usr.badpwd && registered) {
  462.       read_system_file("WARNPWD");
  463.       usr.badpwd = 0;
  464.    }
  465.  
  466.    if (usr.baud_rate && rate) {
  467.       if (usr.baud_rate < rate)
  468.          read_system_file ("MOREBAUD");
  469.       if (usr.baud_rate > rate)
  470.          read_system_file ("LESSBAUD");
  471.    }
  472.  
  473.    usr.baud_rate = local_mode ? 0 : rate;
  474.  
  475.    if (!CARRIER)
  476.       return (0);
  477.  
  478.    sprintf (filename, "%s.BBS", config->user_file);
  479.    fd = sh_open (filename, SH_DENYWR, O_RDWR|O_BINARY, S_IREAD|S_IWRITE);
  480.    lseek (fd, (long)posit * sizeof (struct _usr), SEEK_SET);
  481.    write (fd, (char *)&usr, sizeof (struct _usr));
  482.    close (fd);
  483.  
  484.    lorainfo.posuser = posit;
  485.  
  486.    if (rate && rate < config->class[usr_class].min_baud) {
  487.       read_system_file ("TOOSLOW");
  488.       FLUSH_OUTPUT ();
  489.       modem_hangup ();
  490.       return (0);
  491.    }
  492.  
  493.    read_system_file ("WELCOME");
  494.    if (!CARRIER)
  495.       return (0);
  496.  
  497.    read_hourly_files ();
  498.    read_comment ();
  499.  
  500.    data (stringa);
  501.    if (!strncmp (stringa, usr.birthdate, 6))
  502.       read_system_file ("BIRTHDAY");
  503.  
  504.    if (usr.times > 1) {
  505.       if (usr.times < config->rookie_calls)
  506.          read_system_file ("ROOKIE");
  507.  
  508.       sprintf (filename, "%s%d", config->sys_path, posit);
  509.       if (dexists (filename))
  510.          read_file (filename);
  511.    }
  512.    else
  513.       read_system_file ("NEWUSER2");
  514.  
  515.    return ((!CARRIER) ? 0 : 1);
  516. }
  517.  
  518. int new_user (char *buff)
  519. {
  520.    int c, fd;
  521.    char stringa[40], filename[80];
  522.    struct _usr tusr;
  523.    struct _usridx usridx;
  524.  
  525.    cmd_string[0] = '\0';
  526.    memset((char *)&tusr,0,sizeof(struct _usr));
  527.    memset((char *)&usr,0,sizeof(struct _usr));
  528.  
  529.    while ((c = select_language ()) == -1 && CARRIER);
  530.    tusr.language = (byte) c;
  531.  
  532.    if (!CARRIER)
  533.       return (0);
  534.    free (bbstxt);
  535.    if (!load_language (tusr.language)) {
  536.       tusr.language = 0;
  537.       load_language (tusr.language);
  538.    }
  539.    if (config->language[tusr.language].txt_path[0])
  540.       text_path = config->language[tusr.language].txt_path;
  541.    else
  542.       text_path = config->language[0].txt_path;
  543.  
  544.    read_system_file ("APPLIC");
  545.  
  546.    strcpy (tusr.name, buff);
  547.    strcpy (tusr.handle, buff);
  548.  
  549.    if (rate && rate >= speed_graphics) {
  550.       if (config->ansigraphics == 2) {
  551.          do {
  552.             m_print(bbstxt[B_ASK_ANSI]);
  553.             c = yesno_question (DEF_NO|QUESTION);
  554.             if(c == QUESTION)
  555.                read_system_file("WHY_ANSI");
  556.             if (!CARRIER)
  557.                return (1);
  558.          } while(c != DEF_NO && c != DEF_YES);
  559.  
  560.          if (c == DEF_YES)
  561.             tusr.ansi = 1;
  562.       }
  563.       else
  564.          tusr.ansi = config->ansigraphics;
  565.  
  566.       if (!tusr.ansi) {
  567.          if (config->avatargraphics == 2) {
  568.             do {
  569.                m_print(bbstxt[B_ASK_AVATAR]);
  570.                c = yesno_question (DEF_NO|QUESTION);
  571.                if(c == QUESTION)
  572.                   read_system_file("WHY_AVT");
  573.                if (!CARRIER)
  574.                   return (1);
  575.             } while(c != DEF_NO && c != DEF_YES);
  576.  
  577.             if(c == DEF_YES)
  578.                tusr.avatar=1;
  579.          }
  580.          else
  581.             tusr.avatar = config->avatargraphics;
  582.       }
  583.  
  584.       if (!CARRIER)
  585.          return (1);
  586.  
  587.       if (tusr.ansi || tusr.avatar) {
  588.          do {
  589.             m_print(bbstxt[B_ASK_COLOR]);
  590.             c = yesno_question (DEF_YES|QUESTION);
  591.             if(c == QUESTION)
  592.                read_system_file("WHY_COL");
  593.             if (!CARRIER)
  594.                return (1);
  595.          } while(c != DEF_NO && c != DEF_YES);
  596.  
  597.          if(c == DEF_YES)
  598.             tusr.color=1;
  599.       }
  600.  
  601.       memcpy((char *)&usr, (char *)&tusr, sizeof(struct _usr));
  602.       usr.name[0] = '\0';
  603.  
  604.       tusr.use_lore = 1;
  605.  
  606.       if (tusr.ansi || tusr.avatar) {
  607.          if (config->fullscrnedit == 2) {
  608.             do {
  609.                m_print(bbstxt[B_ASK_EDITOR]);
  610.                c = yesno_question (DEF_YES|QUESTION);
  611.                if(c == QUESTION)
  612.                   read_system_file("WHY_OPED");
  613.                if (!CARRIER)
  614.                   return (1);
  615.             } while(c != DEF_NO && c != DEF_YES);
  616.  
  617.             if(c == DEF_YES)
  618.                tusr.use_lore = 0;
  619.          }
  620.          else if (config->fullscrnedit)
  621.             tusr.use_lore = 0;
  622.          else
  623.             tusr.use_lore = 1;
  624.       }
  625.  
  626.       if (tusr.ansi || tusr.avatar) {
  627.          do {
  628.             m_print(bbstxt[B_ASK_FULLREAD]);
  629.             c = yesno_question (DEF_YES|QUESTION);
  630.             if(c == QUESTION)
  631.                read_system_file("WHY_FULR");
  632.             if (!CARRIER)
  633.                return (1);
  634.          } while(c != DEF_NO && c != DEF_YES);
  635.  
  636.          if(c == DEF_YES)
  637.             tusr.full_read=1;
  638.       }
  639.    }
  640.  
  641.    if (config->ask_alias) {
  642.       handle_change ();
  643.       strcpy (tusr.handle, usr.handle);
  644.    }
  645.  
  646.    if (config->hotkeys == 2) {
  647.       m_print (bbstxt[B_USE_HOTKEY]);
  648.       if (yesno_question (DEF_YES) == DEF_YES)
  649.          usr.hotkey = tusr.hotkey = 1;
  650.    }
  651.    else
  652.       usr.hotkey = tusr.hotkey = config->hotkeys;
  653.  
  654.    if (config->ibmset) {
  655.       do {
  656.          m_print(bbstxt[B_ASK_IBMSET]);
  657.          c = yesno_question ((usr.ansi || usr.avatar) ? DEF_YES|QUESTION : DEF_NO|QUESTION);
  658.          if(c == QUESTION)
  659.             read_system_file("WHY_IBM");
  660.          if (!CARRIER)
  661.             return (1);
  662.       } while(c != DEF_NO && c != DEF_YES);
  663.  
  664.       if(c == DEF_YES)
  665.          tusr.ibmset=1;
  666.    }
  667.    else
  668.       tusr.ibmset = 1;
  669.  
  670.    usr.len = 24;
  671.    screen_change ();
  672.    tusr.len = usr.len;
  673.  
  674.    if (config->moreprompt == 2) {
  675.       do {
  676.          m_print(bbstxt[B_ASK_MORE]);
  677.          c = yesno_question (DEF_YES);
  678.          if (!CARRIER)
  679.             return (1);
  680.       } while(c != DEF_NO && c != DEF_YES);
  681.  
  682.       if(c == DEF_YES)
  683.          tusr.more = 1;
  684.    }
  685.    else
  686.       tusr.more = config->moreprompt;
  687.  
  688.    if (config->screenclears == 2) {
  689.       do {
  690.          m_print(bbstxt[B_ASK_CLEAR]);
  691.          c = yesno_question (DEF_YES);
  692.          if (!CARRIER)
  693.             return (1);
  694.       } while(c != DEF_NO && c != DEF_YES);
  695.  
  696.       if(c == DEF_YES)
  697.          tusr.formfeed = 1;
  698.    }
  699.    else
  700.       tusr.formfeed = config->screenclears;
  701.  
  702.    memcpy((char *)&usr, (char *)&tusr, sizeof(struct _usr));
  703.    usr.name[0] = '\0';
  704.  
  705.    do {
  706.       m_print(bbstxt[B_CITY_STATE]);
  707.       chars_input(stringa,35,INPUT_FIELD);
  708.       if (!CARRIER)
  709.          return (1);
  710.    } while(!strlen(stringa));
  711.  
  712.    strcpy(tusr.city,fancy_str(stringa));
  713.  
  714.    if (config->birthdate) {
  715.       ask_birthdate ();
  716.       strcpy (tusr.birthdate, usr.birthdate);
  717.    }
  718.  
  719.    if (config->voicephone) {
  720.       voice_phone_change();
  721.       strcpy(tusr.voicephone, usr.voicephone);
  722.       if (!CARRIER)
  723.          return (1);
  724.    }
  725.  
  726.    if (config->dataphone) {
  727.       data_phone_change();
  728.       strcpy(tusr.dataphone, usr.dataphone);
  729.       if (!CARRIER)
  730.          return (1);
  731.    }
  732.  
  733.    if (config->mailcheck == 2) {
  734.       do {
  735.          m_print(bbstxt[B_LOGON_CHECKMAIL]);
  736.          c = yesno_question (DEF_YES);
  737.          if (!CARRIER)
  738.                  return (1);
  739.       } while(c != DEF_NO && c != DEF_YES);
  740.  
  741.       if(c == DEF_YES)
  742.          tusr.scanmail = 1;
  743.    }
  744.    else
  745.       tusr.scanmail = config->mailcheck;
  746.  
  747.    if (config->ask_protocol) {
  748.       ask_default_protocol ();
  749.       tusr.protocol = usr.protocol;
  750.    }
  751.  
  752.    if (config->ask_packer) {
  753.       ask_default_archiver ();
  754.       tusr.archiver = usr.archiver;
  755.    }
  756.  
  757.    memcpy((char *)&usr, (char *)&tusr, sizeof(struct _usr));
  758.    usr.name[0] = '\0';
  759.  
  760.    strcpy (tusr.ldate," 1 Jan 80  00:00:00");
  761.    data (tusr.firstdate);
  762.    tusr.priv = config->logon_level;
  763.    tusr.flags = config->logon_flags;
  764.    tusr.width = 80;
  765.    tusr.tabs = 1;
  766.    tusr.ptrquestion = -1L;
  767.    if (config->filebox)
  768.       tusr.havebox = 1;
  769.  
  770.    memcpy((char *)&usr, (char *)&tusr, sizeof(struct _usr));
  771.    usr.name[0] = '\0';
  772.  
  773.    read_system_file("NEWUSER1");
  774.    change_attr(LRED|_BLACK);
  775.  
  776.    for(;;) {
  777.       do {
  778.          m_print(bbstxt[B_SELECT_PASSWORD]);
  779.          chars_input(stringa,15,INPUT_PWD|INPUT_FIELD);
  780.          if (!CARRIER)
  781.             return (1);
  782.       } while(strlen(stringa) < 4);
  783.  
  784.       if (is_trashpwd (stringa)) {
  785.          status_line ("!Trashcan password `%s'", stringa);
  786.          read_system_file ("TRASHPWD");
  787.          continue;
  788.       }
  789.  
  790.       strcpy(tusr.pwd,stringa);
  791.  
  792.       do {
  793.          m_print(bbstxt[B_VERIFY_PASSWORD]);
  794.          chars_input(stringa,15,INPUT_PWD|INPUT_FIELD);
  795.          if (!CARRIER)
  796.             return (1);
  797.       } while(!strlen(stringa));
  798.  
  799.       if(!stricmp(stringa, tusr.pwd))
  800.          break;
  801.  
  802.       m_print(bbstxt[B_WRONG_PWD1],strupr(tusr.pwd));
  803.       m_print(bbstxt[B_WRONG_PWD2],strupr(stringa));
  804.    }
  805.  
  806.    strcpy(tusr.pwd,strcode(strupr(stringa),tusr.name));
  807.    data (stringa);
  808.    stringa[9] = '\0';
  809.    strcpy (usr.lastpwdchange, stringa);
  810.  
  811.    usridx.id = crc_name (tusr.name);
  812.    usridx.alias_id = crc_name (tusr.handle);
  813.    tusr.id = usridx.id;
  814.    tusr.alias_id = usridx.alias_id;
  815.    memcpy ((char *)&usr, (char *)&tusr, sizeof(struct _usr));
  816.  
  817.    sprintf (filename, "%s.IDX", config->user_file);
  818.    fd = open (filename, O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  819.    lseek (fd, 0L, SEEK_END);
  820.    write (fd, (char *)&usridx, sizeof (struct _usridx));
  821.    close (fd);
  822.  
  823.    sprintf (filename, "%s.BBS", config->user_file);
  824.    fd = open (filename, O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  825.    lseek (fd, 0L, SEEK_END);
  826.    write (fd, (char *)&usr, sizeof (struct _usr));
  827.    close (fd);
  828.  
  829.    return (1);
  830. }
  831.  
  832. long crc_name (name)
  833. char *name;
  834. {
  835.    int i;
  836.    long crc;
  837.  
  838.    crc = 0xFFFFFFFFL;
  839.    for (i=0; i < strlen(name); i++)
  840.            crc = Z_32UpdateCRC (((unsigned short) name[i]), crc);
  841.  
  842.    return (crc);
  843. }
  844.  
  845. static int is_trashpwd (s)
  846. char *s;
  847. {
  848.    FILE *fp;
  849.    char buffer[40];
  850.  
  851.    fp = fopen ("PWDTRASH.CFG", "rt");
  852.    if (fp != NULL) {
  853.       while (fgets (buffer, 38, fp) != NULL) {
  854.          buffer[strlen (buffer) - 1] = '\0';
  855.          if (!stricmp (buffer, s))
  856.             return (1);
  857.       }
  858.  
  859.       fclose (fp);
  860.    }
  861.  
  862.    return (0);
  863. }
  864.  
  865. static int is_trashcan (s)
  866. char *s;
  867. {
  868.    FILE *fp;
  869.    char buffer[40];
  870.  
  871.    fp = fopen ("TRASHCAN.CFG", "rt");
  872.    if (fp != NULL) {
  873.       while (fgets (buffer, 38, fp) != NULL) {
  874.          buffer[strlen(buffer) - 1] = '\0';
  875.          if (!stricmp (buffer, s))
  876.             return (1);
  877.       }
  878.  
  879.       fclose (fp);
  880.    }
  881.  
  882.    return (0);
  883. }
  884.  
  885. int iemsi_login (void)
  886. {
  887.    int fd, fflag, posit, m, i;
  888.    char stringa[36], filename[80], c;
  889.    long crc;
  890.    struct _usr tusr;
  891.    struct _usridx usridx[MAX_INDEX];
  892.    struct _usridx uidx;
  893.  
  894.    status_line (":IEMSI login detected");
  895.  
  896.    strcpy (stringa, strbtrim (usr.name));
  897.    strcpy (usr.name, fancy_str (stringa));
  898.  
  899.    if (is_trashcan (stringa)) {
  900.       status_line ("!Trashcan user `%s'", stringa);
  901.       read_system_file ("TRASHCAN");
  902.       return (-2);
  903.    }
  904.  
  905.    status_line(msgtxt[M_USER_CALLING], stringa);
  906.    crc = crc_name (stringa);
  907.  
  908.    sprintf (filename, "%s.IDX", config->user_file);
  909.    fd = sh_open (filename, SH_DENYWR, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE);
  910.  
  911.    fflag = 0;
  912.    posit = 0;
  913.  
  914.    do {
  915.       i = read(fd,(char *)&usridx,sizeof(struct _usridx) * MAX_INDEX);
  916.       m = i / sizeof (struct _usridx);
  917.  
  918.       for (i = 0; i < m; i++, posit++)
  919.          if (usridx[i].id == crc) {
  920.             fflag = 1;
  921.             break;
  922.          }
  923.    } while (m == MAX_INDEX && !fflag);
  924.  
  925.    if (!fflag) {
  926.       lseek (fd, 0L, SEEK_SET);
  927.       posit = 0;
  928.  
  929.       do {
  930.          i = read(fd,(char *)&usridx,sizeof(struct _usridx) * MAX_INDEX);
  931.          m = i / sizeof (struct _usridx);
  932.  
  933.          for (i = 0; i < m; i++, posit++)
  934.             if (usridx[i].alias_id == crc) {
  935.                fflag = 1;
  936.                break;
  937.             }
  938.       } while (m == MAX_INDEX && !fflag);
  939.    }
  940.  
  941.    close (fd);
  942.  
  943.    if (!fflag) {
  944.       status_line(msgtxt[M_NOT_IN_LIST],stringa);
  945.  
  946.       m_print(bbstxt[B_TWO_CR]);
  947.  
  948.       if (check_multilogon(stringa)) {
  949.          read_system_file("1ATATIME");
  950.          return (-2);
  951.       }
  952.  
  953.       if (config->logon_level == HIDDEN) {
  954.          read_system_file ("PREREG");
  955.          return (-2);
  956.       }
  957.  
  958.       while ((c = select_language ()) == -1 && CARRIER)
  959.          ;
  960.       usr.language = (byte) c;
  961.  
  962.       if (!CARRIER)
  963.          return (0);
  964.       free (bbstxt);
  965.       if (!load_language (usr.language)) {
  966.          usr.language = 0;
  967.          load_language (usr.language);
  968.       }
  969.       if (config->language[usr.language].txt_path[0])
  970.          text_path = config->language[usr.language].txt_path;
  971.       else
  972.          text_path = config->language[0].txt_path;
  973.  
  974.       read_system_file ("APPLIC");
  975.  
  976.       if (config->birthdate)
  977.          ask_birthdate ();
  978.  
  979.       if (config->ask_protocol)
  980.          ask_default_protocol ();
  981.  
  982.       if (config->ask_packer)
  983.          ask_default_archiver ();
  984.  
  985.       strcode (strupr (usr.pwd), usr.name);
  986.  
  987.       strcpy (usr.ldate, " 1 Jan 80  00:00:00");
  988.       data (stringa);
  989.       strcpy (usr.firstdate, stringa);
  990.       stringa[9] = '\0';
  991.       strcpy (usr.lastpwdchange, stringa);
  992.       usr.priv = config->logon_level;
  993.       usr.flags = config->logon_flags;
  994.       usr.tabs = 1;
  995.       usr.ptrquestion = -1L;
  996.       if (config->filebox)
  997.          usr.havebox = 1;
  998.  
  999.       uidx.id = crc_name (usr.name);
  1000.       uidx.alias_id = crc_name (usr.handle);
  1001.       usr.id = uidx.id;
  1002.       usr.alias_id = uidx.alias_id;
  1003.  
  1004.       sprintf (filename, "%s.IDX", config->user_file);
  1005.       fd = sh_open (filename, SH_DENYWR, O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  1006.       lseek (fd, 0L, SEEK_END);
  1007.       posit = (int)(tell (fd) / sizeof (struct _usridx));
  1008.       write (fd, (char *)&uidx, sizeof (struct _usridx));
  1009.       close (fd);
  1010.  
  1011.       sprintf (filename, "%s.BBS", config->user_file);
  1012.       fd = sh_open (filename, SH_DENYWR, O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  1013.       lseek (fd, 0L, SEEK_END);
  1014.       write (fd, (char *)&usr, sizeof (struct _usr));
  1015.       close (fd);
  1016.    }
  1017.    else {
  1018.       sprintf (filename, "%s.BBS", config->user_file);
  1019.  
  1020.       fd = sh_open (filename, SH_DENYWR, O_RDWR|O_BINARY, S_IREAD|S_IWRITE);
  1021.       lseek (fd, (long)posit * sizeof (struct _usr), SEEK_SET);
  1022.       read (fd, (char *)&tusr, sizeof(struct _usr));
  1023.       close (fd);
  1024.  
  1025.       m = 1;
  1026.  
  1027.       free (bbstxt);
  1028.       if (!load_language (tusr.language)) {
  1029.          tusr.language = 0;
  1030.          load_language (tusr.language);
  1031.       }
  1032.       if (config->language[tusr.language].txt_path[0])
  1033.          text_path = config->language[tusr.language].txt_path;
  1034.       else
  1035.          text_path = config->language[0].txt_path;
  1036.  
  1037.       if (stricmp (tusr.pwd, strcode (strupr(usr.pwd), tusr.name))) {
  1038.          m_print(bbstxt[B_BAD_PASSWORD]);
  1039.          status_line(msgtxt[M_BAD_PASSWORD],strcode(stringa,tusr.name));
  1040.  
  1041.          return (-1);
  1042.       }
  1043.  
  1044.       if (check_multilogon (tusr.name)) {
  1045.          read_system_file ("1ATATIME");
  1046.          return (-2);
  1047.       }
  1048.  
  1049.       strcpy (tusr.handle, usr.handle);
  1050.       strcpy (tusr.city, usr.city);
  1051.       strcpy (tusr.dataphone, usr.dataphone);
  1052.       strcpy (tusr.voicephone, usr.voicephone);
  1053.       tusr.ansi = usr.ansi;
  1054.       tusr.avatar = usr.avatar;
  1055.       tusr.color = usr.color;
  1056.       tusr.len = usr.len;
  1057.       tusr.width = usr.width;
  1058.       tusr.nulls = usr.nulls;
  1059.       tusr.ibmset = usr.ibmset;
  1060.       tusr.more = usr.more;
  1061.       tusr.hotkey = usr.hotkey;
  1062.       tusr.formfeed = usr.formfeed;
  1063.       tusr.use_lore = usr.use_lore;
  1064.  
  1065.       memcpy ((char *)&usr, (char *)&tusr, sizeof (struct _usr));
  1066.    }
  1067.  
  1068.    return (posit);
  1069. }
  1070.  
  1071.