Skip to content

Commit

Permalink
drop root privileges after bind
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Abraham committed Mar 22, 2012
1 parent 9642523 commit 056f309
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions SSLServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void SSLServer::run()
abort();
}

dropRights();

fd_set fds;

int afd = BIO_get_fd( abio,NULL );
Expand Down Expand Up @@ -210,3 +212,13 @@ std::string SSLServer::decodeDigest( std::string digest )

return decoded;
}

void SSLServer::dropRights()
{
if (getuid() == 0) {
if (setgid( 1000 ) != 0)
printf("setgid: Unable to drop group privileges: %s", strerror(errno));
if (setuid( 1000 ) != 0)
printf("setuid: Unable to drop user privileges: %S", strerror(errno));
}
}
1 change: 1 addition & 0 deletions SSLServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SSLServer
std::string createAnswer200();
bool parseReq( std::string req );
std::string decodeDigest( std::string digest );
void dropRights();

};

Expand Down

0 comments on commit 056f309

Please sign in to comment.