我的应用程序需要以非 root 用户身份运行,但需要切换到其他用户来执行一些命令。我尝试过了:写一个 JNI,JNIEXPORT void JNICALL Java_SetUIDJNI_setuid(JNIEnv *env, jobject thisObj,jstring uname) { const char *name = jstringTostring(env,uname); int pid; struct passwd *p; show_ids(); if ((p = getpwnam(name)) == NULL) { perror(name); exit(EXIT_FAILURE); } pid = (int) p->pw_uid; printf("pid=%d\n",pid); if (seteuid (pid) < 0) { perror ("setuid"); exit (EXIT_FAILURE); } show_ids();}以root和chmod u+s构建它-rwsr-xr-x 1 root root 76155 Aug 7 16:56 libsetuid.so*在java中调用它api = new SetUIDJNI(); // invoke the native methodapi.setuid("slurm");但是如果以非root身份运行它,它就不起作用/opt/jdk1.8/jre/bin/java -Djava.library.path=../jni HelloJNI The real user ID is: 1000 The effective user ID is :1000 <= which expected is 0 setuid: Operation not permitted但如果 runner 是 root 则它有效The real user ID is: 0The effective user ID is :0pid=1002The real user ID is: 0The effective user ID is :1002这里有什么问题吗?
添加回答
举报
0/150
提交
取消