-
Notifications
You must be signed in to change notification settings - Fork 0
/
rshd.148
150 lines (123 loc) · 3.21 KB
/
rshd.148
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* RSHD.C -- Phil Budne @ BostonU / Distributed Systems
* BSD Un*x style remote shell daemon for Twenex
*
* (c) 1986 Boston University.
* Permission granted to copy for non-profit use.
*
* Written using UTAH PCC-20. Link with RSHLIB.
*
* Scenario:
* Wait for connection, then spawn a new job loaded with RSHSRV,
* NLI with the CJ%LWP (BU -- login without password).
*/
# include "pcc:stdio.h"
# include "pcc:tops20.h"
# include "pcc:mon_files.h"
# include "pcc:mon_fork.h"
# include "mon_crjob.h"
main() {
int jfn;
epcap(FHslf,-1); /* wheel up */
for( ; ; ) {
jfn = srvjfn(); /* wait for connect */
if( jfn < 0 ) {
perror("could not get jfn");
exit(1);
} /* could not open server */
worker(jfn);
} /* forever */
} /* main */
worker(jfn)
int jfn;
{
char foreign[30];
int host, sock;
if( (sock = get_fsock(jfn)) > 1023 || (host = get_fhost(jfn)) < 0 ||
hostname(foreign, host) < 0 )
return( punt(jfn,"Permission denied.") );
printf("RSHD: contact from %s, port %d\n", foreign, sock);
if( makjob(jfn, "SYSTEM:RSHSRV.EXE") < 0 )
printf("could not create job");
} /* worker */
/*
* jfn jfn of TCP: connection
* prog name of .EXE file or NULL
*/
int makjob(jfn, prog)
char *prog;
int jfn;
{
int tvt, job;
int crjblk[015], acs[5];
register int i;
for( i = 0; i < sizeof( crjblk ); i++ )
crjblk[i] = 0;
/* wait 'till attached, load file, give my caps, login w/o password */
ac1 = Value(CJ_wta) | Value(CJ_fil) | Value(CJ_cap) | Value(CJ_lwp);
ac2 = (int) crjblk;
crjblk[CJfil] = POINT(prog); /* BP to program to load */
crjblk[CJtty] = NUlio; /* new job is detached */
if( JSYS(JScrjob,acs) == JSerr )
return( punt(jfn, "Could not create job") );
job = ac1; /* save job number */
tvt = maktvt(jfn); /* convert jfn to tvt */
if( tvt < 0 ) {
logout(job); /* could not create TVT, kill job */
return( punt(jfn, "Could not create net virtual terminal") );
} /* maktvt failed */
ac1 = job | (0100000 << 18); /* AT%TRM */
ac2 = 0;
ac3 = 0;
ac4 = tvt;
if( JSYS(JSatach,acs) == JSerr ) { /* attach job to terminal */
ac1 = job; /* failed!! */
JSYS(JSlgout,acs); /* blast job */
return( -1 ); /* no way to send error text!! */
} /* atach failed */
return( job );
} /* makjob */
int maktvt(jfn)
int jfn;
{
int nvtdes, acs[5];
acs[1] = jfn;
if( JSYS(JSatnvt,acs) == JSerr )
return( -1 );
nvtdes = acs[1];
if( JSYS(JSrfmod,acs) == JSerr )
return( nvtdes );
acs[2] |= 040000<<18; /* set TT%LCA */
JSYS(JSstpar,acs);
acs[1] = nvtdes;
acs[2] = 031; /* .MOSLW - set width */
acs[3] = 0; /* to zero */
JSYS(JSmtopr,acs);
return( nvtdes );
}
int get_fsocket(jfn)
int jfn;
{
int acs[5];
ac1 = jfn;
if( JSYS(JSgdsts,acs) == JSerr )
return( 0377777777777 ); /* +INF as local socket */
else
return( ac4 );
} /* get_fsocket */
int get_fhost(jfn)
int jfn;
{
int acs[5];
ac1 = jfn;
if( JSYS(JSgdsts,acs) == JSerr )
return( -1 );
else
return( ac3 );
} /* get_fhost */
int srvjfn() {
return( trytcp( "TCP:514\026#;CONNECT:PASSIVE" ) );
} /* srvjfn */
/** Local Modes: * */
/** Comment Column:40 * */
/** End: * */