On 2011-02-08 17:30, Julian Fagir wrote:
Hi,
I wanted to write a tool starting a shell in a jail. I know, jexec
accomplishes this too, but I want to compile the name of the jail into the
program, no commandline-parameters (more about this topic will be posted on
this list soon).
Thus, I used libjail, more specific jail_getid(3) to get the id of the jail
and start a shell in it.
The name of the jail is 'jail2', it was created by ezjail(5), and the
important lines in /usr/local/etc/ezjail/jail2 are:
export jail_jail2_hostname="zweihorn2"
export jail_jail2_ip="IPADDRESS"
export jail_jail22_rootdir="/usr/jails/jail2"
Anyway, when starting the jail, `jls` bravely shows as the hostname of the
jail 'jail2'.
But when I compile this program (with `cc -ljail jexec_sh.c -o jexec_sh`)
#include<sys/types.h>
#include<sys/param.h>
#include<sys/jail.h>
#include<string.h>
#include<unistd.h>
#include<stdio.h>
#include<jail.h>
#define JAIL_NAME "jail2"
int
main(int argc, char* argv[]) {
char *jname;
int jid;
jid = jail_getid(JAIL_NAME);
printf("Jail 2 is running: %d\n", jid);
jname = jail_getname(jid);
printf("Jailname: '%s' to jid %d\n", jname, jid);
return(0);
}
jail_getid returns -1; meaning the jailname does not exist. When setting
JAIL_NAME to "1" (or "2", etc., according to the jid, if I restarted it), the
jid is correctly returned:
zweihorn1# /home/julian/jexec_sh
Jail 1 is running: 1
Jailname: '1' to jid 1
Am i missing something? jail_getid/jail_getname should return exactly the
output I expected?! ezjail must be setting the name right as jls returns the
correct name. jls does nearly the same, though requesting directly the params
without libjail, but libjail does that internally, too.
Regards, Julian
jail_name and jail_hostname are not the same thing - jls without options
does not display jail_name only hostname - try to look at the output of
"jls -v"
This (pending) patch enabled setting of jail_name from rc.d/rc.conf
framework
http://www.freebsd.org/cgi/query-pr.cgi?pr=conf/150599
/Uffe
_______________________________________________
freebsd-jail@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-jail
To unsubscribe, send any mail to "freebsd-jail-unsubscr...@freebsd.org"