Name: dk106046 Date: 04/06/2004
OPERATING SYSTEM(S): LinuxIA32, RHEL 2.1
FULL JDK VERSION(S): SUN JDK 1.4.2,1.5 beta
A small C program below uses seteuid to change the effective
uid for the entire java process (the app runs the java command). The
problem is that when Java is run this way, it hangs.
Steps to reproduce:
runuid -eu 500 java -version
runuid.cpp:
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char *argv[], char *envp[])
{
char **runArgs = &argv[1];
char *pgm;
uid_t id;
int i;
int verbose = 0;
for (i=0; i<3; i++)
{
if (!strcmp(*runArgs, "-v"))
{
verbose = 1;
runArgs++;
}
else if (!strcmp(*runArgs, "-u"))
{
runArgs++;
id = atoi(*runArgs);
if (verbose) printf("Setuid %d\n", id);
if (setuid(id) == -1)
{
printf("ERROR: cannot setuid %d, reason: %s\n", id, strerror(errno));
exit(1);
}
runArgs++;
}
else if (!strcmp(*runArgs, "-eu"))
{
runArgs++;
id = atoi(*runArgs);
if (verbose) printf("Seteuid %d\n", id);
if (seteuid(id) == -1)
{
printf("ERROR: cannot seteuid %d, reason: %s\n", id, strerror(errno));
exit(1);
}
runArgs++;
}
else if (!strcmp(*runArgs, "-g"))
{
runArgs++;
id = atoi(*runArgs);
if (verbose) printf("Setgid %d\n", id);
if (setgid(id) == -1)
{
printf("ERROR: cannot setgid %d, reason: %s\n", id, strerror(errno));
exit(1);
}
runArgs++;
}
else if (!strcmp(*runArgs, "-eg"))
{
runArgs++;
id = atoi(*runArgs);
if (verbose) printf("Setegid %d\n", id);
if (setegid(id) == -1)
{
printf("ERROR: cannot setegid %d, reason: %s\n", id, strerror(errno));
exit(1);
}
runArgs++;
}
else
break;
}
pgm = *runArgs;
runArgs;
if (verbose)
{
printf("Execute %s\n", pgm);
for ( i = 0; *(runArgs+i); i++ )
printf("args %d=[%s]\n", i, *(runArgs+i));
for ( i = 0; *(envp+i); i++ )
printf("envs %d=[%s]\n", i, *(envp+i));
fflush(stdout);
}
i = execvp(pgm, runArgs);
if (i == -1)
{
printf("ERROR: cannot execute %s, reason %s\n", pgm, strerror(errno));
exit(1);
}
return i;
}
======================================================================
- duplicates
-
JDK-5009832 Linux: libjvm.so should set soname
-
- Closed
-