Annotation of 43BSDReno/contrib/isode-beta/imisc/imisc.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.