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

1.1     ! root        1: /* lookup_service.c - password lookup service -- responder */
        !             2: 
        !             3: #include <stdio.h>
        !             4: #include <pwd.h>
        !             5: #include "ryresponder.h"               /* for generic idempotent responders */
        !             6: #include "PasswordLookup-ops.h"                /* operation definitions */
        !             7: #include "PasswordLookup-types.h"      /* type definitions */
        !             8: 
        !             9: 
        !            10: #define        xalloc(p, type) \
        !            11:        ((p) = (type) calloc (1, sizeof *(p)))
        !            12: 
        !            13: #define        salloc(s) \
        !            14:        str2qb ((s), strlen (s), 1)
        !            15: 
        !            16: 
        !            17: #ifdef SYS5
        !            18: struct passwd *getpwnam (), *getpwuid ();
        !            19: #endif
        !            20: 
        !            21: 
        !            22: /* DATA */
        !            23: 
        !            24: static char *myservice = "passwdstore";
        !            25: 
        !            26: static char *mycontext = "isode passwd lookup demo";
        !            27: 
        !            28: 
        !            29:                                        /* OPERATIONS */
        !            30: int    op_lookupUser (), op_lookupUID ();
        !            31: 
        !            32: static struct dispatch dispatches[] = {
        !            33:     "lookupUser", operation_PasswordLookup_lookupUser, op_lookupUser,
        !            34: 
        !            35:     "lookupUID", operation_PasswordLookup_lookupUID, op_lookupUID,
        !            36: 
        !            37:     NULL
        !            38: };
        !            39: 
        !            40: 
        !            41: /* MAIN */
        !            42: 
        !            43: /* ARGSUSED */
        !            44: 
        !            45: main (argc, argv, envp)
        !            46: int    argc;
        !            47: char  **argv,
        !            48:       **envp;
        !            49: {
        !            50:     ryresponder (argc, argv, PLocalHostName (), myservice, mycontext,
        !            51:                 dispatches, table_PasswordLookup_Operations,
        !            52:                 NULLIFP, NULLIFP);
        !            53: 
        !            54:     exit (0);                  /* NOTREACHED */
        !            55: }
        !            56: 
        !            57: 
        !            58: /* OPERATIONS */
        !            59: 
        !            60: static int  op_lookupUser (sd, ryo, rox, in, roi)
        !            61: int    sd;
        !            62: struct RyOperation *ryo;
        !            63: struct RoSAPinvoke *rox;
        !            64: caddr_t        in;
        !            65: struct RoSAPindication *roi;
        !            66: {
        !            67:     int     result;
        !            68:     char   *cp;
        !            69:     register struct type_PasswordLookup_UserName   *arg =
        !            70:                (struct type_PasswordLookup_UserName   *) in;
        !            71: 
        !            72:     if (rox -> rox_nolinked == 0) {
        !            73:        advise (LLOG_NOTICE, NULLCP,
        !            74:                "RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
        !            75:                sd, ryo -> ryo_name, rox -> rox_linkid);
        !            76:        return ureject (sd, ROS_IP_LINKED, rox, roi);
        !            77:     }
        !            78:     if (debug)
        !            79:        advise (LLOG_DEBUG, NULLCP, "RO-INVOKE.INDICATION/%d: %s",
        !            80:                sd, ryo -> ryo_name);
        !            81: 
        !            82:     if ((cp = qb2str (arg)) == NULL)
        !            83:        result = error (sd, error_PasswordLookup_congested, (caddr_t) NULL,
        !            84:                        rox, roi);
        !            85:     else {
        !            86:        result = lookup (sd, getpwnam (cp), rox, roi);
        !            87:        free (cp);
        !            88:     }
        !            89: 
        !            90:     return result;
        !            91: }
        !            92: 
        !            93: 
        !            94: static int  op_lookupUID (sd, ryo, rox, in, roi)
        !            95: int    sd;
        !            96: struct RyOperation *ryo;
        !            97: struct RoSAPinvoke *rox;
        !            98: caddr_t        in;
        !            99: struct RoSAPindication *roi;
        !           100: {
        !           101:     register struct type_PasswordLookup_UserID   *arg =
        !           102:                (struct type_PasswordLookup_UserID   *) in;
        !           103: 
        !           104:     if (rox -> rox_nolinked == 0) {
        !           105:        advise (LLOG_EXCEPTIONS, NULLCP,
        !           106:                "RO-INVOKE.INDICATION/%d: %s, unknown linkage %d",
        !           107:                sd, ryo -> ryo_name, rox -> rox_linkid);
        !           108:        return ureject (sd, ROS_IP_LINKED, rox, roi);
        !           109:     }
        !           110:     if (debug)
        !           111:        advise (LLOG_DEBUG, NULLCP, "RO-INVOKE.INDICATION/%d: %s",
        !           112:                sd, ryo -> ryo_name);
        !           113: 
        !           114:     return lookup (sd, getpwuid (arg -> arg), rox, roi);
        !           115: }
        !           116: 
        !           117: 
        !           118: static int  lookup (sd, pw, rox, roi)
        !           119: int    sd;
        !           120: struct passwd *pw;
        !           121: struct RoSAPinvoke *rox;
        !           122: struct RoSAPindication *roi;
        !           123: {
        !           124:     int            result;
        !           125: 
        !           126:     if (pw) {
        !           127:        register struct type_PasswordLookup_Passwd *res = NULL;
        !           128: 
        !           129:        if (xalloc (res, struct type_PasswordLookup_Passwd *) == NULL
        !           130:                || (res -> name = salloc (pw -> pw_name)) == NULL
        !           131:                || (*pw -> pw_passwd
        !           132:                        && (res -> passwd = salloc (pw -> pw_passwd)) == NULL)
        !           133:                || xalloc (res -> uid, struct type_PasswordLookup_UserID *)
        !           134:                        == NULL
        !           135:                || xalloc (res -> gid, struct type_PasswordLookup_GroupID *)
        !           136:                        == NULL
        !           137:                || (pw -> pw_comment
        !           138:                        && (res -> comment = salloc (pw -> pw_comment))
        !           139:                                == NULL)
        !           140:                || (pw -> pw_gecos
        !           141:                        && (res -> gecos = salloc (pw -> pw_gecos)) == NULL)
        !           142:                || (pw -> pw_dir
        !           143:                        && (res -> dir = salloc (pw -> pw_dir)) == NULL)
        !           144:                || (pw -> pw_shell
        !           145:                        && (res -> shell = salloc (pw -> pw_shell))
        !           146:                                    == NULL))
        !           147:            result = error (sd, error_PasswordLookup_congested, (caddr_t) NULL,
        !           148:                rox, roi);
        !           149:        else {
        !           150:            res -> uid -> arg = pw -> pw_uid;
        !           151:            res -> gid -> arg = pw -> pw_gid;
        !           152:            res -> quota = pw -> pw_quota;
        !           153: 
        !           154:            if (RyDsResult (sd, rox -> rox_id, (caddr_t) res, ROS_NOPRIO, roi)
        !           155:                    == NOTOK)
        !           156:                ros_adios (&roi -> roi_preject, "RESULT");
        !           157:            result = OK;
        !           158:        }
        !           159: 
        !           160:        free_PasswordLookup_Passwd (res);
        !           161:     }
        !           162:     else
        !           163:        result = error (sd, error_PasswordLookup_noSuchUser, (caddr_t) NULL,
        !           164:                rox, roi);
        !           165: 
        !           166:     return result;
        !           167: }
        !           168: 
        !           169: 
        !           170: /* ERROR */
        !           171: 
        !           172: static int  error (sd, err, param, rox, roi)
        !           173: int    sd,
        !           174:        err;
        !           175: caddr_t        param;
        !           176: struct RoSAPinvoke *rox;
        !           177: struct RoSAPindication *roi;
        !           178: {
        !           179:     if (RyDsError (sd, rox -> rox_id, err, param, ROS_NOPRIO, roi) == NOTOK)
        !           180:        ros_adios (&roi -> roi_preject, "ERROR");
        !           181: 
        !           182:     return OK;
        !           183: }
        !           184: 
        !           185: 
        !           186: /* U-REJECT */
        !           187: 
        !           188: static int  ureject (sd, reason, rox, roi)
        !           189: int    sd,
        !           190:        reason;
        !           191: struct RoSAPinvoke *rox;
        !           192: struct RoSAPindication *roi;
        !           193: {
        !           194:     if (RyDsUReject (sd, rox -> rox_id, reason, ROS_NOPRIO, roi) == NOTOK)
        !           195:        ros_adios (&roi -> roi_preject, "U-REJECT");
        !           196: 
        !           197:     return OK;
        !           198: }

unix.superglobalmegacorp.com

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