OpenDBX odbx_init blocks with gdb (eclipse) - sql

I am testing OpenDBX to connect to MSSQL server for a project on Ubuntu Linux.
I am using C/C++ and eclipse CDT IDE.
I built a simple test app from the OpenDBX Web page (below without error testing shown).
odbx_init( &handle, "mssql", "172.16.232.60", "" );
odbx_bind( handle, "testdb", "testuser", "testpwd", ODBX_BIND_SIMPLE );
odbx_finish( handle );
Problem:
When I run the code from shell or Run->Run I see connection established with server (wireshark).
When I attempt to run from with eclipse debugger the application blocks on odbx_init(...) and I see nothing go out on wireshark (SYN/ACK).
I have gdb setup as sudo, (how to debug application as root in eclipse in Ubuntu?)
I also use this same platform and setup to access network with sockets with other applications we are developing.
Any ideas on why odbx_init might be blocking from debugger?
One last bit of information to add. The issue does not occur when using the C++ API. Only the C API presents the issue described.
One last bit of information to add.
The issue does not occur when using the C++ API.
Only the C API presents the issue described.

I found a "work-around". Apparently the dynamic load of the library fails when in the eclipse GDB debug mode. To work around this at beginning of main I explicitly load the library and then close it immediately. This puts the library in memory so when the calls to the OpenDBX API are made the library is already resident. Not sure about all the low level details but this allows me to debug OpenDBX in eclipse. If anyone has a better explanation or fix/work-around please let me know. Here is the workaround code at beginning of main():
void *lib_handle_mssql;
lib_handle_mssql = dlopen("/usr/lib/opendbx/libmssqlbackend.so",RTLD_NOW);
if(!lib_handle_mssql)
{
// Bad, Bad, Bad...
printf("%s\n",dlerror());
exit(EXIT_FAILURE);
}
dlclose(lib_handle_mssql);
// Can now debug in eclipse IDE.

Related

How to run/debug open-source macOS `Privileges` app w/ XPC service/daemon and DockTile plugin

I'm attempting to try out some modifications in SAP's Privileges.app. Unfortunately, their (understandable) Support policy is
This project is 'as-is' with no support, no changes being made. You are welcome to make changes to improve it but we are not available for questions or support of any kind.
Unfortunately, this app uses two constructs I've never come across before in my professional experience, an XPC service + helper (Launch daemon?) and a DockTile plugin. I'm having a hard time just fundamentally getting the app to work when launched from Xcode - it launches, but it seems that there are issues between (maybe?) sandboxing, signing and perhaps entitlements? I've updated the signing to use my own team, of course, and everything compiles/links/launches properly, but when the XPC service tries to install the helper tool it fails
2022-06-29 17:03:56.284544-0500 PrivilegesXPC[13079:128535] [logging-persist] cannot open file at line 45530 of [9ff244ce07]
2022-06-29 17:03:56.284570-0500 PrivilegesXPC[13079:128535] [logging-persist] os_unix.c:45530: (0) open(/var/db/DetachedSignatures) - Undefined error: 0
2022-06-29 17:04:21.060214-0500 PrivilegesXPC[13079:128537] SAPCorp: ERROR! Failed to connect to helper tool: NSCocoaErrorDomain / 4097
2022-06-29 17:04:31.471555-0500 Privileges[13064:127420] SAPCorp: ERROR! Error Domain=NSPOSIXErrorDomain Code=25 "Inappropriate ioctl for device"
2022-06-29 17:04:45.717751-0500 Privileges[13064:129162] SAPCorp: ERROR! Installation of the helper tool failed: Error Domain=CFErrorDomainLaunchd Code=4 "(null)"
As near as I can tell, the last two errors are thrown from a failure in
success = SMJobBless(
kSMDomainSystemLaunchd,
CFSTR("corp.sap.privileges.helper"),
self->_authRef,
&error
);
but I haven't been able to ascertain why this is failing. Searching for errors around Inappropriate ioctl for device has not been fruitful, unfortunately.
If there's anyone out there with some experience in dealing with apps using some of these more esoteric moving parts that can share some things to try, I'd be much obliged. Bonus points if there's any way to debug code running in a DockTile plugin - as near as I can tell, it's running in SystemUIServer, but I can't attach to that (even as root) from Xcode.
I think I've sorted out getting this running. Here's a few roadblocks I encountered.
SMJobBless has some very particular expectations around code-signing - you'll find references to this in some forum posts and there's a sample project that's also referenced with a utility script - which doesn't run on modern macOS because it's written for Python 2 -- which isn't installed by default anymore and a bit difficult to come by. But, after agonizingly converting Python 2-isms over to Python 3, you'll come to find out that that's not the only thing that's changed, a number of the tools (codesign and otool) don't output the same on ARM64 at which time you'll finally stumble across a kind soul that converted SMJobBless.py ... only to find out that it's not actually needed for this project?! Not sure if it's because the Launch Service is contained in the XPC and not the app, but either way - it seems to not be needed.
If you've run Privileges before, it'll have installed it's escalated helper, which will stand in the way of a local Xcode build copying itself over - which matters because of the aforementioned code signing. You'll need to clear away these artifacts
$ sudo rm -rf /Library/PrivilegedHelperTools/corp.sap.privileges.helper
$ sudo rm /Library/LaunchDaemons/corp.sap.privileges.helper.plist
Just deleting them isn't enough, it seems some sort of runtime launchd state needs to be wiped. It's unclear to me if some incantation of launchctl will clear this out, maybe an invocation of launchctl kickstart -k <foo> or something? I ended up rebooting and that seemed to do the trick anyway.
It seems like you need a particular signing certificate to allow the various signing validations that SMJobBless and the XPC communications are doing to be valid. Particularly, it seems you'll need a Developer ID Application, which happens to match what's encoded in the .xcodeproj pulled down from the GitHub repo. This means you can't enable Automatically manage signing as you won't get this type of certificate (as near as I can tell - please correct me if I'm wrong).
Once you've got all that sorted, since you aren't signing with the SAP developer's certificate, your certificate will have a different unique Team ID, so you'll need to update SMAuthorizedClients and SMPrivilegedExecutables, respectively, (look for 7R5ZEU67FQ and replace with your team ID) in
PrivilegesHelper/PrivilegesHelper-Info.plist
PrivilegesXPC/Info.plist
I think that's basically got it. Hope that helps someone else

Using IOSleep in socket filtering kernel extension

I'm developing a kernel extension which processes every socket is build on system and waits in user space to get confirmation from user to allow or deny that socket.
I'm using IOSleep to apply the wait i mentioned above but it gives this error when loading kernel extension.
"the following symbols are unresolved for this kext:
_IOSleep"
First of all , i want to know am i correct about using IOSleep to make waiting ?
If not , how should i apply desired waiting to cover time interval that i need to get user confirmation about allowing or rejecting a specific socket connection?
Thanks in advance for any useful response.
IOSleep is perfectly fine in a kernel extension. The error you see is because libraries are linked to kexts at load time, not compile time.
When you add functions to your code that require linking against new libraries, you must call kextlibs on the compiled binary in order to find out what you need to add to the plist file. This is explained in the Add Library Declarations section of the Generic Kernel Extension tutorial in the Mac Developer Library, but it's easy to forget to do this after the first time.
The basic steps are:
Build your kext
Run the command kextlibs -xml MyKext.kext in the Terminal
Replace the <key>OSBundleLibraries</key><dict>...</dict> part of your kext's Info.plist file with the printout from the above
Rebuild your kext
It should now link correctly when you load it with kextload.

JVMTI native agent (DLL) can not be loaded to a runing Java program - AgentLoadException

I struggled on this issue for a few days but didn't get a right answer yet.
Here is the Problem Description:
I wrote a normal Java program (Program-A), and wrote a Windows-based native agent (*.dll, written in C/C++) with Agent_OnLoad, Agent_OnAttach, Agent_OnUnload method, which works fine if using Java command-line flag (-agentlib). Then I wrote another Java program to attach the native agent onto a runing the Java Program-A (see the below code piece for VM attach and loadAgentPath), however I got the exception:
com.sun.tools.attach.AgentLoadException: Failed to load agent library
I tried to change the agentPath (absolute or relative file path) this or that way, none of these works. Should I try some other way to make this work. What I need is to attach a native agent onto a runing java program rather than using command-line flag.
Does anyone know the root cause or a clue for the solution?
BTW, the command line to run attach VM Java code as:
java -Djava.library.path=D:\DevTools\Java7\jre7\bin -classpath .;./tools.jar com.xxx.TestAgentVMAttacher
...
VirtualMachine virtualMachine = com.sun.tools.attach.VirtualMachine.attach(pid); // Note: this code line is executed normally, I am sure the pid is correct
...
agentPath = theFilePath + "/myagent.dll"; // Note: I am sure the dll file path is correct
virtualMachine.loadAgentPath(agentPath,null); // Note: this code line would cause the exception (AgentLoadException) as I mentioned above, no matter how I set the agentPath, even I set it as null, same exception happened.
Environment related info:
- OS: Windows XP
- Java Version: Java(TM) SE Runtime Environment (build 1.7.0-b147)
Eventually I found the answer for my question, I had a wrong method name ('Agent_Attach') in Agent.cpp file, the correct one should be 'Agent_OnAttach', with this fix, my agent lib (.dll) can be loaded to a running Java program now.

Idea with PHP (not only) error handling & IDE jump-to-error-line

I have some idea with error handling in PHP - way to immediately get to place in code where error occurred.
I have written error handler to catch PHP errors, which loads file, that caused an error and displays +/- few lines of code from that file. It also mark line where error occurred and print stack trace, like this:
http://img834.imageshack.us/img834/3754/errh.png
Now, I have an idea, to provide some link (a href=) like other than http protocols (torrent:// or sth), like "netbeans://C:/some/file.php#110" which will put me back into NetBeans editor, open file where error occurred and put cursor in line, which caused a error.
Any ideas how to achieve that goal ?
What you need to do is register a custom url protocol. The techniques depend on the underlying operating system. here's is an example for windows. By opening NetBeans with a system call and the --open [filename] argument, you can open the file in question. However, that way you won't be able to go to a specific line.
In order to do so, you need to use the NetBeans API. If needed, you can use JNBridge to access Java functionality from .NET languages (which you'd need for windows).
All in all, it won't be easy and not cross-platform. A much easier way to go is to use xDebug on the server side and implement the library in the NetBeans editor, which will allow a lot more functionality than what you currently try to accomplish (stack traces, Jumping in Code, Stepping, variable views, ... - just to name a few). There seems to be a started proposal on this for the NetBeans editor.
If you do not care to switch the editor, you can check out Eclipse PHP Development Tools (Eclipse PDT), which has the debugger already implemented. Check out this article on the setup instructions.
I'd use xDebug with Netbean's xdebug integration which already jumps to the errors.
NetBeans IDE already has this option
Please open your project in NetBeans IDE.
main menu -> options -> editor -> hints -> select language php & select all check-boxes.
then refresh project show highlighting errors or undefined variables warnings.
if more with NetBeans IDE
http://netbeans.org/kb/docs/php/editorguide.html

Why would a native program run fine when executed directly, but fail with a seg fault when submitted through condor

I have a third party library that I'm attempting to incorporate into a simulation. We have the static library (.a), along with all of it's runtime dependencies (shared objects). I've created a very simple application (in C) that is linked against the library. All it does is call an initialization function that is part of the third party library's API, and exits. When I run this directly from the command line, it works fine. If I submit the executable to our Condor grid, it fails with a seg fault on strncpy (libc.so.6). I've forced condor to only run the executable on a particular machine, and if I run it directly on that machine, it works fine.
I'm mostly a Java programmer... limited amount of native coding experience. I'm familiar with tools such as nm, ldd, catchsegv, etc... to the point where I can run them. I don't really know where to start looking for an issue though.
I've run ldd directly on the executing machine, and via a script submitted through condor, along with my executable. ldd reports the same files in both cases.
I don't understand how running it directly would work, but it would fail being run by condor. The process that ultimately executes the program, condor_startd, is a process that starts as root, and changes its effective uid to the submitter. Perhaps this has something to do with it?
Don't know why this would cause an issue, but the culprit was the LANG environment variable. It was not set when running under Condor, but was set to US_EN.UTF-8 when running locally. Adding this value to the condor execution environment fixed the problem.