|
|
1.1 root 1: /* ryinitiator.c - remote association initiator */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/others/idist/RCS/ryinitiator.c,v 7.2 90/07/09 14:39:25 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/others/idist/RCS/ryinitiator.c,v 7.2 90/07/09 14:39:25 mrose Exp $
9: *
10: * Severely hacked to give embedded functionality for client.
11: *
12: * Julian Onions <[email protected]>
13: * Nottingham University Computer Science
14: *
15: *
16: * $Log: ryinitiator.c,v $
17: * Revision 7.2 90/07/09 14:39:25 mrose
18: * sync
19: *
20: * Revision 7.1 90/07/01 21:04:19 mrose
21: * pepsy
22: *
23: * Revision 7.0 89/11/23 21:58:41 mrose
24: * Release 6.0
25: *
26: */
27:
28: #include <stdio.h>
29: #include <varargs.h>
30: #include "Idist-ops.h"
31: #include "Idist-types.h"
32: #include "defs.h"
33:
34: /* DATA */
35:
36: void adios (), advise (), ros_adios (), ros_advise (),
37: acs_advise (), acs_adios ();
38:
39: char *getstring ();
40:
41: static char *myservice = "isode idist";
42:
43: static char *mycontext = "isode idist";
44: static char *mypci = "isode idist pci";
45:
46:
47: extern char *isodeversion;
48:
49: static int ryconnect ();
50:
51: /* INITIATOR */
52:
53: makeconn (thehost)
54: char *thehost;
55: {
56: int result;
57: PE data;
58: struct type_Idist_Initiate *initial;
59: char *cp;
60: char buf[BUFSIZ];
61: char ruser[128], *rhost;
62: static char lasthost[BUFSIZ];
63:
64: if (lasthost[0] != 0) {
65: if (strcmp (thehost, lasthost) == 0)
66: return 1;
67: closeconn ();
68: }
69:
70: (void) strcpy (lasthost, thehost);
71:
72: if ((initial = (struct type_Idist_Initiate *)
73: malloc (sizeof *initial)) == NULL)
74: adios ("memory", "out of");
75:
76: initial -> version = VERSION;
77:
78: if (cp = index(thehost, '@')) {
79: rhost = cp + 1;
80: (void) strncpy (ruser, thehost, cp - thehost);
81: ruser[cp - thehost] = 0;
82: }
83: else {
84: (void) strcpy (ruser, user);
85: rhost = thehost;
86: }
87: if (!qflag)
88: printf ("updating host %s\n", rhost);
89: (void) sprintf (buf, "user (%s:%s): ", rhost, ruser);
90: cp = getstring (buf);
91: if (cp == NULL)
92: cp = ruser;
93: initial -> user = str2qb (cp, strlen (cp), 1);
94:
95: (void) sprintf (buf, "password (%s:%s): ", rhost, cp);
96: cp = getpassword (buf);
97:
98: initial -> passwd = str2qb (cp, strlen(cp), 1);
99: bzero (cp, strlen (cp)); /* in case of cores */
100:
101: if (encode_Idist_Initiate (&data, 1, 0, NULLCP, initial) == NOTOK) {
102: advise (NULLCP, "Error encoding data");
103: return 0;
104: }
105: data -> pe_context = 3; /* hack */
106:
107: result = ryconnect (rhost, data, myservice, mycontext, mypci);
108:
109: free_Idist_Initiate (initial);
110:
111: return result == OK ? 1 : 0;
112: }
113:
114:
115: static int ry_sd = NOTOK;
116:
117: static int ryconnect (thehost, data, theservice, thecontext, thepci)
118: char *thehost,
119: *theservice,
120: *thecontext,
121: *thepci;
122: PE data;
123: {
124: struct SSAPref sfs;
125: register struct SSAPref *sf;
126: register struct PSAPaddr *pa;
127: struct AcSAPconnect accs;
128: register struct AcSAPconnect *acc = &accs;
129: struct AcSAPindication acis;
130: register struct AcSAPindication *aci = &acis;
131: register struct AcSAPabort *aca = &aci -> aci_abort;
132: AEI aei;
133: OID ctx,
134: pci;
135: struct PSAPctxlist pcs;
136: register struct PSAPctxlist *pc = &pcs;
137: struct RoSAPindication rois;
138: register struct RoSAPindication *roi = &rois;
139: register struct RoSAPpreject *rop = &roi -> roi_preject;
140:
141: if ((aei = _str2aei (thehost, theservice, thecontext, 0)) == NULLAEI)
142: adios (NULLCP, "unable to resolve service: %s", PY_pepy);
143: if ((pa = aei2addr (aei)) == NULLPA)
144: adios (NULLCP, "address translation failed");
145:
146: if ((ctx = ode2oid (thecontext)) == NULLOID)
147: adios (NULLCP, "%s: unknown object descriptor", thecontext);
148: if ((ctx = oid_cpy (ctx)) == NULLOID)
149: adios (NULLCP, "out of memory");
150: if ((pci = ode2oid (thepci)) == NULLOID)
151: adios (NULLCP, "%s: unknown object descriptor", thepci);
152: if ((pci = oid_cpy (pci)) == NULLOID)
153: adios (NULLCP, "out of memory");
154: pc -> pc_nctx = 1;
155: pc -> pc_ctx[0].pc_id = 1;
156: pc -> pc_ctx[0].pc_asn = pci;
157: pc -> pc_ctx[0].pc_atn = NULLOID;
158:
159: if ((sf = addr2ref (PLocalHostName ())) == NULL) {
160: sf = &sfs;
161: (void) bzero ((char *) sf, sizeof *sf);
162: }
163:
164: if (AcAssocRequest (ctx, NULLAEI, aei, NULLPA, pa, pc, NULLOID,
165: 0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, &data, 1, NULLQOS,
166: acc, aci)
167: == NOTOK)
168: acs_adios (aca, "A-ASSOCIATE.REQUEST");
169:
170: if (acc -> acc_result != ACS_ACCEPT) {
171: int slen;
172: char *str;
173:
174: if (acc -> acc_ninfo > 0 && (str = prim2str(acc->acc_info[0], &slen)))
175: adios (NULLCP, "association rejected: [%s] %*.*s",
176: AcErrString (acc -> acc_result),
177: slen, slen, str);
178: else
179: adios (NULLCP, "association rejected: [%s]",
180: AcErrString (acc -> acc_result));
181: }
182:
183: ry_sd = acc -> acc_sd;
184: ACCFREE (acc);
185:
186: if (RoSetService (ry_sd, RoPService, roi) == NOTOK)
187: ros_adios (rop, "set RO/PS fails");
188: return OK;
189: }
190:
191: closeconn ()
192: {
193: struct AcSAPrelease acrs;
194: register struct AcSAPrelease *acr = &acrs;
195: struct AcSAPindication acis;
196: register struct AcSAPindication *aci = &acis;
197: register struct AcSAPabort *aca = &aci -> aci_abort;
198:
199: if (ry_sd == NOTOK)
200: return;
201:
202: if (AcRelRequest (ry_sd, ACF_NORMAL, NULLPEP, 0, NOTOK, acr, aci) == NOTOK)
203: acs_adios (aca, "A-RELEASE.REQUEST");
204:
205: if (!acr -> acr_affirmative) {
206: (void) AcUAbortRequest (ry_sd, NULLPEP, 0, aci);
207: adios (NULLCP, "release rejected by peer: %d", acr -> acr_reason);
208: }
209:
210: ACRFREE (acr);
211: }
212:
213: /* */
214:
215: invoke (op, arg, mod, ind, rfx, efx)
216: int op;
217: modtyp *mod; /* encoding/decoding table for Idist */
218: int ind; /* index of this type in tables */
219: caddr_t arg;
220: IFP rfx, efx;
221: {
222: int result;
223: struct RoSAPindication rois;
224: register struct RoSAPindication *roi = &rois;
225: register struct RoSAPpreject *rop = &roi -> roi_preject;
226: extern int result_value;
227:
228: switch (result = RyStub (ry_sd, table_Idist_Operations, op,
229: RyGenID (ry_sd), NULLIP, arg, rfx, efx,
230: ROS_SYNC, roi)) {
231: case NOTOK: /* failure */
232: if (ROS_FATAL (rop -> rop_reason))
233: ros_adios (rop, "STUB");
234: ros_advise (rop, "STUB");
235: break;
236:
237: case OK: /* got a result/error response */
238: break;
239:
240: case DONE: /* got RO-END? */
241: adios (NULLCP, "got RO-END.INDICATION");
242: /* NOTREACHED */
243:
244: default:
245: adios (NULLCP, "unknown return from RyStub=%d", result);
246: /* NOTREACHED */
247: }
248:
249: if (mod && ind >= 0 && arg)
250: fre_obj(arg, mod->md_dtab[ind], mod);
251: return result_value;
252: }
253:
254: /* */
255:
256: /* */
257:
258: void ros_adios (rop, event)
259: register struct RoSAPpreject *rop;
260: char *event;
261: {
262: ros_advise (rop, event);
263:
264: cleanup ();
265:
266: _exit (1);
267: }
268:
269:
270: void ros_advise (rop, event)
271: register struct RoSAPpreject *rop;
272: char *event;
273: {
274: char buffer[BUFSIZ];
275:
276: if (rop -> rop_cc > 0)
277: (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason),
278: rop -> rop_cc, rop -> rop_cc, rop -> rop_data);
279: else
280: (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason));
281:
282: advise (NULLCP, "%s: %s", event, buffer);
283: }
284:
285: /* */
286:
287: void acs_adios (aca, event)
288: register struct AcSAPabort *aca;
289: char *event;
290: {
291: acs_advise (aca, event);
292:
293: cleanup ();
294: _exit (1);
295: }
296:
297:
298: void acs_advise (aca, event)
299: register struct AcSAPabort *aca;
300: char *event;
301: {
302: char buffer[BUFSIZ];
303:
304: if (aca -> aca_cc > 0)
305: (void) sprintf (buffer, "[%s] %*.*s",
306: AcErrString (aca -> aca_reason),
307: aca -> aca_cc, aca -> aca_cc, aca -> aca_data);
308: else
309: (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason));
310:
311: advise (NULLCP, "%s: %s (source %d)", event, buffer,
312: aca -> aca_source);
313: }
314:
315: /* */
316:
317: #ifndef lint
318: void _advise ();
319:
320:
321: void adios (va_alist)
322: va_dcl
323: {
324: va_list ap;
325:
326: va_start (ap);
327:
328: _advise (ap);
329:
330: cleanup ();
331:
332: va_end (ap);
333:
334: _exit (1);
335: }
336: #else
337: /* VARARGS */
338:
339: void adios (what, fmt)
340: char *what,
341: *fmt;
342: {
343: adios (what, fmt);
344: }
345: #endif
346:
347:
348: #ifndef lint
349: void advise (va_alist)
350: va_dcl
351: {
352: va_list ap;
353:
354: va_start (ap);
355:
356: _advise (ap);
357:
358: va_end (ap);
359: }
360:
361:
362: static void _advise (ap)
363: va_list ap;
364: {
365: char buffer[BUFSIZ];
366:
367: asprintf (buffer, ap);
368:
369: (void) fflush (stdout);
370:
371: fprintf (stderr, "%s: ", myname);
372: (void) fputs (buffer, stderr);
373: (void) fputc ('\n', stderr);
374:
375: (void) fflush (stderr);
376: }
377: #else
378: /* VARARGS */
379:
380: void advise (what, fmt)
381: char *what,
382: *fmt;
383: {
384: advise (what, fmt);
385: }
386: #endif
387:
388:
389: #ifndef lint
390: void ryr_advise (va_alist)
391: va_dcl
392: {
393: va_list ap;
394:
395: va_start (ap);
396:
397: _advise (ap);
398:
399: va_end (ap);
400: }
401: #else
402: /* VARARGS */
403:
404: void ryr_advise (what, fmt)
405: char *what,
406: *fmt;
407: {
408: ryr_advise (what, fmt);
409: }
410: #endif
411:
412: char *getstring (prompt)
413: char *prompt;
414: {
415: static char buffer[BUFSIZ];
416: char *cp;
417:
418: fputs (prompt, stdout);
419: (void) fflush (stdout);
420:
421: if (fgets (buffer, sizeof buffer, stdin) == NULL)
422: return NULLCP;
423:
424: if (cp = index (buffer, '\n'))
425: *cp = '\0';
426: if (buffer[0] == '\0')
427: return NULLCP;
428: return buffer;
429: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.