Commit | Line | Data |
---|---|---|
a0be6343 WJ |
1 | /* ssapexec.c - SPM: exec */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/ssap/RCS/ssapexec.c,v 7.1 91/02/22 09:45:46 mrose Interim $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/ssap/RCS/ssapexec.c,v 7.1 91/02/22 09:45:46 mrose Interim $ | |
9 | * | |
10 | * | |
11 | * $Log: ssapexec.c,v $ | |
12 | * Revision 7.1 91/02/22 09:45:46 mrose | |
13 | * Interim 6.8 | |
14 | * | |
15 | * Revision 7.0 89/11/23 22:25:26 mrose | |
16 | * Release 6.0 | |
17 | * | |
18 | */ | |
19 | ||
20 | /* | |
21 | * NOTICE | |
22 | * | |
23 | * Acquisition, use, and distribution of this module and related | |
24 | * materials are subject to the restrictions of a license agreement. | |
25 | * Consult the Preface in the User's Manual for the full terms of | |
26 | * this agreement. | |
27 | * | |
28 | */ | |
29 | ||
30 | ||
31 | /* LINTLIBRARY */ | |
32 | ||
33 | #include <stdio.h> | |
34 | #include "spkt.h" | |
35 | #include "isoservent.h" | |
36 | #include "tailor.h" | |
37 | ||
38 | /* \f SERVER only */ | |
39 | ||
40 | int SExec (ts, si, hook, setperms) | |
41 | struct TSAPstart *ts; | |
42 | struct SSAPindication *si; | |
43 | IFP hook, | |
44 | setperms; | |
45 | { | |
46 | int sd; | |
47 | char *cp; | |
48 | register struct isoservent *is; | |
49 | register struct ssapkt *s; | |
50 | struct TSAPdata txs; | |
51 | register struct TSAPdata *tx = &txs; | |
52 | struct TSAPdisconnect tds; | |
53 | register struct TSAPdisconnect *td = &tds; | |
54 | ||
55 | if (TReadRequest (sd = ts -> ts_sd, tx, NOTOK, td) == NOTOK) | |
56 | return ts2sslose (si, "TReadRequest", td); | |
57 | ||
58 | s = tsdu2spkt (&tx -> tx_qbuf, tx -> tx_cc, NULLIP); | |
59 | TXFREE (tx); | |
60 | ||
61 | if (s == NULL || s -> s_errno != SC_ACCEPT) { | |
62 | (void) spktlose (sd, si, (s ? s -> s_errno : SC_CONGEST) | SC_REFUSE, | |
63 | NULLCP, NULLCP); | |
64 | goto out1; | |
65 | } | |
66 | ||
67 | switch (s -> s_code) { | |
68 | case SPDU_CN: | |
69 | if ((s -> s_mask & SMASK_CN_VRSN) | |
70 | && !(s -> s_cn_version & SB_ALLVRSNS)) { | |
71 | (void) spktlose (sd, si, SC_VERSION | SC_REFUSE, NULLCP, | |
72 | "version mismatch: expecting 0x%x, got 0x%x", | |
73 | SB_ALLVRSNS, s -> s_cn_version); | |
74 | break; | |
75 | } | |
76 | ||
77 | if ((s -> s_mask & SMASK_CN_CALLED) && s -> s_calledlen > 0) { | |
78 | if ((is = getisoserventbyselector ("ssap", s -> s_called, | |
79 | s -> s_calledlen)) == NULL) { | |
80 | char buffer[BUFSIZ]; | |
81 | ||
82 | buffer[explode (buffer, (u_char *) s -> s_called, | |
83 | s -> s_calledlen)] = NULL; | |
84 | (void) spktlose (sd, si, SC_SSAPID | SC_REFUSE, NULLCP, | |
85 | "ISO service ssap/%s not found", buffer); | |
86 | break; | |
87 | } | |
88 | } | |
89 | else | |
90 | if ((is = getisoserventbyname ("presentation", "ssap")) | |
91 | == NULL) { | |
92 | (void) spktlose (sd, si, SC_SSUSER | SC_REFUSE, NULLCP, | |
93 | "default presentation service not found"); | |
94 | break; | |
95 | } | |
96 | ||
97 | if (TSaveState (sd, is -> is_tail, td) == NOTOK) { | |
98 | (void) spktlose (sd, si, SC_CONGEST | SC_REFUSE, NULLCP, | |
99 | NULLCP); | |
100 | break; | |
101 | } | |
102 | cp = *is -> is_tail++; | |
103 | if ((*is -> is_tail++ = spkt2str (s)) == NULL) { | |
104 | (void) spktlose (sd, si, SC_CONGEST | SC_REFUSE, NULLCP, | |
105 | NULLCP); | |
106 | break; | |
107 | } | |
108 | *is -> is_tail = NULL; | |
109 | ||
110 | switch (hook ? (*hook) (is, si) : OK) { | |
111 | case NOTOK: | |
112 | return NOTOK; | |
113 | ||
114 | case DONE: | |
115 | return OK; | |
116 | ||
117 | case OK: | |
118 | default: | |
119 | if (setperms) | |
120 | (void) (*setperms) (is); | |
121 | (void) execv (*is -> is_vec, is -> is_vec); | |
122 | SLOG (ssap_log, LLOG_FATAL, *is -> is_vec, | |
123 | ("unable to exec")); | |
124 | (void) TRestoreState (cp, ts, td); | |
125 | (void) spktlose (ts -> ts_sd, si, SC_CONGEST | SC_REFUSE, | |
126 | *is -> is_vec, "unable to exec"); | |
127 | break; | |
128 | } | |
129 | break; | |
130 | ||
131 | default: | |
132 | (void) spktlose (sd, si, SC_PROTOCOL | SC_REFUSE, NULLCP, | |
133 | "session protocol mangled: expecting 0x%x, got 0x%x", | |
134 | SPDU_CN, s -> s_code); | |
135 | break; | |
136 | } | |
137 | ||
138 | out1: ; | |
139 | freespkt (s); | |
140 | ||
141 | return NOTOK; | |
142 | } |