View | Details | Raw Unified | Return to bug 58298
Collapse All | Expand All

(-)dcopserver.cpp (-68 / +69 lines)
Lines 443-477 write_iceauth (FILE *addfp, IceAuthDataE Link Here
443
    fprintf (addfp, "\n");
443
    fprintf (addfp, "\n");
444
}
444
}
445
445
446
#ifndef HAVE_MKSTEMPS
447
#include <string.h>
448
#include <strings.h>
446
449
447
#ifndef HAVE_MKSTEMP
450
/* this is based on code taken from the GNU libc, distributed under the LGPL license */
448
static char *unique_filename (const char *path, const char *prefix)
451
449
#else
452
/* Generate a unique temporary file name from TEMPLATE.
450
static char *unique_filename (const char *path, const char *prefix, int *pFd)
453
451
#endif
454
   TEMPLATE has the form:
455
456
   <path>/ccXXXXXX<suffix>
457
458
   SUFFIX_LEN tells us how long <suffix> is (it can be zero length).
459
460
   The last six characters of TEMPLATE before <suffix> must be "XXXXXX";
461
   they are replaced with a string that makes the filename unique.
462
463
   Returns a file descriptor open on the file for reading and writing.  */
464
465
int mkstemps (char* _template, int suffix_len)
452
{
466
{
453
#ifndef HAVE_MKSTEMP
467
  static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
454
#ifndef X_NOT_POSIX
468
  char *XXXXXX;
455
    return ((char *) tempnam (path, prefix));
469
  int len;
456
#else
470
  int count;
457
    char tempFile[PATH_MAX];
471
  int value;
458
    char *tmp;
472
473
  len = strlen (_template);
474
475
  if ((int) len < 6 + suffix_len || strncmp (&_template[len - 6 - suffix_len], "XXXXXX", 6))
476
      return -1;
477
478
  XXXXXX = &_template[len - 6 - suffix_len];
479
480
  value = rand();
481
  for (count = 0; count < 256; ++count)
482
  {
483
      int v = value;
484
      int fd;
485
486
      /* Fill in the random bits.  */
487
      XXXXXX[0] = letters[v % 62];
488
      v /= 62;
489
      XXXXXX[1] = letters[v % 62];
490
      v /= 62;
491
      XXXXXX[2] = letters[v % 62];
492
      v /= 62;
493
      XXXXXX[3] = letters[v % 62];
494
      v /= 62;
495
      XXXXXX[4] = letters[v % 62];
496
      v /= 62;
497
      XXXXXX[5] = letters[v % 62];
498
499
      fd = open (_template, O_RDWR|O_CREAT|O_EXCL, 0600);
500
      if (fd >= 0)
501
	/* The file does not exist.  */
502
	return fd;
503
504
      /* This is a random value.  It is only necessary that the next
505
	 TMP_MAX values generated by adding 7777 to VALUE are different
506
	 with (module 2^32).  */
507
      value += 7777;
508
    }
509
  /* We return the null string if we can't find a unique file name.  */
510
  _template[0] = '\0';
511
  return -1;
512
}
459
513
460
    snprintf (tempFile, PATH_MAX, "%s/%sXXXXXX", path, prefix);
461
    tmp = (char *) mktemp (tempFile);
462
    if (tmp)
463
	{
464
	    char *ptr = (char *) malloc (strlen (tmp) + 1);
465
        if (ptr != NULL)
466
        {
467
	        strcpy (ptr, tmp);
468
        }
469
	    return (ptr);
470
	}
471
    else
472
	return (NULL);
473
#endif
514
#endif
474
#else
515
516
static char *unique_filename (const char *path, const char *prefix, int *pFd)
517
{
475
    char tempFile[PATH_MAX];
518
    char tempFile[PATH_MAX];
476
    char *ptr;
519
    char *ptr;
477
520
Lines 480-522 static char *unique_filename (const char Link Here
480
    if (ptr != NULL)
523
    if (ptr != NULL)
481
	{
524
	{
482
	    strcpy(ptr, tempFile);
525
	    strcpy(ptr, tempFile);
483
	    *pFd =  mkstemp(ptr);
526
	    *pFd =  mkstemps(ptr, 0);
484
	}
527
	}
485
    return ptr;
528
    return ptr;
486
#endif
487
}
488
489
#if 0
490
Status SetAuthentication_local (int count, IceListenObj *listenObjs)
491
{
492
    int i;
493
    for (i = 0; i < count; i ++) {
494
	char *prot = IceGetListenConnectionString(listenObjs[i]);
495
	if (!prot) continue;
496
	char *host = strchr(prot, '/');
497
	char *sock = 0;
498
	if (host) {
499
	    *host=0;
500
	    host++;
501
	    sock = strchr(host, ':');
502
	    if (sock) {
503
		*sock = 0;
504
		sock++;
505
	    }
506
	}
507
#ifndef NDEBUG
508
	qDebug("DCOPServer: SetAProc_loc: conn %d, prot=%s, file=%s",
509
		(unsigned)i, prot, sock);
510
#endif
511
	if (sock && !strcmp(prot, "local")) {
512
	    chmod(sock, 0700);
513
	}
514
	IceSetHostBasedAuthProc (listenObjs[i], HostBasedAuthProc);
515
	free(prot);
516
    }
517
    return 1;
518
}
529
}
519
#endif
520
530
521
#define MAGIC_COOKIE_LEN 16
531
#define MAGIC_COOKIE_LEN 16
522
532
Lines 529-556 SetAuthentication (int count, IceListenO Link Here
529
    int         original_umask;
539
    int         original_umask;
530
    int         i;
540
    int         i;
531
    QCString command;    
541
    QCString command;    
532
#ifdef HAVE_MKSTEMP
533
    int         fd;
542
    int         fd;
534
#endif
535
543
536
    original_umask = umask (0077);      /* disallow non-owner access */
544
    original_umask = umask (0077);      /* disallow non-owner access */
537
545
538
    path = getenv ("DCOP_SAVE_DIR");
546
    path = getenv ("DCOP_SAVE_DIR");
539
    if (!path)
547
    if (!path)
540
	path = "/tmp";
548
	path = "/tmp";
541
#ifndef HAVE_MKSTEMP
542
    if ((addAuthFile = unique_filename (path, "dcop")) == NULL)
543
	goto bad;
544
549
545
    if (!(addfp = fopen (addAuthFile, "w")))
546
	goto bad;
547
#else
548
    if ((addAuthFile = unique_filename (path, "dcop", &fd)) == NULL)
550
    if ((addAuthFile = unique_filename (path, "dcop", &fd)) == NULL)
549
	goto bad;
551
	goto bad;
550
552
551
    if (!(addfp = fdopen(fd, "wb")))
553
    if (!(addfp = fdopen(fd, "wb")))
552
	goto bad;
554
	goto bad;
553
#endif
554
555
555
    if ((*_authDataEntries = static_cast<IceAuthDataEntry *>(malloc (count * 2 * sizeof (IceAuthDataEntry)))) == NULL)
556
    if ((*_authDataEntries = static_cast<IceAuthDataEntry *>(malloc (count * 2 * sizeof (IceAuthDataEntry)))) == NULL)
556
	goto bad;
557
	goto bad;

Return to bug 58298