MODRET authfile_name2uid(cmd_rec *cmd) { struct passwd *pwd = NULL; if (af_setpwent() < 0) return PR_DECLINED(cmd); pwd = af_getpwnam(cmd->argv[0]); return pwd ? mod_create_data(cmd, (void *) &pwd->pw_uid) : PR_DECLINED(cmd); }
static char *af_getpwpass(const char *name) { struct passwd *pwd = af_getpwnam(name); return pwd ? pwd->pw_passwd : NULL; }
MODRET authfile_getgroups(cmd_rec *cmd) { struct passwd *pwd = NULL; struct group *grp = NULL; array_header *gids = NULL, *groups = NULL; char *name = cmd->argv[0]; if (name == NULL) { return PR_DECLINED(cmd); } if (af_setpwent() < 0) { return PR_DECLINED(cmd); } if (af_setgrent() < 0) { return PR_DECLINED(cmd); } /* Check for NULLs */ if (cmd->argv[1]) gids = (array_header *) cmd->argv[1]; if (cmd->argv[2]) groups = (array_header *) cmd->argv[2]; /* Retrieve the necessary info. */ pwd = af_getpwnam(name); if (pwd == NULL) { return PR_DECLINED(cmd); } /* Populate the first group ID and name. */ if (gids) { *((gid_t *) push_array(gids)) = pwd->pw_gid; } if (groups && (grp = af_getgrgid(pwd->pw_gid)) != NULL) { *((char **) push_array(groups)) = pstrdup(session.pool, grp->gr_name); } af_setgrent(); /* This is where things get slow, expensive, and ugly. Loop through * everything, checking to make sure we haven't already added it. */ while ((grp = af_getgrent()) != NULL && grp->gr_mem) { char **gr_mems = NULL; pr_signals_handle(); /* Loop through each member name listed */ for (gr_mems = grp->gr_mem; *gr_mems; gr_mems++) { /* If it matches the given username... */ if (strcmp(*gr_mems, pwd->pw_name) == 0) { /* ...add the GID and name */ if (gids) *((gid_t *) push_array(gids)) = grp->gr_gid; if (groups) *((char **) push_array(groups)) = pstrdup(session.pool, grp->gr_name); } } } if (gids && gids->nelts > 0) { return mod_create_data(cmd, (void *) &gids->nelts); } else if (groups && groups->nelts > 0) { return mod_create_data(cmd, (void *) &groups->nelts); } return PR_DECLINED(cmd); }