[sane-devel] [sane-commit] CVS update of sane-backends (3 files)
Nicolas Martin
nicolas.martin at freesurf.fr
Sat Dec 6 16:59:26 UTC 2008
Ok, I don't know too much about those functions, but this quick & dirty
code seems to work well on Ubuntu (Hardy 8.04):
#include <pwd.h>
#include <stdio.h>
int main()
{
struct passwd *uid;
uid = getpwuid(geteuid());
printf("user=%s\n", uid->pw_name);
}
Prints my username correctly. Also prints root if runned with sudo ;-)
Le samedi 06 décembre 2008 à 17:31 +0100, Julien BLACHE a écrit :
> Louis Lagendijk <llagendijk-guest at alioth.debian.org> wrote:
>
> Hi,
>
> > backend/pixma_bjnp.c pixma_bjnp_private.h
> > On Ubuntu getlogin() returns NULL. So we noew first try getlogin()
> > and if that fails, we try getenv("USER") and if that fails we use
> > a defaul user string
>
> You want geteuid() + getpwuid() instead of getlogin() which relies on
> utmp and thus is unreliable.
>
> Also, never trust an environment variable.
>
> JB.
>
> --
> Julien BLACHE <http://www.jblache.org>
> <jb at jblache.org> GPG KeyID 0xF5D65169
>
More information about the sane-devel
mailing list