aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-09-06 22:59:43 +0000
committerMike Frysinger <vapier@gentoo.org>2009-09-06 22:59:43 +0000
commitd50af4c519c6ee0ce2bd698450904743b4b3ae77 (patch)
tree07fab091d1598ffc728b6e654b884599460a9eeb
parentenable -fno-strict-aliasing until the code base gets a hefty clean up to fix ... (diff)
downloadnet-tools-d50af4c519c6ee0ce2bd698450904743b4b3ae77.tar.gz
net-tools-d50af4c519c6ee0ce2bd698450904743b4b3ae77.tar.bz2
net-tools-d50af4c519c6ee0ce2bd698450904743b4b3ae77.zip
slattach: use fchown() rather than chown() to avoid race between creation and permission changing
-rw-r--r--slattach.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/slattach.c b/slattach.c
index 2e50896..d2b6f3c 100644
--- a/slattach.c
+++ b/slattach.c
@@ -73,7 +73,7 @@
const char *Release = RELEASE,
- *Version = "$Id: slattach.c,v 1.11 2005/12/04 05:15:36 ecki Exp $",
+ *Version = "$Id: slattach.c,v 1.12 2009/09/06 22:59:43 vapier Exp $",
*Signature = "net-tools, Fred N. van Kempen et al.";
@@ -195,15 +195,17 @@ tty_lock(char *path, int mode)
return(-1);
}
- (void) close(fd);
-
/* Make sure UUCP owns the lockfile. Required by some packages. */
if ((pw = getpwnam(_UID_UUCP)) == NULL) {
if (opt_q == 0) fprintf(stderr, _("slattach: tty_lock: UUCP user %s unknown!\n"),
_UID_UUCP);
+ (void) close(fd);
return(0); /* keep the lock anyway */
}
- (void) chown(saved_path, pw->pw_uid, pw->pw_gid);
+ (void) fchown(fd, pw->pw_uid, pw->pw_gid);
+
+ (void) close(fd);
+
saved_lock = 1;
} else { /* unlock */
if (saved_lock != 1) return(0);