home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / Logger / Finger.S < prev    next >
Text File  |  1993-12-21  |  9KB  |  512 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    03/08/1992            *
  10. *                        *
  11. * BUGS:    No plan or login texts            *
  12. *                        *
  13. * I have been up for 38 hours now. It must be    *
  14. * time to start writing this program :)        *
  15. *                        *
  16. * Version 1.01    08/08/1992            *
  17. *                        *
  18. * BUGS:    Didn't check for UNUSED in username    *
  19. *                        *
  20. * Version 1.02    10/08/1992            *
  21. *                        *
  22. * BUGS:                        *
  23. *                        *
  24. * Version 1.03    14/08/1992            *
  25. *                        *
  26. * BUGS:                        *
  27. *                        *
  28. * Version 1.04    28/12/1992            *
  29. *                        *
  30. * BUGS:                        *
  31. *                        *
  32. * Version 1.05    30/12/1992            *
  33. *                        *
  34. * CBM parser guidelines.            *
  35. *                        *
  36. * BUGS:    Won't find user if '?' was used first    *
  37. *                        *
  38. *************************************************
  39.  
  40.     INCLUDE    "JMPLibs.i"
  41.     INCLUDE    "exec/types.i"
  42.     INCLUDE    "exec/memory.i"
  43.     INCLUDE    "libraries/dos.i"
  44.  
  45.     INCLUDE    "XREF:2.0.xref"
  46.     INCLUDE    "XREF:exec.xref"
  47.     INCLUDE    "XREF:dos.xref"
  48.  
  49.     XREF    _LVOSetMode
  50.  
  51.     BITDEF  GV,LOCAL_ONLY,9
  52.  
  53. TRUE:        EQU    1
  54. FALSE:        EQU    0
  55.  
  56.         section    Finger,CODE
  57.  
  58.         move.l    a0,a4
  59.         clr.b    -1(a0,d0.l)
  60.         openlib    Dos,NoDos
  61.  
  62.         lib    Dos,Input
  63.         move.l    d0,_stdin
  64.  
  65.         lea.l    CLTemplate1,a0
  66.         move.l    a0,d1
  67.         lea.l    CLArray1,a0
  68.         move.l    a0,d2
  69.         clr.l    d3
  70.         lib    Dos,ReadArgs
  71.         move.l    d0,RDArgs1
  72.         beq    NoRDArgs
  73.  
  74. DoCmdLine:    tst.l    UNPointer
  75.         bne    CopyLoop
  76.  
  77.         lea.l    UserVarText1,a0
  78.         move.l    a0,d1
  79.         lea.l    Buffer3,a0
  80.         move.l    a0,d2
  81.         move.l    #10,d3
  82.         clr.l    d4            ;LV_VAR actually
  83.         or.l    #GVF_LOCAL_ONLY,d4
  84.         lib    Dos,GetVar
  85.         cmp.l    #-1,d0
  86.         beq    NoLocVars
  87.         bra    CopyLoop_OUT
  88.  
  89. CopyLoop:    lea.l    Buffer3,a0
  90.         move.l    a4,a5
  91.         add.l    #10,a5
  92. CopyLoop1:    move.b    (a4)+,(a0)+
  93.         tst.b    (a4)
  94.         beq    CopyLoop_OUT
  95.         cmp.l    a4,a5
  96.         beq    CopyLoop_OUT
  97.         cmp.b    #' ',(a4)
  98.         bne    CopyLoop1
  99. CopyLoop_OUT:
  100.  
  101.         lea.l    PassWdFileN,a0
  102.         move.l    a0,d1
  103.         move.l    #MODE_OLDFILE,d2
  104.         lib    Dos,Open
  105.         move.l    d0,PassWdFile
  106.         bne    StartMain
  107.  
  108.         bsr    FileError1
  109.         bra    ShutDown
  110.  
  111. StartMain:    lea.l    UNUSEDText1,a0
  112.         lea.l    Buffer3,a1
  113.         bsr    CmpStrings
  114.         tst.l    d0
  115.         beq    StartMain1
  116.         lea.l    InvalidText1,a0    
  117.         bsr    Printer
  118.         bra    ShutDown
  119.  
  120. StartMain1:    bsr    FindUser
  121.         tst.l    d0
  122.         bne    ShutDown
  123.  
  124.         lea.l    UserNText1,a0
  125.         bsr    Printer
  126.         lea.l    UserName,a0
  127.         bsr    Printer
  128.         lea.l    SpacesText1,a0
  129.         bsr    Printer
  130.         lea.l    RealNText1,a0
  131.         bsr    Printer
  132.         lea.l    RealName,a0
  133.         bsr    Printer
  134.         lea.l    UserHomeText2,a0
  135.         bsr    Printer
  136.         lea.l    UserHome,a0
  137.         bsr    Printer
  138.         lea.l    OfficeText2,a0
  139.         bsr    Printer
  140.         lea.l    Office,a0
  141.         bsr    Printer
  142.  
  143.         lea.l    LoginText1,a0
  144.         bsr    Printer
  145.  
  146.         lea.l    UserHome,a0
  147.         move.l    a0,d1
  148.         move.l    #ACCESS_READ,D2
  149.         lib    Dos,Lock
  150.         move.l    d0,NewLock
  151.         beq    FileError3
  152.  
  153.         move.l    NewLock,d1
  154.         lib    Dos,CurrentDir
  155.         move.l    d0,OldLock
  156.  
  157.         lea.l    LastLoginN,a0
  158.         move.l    a0,d1
  159.         move.l    #MODE_OLDFILE,d2
  160.         lib    Dos,Open
  161.         move.l    d0,LoginFile
  162.         beq    GivePlan
  163.  
  164.         move.l    LoginFile,d1
  165.         bsr    TypeFile
  166.  
  167. GivePlan:    lea.l    PlanName,a0
  168.         move.l    a0,d1
  169.         move.l    #MODE_OLDFILE,d2
  170.         lib    Dos,Open
  171.         move.l    d0,PlanFile
  172.         beq    GivePlan2
  173.  
  174.         lea.l    PlanText1,a0
  175.         bsr    Printer
  176.  
  177.         move.l    PlanFile,d1
  178.         bsr    TypeFile
  179.  
  180.         lea.l    CRLFText1,a0
  181.         bsr    Printer
  182.         bra    ShutDown
  183.  
  184. GivePlan2:    lea.l    PlanText2,a0
  185.         bsr    Printer
  186.  
  187. ShutDown:    move.l    RDArgs1,d1
  188.         beq    ShutDown9100
  189.         lib    Dos,FreeArgs
  190.  
  191. ShutDown9100:    move.l    PassWdFile,d1
  192.         beq    ShutDown9000
  193.         lib    Dos,Close
  194.  
  195. ShutDown9000:    move.l    LoginFile,d1
  196.         beq    ShutDown8500
  197.         lib    Dos,Close
  198. ShutDown8500:    move.l    PlanFile,d1
  199.         beq    ShutDown8000
  200.         lib    Dos,Close
  201.  
  202. ShutDown8000:    move.l    NewLock,d1
  203.         beq    ShutDown7500
  204.         lib    Dos,UnLock
  205.  
  206. ShutDown7500:    move.l    OldLock,d1
  207.         beq    ShutDown6000
  208.         lib    Dos,CurrentDir
  209.  
  210. ShutDown6000:    tst.l    TypeFileMem
  211.         beq    ShutDown5000
  212.         move.l    TypeFileMem,a1
  213.         move.l    TypeFileLength,d0
  214.         lib    Exec,FreeMem
  215.  
  216. ShutDown5000:
  217. ShutDown1000:    closlib    Dos
  218.  
  219.         move.l    #RETURN_OK,d0
  220.         rts
  221.  
  222. NoDos:        move.l    #RETURN_FAIL,d0
  223.         rts
  224.  
  225. NoLocVars:    move.l    #ERROR_REQUIRED_ARG_MISSING,d1
  226.         lib    Dos,SetIoErr            ;DO NOT SEPARATE!*1
  227. NoRDArgs:    lib    Dos,IoErr            ;DO NOT SEPARATE!*1
  228.         move.l    d0,d1
  229.         clr.l    d2
  230.         lib    Dos,PrintFault
  231.         bra    ShutDown
  232.  
  233. FileError1:    lea.l    FileErrorText1,a0
  234.         bsr    Printer
  235.         rts
  236. FileError2:    lea.l    FileErrorText2,a0
  237.         bsr    Printer
  238.         rts
  239. FileError3:    lea.l    FileErrorText3,a0
  240.         bsr    Printer
  241.         bra    ShutDown
  242. FileError4:    lea.l    FileErrorText4,a0
  243.         bsr    Printer
  244.         bra    ShutDown
  245.  
  246. WarnLowMem:    lea.l    LowMemText1,a0
  247.         bsr    Printer
  248.         rts
  249.  
  250. Printer:    printa    a0
  251.         rts
  252.  
  253. ;Inputs Buffer3 = user to find
  254.  
  255. FindUser:    bsr    ReadUser
  256.         tst.l    d0
  257.         bne    FindUser_ERR1
  258.         lea.l    UserName,a0
  259.         lea.l    Buffer3,a1
  260.         bsr    CmpStrings
  261.         tst.l    d0
  262.         beq    FindUser
  263.         clr.l    d0
  264.         rts
  265. FindUser_ERR1:    move.l    #-1,d0
  266.         rts
  267.  
  268. ReadUser:    move.l    PassWdFile,d1
  269.         lea.l    UserName,a0
  270.         move.l    a0,d2
  271.         move.l    #DataSize,d3
  272.         lib    Dos,Read
  273.         cmp.l    #DataSize,d0
  274.         beq    ReadUser2
  275.         lib    Dos,IoErr
  276.         tst.l    d0
  277.         beq    ReadUser1
  278.         bsr    FileError2
  279.         move.l    #-1,d0
  280.         rts
  281. ReadUser1:    lea.l    NoUserText1,a0
  282.         bsr    Printer
  283.         move.l    #-1,d0
  284.         rts
  285. ReadUser2:    clr.l    d0
  286.         rts
  287.  
  288. ;Compares two strings.
  289. ;
  290. ;INPUT
  291. ;
  292. ;A0 String 1 (original password f.ex(?))
  293. ;A1 String 2
  294. ;
  295. ;OUTPUT
  296. ;
  297. ;D0 = 0 if not same
  298. ;
  299. ;BUGS
  300. ;
  301. ;String 1 has to have NULL at end!
  302. ;
  303.  
  304. CmpStrings:    bsr    GetLength
  305.         move.l    d3,d4        ;length of string1 to d4
  306.         push    a0
  307.         move.l    a1,a0
  308.         bsr    GetLength
  309.         pull    a0
  310.         cmp.l    d4,d3        ;length of string2 in d3
  311.         bne    CmpStrings1.1
  312. CmpStrings1:    tst.b    (a0)
  313.         beq    CmpStrings2
  314.         cmp.b    (a0)+,(a1)+
  315.         beq    CmpStrings1
  316. CmpStrings1.1:    clr.l    d0
  317.         rts
  318. CmpStrings2:    move.l    #-1,d0
  319.         rts
  320.  
  321. ;CmpStrings:    tst.b    (a0)
  322. ;        beq    CmpStrings2
  323. ;        cmp.b    (a0)+,(a1)+
  324. ;        beq    CmpStrings
  325. ;        clr.l    d0
  326. ;        rts
  327. ;CmpStrings2:    move.l    #-1,d0
  328. ;        rts
  329.  
  330. ;Get length of text in given address
  331. ;
  332. ;Input a0 = Address of null terminated text string
  333. ;
  334. ;Result d3 = Length
  335.  
  336. GetLength:    push    a0
  337.         clr.l    d3
  338.         cmp.l    #$00,a0        ;fixes enforcer hit
  339.         beq    GetLength_OUT
  340. GetLength2:    add.l    #1,d3
  341.         tst.b    (a0)+
  342.         bne    GetLength2
  343.         sub.l    #1,d3        ;don't include NULL
  344. GetLength_OUT:    pull    a0
  345.         rts
  346.  
  347. ;Gets the length of the file given
  348. ;
  349. ;Input d1 = File
  350. ;
  351. ;Result d0 = Length of file in bytes
  352. ;
  353.  
  354. GetFileLength:    push    d5-d6
  355.         move.l    d1,d6
  356.         move.l    #00,d2
  357.         move.l    #01,d3
  358.         lib    Dos,Seek
  359.         move.l    d6,d1
  360.         lib    Dos,Seek
  361.  
  362.         move.l    d0,d5
  363.         move.l    d6,d1
  364.         move.l    #0,d2
  365.         move.l    #-1,d3
  366.         lib    Dos,Seek
  367.  
  368.         move.l    d5,d0
  369.         pull    d5-d6
  370.         rts
  371.  
  372. ;Checks for CTRL_C
  373. ;
  374. ;Result d0 = -1 if CTRL_C was pressed
  375. ;
  376.  
  377. CheckBreak:    clr.l    d1
  378.         bset.l    #SIGBREAKB_CTRL_C,d1    ;check for CTRL_C
  379.         lib    Dos,CheckSignal
  380.         btst.l    #SIGBREAKB_CTRL_C,d0
  381.         bne    CheckBreak1
  382.         clr.l    d0
  383.         rts
  384. CheckBreak1:    lea.l    BreakText1,a0
  385.         bsr    Printer
  386.         move.l    #-1,d0
  387.         rts
  388.  
  389. TypeFile:    move.l    d1,d4
  390.         bsr    GetFileLength
  391.         tst.l    d0
  392.         beq    TypeFile_OUT
  393.  
  394.         move.l    d0,TypeFileLength
  395.         move.l    #MEMF_CLEAR!MEMF_PUBLIC,d1    ;Type of memory wanted
  396.         lib    Exec,AllocMem
  397.         move.l    d0,TypeFileMem
  398.         beq    TypeFile_ERR2
  399.  
  400.         move.l    d4,d1
  401.         move.l    TypeFileMem,d2
  402.         move.l    TypeFileLength,d3
  403.         lib    Dos,Read
  404.         cmp.l    TypeFileLength,d0
  405.         bne    TypeFile_ERR3
  406.  
  407.         move.l    TypeFileMem,a0
  408.         bsr    Printer
  409.  
  410. TypeFile2:    tst.l    TypeFileMem
  411.         beq    TypeFile_OUT
  412.         move.l    TypeFileMem,a1
  413.         move.l    TypeFileLength,d0
  414.         lib    Exec,FreeMem
  415.         clr.l    TypeFileMem
  416.         clr.l    TypeFileLength
  417. TypeFile_OUT:    rts
  418.  
  419. TypeFile_ERR2:    bsr    WarnLowMem
  420.         bra    TypeFile2
  421.  
  422. TypeFile_ERR3:    bsr    FileError4
  423.         bra    TypeFile_OUT
  424.  
  425.  
  426. ;Structures and reservations
  427.  
  428. ;Files
  429.  
  430. _stdin:        dc.l    0
  431. PassWdFile:    dc.l    0
  432. LoginFile:    dc.l    0
  433. PlanFile:    dc.l    0
  434. OldLock:    dc.l    0
  435. NewLock:    dc.l    0
  436. TypeFileLength:    dc.l    0
  437. TypeFileMem:    dc.l    0
  438. RDArgs1:    dc.l    0
  439.  
  440. ;Options
  441.  
  442. CLArray1:
  443. UNPointer:    dc.l    0
  444.  
  445. ;Texts to output
  446.  
  447. CLTemplate1:    dc.b    "USERNAME/F",0
  448.  
  449.         dc.b    "$VER: Finger 1.05 (1.1.93) (C)opyright Tomi Blinnikka 1993",0
  450.  
  451. BreakText1:    dc.b    "***Break",13,10,0
  452. CRLFText1:    dc.b    13,10,0
  453. SpacesText1:    dc.b    "                   ",0
  454. CreatingText1:    dc.b    "Password file doesn't exist! Creating new PassWd-file...",13,10,0
  455. NoUserText1:    dc.b    "No user with that name!",13,10,0
  456.  
  457. UserNText1:    dc.b    "Login name: ",0
  458. RealNText1:    dc.b    "In real life: ",0
  459. OfficeText2:    dc.b    13,10,"Office: ",0
  460. UserHomeText2:    dc.b    13,10,"Directory: ",0
  461. LoginText1:    dc.b    13,10,"Last login ",0
  462. PlanText1:    dc.b    "Plan:",13,10,0
  463. PlanText2:    dc.b    "No Plan.",13,10,0
  464.  
  465. UserVarText1:    dc.b    "username",0
  466. PassWdFileN:    dc.b    "LOGGER:PassWd.LOGGER",0
  467. LastLoginN:    dc.b    ".lastlogin",0
  468. PlanName:    dc.b    ".plan",0
  469. UNUSEDText1:    dc.b    "UNUSED",0
  470.  
  471. ;Error texts
  472.  
  473. FileErrorText1:    dc.b    "Couldn't open file 'LOGGER:PassWd.LOGGER'",13,10,0
  474. FileErrorText2:    dc.b