]> git.pld-linux.org Git - packages/vim.git/blob - 6.4.002
- detect apache2 configs; rel 2
[packages/vim.git] / 6.4.002
1 To: vim-dev@vim.org
2 Subject: Patch 6.4.002
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 6.4.002
11 Problem:    Unix: There is a small chance that the ownership of the wrong file
12             is changed.
13 Solution:   Use fchown() instead of chown() for the viminfo file and the
14             backup file.
15 Files:      src/ex_cmds.c, src/fileio.c
16
17
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
20 ***************
21 *** 14,19 ****
22 --- 14,23 ----
23   #include "vim.h"
24   #include "version.h"
25   
26 + #ifdef HAVE_FCNTL_H
27 + # include <fcntl.h>
28 + #endif
29
30   #ifdef FEAT_EX_EXTRA
31   static int linelen __ARGS((int *has_tab));
32   #endif
33 ***************
34 *** 1510,1516 ****
35   
36         if (tempname != NULL)
37         {
38 !           fp_out = mch_fopen((char *)tempname, WRITEBIN);
39   
40             /*
41              * If we can't create in the same directory, try creating a
42 --- 1514,1536 ----
43   
44         if (tempname != NULL)
45         {
46 !           int fd;
47
48 !           /* Use mch_open() to be able to use O_EXCL and set file
49 !            * protection same as original file, but strip s-bit. */
50 ! #ifdef UNIX
51 !           fd = mch_open((char *)tempname,
52 !                   O_CREAT|O_EXTRA|O_EXCL|O_WRONLY,
53 !                                      (int)((st_old.st_mode & 0777) | 0600));
54 ! #else
55 !           fd = mch_open((char *)tempname,
56 !                   O_CREAT|O_EXTRA|O_EXCL|O_WRONLY,
57 !                                      0600);   /* r&w for user only */
58 ! #endif
59 !           if (fd < 0)
60 !               fp_out = NULL;
61 !           else
62 !               fp_out = fdopen(fd, WRITEBIN);
63   
64             /*
65              * If we can't create in the same directory, try creating a
66 ***************
67 *** 1522,1539 ****
68                 if ((tempname = vim_tempname('o')) != NULL)
69                     fp_out = mch_fopen((char *)tempname, WRITEBIN);
70             }
71 ! #ifdef UNIX
72             /*
73 !            * Set file protection same as original file, but strip s-bit
74 !            * and make sure the owner can read/write it.
75              */
76             if (fp_out != NULL)
77 !           {
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);
82 !           }
83   #endif
84         }
85       }
86 --- 1542,1555 ----
87                 if ((tempname = vim_tempname('o')) != NULL)
88                     fp_out = mch_fopen((char *)tempname, WRITEBIN);
89             }
90
91 ! #if defined(UNIX) && defined(HAVE_FCHOWN)
92             /*
93 !            * Make sure the owner can read/write it.  This only works for
94 !            * root.
95              */
96             if (fp_out != NULL)
97 !               (void)fchown(fileno(fp_out), st_old.st_uid, st_old.st_gid);
98   #endif
99         }
100       }
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
103 ***************
104 *** 3087,3093 ****
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)
109                 backup_copy = TRUE;
110             else
111   # endif
112 --- 3087,3098 ----
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
120 ! #  endif
121 !                   )
122                 backup_copy = TRUE;
123             else
124   # endif
125 ***************
126 *** 3102,3125 ****
127                 for (i = 4913; ; i += 123)
128                 {
129                     sprintf((char *)gettail(IObuff), "%d", i);
130 !                   if (mch_stat((char *)IObuff, &st) < 0)
131                         break;
132                 }
133                 fd = mch_open((char *)IObuff, O_CREAT|O_WRONLY|O_EXCL, perm);
134 -               close(fd);
135                 if (fd < 0)     /* can't write in directory */
136                     backup_copy = TRUE;
137                 else
138                 {
139   # ifdef UNIX
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)
146                         backup_copy = TRUE;
147   # endif
148                     mch_remove(IObuff);
149                 }
150             }
151 --- 3107,3133 ----
152                 for (i = 4913; ; i += 123)
153                 {
154                     sprintf((char *)gettail(IObuff), "%d", i);
155 !                   if (mch_lstat((char *)IObuff, &st) < 0)
156                         break;
157                 }
158                 fd = mch_open((char *)IObuff, O_CREAT|O_WRONLY|O_EXCL, perm);
159                 if (fd < 0)     /* can't write in directory */
160                     backup_copy = TRUE;
161                 else
162                 {
163   # ifdef UNIX
164 ! #  ifdef HAVE_FCHOWN
165 !                   fchown(fd, st_old.st_uid, st_old.st_gid);
166 ! #  endif
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)
171                         backup_copy = TRUE;
172   # endif
173 +                   /* Close the file before removing it, on MS-Windows we
174 +                    * can't delete an open file. */
175 +                   close(fd);
176                     mch_remove(IObuff);
177                 }
178             }
179 ***************
180 *** 3333,3343 ****
181                          * bits for the group same as the protection bits for
182                          * others.
183                          */
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
187 ! # else
188 !                         chown((char *)backup, (uid_t)-1, st_old.st_gid) != 0
189   # endif
190                                                 )
191                             mch_setperm(backup,
192 --- 3341,3349 ----
193                          * bits for the group same as the protection bits for
194                          * others.
195                          */
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
199   # endif
200                                                 )
201                             mch_setperm(backup,
202 ***************
203 *** 3999,4004 ****
204 --- 4005,4033 ----
205       }
206   #endif
207   
208 + #ifdef UNIX
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)
212 +     {
213 + # ifdef HAVE_FCHOWN
214 +       struct stat     st;
215
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)
221 +       {
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);
225 +       }
226 + # endif
227 +       buf_setino(buf);
228 +     }
229 + #endif
230
231       if (close(fd) != 0)
232       {
233         errmsg = (char_u *)_("E512: Close failed");
234 ***************
235 *** 4021,4047 ****
236        * ACL on a file the user doesn't own). */
237       if (!backup_copy)
238         mch_set_acl(wfname, acl);
239 - #endif
240
241 - #ifdef UNIX
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)
245 -     {
246 -       struct stat     st;
247
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)
253 -       {
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);
257 -       }
258 -       buf_setino(buf);
259 -     }
260   #endif
261   
262   
263 --- 4050,4055 ----
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
266 ***************
267 *** 643,644 ****
268 --- 643,646 ----
269   {   /* Add new patch number below this line */
270 + /**/
271 +     2,
272   /**/
273
274 -- 
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.
278
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         ///
This page took 0.058544 seconds and 3 git commands to generate.