diff options
author | philip <philip@FreeBSD.org> | 2005-12-03 17:32:39 +0000 |
---|---|---|
committer | philip <philip@FreeBSD.org> | 2005-12-03 17:32:39 +0000 |
commit | 865e779b5d6ed4275a000576a9d4af4bf4b52706 (patch) | |
tree | a7da8029ecda4d884a884fff5ccee9bef7f49e21 /usr.sbin/jail | |
parent | da548b327a83e5cbfe0aa258e27ef20cb2dea46b (diff) | |
download | FreeBSD-src-865e779b5d6ed4275a000576a9d4af4bf4b52706.zip FreeBSD-src-865e779b5d6ed4275a000576a9d4af4bf4b52706.tar.gz |
Add [-J jid_file] option to write out a JidFile, similar to a PidFile,
containing the jailid, path, hostname, ip and the command used to start
the jail.
PR: misc/89883
Submitted by: L. Jason Godsey <lannygodsey -at- yahoo.com>
Reviewed by: phk
MFC after: 1 week
Diffstat (limited to 'usr.sbin/jail')
-rw-r--r-- | usr.sbin/jail/jail.8 | 4 | ||||
-rw-r--r-- | usr.sbin/jail/jail.c | 32 |
2 files changed, 30 insertions, 6 deletions
diff --git a/usr.sbin/jail/jail.8 b/usr.sbin/jail/jail.8 index 0583f0e..bbdd336 100644 --- a/usr.sbin/jail/jail.8 +++ b/usr.sbin/jail/jail.8 @@ -42,6 +42,7 @@ .Sh SYNOPSIS .Nm .Op Fl i +.Op Fl J Ar jid_file .Op Fl l u Ar username | Fl U Ar username .Ar path hostname ip-number command ... .Sh DESCRIPTION @@ -53,6 +54,9 @@ The options are as follows: .Bl -tag -width ".Fl u Ar username" .It Fl i Output the jail identifier of the newly created jail. +.It Fl J Ar jid_file +Write a JidFile, like a PidFile, containing jailid, path, hostname, ip and +command used to start the jail. .It Fl l Run program in the clean environment. The environment is discarded except for diff --git a/usr.sbin/jail/jail.c b/usr.sbin/jail/jail.c index 84cab55..76bb01d 100644 --- a/usr.sbin/jail/jail.c +++ b/usr.sbin/jail/jail.c @@ -54,19 +54,25 @@ main(int argc, char **argv) struct passwd *pwd = NULL; struct in_addr in; gid_t groups[NGROUPS]; - int ch, i, iflag, lflag, ngroups, uflag, Uflag; - char path[PATH_MAX], *username; + int ch, i, iflag, Jflag, lflag, ngroups, uflag, Uflag; + char path[PATH_MAX], *username, *JidFile; static char *cleanenv; const char *shell, *p = NULL; + FILE *fp; - iflag = lflag = uflag = Uflag = 0; - username = cleanenv = NULL; + iflag = Jflag = lflag = uflag = Uflag = 0; + username = JidFile = cleanenv = NULL; + fp = NULL; - while ((ch = getopt(argc, argv, "ilu:U:")) != -1) { + while ((ch = getopt(argc, argv, "ilu:U:J:")) != -1) { switch (ch) { case 'i': iflag = 1; break; + case 'J': + JidFile = optarg; + Jflag = 1; + break; case 'u': username = optarg; uflag = 1; @@ -103,6 +109,11 @@ main(int argc, char **argv) if (inet_aton(argv[2], &in) == 0) errx(1, "Could not make sense of ip-number: %s", argv[2]); j.ip_number = ntohl(in.s_addr); + if (Jflag) { + fp = fopen(JidFile, "w"); + if (fp == NULL) + errx(1, "Could not create JidFile: %s", JidFile); + } i = jail(&j); if (i == -1) err(1, "jail"); @@ -110,6 +121,15 @@ main(int argc, char **argv) printf("%d\n", i); fflush(stdout); } + if (Jflag) { + if (fp != NULL) { + fprintf(fp, "%d\t%s\t%s\t%s\t%s\n", + i, j.path, j.hostname, argv[2], argv[3]); + (void)fclose(fp); + } else { + errx(1, "Could not write JidFile: %s", JidFile); + } + } if (username != NULL) { if (Uflag) GET_USER_INFO; @@ -149,7 +169,7 @@ usage(void) { (void)fprintf(stderr, "%s%s\n", - "usage: jail [-i] [-l -u username | -U username]", + "usage: jail [-i] [-J jid_file] [-l -u username | -U username]", " path hostname ip-number command ..."); exit(1); } |