[Home]WikiPatches/UseSystemLogin

UseModWiki | WikiPatches | RecentChanges | Preferences

On our system, we use http authentication to restrict Wiki access. You must be a valid system user to be allowed to access the Wiki. Since we did not want to then have to log in to the Wiki to set a user name, I wrote this patch to use the REMOTE_USER login, and retrieve the corresponding system user from that. The Wiki uid is the system uid + 5000.

This seems to work fine, but any suggestions on improvements are welcome. I am not sure whether preferences work properly without setting a password manually.

--- wiki.pl	2003/03/05 09:39:37	1.18
+++ wiki.pl	2003/03/06 15:02:17	1.21
@@ -335,7 +335,16 @@
   $UserID = $UserCookie{'id'};
   $UserID =~ s/\D//g;  # Numeric only
   if ($UserID < 200) {
-    $UserID = 111;
+    if (defined $ENV{REMOTE_USER})
+    {
+      # Use system uid + 5000 as user ID
+      my $httpuser = $ENV{REMOTE_USER};
+      $UserID = getpwnam($httpuser) + 5000;
+    }
+    else
+    {
+      $UserID = 111;
+    }
   } else {
     &LoadUserData($UserID);
   }
@@ -2435,6 +2444,15 @@
       $result = $UserData{$name};
     } else {
       $result = $default;
+    }
+  }
+  if ($name eq "username" && $result eq "")
+  { # Quick hack to use http authentication user name if defined
+    if (defined $ENV{REMOTE_USER})
+    {
+      my $httpuser = $ENV{REMOTE_USER};
+      my $realname = (split(/,/, (getpwnam($httpuser))[6]))[0] || '';
+      $result = $realname eq '' ? $httpuser : $realname;
     }
   }
   return $result;

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited October 22, 2007 8:23 am by JuanmaMP (diff)
Search: