tgXID, tgUTS, tgSYSINFO,
tgFEATURE, tgCANONIFY,
tgVERIFYCAP, tgXIDTYPE, tgVERIFYPROC,
+ tgNID, tgTAG,
} VserverTag;
static struct {
{ "VERIFYCAP", tgVERIFYCAP, "test if the kernel supports linux capabilities" },
{ "VERIFYPROC", tgVERIFYPROC, "test if /proc can be read by contexts!=0" },
{ "XIDTYPE", tgXIDTYPE, "returns the type of the given XID" },
+ { "NID", tgNID, "outputs the network context-id of the given pid" },
+ { "TAG", tgTAG, "outputs the filesystem tag of the given pid" },
};
int wrapper_exit_code = 1;
static bool
verifyCap()
{
+ int retried = 0;
struct __user_cap_header_struct header;
- struct __user_cap_data_struct user;
- header.version = _LINUX_CAPABILITY_VERSION;
+ struct __user_cap_data_struct user[2];
+
+ header.version = _LINUX_CAPABILITY_VERSION_3;
header.pid = 0;
if (getuid()!=0) {
// perror( "prctl:" );
// return false;
// }
-
- if (capget(&header, &user)==-1) {
+
+retry:
+ if (capget(&header, user)==-1) {
+ if (!retried &&
+ header.version != _LINUX_CAPABILITY_VERSION_3) {
+ header.version = _LINUX_CAPABILITY_VERSION_1;
+ retried = 1;
+ goto retry;
+ }
perror("capget()");
return false;
}
- user.effective = 0;
- user.permitted = 0;
- user.inheritable = 0;
+ user[0].effective = user[1].effective = 0;
+ user[0].permitted = user[1].permitted = 0;
+ user[0].inheritable = user[1].inheritable = 0;
- if (capset(&header, &user)==-1) {
+ if (capset(&header, user)==-1) {
perror("capset()");
return false;
}
}
static char *
-getXid(char *buf, char const *pid_str)
+getAPIConfig(char *buf)
+{
+ vc_vci_t v = vc_get_vci();
+ size_t l;
+
+ if (v==-1) return 0;
+
+ l = utilvserver_fmt_xuint64(0, (unsigned int)v);
+ memcpy(buf, "0x0000000000000000", 19);
+ utilvserver_fmt_xuint64(buf+2+16-l, (unsigned int)v);
+
+ return buf;
+}
+
+static inline char *
+getCtxId(char *buf, const char *pid_str, xid_t (*get_id)(pid_t pid), const char *err_str)
{
pid_t pid = atoi(pid_str);
- xid_t xid = vc_get_task_xid(pid);
+ xid_t xid = get_id(pid);
- if (xid==VC_NOCTX) perror("vc_get_task_xid()");
+ if (xid==VC_NOCTX) perror(err_str);
else {
utilvserver_fmt_long(buf, xid);
return buf;
}
static char *
+getXid(char *buf, char const *pid_str)
+{
+ return getCtxId(buf, pid_str, vc_get_task_xid, "vc_get_task_xid()");
+}
+
+static char *
+getNid(char *buf, const char *pid_str)
+{
+ return getCtxId(buf, pid_str, vc_get_task_nid, "vc_get_task_nid()");
+}
+
+static char *
+getTag(char *buf, const char *pid_str)
+{
+ return getCtxId(buf, pid_str, vc_get_task_tag, "vc_get_task_tag()");
+}
+
+static char *
getPXid(char UNUSED *buf, char const UNUSED *vserver)
{
// TODO: implement me when available
"Versions:\n"
" Kernel: ");
WRITE_STR(1, uts.release);
+
WRITE_MSG(1, "\n"
" VS-API: ");
-
memset(buf, 0, 128);
if (getAPIVer(buf)) WRITE_STR(1, buf);
else WRITE_MSG(1, "???");
+
+ WRITE_MSG(1, "\n"
+ " VCI: ");
+ memset(buf, 0, 128);
+ if (getAPIConfig(buf)) WRITE_STR(1, buf);
+ else WRITE_MSG(1, "???");
WRITE_MSG(1, "\n"
" util-vserver: " PACKAGE_VERSION "; " __DATE__ ", " __TIME__"\n"
getContext(char *buf, char const *vserver, bool allow_only_static)
{
xid_t xid = vc_getVserverCtx(vserver, vcCFG_AUTO,
- allow_only_static, 0);
+ allow_only_static, 0, vcCTX_XID);
if (xid==VC_NOCTX) return 0;
utilvserver_fmt_long(buf, xid);
if (isNumber(vserver, &xid, true) && xid>=0)
res = (vc_get_vx_info(xid, &info)==-1) ? 0 : "1";
else
- res = (vc_getVserverCtx(vserver, vcCFG_AUTO, false, 0)==VC_NOCTX) ? 0 : "1";
+ res = (vc_getVserverCtx(vserver, vcCFG_AUTO, false, 0, vcCTX_XID)==VC_NOCTX) ? 0 : "1";
break;
}
case tgFEATURE : return testFeature(argc,argv); break;
case tgVERIFYCAP : return verifyCap() ? 0 : 1; break;
case tgVERIFYPROC : return verifyProc() ? 0 : 1; break;
+ case tgNID : res = getNid(buf, vserver); break;
+ case tgTAG : res = getTag(buf, vserver); break;
default : {
default :
WRITE_MSG(2, "Try '");
WRITE_STR(2, argv[0]);
- WRITE_MSG(2, " --help\" for more information.\n");
+ WRITE_MSG(2, " --help' for more information.\n");
exit(1);
break;
}