Annotation of 43BSDReno/contrib/isode-beta/doc/manual/passwd-init.c, revision 1.1

1.1     ! root        1: /* lookup.c - password lookup service -- initiator */
        !             2: 
        !             3: #include <stdio.h>
        !             4: #include "ryinitiator.h"               /* for generic interctive initiators */
        !             5: #include "PasswordLookup-ops.h"                /* operation definitions */
        !             6: #include "PasswordLookup-types.h"      /* type definitions */
        !             7: 
        !             8: /* DATA */
        !             9: 
        !            10: static char *myservice = "passwdstore";
        !            11: 
        !            12: static char *mycontext = "isode passwd lookup demo";
        !            13: static char *mypci = "isode passwd lookup demo pci";
        !            14: 
        !            15: 
        !            16:                                        /* ARGUMENTS */
        !            17: int    do_lookupUser (), do_lookupUID (), do_help (), do_quit ();
        !            18: 
        !            19:                                        /* RESULTS */
        !            20: int    lookup_result ();
        !            21: 
        !            22:                                        /* ERRORS */
        !            23: int    lookup_error ();
        !            24: 
        !            25: 
        !            26: static struct dispatch dispatches[] = {
        !            27:     "lookupUser", operation_PasswordLookup_lookupUser,
        !            28:     do_lookupUser, free_PasswordLookup_UserName,
        !            29:     lookup_result, lookup_error,
        !            30:     "find user by name",
        !            31: 
        !            32:     "lookupUID", operation_PasswordLookup_lookupUID,
        !            33:     do_lookupUID, free_PasswordLookup_UserID,
        !            34:     lookup_result, lookup_error,
        !            35:     "find user by id",
        !            36: 
        !            37:     "help", 0,
        !            38:     do_help, NULLIFP,
        !            39:     NULLIFP, NULLIFP,
        !            40:     "print this information",
        !            41: 
        !            42:     "quit", 0,
        !            43:     do_quit, NULLIFP,
        !            44:     NULLIFP, NULLIFP,
        !            45:     "terminate the association and exit",
        !            46: 
        !            47:     NULL
        !            48: };
        !            49: 
        !            50: /* MAIN */
        !            51: 
        !            52: /* ARGSUSED */
        !            53: 
        !            54: main (argc, argv, envp)
        !            55: int    argc;
        !            56: char  **argv,
        !            57:       **envp;
        !            58: {
        !            59:     (void) ryinitiator (argc, argv, myservice, mycontext, mypci,
        !            60:                        table_PasswordLookup_Operations, dispatches, do_quit);
        !            61: 
        !            62:     exit (0);                  /* NOTREACHED */
        !            63: }
        !            64: 
        !            65: /* ARGUMENTS */
        !            66: 
        !            67: /* ARGSUSED */
        !            68: 
        !            69: static int  do_lookupUser (sd, ds, args, arg)
        !            70: int    sd;
        !            71: struct dispatch *ds;
        !            72: char  **args;
        !            73: register struct type_PasswordLookup_UserName **arg;
        !            74: {
        !            75:     char   *cp;
        !            76: 
        !            77:     if ((cp = *args++) == NULL) {
        !            78:        advise (NULLCP, "usage: lookupUser username");
        !            79:        return NOTOK;
        !            80:     }
        !            81: 
        !            82:     if ((*arg = str2qb (cp, strlen (cp), 1)) == NULL)
        !            83:            adios (NULLCP, "out of memory");
        !            84: 
        !            85:     return OK;
        !            86: }
        !            87: 
        !            88: /*  */
        !            89: 
        !            90: /* ARGSUSED */
        !            91: 
        !            92: static int  do_lookupUID (sd, ds, args, arg)
        !            93: int    sd;
        !            94: struct dispatch *ds;
        !            95: char  **args;
        !            96: register struct type_PasswordLookup_UserID **arg;
        !            97: {
        !            98:     char   *cp;
        !            99: 
        !           100:     if ((cp = *args++) == NULL) {
        !           101:        advise (NULLCP, "usage: lookupUID userid");
        !           102:        return NOTOK;
        !           103:     }
        !           104: 
        !           105:     if ((*arg = (struct type_PasswordLookup_UserID *) calloc (1, sizeof **arg))
        !           106:            == NULL)
        !           107:        adios (NULLCP, "out of memory");
        !           108: 
        !           109:     (*arg) -> parm = atoi (cp);
        !           110: 
        !           111:     return OK;
        !           112: }
        !           113: 
        !           114: /*  */
        !           115: 
        !           116: /* ARGSUSED */
        !           117: 
        !           118: static int  do_help (sd, ds, args, dummy)
        !           119: int    sd;
        !           120: register struct dispatch *ds;
        !           121: char  **args;
        !           122: caddr_t *dummy;
        !           123: {
        !           124:     printf ("\nCommands are:\n");
        !           125:     for (ds = dispatches; ds -> ds_name; ds++)
        !           126:        printf ("%s\t%s\n", ds -> ds_name, ds -> ds_help);
        !           127: 
        !           128:     return NOTOK;
        !           129: }
        !           130: 
        !           131: /*  */
        !           132: 
        !           133: /* ARGSUSED */
        !           134: 
        !           135: static int  do_quit (sd, ds, args, dummy)
        !           136: int    sd;
        !           137: struct dispatch *ds;
        !           138: char  **args;
        !           139: caddr_t *dummy;
        !           140: {
        !           141:     struct AcSAPrelease acrs;
        !           142:     register struct AcSAPrelease   *acr = &acrs;
        !           143:     struct AcSAPindication  acis;
        !           144:     register struct AcSAPindication *aci = &acis;
        !           145:     register struct AcSAPabort *aca = &aci -> aci_abort;
        !           146: 
        !           147:     if (AcRelRequest (sd, ACF_NORMAL, NULLPEP, 0, NOTOK, acr, aci) == NOTOK)
        !           148:        acs_adios (aca, "A-RELEASE.REQUEST");
        !           149: 
        !           150:     if (!acr -> acr_affirmative) {
        !           151:        (void) AcUAbortRequest (sd, NULLPEP, 0, aci);
        !           152:        adios (NULLCP, "release rejected by peer: %d", acr -> acr_reason);
        !           153:     }
        !           154: 
        !           155:     ACRFREE (acr);
        !           156: 
        !           157:     exit (0);
        !           158: }
        !           159: 
        !           160: /* RESULTS */
        !           161: 
        !           162: /* ARGSUSED */
        !           163: 
        !           164: static int  lookup_result (sd, id, dummy, result, roi)
        !           165: int    sd,
        !           166:        id,
        !           167:        dummy;
        !           168: register struct type_PasswordLookup_Passwd *result;
        !           169: struct RoSAPindication *roi;
        !           170: {
        !           171:     print_qb (result -> name);
        !           172:     putchar (':');
        !           173:     print_qb (result -> passwd);
        !           174:     printf (":%d:%d:", result -> uid -> parm, result -> gid -> parm);
        !           175:     print_qb (result -> gecos);
        !           176:     putchar (':');
        !           177:     print_qb (result -> dir);
        !           178:     putchar (':');
        !           179:     print_qb (result -> shell);
        !           180:     putchar ('\n');
        !           181: 
        !           182:     return OK;
        !           183: }
        !           184: 
        !           185: 
        !           186: static print_qb (q)
        !           187: register struct qbuf *q;
        !           188: {
        !           189:     register struct qbuf *p;
        !           190: 
        !           191:     if (q == NULL)
        !           192:        return;
        !           193: 
        !           194:     for (p = q -> qb_forw; p != q; p = p -> qb_forw)
        !           195:        printf ("%*.*s", p -> qb_len, p -> qb_len, p -> qb_data);
        !           196: }
        !           197: 
        !           198: /* ERRORS */
        !           199: 
        !           200: /* ARGSUSED */
        !           201: 
        !           202: static int  lookup_error (sd, id, error, parameter, roi)
        !           203: int    sd,
        !           204:        id,
        !           205:        error;
        !           206: caddr_t parameter;
        !           207: struct RoSAPindication *roi;
        !           208: {    
        !           209:     register struct RyError *rye;
        !           210: 
        !           211:     if (error == RY_REJECT) {
        !           212:        advise (NULLCP, "%s", RoErrString ((int) parameter));
        !           213:        return OK;
        !           214:     }
        !           215: 
        !           216:     if (rye = finderrbyerr (table_PasswordLookup_Errors, error))
        !           217:        advise (NULLCP, "%s",  rye -> rye_name);
        !           218:     else
        !           219:        advise (NULLCP, "Error %d", error);
        !           220: 
        !           221:     return OK;
        !           222: }

unix.superglobalmegacorp.com

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