Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 178

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

diff --git a/lib/mounts.c b/lib/mounts.c
index c2a8f04..050ec8c 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -38,16 +38,17 @@ static const char kver_options_template[
 
 unsigned int query_kproto_ver(void)
 {
-	char options[MAX_OPTIONS_LEN + 1], *tmp;
+	char dir[] = "/tmp/autoXXXXXX", *t_dir;
+	char options[MAX_OPTIONS_LEN + 1];
 	pid_t pgrp = getpgrp();
 	int pipefd[2], ioctlfd, len;
 
-	tmp = tempnam(NULL, "auto");
-	if (mkdir(tmp, 0700) == -1)
+	t_dir = mkdtemp(dir);
+	if (!t_dir)
 		return 0;
 
 	if (pipe(pipefd) == -1) {
-		rmdir(tmp);
+		rmdir(t_dir);
 		return 0;
 	}
 
@@ -56,24 +57,24 @@ unsigned int query_kproto_ver(void)
 	if (len < 0) {
 		close(pipefd[0]);
 		close(pipefd[1]);
-		rmdir(tmp);
+		rmdir(t_dir);
 		return 0;
 	}
 
-	if (mount("automount", tmp, "autofs", MS_MGC_VAL, options)) {
+	if (mount("automount", t_dir, "autofs", MS_MGC_VAL, options)) {
 		close(pipefd[0]);
 		close(pipefd[1]);
-		rmdir(tmp);
+		rmdir(t_dir);
 		return 0;
 	}
 
 	close(pipefd[1]);
 
-	ioctlfd = open(tmp, O_RDONLY);
+	ioctlfd = open(t_dir, O_RDONLY);
 	if (ioctlfd == -1) {
-		umount(tmp);
+		umount(t_dir);
 		close(pipefd[0]);
-		rmdir(tmp);
+		rmdir(t_dir);
 		return 0;
 	}
 
@@ -82,25 +83,25 @@ unsigned int query_kproto_ver(void)
 	/* If this ioctl() doesn't work, it is kernel version 2 */
 	if (ioctl(ioctlfd, AUTOFS_IOC_PROTOVER, &kver.major) == -1) {
 		close(ioctlfd);
-		umount(tmp);
+		umount(t_dir);
 		close(pipefd[0]);
-		rmdir(tmp);
+		rmdir(t_dir);
 		return 0;
 	}
 
 	/* If this ioctl() doesn't work, version is 4 or less */
 	if (ioctl(ioctlfd, AUTOFS_IOC_PROTOSUBVER, &kver.minor) == -1) {
 		close(ioctlfd);
-		umount(tmp);
+		umount(t_dir);
 		close(pipefd[0]);
-		rmdir(tmp);
+		rmdir(t_dir);
 		return 0;
 	}
 
 	close(ioctlfd);
-	umount(tmp);
+	umount(t_dir);
 	close(pipefd[0]);
-	rmdir(tmp);
+	rmdir(t_dir);
 
 	return 1;
 }
diff --git a/modules/mount_bind.c b/modules/mount_bind.c
index 1cdb1c6..e76e5ee 100644
--- a/modules/mount_bind.c
+++ b/modules/mount_bind.c
@@ -34,46 +34,39 @@ static int bind_works = 0;
 
 int mount_init(void **context)
 {
-	char *tmp1 = tempnam(NULL, "auto");
-	char *tmp2 = tempnam(NULL, "auto");
+	char tmp1[] = "/tmp/autoXXXXXX", *t1_dir;
+	char tmp2[] = "/tmp/autoXXXXXX", *t2_dir;
 	int err;
 	struct stat st1, st2;
 
-	if (tmp1 == NULL || tmp2 == NULL) {
-		if (tmp1)
-			free(tmp1);
-		if (tmp2)
-			free(tmp2);
+	t1_dir = mkdtemp(tmp1);
+	t2_dir = mkdtemp(tmp2);
+	if (t1_dir == NULL || t2_dir == NULL) {
+		if (t1_dir)
+			rmdir(t1_dir);
+		if (t2_dir)
+			rmdir(t2_dir);
 		return 0;
 	}
 
-	if (mkdir(tmp1, 0700) == -1)
-		goto out2;
-
-	if (mkdir(tmp2, 0700) == -1)
-		goto out1;
-
-	if (lstat(tmp1, &st1) == -1)
+	if (lstat(t1_dir, &st1) == -1)
 		goto out;
 
-	err = spawn_mount(log_debug, "-n", "--bind", tmp1, tmp2, NULL);
+	err = spawn_mount(log_debug, "-n", "--bind", t1_dir, t2_dir, NULL);
 	if (err == 0 &&
-	    lstat(tmp2, &st2) == 0 &&
+	    lstat(t2_dir, &st2) == 0 &&
 	    st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) {
 		bind_works = 1;
 	}
 
 	debug(LOGOPT_NONE, MODPREFIX "bind_works = %d", bind_works);
 
-	spawn_umount(log_debug, "-n", tmp2, NULL);
+	spawn_umount(log_debug, "-n", t2_dir, NULL);
+
+out:
+	rmdir(t2_dir);
+	rmdir(t2_dir);
 
-      out:
-	rmdir(tmp2);
-      out1:
-	free(tmp2);
-	rmdir(tmp1);
-      out2:
-	free(tmp1);
 	return 0;
 }