Commit Message
On Mon, 2005-06-27 at 11:00 +0200, Ludwig Nussel wrote:
> Udo Richter wrote:
> >
> > Nice, but I'll have to merge it with the settime patch (using external
> > shell script to set time via sudo). Not a big deal, I'll write something
> > similar to yours.
>
> Let vdr do the user switching and save yourself from such hacks:
> http://www.suse.de/~lnussel/vdr/vdr-1.3.24-su.diff
Nifty. Attached is a patch (to be applied over the above one) that
makes it use the reentrant get*nam variants, making it compilable with a
"thread poison" patched VDR. Caveat: I don't claim to understand the
patch fully, it was mostly kind of borrowed from dbus :)
@@ -100,13 +100,17 @@
{
gid_t ngid = 0;
struct group* grp = NULL;
+ struct group grp_str;
struct passwd *user = NULL;
+ struct passwd user_str;
+ int result;
+ char buf[1024];
if(!username) return 0;
errno = 0;
- user = getpwnam(username);
- if(!user)
+ result = getpwnam_r(username, &user_str, buf, sizeof(buf), &user);
+ if (result != 0 || user != &user_str)
{
fprintf(stderr,"invalid user %s: %s\n",username,errno?strerror(errno):"user does not exist");
endpwent();
@@ -116,8 +120,8 @@
if(groupname)
{
errno = 0;
- grp = getgrnam(groupname);
- if(!grp)
+ result = getgrnam_r(groupname, &grp_str, buf, sizeof(buf), &grp);
+ if (result != 0 || grp != &grp_str)
{
fprintf(stderr,"invalid group %s: %s\n",groupname,errno?strerror(errno):"group does not exist");
endgrent();