提交 d171f58a 编写于 作者: K kohsuke

need to chown in case this code is executed as a super user

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15264 71c3de6d-444a-0410-be80-ed276b4c234a
上级 5a828cc7
......@@ -152,7 +152,8 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable
private String createZfsFileSystem(final TaskListener listener, String rootUsername, String rootPassword) throws IOException, InterruptedException, ZFSException {
// capture the UID that Hudson runs under
// so that we can allow this user to do everything on this new partition
int uid = LIBC.geteuid();
final int uid = LIBC.geteuid();
final int gid = LIBC.getegid();
passwd pwd = LIBC.getpwuid(uid);
if(pwd==null)
throw new IOException("Failed to obtain the current user information for "+uid);
......@@ -178,6 +179,14 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable
out.println("Creating "+name);
ZFSFileSystem hudson = zfs.create(name, ZFSFileSystem.class);
// mount temporarily to set the owner right
File dir = Util.createTempDir();
hudson.setMountPoint(dir);
hudson.mount();
if(LIBC.chown(dir.getPath(),uid,gid)!=0)
throw new IOException("Failed to chown "+dir);
hudson.unmount();
try {
hudson.setProperty("hudson:managed-by","hudson"); // mark this file system as "managed by Hudson"
......@@ -286,7 +295,7 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable
}
// re-exec with the system property to indicate where to migrate the data to.
// the 2nd phase starts in the init method.
// the 2nd phase is implemented in the migrate method.
JavaVMArguments args = JavaVMArguments.current();
args.setSystemProperty(ZFSInstaller.class.getName()+".migrate",datasetName);
Daemon.selfExec(args);
......
......@@ -42,6 +42,7 @@ public interface GNUCLibrary extends Library {
int umask(int mask);
int getpid();
int geteuid();
int getegid();
int getppid();
int chdir(String dir);
int getdtablesize();
......@@ -61,6 +62,8 @@ public interface GNUCLibrary extends Library {
static final int F_GETFD = 1;
static final int F_SETFD = 2;
static final int FD_CLOEXEC = 1;
int chown(String fileName, int uid, int gid);
// this is listed in http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man3/sysctlbyname.3.html
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册