home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / UNIFLEX / UNIFLEX / UniFLEX_Std.Utils1.tar.Z / UniFLEX_Std.Utils1.tar / utils1 / newuser < prev    next >
Text File  |  1984-02-01  |  11KB  |  601 lines

  1.  opt nol
  2.  opt pag
  3.  ttl Newuser Program
  4.  lib sysdef
  5.  pag
  6.  opt lis
  7.  info UniFLEX newuser
  8.  info Version 1.00, Released Feb 3, 1984
  9.  info Copyright, (C) 1984, by
  10.  info Technical Systems Consultants, Inc.
  11.  info All rights reserved.
  12.  
  13. * constants
  14.  
  15. ECHO equ %00000010 echo bit
  16. LCASE equ %00001000 lower case bit
  17. CR equ $d carriage return
  18. st_siz equ 9 status size offset
  19.  
  20.  
  21. * newuser program
  22.  
  23.  org 0
  24.  
  25. login sys cpint,2,1 catch INTS
  26.  sys cpint,3,1 catch QUITS
  27.  ldd #0 set user id to 0
  28.  sta pwex
  29.  sys suid
  30.  ldd #2 close file 2
  31.  sys close
  32.  ldd #1 get standard out file desc
  33.  sys dup duplicate the file (error chan)
  34.  ldd #0 set priority bias
  35.  sys setpr
  36.  ldd #0 set file desc
  37.  sys ttyget,ttbuf
  38.  lda ttbuf get flag bits
  39.  anda #%10111110
  40.  sta ttbuf set back in buffer
  41.  ldd #0 set file desc
  42.  sys ttyset,ttbuf
  43.  ldd 0,s get arg count
  44.  ldx #buffer point to buffer
  45.  ldu 4,s point to name
  46.   cmpd #2 name specified?
  47.  bhs login0
  48.  ldu #sysnam point to "system" string
  49. login0 lda 0,u+ xfr name to buffer
  50.  sta 0,x+
  51.  bne login0
  52. logi25 lbsr fndnam find login name in file
  53.  bec login3 error?
  54.  inc ngflg set no good ind
  55.  inc pwex set flag
  56. login3 tst pwex password exist?
  57.  beq login4 if not - no prompt
  58.  lda ttbuf get flags
  59.  anda #!ECHO turn off echo
  60.  sta ttbuf
  61.  ldd #0 set file desc
  62.  sys ttyset,ttbuf
  63.  ldd #1 set file desc
  64.  sys write,pswst,PSZ output 'Password'
  65.  ldd #0 set file desc
  66.  sys read,buffer,32 read response
  67.  pshs d save count
  68.  lda ttbuf get tty flags
  69.  ora #ECHO set echo on
  70.  sta ttbuf
  71.  ldd #0 set file desc
  72.  sys ttyset,ttbuf set status
  73.  ldd #1 set file desc
  74.  sys write,crst,1 write out cr
  75.  puls d get count
  76.  cmpd #0 end of file?
  77.  lbeq nogud
  78.  ldx #buffer-1 point to buffer
  79.  clr d,x set null term
  80. login4 tst ngflg no good set?
  81.  lbne nogud if so, error
  82.  lbsr chkps check password
  83.  lbes nogud error?
  84. logi45 lbsr getid get user id from file
  85.  lbes nogud
  86.  lbsr setdr set up user's dir
  87.  bec login5 error?
  88.  ldd #1 set file desc
  89.  sys write,ndrms,NDSZ write error message
  90.  ldd #$ff
  91.  sys term terminate task
  92. login5 ldd usrid get user id
  93.  std icho2 set up os call
  94.  sys ind,icho change tty owner
  95.  ldd usrid get user id
  96.  sys suid set user id
  97.  lbsr mkhom write home file
  98.  lda [nxtfld] program specified?
  99.  cmpa #$d if null - do shell
  100.  bne login6
  101.  lbsr chkml check for mail
  102.  sys exec,shell,args
  103.  sys term
  104. login6 ldx nxtfld get field pointer
  105.  stx subrg2 set up call
  106. login7 lda 0,x+ look for line end
  107.  cmpa #$d is it cr?
  108.  bne login7
  109.  clr -1,x set line end
  110.  sys exec,shell,subrg execute the program thru shell
  111.  sys term error?
  112.  
  113.  pag
  114.  
  115. * print file message
  116.  
  117. prtmsg stx iopn2 save file name in ind call
  118.  sys ind,iopn do file open for read (ind)
  119.  bes prtms8 error?
  120.  pshs d save file desc
  121. prtms2 ldd 0,s get file desc
  122.  sys read,buffer,32 read in file
  123.  bes prtms5 error?
  124.  std iwrt2 set count in ind call
  125.  beq prtms5
  126.  ldd #1 set file desc
  127.  sys ind,iwrt do write
  128.  bra prtms2 repeat
  129. prtms5 puls d get file desc
  130.  sys close close the file
  131. prtms8 rts return
  132.  
  133.  
  134. *
  135. * nogud
  136. *
  137. * Report incorrect login
  138. *
  139.  
  140. nogud lda ttbuf get ttyset flags
  141.  anda #!LCASE reset lower case bit
  142.  sta ttbuf
  143.  ldd #0 set file desc
  144.  sys ttyset,ttbuf reset data
  145.  ldd #1 set file desc
  146.  sys write,ngmsg,NGSZ write out message
  147.  ldd #$ff
  148.  sys term
  149.  
  150. *
  151. * mkhom
  152. *
  153. * Create the 'home*' file which contains the name of
  154. * this guys login directory.  This is used by shell.
  155. *
  156.  
  157. mkhom sys create,homnm,$1b create file
  158.  bes mkhom6 if error - skip
  159.  pshs d save file desc
  160.  ldx ichd2 get ptr to dir name
  161.  stx ihwrt2 set up os call
  162.  ldd #0 set counter to 0
  163. mkhom2 tst 0,x+ get size of string
  164.  beq mkhom3
  165.  incb
  166.  bra mkhom2
  167. mkhom3 incb
  168.  std ihwrt3 save count in call
  169.  ldd 0,s get file desc
  170.  sys ind,ihwrt output name
  171.  puls d get file desc
  172.  sys close close the file
  173. mkhom6 rts return
  174.  
  175.  pag
  176.  
  177. *
  178. * fndnam
  179. *
  180. * Find name in password file.  Return error set
  181. * if error.
  182. *
  183.  
  184. fndnam ldx #fbuf point to file buffer
  185.  stx linpt init buf ptrs
  186.  stx linend
  187.  sys open,nfile,0 open password file
  188.  bes fndna4 error?
  189.  std namfd save file desc
  190. fndna2 bsr getlin get a line from the file
  191.  beq fndna5 eof?
  192.  ldx #buffer point to name
  193.  ldy #linbuf point to line
  194.  bsr cmpnam compare names
  195.  bne fndna2 if no compare, repeat
  196.  sty nxtfld save field pointer
  197.  lda 0,y check for null pw
  198.  cmpa #':
  199.  beq fndna3
  200.  inc pwex set pw flag
  201. fndna3 ldd namfd get file desc
  202.  sys close close the file
  203.  clc clear error
  204. fndna4 rts return
  205. fndna5 ldd namfd get file desc
  206.  sys close close the file
  207.  sec set error
  208.  rts return
  209.  
  210.  
  211. *
  212. * getlin
  213. *
  214. * Get a line from the password file.  Put it
  215. * in the linbuf.
  216. *
  217.  
  218. getlin ldx #linbuf point to line buffer
  219. getli2 bsr gtch get a character
  220.  beq getli4 eof?
  221.  sta 0,x+ save character in buffer
  222.  cmpa #CR end of line?
  223.  bne getli2
  224.  clz set ok status
  225. getli4 rts return
  226.  
  227.  pag
  228.  
  229. *
  230. * gtch
  231. *
  232. * Get a character from the password file.  Return
  233. * eq status if eof.
  234. *
  235.  
  236. gtch pshs x save x
  237. gtch2 ldx linpt get line pointer
  238.  cmpx linend end of buffer?
  239.  bne gtch4
  240.  ldd namfd get file desc
  241.  sys read,fbuf,512 read in some file
  242.  bes gtch6 error?
  243.  cmpd #0 eof?
  244.  beq gtch6
  245.  ldx #fbuf point to buffer begin
  246.  stx linpt save pointer
  247.  leax d,x mark end of buffer
  248.  stx linend
  249.  ldx linpt reset pointer
  250. gtch4 lda 0,x+ get next character
  251.  stx linpt save pointer
  252.  clz set ok status
  253.  puls x,pc return
  254. gtch6 sez set error
  255.  puls x,pc return
  256.  
  257.  
  258. *
  259. * cmpnam
  260. *
  261. * Compare name pointed at by X to name pointed
  262. * at by Y.  Return eq or ne status.
  263. *
  264.  
  265. cmpnam lda 0,x+ get a character
  266.  beq cmpna4 end of name?
  267.  cmpa 0,y+ compare chars
  268.  beq cmpnam repeat?
  269.  rts return ne
  270. cmpna4 lda 0,y+ get next
  271.  beq cmpna6 null?
  272.  cmpa #': end of field?
  273. cmpna6 rts return
  274.  
  275.  pag
  276.  
  277. *
  278. * decvt
  279. *
  280. * Decimal convert routine.  Convert ascii string
  281. * pointed at by x and null terminated.
  282. * Return number in D and ne if error.
  283. *
  284.  
  285. decvt ldd #0 set up zero
  286.  pshs d
  287. decvt2 lda 0,x+ get character
  288.  beq decvt4 end of list?
  289.  cmpa #'0 check for valid number
  290.  blo decvt3 error?
  291.  cmpa #'9
  292.  bhi decvt3
  293.  anda #$F mask character
  294.  pshs a save digit
  295.  ldd 1,s get number
  296.  aslb multiply by 8
  297.  rola
  298.  aslb
  299.  rola
  300.  aslb
  301.  rola
  302.  addd 1,s add in original twice
  303.  addd 1,s
  304.  addb 0,s+ add in new digit
  305.  adca #0
  306.  std 0,s save result
  307.  bra decvt2 repeat
  308. decvt3 clz set error
  309. decvt4 puls d,pc return
  310.  
  311.  pag
  312. *
  313. * chkps
  314. *
  315. * Check for valid password.  Return carry set on error.
  316. *
  317.  
  318. chkps pshs d save count
  319.  bsr gtnxt get next field
  320.  puls d reset count
  321.  tst pwex pw exist?
  322.  beq chkps4
  323.  cmpd #1 check for eof or cr
  324.  bls chkps3 if so, error
  325.  pshs x save buffer pointer
  326.  ldx #buffer point to name
  327.  pshs x save as arg
  328.  ldx #encpw point to encryption buffer
  329.  pshs x save as arg
  330.  lbsr crypt do encryption
  331.  leas 4,s clean stack
  332.  lbsr mkasc make ascii string
  333.  puls x
  334.  ldy #ascpw point to encrypted pswd
  335.  lbsr cmpnam compare names
  336.  beq chkps4
  337. chkps3 sec set error
  338.  rts return
  339. chkps4 clc clear error
  340.  rts return
  341.  
  342.  pag
  343.  
  344. *
  345. * gtnxt
  346. *
  347. * Get next field from linbuf
  348. *
  349.  
  350. gtnxt ldx nxtfld get field pointer
  351.  pshs x save it
  352. gtnxt2 lda 0,x+ get character
  353.  cmpa #': is it term?
  354.  bne gtnxt2
  355.  clr -1,x set null term
  356.  stx nxtfld set next ptr
  357.  puls x,pc return
  358.  
  359.  
  360. *
  361. * getid
  362. *
  363. * Get user id from password file.
  364. *
  365.  
  366. getid bsr gtnxt get next field
  367.  lbsr decvt convert number to binary
  368.  bne getid4 error?
  369.  std usrid save id
  370.  clc set ok status
  371.  rts return
  372. getid4 sec set error
  373.  rts return
  374.  
  375.  
  376. *
  377. * setdr
  378. *
  379. * Setup new user directory.
  380. *
  381.  
  382. setdr bsr gtnxt get next field
  383.  stx ichd2 set in ind call
  384.  sys ind,ichd do chdir
  385.  rts return
  386.  
  387.  
  388.  pag
  389.  
  390. *
  391. * chkml
  392. *
  393. * Check for mail file.
  394. *
  395.  
  396. chkml sys status,malnm,stb check status
  397.  bes chkml6 if error, no mail
  398.  ldd stb+st_siz+2 check size of file
  399.  bne chkml4 if != 0, then mail
  400.  ldd stb+st_siz
  401.  beq chkml6
  402. chkml4 ldd #1 set file desc
  403.  sys write,mlstr,MLSZ output message
  404. chkml6 rts return
  405.  
  406. *
  407. * mkasc
  408. *
  409. * Make encrypted password an ascii string.
  410. *
  411.  
  412. mkasc ldb #8 set count
  413.  pshs b
  414.  ldx #encpw point to password
  415.  ldy #ascpw point to buffer
  416. mkasc2 lda 0,x get a byte
  417.  anda #$f mask low 4 bits
  418.  adda #'k make a letter
  419.  sta 0,y+ save in buffer
  420.  lda 0,x+ get byte
  421.  lsra shift to get hi 4 bits
  422.  lsra
  423.  lsra
  424.  lsra
  425.  adda #'a make a letter
  426.  sta 0,y+ add to buffer
  427.  dec 0,s dec the count
  428.  bne mkasc2 repeat?
  429.  puls b,pc return
  430.  
  431.  pag
  432.  
  433. **   CRYPT - ENCRYPT PASSWORD.
  434. *
  435. *    ENTRY (2,S)=POINTER TO 8 BYTE RESPONSE AREA
  436. *          (4,S)=POINTER TO PASSWORD, TERMINATED BY
  437. *                A ZERO BYTE
  438.  SPC 2
  439. crypt LDX 2,S (X)=ADDRESS OF RESPONSE AREA
  440.  LDY 4,S (Y)=ADDRESS OF PASSWORD
  441.  LDA #251 SET LOOP COUNTER
  442.  PSHS A
  443.  LEAS -8,S RESERVE WORK SPACE
  444.  CLRB (B)=INDEX/COUNTER
  445.  
  446. *   COPY PASSWORD TO RESPONSE AND WORK AREAS.
  447.  
  448. crypt1 LDA 0,Y+
  449.  BNE crypt2 IF NOT END OF PASSWORD
  450.  LEAY -1,Y BACK UP POINTER
  451. crypt2 STA B,X STORE IN RESPONSE AREA
  452.  STA B,S STORE IN WORK AREA
  453.  INCB COUNT CHARACTER
  454.  CMPB #8
  455.  BLO crypt1 LOOP FOR 8 BYTES
  456.  
  457. *    TAUSWORTHE RANDOM NUMBER GENERATOR.
  458. *    ADAPTED FROM THE ALGORITHM OF E. J. WATSON,
  459. *    UNIVERSITY OF MANCHESTER.
  460. *    ALGORITHM DOCUMENTED IN CACM, VOL 11, NO. 9, SEPT, 1968
  461. *    P. 643.
  462. *    VALUES USED: N=63, M=31
  463. *    TO BE CONSISTENT WITH ALGORITHM, BITS NUMBERS ARE FROM
  464. *    LEFT TO RIGHT, STARTING AT ZERO.
  465.  
  466. crypt4 LDA 4,S PUT BIT 32 IN CARRY
  467.  LSLA
  468.  LDD 2,S (D)=BITS 16-31
  469.  ROLB
  470.  ROLA (D)=BITS 17-32, CARRY=BIT 16
  471.  EORB 7,S BITS 17-32 XOR BITS 48-63
  472.  EORA 6,S
  473.  STD 6,S REPLACE BITS 48-63
  474.  EORB 3,S NEW 48-64 XOR BITS 16-31
  475.  EORA 2,S
  476.  STD 2,S REPLACE BITS 16-31
  477.  LDD 0,S (D)=BITS 0-15
  478.  ROLB
  479.  ROLA (D)=BITS 1-16
  480.  EORB 5,S BITS 1-16 XOR BITS 32-47
  481.  EORA 4,S
  482.  STD 4,S REPLACE BITS 32-47
  483.  EORB 1,S NEW 32-47 XOR BITS 0-15
  484.  EORA 0,S
  485.  STD 0,S REPLACE BITS 0-15
  486.  DEC 8,S COUNT ITERATION
  487.  BNE crypt4 REPEAT 8 TIMES
  488.  LDB #7 (B)=BYTE COUNTER
  489.  ANDCC #$FE CLEAR CARRY
  490. crypt5 LDA B,S ADD BACK ORIGINAL PASSWORD
  491.  ADCA B,X
  492.  STA B,X
  493.  DECB
  494.  BPL crypt5
  495.  LEAS 9,S CLEAN UP STACK
  496.  RTS RETURN
  497.  
  498.  pag
  499.  
  500. * indirect calls
  501.  
  502. iopn fcb open
  503. iopn2 fdb 0,0
  504.  
  505. iwrt fcb write
  506.  fdb buffer
  507. iwrt2 fdb 0
  508.  
  509. ichd fcb chdir ind chdir call
  510. ichd2 fdb 0
  511.  
  512. isk fcb seek ind seek call
  513.  fdb 0
  514. isk2 fdb 0,0
  515.  
  516. icho fcb chown change owner
  517.  fdb ttchn
  518. icho2 fdb 0
  519.  
  520. ihwrt fcb write
  521. ihwrt2 fdb 0
  522. ihwrt3 fdb 0
  523.  
  524.  
  525. * constant strings
  526.  
  527. sysnam fcc 'system',0
  528. homnm fcc '.home?',0
  529. shell fcc '/bin/shell',0
  530. args fdb shelln,0
  531. shelln fcc '+shell',0
  532. nfile fcc '/etc/log/password',0
  533. malnm fcc '.mail',0
  534. cptst fcc '+cx',0
  535. ttydir fcc '/dev',0
  536. ttnam fcc 'tty'
  537. ttnam2 fcc 'xx',0
  538. spcs fcc '                    '
  539. ttchn fcc '/dev/tty'
  540. ttchn2 fcc 'xx',0
  541.  
  542. ngmsg fcc 'Login incorrect!',$d,$d
  543. NGSZ equ *-ngmsg
  544.  
  545.  
  546. pswst fcc 'Password: '
  547. PSZ equ *-pswst
  548.  
  549. ndrms fcc 'No directory!'
  550. NDSZ equ *-ndrms
  551.  
  552. mlstr fcc 'You have mail.',$d
  553. MLSZ equ *-mlstr
  554.  
  555. bdtr fcc 'Bad terminal.',$d
  556. BDSZ equ *-bdtr
  557.  
  558. crst fcb $d carriage string
  559. subrg fdb shell+5,cptst
  560. subrg2 fdb 0,0
  561.  
  562. * buffers
  563.  
  564. r0 fdb 0,0 regs for div and mul
  565. r1 fdb 0,0
  566. work fdb 0,0
  567. day fdb 0 day temp
  568. ntime fdb 0,0 new time
  569. eutc fcb 0 east of utc flag
  570. fstdl fdb 0 1st day of dlst
  571. lstdl fdb 0 last day of dlst
  572. dlflg fcb 0 dlst flag
  573. ltime fdb 0,0 local time
  574. tzn fdb 0,0 time zone seconds
  575.  
  576. ttbuf rmb 6 ttyset buffer
  577. buffer rmb 32
  578. ngflg fcb 0 no good flag
  579. nxtfld fdb 0 next field pointer
  580. namfd fdb 0 name file descriptor
  581. linpt fdb 0 line pointer
  582. linend fdb 0 end of line pointer
  583. usrid fdb 0 user id
  584. pwex fcb 0 pw exists flag
  585. noban fcb 0 if banner should not be displayed
  586. stb rmb 24 status buffer
  587. encpw rmb 8 password buffer
  588. ascpw rmb 16 ascii pswd buffer
  589.  fcb 0 null term for above
  590. curtim rmb 8 current time
  591.  rmb 4 spare
  592. ttybuf rmb 16 tty buffer
  593. ttystb rmb 24 tty status buffer
  594. linbuf rmb 128 line buffer
  595.  
  596.  org $E00
  597.  
  598. fbuf rmb 512 file buffer
  599.  
  600.  end login
  601.