BSD 4_3_Net_2 development
[unix-history] / usr / src / contrib / isode / imisc / imisc.c
CommitLineData
0f910683
C
1/* imisc.c - miscellaneous network service -- initiator */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/imisc/RCS/imisc.c,v 7.3 91/02/22 09:26:17 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/imisc/RCS/imisc.c,v 7.3 91/02/22 09:26:17 mrose Interim $
9 *
10 *
11 * $Log: imisc.c,v $
12 * Revision 7.3 91/02/22 09:26:17 mrose
13 * Interim 6.8
14 *
15 * Revision 7.2 90/07/09 14:38:45 mrose
16 * sync
17 *
18 * Revision 7.1 90/07/01 21:04:02 mrose
19 * pepsy
20 *
21 * Revision 7.0 89/11/23 21:57:35 mrose
22 * Release 6.0
23 *
24 */
25
26/*
27 * NOTICE
28 *
29 * Acquisition, use, and distribution of this module and related
30 * materials are subject to the restrictions of a license agreement.
31 * Consult the Preface in the User's Manual for the full terms of
32 * this agreement.
33 *
34 */
35
36
37#include <ctype.h>
38#include <stdio.h>
39#include <pwd.h>
40#include "ryinitiator.h" /* for generic interactive initiators */
41#include "IMISC-ops.h" /* IMISC operation definitions */
42#include "IMISC-types.h" /* IMISC type definitions */
43
44
45#ifdef SYS5
46struct passwd *getpwuid ();
47#endif
48
49/* \f DATA */
50
51static char *myservice = "isode miscellany";/* should be something other
52 than mycontext */
53
54static char *mycontext = "isode miscellany";
55static char *mypci = "isode miscellany pci";
56
57
58extern int length;
59static type_IMISC_Data *data = NULLPE;
60
61 /* TYPES */
62struct type_IMISC_IA5List *vec2ia5list ();
63
64
65 /* ARGUMENTS */
66int do_finger (), do_tell (), do_data (), do_help (), do_quit ();
67
68
69 /* RESULTS */
70#define gentime_result utctime_result
71
72int utctime_result (), timeofday_result (), ia5_result (), tell_result (),
73 null_result (), echo_result ();
74
75 /* ERRORS */
76int imisc_error ();
77
78
79static struct dispatch dispatches[] = {
80 "utctime", operation_IMISC_utcTime,
81 NULLIFP, NULL, 0,
82 utctime_result, imisc_error,
83 "the universal time",
84
85 "gentime", operation_IMISC_genTime,
86 NULLIFP, NULL, 0,
87 gentime_result, imisc_error,
88 "the generalized time",
89
90 "time", operation_IMISC_timeOfDay,
91 NULLIFP, NULL, 0,
92 timeofday_result, imisc_error,
93 "the current time since the epoch",
94
95 "users", operation_IMISC_users,
96 NULLIFP, NULL, 0,
97 ia5_result, imisc_error,
98 "the users logged in on the system",
99
100 "chargen", operation_IMISC_charGen,
101 NULLIFP, NULL, 0,
102 ia5_result, imisc_error,
103 "the character generation pattern",
104
105 "qotd", operation_IMISC_qotd,
106 NULLIFP, NULL, 0,
107 ia5_result, imisc_error,
108 "the quote of the day",
109
110 "finger", operation_IMISC_finger,
111 do_finger, &_ZIMISC_mod, _ZIA5ListIMISC,
112 ia5_result, imisc_error,
113 "the finger of users logged in",
114
115 "pwdgen", operation_IMISC_pwdGen,
116 NULLIFP, NULL, 0,
117 ia5_result, imisc_error,
118 "some pseudo-randomly generated passwords",
119
120 "tell", operation_IMISC_tellUser,
121 do_tell, &_ZIMISC_mod, _ZIA5ListIMISC,
122 tell_result, imisc_error,
123 "send a message to a remote user",
124
125 "ping", operation_IMISC_ping,
126 NULLIFP, NULL, 0,
127 null_result, imisc_error,
128 "ping responder",
129
130 "sink", operation_IMISC_sink,
131 do_data, NULL, 0,
132 null_result, imisc_error,
133 "sink data",
134
135 "echo", operation_IMISC_echo,
136 do_data, NULL, 0,
137 echo_result, imisc_error,
138 "echo data",
139
140 "help", 0,
141 do_help, NULL, 0,
142 NULLIFP, NULLIFP,
143 "print this information",
144
145 "quit", 0,
146 do_quit, NULL, 0,
147 NULLIFP, NULLIFP,
148 "terminate the association and exit",
149
150 NULL
151};
152
153
154char *ctime ();
155
156/* \f MAIN */
157
158/* ARGSUSED */
159
160main (argc, argv, envp)
161int argc;
162char **argv,
163 **envp;
164{
165 ryinitiator (argc, argv, myservice, mycontext, mypci,
166 table_IMISC_Operations, dispatches, do_quit);
167
168 exit (0); /* NOTREACHED */
169}
170
171/* \f TYPES */
172
173struct type_IMISC_IA5List *vec2ia5list (vec)
174char **vec;
175{
176 struct type_IMISC_IA5List *ia5;
177 register struct type_IMISC_IA5List **ia5p;
178
179 ia5 = NULL;
180 ia5p = &ia5;
181
182 for (; *vec; vec++) {
183 if ((*ia5p = (struct type_IMISC_IA5List *) calloc (1, sizeof **ia5p))
184 == NULL)
185 adios (NULLCP, "out of memory");
186
187 if (((*ia5p) -> IA5String = str2qb (*vec, strlen (*vec), 1)) == NULL)
188 adios (NULLCP, "out of memory");
189
190 ia5p = &((*ia5p) -> next);
191 }
192
193 return ia5;
194}
195
196/* \f */
197
198static print_ia5list (ia5)
199register struct type_IMISC_IA5List *ia5;
200{
201 register struct qbuf *p,
202 *q;
203
204 for (; ia5; ia5 = ia5 -> next) {
205 p = ia5 -> IA5String;
206 for (q = p -> qb_forw; q != p ; q = q -> qb_forw)
207 printf ("%*.*s", q -> qb_len, q -> qb_len, q -> qb_data);
208 printf ("\n");
209 }
210}
211
212/* \f ARGUMENTS */
213
214/* ARGSUSED */
215
216static int do_finger (sd, ds, args, ia5)
217int sd;
218struct dispatch *ds;
219char **args;
220struct type_IMISC_IA5List **ia5;
221{
222 *ia5 = vec2ia5list (args);
223
224 return OK;
225}
226
227/* \f */
228
229/* ARGSUSED */
230
231static int do_tell (sd, ds, args, ia5)
232int sd;
233struct dispatch *ds;
234char **args;
235register struct type_IMISC_IA5List **ia5;
236{
237 char *cp,
238 *dp,
239 buffer[BUFSIZ];
240 register struct type_IMISC_IA5List *ia52;
241 register struct passwd *pw;
242
243 if (args[0] == NULL || args[1] == NULL) {
244 advise (NULLCP, "usage: tell user message ...");
245 return NOTOK;
246 }
247
248 *ia5 = vec2ia5list (args);
249
250 cp = (pw = getpwuid (getuid ())) ? pw -> pw_name : "anon";
251 dp = PLocalHostName ();
252
253 if ((ia52 = (struct type_IMISC_IA5List *) calloc (1, sizeof *ia52))
254 == NULL)
255 adios (NULLCP, "out of memory");
256 (void) sprintf (buffer, "%s@%s", cp, dp);
257 if ((ia52 -> IA5String = str2qb (buffer, strlen (buffer), 1)) == NULL)
258 adios (NULLCP, "out of memory");
259
260/* kludge this arg onto front of list - HACK ATTACK */
261 ia52 -> next = *ia5;
262 *ia5 = ia52;
263
264 return OK;
265}
266
267/* \f */
268
269/* ARGSUSED */
270
271static int do_data (sd, ds, args, pep)
272int sd;
273struct dispatch *ds;
274char **args;
275register struct type_IMISC_Data **pep;
276{
277 char *cp;
278
279 if (data == NULLPE) {
280 if (length > 0) {
281 if ((cp = malloc ((unsigned) length)) == NULL)
282 adios (NULLCP, "no memory");
283 }
284 else
285 cp = NULL;
286 if ((data = oct2prim (cp, length)) == NULLPE)
287 adios (NULLCP, "no memory");
288 if (cp)
289 free (cp);
290 }
291
292 *pep = data;
293 return OK;
294}
295
296/* \f */
297
298/* ARGSUSED */
299
300static int do_help (sd, ds, args, dummy)
301int sd;
302register struct dispatch *ds;
303char **args;
304caddr_t *dummy;
305{
306 printf ("\nCommands are:\n");
307 for (ds = dispatches; ds -> ds_name; ds++)
308 printf ("%s\t%s\n", ds -> ds_name, ds -> ds_help);
309
310 return NOTOK;
311}
312
313/* \f */
314
315/* ARGSUSED */
316
317static int do_quit (sd, ds, args, dummy)
318int sd;
319struct dispatch *ds;
320char **args;
321caddr_t *dummy;
322{
323 struct AcSAPrelease acrs;
324 register struct AcSAPrelease *acr = &acrs;
325 struct AcSAPindication acis;
326 register struct AcSAPindication *aci = &acis;
327 register struct AcSAPabort *aca = &aci -> aci_abort;
328
329 if (AcRelRequest (sd, ACF_NORMAL, NULLPEP, 0, NOTOK, acr, aci) == NOTOK)
330 acs_adios (aca, "A-RELEASE.REQUEST");
331
332 if (!acr -> acr_affirmative) {
333 (void) AcUAbortRequest (sd, NULLPEP, 0, aci);
334 adios (NULLCP, "release rejected by peer: %d", acr -> acr_reason);
335 }
336
337 ACRFREE (acr);
338
339 exit (0);
340}
341
342/* \f RESULTS */
343
344/* ARGSUSED */
345
346static int utctime_result (sd, id, dummy, result, roi)
347int sd,
348 id,
349 dummy;
350register struct type_IMISC_UTCResult *result;
351struct RoSAPindication *roi;
352{
353 register struct qbuf *q;
354
355 for (q = result -> qb_forw; q != result; q = q -> qb_forw)
356 printf ("%*.*s", q -> qb_len, q -> qb_len, q -> qb_data);
357 printf ("\n");
358
359 return OK;
360}
361
362/* \f */
363
364/* ARGSUSED */
365
366static int timeofday_result (sd, id, dummy, result, roi)
367int sd,
368 id,
369 dummy;
370register struct type_IMISC_TimeResult *result;
371struct RoSAPindication *roi;
372{
373 long s;
374
375 s = result -> parm - 2208988800L; /* UNIX epoch */
376 printf ("%s", ctime (&s));
377
378 return OK;
379}
380
381/* \f */
382
383/* ARGSUSED */
384
385static int ia5_result (sd, id, dummy, result, roi)
386int sd,
387 id,
388 dummy;
389register struct type_IMISC_IA5List *result;
390struct RoSAPindication *roi;
391{
392 print_ia5list (result);
393
394 return OK;
395}
396
397/* \f */
398
399/* ARGSUSED */
400
401static int tell_result (sd, id, dummy, result, roi)
402int sd,
403 id,
404 dummy;
405caddr_t result;
406struct RoSAPindication *roi;
407{
408 printf ("told.\n");
409
410 return OK;
411}
412
413/* \f */
414
415/* ARGSUSED */
416
417static int null_result (sd, id, dummy, result, roi)
418int sd,
419 id,
420 dummy;
421caddr_t result;
422struct RoSAPindication *roi;
423{
424 return OK;
425}
426
427/* \f */
428
429/* ARGSUSED */
430
431static int echo_result (sd, id, dummy, result, roi)
432int sd,
433 id,
434 dummy;
435struct type_IMISC_Data *result;
436struct RoSAPindication *roi;
437{
438 if (pe_cmp (result, data))
439 advise (NULLCP, "data mismatch");
440
441 return OK;
442}
443
444/* \f ERRORS */
445
446/* ARGSUSED */
447
448static int imisc_error (sd, id, error, parameter, roi)
449int sd,
450 id,
451 error;
452register struct type_IMISC_IA5List *parameter;
453struct RoSAPindication *roi;
454{
455 register struct RyError *rye;
456
457 if (error == RY_REJECT) {
458 advise (NULLCP, "%s", RoErrString ((int) parameter));
459 return OK;
460 }
461
462 if (rye = finderrbyerr (table_IMISC_Errors, error))
463 advise (NULLCP, "%s", rye -> rye_name);
464 else
465 advise (NULLCP, "Error %d", error);
466
467 if (parameter)
468 print_ia5list (parameter);
469
470 return OK;
471}