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/jail.c | |
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/jail.c')
-rw-r--r-- | usr.sbin/jail/jail.c | 32 |
1 files changed, 26 insertions, 6 deletions
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); } |