]>
Commit | Line | Data |
---|---|---|
408e1e99 | 1 | Index: dcopserver.cpp |
2 | =================================================================== | |
3 | RCS file: /home/kde/kdelibs/dcop/dcopserver.cpp,v | |
4 | retrieving revision 1.160.2.3 | |
5 | diff -u -p -r1.160.2.3 dcopserver.cpp | |
6 | --- kdelibs/dcop/dcopserver.cpp 30 Apr 2004 15:00:08 -0000 1.160.2.3 | |
7 | +++ kdelibs/dcop/dcopserver.cpp 26 Jul 2004 09:03:06 -0000 | |
8 | @@ -443,35 +443,78 @@ write_iceauth (FILE *addfp, IceAuthDataE | |
9 | fprintf (addfp, "\n"); | |
10 | } | |
11 | ||
12 | +#ifndef HAVE_MKSTEMPS | |
13 | +#include <string.h> | |
14 | +#include <strings.h> | |
15 | ||
16 | -#ifndef HAVE_MKSTEMP | |
17 | -static char *unique_filename (const char *path, const char *prefix) | |
18 | -#else | |
19 | -static char *unique_filename (const char *path, const char *prefix, int *pFd) | |
20 | -#endif | |
21 | +/* this is based on code taken from the GNU libc, distributed under the LGPL license */ | |
22 | + | |
23 | +/* Generate a unique temporary file name from TEMPLATE. | |
24 | + | |
25 | + TEMPLATE has the form: | |
26 | + | |
27 | + <path>/ccXXXXXX<suffix> | |
28 | + | |
29 | + SUFFIX_LEN tells us how long <suffix> is (it can be zero length). | |
30 | + | |
31 | + The last six characters of TEMPLATE before <suffix> must be "XXXXXX"; | |
32 | + they are replaced with a string that makes the filename unique. | |
33 | + | |
34 | + Returns a file descriptor open on the file for reading and writing. */ | |
35 | + | |
36 | +int mkstemps (char* _template, int suffix_len) | |
37 | { | |
38 | -#ifndef HAVE_MKSTEMP | |
39 | -#ifndef X_NOT_POSIX | |
40 | - return ((char *) tempnam (path, prefix)); | |
41 | -#else | |
42 | - char tempFile[PATH_MAX]; | |
43 | - char *tmp; | |
44 | + static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
45 | + char *XXXXXX; | |
46 | + int len; | |
47 | + int count; | |
48 | + int value; | |
49 | + | |
50 | + len = strlen (_template); | |
51 | + | |
52 | + if ((int) len < 6 + suffix_len || strncmp (&_template[len - 6 - suffix_len], "XXXXXX", 6)) | |
53 | + return -1; | |
54 | + | |
55 | + XXXXXX = &_template[len - 6 - suffix_len]; | |
56 | + | |
57 | + value = rand(); | |
58 | + for (count = 0; count < 256; ++count) | |
59 | + { | |
60 | + int v = value; | |
61 | + int fd; | |
62 | + | |
63 | + /* Fill in the random bits. */ | |
64 | + XXXXXX[0] = letters[v % 62]; | |
65 | + v /= 62; | |
66 | + XXXXXX[1] = letters[v % 62]; | |
67 | + v /= 62; | |
68 | + XXXXXX[2] = letters[v % 62]; | |
69 | + v /= 62; | |
70 | + XXXXXX[3] = letters[v % 62]; | |
71 | + v /= 62; | |
72 | + XXXXXX[4] = letters[v % 62]; | |
73 | + v /= 62; | |
74 | + XXXXXX[5] = letters[v % 62]; | |
75 | + | |
76 | + fd = open (_template, O_RDWR|O_CREAT|O_EXCL, 0600); | |
77 | + if (fd >= 0) | |
78 | + /* The file does not exist. */ | |
79 | + return fd; | |
80 | + | |
81 | + /* This is a random value. It is only necessary that the next | |
82 | + TMP_MAX values generated by adding 7777 to VALUE are different | |
83 | + with (module 2^32). */ | |
84 | + value += 7777; | |
85 | + } | |
86 | + /* We return the null string if we can't find a unique file name. */ | |
87 | + _template[0] = '\0'; | |
88 | + return -1; | |
89 | +} | |
90 | ||
91 | - snprintf (tempFile, PATH_MAX, "%s/%sXXXXXX", path, prefix); | |
92 | - tmp = (char *) mktemp (tempFile); | |
93 | - if (tmp) | |
94 | - { | |
95 | - char *ptr = (char *) malloc (strlen (tmp) + 1); | |
96 | - if (ptr != NULL) | |
97 | - { | |
98 | - strcpy (ptr, tmp); | |
99 | - } | |
100 | - return (ptr); | |
101 | - } | |
102 | - else | |
103 | - return (NULL); | |
104 | #endif | |
105 | -#else | |
106 | + | |
107 | +static char *unique_filename (const char *path, const char *prefix, int *pFd) | |
108 | +{ | |
109 | char tempFile[PATH_MAX]; | |
110 | char *ptr; | |
111 | ||
112 | @@ -480,43 +523,10 @@ static char *unique_filename (const char | |
113 | if (ptr != NULL) | |
114 | { | |
115 | strcpy(ptr, tempFile); | |
116 | - *pFd = mkstemp(ptr); | |
117 | + *pFd = mkstemps(ptr, 0); | |
118 | } | |
119 | return ptr; | |
120 | -#endif | |
121 | -} | |
122 | - | |
123 | -#if 0 | |
124 | -Status SetAuthentication_local (int count, IceListenObj *listenObjs) | |
125 | -{ | |
126 | - int i; | |
127 | - for (i = 0; i < count; i ++) { | |
128 | - char *prot = IceGetListenConnectionString(listenObjs[i]); | |
129 | - if (!prot) continue; | |
130 | - char *host = strchr(prot, '/'); | |
131 | - char *sock = 0; | |
132 | - if (host) { | |
133 | - *host=0; | |
134 | - host++; | |
135 | - sock = strchr(host, ':'); | |
136 | - if (sock) { | |
137 | - *sock = 0; | |
138 | - sock++; | |
139 | - } | |
140 | - } | |
141 | -#ifndef NDEBUG | |
142 | - qDebug("DCOPServer: SetAProc_loc: conn %d, prot=%s, file=%s", | |
143 | - (unsigned)i, prot, sock); | |
144 | -#endif | |
145 | - if (sock && !strcmp(prot, "local")) { | |
146 | - chmod(sock, 0700); | |
147 | - } | |
148 | - IceSetHostBasedAuthProc (listenObjs[i], HostBasedAuthProc); | |
149 | - free(prot); | |
150 | - } | |
151 | - return 1; | |
152 | } | |
153 | -#endif | |
154 | ||
155 | #define MAGIC_COOKIE_LEN 16 | |
156 | ||
157 | @@ -529,28 +539,19 @@ SetAuthentication (int count, IceListenO | |
158 | int original_umask; | |
159 | int i; | |
160 | QCString command; | |
161 | -#ifdef HAVE_MKSTEMP | |
162 | int fd; | |
163 | -#endif | |
164 | ||
165 | original_umask = umask (0077); /* disallow non-owner access */ | |
166 | ||
167 | path = getenv ("DCOP_SAVE_DIR"); | |
168 | if (!path) | |
169 | path = "/tmp"; | |
170 | -#ifndef HAVE_MKSTEMP | |
171 | - if ((addAuthFile = unique_filename (path, "dcop")) == NULL) | |
172 | - goto bad; | |
173 | ||
174 | - if (!(addfp = fopen (addAuthFile, "w"))) | |
175 | - goto bad; | |
176 | -#else | |
177 | if ((addAuthFile = unique_filename (path, "dcop", &fd)) == NULL) | |
178 | goto bad; | |
179 | ||
180 | if (!(addfp = fdopen(fd, "wb"))) | |
181 | goto bad; | |
182 | -#endif | |
183 | ||
184 | if ((*_authDataEntries = static_cast<IceAuthDataEntry *>(malloc (count * 2 * sizeof (IceAuthDataEntry)))) == NULL) | |
185 | goto bad; |