summaryrefslogtreecommitdiffstats
path: root/opensuse/tdelibs/use-xauthlocalhostname.diff
blob: 42ef39b9c16e028ce4438065afa940e4afa3bb97 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Index: kinit/wrapper.c
===================================================================
--- kinit/wrapper.c.orig
+++ kinit/wrapper.c
@@ -164,7 +164,9 @@ static int openSocket()
      sock_file[strlen(sock_file)-1] = 0;
   
   strncat(sock_file, "/socket-", MAX_SOCK_FILE - strlen(sock_file));
-  if (gethostname(sock_file+strlen(sock_file), MAX_SOCK_FILE - strlen(sock_file) - 1) != 0)
+  if( getenv("XAUTHLOCALHOSTNAME"))
+      strncat(sock_file, getenv("XAUTHLOCALHOSTNAME"), MAX_SOCK_FILE - strlen(sock_file) - 1);
+  else if (gethostname(sock_file+strlen(sock_file), MAX_SOCK_FILE - strlen(sock_file) - 1) != 0)
   {
      perror("Warning: Could not determine hostname: ");
      return -1;
Index: kinit/lnusertemp.c
===================================================================
--- kinit/lnusertemp.c.orig
+++ kinit/lnusertemp.c
@@ -39,7 +39,7 @@
 
 int check_tmp_dir(const char *tmp_dir);
 int create_link(const char *file, const char *tmp_dir);
-int build_link(const char *tmp_prefix, const char *kde_prefix);
+int build_link(const char *tmp_prefix, const char *kde_prefix, int kdehostname);
 
 int check_tmp_dir(const char *tmp_dir)
 {
@@ -89,7 +89,7 @@ int create_link(const char *file, const
 }
 
 
-int build_link(const char *tmp_prefix, const char *kde_prefix)
+int build_link(const char *tmp_prefix, const char *kde_prefix, int kdehostname)
 {
   struct passwd *pw_ent;
   char kde_tmp_dir[PATH_MAX+1];
@@ -157,10 +157,21 @@ int build_link(const char *tmp_prefix, c
   }  
 
   strncat(kde_tmp_dir, kde_prefix, PATH_MAX - strlen(kde_tmp_dir));
-  if (gethostname(kde_tmp_dir+strlen(kde_tmp_dir), PATH_MAX - strlen(kde_tmp_dir) - 1) != 0)
+
+  if( kdehostname )
+  {
+      if( getenv("XAUTHLOCALHOSTNAME"))
+          strncat(kde_tmp_dir+strlen(kde_tmp_dir), getenv("XAUTHLOCALHOSTNAME"), PATH_MAX - strlen(kde_tmp_dir) - 1);
+      else
+          return 0;
+  }
+  else
   {
-     perror("Aborting. Could not determine hostname: ");
-     exit(255);
+     if (gethostname(kde_tmp_dir+strlen(kde_tmp_dir), PATH_MAX - strlen(kde_tmp_dir) - 1) != 0)
+     {
+        perror("Could not determine hostname: ");
+        return 1;
+     }
   }
   kde_tmp_dir[sizeof(kde_tmp_dir)-1] = '\0';
 
@@ -266,7 +277,9 @@ int main(int argc, char **argv)
     kde_prefix = "/cache-"; 
   }
 
-  res = build_link(tmp_prefix, kde_prefix); 
+  res = build_link(tmp_prefix, kde_prefix, 1); 
+  if( build_link(tmp_prefix, kde_prefix, 0))
+    res = 1;
     
   free(tmp_prefix);
 
Index: kdecore/kstandarddirs.cpp
===================================================================
--- kdecore/kstandarddirs.cpp.orig
+++ kdecore/kstandarddirs.cpp
@@ -719,7 +719,10 @@ void KStandardDirs::createSpecialResourc
 {
    char hostname[256];
    hostname[0] = 0;
-   gethostname(hostname, 255);
+   if( getenv("XAUTHLOCALHOSTNAME"))
+       strlcpy(hostname, getenv("XAUTHLOCALHOSTNAME"), 255 );
+   else
+       gethostname(hostname, 255);
    QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname);
    char link[1024];
    link[1023] = 0;
Index: kdecore/kcrash.cpp
===================================================================
--- kdecore/kcrash.cpp.orig
+++ kdecore/kcrash.cpp
@@ -466,7 +466,9 @@ static int openSocket()
      sock_file[strlen(sock_file)-1] = 0;
   
   strncat(sock_file, "/socket-", MAX_SOCK_FILE - strlen(sock_file));
-  if (gethostname(sock_file+strlen(sock_file), MAX_SOCK_FILE - strlen(sock_file) - 1) != 0)
+  if( getenv("XAUTHLOCALHOSTNAME"))
+      strncat(sock_file, getenv("XAUTHLOCALHOSTNAME"), MAX_SOCK_FILE - strlen(sock_file) - 1);
+  else if (gethostname(sock_file+strlen(sock_file), MAX_SOCK_FILE - strlen(sock_file) - 1) != 0)
   {
      perror("Warning: Could not determine hostname: ");
      return -1;
Index: dcop/dcopserver_shutdown.c
===================================================================
--- dcop/dcopserver_shutdown.c.orig
+++ dcop/dcopserver_shutdown.c
@@ -95,7 +95,9 @@ static void getDCOPFile(char *dcop_file,
   strncat(dcop_file, "/.DCOPserver_", n);
   n -= strlen("/.DCOPserver_");
 
-  if (gethostname(dcop_file+strlen(dcop_file), n) != 0)
+  if (getenv("XAUTHLOCALHOSTNAME"))
+     strncat(dcop_file+strlen(dcop_file), getenv("XAUTHLOCALHOSTNAME"), n);
+  else if (gethostname(dcop_file+strlen(dcop_file), n) != 0)
   {
      perror("Error. Could not determine hostname: ");
      dcop_file[0] = '\0';
Index: dcop/dcopc.c
===================================================================
--- dcop/dcopc.c.orig
+++ dcop/dcopc.c
@@ -684,7 +684,9 @@ dcop_connect()
     }
 
     hostName[0] = '\0';
-    if (gethostname(hostName, sizeof(hostName)))
+    if (getenv("XAUTHLOCALHOSTNAME"))
+            strlcpy(hostName, getenv("XAUTHLOCALHOSTNAME"),sizeof(hostName)-1);
+    else if (gethostname(hostName, sizeof(hostName)))
 	    strcpy(hostName, "localhost");
     else
 	    hostName[sizeof(hostName)-1] = '\0';
Index: dcop/dcopclient.cpp
===================================================================
--- dcop/dcopclient.cpp.orig
+++ dcop/dcopclient.cpp
@@ -277,7 +277,9 @@ static QCString dcopServerFile(const QCS
     {
         char hostName[256];
         hostName[0] = '\0';
-        if (gethostname(hostName, sizeof(hostName)))
+        if (getenv("XAUTHLOCALHOSTNAME"))
+            fName += getenv("XAUTHLOCALHOSTNAME");
+        else if (gethostname(hostName, sizeof(hostName)))
         {
             fName += "localhost";
         }
Index: dcop/KDE-ICE/Xtranssock.c
===================================================================
--- dcop/KDE-ICE/Xtranssock.c.orig
+++ dcop/KDE-ICE/Xtranssock.c
@@ -1444,6 +1444,7 @@ UnixHostReallyLocal (char *host)
 
 {
     char hostnamebuf[256];
+    char* xauthlocalname = getenv("XAUTHLOCALHOSTNAME");
 
     TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf));
 
@@ -1451,6 +1452,10 @@ UnixHostReallyLocal (char *host)
     {
 	return (1);
     }
+    else if(xauthlocalname && strcmp (xauthlocalname, host) == 0)
+    {
+       return (1);
+    }
     else
     {
 	/*
Index: kded/khostname.cpp
===================================================================
--- kded/khostname.cpp.orig
+++ kded/khostname.cpp
@@ -111,7 +111,8 @@ static QCStringList split(const QCString
 
 void KHostName::changeX()
 {
-   QString cmd = "xauth list";
+   const char* xauthlocalhostname = getenv("XAUTHLOCALHOSTNAME");
+   QString cmd = "xauth -n list";
    FILE *xFile = popen(QFile::encodeName(cmd), "r");
    if (!xFile)
    {
@@ -123,6 +124,7 @@ void KHostName::changeX()
       char buf[1024+1];
       while (!feof(xFile))
       {
+         buf[1024]='\0';
          QCString line = fgets(buf, 1024, xFile);
          if (line.length())
             line.truncate(line.length()-1); // Strip LF.
@@ -157,12 +159,17 @@ void KHostName::changeX()
       QCString newNetId = newName+netId.mid(i);
       QCString oldNetId = netId.left(i);
 
-      if(oldNetId != oldName)
-         continue;
+      if(oldNetId != oldName
+        && (!xauthlocalhostname || strcmp(xauthlocalhostname, oldNetId.data()) != 0))
+        continue;
 
-      cmd = "xauth remove "+KProcess::quote(netId);
-      system(QFile::encodeName(cmd));
-      cmd = "xauth add ";
+      // don't nuke the xauth when XAUTHLOCALHOSTNAME points to it
+      if (!xauthlocalhostname || oldNetId != xauthlocalhostname)
+      {
+        cmd = "xauth -n remove "+KProcess::quote(netId);
+        system(QFile::encodeName(cmd));
+      }
+      cmd = "xauth -n add ";
       cmd += KProcess::quote(newNetId);
       cmd += " ";
       cmd += KProcess::quote(authName);
@@ -276,7 +283,10 @@ void KHostName::changeDcop()
       }
    }
 
-   // Remove old entries
+   // Remove old entries, but only if XAUTHLOCALHOSTNAME doesn't point
+   // to it
+   char* xauthlocalhostname = getenv("XAUTHLOCALHOSTNAME");
+   if (!xauthlocalhostname || !oldNetId.contains(xauthlocalhostname))
    {
       QString cmd = "iceauth remove "+KProcess::quote("netid="+oldNetId);
       system(QFile::encodeName(cmd));
@@ -368,9 +378,7 @@ int main(int argc, char **argv)
 
    KHostName hn;
 
-   if(!getenv("XAUTHLOCALHOSTNAME"))
-       hn.changeX();
-
+   hn.changeX();
    hn.changeDcop();
    hn.changeStdDirs("socket");
    hn.changeStdDirs("tmp");