aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2008-03-07 02:11:40 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2008-03-07 02:11:40 +0000
commitc284eb4e38721f567db15bde24ea53822d0cefb4 (patch)
treed126f1958112b7f8afe9039fa112efbd07f53a86 /libssh
parent0d6e3c17903bf370765b24b5f2cfeaf9d5d57e3f (diff)
downloadlibssh-c284eb4e38721f567db15bde24ea53822d0cefb4.tar.gz
libssh-c284eb4e38721f567db15bde24ea53822d0cefb4.tar.xz
libssh-c284eb4e38721f567db15bde24ea53822d0cefb4.zip
second part of win32 changes
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@143 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh')
-rw-r--r--libssh/client.c1
-rw-r--r--libssh/init.c6
-rw-r--r--libssh/misc.c23
-rw-r--r--libssh/options.c18
-rw-r--r--libssh/server.c1
-rw-r--r--libssh/socket.c13
6 files changed, 59 insertions, 3 deletions
diff --git a/libssh/client.c b/libssh/client.c
index c498a9ad..e931fe4e 100644
--- a/libssh/client.c
+++ b/libssh/client.c
@@ -235,6 +235,7 @@ int ssh_connect(SSH_SESSION *session){
session->alive=0;
session->client=1;
ssh_crypto_init();
+ ssh_socket_init();
if(options->fd==-1 && !options->host){
ssh_set_error(session,SSH_FATAL,"Hostname required");
return SSH_ERROR;
diff --git a/libssh/init.c b/libssh/init.c
index f1ae11f0..5a242844 100644
--- a/libssh/init.c
+++ b/libssh/init.c
@@ -22,6 +22,9 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "libssh/priv.h"
+#ifdef _WIN32
+#include <winsock2.h>
+#endif
int ssh_finalize()
{
@@ -31,5 +34,8 @@ int ssh_finalize()
#elif defined HAVE_LIBCRYPTO
EVP_cleanup();
#endif
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 0;
}
diff --git a/libssh/misc.c b/libssh/misc.c
index b9400f7d..84dd4eaf 100644
--- a/libssh/misc.c
+++ b/libssh/misc.c
@@ -24,11 +24,20 @@ MA 02111-1307, USA. */
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
-#include <pwd.h>
#include <sys/types.h>
+
+#ifdef _WIN32
+#define _WIN32_IE 0x0400 //SHGetSpecialFolderPath
+#include <shlobj.h>
+#include <winsock2.h>
+#else
+#include <pwd.h>
#include <netdb.h>
+#endif
+
#include "libssh/libssh.h"
+#ifndef _WIN32
/* if the program was executed suid root, don't trust the user ! */
static int is_trusted(){
if(geteuid()!=getuid())
@@ -77,6 +86,18 @@ char *ssh_get_user_home_dir(){
return get_homedir_from_uid(getuid());
}
+#else /* _WIN32 */
+
+char *ssh_get_user_home_dir(){
+ static char szPath[MAX_PATH];
+ if (SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, TRUE))
+ return szPath;
+ else
+ return NULL;
+}
+
+#endif
+
/* we have read access on file */
int ssh_file_readaccess_ok(char *file){
if(!access(file,R_OK))
diff --git a/libssh/options.c b/libssh/options.c
index 8c6c7253..04bcb553 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -23,7 +23,9 @@ MA 02111-1307, USA. */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#ifndef _WIN32
#include <pwd.h>
+#endif
#include <sys/types.h>
#include "libssh/priv.h"
@@ -176,7 +178,7 @@ void ssh_options_set_username(SSH_OPTIONS *opt, char *username){
* \param opt options structure
* \param fd an opened file descriptor to use
*/
-void ssh_options_set_fd(SSH_OPTIONS *opt, int fd){
+void ssh_options_set_fd(SSH_OPTIONS *opt, socket_t fd){
opt->fd=fd;
}
@@ -289,6 +291,7 @@ int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list){
return 0;
}
+#ifndef _WIN32
static char *get_username_from_uid(SSH_OPTIONS *opt, int uid){
struct passwd *pwd;
char *user;
@@ -303,6 +306,7 @@ static char *get_username_from_uid(SSH_OPTIONS *opt, int uid){
ssh_set_error(opt,SSH_FATAL,"uid %d doesn't exist !",uid);
return NULL;
}
+#endif
/* this function must be called when no specific username has been asked. it has to guess it */
int ssh_options_default_username(SSH_OPTIONS *opt){
@@ -314,11 +318,23 @@ int ssh_options_default_username(SSH_OPTIONS *opt){
opt->username=strdup(user);
return 0;
}
+#ifndef _WIN32
user=get_username_from_uid(opt,getuid());
if(user){
opt->username=user;
return 0;
}
+#else
+ DWORD Size = 0;
+ GetUserName(NULL, &Size); //Get Size
+ user = malloc(Size);
+ if (GetUserName(user, &Size)){
+ opt->username=user;
+ return 0;
+ } else {
+ free(user);
+ }
+#endif
return -1;
}
diff --git a/libssh/server.c b/libssh/server.c
index 4f28c6a1..cbc6eea8 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -94,6 +94,7 @@ int ssh_bind_listen(SSH_BIND *ssh_bind){
int fd;
if(!ssh_bind->options)
return -1;
+ ssh_socket_init();
host=ssh_bind->options->bindaddr;
if(!host)
host="0.0.0.0";
diff --git a/libssh/socket.c b/libssh/socket.c
index 52a318d6..09b48573 100644
--- a/libssh/socket.c
+++ b/libssh/socket.c
@@ -35,7 +35,18 @@ struct socket {
int last_errno;
};
-
+/*
+ * \internal
+ * \brief inits the socket system (windows specific)
+ */
+void ssh_socket_init(){
+#ifdef _WIN32
+ struct WSAData wsaData;
+ if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
+ ssh_say(1,"Error initialising Windows sockets.\n");
+ }
+#endif
+}
/*
* \internal
* \brief creates a new Socket object