summaryrefslogtreecommitdiff
path: root/devel/cvs-devel/files/patch-homedir
blob: 44961cb36123b5221c8501a08dc0a1d4c6ba1b9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Fix handling of homedirectory for pserver, patch from
#  Jim Studt <jim@federated.com>. Closes: Bug#51234
diff -Nur src/filesubr.c src/filesubr.c
--- src/filesubr.c	2005-09-28 23:25:59.000000000 +0800
+++ src/filesubr.c	2006-02-26 22:31:57.000000000 +0800
@@ -795,6 +795,11 @@
    The workaround is to put -f in inetd.conf which means that
    get_homedir won't get called until after the switch in user ID.
 
+   NOTE: the above paragraph is not sufficient if the HOME environment
+   variable is set, it overrides the uid based password lookup, hence
+   the change_uid logic path that blocks the HOME environment variable
+   when the uid gets changed.
+
    The whole concept of a "home directory" on the server is pretty
    iffy, although I suppose some people probably are relying on it for
    .cvsrc and such, in the cases where it works.  */
@@ -802,15 +807,24 @@
 get_homedir (void)
 {
     static char *home = NULL;
+    static uid_t home_uid = 0;
+    static int changed_uid = 0;
     char *env;
+    uid_t uid = getuid();
     struct passwd *pw;
 
+    if ( home && home_uid != uid) {
+        home = 0;
+        home_uid = uid;
+        changed_uid = 1;
+    }
+
     if (home != NULL)
 	return home;
 
-    if (!server_active && (env = getenv ("HOME")) != NULL)
+    if (!server_active && ((env = getenv ("HOME")) != NULL) && !changed_uid)
 	home = env;
-    else if ((pw = (struct passwd *) getpwuid (getuid ()))
+    else if ((pw = (struct passwd *) getpwuid (uid))
 	     && pw->pw_dir)
 	home = xstrdup (pw->pw_dir);
     else