home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / asm / tbsource / logger / passwd.s < prev    next >
Text File  |  1993-12-21  |  22KB  |  1,245 lines

  1. *************************************************
  2. *                        *
  3. *        (C)opyright 1992-93        *
  4. *                        *
  5. *         by Tomi Blinnikka        *
  6. *                        *
  7. *    Don´t try to understand the code    *
  8. *                        *
  9. * Version 1.00    01/08/1992            *
  10. *                        *
  11. * BUGS:    Didn't check for UNUSED            *
  12. *                        *
  13. * Version 1.01    08/08/1992            *
  14. *                        *
  15. * Added -l option                *
  16. *                        *
  17. * BUGS:    RemUser    jumped to AddUser_OUT        *
  18. *                        *
  19. * Version 1.02    10/08/1992            *
  20. *                        *
  21. * Added -e option                *
  22. *                        *
  23. * Version 1.03    14/08/1992            *
  24. *                        *
  25. * Added command to start            *
  26. *                        *
  27. * Version 1.04    03/02/1993            *
  28. *                        *
  29. * Changed parser to CBM ReadArgs        *
  30. *                        *
  31. *************************************************
  32.  
  33.     INCLUDE    "JMPLibs.i"
  34.     INCLUDE    "exec/types.i"
  35.     INCLUDE    "libraries/dos.i"
  36.  
  37.     INCLUDE    "XREF:2.0.xref"
  38.     INCLUDE    "XREF:exec.xref"
  39.     INCLUDE    "XREF:dos.xref"
  40.  
  41.  
  42.     XREF    _LVOSetMode
  43.  
  44.     BITDEF  GV,LOCAL_ONLY,9
  45.  
  46. TRUE:        EQU    1
  47. FALSE:        EQU    0
  48.  
  49.         section    PassWd,CODE
  50.  
  51.         openlib    Dos,NoDos
  52.  
  53.         lib    Dos,Input
  54.         move.l    d0,_stdin
  55.  
  56.         lea.l    CLTemplate1,a0
  57.         move.l    a0,d1
  58.         lea.l    CLArray1,a0
  59.         move.l    a0,d2
  60.         clr.l    d3
  61.         lib    Dos,ReadArgs
  62.         move.l    d0,RDArgs1
  63.         beq    NoRDArgs
  64.  
  65.         move.l    UserPointer,a4
  66.         tst.b    (a4)
  67.         bne    CopyLoop
  68.  
  69.         lea.l    UserVarText1,a0
  70.         move.l    a0,d1
  71.         lea.l    Buffer3,a0
  72.         move.l    a0,d2
  73.         move.l    #10,d3
  74.         clr.l    d4            ;LV_VAR actually
  75.         or.l    #GVF_LOCAL_ONLY,d4
  76.         lib    Dos,GetVar
  77.         cmp.l    #-1,d0
  78.         beq    ArgMissing
  79.         bra    CopyLoop_OUT
  80.  
  81. CopyLoop:    lea.l    Buffer3,a0
  82.         move.l    a4,a5
  83.         add.l    #10,a5
  84. CopyLoop1:    move.b    (a4)+,(a0)+
  85.         tst.b    (a4)
  86.         beq    CopyLoop_OUT
  87.         cmp.l    a4,a5
  88.         beq    CopyLoop_OUT
  89.         cmp.b    #' ',(a4)
  90.         bne    CopyLoop1
  91. CopyLoop_OUT:
  92.  
  93.         lea.l    PassWdFileN,a0
  94.         move.l    a0,d1
  95.         move.l    #MODE_OLDFILE,d2
  96.         lib    Dos,Open
  97.         move.l    d0,PassWdFile
  98.         bne    DoCommands
  99.  
  100.         lib    Dos,IoErr
  101.         cmp.l    #ERROR_OBJECT_NOT_FOUND,d0
  102.         beq    CreatePWFile
  103.         bsr    FileError1
  104.         bra    ShutDown
  105.  
  106. CreatePWFile:    lea.l    CreatingText1,a0
  107.         bsr    Printer
  108.  
  109.         lea.l    PassWdFileN,a0
  110.         move.l    a0,d1
  111.         move.l    #MODE_NEWFILE,d2
  112.         lib    Dos,Open
  113.         move.l    d0,PassWdFile
  114.         bne    CreatePWFile2
  115.         bsr    FileError4
  116.         bra    ShutDown
  117. CreatePWFile2:    move.l    #'root',Buffer1
  118.         lea.l    Buffer1,a0
  119.         lea.l    PassWord,a1
  120.         bsr    Encrypt
  121.  
  122.         bsr    WriteUser
  123.         bsr    SeekStart
  124.  
  125. DoCommands:    tst.l    OptionAdd
  126.         beq    DoCommands1
  127.         bsr    AddUser
  128. DoCommands1:    tst.l    OptionRemove
  129.         beq    DoCommands2
  130.         bsr    RemUser
  131. DoCommands2:    tst.l    OptionList
  132.         beq    DoCommands3
  133.         bsr    ListUsers
  134. DoCommands3:    tst.l    OptionEdit
  135.         beq    DoCommands4
  136.         bsr    EditUser
  137. DoCommands4:    tst.w    SomethingDone
  138.         bne    DoCommands5
  139.         bsr    ChangePW
  140. DoCommands5:    bra    ShutDown
  141.  
  142. ChangePW:    bsr    FindUser
  143.         tst.l    d0
  144.         bne    ChangePW_OUT
  145.  
  146.         lea.l    UNUSEDText1,a0
  147.         lea.l    UserName,a1
  148.         bsr    CmpStrings
  149.         tst.l    d0
  150.         beq    ChangePW0.1
  151.         lea.l    InvalidText1,a0    
  152.         bsr    Printer
  153.         bra    ChangePW_OUT
  154.  
  155. ChangePW0.1:    lea.l    PasswordText3,a0
  156.         bsr    Printer
  157.         lea.l    Buffer1,a0
  158.         move.l    #10,d0
  159.         bsr    GetString2
  160.         cmp.l    #-1,d0
  161.         bne    ChangePW1
  162.         lea.l    BreakText1,a0
  163.         bsr    Printer
  164.         bra    ChangePW_OUT
  165. ChangePW1:    lea.l    PassWord,a0
  166.         lea.l    Buffer2,a1
  167.         bsr    Decrypt
  168.  
  169.         lea.l    Buffer1,a1
  170.         lea.l    Buffer2,a0
  171.         bsr    CmpStrings
  172.         tst.l    d0
  173.         bne    ChangePW2
  174.         lea.l    MismatchText2,a0
  175.         bsr    Printer
  176.         bra    ChangePW_OUT
  177. ChangePW2:    lea.l    CRLFText1,a0
  178.         bsr    Printer
  179.         bsr    GetPW
  180.         tst.l    d0
  181.         bne    ChangePW_OUT
  182.  
  183. ChangePW6:    lea.l    CRLFText1,a0
  184.         bsr    Printer
  185.  
  186.         lea.l    Buffer1,a0
  187.         lea.l    PassWord,a1
  188.         bsr    Encrypt
  189.  
  190.         bsr    SeekBack
  191.         bsr    WriteUser
  192.  
  193. ChangePW_OUT:    rts
  194.  
  195. AddUser:    move.w    #1,SomethingDone
  196.         bsr    CheckClone
  197.         tst.l    d0
  198.         bne    AddUser0.01
  199.         lea.l    DoubleNameText1,a0
  200.         bsr    Printer
  201.         bra    AddUser_OUT
  202.  
  203. AddUser0.01:    bsr    CheckRoot
  204.         tst.l    d0
  205.         bne    AddUser_OUT
  206.  
  207.         bsr    FindFree
  208.  
  209.         bsr    ClearUser
  210.         bsr    CopyUN1
  211.  
  212. AddUser0.1:    bsr    GetRealN
  213.         tst.l    d0
  214.         bne    AddUser_OUT
  215.  
  216. AddUser1.1:    lea.l    PasswordText1,a0
  217.         bsr    Printer
  218.  
  219.         lea.l    Buffer1,a0
  220.         move.l    #10,d0
  221.         bsr    GetString2
  222.         cmp.l    #-1,d0
  223.         bne    AddUser2
  224.         lea.l    BreakText1,a0
  225.         bsr    Printer
  226.         bra    AddUser_OUT
  227.  
  228. AddUser2:    cmp.l    #4,d0
  229.         bhi    AddUser2.1
  230.         lea.l    ShortText1,a0
  231.         bsr    Printer
  232.         bra    AddUser1.1
  233.  
  234. AddUser2.1:    lea.l    PasswordText2,a0
  235.         bsr    Printer
  236.  
  237.         lea.l    Buffer2,a0
  238.         move.l    #10,d0
  239.         bsr    GetString2
  240.         cmp.l    #-1,d0
  241.         bne    AddUser3
  242.         lea.l    BreakText1,a0
  243.         bsr    Printer
  244.         bra    AddUser_OUT
  245.  
  246. AddUser3:    lea.l    Buffer2,a0
  247.         lea.l    Buffer1,a1
  248.         bsr    CmpStrings
  249.         tst.l    d0
  250.         bne    AddUser4
  251.         lea.l    MismatchText1,a0
  252.         bsr    Printer
  253.         bra    AddUser1.1
  254.  
  255. AddUser4:    bsr    GetHome
  256.         tst.l    d0
  257.         bne    AddUser_OUT
  258.  
  259. AddUser5:    bsr    GetOffice
  260.         tst.l    d0
  261.         bne    AddUser_OUT
  262.  
  263. AddUser6:    bsr    GetCommand
  264.         tst.l    d0
  265.         bne    AddUser_OUT
  266.  
  267. AddUser7:    bsr    GiveUserInfo
  268.  
  269.         lea.l    AddUserText1,a0
  270.         bsr    Printer
  271.         bsr    GetAnswer
  272.         tst.l    d0
  273.         bne    AddUser_OUT
  274.  
  275.         lea.l    Buffer1,a0
  276.         lea.l    PassWord,a1
  277.         bsr    Encrypt
  278.  
  279.         bsr    WriteUser
  280. AddUser_OUT:    rts
  281.  
  282. RemUser:    move.w    #1,SomethingDone
  283.         bsr    CheckRoot
  284.         tst.l    d0
  285.         bne    RemUser_OUT
  286.         bsr    FindUser
  287.         tst.l    d0
  288.         bne    RemUser_OUT
  289.  
  290.         cmp.l    #'root',UserName
  291.         bne    RemUser1
  292.         lea.l    RemUserText2,a0
  293.         bsr    Printer
  294.         bra    RemUser_OUT
  295.  
  296. RemUser1:    bsr    GiveUserInfo
  297.  
  298.         lea.l    RemUserText1,a0
  299.         bsr    Printer
  300.  
  301.         bsr    GetAnswer
  302.         tst.l    d0
  303.         bne    RemUser_OUT
  304.  
  305.         bsr    SeekBack
  306.         bsr    ClearUser
  307.         move.l    #'UNUS',UserName
  308.         move.w    #'ED',UserName+4
  309.         bsr    WriteUser
  310.  
  311. RemUser_OUT:    rts
  312.  
  313. ListUsers:    move.w    #1,SomethingDone
  314.         lea.l    AllUsersText1,a0
  315.         bsr    Printer
  316.  
  317. ListUsers1:    clr.w    Quiet
  318.         bsr    ReadUser
  319.         tst.l    d0
  320.         bne    ListUsers_OUT
  321.  
  322.         move.w    #1,Quiet
  323.         lea.l    UNUSEDText1,a0
  324.         lea.l    UserName,a1
  325.         bsr    CmpStrings
  326.         tst.l    d0
  327.         bne    ListUsers1
  328.  
  329.         bsr    GiveUserInfo
  330.  
  331.         bsr    CheckBreak
  332.         tst.l    d0
  333.         beq    ListUsers1
  334.  
  335. ListUsers_OUT:    move.w    #1,Quiet
  336.         rts
  337.  
  338. EditUser:    move.w    #1,SomethingDone
  339.         bsr    CheckRoot
  340.         tst.l    d0
  341.         bne    EditUser_OUT
  342.         bsr    FindUser
  343.         tst.l    d0
  344.         bne    EditUser_OUT
  345.  
  346. EditUser0.1:    bsr    GiveUserInfo
  347.         bsr    GetOption
  348.         cmp.l    #-1,d0
  349.         beq    EditUser_OUT
  350.         tst.l    d0
  351.         beq    EditUser1
  352.         cmp.l    #1,d0
  353.         beq    EditUser2
  354.         cmp.l    #2,d0
  355.         beq    EditUser3
  356.         cmp.l    #3,d0
  357.         beq    EditUser4
  358.         cmp.l    #4,d0
  359.         beq    EditUser5
  360.         cmp.l    #5,d0
  361.         beq    EditUser6
  362.         cmp.l    #6,d0
  363.         beq    EditUser7
  364. EditUser_OUT    rts
  365. EditUser1:    bsr    GetUserN
  366.         tst.l    d0
  367.         bne    EditUser_OUT
  368.         bra    EditUser0.1
  369. EditUser2:    bsr    GetPW
  370.         tst.l    d0
  371.         bne    EditUser_OUT
  372.         lea.l    Buffer1,a0
  373.         lea.l    PassWord,a1
  374.         bsr    Encrypt
  375.         bra    EditUser0.1
  376. EditUser3:    bsr    GetRealN
  377.         tst.l    d0
  378.         bne    EditUser_OUT
  379.         bra    EditUser0.1
  380. EditUser4:    bsr    GetHome
  381.         tst.l    d0
  382.         bne    EditUser_OUT
  383.         bra    EditUser0.1
  384. EditUser5:    bsr    GetOffice
  385.         tst.l    d0
  386.         bne    EditUser_OUT
  387.         bra    EditUser0.1
  388. EditUser6:    bsr    SeekBack
  389.         bsr    WriteUser
  390.         bra    EditUser_OUT
  391. EditUser7:    bsr    GetCommand
  392.         tst.l    d0
  393.         bne    EditUser_OUT
  394.         bra    EditUser0.1
  395.  
  396. ShutDown:    move.l    PassWdFile,d1
  397.         beq    ShutDown9000
  398.         lib    Dos,Close
  399.  
  400. ShutDown9000:    move.l    RDArgs1,d1
  401.         beq    ShutDown8000
  402.         lib    Dos,FreeArgs
  403.  
  404. ShutDown8000:
  405. ShutDown1000:    closlib    Dos
  406.  
  407.         move.l    #RETURN_OK,d0
  408.         rts
  409.  
  410. ArgMissing:    move.l    #ERROR_REQUIRED_ARG_MISSING,d1
  411.         lib    Dos,SetIoErr
  412.         bra    NoRDArgs
  413.  
  414. NoRDArgs:    lib    Dos,IoErr
  415.         move.l    d0,d1
  416.         clr.l    d2
  417.         lib    Dos,PrintFault
  418.         bra    ShutDown
  419.  
  420. NoDos:        move.l    #RETURN_FAIL,d0
  421.         rts
  422.  
  423. FileError1:    lea.l    FileErrorText1,a0
  424.         bsr    Printer
  425.         rts
  426.  
  427. FileError2:    lea.l    FileErrorText2,a0
  428.         bsr    Printer
  429.         rts
  430.  
  431. FileError3:    lea.l    FileErrorText3,a0
  432.         bsr    Printer
  433.         bra    ShutDown
  434.  
  435. FileError4:    lea.l    FileErrorText4,a0
  436.         bsr    Printer
  437.         bra    ShutDown
  438.  
  439. Printer:    tst.w    Quiet
  440.         beq    Printer1
  441.         printa    a0
  442. Printer1:    rts
  443.  
  444. CheckRoot:    bsr    SeekStart
  445.         bsr    ReadUser
  446.         tst.l    d0
  447.         bne    CheckRoot_OUT
  448.         lea.l    PasswordText1,a0
  449.         bsr    Printer
  450.         lea.l    Buffer1,a0
  451.         move.l    #10,d0
  452.         bsr    GetString2
  453.         cmp.l    #-1,d0
  454.         bne    CheckRoot1
  455.         lea.l    BreakText1,a0
  456.         bsr    Printer
  457.         bra    CheckRoot_OUT
  458. CheckRoot1:    lea.l    CRLFText1,a0
  459.         bsr    Printer
  460.         lea.l    PassWord,a0
  461.         lea.l    Buffer2,a1
  462.         bsr    Decrypt
  463.  
  464.         bsr    SeekStart
  465.  
  466.         lea.l    Buffer2,a0
  467.         lea.l    Buffer1,a1
  468.         bsr    CmpStrings
  469.         tst.l    d0
  470.         bne    CheckRoot2
  471.         lea.l    MismatchText2,a0
  472.         bsr    Printer
  473. CheckRoot_OUT:    move.l    #-1,d0
  474.         rts
  475. CheckRoot2:    clr.l    d0
  476.         rts
  477.  
  478. ;Seek to end of PassWdFile
  479. ;
  480. ;Results d0 = length
  481. ;
  482.  
  483. SeekEnd:    push    d2-d3
  484.         move.l    PassWdFile,d1
  485.         move.l    d1,d6
  486.         move.l    #00,d2
  487.         move.l    #01,d3
  488.         lib    Dos,Seek
  489.         move.l    d6,d1
  490.         lib    Dos,Seek
  491.         pull    d2-d3
  492.         rts
  493.  
  494. SeekStart:    push    d2-d3
  495.         move.l    PassWdFile,d1
  496.         move.l    #0,d2
  497.         move.l    #-1,d3
  498.         lib    Dos,Seek
  499.         pull    d2-d3
  500.         rts
  501.  
  502. SeekBack:    push    d2-d3
  503.         move.l    PassWdFile,d1
  504.         move.l    #-DataSize,d2
  505.         move.l    #0,d3
  506.         lib    Dos,Seek
  507.         pull    d2-d3
  508.         rts
  509.  
  510. CopyUN1:    move.l    Buffer3,UserName
  511.         move.l    Buffer3+4,UserName+4
  512.         move.l    Buffer3+8,UserName+8
  513.         rts
  514.  
  515. ClearUser:    clr.l    UserName
  516.         clr.l    UserName+4
  517.         clr.l    UserName+8
  518.         clr.l    PassWord
  519.         clr.l    PassWord+4
  520.         clr.l    PassWord+8
  521.         clr.l    RealName
  522.         clr.l    RealName+4
  523.         clr.l    RealName+8
  524.         clr.l    RealName+12
  525.         clr.l    RealName+16
  526.         clr.l    RealName+20
  527.         clr.l    RealName+24
  528.         clr.l    RealName+28
  529.         clr.l    UserHome
  530.         clr.l    Office
  531.         clr.l    UserCommand
  532.         rts
  533.  
  534. ;Inputs Buffer3 = user to find
  535.  
  536. FindUser:    bsr    ReadUser
  537.         tst.l    d0
  538.         bne    FindUser_ERR1
  539.         lea.l    UserName,a0
  540.         lea.l    Buffer3,a1
  541.         bsr    CmpStrings
  542.         tst.l    d0
  543.         beq    FindUser
  544.         clr.l    d0
  545.         rts
  546. FindUser_ERR1:    move.l    #-1,d0
  547.         rts
  548.  
  549. FindFree:    clr.w    Quiet
  550.         bsr    ReadUser
  551.         tst.l    d0
  552.         bne    FindFree_ERR1
  553.         lea.l    UNUSEDText1,a0
  554.         lea.l    UserName,a1
  555.         bsr    CmpStrings
  556.         tst.l    d0
  557.         beq    FindFree
  558.         bsr    SeekBack
  559. FindFree_ERR1:    move.w    #1,Quiet
  560.         rts
  561.  
  562. CheckClone:    clr.w    Quiet
  563.         bsr    ReadUser
  564.         tst.l    d0
  565.         bne    CheckClone_ERR1
  566.         lea.l    Buffer3,a0
  567.         lea.l    UserName,a1
  568.         bsr    CmpStrings
  569.         tst.l    d0
  570.         beq    CheckClone
  571.         move.w    #1,Quiet
  572.         clr.l    d0
  573.         rts
  574. CheckClone_ERR1: move.w    #1,Quiet
  575.         move.l    #-1,d0
  576.         rts
  577.  
  578. WriteUser:    move.l    PassWdFile,d1
  579.         lea.l    UserName,a0
  580.         move.l    a0,d2
  581.         move.l    #DataSize,d3
  582.         lib    Dos,Write
  583.         cmp.l    #DataSize,d0
  584.         beq    WriteUser1
  585.         bsr    FileError3
  586.         move.l    #-1,d0
  587.         rts
  588. WriteUser1:    clr.l    d0
  589.         rts
  590.  
  591. ReadUser:    move.l    PassWdFile,d1
  592.         lea.l    UserName,a0
  593.         move.l    a0,d2
  594.         move.l    #DataSize,d3
  595.         lib    Dos,Read
  596.         cmp.l    #DataSize,d0
  597.         beq    ReadUser2
  598.         lib    Dos,IoErr
  599.         tst.l    d0
  600.         beq    ReadUser1
  601.         bsr    FileError2
  602.         move.l    #-1,d0
  603.         rts
  604. ReadUser1:    lea.l    NoUserText1,a0
  605.         bsr    Printer
  606.         move.l    #-1,d0
  607.         rts
  608. ReadUser2:    clr.l    d0
  609.         rts
  610.  
  611.  
  612. GiveUserInfo:    lea.l    UserNText1,a0
  613.         bsr    Printer
  614.         lea.l    UserName,a0
  615.         bsr    Printer
  616.         lea.l    RealNText1,a0
  617.         bsr    Printer
  618.         lea.l    RealName,a0
  619.         bsr    Printer
  620.         lea.l    UserHomeText2,a0
  621.         bsr    Printer
  622.         lea.l    UserHome,a0
  623.         bsr    Printer
  624.         lea.l    OfficeText2,a0
  625.         bsr    Printer
  626.         lea.l    Office,a0
  627.         bsr    Printer
  628.         lea.l    CommandText2,a0
  629.         bsr    Printer
  630.         lea.l    UserCommand,a0
  631.         bsr    Printer
  632.         lea.l    CRLFText1,a0
  633.         bsr    Printer
  634.         rts
  635.  
  636. ;Asks for username (login name)
  637.  
  638. GetUserN:    lea.l    GiveNameText2,a0
  639.         bsr    Printer
  640.         lea.l    UserName,a0
  641.         move.l    #64,d0
  642.         bsr    GetString
  643.         tst.l    d0
  644.         beq    GetUserN_OUT1
  645.  
  646.         bsr    CheckBreak
  647.         tst.l    d0
  648.         bne    GetUserN_OUT1
  649.  
  650.         cmp.b    #10,UserName
  651.         beq    GetUserN
  652.  
  653.         lea.l    UserName,a0
  654.         move.l    #64,d0
  655.         bsr    RemoveLF
  656. GetUserN_OUT:    clr.l    d0
  657.         rts
  658. GetUserN_OUT1:    move.l    #-1,d0
  659.         rts
  660.  
  661. ;Gets password from user
  662. ;
  663. ;Result    d0 = -1 if failed (break etc)
  664. ;
  665.  
  666. GetPW:        lea.l    PasswordText1,a0
  667.         bsr    Printer
  668.  
  669.         lea.l    Buffer1,a0
  670.         move.l    #10,d0
  671.         bsr    GetString2
  672.         cmp.l    #-1,d0
  673.         bne    GetPW2
  674.         lea.l    BreakText1,a0
  675.         bsr    Printer
  676.         bra    GetPW_OUT1
  677.  
  678. GetPW2:        cmp.l    #4,d0
  679.         bhi    GetPW2.1
  680.         lea.l    ShortText1,a0
  681.         bsr    Printer
  682.         bra    GetPW
  683.  
  684. GetPW2.1:    lea.l    PasswordText2,a0
  685.         bsr    Printer
  686.  
  687.         lea.l    Buffer2,a0
  688.         move.l    #10,d0
  689.         bsr    GetString2
  690.         cmp.l    #-1,d0
  691.         bne    GetPW3
  692.         lea.l    BreakText1,a0
  693.         bsr    Printer
  694.         bra    GetPW_OUT1
  695.  
  696. GetPW3:        lea.l    Buffer2,a0
  697.         lea.l    Buffer1,a1
  698.         bsr    CmpStrings
  699.         tst.l    d0
  700.         bne    GetPW_OUT
  701.         lea.l    MismatchText1,a0
  702.         bsr    Printer
  703.         bra    GetPW
  704. GetPW_OUT:    clr.l    d0
  705.         rts
  706. GetPW_OUT1:    move.l    #-1,d0
  707.         rts
  708.  
  709. ;Asks for realname for user
  710.  
  711. GetRealN:    lea.l    GiveNameText1,a0
  712.         bsr    Printer
  713.         lea.l    RealName,a0
  714.         move.l    #64,d0
  715.         bsr    GetString
  716.         tst.l    d0
  717.         beq    GetRealN_OUT1
  718.  
  719.         bsr    CheckBreak
  720.         tst.l    d0
  721.         bne    GetRealN_OUT1
  722.  
  723.         cmp.b    #10,RealName
  724.         beq    GetRealN
  725.  
  726.         lea.l    RealName,a0
  727.         move.l    #64,d0
  728.         bsr    RemoveLF
  729. GetRealN_OUT:    clr.l    d0
  730.         rts
  731. GetRealN_OUT1:    move.l    #-1,d0
  732.         rts
  733.  
  734. ;Ask for home directory
  735.  
  736. GetHome:    lea.l    UserHomeText1,a0
  737.         bsr    Printer
  738.         lea.l    UserHome,a0
  739.         move.l    #64,d0
  740.         bsr    GetString
  741.         tst.l    d0
  742.         beq    GetHome_OUT1
  743.  
  744.         bsr    CheckBreak
  745.         tst.l    d0
  746.         bne    GetHome_OUT1
  747.  
  748.         cmp.b    #10,UserHome
  749.         beq    GetHome
  750.  
  751. GetHome2:    lea.l    UserHome,a0
  752.         move.l    #64,d0
  753.         bsr    RemoveLF
  754. GetHome_OUT:    clr.l    d0
  755.         rts
  756. GetHome_OUT1:    move.l    #-1,d0
  757.         rts
  758.  
  759. ;Asks for office for user
  760.  
  761. GetOffice:    lea.l    OfficeText1,a0
  762.         bsr    Printer
  763.         lea.l    Office,a0
  764.         move.l    #64,d0
  765.         bsr    GetString
  766.         tst.l    d0
  767.         beq    GetOffice_OUT1
  768.  
  769.         bsr    CheckBreak
  770.         tst.l    d0
  771.         bne    GetOffice_OUT1
  772.  
  773.         cmp.b    #10,Office
  774.         beq    GetOffice
  775.  
  776. GetOffice1:    lea.l    Office,a0
  777.         move.l    #64,d0
  778.         bsr    RemoveLF
  779. GetOffice_OUT:    clr.l    d0
  780.         rts
  781. GetOffice_OUT1:    move.l    #-1,d0
  782.         rts
  783.  
  784. ;Asks for command for user
  785.  
  786. GetCommand:    lea.l    CommandText1,a0
  787.         bsr    Printer
  788.         lea.l    UserCommand,a0
  789.         move.l    #64,d0
  790.         bsr    GetString
  791.         tst.l    d0
  792.         beq    GetCommand_OUT1
  793.  
  794.         bsr    CheckBreak
  795.         tst.l    d0
  796.         bne    GetCommand_OUT1
  797.  
  798.         cmp.b    #10,UserCommand
  799.         beq    GetCommand
  800.  
  801. GetCommand1:    lea.l    UserCommand,a0
  802.         move.l    #64,d0
  803.         bsr    RemoveLF
  804. GetCommand_OUT:    clr.l    d0
  805.         rts
  806. GetCommand_OUT1: move.l    #-1,d0
  807.         rts
  808.  
  809. ;Get yes or no answer from CLI
  810.  
  811. GetAnswer:    move.l    _stdin,d1
  812.         move.l    #TRUE,d2
  813.         lib    Dos,SetMode
  814.  
  815.         lea.l    AskText1,a0
  816.         bsr    Printer
  817.         move.l    _stdin,d1
  818.         lib    Dos,Flush
  819.         move.l    _stdin,d1
  820.         lib    Dos,FGetC
  821.         cmp.l    #-1,d0
  822.         beq    GetAnswer_Neg
  823.         cmp.l    #'n',d0
  824.         beq    GetAnswer_Neg
  825.         cmp.l    #'N',d0
  826.         beq    GetAnswer_Neg
  827.         cmp.l    #'y',d0
  828.         beq    GetAnswer_Pos
  829.         cmp.l    #'Y',d0
  830.         beq    GetAnswer_Pos
  831. GetAnswer_Neg:    lea.l    NoText1,a0
  832.         bsr    Printer
  833.         move.l    _stdin,d1
  834.         move.l    #FALSE,d2
  835.         lib    Dos,SetMode
  836.         move.l    #-1,d0
  837.         rts
  838. GetAnswer_Pos:    lea.l    YesText1,a0
  839.         bsr    Printer
  840.         move.l    _stdin,d1
  841.         move.l    #FALSE,d2
  842.         lib    Dos,SetMode
  843.         clr.l    d0
  844.         rts
  845.  
  846. ;Get option from user
  847. ;
  848. ;Result    d0 = Option (0=username, 1=password, 2=realname, 3=home, 4=office,
  849. ;             5=write,6=command)
  850.  
  851. GetOption:    move.l    _stdin,d1
  852.         move.l    #TRUE,d2
  853.         lib    Dos,SetMode
  854.  
  855.         lea.l    EditUserText1,a0
  856.         bsr    Printer
  857.  
  858.         move.l    _stdin,d1
  859.         lib    Dos,Flush
  860. GetOption1:    move.l    _stdin,d1
  861.         lib    Dos,FGetC
  862.         cmp.l    #-1,d0
  863.         beq    GetOption_OUT
  864.         cmp.l    #'u',d0
  865.         beq    GetOption2
  866.         cmp.l    #'U',d0
  867.         beq    GetOption2
  868.         cmp.l    #'p',d0
  869.         beq    GetOption3
  870.         cmp.l    #'P',d0
  871.         beq    GetOption3
  872.         cmp.l    #'r',d0
  873.         beq    GetOption4
  874.         cmp.l    #'R',d0
  875.         beq    GetOption4
  876.         cmp.l    #'h',d0
  877.         beq    GetOption5
  878.         cmp.l    #'H',d0
  879.         beq    GetOption5
  880.         cmp.l    #'o',d0
  881.         beq    GetOption6
  882.         cmp.l    #'O',d0
  883.         beq    GetOption6
  884.         cmp.l    #'w',d0
  885.         beq    GetOption7
  886.         cmp.l    #'W',d0
  887.         beq    GetOption7
  888.         cmp.l    #'c',d0
  889.         beq    GetOption8
  890.         cmp.l    #'C',d0
  891.         beq    GetOption8
  892.         cmp.l    #13,d0
  893.         beq    GetOption_ERR
  894.         cmp.l    #10,d0
  895.         beq    GetOption_ERR
  896.         bra    GetOption1
  897. GetOption2:    lea.l    OptText1,a0
  898.         bsr    Printer
  899.         move.l    #0,d0
  900.         bra    GetOption_OUT
  901. GetOption3:    lea.l    OptText2,a0
  902.         bsr    Printer
  903.         move.l    #1,d0
  904.         bra    GetOption_OUT
  905. GetOption4:    lea.l    OptText3,a0
  906.         bsr    Printer
  907.         move.l    #2,d0
  908.         bra    GetOption_OUT
  909. GetOption5:    lea.l    OptText4,a0
  910.         bsr    Printer
  911.         move.l    #3,d0
  912.         bra    GetOption_OUT
  913. GetOption6:    lea.l    OptText5,a0
  914.         bsr    Printer
  915.         move.l    #4,d0
  916.         bra    GetOption_OUT
  917. GetOption7:    lea.l    OptText6,a0
  918.         bsr    Printer
  919.         move.l    #5,d0
  920.         bra    GetOption_OUT
  921. GetOption8:    lea.l    OptText7,a0
  922.         bsr    Printer
  923.         move.l    #6,d0
  924. ;        bra    GetOption_OUT
  925. GetOption_OUT:    push    d0
  926.         move.l    _stdin,d1
  927.         move.l    #FALSE,d2
  928.         lib    Dos,SetMode
  929.         pull    d0
  930.         rts
  931. GetOption_ERR:    lea.l    CRLFText1,a0
  932.         bsr    Printer
  933.         move.l    #-1,d0
  934.         bra    GetOption_OUT
  935.  
  936. ;Gets a string from the CLI
  937. ;
  938. ;Input a0 = Buffer
  939. ;      d0 = Length
  940. ;
  941.  
  942. GetString:    move.l    d0,d3
  943.         move.l    a0,d2
  944.         move.l    _stdin,d1
  945.         lib    Dos,Flush
  946.         move.l    _stdin,d1
  947. ;        move.l    a2,d2
  948.         lib    Dos,FGets
  949.         rts
  950.  
  951. ;Gets a string one letter at a time from the CLI. Handles BS correctly
  952. ;
  953. ;Input a0 = Buffer
  954. ;      d0 = Max. length
  955. ;
  956. ;Result d0 = Length (without NULL)
  957. ;
  958.  
  959. GetString2:    move.l    d0,d3
  960.         move.l    a0,a2
  961.         move.l    _stdin,d1
  962.         move.l    #TRUE,d2
  963.         lib    Dos,SetMode
  964.         move.l    _stdin,d1
  965.         lib    Dos,Flush
  966.         clr.l    d4
  967. GetString2.1:    move.l    _stdin,d1
  968.         lib    Dos,FGetC
  969.         cmp.l    #-1,d0
  970.         beq    GetString2_OUT
  971.         cmp.l    #8,d0            ;BS
  972.         bne    GetString2.2
  973.         beq    DoBS
  974. GetString2.2:    cmp.l    #3,d0            ;CTRL_C
  975.         beq    GetString2_OUT
  976. GetString2.3:    cmp.l    #13,d0            ;CR
  977.         beq    GetString2.4
  978.         add.l    #1,d4
  979.         move.b    d0,(a2)+
  980.         cmp.l    d3,d4
  981.         bne    GetString2.1
  982.         lea.l    MaxText1,a0
  983.         bsr    Printer
  984. GetString2.4:    clr.b    (a2)+
  985.         move.l    _stdin,d1
  986.         move.l    #FALSE,d2
  987.         lib    Dos,SetMode
  988.         move.l    d4,d0
  989.         rts
  990. GetString2_OUT:    move.l    _stdin,d1
  991.         move.l    #FALSE,d2
  992.         lib    Dos,SetMode
  993.         move.l    #-1,d0
  994.         rts
  995.  
  996. DoBS:        tst.l    d4
  997.         beq    DoBS_OUT
  998.         sub.l    #1,d4
  999.         sub.l    #1,a2
  1000. DoBS_OUT:    bra    GetString2.1
  1001.  
  1002. ;Compares two strings.
  1003. ;
  1004. ;INPUT
  1005. ;
  1006. ;A0 String 1 (original password f.ex(?))
  1007. ;A1 String 2
  1008. ;
  1009. ;OUTPUT
  1010. ;
  1011. ;D0 = 0 if not same
  1012. ;    -1 if same
  1013. ;
  1014. ;BUGS
  1015. ;
  1016. ;String 1 has to have NULL at end!
  1017. ;
  1018.  
  1019. CmpStrings:    bsr    GetLength
  1020.         move.l    d3,d4        ;length of string1 to d4
  1021.         push    a0
  1022.         move.l    a1,a0
  1023.         bsr    GetLength
  1024.         pull    a0
  1025.         cmp.l    d4,d3        ;length of string2 in d3
  1026.         bne    CmpStrings1.1
  1027. CmpStrings1:    tst.b    (a0)
  1028.         beq    CmpStrings2
  1029.         cmp.b    (a0)+,(a1)+
  1030.         beq    CmpStrings1
  1031. CmpStrings1.1:    clr.l    d0
  1032.         rts
  1033. CmpStrings2:    move.l    #-1,d0
  1034.         rts
  1035.  
  1036. ;Get length of text in given address
  1037. ;
  1038. ;Input a0 = Address of null terminated text string
  1039. ;
  1040. ;Result d3 = Length
  1041.  
  1042. GetLength:    push    a0
  1043.         clr.l    d3
  1044.         cmp.l    #$00,a0        ;fixes enforcer hit
  1045.         beq    GetLength_OUT
  1046. GetLength2:    add.l    #1,d3
  1047.         tst.b    (a0)+
  1048.         bne    GetLength2
  1049.         sub.l    #1,d3        ;don't include NULL
  1050. GetLength_OUT:    pull    a0
  1051.         rts
  1052.  
  1053. ;Removes LF from string
  1054. ;
  1055. ;Inputs a0 = string to remove LF from
  1056. ;    d0 = maxlength
  1057.  
  1058. RemoveLF:    move.l    a0,a1
  1059.         add.l    d0,a1
  1060. RemoveLF1:    cmp.b    #10,(a0)+
  1061.         beq    RemoveLF2
  1062.         cmp.l    a0,a1
  1063.         bne    RemoveLF1
  1064.         rts
  1065. RemoveLF2:    clr.b    -1(a0)
  1066.         rts
  1067.  
  1068. ;Encrypts passwords
  1069. ;
  1070. ;Input a0 = pointer to ASCII password
  1071. ;      a1 = pointer to buffer for encrypted password
  1072. ;
  1073.  
  1074. Encrypt:    clr.l    d1
  1075. Encrypt1:    move.l    (a0)+,d0
  1076.         rol.l    #2,d0
  1077.         add.l    #$DEADBEEF,d0
  1078.         ror.l    #7,d0
  1079.         swap.l    d0
  1080.         move.l    d0,(a1)+
  1081.         add.l    #1,d1
  1082.         cmp.l    #3,d1
  1083.         bne    Encrypt1
  1084.         rts
  1085.  
  1086.  
  1087. ;Decrypts passwords
  1088. ;
  1089. ;Input a0 = pointer to encrypted password
  1090. ;      a1 = pointer to buffer for decrypted password
  1091. ;
  1092.  
  1093. Decrypt:    clr.l    d1
  1094. Decrypt1:    move.l    (a0)+,d0
  1095.         swap.l    d0
  1096.         rol.l    #7,d0
  1097.         sub.l    #$DEADBEEF,d0
  1098.         ror.l    #2,d0
  1099.         move.l    d0,(a1)+
  1100.         add.l    #1,d1
  1101.         cmp.l    #3,d1
  1102.         bne    Decrypt1
  1103.         rts
  1104.  
  1105. ;Checks for CTRL_C
  1106. ;
  1107. ;Result d0 = -1 if CTRL_C was pressed
  1108. ;
  1109.  
  1110. CheckBreak:    clr.l    d1
  1111.         bset.l    #SIGBREAKB_CTRL_C,d1    ;check for CTRL_C
  1112.         lib    Dos,CheckSignal
  1113.         btst.l    #SIGBREAKB_CTRL_C,d0
  1114.         bne    CheckBreak1
  1115.         clr.l    d0
  1116.         rts
  1117. CheckBreak1:    lea.l    BreakText1,a0
  1118.         bsr    Printer
  1119.         move.l    #-1,d0
  1120.         rts
  1121.  
  1122. ;Reservations
  1123.  
  1124. RDArgs1:    dc.l    0
  1125.  
  1126. ;Options
  1127.  
  1128. CLArray1:
  1129. OptionAdd:    dc.l    0
  1130. OptionRemove:    dc.l    0
  1131. OptionEdit:    dc.l    0
  1132. OptionList:    dc.l    0
  1133. UserPointer:    dc.l    0
  1134.  
  1135. Quiet:        dc.w    1        ;0=Quiet, 1=Loud as hell...
  1136.  
  1137. SomethingDone:    dc.w    0
  1138.  
  1139. ;Files
  1140.  
  1141. _stdin:        dc.l    0
  1142.         dc.l    0
  1143. PassWdFile:    dc.l    0
  1144.  
  1145. ;Texts to output
  1146.  
  1147. CLTemplate1:    dc.b    "ADD/S,REMOVE/S,EDIT/S,LIST/S,USER",0
  1148.         dc.b    "$VER: PassWd 1.04 (3.2.93) Tomi Blinnikka 1993",0
  1149.  
  1150. UsageText1:    dc.b    "USAGE: PassWd [a] [r] [l] [e] [Username]",13,10,13,10
  1151.         dc.b    "       Where: [a] Add a user",13,10
  1152.         dc.b    "              [r] Remove a user",13,10
  1153.         dc.b    "              [e] Edit a user",13,10
  1154.         dc.b    "              [l] List active users",13,10
  1155.         dc.b    "              [Username] is the login name for user",13,10,13,10
  1156.         dc.b    "Adds & removes users and changes their passwords. Use with Logger.",13,10
  1157.         dc.b    "See docs for more information.",13,10,0
  1158.  
  1159. BreakText1:    dc.b    "***Break",13,10,0
  1160. CRLFText1:    dc.b    13,10,0
  1161. CreatingText1:    dc.b    "Password file doesn't exist! Creating new PassWd-file...",13,10,0
  1162. UserNText1:    dc.b    13,10,"Username: ",0
  1163. RealNText1:    dc.b    13,10,"Realname: ",0
  1164. AddUserText1:    dc.b    13,10,"Add user? ",0
  1165. RemUserText1:    dc.b    13,10,"Remove this user? ",0
  1166. EditUserText1:    dc.b    13,10,"Please choose item (press <Return> to quit)."
  1167.         dc.b    13,10,"(U)sername, (P)assword, (R)ealname, (H)ome, (O)ffice, (C)ommand, (W)rite: ",0
  1168. RemUserText2:    dc.b    "ERROR: Cannot remove 'root'!",13,10,0
  1169. GiveNameText1:    dc.b    "Enter realname for user: ",0
  1170. GiveNameText2:    dc.b    "Enter username for user: ",0
  1171. PasswordText1:    dc.b    "Enter password: ",0
  1172. PasswordText2:    dc.b    13,10,"Re-enter password: ",0
  1173. PasswordText3:    dc.b    "Enter current password: ",0
  1174. UserHomeText1:    dc.b    13,10,"Enter home directory for user: ",0
  1175. UserHomeText2:    dc.b    13,10,"Home directory: ",0
  1176. OfficeText1:    dc.b    13,10,"Enter office for user: ",0
  1177. OfficeText2:    dc.b    13,10,"Office: ",0
  1178. CommandText1:    dc.b    13,10,"Enter command for user: ",0
  1179. CommandText2:    dc.b    13,10,"Command: ",0
  1180. MaxText1:    dc.b    13,10,"Maximum length reached (10 characters)!",13,10,0
  1181. ShortText1:    dc.b    13,10,"Please enter a longer password. Minimum of 5 characters required.",13,10,0
  1182. MismatchText1:    dc.b    13,10,"Password mismatch! Please retry.",13,10,0
  1183. MismatchText2:    dc.b    13,10,"Incorrect password!",13,10,0
  1184. NoUserText1:    dc.b    "No user with that name!",13,10,0
  1185. DoubleNameText1: dc.b    "A user with that name already exists!",13,10,0
  1186. AllUsersText1:    dc.b    "List of active users:",13,10,0
  1187. InvalidText1:    dc.b    "Invalid username!",13,10,0
  1188.  
  1189. AskText1:    dc.b    "(Y/N): ",0
  1190. YesText1:    dc.b    "Yes",13,10,0
  1191. NoText1:    dc.b    "No",13,10,0
  1192. OptText1:    dc.b    "Username",13,10,0
  1193. OptText2:    dc.b    "Password",13,10,0
  1194. OptText3:    dc.b    "Realname",13,10,0
  1195. OptText4:    dc.b    "Home",13,10,0
  1196. OptText5:    dc.b    "Office",13,10,0
  1197. OptText6:    dc.b    "Write",13,10,0
  1198. OptText7:    dc.b    "Command",13,10,0
  1199.  
  1200. UserVarText1:    dc.b    "username",0
  1201. UNUSEDText1:    dc.b    "UNUSED",0
  1202. PassWdFileN:    dc.b    "LOGGER:PassWd.LOGGER",0
  1203.  
  1204. ;Error texts
  1205.  
  1206. FileErrorText1:    dc.b    "Couldn't open file 'GETTY:PassWd.LOGGER'",13,10,0
  1207. FileErrorText2:    dc.b    "Read error with file 'GETTY:PassWd.LOGGER'",13,10,0
  1208. FileErrorText3:    dc.b    "Write error with file 'GETTY:PassWd.LOGGER'",13,10,0
  1209. FileErrorText4:    dc.b    "Couldn't create file 'GETTY:PassWd.LOGGER'",13,10,0
  1210.  
  1211.         ds.l    0
  1212.  
  1213. ;library stuff
  1214.  
  1215.         libnames
  1216.  
  1217. ;buffers
  1218.  
  1219. Buffer1:    dcb.b    12,0        ;Temporary buffer for password
  1220. Buffer2:    dcb.b    12,0        ;Temporary buffer for password
  1221. Buffer3:    dcb.b    12,0        ;Temporary buffer for username
  1222.  
  1223. ;User template. Has template for user "root". This way it's easier to
  1224. ;create the new PassWd-file and new users
  1225.  
  1226. DATA_START:
  1227. UserName:    dc.b    "root"
  1228.         dcb.b    12-4,0                ;username
  1229. PassWord:    dcb.b    12,0                ;passwd (default is 'root')
  1230. RealName:    dc.b    "System Administraitor"        ;note the 'i' :)
  1231.         dcb.b    64-21,0                ;realname of user
  1232. UserHome:    dc.b    "USERS:root"
  1233.         dcb.b    64-10,0                ;user home directory
  1234. Office:        dc.b    "Admin"
  1235.         dcb.b    64-5,0                ;Office for finger etc.
  1236. UserCommand:    dc.b    "C:Execute Rem:Login-Start"    ;command to start
  1237.         dcb.b    64-25,0
  1238.  
  1239. DATA_END:    dc.l    0,0
  1240.  
  1241. DataSize:    EQU    (DATA_END-DATA_START)
  1242.  
  1243.         END
  1244.  
  1245.