how to use a callback from a pysnmp V3 command responder? - callback

I am using latest version of pysnmp 4.2.4 and have tested the SNMPV1/2C command responder example (http://pysnmp.sourceforge.net/examples/current/v1arch/agent/cmdrsp.html) which is returning an Uptime value in response to OID 1,3,6,1,2,1,1,3,0
I have used the V3 responder example (http://pysnmp.sourceforge.net/examples/current/v3arch/agent/cmdrsp/v3-multiple-users.html) and have that returning the system value (none) for 1,3,6,1,2,1,1,3,0.
How can I add a call back to the V3 version so that it calls an Uptime class similar to the V1 version (and returns a local value)?
TIA
Steve

The v3 model introduces a notion of MIB instrumentation controller class which provides callbacks - one for read and the other for set operations. Stock MIB controller implementation invokes Managed Object Instances Python objects (each identified by an OID) to get/set their values.
So you could either setup your own MibInstrumentatonController class (see EchoMibInstrumController here) or use stock MIB controller with your own Managed Object Instances (see MyStaticMibScalarInstance here).
The SNMPv3 settings in these examples are slightly different but that is not relevant to MIB implementation.

Related

Kaitai Struct Parameter Type

I am trying to pass a parameter to ksy file. The parameter is of type another ksy file. The reason is that i need to access all the fields from the ksy file passed as parameter.
Is that possible?
If yes, would you please provide me with syntax code snippet so I can mimic it.
If no, what would be another solution?
Thank You.
Affiliate disclaimer: I'm a Kaitai Struct maintainer (see my GitHub profile).
First, I recommend always using the development version of the Kaitai Struct Web IDE (https://ide.kaitai.io/devel/), not the stable one. The stable IDE deployed at https://ide.kaitai.io/ has KS compiler of version 0.8, which is indeed the latest stable version, but already 2 years old at the moment. But the project is under active development, new bug fixes and improvements are coming every week, so the stable Web IDE is pretty much outdated. And thanks to the recent infrastructure enhancement, the devel Web IDE now gets rebuilt every time the compiler is updated, so you can use even the most recent features.
However, you won't be able to simulate the particular situation you describe in the Web IDE, because it can't currently handle top-level parameteric types (there is no hook where you can pass your own values as arguments). But it should work in a local environment. You can compile the commontype.ksy and pty.ksy specs in the Web IDE to the target language you want to use (the manual shows how to do it). The code putting it together could look like this (Java):
Commontype ct = new Commontype(new ByteBufferKaitaiStream(new byte[] { 80, 75 }));
Pty r = new Pty(
new ByteBufferKaitaiStream(new byte[] { 80 }), // IO stream
ct // commonword
);
Note that the actual parameter order of the Pty constructor may be different, e.g. in Python come the custom params (commonword) first and then the IO object. Check the generated code in your particular language.

Free Radius upgrade Issues

I recently upgraded my Free Radius code from 2.0 to 3.x build. I am looking for some of the APIs supported by older Free Radius versions. I am looking for APIs ldap_pairget(). Can you please let me know what APIs should be used in place of ldap_pairget. ALso these function include pairmake(), pairadd(), pairdelete() APIs which are not available in newe Free Radius Code.
Thanks
In v3.0.x theres a concept of "tmpls" (templates) and maps. Templates describe a data source or sink, and maps describe how to move data from one tmpl to another. There are still the low level pair move functions.
Pair allocation fr_pair_alloc.
Assigning value from string fr_pair_value_from_str.
Add a pair to a list fr_pair_add.
Replace an existing pair in a list fr_pair_replace.
Delete a pair by its protocol number fr_pair_delete_by_num.
The equivalent function to ldap_pairget in v3.0.x is fr_ldap_map_do, but it's not designed to be used by external callers. It'll work, but it's a lot of effort to feed it the structures it expects.
In general, if you have user configurable mappings you should call map_to_request, and pass it the callback it needs to get values for the pairs being created.

OPAL-Regarding implementing construct call graph in OPAL

In Paper [A Software Product Line for Static Analyses(2014)], there is an illustration related constructing call graph(Listing7).
In this example, Line14 is related to construct call graph. while i check the src code and API, what i could find is DefaultCHACallGraphDomain.scala which has no implementation of construct call graph.
As my purpose is using OPAL to construct call graph. Is there any demo or documents help me understanding existing CallGraphDomain in OPAL? currently, i can only find some class declaration.
I'll be really appreciated if anyone can give me some suggestions related this topic.
Thanks in advance.
Jiang
The interface that was shown in the paper doesn't exist anymore, so you can totally forget about it.
The default interface to get a CallGraph class is provided by the Project object you retrieve when you load the bytecode a Java project.
A general code Example:
val project = ... // a java project
val computedCallGraph = project.get(/* Some call graph key */)
val callGraph = computedCallGraph.callGraph // the final call graph interface.
The computed call graph contains several things. It contains the entry points, unresolved method calls, exceptions when something went wrong at the construction time and the actual call graph.
OPAL provides you several call graph algorithms, you can retrieve each by passing the corresponding call graph key to the Project's get method.
Currently, the following two keys are available and can be passed to Project.get (more information is available in the documentation of this classes):
CHACallGraphKey
VTACallGraphKey
Analysis mode - Library vs Application
To construct a valid call graph for a software project it depends on the project kind which analysis mode to chose. While applications provide complete information (except incomplete projects, class loading and so on), software libraries are intended to be used by other projects. However, those two different scenarios have to be kept in mind, when construction call graphs. More details can be found here: org.opalj.AnalysisModes
OPAL offers the following analysis modes:
DesktopApplication (safe for application call graphs)
LibraryWithClosePackagesAssumption (safe for call graphs that are used for security-insensitive analyses)
LibraryWithOpenPackagesAssumption (very conservative/safe for security analyses)
The analysis mode can be either configured in OPAL's config file or set as project setting at runtime. You can find the config file in the Common project under /src/main/resources/reference.conf.
All of those analysis modes are supported by the the CHACallGraphKey while VTACallGraphKey only supports applications so far.
NOTE: The interface may change in upcoming versions again.

How to create a UEFI read only variable?

On an EFI system that boots GRUB2, I want to create a read-only EFI variable. Is this possbile?
Thanks,
Mat
According to Uefi Specification 2.7 there is a straight forward way of creating a read-only UEFI variable post ExitBootServices() by not providing EFI_VARIABLE_NON_VOLATILE attribute.
See Chapter '8.2 Variable Services' SetVariable() description:
Once ExitBootServices() is performed, only variables that have
EFI_VARIABLE_RUNTIME_ACCESS and EFI_VARIABLE_NON_VOLATILE set can be
set with SetVariable(). Variables that have runtime access but that are not nonvolatile are read-only data variables once ExitBootServices() is performed.
See also Chapter '8.2 Variable Services' GetVariable() Related Definitions:
//*******************************************************
// Variable Attributes
//*******************************************************
#define EFI_VARIABLE_NON_VOLATILE 0x00000001
According to UEFI Specification 2.5 there is no straight forward way of creating read-only UEFI variable.
Expecting result can be achieved by using variables with Attributes: EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS and EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS.
According to chapter 7.2 (SetVariable description part) of UEFI Spec 2.5:
(...)
An attempt to delete a variable created with the EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS or
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute for which the
prescribed AuthInfo validation fails or when called using DataSize of zero will fail with an
EFI_SECURITY_VIOLATION status.
According to chapter 7.2.1 (Using the EFI_VARIABLE_AUTHENTICATION_2 descriptor), after long procedure describing variable update process:
The driver shall update the value of the variable only if all of these checks pass. If any of the checks
fails, firmware must return EFI_SECURITY_VIOLATION.
Concluding, it is impossible to delete or modify variable, that was created using *_WRITE_ACCESS attributes, without authentication. GetVariable will return correct value indicating in attributes that returned variable requires authentication before update or delete. For more information please read UEFI Spec 2.5 chapter 7.2.1 and 7.2.2.

How can I create a transient domain in libvirt?

How can I create a transient domain using libvirt? (Using QEMU/KVM as back-end)
The documentation discusses the difference between transient and persistent domains at this link: http://wiki.libvirt.org/page/VM_lifecycle#Transient_guest_domains_vs_Persistent_guest_domains
Still, I haven't found any concrete example on how to create one.
The only pointer I found is in this email: https://www.redhat.com/archives/libvirt-users/2011-August/msg00057.html, where the maintainer suggests to add the <transient/> tag in the <disk> field of the XML's description.
When I tried, I got this disappointing answer: "libvirtError: unsupported configuration: transient disks not supported yet".
Is this feature really "not supported yet", or am I missing something? The documentation makes me think that this should be supported.
Any answer related to the C or Python binding, virsh, or virt-manager will be highly appreciated!
Using virsh
If you are using virsh, than there are commands:
define -- This command takes an XML file as it's parameter and makes the domain known to libvirt (you can reference that domain by using its name or UUID).
start -- This command takes the domain name or UUID as its parameter and starts (boots) the domain.
create -- This command takes an XML file as it's parameter and creates (starts) the domain with settings described in that file. Depending on whether the domain is known to libvirt (previously defined with that UUID) it may result in two things:
if it is already defined, the known domain is marked as started, it is persistent domain, but it is started with the settings supplied and not those it was defined with).
in case it is not defined, the domain started is now a transient domain (it disappears when it is destroyed, shuts down, etc.).
undefine -- This command takes a domain name or UUID (or ID if it's started) and makes it unknown to libvirt, but if that domain is running it doesn't destroy it, just marks it transient.
C functions
In C, the APIs that virsh is using for these commands are:
define -- virDomainDefineXML
start -- virDomainCreate
create -- virDomainCreateXML
undefine -- virDomainUndefine
Notes:
The names may be a little bit confusing, but due to backward compatibility it is kept from Xen times.
Most of those mention commands have parameters which may alter the behavior, these may cause using different C functions for the purpose.