Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
a6086377
Commit
a6086377
authored
Jun 09, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another for for exec() removal and finding binaries.
parent
cb8539f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
36 deletions
+38
-36
src/backend/postmaster/postmaster.c
src/backend/postmaster/postmaster.c
+4
-4
src/backend/tcop/postgres.c
src/backend/tcop/postgres.c
+3
-3
src/backend/utils/init/findbe.c
src/backend/utils/init/findbe.c
+28
-26
src/include/miscadmin.h
src/include/miscadmin.h
+3
-3
No files found.
src/backend/postmaster/postmaster.c
View file @
a6086377
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.8
5 1998/06/09 04:06:12
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.8
6 1998/06/09 17:13:03
momjian Exp $
*
*
* NOTES
* NOTES
*
*
...
@@ -324,7 +324,7 @@ PostmasterMain(int argc, char *argv[])
...
@@ -324,7 +324,7 @@ PostmasterMain(int argc, char *argv[])
new_argv
[
i
]
=
""
;
new_argv
[
i
]
=
""
;
new_argv
[
4
]
=
NULL
;
new_argv
[
4
]
=
NULL
;
if
(
!
Execfile
[
0
]
&&
FindExec
(
Execfile
,
argv
[
0
])
<
0
)
if
(
!
Execfile
[
0
]
&&
FindExec
(
Execfile
,
argv
[
0
]
,
"postmaster"
)
<
0
)
{
{
fprintf
(
stderr
,
"%s: could not find postmaster to execute...
\n
"
,
fprintf
(
stderr
,
"%s: could not find postmaster to execute...
\n
"
,
argv
[
0
]);
argv
[
0
]);
...
@@ -385,7 +385,7 @@ PostmasterMain(int argc, char *argv[])
...
@@ -385,7 +385,7 @@ PostmasterMain(int argc, char *argv[])
break
;
break
;
case
'b'
:
case
'b'
:
/* Set the backend executable file to use. */
/* Set the backend executable file to use. */
if
(
!
ValidateB
ackend
(
optarg
))
if
(
!
ValidateB
inary
(
optarg
))
strcpy
(
Execfile
,
optarg
);
strcpy
(
Execfile
,
optarg
);
else
else
{
{
...
@@ -479,7 +479,7 @@ PostmasterMain(int argc, char *argv[])
...
@@ -479,7 +479,7 @@ PostmasterMain(int argc, char *argv[])
exit
(
2
);
exit
(
2
);
}
}
if
(
!
Execfile
[
0
]
&&
FindExec
(
Execfile
,
argv
[
0
])
<
0
)
if
(
!
Execfile
[
0
]
&&
FindExec
(
Execfile
,
argv
[
0
]
,
"postgres"
)
<
0
)
{
{
fprintf
(
stderr
,
"%s: could not find backend to execute...
\n
"
,
fprintf
(
stderr
,
"%s: could not find backend to execute...
\n
"
,
argv
[
0
]);
argv
[
0
]);
...
...
src/backend/tcop/postgres.c
View file @
a6086377
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.7
4 1998/06/08 22:28:27
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.7
5 1998/06/09 17:13:04
momjian Exp $
*
*
* NOTES
* NOTES
* this is the "main" module of the postgres backend and
* this is the "main" module of the postgres backend and
...
@@ -1167,7 +1167,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
...
@@ -1167,7 +1167,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
SetCharSet
();
SetCharSet
();
#endif
#endif
if
(
FindExec
(
pg_pathname
,
argv
[
0
])
<
0
)
if
(
FindExec
(
pg_pathname
,
argv
[
0
]
,
"postgres"
)
<
0
)
elog
(
FATAL
,
"%s: could not locate executable, bailing out..."
,
elog
(
FATAL
,
"%s: could not locate executable, bailing out..."
,
argv
[
0
]);
argv
[
0
]);
...
@@ -1314,7 +1314,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
...
@@ -1314,7 +1314,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if
(
!
IsUnderPostmaster
)
if
(
!
IsUnderPostmaster
)
{
{
puts
(
"
\n
POSTGRES backend interactive interface"
);
puts
(
"
\n
POSTGRES backend interactive interface"
);
puts
(
"$Revision: 1.7
4 $ $Date: 1998/06/08 22:28:27
$"
);
puts
(
"$Revision: 1.7
5 $ $Date: 1998/06/09 17:13:04
$"
);
}
}
/* ----------------
/* ----------------
...
...
src/backend/utils/init/findbe.c
View file @
a6086377
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.
8 1998/06/08 22:28:28
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.
9 1998/06/09 17:13:05
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -34,14 +34,14 @@
...
@@ -34,14 +34,14 @@
#endif
#endif
/*
/*
* ValidateB
ackend -- validate "path" as a
POSTGRES executable file
* ValidateB
inary -- validate "path" as a POSTMASTER/
POSTGRES executable file
*
*
* returns 0 if the file is found and no error is encountered.
* returns 0 if the file is found and no error is encountered.
* -1 if the regular file "path" does not exist or cannot be executed.
* -1 if the regular file "path" does not exist or cannot be executed.
* -2 if the file is otherwise valid but cannot be read.
* -2 if the file is otherwise valid but cannot be read.
*/
*/
int
int
ValidateB
ackend
(
char
*
path
)
ValidateB
inary
(
char
*
path
)
{
{
struct
stat
buf
;
struct
stat
buf
;
uid_t
euid
;
uid_t
euid
;
...
@@ -61,7 +61,7 @@ ValidateBackend(char *path)
...
@@ -61,7 +61,7 @@ ValidateBackend(char *path)
if
(
strlen
(
path
)
>=
MAXPGPATH
)
if
(
strlen
(
path
)
>=
MAXPGPATH
)
{
{
if
(
DebugLvl
>
1
)
if
(
DebugLvl
>
1
)
fprintf
(
stderr
,
"ValidateB
ackend
: pathname
\"
%s
\"
is too long
\n
"
,
fprintf
(
stderr
,
"ValidateB
inary
: pathname
\"
%s
\"
is too long
\n
"
,
path
);
path
);
return
(
-
1
);
return
(
-
1
);
}
}
...
@@ -69,14 +69,14 @@ ValidateBackend(char *path)
...
@@ -69,14 +69,14 @@ ValidateBackend(char *path)
if
(
stat
(
path
,
&
buf
)
<
0
)
if
(
stat
(
path
,
&
buf
)
<
0
)
{
{
if
(
DebugLvl
>
1
)
if
(
DebugLvl
>
1
)
fprintf
(
stderr
,
"ValidateB
ackend
: can't stat
\"
%s
\"\n
"
,
fprintf
(
stderr
,
"ValidateB
inary
: can't stat
\"
%s
\"\n
"
,
path
);
path
);
return
(
-
1
);
return
(
-
1
);
}
}
if
(
!
(
buf
.
st_mode
&
S_IFREG
))
if
(
!
(
buf
.
st_mode
&
S_IFREG
))
{
{
if
(
DebugLvl
>
1
)
if
(
DebugLvl
>
1
)
fprintf
(
stderr
,
"ValidateB
ackend
:
\"
%s
\"
is not a regular file
\n
"
,
fprintf
(
stderr
,
"ValidateB
inary
:
\"
%s
\"
is not a regular file
\n
"
,
path
);
path
);
return
(
-
1
);
return
(
-
1
);
}
}
...
@@ -85,7 +85,7 @@ ValidateBackend(char *path)
...
@@ -85,7 +85,7 @@ ValidateBackend(char *path)
* Ensure that we are using an authorized backend.
* Ensure that we are using an authorized backend.
*
*
* XXX I'm open to suggestions here. I would like to enforce ownership
* XXX I'm open to suggestions here. I would like to enforce ownership
* of b
ackend
s by user "postgres" but people seem to like to run as
* of b
inarie
s by user "postgres" but people seem to like to run as
* users other than "postgres"...
* users other than "postgres"...
*/
*/
...
@@ -102,7 +102,7 @@ ValidateBackend(char *path)
...
@@ -102,7 +102,7 @@ ValidateBackend(char *path)
is_r
=
buf
.
st_mode
&
S_IRUSR
;
is_r
=
buf
.
st_mode
&
S_IRUSR
;
is_x
=
buf
.
st_mode
&
S_IXUSR
;
is_x
=
buf
.
st_mode
&
S_IXUSR
;
if
(
DebugLvl
>
1
&&
!
(
is_r
&&
is_x
))
if
(
DebugLvl
>
1
&&
!
(
is_r
&&
is_x
))
fprintf
(
stderr
,
"ValidateB
ackend
:
\"
%s
\"
is not user read/execute
\n
"
,
fprintf
(
stderr
,
"ValidateB
inary
:
\"
%s
\"
is not user read/execute
\n
"
,
path
);
path
);
return
(
is_x
?
(
is_r
?
0
:
-
2
)
:
-
1
);
return
(
is_x
?
(
is_r
?
0
:
-
2
)
:
-
1
);
}
}
...
@@ -130,7 +130,7 @@ ValidateBackend(char *path)
...
@@ -130,7 +130,7 @@ ValidateBackend(char *path)
is_r
=
buf
.
st_mode
&
S_IRGRP
;
is_r
=
buf
.
st_mode
&
S_IRGRP
;
is_x
=
buf
.
st_mode
&
S_IXGRP
;
is_x
=
buf
.
st_mode
&
S_IXGRP
;
if
(
DebugLvl
>
1
&&
!
(
is_r
&&
is_x
))
if
(
DebugLvl
>
1
&&
!
(
is_r
&&
is_x
))
fprintf
(
stderr
,
"ValidateB
ackend
:
\"
%s
\"
is not group read/execute
\n
"
,
fprintf
(
stderr
,
"ValidateB
inary
:
\"
%s
\"
is not group read/execute
\n
"
,
path
);
path
);
return
(
is_x
?
(
is_r
?
0
:
-
2
)
:
-
1
);
return
(
is_x
?
(
is_r
?
0
:
-
2
)
:
-
1
);
}
}
...
@@ -138,7 +138,7 @@ ValidateBackend(char *path)
...
@@ -138,7 +138,7 @@ ValidateBackend(char *path)
is_r
=
buf
.
st_mode
&
S_IROTH
;
is_r
=
buf
.
st_mode
&
S_IROTH
;
is_x
=
buf
.
st_mode
&
S_IXOTH
;
is_x
=
buf
.
st_mode
&
S_IXOTH
;
if
(
DebugLvl
>
1
&&
!
(
is_r
&&
is_x
))
if
(
DebugLvl
>
1
&&
!
(
is_r
&&
is_x
))
fprintf
(
stderr
,
"ValidateB
ackend
:
\"
%s
\"
is not other read/execute
\n
"
,
fprintf
(
stderr
,
"ValidateB
inary
:
\"
%s
\"
is not other read/execute
\n
"
,
path
);
path
);
return
(
is_x
?
(
is_r
?
0
:
-
2
)
:
-
1
);
return
(
is_x
?
(
is_r
?
0
:
-
2
)
:
-
1
);
}
}
...
@@ -147,11 +147,12 @@ ValidateBackend(char *path)
...
@@ -147,11 +147,12 @@ ValidateBackend(char *path)
* FindExec -- find an absolute path to a valid backend executable
* FindExec -- find an absolute path to a valid backend executable
*
*
* The reason we have to work so hard to find an absolute path is that
* The reason we have to work so hard to find an absolute path is that
* we need to feed the backend server the location of its actual
* we need to feed the binary the location of its actual executable file,
* executable file -- otherwise, we can't do dynamic loading.
* otherwise, we can't do dynamic loading. It needs a full pathname because
* we change directories to the /data directory.
*/
*/
int
int
FindExec
(
char
*
backend
,
char
*
argv0
)
FindExec
(
char
*
full_path
,
char
*
argv0
,
char
*
binary_name
)
{
{
char
buf
[
MAXPGPATH
+
2
];
char
buf
[
MAXPGPATH
+
2
];
char
*
p
;
char
*
p
;
...
@@ -161,7 +162,7 @@ FindExec(char *backend, char *argv0)
...
@@ -161,7 +162,7 @@ FindExec(char *backend, char *argv0)
int
pathlen
;
int
pathlen
;
/*
/*
* for the postmaster: First try: use the b
ackend
that's located in
* for the postmaster: First try: use the b
inary
that's located in
* the same directory as the postmaster, if it was invoked with an
* the same directory as the postmaster, if it was invoked with an
* explicit path. Presumably the user used an explicit path because it
* explicit path. Presumably the user used an explicit path because it
* wasn't in PATH, and we don't want to use incompatible executables.
* wasn't in PATH, and we don't want to use incompatible executables.
...
@@ -171,7 +172,7 @@ FindExec(char *backend, char *argv0)
...
@@ -171,7 +172,7 @@ FindExec(char *backend, char *argv0)
* trees (obj/post{master,gres}) because they all put the two binaries
* trees (obj/post{master,gres}) because they all put the two binaries
* in the same place.
* in the same place.
*
*
* for the b
ackend server
: First try: if we're given some kind of path,
* for the b
inary
: First try: if we're given some kind of path,
* use it (making sure that a relative path is made absolute before
* use it (making sure that a relative path is made absolute before
* returning it).
* returning it).
*/
*/
...
@@ -183,16 +184,16 @@ FindExec(char *backend, char *argv0)
...
@@ -183,16 +184,16 @@ FindExec(char *backend, char *argv0)
strcat
(
buf
,
"/"
);
strcat
(
buf
,
"/"
);
strcat
(
buf
,
argv0
);
strcat
(
buf
,
argv0
);
p
=
strrchr
(
buf
,
'/'
);
p
=
strrchr
(
buf
,
'/'
);
strcpy
(
++
p
,
"postgres"
);
strcpy
(
++
p
,
binary_name
);
if
(
!
ValidateB
ackend
(
buf
))
if
(
!
ValidateB
inary
(
buf
))
{
{
strncpy
(
backend
,
buf
,
MAXPGPATH
);
strncpy
(
full_path
,
buf
,
MAXPGPATH
);
if
(
DebugLvl
)
if
(
DebugLvl
)
fprintf
(
stderr
,
"FindExec: found
\"
%s
\"
using argv[0]
\n
"
,
fprintf
(
stderr
,
"FindExec: found
\"
%s
\"
using argv[0]
\n
"
,
backend
);
full_path
);
return
(
0
);
return
(
0
);
}
}
fprintf
(
stderr
,
"FindExec: invalid b
ackend
\"
%s
\"\n
"
,
fprintf
(
stderr
,
"FindExec: invalid b
inary
\"
%s
\"\n
"
,
buf
);
buf
);
return
(
-
1
);
return
(
-
1
);
}
}
...
@@ -219,20 +220,21 @@ FindExec(char *backend, char *argv0)
...
@@ -219,20 +220,21 @@ FindExec(char *backend, char *argv0)
if
(
*
startp
==
'/'
||
!
getcwd
(
buf
,
MAXPGPATH
))
if
(
*
startp
==
'/'
||
!
getcwd
(
buf
,
MAXPGPATH
))
buf
[
0
]
=
'\0'
;
buf
[
0
]
=
'\0'
;
strcat
(
buf
,
startp
);
strcat
(
buf
,
startp
);
strcat
(
buf
,
"/postgres"
);
strcat
(
buf
,
"/"
);
switch
(
ValidateBackend
(
buf
))
strcat
(
buf
,
binary_name
);
switch
(
ValidateBinary
(
buf
))
{
{
case
0
:
/* found ok */
case
0
:
/* found ok */
strncpy
(
backend
,
buf
,
MAXPGPATH
);
strncpy
(
full_path
,
buf
,
MAXPGPATH
);
if
(
DebugLvl
)
if
(
DebugLvl
)
fprintf
(
stderr
,
"FindExec: found
\"
%s
\"
using PATH
\n
"
,
fprintf
(
stderr
,
"FindExec: found
\"
%s
\"
using PATH
\n
"
,
backend
);
full_path
);
free
(
path
);
free
(
path
);
return
(
0
);
return
(
0
);
case
-
1
:
/* wasn't even a candidate, keep looking */
case
-
1
:
/* wasn't even a candidate, keep looking */
break
;
break
;
case
-
2
:
/* found but disqualified */
case
-
2
:
/* found but disqualified */
fprintf
(
stderr
,
"FindExec: could not read b
ackend
\"
%s
\"\n
"
,
fprintf
(
stderr
,
"FindExec: could not read b
inary
\"
%s
\"\n
"
,
buf
);
buf
);
free
(
path
);
free
(
path
);
return
(
-
1
);
return
(
-
1
);
...
@@ -243,6 +245,6 @@ FindExec(char *backend, char *argv0)
...
@@ -243,6 +245,6 @@ FindExec(char *backend, char *argv0)
free
(
path
);
free
(
path
);
}
}
fprintf
(
stderr
,
"FindExec: could not find a
backend to execute...
\n
"
);
fprintf
(
stderr
,
"FindExec: could not find a
%s to execute...
\n
"
,
binary_name
);
return
(
-
1
);
return
(
-
1
);
}
}
src/include/miscadmin.h
View file @
a6086377
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: miscadmin.h,v 1.2
5 1998/06/08 22:28:30
momjian Exp $
* $Id: miscadmin.h,v 1.2
6 1998/06/09 17:13:06
momjian Exp $
*
*
* NOTES
* NOTES
* some of the information in this file will be moved to
* some of the information in this file will be moved to
...
@@ -125,8 +125,8 @@ extern char *getpgusername(void);
...
@@ -125,8 +125,8 @@ extern char *getpgusername(void);
extern
void
SetPgUserName
(
void
);
extern
void
SetPgUserName
(
void
);
extern
Oid
GetUserId
(
void
);
extern
Oid
GetUserId
(
void
);
extern
void
SetUserId
(
void
);
extern
void
SetUserId
(
void
);
extern
int
ValidateB
ackend
(
char
*
path
);
extern
int
ValidateB
inary
(
char
*
path
);
extern
int
FindExec
(
char
*
backend
,
char
*
argv0
);
extern
int
FindExec
(
char
*
backend
,
char
*
argv0
,
char
*
binary_name
);
extern
int
CheckPathAccess
(
char
*
path
,
char
*
name
,
int
open_mode
);
extern
int
CheckPathAccess
(
char
*
path
,
char
*
name
,
int
open_mode
);
/* lower case version for case-insensitive SQL referenced in pg_proc.h */
/* lower case version for case-insensitive SQL referenced in pg_proc.h */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment