summaryrefslogtreecommitdiff
path: root/srcx/jid.c
diff options
context:
space:
mode:
Diffstat (limited to 'srcx/jid.c')
-rw-r--r--srcx/jid.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/srcx/jid.c b/srcx/jid.c
index a201822..9f48b8b 100644
--- a/srcx/jid.c
+++ b/srcx/jid.c
@@ -1,5 +1,8 @@
#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/jail.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -14,8 +17,8 @@ static void usage();
int main(int argc, char* argv[])
{
- int i;
int jid = 0;
+ char* e;
/* Remove the program name */
argc--;
@@ -24,14 +27,47 @@ int main(int argc, char* argv[])
if(argc != 1)
usage();
- if(in_jail())
+ if(running_in_jail())
errx(1, "can't run from inside jail");
- jid = translate_jail_id(argv[0]);
- if(jid == -1)
- errx(1, "unknown jail host name: %s", argv[0]);
+ jid = strtol(argv[0], &e, 10);
+
+ /* If it was all a number ... */
+ if(!*e)
+ {
+ struct xprison* xp;
+ size_t len, i;
+
+ len = get_jail_sysctl(&xp);
+ if(len > 0)
+ {
+ for(i = 0; i < len; i++)
+ {
+ if(xp[i].pr_id == jid)
+ {
+ printf("%s\n", xp[i].pr_host);
+ jid = -1;
+ break;
+ }
+ }
+
+ free(xp);
+
+ if(jid != -1)
+ errx(1, "unknown jail id: %s", argv[0]);
+ }
+ }
+
+ /* otherwise it's a host name */
+ else
+ {
+ jid = translate_jail_name(argv[0]);
+ if(jid == -1)
+ errx(1, "unknown jail host name: %s", argv[0]);
+
+ printf("%d\n", (int)jid);
+ }
- printf("%d \n", (int)jid);
return 0;
}
@@ -40,3 +76,4 @@ static void usage()
fprintf(stderr, "usage: jid hostname \n");
exit(2);
}
+