[sane-devel] [sane-commit] CVS update of sane-backends (3 files)

2008-12-06 Thread Julien BLACHE
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



[sane-devel] [sane-commit] CVS update of sane-backends (3 files)

2008-12-06 Thread Nicolas Martin
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
 




[sane-devel] [sane-commit] CVS update of sane-backends (3 files)

2008-12-06 Thread Julien BLACHE
Nicolas Martin nicolas.martin at freesurf.fr wrote:

Hi,

   struct passwd *uid;
   uid = getpwuid(geteuid());
   printf(user=%s\n, uid-pw_name);

 Prints my username correctly. Also prints root if runned with sudo ;-)

Yep, use getuid() instead of geteuid() if you want to avoid that.

Also, you want some error checking in there... :)

JB.

-- 
Julien BLACHE   http://www.jblache.org 
jb at jblache.org  GPG KeyID 0xF5D65169



[sane-devel] [sane-commit] CVS update of sane-backends (3 files)

2008-12-06 Thread E. MARC
Le samedi 6 d?cembre 2008, ? 18:10, Julien BLACHE a ?crit?:
 Nicolas Martin nicolas.martin at freesurf.fr wrote:

 Hi,

  ? struct passwd *uid;
  ? uid = getpwuid(geteuid());
  ? printf(user=%s\n, uid-pw_name);
 
  Prints my username correctly. Also prints root if runned with sudo ;-)

 Yep, use getuid() instead of geteuid() if you want to avoid that.
On debian, I get same result with both functions:

#include pwd.h
#include stdio.h

int main()
{
? struct passwd *uid;
? uid = getpwuid(getuid());
? printf(method 1 getuid : user=%s\n, uid-pw_name);
? uid = getpwuid(geteuid());
? printf(method 2 geteuid: user=%s\n, uid-pw_name);
}

erwan at PC1:~$ ./myname 
method 1 getuid : user=erwan
method 2 geteuid: user=erwan

erwan at PC1:~$ sudo ./myname 
method 1 getuid : user=root
method 2 geteuid: user=root

Is there a bug?

EM

 Also, you want some error checking in there... :)

 JB.

 --
 Julien BLACHE ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://www.jblache.org
 jb at jblache.org ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?GPG KeyID 0xF5D65169




[sane-devel] [sane-commit] CVS update of sane-backends (3 files)

2008-12-06 Thread Nicolas Martin
Same on Ubuntu:

$ ./getlgn
method 1 getuid : user=nicolas
method 2 geteuid: user=nicolas
$ sudo ./getlgn
[sudo] password for nicolas: 
method 1 getuid : user=root
method 2 geteuid: user=root

?

Le samedi 06 d?cembre 2008 ? 18:27 +0100, E. MARC a ?crit :
 Le samedi 6 d?cembre 2008, ? 18:10, Julien BLACHE a ?crit :
  Nicolas Martin nicolas.martin at freesurf.fr wrote:
 
  Hi,
 
 struct passwd *uid;
 uid = getpwuid(geteuid());
 printf(user=%s\n, uid-pw_name);
  
   Prints my username correctly. Also prints root if runned with sudo ;-)
 
  Yep, use getuid() instead of geteuid() if you want to avoid that.
 On debian, I get same result with both functions:
 
 #include pwd.h
 #include stdio.h
 
 int main()
 {
   struct passwd *uid;
   uid = getpwuid(getuid());
   printf(method 1 getuid : user=%s\n, uid-pw_name);
   uid = getpwuid(geteuid());
   printf(method 2 geteuid: user=%s\n, uid-pw_name);
 }
 
 erwan at PC1:~$ ./myname 
 method 1 getuid : user=erwan
 method 2 geteuid: user=erwan
 
 erwan at PC1:~$ sudo ./myname 
 method 1 getuid : user=root
 method 2 geteuid: user=root
 
 Is there a bug?
 
 EM
 
  Also, you want some error checking in there... :)
 
  JB.
 
  --
  Julien BLACHE   http://www.jblache.org
  jb at jblache.org  GPG KeyID 0xF5D65169
 
 




[sane-devel] [sane-commit] CVS update of sane-backends (3 files)

2008-12-06 Thread m. allan noah
do you want getruid() ?

allan

On Sat, Dec 6, 2008 at 12:39 PM, Nicolas Martin
nicolas.martin at freesurf.fr wrote:
 Same on Ubuntu:

 $ ./getlgn
 method 1 getuid : user=nicolas
 method 2 geteuid: user=nicolas
 $ sudo ./getlgn
 [sudo] password for nicolas:
 method 1 getuid : user=root
 method 2 geteuid: user=root

 ?

 Le samedi 06 d?cembre 2008 ? 18:27 +0100, E. MARC a ?crit :
 Le samedi 6 d?cembre 2008, ? 18:10, Julien BLACHE a ?crit :
  Nicolas Martin nicolas.martin at freesurf.fr wrote:
 
  Hi,
 
 struct passwd *uid;
 uid = getpwuid(geteuid());
 printf(user=%s\n, uid-pw_name);
  
   Prints my username correctly. Also prints root if runned with sudo ;-)
 
  Yep, use getuid() instead of geteuid() if you want to avoid that.
 On debian, I get same result with both functions:

 #include pwd.h
 #include stdio.h

 int main()
 {
   struct passwd *uid;
   uid = getpwuid(getuid());
   printf(method 1 getuid : user=%s\n, uid-pw_name);
   uid = getpwuid(geteuid());
   printf(method 2 geteuid: user=%s\n, uid-pw_name);
 }

 erwan at PC1:~$ ./myname
 method 1 getuid : user=erwan
 method 2 geteuid: user=erwan

 erwan at PC1:~$ sudo ./myname
 method 1 getuid : user=root
 method 2 geteuid: user=root

 Is there a bug?

 EM

  Also, you want some error checking in there... :)
 
  JB.
 
  --
  Julien BLACHE   http://www.jblache.org
  jb at jblache.org  GPG KeyID 0xF5D65169




 --
 sane-devel mailing list: sane-devel at lists.alioth.debian.org
 http://lists.alioth.debian.org/mailman/listinfo/sane-devel
 Unsubscribe: Send mail with subject unsubscribe your_password
 to sane-devel-request at lists.alioth.debian.org




-- 
The truth is an offense, but not a sin



[sane-devel] [sane-commit] CVS update of sane-backends ( 3 files )

2008-12-06 Thread E. MARC
Le samedi 6 d?cembre 2008, ? 18:39, Nicolas Martin a ?crit?:
 Same on Ubuntu:

 $ ./getlgn
 method 1 getuid : user=nicolas
 method 2 geteuid: user=nicolas
 $ sudo ./getlgn
 [sudo] password for nicolas:
 method 1 getuid : user=root
 method 2 geteuid: user=root

 ?
so it works fine with both functions.
Why do you suggest Yep, use getuid() instead of geteuid() if you want to 
avoid that.?




[sane-devel] [sane-commit] CVS update of sane-backends (3 files)

2008-12-06 Thread Louis Lagendijk
ok, changed this according to the excellent suggestion by Julien. I
simply do not know why I never thought of this before. It is so obvious.

Louis L

On Sat, 2008-12-06 at 17:31 +0100, Julien BLACHE wrote:
 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