ssh client returning error "Couldn't apply options" - libssh

I am getting "Couldn't apply options" while connecting to a SSH server.
When I checked the source code of the library I found the following code in the client.c
which is returning the error.
ret = ssh_options_apply(session);
if (ret < 0) {
ssh_set_error(session, SSH_FATAL, "Couldn't apply options");
leave_function();
return SSH_ERROR;
}
Can anyone please tell me what are the possibilities that could result into this error ?

That no options are set using ssh_options_set(). ssh_options_apply() does sanity checks.

I had the same problem. I don't know why but when I added this "optional" option to the libssh tutorial then it worked:
ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, "random_username");
Put this before setting the hostname option in your main application.

I struggled this problem a lot until I managed to solve it. libssh tries to set SSH_OPTIONS_SSH_DIR option which is basically the path where known_hosts file would be written and it fails. In previous versions of libssh the path was something like "C:/Users/your_user/" by default where ".ssh" folder was created with "known_hosts" file inside. In latest versions you need to specify this path by yourself. And also don't forget to set SSH_OPTIONS_USER too.
ssh_options_set(sshSession, SSH_OPTIONS_SSH_DIR, "C://temp");
ssh_options_set(sshSession, SSH_OPTIONS_USER, "user");
Hope this helps.

Related

Remote-SSH Vscode - problem - "tput: No value for $TERM and no -T specified"

Situation:
I'm unable to connect to remote machnie via vscode + remote-SSH.
I CAN though connect to that machine using SSH from any shell.
Before the problem when I shut down my machine there was mandatory Windows update...
First error I get in terminal just after "You are connected to: [company-servername]" is:
After this there is never-ending error log whit most errors are similar to:
What I have already tried:
reinstalling Remote-ssh
killing vscode remote-server
making additional space on remote
running without any extensions except remote-ssh
reinstalling vscode
deleting all vscode config files and reinstalling
deleting vscode config files on remote in my home
I'm a bit stuck here, and our foreign 'Support' isn't very supportive...
maybe anyone had similar problem or has any idea?
FYI I managed to fix the problem which was really trivial...
Some facts:
Problem was with REMOTE SERVER not VSCODE
As "tput: no value for $TERM" suggested something 'with terminal'
So what I did was clean my .bashrc to some generic sample. And it worked.
After investigation I figured that in my .bashrc I have
source /somepath/myAliases
which causes the problem. So what in that file was wrong?
In 'myAliases' there was broken alias where I used invalid quotation:
alias name='some commands' #OK
alias name="some commands" #OK
alias name=`some commands` # <-- this caused error shown above.
I hope this explanation may be of some use to any of you.
BR

fopen() working with windows but giving issues in linux

I am trying to use fopen() in a program in which I am creating a new file and then using that file into another function. The function is created as follows:-
FILE* check=NULL;
check =fopen(convert_wchartoString(file_Name.c_str()).c_str(), "rb");
if(check==NULL)
{
cout<<"Unable to open";
}
Now, the issue is that fopen is returning NULL in linux but, in windows it is working. I am not sure why this issue is coming. I have debugged the value of file_name and it is coming fine on both the platforms. Please advice something which could be potentially wrong in this?
UPDATE:-
Seems like it is a path issue. Currently, the file_name has path to C:\files but when i try to run the same code in wsl, it doesn't work. The path in wsl is /mnt/c/files. But when trying to give this path to file_name. It is also not working. Is there any permission issues for the same or should I need to modify the path?

How to make QSslSocket support SSL using an OpenSSL installation?

I'm trying to run a simple client/server to implement a communication using QSslSocket. I work on Windows (unfortunately) and I use QtCreator for more convenience.
When I try, from the client side, to connect to the server using MyQSslSocket->connectToHostEncrypted(ip, port), I get the following message:
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
When I print the raised error, I get the following one:
QAbstractSocket::SocketError(20)
In the documentation we can find that this error code corresponds to QAbstractSocket::SslInternalError whose the description is:
"The SSL library being used reported an internal error. This is probably the result of a bad installation or misconfiguration of the library."
After some investigations I found that Qt does not provide OpenSSL by itself so I installed it (the binaries, for both 32 and 64 bits versions to be sure) from here https://slproweb.com/products/Win32OpenSSL.html.
During the installation, the dll was copied to C:\Windows\System32 (for the 64 bits). Then I checked that the PATH environment variable does well contain this folder.
At this point I tried again, but I still had the same problem, as if the OpenSSL installation was still not found.
When I print the output of the following calls (in the main function of my client):
qDebug() << QSslSocket::supportsSsl();
qDebug() << QSslSocket::sslLibraryVersionString();
I get the following outputs:
false""
My question is, how to make QSslSocket::supportsSsl() return true ?
If anyone could teach me what I missed, what I am doing wrong and tell me what I should do to be able to make this SSL connection run properly, I would be very grateful.
Fareanor.
PS: Sorry for the long question but I think it is important to clearly expose the problem and the context to help you to easily understand the problem and give me more relevant answers.
Ok,
Thanks to #AlienPenguin and #Macias advices, it was that my version of OpenSSL was too recent.
Finally I have installed the closest available version of the one used for the Qt build (which does make sense, I should have thought of it) which can be found by running the following call:
qDebug() << QSslSocket::sslLibraryBuildVersionString();
Problem solved.
Thanks again.

How to initialise a git repository with libgit2

On a Windows XP, 32-bit machine I've cloned the libgit2 repository using
git clone git://github.com/libgit2/libgit2.git trunk
Then I configured from trunk_build_debug for mingw using:
cmake ../trunk -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-g
and build-ed it with
make
With this newly build library I'm trying to create a new repository. So I'm using
error_code = git_repository_init( &repo, path, 0 );
if ( error_code != 0 )
{
const git_error * error = giterr_last();
/* the text representation:
( error == NULL || error->message == NULL ?
"(no description)" :
error->message )
*/
}
On first attempt this fails with the error message:
Git error -1: The global file '.config/git/config' doesn't exist: The
system cannot find the file specified.
The .git directory is created and I can use git status to query it. Also, I have git installed in Program Files/git and it works just fine. The file that is mentioned does not exist in user directory, that is true. I'm not happy because I can't check the returned error code (the error may be "real").
So I've created an empty file in D:\Documents and Settings\User Name.config\git\config
The .git directory is again created but I get the same -1 error code. This time giterr_last() returns NULL.
Tracing the code in debugger seems to indicate that the library is not happy with my empty file.
However, I think this indicates that I'm doing something wrong. Is there an initialization method? Do I need to create the file and use the git_config_ functions to point the library to it?
BTW, is this the wrong place to ask this? Is there a dedicated forum where I should ask this question?
Thanks
Here is the back trace where the call fails: pastebin
It seems that the configure file inside .git directory can't be parsed (not shown in in trace is the 'config_parse()' that fails).
I've opened an issue in libgit2.
To create a new repository, one should rather rely on git_repository_init(). For more information, you can peek at the header and the tests.
git_repository_open() should rather be used when the repository already exists.
Is there a dedicated forum where I should ask this question?
It's ok to ask programming related question on StackOverflow. Beside this, some libgit2 developers hang out in the #libgit2 channel on irc.freenode.net. However, when you encounter bugs, it's recommended to submit them to the issue tracker.
Update
There had been some issues in the past with the way the configuration files are being probbed on Windows. Along with some attempts to fix them. See this issue for some background about this.
Beside the complexity of the probbing, some users may want to explictly provide alternate locations for their files. This pull request works this angle.
Considering what you discovered while debugging the libgit2, maybe now would be a good time to open a bug in the issue tracker. Beware that two issues may be at play: the probbing one and and the empty config issue.

Connect to MS SQL Server through ODBC

I have a Qt 4 application that is trying to connect to an MS SQL Server 2008 database using the Qt ODBC driver. The application runs fine when it is running in Windows; however, the target OS for the application is to have it run in GNU/Linux. When the application runs in GNU/Linux I get the following error:
QSqlError(0, "QODBC3: Unable to connect", " [unixODBC][Driver Manager]Data source name not found, and no default driver specified")
Is there something I need to configure on the SQL server or application side to get the connection to work?
I don't really know much about unixODBC, but have a look here:
unixodbc.org/doc/
For connecting to MSSQL, the following might be useful:
http://www.unixodbc.org/doc/FreeTDS.html
or .../FreeTDS2.html
Try to copy the odbc.ini file in ~/.odbc.ini . If not working again, try to copy the same file into /etc/odbc.ini. If this is not working, as these directories are different for different Unix systems, find all files: *odbc*\.ini and see if some of them are empty. If so, replace them with the correct .ini file.
I had the same problem and this solved it. But it's a really stupid solution, so I'm looking for a better one. Hope that helped (: