Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
Libraries
nghttp2
Commits
7962c1bf
Commit
7962c1bf
authored
Aug 02, 2012
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shrpx: drop root priviledgs after loading private key
parent
75c98406
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
+24
-14
examples/shrpx.cc
examples/shrpx.cc
+24
-14
No files found.
examples/shrpx.cc
View file @
7962c1bf
...
...
@@ -202,6 +202,26 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
}
}
// namespace
namespace
{
void
drop_privileges
()
{
if
(
getuid
()
==
0
&&
get_config
()
->
uid
!=
0
)
{
if
(
setgid
(
get_config
()
->
gid
)
!=
0
)
{
LOG
(
FATAL
)
<<
"Could not change gid: "
<<
strerror
(
errno
);
exit
(
EXIT_FAILURE
);
}
if
(
setuid
(
get_config
()
->
uid
)
!=
0
)
{
LOG
(
FATAL
)
<<
"Could not change uid: "
<<
strerror
(
errno
);
exit
(
EXIT_FAILURE
);
}
if
(
setuid
(
0
)
!=
-
1
)
{
LOG
(
FATAL
)
<<
"Still have root privileges?"
;
exit
(
EXIT_FAILURE
);
}
}
}
}
// namespace
namespace
{
int
event_loop
()
{
...
...
@@ -209,6 +229,10 @@ int event_loop()
ListenHandler
*
listener_handler
=
new
ListenHandler
(
evbase
);
// ListenHandler loads private key. After that, we drop the root
// privileges if needed.
drop_privileges
();
evconnlistener
*
evlistener6
,
*
evlistener4
;
evlistener6
=
create_evlistener
(
listener_handler
,
AF_INET6
);
evlistener4
=
create_evlistener
(
listener_handler
,
AF_INET
);
...
...
@@ -583,20 +607,6 @@ int main(int argc, char **argv)
if
(
get_config
()
->
pid_file
)
{
save_pid
();
}
if
(
getuid
()
==
0
&&
get_config
()
->
uid
!=
0
)
{
if
(
setgid
(
get_config
()
->
gid
)
!=
0
)
{
LOG
(
FATAL
)
<<
"Could not change gid: "
<<
strerror
(
errno
);
exit
(
EXIT_FAILURE
);
}
if
(
setuid
(
get_config
()
->
uid
)
!=
0
)
{
LOG
(
FATAL
)
<<
"Could not change uid: "
<<
strerror
(
errno
);
exit
(
EXIT_FAILURE
);
}
if
(
setuid
(
0
)
!=
-
1
)
{
LOG
(
FATAL
)
<<
"Still have root privileges?"
;
exit
(
EXIT_FAILURE
);
}
}
struct
sigaction
act
;
memset
(
&
act
,
0
,
sizeof
(
struct
sigaction
));
...
...
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