2015-05-15 6 views
5

Quindi, ho un processo di root (eseguito come root), e voglio che carichi un altro processo con un uid non-root.Caricamento di un processo come un altro utente?

Al momento, sto chiamando seteuid e setegid, quindi reimpostato su root dopo che il processo è stato creato. Ho trovato che il processo continua a caricare con un UID di root. Cosa dovrei usare per fare questo?

codice Java (JNA):

public boolean loadVHost(String java, File sockfile) throws IOException { 
    if (CLib.INSTANCE.setegid(suid) != 0) { 
     log("setegid C call failed! @ " + id); 
     return false; 
    } 
    if (CLib.INSTANCE.seteuid(suid) != 0) { 
     log("seteuid C call failed! @ " + id); 
     return false; 
    } 
    if (CLib.INSTANCE.getegid() != suid || CLib.INSTANCE.geteuid() != suid) { 
     log("geteuid/egid C call returned unwanted value! @ " + id + " (returned " + CLib.INSTANCE.getuid() + ":" + CLib.INSTANCE.getgid() + ")"); 
     return false; 
    } 
    File hp = new File(homepath); 
    hp.mkdirs(); 
    File avuna = new File(hp, "avuna.jar"); 
    File main = new File(hp, "main.cfg"); // TODO: add linux user-based RAM/HDD/bandwidth caps 
    File hosts = new File(hp, "hosts.cfg"); 
    if (!avuna.exists() || !main.exists() || !hosts.exists()) { 
     log("VHost corrupted, avuna.jar/main.cfg/hosts.cfg is missing! Reinstalling..."); 
     // if (createVHost(java, sockfile.getAbsolutePath())) { 
     // log("Reinstallation completed, vhost loading..."); 
     // }else { 
     // log("Reinstallation failed, vhost NOT loading."); 
     // return false; 
     // } 
    } 
    ProcessBuilder builder = new ProcessBuilder(java, "-Xmx" + maxram + "M", "-Xms16M", "-jar", avuna.getAbsolutePath(), main.getAbsolutePath()); 
    // TODO: if we want to be able to pass std input/output/err, this would be the place 
    builder.redirectErrorStream(true); 
    this.process = builder.start(); 
    if (CLib.INSTANCE.seteuid(0) != 0) { 
     log("[CRITICAL] setuid C call failed! @ " + id + ", the VHost was loaded, but we were NOT able to re-escalate!"); 
     return false; 
    } 
    if (CLib.INSTANCE.setegid(0) != 0) { 
     log("[CRITICAL] setgid C call failed! @ " + id + ", the VHost was loaded, but we were NOT able to re-escalate!"); 
     return false; 
    } 
    return true; 
} 
+0

Cosa intendi con "caricare un altro processo"? – Brian

+0

Invece di descrivere quello che stai facendo, aiuta a mostrarci il codice. Non deve essere un codice reale, ma un [Esempio minimo, completo e verificabile] (http://stackoverflow.com/help/mcve) sarebbe bello. –

+0

Bene, il mio codice è in realtà Java che chiama JNA, quindi ho pensato che non sarebbe stato molto utile. Lo posterò tra un secondo. @JoachimPileborg – JavaProphet

risposta

0

ho fatto quello che Brian ha suggerito, e utilizzato un altro processo per setuid, quindi appena eseguito la mia roba.