You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2010/02/16 00:57:05 UTC
svn commit: r910366 - in /incubator/trafficserver/traffic/trunk/proxy/mgmt2:
LocalManager.cc LocalManager.h Rollback.cc utils/WebMgmtUtils.cc
Author: zwoop
Date: Mon Feb 15 23:57:04 2010
New Revision: 910366
URL: http://svn.apache.org/viewvc?rev=910366&view=rev
Log:
TS-165: Make sure traffic_manager runs as admin user even when port is < 1024.
Author: George and Leif
Review: George P.
Modified:
incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc
incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.h
incubator/trafficserver/traffic/trunk/proxy/mgmt2/Rollback.cc
incubator/trafficserver/traffic/trunk/proxy/mgmt2/utils/WebMgmtUtils.cc
Modified: incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc?rev=910366&r1=910365&r2=910366&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.cc Mon Feb 15 23:57:04 2010
@@ -1324,14 +1324,14 @@
// and false on failure
// - no-op on WIN32
bool
-removeRootPriv(void)
+removeRootPriv(uid_t euid)
{
- if (seteuid(getuid()) < 0) {
- Debug("lm", "[restoreRootPiv] seteuid root failed : %s\n", strerror(errno));
+ if (seteuid(euid) < 0) {
+ Debug("lm", "[restoreRootPriv] seteuid failed : %s\n", strerror(errno));
return false;
}
- Debug("lm", "[removeRootPiv] removed root privileges. Euid is %d\n", geteuid());
+ Debug("lm", "[removeRootPriv] removed root privileges. Euid is %d\n", euid);
return true;
}
@@ -1343,14 +1343,16 @@
// and false on failure
// - no-op on WIN32
bool
-restoreRootPriv(void)
+restoreRootPriv(uid_t *old_euid)
{
+ if (old_euid)
+ *old_euid = geteuid();
if (seteuid(0) < 0) {
- Debug("lm", "[restoreRootPiv] seteuid root failed : %s\n", strerror(errno));
+ Debug("lm", "[restoreRootPriv] seteuid root failed : %s\n", strerror(errno));
return false;
}
- Debug("lm", "[restoreRootPiv] restored root privileges. Euid is %d\n", geteuid());
+ Debug("lm", "[restoreRootPriv] restored root privileges. Euid is %d\n", 0);
return true;
}
@@ -1368,9 +1370,10 @@
int proxy_port_fd = -1;
bool privBoost = false;
uid_t euid = geteuid();
+ uid_t saved_euid = 0;
if (proxy_port < 1024 && euid != 0) {
- if (restoreRootPriv() == false) {
+ if (restoreRootPriv(&saved_euid) == false) {
mgmt_elog(stderr, "[bindProxyPort] Unable to get root priviledges to bind port %d. euid is %d. Exiting\n",
proxy_port, euid);
_exit(0);
@@ -1402,7 +1405,7 @@
Debug("lm", "[bindProxyPort] Successfully bound proxy port %d\n", proxy_port);
if (privBoost == true) {
- if (removeRootPriv() == false) {
+ if (removeRootPriv(saved_euid) == false) {
mgmt_elog(stderr, "[bindProxyPort] Unable to reset permissions to euid %d. Exiting...\n", getuid());
_exit(1);
}
Modified: incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.h?rev=910366&r1=910365&r2=910366&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.h (original)
+++ incubator/trafficserver/traffic/trunk/proxy/mgmt2/LocalManager.h Mon Feb 15 23:57:04 2010
@@ -193,8 +193,8 @@
}; /* End class LocalManager */
-bool restoreRootPriv(void);
-bool removeRootPriv(void);
+bool restoreRootPriv(uid_t *old_euid = NULL);
+bool removeRootPriv(uid_t euid);
#endif /* _LOCAL_MANAGER_H */
Modified: incubator/trafficserver/traffic/trunk/proxy/mgmt2/Rollback.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/mgmt2/Rollback.cc?rev=910366&r1=910365&r2=910366&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/mgmt2/Rollback.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/mgmt2/Rollback.cc Mon Feb 15 23:57:04 2010
@@ -312,19 +312,20 @@
{
char *filePath;
int statResult;
+ uid_t saved_euid = 0;
if (version == this->currentVersion) {
version = ACTIVE_VERSION;
}
filePath = createPathStr(version);
if (root_access_needed) {
- if (restoreRootPriv() != true) {
+ if (restoreRootPriv(&saved_euid) != true) {
mgmt_log(stderr, "[Rollback] Unable to acquire root privileges.\n");
}
}
statResult = stat(filePath, buf);
if (root_access_needed) {
- if (removeRootPriv() != true) {
+ if (removeRootPriv(saved_euid) != true) {
mgmt_log(stderr, "[Rollback] Unable to restore non-root privileges.\n");
}
}
@@ -343,17 +344,18 @@
{
char *filePath;
int fd;
+ uid_t saved_euid = 0;
filePath = createPathStr(version);
if (root_access_needed) {
- if (restoreRootPriv() != true) {
+ if (restoreRootPriv(&saved_euid) != true) {
mgmt_log(stderr, "[Rollback] Unable to acquire root privileges.\n");
}
}
fd = mgmt_open_mode(filePath, oflags, 0644);
if (root_access_needed) {
- if (removeRootPriv() != true) {
+ if (removeRootPriv(saved_euid) != true) {
mgmt_log(stderr, "[Rollback] Unable to restore non-root privileges.\n");
}
}
Modified: incubator/trafficserver/traffic/trunk/proxy/mgmt2/utils/WebMgmtUtils.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/mgmt2/utils/WebMgmtUtils.cc?rev=910366&r1=910365&r2=910366&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/mgmt2/utils/WebMgmtUtils.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/mgmt2/utils/WebMgmtUtils.cc Mon Feb 15 23:57:04 2010
@@ -1578,6 +1578,7 @@
long total;
bool cutoff;
char *too_large_msg = "\nfile too large, truncated here...";
+ uid_t saved_euid = 0;
if (pipe(stdinPipe) == -1)
mgmt_elog(stderr, "[processSpawn] unable to create stdin pipe\n");
@@ -1599,7 +1600,7 @@
}
// set uid to be the effective uid if it's run as root
if (run_as_root) {
- restoreRootPriv();
+ restoreRootPriv(&saved_euid);
if (setuid(geteuid()) == -1) {
mgmt_elog(stderr, "[processSpawn] unable to set uid to euid");
}
@@ -1690,7 +1691,7 @@
}
if (run_as_root) {
- removeRootPriv();
+ removeRootPriv(saved_euid);
}
#endif // _WIN32
return status;