Equivalent of pwd.h lib of c++ in java -


i have found link illustrates use of getting pwd based in uid of user.

i have similar requirement in java running script different user needs implemetation.

the code snippet in c++ below:

static void su(const char* user) {     struct passwd* pwentry=getpwnam(user);     if(!pwentry)         cout<<"su:getpwnam:couldnot pwd entry user %s",user;     uid_t new_uid=pwentry->pw_uid;     struct passwd* pwentry_nmsadm=getpwnam("nmsadm");     if(!pwentry_nmsadm)         cout<<"su:getpwnam:could not pwd nmsadm");     gid_t new_gid=pwentry->pw_gid;     if(chdir(pwentry->pw_dir)<0)         cout<<"su:chdir";     uid_t current_uid=geteuid();     gid_t current_gid=getegid();     if(current_gid!=new_gid)     {         if(setgid(new_gid)<0)         cout<<"su:setgid";     }     if(current_uid!=new_uid)     {         if(setuid(new_uid)<0)         cout<<"su: setuid";     } 

please suggest links can helpful(libraries can used) or solution above requirement in java.

java not provide out-of-the-box, since both system dependant , break security concepts of java.

some possible solutions be:

  • use jni wrapper call c++ method, can need in c++
  • use ssh launch script different user
  • use sudo launch script different user

see also


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -