2475
|
1 ********************************************************************
|
|
2 * inetd - internet daemon
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Edt/Rev YYYY/MM/DD Modified by
|
|
7 * Comment
|
|
8 * ------------------------------------------------------------------
|
|
9 * 1 2010/01/08 Boisy G. Pitre
|
|
10 * Started.
|
|
11 *
|
|
12 * 2 2010/01/22 Boisy G. Pitre
|
|
13 * Now reads inetd.conf file.
|
2578
|
14 *
|
|
15 * 3 2011/08/07 Boisy G. Pitre
|
|
16 * Fixed bug where conf file wasn't being processed correctly.
|
2475
|
17
|
|
18 nam inetd
|
|
19 ttl internet daemon
|
|
20
|
|
21 tylg set $01 Prgrm+Objct
|
|
22 atrv set $80+rev ReEnt+rev
|
|
23 rev set $00
|
2578
|
24 edition set 3
|
2475
|
25
|
|
26 psect inetd_a,$01,$80,1,200,start
|
|
27
|
|
28 DEBUG equ 1
|
|
29
|
|
30 vsect
|
|
31 targetport rmb 2
|
|
32 netdatardy rmb 1
|
|
33 nbufferl equ 128
|
|
34 nbuffer rmb nbufferl
|
|
35 lbufferl equ 128
|
|
36 lbuffer rmb lbufferl
|
|
37 nnext rmb 2
|
|
38 token rmb 2
|
|
39 orgstdin rmb 1
|
|
40 orgstdout rmb 1
|
|
41 orgstderr rmb 1
|
|
42 childnetpath rmb 1
|
|
43 netpath rmb 1
|
|
44 targetprog rmb 128
|
|
45 targetparams rmb 128
|
2579
|
46 tmodeparamlen rmb 1
|
|
47 tmodeparams rmb 128
|
2475
|
48 endsect
|
|
49
|
|
50 NetSig equ 2
|
|
51
|
2579
|
52 tmode fcs /tmode/
|
|
53
|
2475
|
54 * signal intercept routine
|
|
55 sigint cmpb #NetSig
|
|
56 bne sigex
|
|
57 inc netdatardy,u
|
|
58 sigex rti
|
|
59
|
|
60 **** Entry Point ****
|
|
61 start:
|
|
62 * setup signal intercept
|
|
63 leax sigint,pcr
|
|
64 os9 F$Icpt
|
|
65
|
|
66 clr netdatardy,u
|
|
67
|
|
68 leax nbuffer,u
|
|
69 stx nnext,u
|
|
70
|
|
71 * open the path to the control channel
|
|
72 lbsr TCPOpen
|
|
73 lbcs errex
|
|
74 sta netpath,u
|
|
75
|
|
76 leax SetupPorts,pcr
|
|
77 lbsr ProcInetd
|
|
78 lbcs errex
|
|
79
|
|
80 IFNE DEBUG
|
|
81 lbsr PRINTS
|
|
82 fcc /Got netpath and setup ports/
|
|
83 fcb C$CR
|
|
84 fcb $00
|
|
85 ENDC
|
|
86
|
|
87 ssignetpath
|
|
88 IFNE DEBUG
|
|
89 lbsr PRINTS
|
|
90 fcc /SS.SSig on NetPath/
|
|
91 fcb C$CR
|
|
92 fcb $00
|
|
93 ENDC
|
|
94
|
|
95 lda netpath,u
|
|
96 ldb #SS.SSig send signal on data ready
|
|
97 ldx #NetSig
|
|
98 os9 I$SetStt
|
|
99 lbcs errex
|
|
100
|
|
101 **** MAIN LOOP ****
|
|
102 mainloop
|
|
103 pshs cc
|
|
104 orcc #IntMasks
|
|
105 tst netdatardy,u
|
|
106 bne gotdata
|
|
107
|
|
108 * wait for a child to die (or wake up via signal)
|
|
109 os9 F$Wait
|
|
110 bcc chkrdy
|
|
111 cmpb #E$NoChld
|
|
112 bne chkrdy got error other than "no children"
|
|
113 * if no children, go to sleep
|
|
114 ldx #$0000
|
|
115 os9 F$Sleep
|
|
116
|
|
117 chkrdy puls cc
|
|
118 bra ssignetpath
|
|
119
|
|
120 gotdata puls cc
|
|
121 dec netdatardy,u
|
|
122 * read the data from netpath
|
|
123 IFNE DEBUG
|
|
124 lbsr PRINTS
|
|
125 fcc /Reading data from netpath/
|
|
126 fcb C$CR
|
|
127 fcb $00
|
|
128 ENDC
|
|
129
|
|
130 lda netpath,u
|
|
131 ldb #SS.Ready
|
|
132 os9 I$GetStt
|
|
133 bcs ssignetpath
|
|
134
|
|
135 clra
|
|
136 tfr d,y
|
|
137 lda netpath,u
|
|
138 ldx nnext,u
|
|
139 os9 I$Read
|
|
140 lbcs errex
|
|
141 tfr y,d
|
|
142 leax d,x
|
|
143 stx nnext,u
|
|
144 lda -1,x
|
|
145 cmpa #C$CR
|
|
146 lbne ssignetpath
|
|
147
|
|
148 leax nbuffer,u
|
|
149 stx nnext,u
|
|
150
|
|
151 lda #1
|
|
152 ldy #256
|
|
153 os9 I$WritLn
|
|
154
|
|
155 * determine response
|
|
156 lda ,x
|
|
157 cmpa #'9
|
|
158 ble incoming
|
|
159
|
|
160 cmpa #'F
|
|
161 lbra ssignetpath
|
|
162
|
|
163 * get token number
|
|
164 incoming
|
|
165 lbsr DEC_BIN
|
|
166 std token,u
|
|
167 IFNE DEBUG
|
|
168 pshs d
|
|
169 lbsr PRINTS
|
|
170 fcc /Got token /
|
|
171 fcb $00
|
|
172 puls d
|
|
173 lbsr PRINT_DEC
|
|
174 lbsr PRINTS
|
|
175 fcb C$CR
|
|
176 fcb $00
|
|
177 ENDC
|
|
178
|
|
179 * skip over token number
|
|
180 IFNE DEBUG
|
|
181 lbsr PRINTS
|
|
182 fcc /To Space.../
|
|
183 fcb C$CR
|
|
184 fcb $00
|
|
185 ENDC
|
|
186 lbsr TO_SP
|
|
187 IFNE DEBUG
|
|
188 lbsr PRINTS
|
|
189 fcc /To Non-Space.../
|
|
190 fcb C$CR
|
|
191 fcb $00
|
|
192 ENDC
|
|
193 lbsr TO_NON_SP
|
|
194
|
|
195 * get port number
|
|
196 lbsr DEC_BIN
|
|
197 std targetport,u
|
|
198
|
|
199 IFNE DEBUG
|
|
200 pshs d
|
|
201 lbsr PRINTS
|
|
202 fcc /Got request for port /
|
|
203 fcb $00
|
|
204 ldd ,s
|
|
205 lbsr PRINT_DEC
|
|
206 lbsr PRINTS
|
|
207 fcb C$CR
|
|
208 fcb $00
|
|
209 puls d
|
|
210 ENDC
|
|
211
|
|
212 leax ForkProcForPort,pcr
|
|
213 lbsr ProcInetd
|
|
214 lbra ssignetpath we may want to tell server we have no app
|
|
215
|
|
216 errex os9 F$Exit
|
|
217
|
|
218
|
|
219 * Process inetd.conf file
|
|
220 *
|
|
221 * Entry: X = processor routine
|
|
222 *
|
|
223 * - open conf file
|
|
224 * - read each line and get first parameter (port number)
|
|
225 * - send it to the processor routine at x
|
|
226 * - if error or end of file, close and return
|
|
227 ProcInetd pshs x
|
|
228 leax inetdconf,pcr
|
|
229 lda #READ.
|
|
230 os9 I$Open
|
|
231 bcs adex
|
|
232 IFNE DEBUG
|
|
233 pshs d
|
|
234 lbsr PRINTS
|
|
235 fcc /Opened inetd.conf ok/
|
|
236 fcb C$CR
|
|
237 fcb $00
|
|
238 puls d
|
|
239 ENDC
|
|
240 nextline leax lbuffer,u
|
|
241 ldy #lbufferl-1
|
|
242 lbsr FGETS
|
|
243 bcs closeup
|
|
244 lbsr TO_NON_SP skip any leading spaces
|
|
245 ldb ,x check for EOL or comment
|
|
246 cmpb #C$CR
|
|
247 beq nextline
|
|
248 cmpb #'#
|
|
249 beq nextline
|
|
250 IFNE DEBUG
|
|
251 pshs d,x
|
|
252 lbsr PRINTS
|
|
253 fcc /Reading line: /
|
|
254 fcb $00
|
|
255 ldx 2,s
|
|
256 lbsr PUTS
|
|
257 puls d,x
|
|
258 ENDC
|
|
259 pshs a
|
|
260 jsr [1,s]
|
|
261 puls a
|
|
262 bcc nextline
|
|
263 closeup cmpb #E$EOF
|
|
264 bne closeandex
|
|
265 clrb
|
|
266 closeandex pshs b,cc
|
|
267 os9 I$Close
|
|
268 puls b,cc
|
|
269 adex puls x,pc
|
|
270
|
|
271
|
|
272 * Setup ports
|
|
273 * Extract first parameter at X and send to server
|
|
274 SetupPorts lbsr DEC_BIN
|
|
275 cmpd #0
|
|
276 beq ret0
|
|
277 * find comma and change it to nul
|
|
278 tfr x,y
|
|
279 setuploop lda ,y+
|
|
280 cmpa #C$CR
|
|
281 beq ret0
|
|
282 cmpa #',
|
|
283 bne setuploop
|
|
284 setuplisten
|
|
285 clr -1,y
|
|
286 IFNE DEBUG
|
|
287 pshs d,x
|
|
288 lbsr PRINTS
|
|
289 fcc /Send listen/
|
|
290 fcb C$CR
|
|
291 fcb $00
|
|
292 puls d,x
|
|
293 ENDC
|
|
294 lda netpath,u
|
|
295 lbsr TCPListen
|
|
296 ret0 rts
|
|
297
|
2578
|
298 retcc clrb
|
|
299 rts
|
|
300
|
2475
|
301 * Fork Proccess that matches target port
|
|
302 * Extract first parameter at X and see if it matches target port
|
|
303 * if so, read rest of line and fork the process
|
2579
|
304 * Line looks like this: portnumberplusoptions,prog,params,path opts
|
2475
|
305 ForkProcForPort
|
|
306 * get port number
|
|
307 lbsr DEC_BIN
|
|
308 IFNE DEBUG
|
|
309 pshs d
|
|
310 lbsr PRINTS
|
|
311 fcc /Reading port /
|
|
312 fcb $00
|
|
313 ldd ,s
|
|
314 lbsr PRINT_DEC
|
|
315 lbsr PRINTS
|
|
316 fcb C$CR
|
|
317 fcb $00
|
2578
|
318 lbsr PRINTS
|
|
319 fcc /Comparing to port /
|
|
320 fcb $00
|
|
321 ldd targetport,u
|
|
322 lbsr PRINT_DEC
|
|
323 lbsr PRINTS
|
|
324 fcb C$CR
|
|
325 fcb $00
|
2475
|
326 puls d
|
|
327 ENDC
|
|
328 cmpd targetport,u
|
2578
|
329 lbne retcc
|
2475
|
330 * point Y to byte after comma
|
|
331 portloop lda ,y+
|
|
332 cmpa #C$CR
|
|
333 beq ret0
|
|
334 cmpa #',
|
|
335 bne portloop
|
|
336 tfr y,x
|
|
337 * copy bytes up to comma at X
|
|
338 leay targetprog,u
|
|
339 prgloop lda ,x+
|
|
340 cmpa #',
|
|
341 beq sethi
|
|
342 cmpa #C$CR
|
|
343 lbeq ret
|
|
344 sta ,y+
|
|
345 bra prgloop
|
|
346 sethi lda -1,y
|
|
347 ora #$80
|
|
348 sta -1,y
|
2579
|
349 copypar clr tmodeparamlen,u
|
|
350 leay targetparams,u
|
2475
|
351 parloop lda ,x+
|
|
352 sta ,y+
|
2579
|
353 cmpa #',
|
|
354 beq procopts
|
2475
|
355 cmpa #C$CR
|
2579
|
356 beq gotprocparms
|
2475
|
357
|
2579
|
358 procopts
|
|
359 leay tmodeparams,u
|
|
360 procoptsloop lda ,x+
|
|
361 sta ,y+
|
|
362 inc targetparams,u
|
|
363 cmpa #C$CR
|
|
364 beq procoptsloop
|
|
365
|
|
366 gotprocparms
|
2475
|
367 IFNE DEBUG
|
|
368 pshs d
|
|
369 lbsr PRINTS
|
|
370 fcc /Got proc and params to fork/
|
|
371 fcb C$CR
|
|
372 fcb $00
|
|
373 puls d
|
|
374 ENDC
|
|
375
|
|
376 * ignore client port number and hostname for now
|
|
377 lbsr TCPOpen
|
|
378 bcc savechild
|
|
379
|
|
380 ldd token,u
|
|
381 leas -8,s
|
|
382 leax ,s
|
|
383 lbsr BIN_DEC
|
|
384 lda netpath,u
|
|
385 tfr x,y
|
|
386 lbsr TCPKill
|
|
387 leas 8,s
|
|
388 lbra forkex
|
|
389
|
|
390 savechild
|
|
391 sta childnetpath,u
|
|
392 ldd token,u
|
|
393 leas -8,s
|
|
394 leax ,s
|
|
395 lbsr BIN_DEC
|
|
396 lda childnetpath,u
|
|
397 tfr x,y
|
|
398 lbsr TCPJoin
|
|
399 leas 8,s
|
|
400 bcc turnonechoalf
|
|
401 os9 I$Close
|
|
402 lbra forkex
|
|
403
|
|
404 turnonechoalf
|
|
405 IFNE DEBUG
|
|
406 pshs d
|
|
407 lbsr PRINTS
|
|
408 fcc /Turning on PD.EKO and PD.ALF/
|
|
409 fcb C$CR
|
|
410 fcb $00
|
|
411 puls d
|
|
412 ENDC
|
|
413 lbsr SetEcho
|
|
414 lbcs ret
|
|
415 lbsr SetAutoLF
|
|
416 lbcs ret
|
|
417
|
|
418 * dup paths
|
|
419 duper
|
|
420 IFNE DEBUG
|
|
421 pshs d
|
|
422 lbsr PRINTS
|
|
423 fcc /Duping paths/
|
|
424 fcb C$CR
|
|
425 fcb $00
|
|
426 puls d
|
|
427 ENDC
|
|
428
|
|
429 clra
|
|
430 os9 I$Dup
|
|
431 lbcs errex
|
|
432 sta orgstdin,u
|
|
433 lda #1
|
|
434 os9 I$Dup
|
|
435 lbcs errex
|
|
436 sta orgstdout,u
|
|
437 lda #2
|
|
438 os9 I$Dup
|
|
439 lbcs errex
|
|
440 sta orgstderr,u
|
|
441
|
|
442 * close original stdin/out/err paths
|
|
443 clra
|
|
444 os9 I$Close
|
|
445 inca
|
|
446 os9 I$Close
|
|
447 inca
|
|
448 os9 I$Close
|
|
449
|
|
450 * Dup child net path to stdin/stdout/stderr
|
|
451 lda childnetpath,u
|
|
452 os9 I$Dup
|
|
453 lbcs errex
|
|
454 os9 I$Dup
|
|
455 lbcs errex
|
|
456 os9 I$Dup
|
|
457 lbcs errex
|
|
458
|
2579
|
459 * fork tmode process if tmode param length > 0
|
|
460 tst tmodeparamlen,u
|
|
461 beq forkchild
|
|
462 pshs u
|
|
463 leax tmode,pcr
|
|
464 leau tmodeparams,u
|
|
465 lda #Objct
|
|
466 clrb
|
|
467 ldy #256
|
|
468 os9 F$Fork
|
|
469 puls u
|
|
470 os9 F$Wait
|
|
471
|
2475
|
472 * fork child process
|
2579
|
473 forkchild
|
2475
|
474 pshs u
|
|
475 leax targetprog,u
|
|
476 leau targetparams,u
|
|
477 lda #Objct
|
|
478 clrb
|
|
479 ldy #256
|
|
480 os9 F$Fork
|
|
481 puls u
|
|
482 * If our F$Fork fails, do not error out...
|
|
483 * bcs ret2
|
|
484
|
|
485 * restore orginal paths
|
|
486 clra
|
|
487 os9 I$Close
|
|
488 inca
|
|
489 os9 I$Close
|
|
490 inca
|
|
491 os9 I$Close
|
|
492
|
|
493 lda orgstdin,u
|
|
494 os9 I$Dup
|
|
495 lbcs errex
|
|
496 lda orgstdout,u
|
|
497 os9 I$Dup
|
|
498 lbcs errex
|
|
499 lda orgstderr,u
|
|
500 os9 I$Dup
|
|
501 lbcs errex
|
|
502 lda orgstdin,u
|
|
503 os9 I$Close
|
|
504 lda orgstdout,u
|
|
505 os9 I$Close
|
|
506 lda orgstderr,u
|
|
507 os9 I$Close
|
|
508 lda childnetpath,u
|
|
509 os9 I$Close
|
|
510
|
|
511 IFNE DEBUG
|
|
512 pshs d
|
|
513 lbsr PRINTS
|
|
514 fcc /Proc forked/
|
|
515 fcb C$CR
|
|
516 fcb $00
|
|
517 puls d
|
|
518 ENDC
|
|
519
|
|
520 forkex comb
|
|
521 ldb #E$EOF
|
|
522 ret rts
|
|
523
|
|
524 inetdconf fcc "....../SYS/inetd.conf"
|
|
525 fcb C$CR
|
|
526 endsect
|