diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-09-06 22:59:43 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-09-06 22:59:43 +0000 |
commit | d50af4c519c6ee0ce2bd698450904743b4b3ae77 (patch) | |
tree | 07fab091d1598ffc728b6e654b884599460a9eeb | |
parent | d114ba0f293ba448ead9682d0fe25e37d395702b (diff) | |
download | net-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.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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); |