home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / Logger / Lock.s < prev    next >
Text File  |  1993-12-21  |  5KB  |  305 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1992        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    Don´t try to understand the code    *
  8. *                        *
  9. * Version 1.00    11/08/1992            *
  10. *                        *
  11. * BUGS:                     *
  12. *                        *
  13. *************************************************
  14.  
  15.     INCLUDE    "JMPLibs.i"
  16.     INCLUDE    "exec/types.i"
  17.     INCLUDE    "libraries/dos.i"
  18.  
  19.     INCLUDE    "XREF:2.0.xref"
  20.     INCLUDE    "XREF:exec.xref"
  21.     INCLUDE    "XREF:dos.xref"
  22.  
  23.     XREF    _LVOSetMode
  24.  
  25.  
  26. TRUE:        EQU    1
  27. FALSE:        EQU    0
  28.  
  29.         section    Lock,CODE
  30.  
  31.         move.l    a0,a4
  32.         clr.b    -1(a0,d0.l)
  33.         openlib    Dos,ShutDown_Out
  34.  
  35.         lib    Dos,Input
  36.         move.l    d0,_stdin
  37.  
  38.         cmp.b    #"?",(a4)
  39.         beq    CmdLineHelp
  40.         cmp.w    #'-?',(a4)
  41.         beq    CmdLineHelp
  42.         cmp.w    #'-h',(a4)
  43.         beq    CmdLineHelp
  44.         cmp.b    #'h',(a4)
  45.  
  46.         bsr    GetPW
  47.         cmp.l    #-1,d0
  48.         beq    ShutDown
  49.  
  50. Cont1:        bsr    Lock
  51.  
  52.         lea.l    PasswordText1,a0
  53.         bsr    Printer
  54.         lea.l    Buffer1,a0
  55.         move.l    #10,d0
  56.         bsr    GetString2
  57.         cmp.l    #-1,d0
  58.         bne    Cont2
  59.         bra    Cont1
  60.  
  61. Cont2:        lea.l    Buffer1,a1
  62.         lea.l    Buffer2,a0
  63.         bsr    CmpStrings
  64.         tst.l    d0
  65.         bne    Cont3
  66.         lea.l    MismatchText2,a0
  67.         bsr    Printer
  68.         bra    Cont1
  69.  
  70. Cont3:        lea.l    LockedText2,a0
  71.         bsr    Printer
  72.  
  73.         bra    ShutDown
  74.  
  75. Lock:        move.l    _stdin,d1
  76.         move.l    #TRUE,d2
  77.         lib    Dos,SetMode
  78.  
  79.         lea.l    LockedText1,a0
  80.         bsr    Printer
  81.  
  82.         move.l    _stdin,d1
  83.         lib    Dos,FGetC
  84.  
  85.         move.l    _stdin,d1
  86.         move.l    #FALSE,d2
  87.         lib    Dos,SetMode
  88.         rts
  89.  
  90. ShutDown:
  91. ShutDown1000:    closlib    Dos
  92.  
  93. ShutDown_Out:    move.l    #RETURN_OK,d0
  94.         rts
  95.  
  96. CmdLineHelp:    lea.l    AuthorText1,a0
  97.         bsr    Printer
  98.         bra    ShutDown
  99.  
  100. Printer:    printa    a0
  101.         rts
  102.  
  103. ;Gets password from user
  104. ;
  105. ;Result    d0 = -1 if failed (break etc)
  106. ;
  107.  
  108. GetPW:        lea.l    PasswordText1,a0
  109.         bsr    Printer
  110.  
  111.         lea.l    Buffer1,a0
  112.         move.l    #10,d0
  113.         bsr    GetString2
  114.         cmp.l    #-1,d0
  115.         bne    GetPW2
  116.         lea.l    BreakText1,a0
  117.         bsr    Printer
  118.         bra    GetPW_OUT1
  119.  
  120. GetPW2:        cmp.l    #4,d0
  121.         bhi    GetPW2.1
  122.         lea.l    ShortText1,a0
  123.         bsr    Printer
  124.         bra    GetPW
  125.  
  126. GetPW2.1:    lea.l    PasswordText2,a0
  127.         bsr    Printer
  128.  
  129.         lea.l    Buffer2,a0
  130.         move.l    #10,d0
  131.         bsr    GetString2
  132.         cmp.l    #-1,d0
  133.         bne    GetPW3
  134.         lea.l    BreakText1,a0
  135.         bsr    Printer
  136.         bra    GetPW_OUT1
  137.  
  138. GetPW3:        lea.l    Buffer2,a0
  139.         lea.l    Buffer1,a1
  140.         bsr    CmpStrings
  141.         tst.l    d0
  142.         bne    GetPW_OUT
  143.         lea.l    MismatchText1,a0
  144.         bsr    Printer
  145.         bra    GetPW
  146. GetPW_OUT:    clr.l    d0
  147.         rts
  148. GetPW_OUT1:    move.l    #-1,d0
  149.         rts
  150.  
  151. ;Gets a string one letter at a time from the CLI. Handles BS correctly
  152. ;
  153. ;Input a0 = Buffer
  154. ;      d0 = Max. length
  155. ;
  156. ;Result d0 = Length (without NULL)
  157. ;
  158.  
  159. GetString2:    move.l    d0,d3
  160.         move.l    a0,a2
  161.         move.l    _stdin,d1
  162.         move.l    #TRUE,d2
  163.         lib    Dos,SetMode
  164.         move.l    _stdin,d1
  165.         lib    Dos,Flush
  166.         clr.l    d4
  167. GetString2.1:    move.l    _stdin,d1
  168.         lib    Dos,FGetC
  169.         cmp.l    #-1,d0
  170.         beq    GetString2_OUT
  171.         cmp.l    #8,d0            ;BS
  172.         bne    GetString2.2
  173.         beq    DoBS
  174. GetString2.2:    cmp.l    #3,d0            ;CTRL_C
  175.         beq    GetString2_OUT
  176. GetString2.3:    cmp.l    #13,d0            ;CR
  177.         beq    GetString2.4
  178.         add.l    #1,d4
  179.         move.b    d0,(a2)+
  180.         cmp.l    d3,d4
  181.         bne    GetString2.1
  182.         lea.l    MaxText1,a0
  183.         bsr    Printer
  184. GetString2.4:    clr.b    (a2)+
  185.         move.l    _stdin,d1
  186.         move.l    #FALSE,d2
  187.         lib    Dos,SetMode
  188.         move.l    d4,d0
  189.         rts
  190. GetString2_OUT:    move.l    _stdin,d1
  191.         move.l    #FALSE,d2
  192.         lib    Dos,SetMode
  193.         move.l    #-1,d0
  194.         rts
  195.  
  196. DoBS:        tst.l    d4
  197.         beq    DoBS_OUT
  198.         sub.l    #1,d4
  199.         sub.l    #1,a2
  200. DoBS_OUT:    bra    GetString2.1
  201.  
  202. ;Compares two strings.
  203. ;
  204. ;INPUT
  205. ;
  206. ;A0 String 1 (original password f.ex(?))
  207. ;A1 String 2
  208. ;
  209. ;OUTPUT
  210. ;
  211. ;D0 = 0 if not same
  212. ;    -1 if same
  213. ;
  214. ;BUGS
  215. ;
  216.  
  217. CmpStrings:    bsr    GetLength
  218.         move.l    d3,d4        ;length of string1 to d4
  219.         push    a0
  220.         move.l    a1,a0
  221.         bsr    GetLength
  222.         pull    a0
  223.         cmp.l    d4,d3        ;length of string2 in d3
  224.         bne    CmpStrings1.1
  225. CmpStrings1:    tst.b    (a0)
  226.         beq    CmpStrings2
  227.         cmp.b    (a0)+,(a1)+
  228.         beq    CmpStrings1
  229. CmpStrings1.1:    clr.l    d0
  230.         rts
  231. CmpStrings2:    move.l    #-1,d0
  232.         rts
  233.  
  234. ;Get length of text in given address
  235. ;
  236. ;Input a0 = Address of null terminated text string
  237. ;
  238. ;Result d3 = Length
  239.  
  240. GetLength:    push    a0
  241.         clr.l    d3
  242.         cmp.l    #$00,a0        ;fixes enforcer hit
  243.         beq    GetLength_OUT
  244. GetLength2:    add.l    #1,d3
  245.         tst.b    (a0)+
  246.         bne    GetLength2
  247.         sub.l    #1,d3        ;don't include NULL
  248. GetLength_OUT:    pull    a0
  249.         rts
  250.  
  251. ;Checks for CTRL_C
  252. ;
  253. ;Result d0 = -1 if CTRL_C was pressed
  254. ;
  255.  
  256. CheckBreak:    clr.l    d1
  257.         bset.l    #SIGBREAKB_CTRL_C,d1    ;check for CTRL_C
  258.         lib    Dos,CheckSignal
  259.         btst.l    #SIGBREAKB_CTRL_C,d0
  260.         bne    CheckBreak1
  261.         clr.l    d0
  262.         rts
  263. CheckBreak1:    lea.l    BreakText1,a0
  264.         bsr    Printer
  265.         move.l    #-1,d0
  266.         rts
  267.  
  268. ;Structures and reservations
  269.  
  270. ;Files
  271.  
  272. _stdin:        dc.l    0
  273.  
  274. ;Texts to output
  275.  
  276.         dc.b    "$VER: "
  277. AuthorText1:    dc.b    "Lock 1.01 (1.1.93) (C)opyright Tomi Blinnikka 1993",13,10,13,10
  278.  
  279. UsageText1:    dc.b    "USAGE: Lock",13,10,13,10
  280.         dc.b    "Lock your TTY temporarily.",13,10
  281.         dc.b    "See docs for more information.",13,10,0
  282.  
  283. BreakText1:    dc.b    "***Break",13,10,0
  284. CRLFText1:    dc.b    13,10,0
  285. PasswordText1:    dc.b    "Enter password: ",0
  286. PasswordText2:    dc.b    13,10,"Re-enter password: ",0
  287. MismatchText1:    dc.b    13,10,"Password mismatch! Please retry.",13,10,0
  288. MismatchText2:    dc.b    13,10,"Incorrect password.",13,10,0
  289. ShortText1:    dc.b    13,10,"Please enter a longer password. Minimum of 5 characters required.",13,10,0
  290. MaxText1:    dc.b    13,10,"Maximum length reached (10 characters)!",13,10,0
  291. LockedText1:    dc.b    13,10,"Your TTY is now locked.",13,10,13,10,0
  292. LockedText2:    dc.b    13,10,"Your TTY is now unlocked",13,10,13,10,0
  293.         ds.l    0
  294.  
  295. ;library stuff
  296.  
  297.         libnames
  298.  
  299. ;buffers
  300.  
  301. Buffer1:    dcb.b    12,0        ;Temporary buffer for password
  302. Buffer2:    dcb.b    12,0        ;Temporary buffer for password
  303.  
  304.         END
  305.