[Dev] Tizen 3.0 Multiuser support architecture proposition

Kok, Auke-jan H auke-jan.h.kok at intel.com
Tue Oct 29 18:00:07 GMT 2013


This sums it up pretty well, and explains the difference between the two models.

A good guideline is that stuff that runs as uid != 0, should probably
use getenv(). Do you really want to open(/etc/passwd) for this?

Code wise it's also a lot cleaner, compare:

        char *c;

        c = getenv("HOME");
        fprintf(stdout, "%s\n", c);

to

        uid_t u;
        struct passwd *p;

        u = getuid();
        p = getpwuid(u);

        fprintf(stdout, "%s\n", p->pw_dir);


Cheers,

Auke


On Tue, Oct 29, 2013 at 8:07 AM, Schaufler, Casey
<casey.schaufler at intel.com> wrote:
>
> Code that enforces or implements security should use getpwent() while programs that are strictly at the whim of the user can use $HOMEDIR.
>
>
>> -----Original Message-----
>> From: dev-bounces at lists.tizen.org [mailto:dev-bounces at lists.tizen.org] On
>> Behalf Of Lukasz Stelmach
>> Sent: Tuesday, October 29, 2013 2:51 AM
>> To: Carsten Haitzler
>> Cc: dev at lists.tizen.org
>> Subject: Re: [Dev] Tizen 3.0 Multiuser support architecture proposition
>>
>> It was <2013-10-29 wto 04:27>, when Carsten Haitzler wrote:
>> > On 10/29/2013 12:20 PM, Leibowitz, Michael wrote:
>> >> On Mon, Oct 28, 2013 at 2:36 AM, Dominig ar Foll (Intel OTC)
>> >> <dominig.arfoll at fridu.net> wrote:
>> >>>> Actually there is a minor issue for $HOME directory. On the *NIX
>> >>> world, the actual user directory is /home/{username}. However, I
>> >>> proposed /opt/usr/uid instead of /opt/usr/username. There is subtle
>> >>> issue of assigning username in the literal form and I think using
>> >>> uid instead of username is fine. The file standard hierarchy does
>> >>> not specify the user directory name in detail and we just need to
>> >>> maintain symbolic link of /home correctly.  I do not think that
>> >>> deriving from the reliable and well accepted method of using the
>> >>> $HOME is the good idea.  Getting the $HOME from the environment is
>> >>> easy and reliable. It has proven its value over the years.
>> >> If you want the home directory, use getpwnam or similar API.  Don't
>> >> rely on the environment.
>> >
>> > i would suggest to rely on $HOME - because it can be changed to
>> > redirect the homedir - eg temporarily or for specific emulation,
>> > testing or isolation purposes. this is based on experience. i used to
>> > use getpwnam but at some point in the past hit a problem (i forgot
>> > what it was now) but i had to switch to $HOME.
>> >
>>
>> +1 Most code I've seen use $HOME.
>>
>> +2 getpwnam(3) can by much slower than getenv(3).
>>
>> +3 If we use $HOME take care to set it properly then we'll get a more
>>    flexible solution.
>>
>> --
>> Łukasz Stelmach
>> Samsung R&D Institute Poland
>> Samsung Electronics
> _______________________________________________
> Dev mailing list
> Dev at lists.tizen.org
> https://lists.tizen.org/listinfo/dev


More information about the Dev mailing list