home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / osi / isode / dosisode / DOSISODE80.ZIP / ISODE8.WRK / IMISC / IMISC.C_N next >
Encoding:
Text File  |  1991-12-18  |  9.3 KB  |  464 lines

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