Subject: Re: magic symlinks: uid keyword translation
To: Quentin Garnier <cube@cubidou.net>
From: Dr R.S. Brooks <R.S.Brooks@liverpool.ac.uk>
List: tech-kern
Date: 10/30/2006 15:24:10
On Mon, 30 Oct 2006, Quentin Garnier wrote:

> On Mon, Oct 30, 2006 at 04:57:51PM +0200, Elad Efrat wrote:
>> Quentin Garnier wrote:
>>> On Mon, Oct 30, 2006 at 02:50:14PM +0200, Elad Efrat wrote:
>>>> hi,
>>>>
>>>> attached diff adds a "uid" keyword translation for magic symlinks.
>>>>
>>>> any objections?
>>>
>>> s/16/LOGIN_NAME_MAX/
>>
>> why?
>
> 1. raw numbers like this are wrong.
> 2. the best example of 1. is that LOGIN_NAME_MAX is 17.
> 3. someone might wish to run a system with a different LOGIN_NAME_MAX,
>   for whatever reason (although it's not recommended, and not made
>   easy either).

But unless I'm mistaken, the code below will substitute the numeric UID
(as a string of ASCII digits).  And trying to do a numeric UID to login
name translation inside a kernel system call seems fraught with problems.
If the passwd table comes from NIS or LDAP (or even NIS+ if it were supported)
then any file access which involved one of these magic symlinks could hang,
even though both the magic symlink and the target were on a local filesystem.
Also, there's the generally unpredictable behaviour where more than one
login name share the same numeric UID.

>
>>>
>>>> Index: vfs_lookup.c
>>>> ===================================================================
>>>> RCS file: /cvsroot/src/sys/kern/vfs_lookup.c,v
>>>> retrieving revision 1.71
>>>> diff -u -p -r1.71 vfs_lookup.c
>>>> --- vfs_lookup.c	23 Jul 2006 22:06:12 -0000	1.71
>>>> +++ vfs_lookup.c	30 Oct 2006 01:36:19 -0000
>>>> @@ -163,6 +163,12 @@ symlink_magic(struct proc *p, char *cp,
>>>>  		} else if (MATCH("ostype")) {
>>>>  			SUBSTITUTE("ostype", ostype,
>>>>  			    strlen(ostype));
>>>> +		} else if (MATCH("uid")) {
>>>> +			char uidtmp[16];
>>>> +
>>>> +			(void)snprintf(uidtmp, sizeof(uidtmp) - 1, "%u",
>>>> +			    kauth_cred_getuid(p->p_cred));
>>>> +			SUBSTITUTE("uid", uidtmp, strlen(uidtmp));
>>>>  		} else {
>>>>  			tmp[newlen++] = '@';
>>>>  			if (termchar == VC)
>>>
>>>
>>
>>
>> --
>> Elad Efrat
>
> -- 
> Quentin Garnier - cube@cubidou.net - cube@NetBSD.org
> "You could have made it, spitting out benchmarks
> Owe it to yourself not to fail"
> Amplifico, Spitting Out Benchmarks, Hometakes Vol. 2, 2005.
>

Roger

------------------------------------------------------------------------------
Roger Brooks (Systems Programmer),          |  Email: R.S.Brooks@liv.ac.uk
Computing Services Dept,                    |  Tel:   +44 151 794 4441
Chadwick Tower,                             |  Fax:   +44 151 794 3759
The University of Liverpool,                |
Liverpool L69 7ZF, UK                       |
------------------------------------------------------------------------------