static bool IgnoreJailInterface(int ifaceidx, struct sockaddr_in *inaddr) { /* FreeBSD jails */ # ifdef HAVE_JAIL_GET struct iovec fbsd_jparams[4]; struct in_addr fbsd_jia; int fbsd_lastjid = 0; *(const void **) &fbsd_jparams[0].iov_base = "lastjid"; fbsd_jparams[0].iov_len = sizeof("lastjid"); fbsd_jparams[1].iov_base = &fbsd_lastjid; fbsd_jparams[1].iov_len = sizeof(fbsd_lastjid); *(const void **) &fbsd_jparams[2].iov_base = "ip4.addr"; fbsd_jparams[2].iov_len = sizeof("ip4.addr"); fbsd_jparams[3].iov_len = sizeof(struct in_addr); fbsd_jparams[3].iov_base = &fbsd_jia; while ((fbsd_lastjid = jail_get(fbsd_jparams, 4, 0)) > 0) { if (fbsd_jia.s_addr == inaddr->sin_addr.s_addr) { CfOut(OUTPUT_LEVEL_VERBOSE, "", "Interface %d belongs to a FreeBSD jail %s\n", ifaceidx, inet_ntoa(fbsd_jia)); return true; } } # endif return false; }
/* * Return the JID corresponding to a jail name. */ int jail_getid(const char *name) { char *ep; int jid; struct iovec jiov[4]; jid = strtoul(name, &ep, 10); if (*name && !*ep) return jid; *(const void **)&jiov[0].iov_base = "name"; jiov[0].iov_len = sizeof("name"); jiov[1].iov_len = strlen(name) + 1; jiov[1].iov_base = alloca(jiov[1].iov_len); strcpy(jiov[1].iov_base, name); *(const void **)&jiov[2].iov_base = "errmsg"; jiov[2].iov_len = sizeof("errmsg"); jiov[3].iov_base = jail_errmsg; jiov[3].iov_len = JAIL_ERRMSGLEN; jail_errmsg[0] = 0; jid = jail_get(jiov, 4, 0); if (jid < 0 && !jail_errmsg[0]) snprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s", strerror(errno)); return jid; }
/* * Return the name corresponding to a JID. */ char * jail_getname(int jid) { struct iovec jiov[6]; char *name; char namebuf[MAXHOSTNAMELEN]; *(const void **)&jiov[0].iov_base = "jid"; jiov[0].iov_len = sizeof("jid"); jiov[1].iov_base = &jid; jiov[1].iov_len = sizeof(jid); *(const void **)&jiov[2].iov_base = "name"; jiov[2].iov_len = sizeof("name"); jiov[3].iov_base = namebuf; jiov[3].iov_len = sizeof(namebuf); *(const void **)&jiov[4].iov_base = "errmsg"; jiov[4].iov_len = sizeof("errmsg"); jiov[5].iov_base = jail_errmsg; jiov[5].iov_len = JAIL_ERRMSGLEN; jail_errmsg[0] = 0; jid = jail_get(jiov, 6, 0); if (jid < 0) { if (!jail_errmsg[0]) snprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s", strerror(errno)); return NULL; } else { name = strdup(namebuf); if (name == NULL) strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN); } return name; }
VALUE list_func(VALUE self){ puts ("Prison#list()"); u_int niov = 0; int flags = 0; int jg_res = jail_get(iov, niov, flags); printf("%d\n", jg_res); return self; }