Merge -r 1333240:1333241 from trunk to branch. FIXES: MAPREDUCE-4219

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1333242 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alejandro Abdelnur 2012-05-02 22:54:36 +00:00
parent a2391dad68
commit d5defb5e60
6 changed files with 56 additions and 3 deletions

View File

@ -54,6 +54,9 @@ Release 2.0.0 - UNRELEASED
MAPREDUCE-3883. Document yarn.nodemanager.delete.debug-delay-sec
configuration property (Eugene Koontz via tgraves)
MAPREDUCE-4219. make default container-executor.conf.dir be a path
relative to the container-executor binary. (rvs via tucu)
OPTIMIZATIONS
BUG FIXES

View File

@ -27,7 +27,7 @@
<properties>
<!-- Basedir eeded for generating FindBugs warnings using parent pom -->
<yarn.basedir>${project.parent.parent.basedir}</yarn.basedir>
<container-executor.conf.dir>/etc/hadoop</container-executor.conf.dir>
<container-executor.conf.dir>../etc/hadoop</container-executor.conf.dir>
<container-executor.additional_cflags></container-executor.additional_cflags>
</properties>

View File

@ -29,6 +29,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <limits.h>
#define MAX_SIZE 10
@ -86,6 +87,25 @@ static int is_only_root_writable(const char *file) {
return 1;
}
/**
* Return a string with the configuration file path name resolved via realpath(3)
*
* NOTE: relative path names are resolved relative to the second argument not getwd(3)
*/
char *resolve_config_path(const char* file_name, const char *root) {
const char *real_fname = NULL;
char buffer[PATH_MAX*2 + 1];
if (file_name[0] == '/') {
real_fname = file_name;
} else if (realpath(root, buffer) != NULL) {
strncpy(strrchr(buffer, '/') + 1, file_name, PATH_MAX);
real_fname = buffer;
}
return (real_fname == NULL) ? NULL : realpath(real_fname, NULL);
}
/**
* Ensure that the configuration file and all of the containing directories
* are only writable by root. Otherwise, an attacker can change the

View File

@ -24,6 +24,13 @@
*/
int check_configuration_permissions(const char* file_name);
/**
* Return a string with the configuration file path name resolved via realpath(3)
*
* NOTE: relative path names are resolved relative to the second argument not getwd(3)
*/
char *resolve_config_path(const char* file_name, const char *root);
// read the given configuration file
void read_config(const char* config_file);

View File

@ -33,6 +33,12 @@
#define STRINGIFY(X) _STRINGIFY(X)
#define CONF_FILENAME "container-executor.cfg"
// When building as part of a Maven build this value gets defined by using
// container-executor.conf.dir property. See:
// hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml
// for details.
// NOTE: if this ends up being a relative path it gets resolved relative to
// the location of the container-executor binary itself, not getwd(3)
#ifndef HADOOP_CONF_DIR
#error HADOOP_CONF_DIR must be defined
#endif
@ -96,7 +102,7 @@ int main(int argc, char **argv) {
char *executable_file = get_executable();
char *orig_conf_file = STRINGIFY(HADOOP_CONF_DIR) "/" CONF_FILENAME;
char *conf_file = realpath(orig_conf_file, NULL);
char *conf_file = resolve_config_path(orig_conf_file, argv[0]);
char *local_dirs, *log_dirs;
if (conf_file == NULL) {

View File

@ -196,6 +196,18 @@ void test_check_user() {
}
}
void test_resolve_config_path() {
printf("\nTesting resolve_config_path\n");
if (strcmp(resolve_config_path("/etc/passwd", NULL), "/etc/passwd") != 0) {
printf("FAIL: failed to resolve config_name on an absolute path name: /etc/passwd\n");
exit(1);
}
if (strcmp(resolve_config_path("../etc/passwd", "/etc/passwd"), "/etc/passwd") != 0) {
printf("FAIL: failed to resolve config_name on a relative path name: ../etc/passwd (relative to /etc/passwd)");
exit(1);
}
}
void test_check_configuration_permissions() {
printf("\nTesting check_configuration_permissions\n");
if (check_configuration_permissions("/etc/passwd") != 0) {
@ -668,7 +680,9 @@ int main(int argc, char **argv) {
int my_username = 0;
// clean up any junk from previous run
system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT);
if (system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT)) {
exit(1);
}
if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) {
exit(1);
@ -700,6 +714,9 @@ int main(int argc, char **argv) {
printf("\nStarting tests\n");
printf("\nTesting resolve_config_path()\n");
test_resolve_config_path();
printf("\nTesting get_user_directory()\n");
test_get_user_directory();