4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Unix: There is a small chance that the ownership of the wrong file
13 Solution: Use fchown() instead of chown() for the viminfo file and the
15 Files: src/ex_cmds.c, src/fileio.c
18 *** ../vim-6.4.001/src/ex_cmds.c Thu Jul 21 22:23:54 2005
19 --- src/ex_cmds.c Tue Nov 29 17:23:48 2005
31 static int linelen __ARGS((int *has_tab));
38 ! fp_out = mch_fopen((char *)tempname, WRITEBIN);
41 * If we can't create in the same directory, try creating a
48 ! /* Use mch_open() to be able to use O_EXCL and set file
49 ! * protection same as original file, but strip s-bit. */
51 ! fd = mch_open((char *)tempname,
52 ! O_CREAT|O_EXTRA|O_EXCL|O_WRONLY,
53 ! (int)((st_old.st_mode & 0777) | 0600));
55 ! fd = mch_open((char *)tempname,
56 ! O_CREAT|O_EXTRA|O_EXCL|O_WRONLY,
57 ! 0600); /* r&w for user only */
62 ! fp_out = fdopen(fd, WRITEBIN);
65 * If we can't create in the same directory, try creating a
68 if ((tempname = vim_tempname('o')) != NULL)
69 fp_out = mch_fopen((char *)tempname, WRITEBIN);
73 ! * Set file protection same as original file, but strip s-bit
74 ! * and make sure the owner can read/write it.
78 ! (void)mch_setperm(tempname,
79 ! (long)((st_old.st_mode & 0777) | 0600));
80 ! /* this only works for root: */
81 ! (void)chown((char *)tempname, st_old.st_uid, st_old.st_gid);
87 if ((tempname = vim_tempname('o')) != NULL)
88 fp_out = mch_fopen((char *)tempname, WRITEBIN);
91 ! #if defined(UNIX) && defined(HAVE_FCHOWN)
93 ! * Make sure the owner can read/write it. This only works for
97 ! (void)fchown(fileno(fp_out), st_old.st_uid, st_old.st_gid);
101 *** ../vim-6.4.001/src/fileio.c Fri Mar 18 19:16:29 2005
102 --- src/fileio.c Tue Nov 29 16:51:26 2005
105 if (st_old.st_nlink > 1
106 || mch_lstat((char *)fname, &st) < 0
107 || st.st_dev != st_old.st_dev
108 ! || st.st_ino != st_old.st_ino)
113 if (st_old.st_nlink > 1
114 || mch_lstat((char *)fname, &st) < 0
115 || st.st_dev != st_old.st_dev
116 ! || st.st_ino != st_old.st_ino
117 ! # ifndef HAVE_FCHOWN
118 ! || st.st_uid != st_old.st_uid
119 ! || st.st_gid != st_old.st_gid
127 for (i = 4913; ; i += 123)
129 sprintf((char *)gettail(IObuff), "%d", i);
130 ! if (mch_stat((char *)IObuff, &st) < 0)
133 fd = mch_open((char *)IObuff, O_CREAT|O_WRONLY|O_EXCL, perm);
135 if (fd < 0) /* can't write in directory */
140 ! chown((char *)IObuff, st_old.st_uid, st_old.st_gid);
141 ! (void)mch_setperm(IObuff, perm);
142 if (mch_stat((char *)IObuff, &st) < 0
143 || st.st_uid != st_old.st_uid
144 || st.st_gid != st_old.st_gid
145 || st.st_mode != perm)
152 for (i = 4913; ; i += 123)
154 sprintf((char *)gettail(IObuff), "%d", i);
155 ! if (mch_lstat((char *)IObuff, &st) < 0)
158 fd = mch_open((char *)IObuff, O_CREAT|O_WRONLY|O_EXCL, perm);
159 if (fd < 0) /* can't write in directory */
164 ! # ifdef HAVE_FCHOWN
165 ! fchown(fd, st_old.st_uid, st_old.st_gid);
167 if (mch_stat((char *)IObuff, &st) < 0
168 || st.st_uid != st_old.st_uid
169 || st.st_gid != st_old.st_gid
170 || st.st_mode != perm)
173 + /* Close the file before removing it, on MS-Windows we
174 + * can't delete an open file. */
181 * bits for the group same as the protection bits for
184 ! if (st_new.st_gid != st_old.st_gid &&
185 # ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */
186 ! fchown(bfd, (uid_t)-1, st_old.st_gid) != 0
188 ! chown((char *)backup, (uid_t)-1, st_old.st_gid) != 0
193 * bits for the group same as the protection bits for
196 ! if (st_new.st_gid != st_old.st_gid
197 # ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */
198 ! && fchown(bfd, (uid_t)-1, st_old.st_gid) != 0
209 + /* When creating a new file, set its owner/group to that of the original
210 + * file. Get the new device and inode number. */
211 + if (backup != NULL && !backup_copy)
213 + # ifdef HAVE_FCHOWN
216 + /* don't change the owner when it's already OK, some systems remove
217 + * permission or ACL stuff */
218 + if (mch_stat((char *)wfname, &st) < 0
219 + || st.st_uid != st_old.st_uid
220 + || st.st_gid != st_old.st_gid)
222 + fchown(fd, st_old.st_uid, st_old.st_gid);
223 + if (perm >= 0) /* set permission again, may have changed */
224 + (void)mch_setperm(wfname, perm);
233 errmsg = (char_u *)_("E512: Close failed");
236 * ACL on a file the user doesn't own). */
238 mch_set_acl(wfname, acl);
242 - /* When creating a new file, set its owner/group to that of the original
243 - * file. Get the new device and inode number. */
244 - if (backup != NULL && !backup_copy)
248 - /* don't change the owner when it's already OK, some systems remove
249 - * permission or ACL stuff */
250 - if (mch_stat((char *)wfname, &st) < 0
251 - || st.st_uid != st_old.st_uid
252 - || st.st_gid != st_old.st_gid)
254 - chown((char *)wfname, st_old.st_uid, st_old.st_gid);
255 - if (perm >= 0) /* set permission again, may have changed */
256 - (void)mch_setperm(wfname, perm);
264 *** ../vim-6.4.001/src/version.c Mon Oct 17 11:09:59 2005
265 --- src/version.c Tue Nov 29 19:23:24 2005
269 { /* Add new patch number below this line */
275 hundred-and-one symptoms of being an internet addict:
276 250. You've given up the search for the "perfect woman" and instead,
277 sit in front of the PC until you're just too tired to care.
279 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
280 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
281 \\\ download, build and distribute -- http://www.A-A-P.org ///
282 \\\ help me help AIDS victims -- http://www.ICCF.nl ///