|
|
1.1 root 1: /* ryinitiator.c - generic interactive initiator */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/others/lookup/RCS/ryinitiator.c,v 7.2 90/07/09 14:39:53 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/others/lookup/RCS/ryinitiator.c,v 7.2 90/07/09 14:39:53 mrose Exp $
9: *
10: *
11: * $Log: ryinitiator.c,v $
12: * Revision 7.2 90/07/09 14:39:53 mrose
13: * sync
14: *
15: * Revision 7.1 90/07/01 21:04:28 mrose
16: * pepsy
17: *
18: * Revision 7.0 89/11/23 22:56:41 mrose
19: * Release 6.0
20: *
21: */
22:
23: /*
24: * NOTICE
25: *
26: * Acquisition, use, and distribution of this module and related
27: * materials are subject to the restrictions of a license agreement.
28: * Consult the Preface in the User's Manual for the full terms of
29: * this agreement.
30: *
31: */
32:
33:
34: #include <stdio.h>
35: #include <varargs.h>
36: #include "PasswordLookup-types.h"
37: #include "ryinitiator.h"
38:
39: /* DATA */
40:
41: static char *myname = "ryinitiator";
42:
43:
44: extern char *isodeversion;
45:
46: /* INITIATOR */
47:
48: ryinitiator (argc, argv, myservice, mycontext, mypci, ops, dispatches, quit)
49: int argc;
50: char **argv,
51: *myservice,
52: *mycontext,
53: *mypci;
54: struct RyOperation ops[];
55: struct dispatch *dispatches;
56: IFP quit;
57: {
58: int iloop,
59: sd;
60: char buffer[BUFSIZ],
61: *vec[NVEC + 1];
62: register struct dispatch *ds;
63: struct SSAPref sfs;
64: register struct SSAPref *sf;
65: register struct PSAPaddr *pa;
66: struct AcSAPconnect accs;
67: register struct AcSAPconnect *acc = &accs;
68: struct AcSAPindication acis;
69: register struct AcSAPindication *aci = &acis;
70: register struct AcSAPabort *aca = &aci -> aci_abort;
71: AEI aei;
72: OID ctx,
73: pci;
74: struct PSAPctxlist pcs;
75: register struct PSAPctxlist *pc = &pcs;
76: struct RoSAPindication rois;
77: register struct RoSAPindication *roi = &rois;
78: register struct RoSAPpreject *rop = &roi -> roi_preject;
79:
80: if (myname = rindex (argv[0], '/'))
81: myname++;
82: if (myname == NULL || *myname == NULL)
83: myname = argv[0];
84:
85: if (argc < 2)
86: adios (NULLCP, "usage: %s host [operation [ arguments ... ]]", myname);
87:
88: if ((aei = _str2aei (argv[1], myservice, mycontext, 0)) == NULLAEI)
89: adios (NULLCP, "unable to resolve service: %s", PY_pepy);
90: if ((pa = aei2addr (aei)) == NULLPA)
91: adios (NULLCP, "address translation failed");
92:
93: if ((ctx = ode2oid (mycontext)) == NULLOID)
94: adios (NULLCP, "%s: unknown object descriptor", mycontext);
95: if ((ctx = oid_cpy (ctx)) == NULLOID)
96: adios (NULLCP, "out of memory");
97: if ((pci = ode2oid (mypci)) == NULLOID)
98: adios (NULLCP, "%s: unknown object descriptor", mypci);
99: if ((pci = oid_cpy (pci)) == NULLOID)
100: adios (NULLCP, "out of memory");
101: pc -> pc_nctx = 1;
102: pc -> pc_ctx[0].pc_id = 1;
103: pc -> pc_ctx[0].pc_asn = pci;
104: pc -> pc_ctx[0].pc_atn = NULLOID;
105:
106: if ((sf = addr2ref (PLocalHostName ())) == NULL) {
107: sf = &sfs;
108: (void) bzero ((char *) sf, sizeof *sf);
109: }
110:
111: if (argc < 3) {
112: printf ("%s", myname);
113: if (sf -> sr_ulen > 2)
114: printf (" running on host %s", sf -> sr_udata + 2);
115: if (sf -> sr_clen > 2)
116: printf (" at %s", sf -> sr_cdata + 2);
117: printf (" [%s, ", oid2ode (ctx));
118: printf ("%s]\n", oid2ode (pci));
119: printf ("using %s\n", isodeversion);
120:
121: printf ("%s... ", argv[1]);
122: (void) fflush (stdout);
123:
124: iloop = 1;
125: }
126: else {
127: for (ds = dispatches; ds -> ds_name; ds++)
128: if (strcmp (ds -> ds_name, argv[2]) == 0)
129: break;
130: if (ds -> ds_name == NULL)
131: adios (NULLCP, "unknown operation \"%s\"", argv[2]);
132:
133: iloop = 0;
134: }
135:
136: if (AcAssocRequest (ctx, NULLAEI, aei, NULLPA, pa, pc, NULLOID,
137: 0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, NULLPEP, 0, NULLQOS,
138: acc, aci)
139: == NOTOK)
140: acs_adios (aca, "A-ASSOCIATE.REQUEST");
141:
142: if (acc -> acc_result != ACS_ACCEPT) {
143: if (iloop)
144: printf ("failed\n");
145:
146: adios (NULLCP, "association rejected: [%s]",
147: AcErrString (acc -> acc_result));
148: }
149: if (iloop) {
150: printf ("connected\n");
151: (void) fflush (stdout);
152: }
153:
154: sd = acc -> acc_sd;
155: ACCFREE (acc);
156:
157: if (RoSetService (sd, RoPService, roi) == NOTOK)
158: ros_adios (rop, "set RO/PS fails");
159:
160: if (iloop) {
161: for (;;) {
162: if (getline (buffer) == NOTOK)
163: break;
164:
165: if (str2vec (buffer, vec) < 1)
166: continue;
167:
168: for (ds = dispatches; ds -> ds_name; ds++)
169: if (strcmp (ds -> ds_name, vec[0]) == 0)
170: break;
171: if (ds -> ds_name == NULL) {
172: advise (NULLCP, "unknown operation \"%s\"", vec[0]);
173: continue;
174: }
175:
176: invoke (sd, ops, ds, vec + 1);
177: }
178: }
179: else
180: invoke (sd, ops, ds, argv + 3);
181:
182: (*quit) (sd, (struct dispatch *) NULL, (char **) NULL, (caddr_t *) NULL);
183: }
184:
185: /* */
186:
187: static invoke (sd, ops, ds, args)
188: int sd;
189: struct RyOperation ops[];
190: register struct dispatch *ds;
191: char **args;
192: {
193: int result;
194: caddr_t in;
195: struct RoSAPindication rois;
196: register struct RoSAPindication *roi = &rois;
197: register struct RoSAPpreject *rop = &roi -> roi_preject;
198:
199: in = NULL;
200: if (ds -> ds_argument && (*ds -> ds_argument) (sd, ds, args, &in) == NOTOK)
201: return;
202:
203: switch (result = RyStub (sd, ops, ds -> ds_operation, RyGenID (sd), NULLIP,
204: in, ds -> ds_result, ds -> ds_error, ROS_SYNC,
205: roi)) {
206: case NOTOK: /* failure */
207: if (ROS_FATAL (rop -> rop_reason))
208: ros_adios (rop, "STUB");
209: ros_advise (rop, "STUB");
210: break;
211:
212: case OK: /* got a result/error response */
213: break;
214:
215: case DONE: /* got RO-END? */
216: adios (NULLCP, "got RO-END.INDICATION");
217: /* NOTREACHED */
218:
219: default:
220: adios (NULLCP, "unknown return from RyStub=%d", result);
221: /* NOTREACHED */
222: }
223:
224: if (ds -> ds_mod && ds -> ds_ind >= 0 && in)
225: (void)fre_obj(in, ds->ds_mod->md_dtab[ds->ds_ind], ds->ds_mod);
226: }
227:
228: /* */
229:
230: static int getline (buffer)
231: char *buffer;
232: {
233: register int i;
234: register char *cp,
235: *ep;
236: static int sticky = 0;
237:
238: if (sticky) {
239: sticky = 0;
240: return NOTOK;
241: }
242:
243: printf ("%s> ", myname);
244: (void) fflush (stdout);
245:
246: for (ep = (cp = buffer) + BUFSIZ - 1; (i = getchar ()) != '\n';) {
247: if (i == EOF) {
248: printf ("\n");
249: clearerr (stdin);
250: if (cp != buffer) {
251: sticky++;
252: break;
253: }
254:
255: return NOTOK;
256: }
257:
258: if (cp < ep)
259: *cp++ = i;
260: }
261: *cp = NULL;
262:
263: return OK;
264: }
265:
266: /* */
267:
268: void ros_adios (rop, event)
269: register struct RoSAPpreject *rop;
270: char *event;
271: {
272: ros_advise (rop, event);
273:
274: _exit (1);
275: }
276:
277:
278: void ros_advise (rop, event)
279: register struct RoSAPpreject *rop;
280: char *event;
281: {
282: char buffer[BUFSIZ];
283:
284: if (rop -> rop_cc > 0)
285: (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason),
286: rop -> rop_cc, rop -> rop_cc, rop -> rop_data);
287: else
288: (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason));
289:
290: advise (NULLCP, "%s: %s", event, buffer);
291: }
292:
293: /* */
294:
295: void acs_adios (aca, event)
296: register struct AcSAPabort *aca;
297: char *event;
298: {
299: acs_advise (aca, event);
300:
301: _exit (1);
302: }
303:
304:
305: void acs_advise (aca, event)
306: register struct AcSAPabort *aca;
307: char *event;
308: {
309: char buffer[BUFSIZ];
310:
311: if (aca -> aca_cc > 0)
312: (void) sprintf (buffer, "[%s] %*.*s",
313: AcErrString (aca -> aca_reason),
314: aca -> aca_cc, aca -> aca_cc, aca -> aca_data);
315: else
316: (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason));
317:
318: advise (NULLCP, "%s: %s (source %d)", event, buffer,
319: aca -> aca_source);
320: }
321:
322: /* */
323:
324: #ifndef lint
325: void _advise ();
326:
327:
328: void adios (va_alist)
329: va_dcl
330: {
331: va_list ap;
332:
333: va_start (ap);
334:
335: _advise (ap);
336:
337: va_end (ap);
338:
339: _exit (1);
340: }
341: #else
342: /* VARARGS */
343:
344: void adios (what, fmt)
345: char *what,
346: *fmt;
347: {
348: adios (what, fmt);
349: }
350: #endif
351:
352:
353: #ifndef lint
354: void advise (va_alist)
355: va_dcl
356: {
357: va_list ap;
358:
359: va_start (ap);
360:
361: _advise (ap);
362:
363: va_end (ap);
364: }
365:
366:
367: static void _advise (ap)
368: va_list ap;
369: {
370: char buffer[BUFSIZ];
371:
372: asprintf (buffer, ap);
373:
374: (void) fflush (stdout);
375:
376: fprintf (stderr, "%s: ", myname);
377: (void) fputs (buffer, stderr);
378: (void) fputc ('\n', stderr);
379:
380: (void) fflush (stderr);
381: }
382: #else
383: /* VARARGS */
384:
385: void advise (what, fmt)
386: char *what,
387: *fmt;
388: {
389: advise (what, fmt);
390: }
391: #endif
392:
393:
394: #ifndef lint
395: void ryr_advise (va_alist)
396: va_dcl
397: {
398: va_list ap;
399:
400: va_start (ap);
401:
402: _advise (ap);
403:
404: va_end (ap);
405: }
406: #else
407: /* VARARGS */
408:
409: void ryr_advise (what, fmt)
410: char *what,
411: *fmt;
412: {
413: ryr_advise (what, fmt);
414: }
415: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.