mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
4.7 KiB

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