Ejemplo n.º 1
0
static int
pwd_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
    nvlist_t *nvlout)
{
	int error;

	if (!pwd_allowed_cmd(limits, cmd))
		return (ENOTCAPABLE);

	if (strcmp(cmd, "getpwent") == 0 || strcmp(cmd, "getpwent_r") == 0)
		error = pwd_getpwent(limits, nvlin, nvlout);
	else if (strcmp(cmd, "getpwnam") == 0 || strcmp(cmd, "getpwnam_r") == 0)
		error = pwd_getpwnam(limits, nvlin, nvlout);
	else if (strcmp(cmd, "getpwuid") == 0 || strcmp(cmd, "getpwuid_r") == 0)
		error = pwd_getpwuid(limits, nvlin, nvlout);
	else if (strcmp(cmd, "setpassent") == 0)
		error = pwd_setpassent(limits, nvlin, nvlout);
	else if (strcmp(cmd, "setpwent") == 0)
		error = pwd_setpwent(limits, nvlin, nvlout);
	else if (strcmp(cmd, "endpwent") == 0)
		error = pwd_endpwent(limits, nvlin, nvlout);
	else
		error = EINVAL;

	return (error);
}
Ejemplo n.º 2
0
/*
 * int
 * pfc_pwd_ismember(uid_t uid, gid_t gid, pfc_bool_t supp)
 *	Determine whether the user specified by user ID `uid' is a member of
 *	the group specified by group ID `gid'.
 *
 *	If PFC_TRUE is specified to `supp', this function returns zero if the
 *	group specified by `gid' is one of supplementary groups for the
 *	specified user. If PFC_FALSE is specified, this function does not
 *	check supplementary groups.
 *
 * Calling/Exit State:
 *	Zero is returned if the specified user is a member of the specified
 *	group.
 *
 *	-1 is returned if the specified user is not a member.
 *	Otherwise error number which indicates the cause of error is returned.
 */
int
pfc_pwd_ismember(uid_t uid, gid_t gid, pfc_bool_t supp)
{
    pwd_passwd_t	pctx;
    pwd_group_t	gctx;
    struct passwd	*pwd;
    struct group	*grp;
    char		*uname, *memp, **mempp;
    int		err;

    /* Get password entry for the given user ID. */
    err = pwd_getpwuid(&pctx, uid);
    if (PFC_EXPECT_FALSE(err != 0)) {
        goto out;
    }

    pwd = &pctx.pp_passwd;
    if (pwd->pw_gid == gid) {
        /* The given user is a member of the given group. */
        PFC_ASSERT(err == 0);
        goto out;
    }

    if (!supp) {
        /* Don't check supplementary groups. */
        err = -1;
        goto out;
    }

    uname = pwd->pw_name;
    if (PFC_EXPECT_FALSE(uname == NULL)) {
        /* This should never happen. */
        err = EFAULT;
        goto out;
    }

    /* Get group entry for the given group ID. */
    err = pwd_getgrgid(&gctx, gid);
    if (PFC_EXPECT_FALSE(err != 0)) {
        goto out_group;
    }

    grp = &gctx.pg_group;
    mempp = grp->gr_mem;
    err = -1;
    if (PFC_EXPECT_FALSE(mempp == NULL)) {
        goto out_group;
    }

    for (memp = *mempp; memp != NULL; mempp++, memp = *mempp) {
        if (strcmp(memp, uname) == 0) {
            /* Found. */
            err = 0;
            break;
        }
    }

out_group:
    pwd_buffer_free(&gctx.pg_buffer);

out:
    pwd_buffer_free(&pctx.pp_buffer);

    return err;
}
Ejemplo n.º 3
0
/*
 * Takes care of updating userfile, by help of gl_userfile module.
 */
char * userfile_update(creditlist_t *l) {
	hashtable_t *cfg = get_config();
	hashtable_t *env = get_context();
	long spend, addkb;
	char buf[1024], userfile[1024], *section, *userdir, *tmp, *group;
	pwdfile *pass;
	int gl_stat_section = 0, gl_credit_section = 0, prespeed, rc, ratio;

	// get pre-section from env.
	section = ht_get(env, "section");
	group = ht_get(env, PROPERTY_GROUP);

	// find the user.
	pass = pwd_getpwuid(l->uid);
	if (!pass)
		return "";

	// get ftp-data/users from conf.
	userdir = ht_get(cfg, PROPERTY_GL_USERDIR);
	if (!userdir)
		quit(" * ERROR: Userdir not defined in pre config, f**k the sysop ;(\n");

	sprintf(userfile, "%s/%s", userdir, pass->name);

	// get the section config from conf.
	gl_stat_section = section_get_int_property(section, PROPERTY_GROUP_GL_SS);
	gl_credit_section = section_get_int_property(section, PROPERTY_GROUP_GL_CS);

	if ((gl_stat_section == -1) && (gl_credit_section == -1)) {
		printf(" * ERROR: No gl_stat_section or gl_credit_section defined for\n");
		printf("          section %s, %s got no stats/credits for pre !\n", section,
			   pass->name);

		return "";
	}

	// try and figure a ratio to use.
	tmp = group_get_property(group, PROPERTY_GROUP_RATIO);

	if (!tmp) {
		printf(" * ERROR: No ratio defined for group %s, no credits given!\n", group);
		return "";
	}

	if (!strcasecmp(tmp, "USERFILE")) {
		ratio = gl_userfile_get_ratio(userfile, gl_credit_section);

		if (ratio == -1) {
			printf(" * ERROR: No ratio found in userfile for %s\n", pass->name);

			return "";
		}
	} else
		ratio = atoi(tmp);

	if (prespeed == 0)
		prespeed = 1024;

	spend = (long)l->bytes / prespeed;
	addkb = l->bytes;

	if (spend == 0)
		spend++;

	printf("   -- %10.10s: ", pass->name);

	if (gl_stat_section > -1)
		printf("%d file/s, %.1f Mb (s:%d)", l->files, (float)addkb/1024, gl_stat_section);
	else
		printf("No stats given");

	if (gl_credit_section > -1)
		printf(", Credits: %.1f Mb, Ratio: %d (s:%d)\n", (float)(ratio * addkb)/1024, ratio, gl_credit_section);
	else
		printf(", No credits given\n");

	// call gl_userfile_* to get the userfile updated.
	rc = gl_userfile_add_stats(userfile, l->files, addkb, spend, (long)ratio * addkb, gl_stat_section, gl_credit_section);

	if (rc > -1) {
		sprintf(buf, "%s/%.1fMb, ", pass->name, (float)l->bytes/1024);
		return strdup(buf);
	} else
		printf(" * ERROR: Couldnt update userfile for %s\n", pass->name);

	return "";
}