Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Sep 2002 05:01:57 +0200
From:      Pawel Jakub Dawidek <nick@garage.freebsd.pl>
To:        freebsd-hackers@freebsd.org
Subject:   Changing process informations.
Message-ID:  <20020915030157.GP68652@garage.freebsd.pl>

next in thread | raw e-mail | index | archive | help

--eQyCKlb8USywWNtC
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello hackers...

When I want change process real or effective uid in kld module
I got functions change_ruid() and change_euid().
I need change many others informations about process.
Correct me if I'm wrong:

void
change_svuid(struct proc *p, uid_t svuid)
{
	struct pcred *pc =3D p->p_cred;

	if (pc->p_svuid !=3D svuid) {
		pc->p_svuid =3D svuid;
		setsugid(p);
	}
}

void
change_rgid(struct proc *p, gid_t rgid)
{
	struct pcred *pc =3D p->p_cred;

	if (pc->p_rgid !=3D rgid) {
		pc->p_rgid =3D rgid;
		setsugid(p);
	}
}

void
change_egid(struct proc *p, gid_t egid)
{
	struct pcred *pc =3D p->p_cred;

	if (pc->pc_ucred->cr_groups[0] !=3D egid) {
		pc->pc_ucred =3D crcopy(pc->pc_ucred);
		pc->pc_ucred->cr_groups[0] =3D egid;
		setsugid(p);
	}
}

void
change_rgid(struct proc *p, gid_t svgid)
{
	struct pcred *pc =3D p->p_cred;

	if (pc->p_svgid !=3D svgid) {
		pc->p_svgid =3D svgid;
		setsugid(p);
	}
}

void
addgroup(struct proc *p, gid_t gid)
{
	struct pcred *pc =3D p->p_cred;

	if (groupmember(gid, pc->pc_ucred))
		return;

	if (pc->pc_ucred->cr_ngroups >=3D NGROUPS)
		return;

	pc->pc_ucred =3D crcopy(pc->pc_ucred);	/* XXX: Have to be here? */
	pc->pc_ucred->cr_groups[pc->pc_ucred->cr_ngroups] =3D gid;
	pc->pc_ucred->cr_ngroups++;
	setsugid(p);	/* XXX: Have to be here? */
}

void
delgroup(struct proc *p, gid_t gid)
{
	struct pcred *pc =3D p->p_cred;
	u_int	i;

	if (!groupmember(gid, pc->pc_ucred))
		return;

	for (i =3D 0; pc->pc_ucred->cr_groups[i] !=3D gid; ++i)
		;

	pc->pc_ucred =3D crcopy(pc->pc_ucred);	/* XXX: Have to be here? */
	for (; i < pc->pc_ucred->cr_ngroups; ++i) {
		/* Yes, some copy operation could be a bit faster, but... */
		pc->pc_ucred->cr_groups[i] =3D pc->pc_ucred->cr_groups[i + 1];
	}
	pc->pc_ucred->cr_ngroups--;
	setsugid(p);	/* XXX: Have to be here? */
}

That's all for now.

--=20
Pawel Jakub Dawidek
UNIX Systems Administrator
http://garage.freebsd.pl
Am I Evil? Yes, I Am.



--=20
Pawel Jakub Dawidek
UNIX Systems Administrator
http://garage.freebsd.pl
Am I Evil? Yes, I Am.

--eQyCKlb8USywWNtC
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (FreeBSD)

iQCVAwUBPYP4JT/PhmMH/Mf1AQFqBAP+ICPhoqadqgDeGbqp6iOrdY1hQaiquCvp
NmK5tkX74wgsXHzy1ch1LNH8k1zAku8zh3+JyRGDxPygujZxkuzrEXSOgq0AEQjl
ZMdw2lmvd0Jpm7kml3FXFdYW+fMzLd8hCB4WfpJQThaQ11rQ04OXQI+RMxM1ZptN
G0jVdyH15GE=
=/ZQR
-----END PGP SIGNATURE-----

--eQyCKlb8USywWNtC--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020915030157.GP68652>