6399N/AUpstream fixes already included in the latest updates to coolkey v1.1.0
6399N/AAddresses cache directory, memory leak and compiler issues.
6399N/AAdded MAP_FILE definiton for Solaris.
6399N/A+bool OSLock::needThread = 0;
6399N/A+// Solaris specific - MAP_FILE needs to be defined
6399N/A // Windows functions to grab a named shared memory segment of a specific size,
6399N/A OSLock::OSLock(bool exceptionAllowed)
6399N/A InitializeCriticalSection(&lockData->mutex);
6399N/A #define RESERVED_OFFSET 256
6399N/A-#define MEMSEGPATH "/tmp/.pk11ipc"
6399N/A+#define MEMSEGPATH BASEPATH"/coolkey-lock"
6399N/A-#define MEMSEGPATH "/tmp/.pk11ipc1"
6399N/A+#define MEMSEGPATH BASEPATH"/coolkey"
6399N/A unsigned long ref = --(*(unsigned long *)addr);
6399N/A munmap(addr,size+RESERVED_OFFSET);
6399N/A+ * The cache directory is shared and accessible by anyone, make
6399N/A+ * sure the cache file we are opening is really a valid cache file.
6399N/A+int safe_open(char *path, int flags, int mode, int size)
6399N/A+ fd = open (path, flags|O_NOFOLLOW, mode);
6399N/A+ /* our cache files are pretty specific, make sure we are looking
6399N/A+ /* first, we should own the file ourselves, don't open a file
6399N/A+ * that someone else wanted us to see. */
6399N/A+ /* next, there should only be one link in this file. Don't
6399N/A+ * use this code to trash another file */
6399N/A+ /* next, This better be a regular file */
6399N/A+ /* if the permissions don't match, something is wrong */
6399N/A+ /* finally the file should be the correct size. This
6399N/A+ * check isn't so much to protect from an attack, as it is to
6399N/A+ * detect a corrupted cache file */
6399N/A+ /* OK, the file checked out, ok to continue */
6399N/A SHMem::SHMem(): shmemData(0) {}
6399N/A- int ret = mkdir (MEMSEGPATH, 0777);
6399N/A+ int ret = mkdir (MEMSEGPATH, 01777);
6399N/A if ((ret == -1) && (errno != EEXIST)) {
6399N/A shmemData->path[sizeof(MEMSEGPATH)-1] = '/';
6399N/A strcpy(&shmemData->path[sizeof(MEMSEGPATH)],name);
6399N/A- if (strcmp(name,"token_names") != 0) {
6399N/A- /* each user gets his own uid array */
6399N/A- sprintf(uid_str, "-%u",getuid());
6399N/A- strcat(shmemData->path,uid_str);
6399N/A+ sprintf(uid_str, "-%u",getuid());
6399N/A+ strcat(shmemData->path,uid_str);
6399N/A shmemData->fd = open(shmemData->path,
6399N/A O_CREAT|O_RDWR|O_EXCL|O_APPEND|O_EXLOCK, mode);
6399N/A- shmemData->fd = open(shmemData->path,O_RDWR|O_EXLOCK, mode);
6399N/A int len = size+RESERVED_OFFSET;
6399N/A buf = (char *)calloc(1,len);
6399N/A- write(shmemData->fd,buf,len);
6399N/A+ ret = write(shmemData->fd,buf,len);
6399N/A+ flock(shmemData->fd, LOCK_UN);
6399N/A+ } else if (errno == EEXIST) {
6399N/A+ shmemData->fd = safe_open(shmemData->path,O_RDWR|O_EXLOCK, mode,
6399N/A rc = pthread_mutexattr_init(&OSLock_attr);