From owner-freebsd-hackers Thu Aug 29 8:29:13 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 692AB37B400 for ; Thu, 29 Aug 2002 08:29:09 -0700 (PDT) Received: from milla.ask33.net (milla.ask33.net [217.197.166.60]) by mx1.FreeBSD.org (Postfix) with ESMTP id B1A4B43E4A for ; Thu, 29 Aug 2002 08:29:08 -0700 (PDT) (envelope-from nick@milla.ask33.net) Received: by milla.ask33.net (Postfix, from userid 1001) id B6B773ABD40; Thu, 29 Aug 2002 17:31:41 +0200 (CEST) Date: Thu, 29 Aug 2002 17:31:41 +0200 From: Pawel Jakub Dawidek To: Giorgos Keramidas Cc: freebsd-hackers@freebsd.org Subject: Re: chown() vs. setfown() prototype in vfs_syscalls.c Message-ID: <20020829153141.GR31943@garage.freebsd.pl> References: <20020829073530.GB33894@hades.hell.gr> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="uLzYCuFow5JXEQYy" Content-Disposition: inline In-Reply-To: <20020829073530.GB33894@hades.hell.gr> X-PGP-Key-URL: http://garage.freebsd.pl/jules.pgp X-OS: FreeBSD 4.6-STABLE i386 User-Agent: Mutt/1.5.1i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --uLzYCuFow5JXEQYy Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 29, 2002 at 10:35:31AM +0300, Giorgos Keramidas wrote: +> Hello, +>=20 +> A friend asked me why he was getting warnings about conversion of +> unsigned to signed, when calling chown() with: +>=20 +> chown("/dev/null", -1, -1); +>=20 +> The manpage of chown has a prototype of: +>=20 +> int +> chown(const char *path, uid_t owner, gid_t group); +>=20 +> But the manpage mentions that (uid_d)-1 is the right value for a chown +> operation that wants to leave the user part of the owner:group set +> unchanged. +>=20 +> After a bit of research he found that the definition of uid_t was +> (unsigned int) and that's why -1 was giving him warnings. But the fun +> doesn't stop there... The implementation of chown in vfs_syscalls.c +> uses `int' as the type of the two uid_t/gid_t arguments in the *uap +> argument, and then calls setfown() which accepts uid_t and gid_t !!! +>=20 +> Then setfown() copies the values in a `struct vattr' at the va_uid and +> va_gid members, which are also uid_t and gid_t. +>=20 +> The only place where the uid & gid arguments of chown() are int and +> not uid_t and gid_t is in the prototype of the system call itself. +> Is this really necessary? Is there a reason behind it? Yes, look at VOP_SETATTR man page: if (vap->va_uid !=3D (uid_t)VNOVAL || vap->va_gid !=3D (gid_t)VNOVAL) { /* * Change owner and/or group of the file. */ } And: leila:root:~# egrep "#define.*VNOVAL" /sys/sys/vnode.h /sys/sys/vnode.h:#define VNOVAL (-1) --=20 Pawel Jakub Dawidek UNIX Systems Administrator http://garage.freebsd.pl Am I Evil? Yes, I Am. --uLzYCuFow5JXEQYy Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iQCVAwUBPW4+XT/PhmMH/Mf1AQE5uAP/XvAwcb+yySvRD3nPeDzsQ7QZKD3ouABD SLnoxZl3vpzX+4UjXTrAxGQ0ZzJxkvEJnO1raT1zqMQrhdM3/cVhhSPUmlGY92l0 4HqATzv2+t5mK08nOCq4Y8rxLYpL6YPldS7RTvTihZ6bFi5nhk6z6RqPLFp/LiuH cYB6ExROfaE= =aI2p -----END PGP SIGNATURE----- --uLzYCuFow5JXEQYy-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message