--- src/main/java/org/libvirt/Connect.java | 15 +++++++++++ src/main/java/org/libvirt/SecurityModel.java | 37 ++++++++++++++++++++++++++++ src/main/java/org/libvirt/jna/Libvirt.java | 16 +++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/libvirt/SecurityModel.java diff --git a/src/main/java/org/libvirt/Connect.java b/src/main/java/org/libvirt/Connect.java index 1d37c22..04de4fd 100644 --- a/src/main/java/org/libvirt/Connect.java +++ b/src/main/java/org/libvirt/Connect.java @@ -1062,6 +1062,21 @@ public class Connect { } /** + * Returns the security model of the connected node. + */ + public SecurityModel getSecurityModel() throws LibvirtException { + Libvirt.SecurityModel secmodel = new Libvirt.SecurityModel(); + + processError(libvirt.virNodeGetSecurityModel(this.VCP, secmodel)); + + if (secmodel.model[0] == 0) + return null; + else + return new SecurityModel(secmodel); + + } + + /** * Returns the XML description of the sysinfo details for the host * on which the hypervisor is running. * <p> diff --git a/src/main/java/org/libvirt/SecurityModel.java b/src/main/java/org/libvirt/SecurityModel.java new file mode 100644 index 0000000..b41835f --- /dev/null +++ b/src/main/java/org/libvirt/SecurityModel.java @@ -0,0 +1,37 @@ +package org.libvirt; + +import org.libvirt.jna.Libvirt; +import com.sun.jna.Native; + +/** + * A security model used for mandatory access control. + * + * @see Connect#getSecurityModel + */ +public final class SecurityModel { + private String model; + private String doi; + + SecurityModel(Libvirt.SecurityModel secmodel) { + model = Native.toString(secmodel.model, "UTF-8"); + doi = Native.toString(secmodel.doi, "UTF-8"); + } + + /** + * Returns the model of this SecurityModel. + * + * @return the model string + */ + public String getModel() { + return model; + } + + /** + * Returns the DOI, domain of interpretation of this security model. + * + * @return the DOI + */ + public String getDomainOfInterpretation() { + return doi; + } +} diff --git a/src/main/java/org/libvirt/jna/Libvirt.java b/src/main/java/org/libvirt/jna/Libvirt.java index 2958233..024e268 100644 --- a/src/main/java/org/libvirt/jna/Libvirt.java +++ b/src/main/java/org/libvirt/jna/Libvirt.java @@ -40,7 +40,6 @@ import java.util.List; * LIBVIRT_0.6.1 * virFreeError * virSaveLastError - * virNodeGetSecurityModel; * * LIBVIRT_0.6.4 * virInterfaceRef @@ -172,6 +171,20 @@ public interface Libvirt extends Library { } }; + static class SecurityModel extends Structure { + private static final int VIR_SECURITY_MODEL_BUFLEN = 256 + 1; + private static final int VIR_SECURITY_DOI_BUFLEN = 256 + 1; + + private static final List<String> fields = Arrays.asList("model", "doi"); + + public byte model[] = new byte[VIR_SECURITY_MODEL_BUFLEN]; + public byte doi[] = new byte[VIR_SECURITY_DOI_BUFLEN]; + + @Override + protected List<String> getFieldOrder() { + return fields; + } + } /** * @deprecated as of libvirt 0.6.0, all errors reported in the @@ -362,6 +375,7 @@ public interface Libvirt extends Library { int virNodeGetCellsFreeMemory(ConnectionPointer virConnectPtr, LongByReference freeMems, int startCell, int maxCells); long virNodeGetFreeMemory(ConnectionPointer virConnectPtr); + int virNodeGetSecurityModel(ConnectionPointer virConnectPtr, SecurityModel secmodel); // Node/Device functions int virNodeNumOfDevices(ConnectionPointer virConnectPtr, String capabilityName, int flags); -- 2.2.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list