time warp

Message ID 1119880706.22291.207.camel@localhost.localdomain
State New
Headers

Commit Message

Ville Skyttä June 27, 2005, 1:58 p.m. UTC
  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 :)
  

Patch

--- vdr.c~	2005-06-27 12:22:26.000000000 +0300
+++ vdr.c	2005-06-27 12:45:13.000000000 +0300
@@ -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();