summaryrefslogtreecommitdiff
path: root/x11/kdelibs3/patches/patch-ap
blob: be7c6ece98067d480f8335649d5800a49dd1f222 (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
$NetBSD: patch-ap,v 1.7.4.1 2004/08/13 13:05:05 agc Exp $

Index: dcopserver.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopserver.cpp,v
retrieving revision 1.160.2.3
diff -u -p -r1.160.2.3 dcopserver.cpp
--- dcop/dcopserver.cpp	30 Apr 2004 15:00:08 -0000	1.160.2.3
+++ dcop/dcopserver.cpp	26 Jul 2004 09:03:06 -0000
@@ -443,35 +443,78 @@ write_iceauth (FILE *addfp, IceAuthDataE
     fprintf (addfp, "\n");
 }
 
+#ifndef HAVE_MKSTEMPS
+#include <string.h>
+#include <strings.h>
 
-#ifndef HAVE_MKSTEMP
-static char *unique_filename (const char *path, const char *prefix)
-#else
-static char *unique_filename (const char *path, const char *prefix, int *pFd)
-#endif
+/* this is based on code taken from the GNU libc, distributed under the LGPL license */
+
+/* Generate a unique temporary file name from TEMPLATE.
+
+   TEMPLATE has the form:
+
+   <path>/ccXXXXXX<suffix>
+
+   SUFFIX_LEN tells us how long <suffix> is (it can be zero length).
+
+   The last six characters of TEMPLATE before <suffix> must be "XXXXXX";
+   they are replaced with a string that makes the filename unique.
+
+   Returns a file descriptor open on the file for reading and writing.  */
+
+int mkstemps (char* _template, int suffix_len)
 {
-#ifndef HAVE_MKSTEMP
-#ifndef X_NOT_POSIX
-    return ((char *) tempnam (path, prefix));
-#else
-    char tempFile[PATH_MAX];
-    char *tmp;
+  static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+  char *XXXXXX;
+  int len;
+  int count;
+  int value;
+
+  len = strlen (_template);
+
+  if ((int) len < 6 + suffix_len || strncmp (&_template[len - 6 - suffix_len], "XXXXXX", 6))
+      return -1;
+
+  XXXXXX = &_template[len - 6 - suffix_len];
+
+  value = rand();
+  for (count = 0; count < 256; ++count)
+  {
+      int v = value;
+      int fd;
+
+      /* Fill in the random bits.  */
+      XXXXXX[0] = letters[v % 62];
+      v /= 62;
+      XXXXXX[1] = letters[v % 62];
+      v /= 62;
+      XXXXXX[2] = letters[v % 62];
+      v /= 62;
+      XXXXXX[3] = letters[v % 62];
+      v /= 62;
+      XXXXXX[4] = letters[v % 62];
+      v /= 62;
+      XXXXXX[5] = letters[v % 62];
+
+      fd = open (_template, O_RDWR|O_CREAT|O_EXCL, 0600);
+      if (fd >= 0)
+	/* The file does not exist.  */
+	return fd;
+
+      /* This is a random value.  It is only necessary that the next
+	 TMP_MAX values generated by adding 7777 to VALUE are different
+	 with (module 2^32).  */
+      value += 7777;
+    }
+  /* We return the null string if we can't find a unique file name.  */
+  _template[0] = '\0';
+  return -1;
+}
 
-    snprintf (tempFile, PATH_MAX, "%s/%sXXXXXX", path, prefix);
-    tmp = (char *) mktemp (tempFile);
-    if (tmp)
-	{
-	    char *ptr = (char *) malloc (strlen (tmp) + 1);
-        if (ptr != NULL)
-        {
-	        strcpy (ptr, tmp);
-        }
-	    return (ptr);
-	}
-    else
-	return (NULL);
 #endif
-#else
+
+static char *unique_filename (const char *path, const char *prefix, int *pFd)
+{
     char tempFile[PATH_MAX];
     char *ptr;
 
@@ -480,43 +523,10 @@ static char *unique_filename (const char
     if (ptr != NULL)
 	{
 	    strcpy(ptr, tempFile);
-	    *pFd =  mkstemp(ptr);
+	    *pFd =  mkstemps(ptr, 0);
 	}
     return ptr;
-#endif
-}
-
-#if 0
-Status SetAuthentication_local (int count, IceListenObj *listenObjs)
-{
-    int i;
-    for (i = 0; i < count; i ++) {
-	char *prot = IceGetListenConnectionString(listenObjs[i]);
-	if (!prot) continue;
-	char *host = strchr(prot, '/');
-	char *sock = 0;
-	if (host) {
-	    *host=0;
-	    host++;
-	    sock = strchr(host, ':');
-	    if (sock) {
-		*sock = 0;
-		sock++;
-	    }
-	}
-#ifndef NDEBUG
-	qDebug("DCOPServer: SetAProc_loc: conn %d, prot=%s, file=%s",
-		(unsigned)i, prot, sock);
-#endif
-	if (sock && !strcmp(prot, "local")) {
-	    chmod(sock, 0700);
-	}
-	IceSetHostBasedAuthProc (listenObjs[i], HostBasedAuthProc);
-	free(prot);
-    }
-    return 1;
 }
-#endif
 
 #define MAGIC_COOKIE_LEN 16
 
@@ -529,28 +539,19 @@ SetAuthentication (int count, IceListenO
     int         original_umask;
     int         i;
     QCString command;    
-#ifdef HAVE_MKSTEMP
     int         fd;
-#endif
 
     original_umask = umask (0077);      /* disallow non-owner access */
 
     path = getenv ("DCOP_SAVE_DIR");
     if (!path)
 	path = "/tmp";
-#ifndef HAVE_MKSTEMP
-    if ((addAuthFile = unique_filename (path, "dcop")) == NULL)
-	goto bad;
 
-    if (!(addfp = fopen (addAuthFile, "w")))
-	goto bad;
-#else
     if ((addAuthFile = unique_filename (path, "dcop", &fd)) == NULL)
 	goto bad;
 
     if (!(addfp = fdopen(fd, "wb")))
 	goto bad;
-#endif
 
     if ((*_authDataEntries = static_cast<IceAuthDataEntry *>(malloc (count * 2 * sizeof (IceAuthDataEntry)))) == NULL)
 	goto bad;