Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3864afa

Browse files
committed
Clean up some copied-and-pasted code in pg_upgrade.
1. Don't reimplement S_ISDIR() and S_ISREG() badly.2. Don't reimplement access() badly.This code appears to have been copied from ancient versions of thecorresponding backend routines, and not patched to incorporate subsequentfixes (see my commits of 2008-03-31 and 2010-01-14 respectively).It might be a good idea to change it to just *call* those routines,but for now I'll just transpose these fixes over.
1 parent1319002 commit3864afa

File tree

2 files changed

+7
-66
lines changed

2 files changed

+7
-66
lines changed

‎contrib/pg_upgrade/exec.c

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include"pg_upgrade.h"
1111

1212
#include<fcntl.h>
13-
#include<grp.h>
13+
#include<unistd.h>
1414

1515

1616
staticvoidcheck_data_dir(constchar*pg_data);
@@ -206,17 +206,9 @@ validate_exec(const char *path)
206206
{
207207
structstatbuf;
208208

209-
#ifndefWIN32
210-
uid_teuid;
211-
structgroup*gp;
212-
structpasswd*pwp;
213-
intin_grp=0;
214-
#else
215-
charpath_exe[MAXPGPATH+sizeof(EXE_EXT)-1];
216-
#endif
217-
218209
#ifdefWIN32
219210
/* Win32 requires a .exe suffix for stat() */
211+
charpath_exe[MAXPGPATH+sizeof(EXE_EXT)-1];
220212

221213
if (strlen(path) >=strlen(EXE_EXT)&&
222214
pg_strcasecmp(path+strlen(path)-strlen(EXE_EXT),EXE_EXT)!=0)
@@ -233,68 +225,17 @@ validate_exec(const char *path)
233225
if (stat(path,&buf)<0)
234226
returngetErrorText(errno);
235227

236-
if ((buf.st_mode&S_IFMT)!=S_IFREG)
228+
if (!S_ISREG(buf.st_mode))
237229
return"not an executable file";
238230

239-
/*
240-
* Ensure that we are using an authorized executable.
241-
*/
242-
243231
/*
244232
* Ensure that the file is both executable and readable (required for
245233
* dynamic loading).
246234
*/
247235
#ifndefWIN32
248-
euid=geteuid();
249-
250-
/* If owned by us, just check owner bits */
251-
if (euid==buf.st_uid)
252-
{
253-
if ((buf.st_mode&S_IRUSR)==0)
254-
return"can't read file (permission denied)";
255-
if ((buf.st_mode&S_IXUSR)==0)
256-
return"can't execute (permission denied)";
257-
returnNULL;
258-
}
259-
260-
/* OK, check group bits */
261-
pwp=getpwuid(euid);/* not thread-safe */
262-
263-
if (pwp)
264-
{
265-
if (pwp->pw_gid==buf.st_gid)/* my primary group? */
266-
++in_grp;
267-
elseif (pwp->pw_name&&
268-
(gp=getgrgid(buf.st_gid))!=NULL&&
269-
/* not thread-safe */gp->gr_mem!=NULL)
270-
{
271-
/* try list of member groups */
272-
inti;
273-
274-
for (i=0;gp->gr_mem[i];++i)
275-
{
276-
if (!strcmp(gp->gr_mem[i],pwp->pw_name))
277-
{
278-
++in_grp;
279-
break;
280-
}
281-
}
282-
}
283-
284-
if (in_grp)
285-
{
286-
if ((buf.st_mode&S_IRGRP)==0)
287-
return"can't read file (permission denied)";
288-
if ((buf.st_mode&S_IXGRP)==0)
289-
return"can't execute (permission denied)";
290-
returnNULL;
291-
}
292-
}
293-
294-
/* Check "other" bits */
295-
if ((buf.st_mode&S_IROTH)==0)
236+
if (access(path,R_OK)!=0)
296237
return"can't read file (permission denied)";
297-
if ((buf.st_mode&S_IXOTH)==0)
238+
if (access(path,X_OK)!=0)
298239
return"can't execute (permission denied)";
299240
returnNULL;
300241
#else

‎contrib/pg_upgrade/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,13 @@ copy_dir(const char *src, const char *dst, bool force)
440440
return-1;
441441
}
442442

443-
if (fst.st_mode&S_IFDIR)
443+
if (S_ISDIR(fst.st_mode))
444444
{
445445
/* recurse to handle subdirectories */
446446
if (force)
447447
copy_dir(src_file,dest_file, true);
448448
}
449-
elseif (fst.st_mode&S_IFREG)
449+
elseif (S_ISREG(fst.st_mode))
450450
{
451451
if ((copy_file(src_file,dest_file,1))==-1)
452452
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp