Linux build compatible

Same source builds both in Linux and windows
This commit is contained in:
arif-pragmasys 2015-11-04 16:15:04 -06:00
parent 7683cc1f65
commit 9ec4bf235c
13 changed files with 122 additions and 64 deletions

View File

@ -37,8 +37,9 @@
*/
#include "includes.h"
#ifdef WIN32_FIXME
#include "xmalloc.h"
#endif
/*
* We support only client side kerberos on Windows.

View File

@ -8,8 +8,7 @@
*/
/* #undef AIX_GETNAMEINFO_HACK */
/* Define if your AIX loginfailed() function takes 4 arguments (AIX >= 5.2)
*/
/* Define if your AIX loginfailed() function takes 4 arguments (AIX >= 5.2) */
/* #undef AIX_LOGINFAILED_4ARG */
/* System only supports IPv4 audit records */
@ -39,8 +38,8 @@
/* Ultrix mmap can't map files */
/* #undef BROKEN_MMAP */
/* Define if your struct dirent expects you to allocate extra space for
d_name */
/* Define if your struct dirent expects you to allocate extra space for d_name
*/
/* #undef BROKEN_ONE_BYTE_DIRENT_D_NAME */
/* Can't do comparisons on readv */
@ -683,8 +682,7 @@
/* Define to 1 if you have the `openpty' function. */
/* #undef HAVE_OPENPTY */
/* Define if your ssl headers are included with #include <openssl/header.h>
*/
/* Define if your ssl headers are included with #include <openssl/header.h> */
#define HAVE_OPENSSL 1
/* Define if you have Digital Unix Security Integration Architecture */
@ -816,6 +814,9 @@
/* Define to 1 if you have the `setluid' function. */
/* #undef HAVE_SETLUID */
/* Define to 1 if you have the `setpassent' function. */
/* #undef HAVE_SETPASSENT */
/* Define to 1 if you have the `setpcred' function. */
/* #undef HAVE_SETPCRED */
@ -1289,8 +1290,7 @@
/* Need setpgrp to acquire controlling tty */
/* #undef NEED_SETPGRP */
/* Define if the concept of ports only accessible to superusers isn't known
*/
/* Define if the concept of ports only accessible to superusers isn't known */
#define NO_IPPORT_RESERVED_CONCEPT 1
/* Define if you don't want to use lastlog in session.c */

View File

@ -127,7 +127,11 @@
#if defined(HAVE_SECURITY_PAM_APPL_H)
# include <security/pam_appl.h>
#elif defined (HAVE_PAM_PAM_APPL_H)
#ifdef WIN32_FIXME
# include <security/pam_appl.h>
#else
# include <pam/pam_appl.h>
#endif
#endif
#endif
#ifdef HAVE_READPASSPHRASE_H

4
key.c
View File

@ -5,9 +5,7 @@
#include "includes.h"
#ifndef WIN32_FIXME
#include <openbsd-compat/openssl-compat.h>
#else
#ifdef WIN32_FIXME
#include "openbsd-compat/openssl-compat.h"
#endif

23
misc.c
View File

@ -545,7 +545,11 @@ char *
tilde_expand_filename(const char *filename, uid_t uid)
{
const char *path, *sep;
#ifdef WIN32_FIXME
char user[128], ret[MAXPATHLEN], *ret2;
#else
char user[128], *ret;
#endif
struct passwd *pw;
u_int len, slash;
@ -578,15 +582,9 @@ tilde_expand_filename(const char *filename, uid_t uid)
}
else if (snprintf(ret, sizeof(ret), "%ls", pw -> pw_dir) <= 0)
#else
if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret))
#endif
/* Make sure directory has a trailing '/' */
#ifdef WIN32_FIXME
// len = strlen(ret);
// if ((len == 0 || ret[len - 1] != '/') &&
// strlcat(ret, "/", sizeof(ret)) >= sizeof(ret))
#else
#ifndef WIN32_FIXME
len = strlen(pw->pw_dir);
if (len == 0 || pw->pw_dir[len - 1] != '/')
sep = "/";
@ -598,14 +596,17 @@ tilde_expand_filename(const char *filename, uid_t uid)
if (path != NULL)
filename = path + 1;
#ifdef WIN32_FIXME
if (xasprintf(&ret2, "%s%s", ret, filename) >= PATH_MAX)
#ifndef WIN32_FIXME
if (xasprintf(&ret, "%s%s%s", pw->pw_dir, sep, filename) >= PATH_MAX)
#else
if (xasprintf(&ret2, "%s%s%s", pw->pw_dir, sep, filename) >= PATH_MAX)
if (xasprintf(&ret2, "%s%s", ret, filename) >= PATH_MAX)
#endif
fatal("tilde_expand_filename: Path too long");
#ifdef WIN32_FIXME
return (ret2);
#else
return (ret);
#endif
}
/*

View File

@ -415,8 +415,10 @@ ssh_packet_connection_af(struct ssh *ssh)
if (getsockname(ssh->state->connection_out, (struct sockaddr *)&to,
&tolen) < 0)
return 0;
#ifdef WIN32_FIXME
if (to.ss_family == AF_INET)
return 1;
#endif
#ifdef IPV4_IN_IPV6
if (to.ss_family == AF_INET6 &&
IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr))

View File

@ -382,9 +382,15 @@ clear_forwardings(Options *options)
options->tun_open = SSH_TUNMODE_NO;
}
#ifdef WIN32_FIXME
void
add_identity_file(Options *options, const char *dir, const char *filename,
int userprovided, struct passwd *pw)
#else
void
add_identity_file(Options *options, const char *dir, const char *filename,
int userprovided)
#endif
{
char *path;
int i;
@ -1004,8 +1010,13 @@ parse_time:
if (*intptr >= SSH_MAX_IDENTITY_FILES)
fatal("%.200s line %d: Too many identity files specified (max %d).",
filename, linenum, SSH_MAX_IDENTITY_FILES);
#ifdef WIN32_FIXME
add_identity_file(options, NULL,
arg, flags & SSHCONF_USERCONF, pw);
#else
add_identity_file(options, NULL,
arg, flags & SSHCONF_USERCONF);
#endif
}
break;
@ -1837,19 +1848,40 @@ void fill_default_options(Options * options, struct passwd *pw)
if (options->num_identity_files == 0) {
if (options->protocol & SSH_PROTO_1) {
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_IDENTITY, 0, pw);
#else
_PATH_SSH_CLIENT_IDENTITY, 0);
#endif
}
if (options->protocol & SSH_PROTO_2) {
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_RSA, 0, pw);
#else
_PATH_SSH_CLIENT_ID_RSA, 0);
#endif
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_DSA, 0, pw);
#else
_PATH_SSH_CLIENT_ID_DSA, 0);
#endif
#ifdef OPENSSL_HAS_ECC
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_ECDSA, 0, pw);
#else
_PATH_SSH_CLIENT_ID_ECDSA, 0);
#endif
#endif
add_identity_file(options, "~/",
#ifdef WIN32_FIXME
_PATH_SSH_CLIENT_ID_ED25519, 0, pw);
#else
_PATH_SSH_CLIENT_ID_ED25519, 0);
#endif
}
}
if (options->escape_char == -1)

View File

@ -206,6 +206,10 @@ void dump_client_config(Options *o, const char *host);
void add_local_forward(Options *, const struct Forward *);
void add_remote_forward(Options *, const struct Forward *);
#ifdef WIN32_FIXME
void add_identity_file(Options *, const char *, const char *, int, struct passwd *);
#else
void add_identity_file(Options *, const char *, const char *, int);
#endif
#endif /* READCONF_H */

View File

@ -406,9 +406,11 @@ typedef enum {
sBadOption, /* == unknown option */
/* Portable-specific options */
sUsePAM,
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
sPAMLibrary,
#endif /* RUNTIME_LIBPAM */
#endif
/* Standard Options */
sPort, sHostKeyFile, sServerKeyBits, sLoginGraceTime,
sKeyRegenerationTime, sPermitRootLogin, sLogFacility, sLogLevel,
@ -458,14 +460,18 @@ static struct {
/* Portable-specific options */
#ifdef USE_PAM
{ "usepam", sUsePAM, SSHCFG_GLOBAL },
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
{"pamlibrary", sPAMLibrary, SSHCFG_GLOBAL},
#endif /* RUNTIME_LIBPAM */
#endif
#else
{ "usepam", sUnsupported, SSHCFG_GLOBAL },
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
{"pamlibrary", sUnsupported, SSHCFG_GLOBAL},
#endif /* RUNTIME_LIBPAM */
#endif
#endif
{ "pamauthenticationviakbdint", sDeprecated, SSHCFG_GLOBAL },
/* Standard Options */
@ -1028,6 +1034,7 @@ process_server_config_line(ServerOptions *options, char *line,
case sUsePAM:
intptr = &options->use_pam;
goto parse_flag;
#ifdef WIN32_FIXME
#ifdef RUNTIME_LIBPAM
/*
@ -1042,7 +1049,7 @@ process_server_config_line(ServerOptions *options, char *line,
}
#endif /* RUNTIME_LIBPAM */
#endif
/* Standard Options */
case sBadOption:
return -1;

View File

@ -201,9 +201,10 @@ typedef struct {
int fingerprint_hash;
#ifdef WIN32_FIXME
int i_am_a_fake_fork;
char *pamLibrary_;
#endif
char *pamLibrary_;
} ServerOptions;
/* Information about the incoming connection as used by Match */

View File

@ -1537,8 +1537,11 @@ main(int ac, char **av)
__progname = ssh_get_progname(av[0]);
seed_rng();
#ifdef WIN32_FIXME
while ((ch = getopt(ac, av, "cDdksE:a:t:f")) != -1) { // PRAGMA:TODO
#else
while ((ch = getopt(ac, av, "cDdksE:a:t:")) != -1) {
#endif
switch (ch) {
case 'E':
fingerprint_hash = ssh_digest_alg_by_name(optarg);

12
ssh.c
View File

@ -840,7 +840,11 @@ main(int ac, char **av)
strerror(errno));
break;
}
#ifdef WIN32_FIXME
add_identity_file(&options, NULL, optarg, 1, pw);
#else
add_identity_file(&options, NULL, optarg, 1);
#endif
break;
case 'I':
#ifdef ENABLE_PKCS11
@ -1808,9 +1812,6 @@ ssh_session(void)
int interactive = 0;
int have_tty = 0;
struct winsize ws;
#ifndef WIN32_FIXME
struct winsize ws;
#endif
char *cp;
const char *display;
@ -2265,7 +2266,8 @@ load_public_identity_files(void)
explicit_bzero(pwdir, strlen(pwdir));
free(pwdir);
}
#ifdef SIGCHLD
#ifndef WIN32_FIXME
static void
main_sigchld_handler(int sig)
{
@ -2281,3 +2283,5 @@ main_sigchld_handler(int sig)
errno = save_errno;
}
#endif

3
ssh2.h
View File

@ -115,13 +115,14 @@
#define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60
#define SSH2_MSG_USERAUTH_INFO_REQUEST 60
#define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
#ifdef WIN32_FIXME
#define SSH2_MSG_USERAUTH_JPAKE_CLIENT_STEP1 60
#define SSH2_MSG_USERAUTH_JPAKE_SERVER_STEP1 61
#define SSH2_MSG_USERAUTH_JPAKE_CLIENT_STEP2 62
#define SSH2_MSG_USERAUTH_JPAKE_SERVER_STEP2 63
#define SSH2_MSG_USERAUTH_JPAKE_CLIENT_CONFIRM 64
#define SSH2_MSG_USERAUTH_JPAKE_SERVER_CONFIRM 65
#endif
/* connection protocol: generic */
#define SSH2_MSG_GLOBAL_REQUEST 80