diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2008-06-10 20:30:18 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2008-06-10 20:30:18 +0000 |
commit | 553d8a18c295273a72b19fbe92a9567c017ec055 (patch) | |
tree | cfe4924c62451837463ed582cda1acb1f8cb0333 /usr.bin | |
parent | 3594b1e4ab8ba4fad0740eb82aa8e520b2723fa4 (diff) |
properly inherit file permissions.
reported & tested by phessler@
input otto@ deraadt@
ok tobias@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/checkout.c | 18 | ||||
-rw-r--r-- | usr.bin/cvs/import.c | 15 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.c | 8 |
3 files changed, 32 insertions, 9 deletions
diff --git a/usr.bin/cvs/checkout.c b/usr.bin/cvs/checkout.c index 13574b4f511..d4b9fd99f49 100644 --- a/usr.bin/cvs/checkout.c +++ b/usr.bin/cvs/checkout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: checkout.c,v 1.147 2008/06/10 01:00:34 joris Exp $ */ +/* $OpenBSD: checkout.c,v 1.148 2008/06/10 20:30:17 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -430,6 +430,7 @@ checkout_repository(const char *repobase, const char *wdbase) void cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags) { + mode_t mode; int cf_kflag, exists, fd; time_t rcstime; CVSENTRIES *ent; @@ -475,7 +476,10 @@ cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags) cvs_merge_file(cf, (cvs_join_rev1 == NULL)); } - if (fchmod(cf->fd, 0644) == -1) + mode = cf->file_rcs->rf_mode; + mode |= S_IWUSR; + + if (fchmod(cf->fd, mode) == -1) fatal("cvs_checkout_file: fchmod: %s", strerror(errno)); if ((exists == 0) && (cf->file_ent == NULL) && @@ -570,6 +574,16 @@ cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags) fd = rcs_rev_write_stmp(cf->file_rcs, rnum, template, 0); + + mode = cf->file_rcs->rf_mode; + mode |= S_IWUSR; + + if (fchmod(fd, mode) == -1) { + cvs_log(LP_ERR, + "failed to set mode for %s", + cf->file_path); + } + tosend = template; } diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c index ca6f024d165..2c864660569 100644 --- a/usr.bin/cvs/import.c +++ b/usr.bin/cvs/import.c @@ -1,4 +1,4 @@ -/* $OpenBSD: import.c,v 1.94 2008/06/10 02:11:19 tobias Exp $ */ +/* $OpenBSD: import.c,v 1.95 2008/06/10 20:30:17 joris Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -292,6 +292,7 @@ import_new(struct cvs_file *cf) { int i; BUF *bp; + mode_t mode; time_t tstamp; struct stat st; struct rcs_branch *brp; @@ -307,12 +308,13 @@ import_new(struct cvs_file *cf) return; } - if (dflag == 1) { - if (fstat(cf->fd, &st) == -1) - fatal("import_new: %s", strerror(errno)); + if (fstat(cf->fd, &st) == -1) + fatal("import_new: %s", strerror(errno)); + mode = st.st_mode; + + if (dflag == 1) tstamp = st.st_mtime; - } if ((branch = rcsnum_parse(import_branch)) == NULL) fatal("import_new: failed to parse branch"); @@ -326,7 +328,8 @@ import_new(struct cvs_file *cf) if (cf->repo_fd < 0) fatal("import_new: %s: %s", cf->file_rpath, strerror(errno)); - cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd, RCS_CREATE, 0444); + cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd, RCS_CREATE, + (mode & ~(S_IWUSR | S_IWGRP | S_IWOTH))); if (cf->file_rcs == NULL) fatal("import_new: failed to create RCS file for %s", cf->file_path); diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 024dba9e019..0fcc3b4ddc4 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.268 2008/06/10 16:05:04 joris Exp $ */ +/* $OpenBSD: rcs.c,v 1.269 2008/06/10 20:30:17 joris Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -244,6 +244,7 @@ rcs_open(const char *path, int fd, int flags, ...) mode_t fmode; RCSFILE *rfp; va_list vap; + struct stat st; struct rcs_delta *rdp; struct rcs_lock *lkr; @@ -255,6 +256,10 @@ rcs_open(const char *path, int fd, int flags, ...) mode = va_arg(vap, int); va_end(vap); fmode = (mode_t)mode; + } else { + if (fstat(fd, &st) == -1) + fatal("rcs_open: %s: fstat: %s", path, strerror(errno)); + fmode = st.st_mode; } fmode &= ~cvs_umask; @@ -498,6 +503,7 @@ rcs_write(RCSFILE *rfp) } fputs("@\n", fp); } + if (fchmod(fd, rfp->rf_mode) == -1) { saved_errno = errno; (void)unlink(fn); |