revert motw entirely for scp and sftp (#668)
* revert motw entirely for scp and sftp * revert scp
This commit is contained in:
parent
29ad502773
commit
e4b56ece19
|
@ -60,8 +60,6 @@
|
|||
#include "w32fd.h"
|
||||
#include "inc\string.h"
|
||||
#include "inc\time.h"
|
||||
#include "..\..\..\atomicio.h"
|
||||
#include "urlmon.h"
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
|
@ -137,9 +135,6 @@ int chroot_path_len = 0;
|
|||
/* UTF-16 version of the above */
|
||||
wchar_t* chroot_pathw = NULL;
|
||||
|
||||
/* motw zone_id initialized to invalid value */
|
||||
DWORD motw_zone_id = 5;
|
||||
|
||||
int
|
||||
usleep(unsigned int useconds)
|
||||
{
|
||||
|
@ -2158,99 +2153,3 @@ strrstr(const char *inStr, const char *pattern)
|
|||
return last;
|
||||
}
|
||||
|
||||
int
|
||||
add_mark_of_web(const char* filename)
|
||||
{
|
||||
if (motw_zone_id > 4) {
|
||||
return -1;
|
||||
}
|
||||
char* fileStreamPath = NULL;
|
||||
size_t fileStreamPathLen = strlen(filename) + strlen(":Zone.Identifier") + 1;
|
||||
|
||||
fileStreamPath = malloc(fileStreamPathLen * sizeof(char));
|
||||
|
||||
if (fileStreamPath == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf_s(fileStreamPath, fileStreamPathLen, "%s:Zone.Identifier", filename);
|
||||
|
||||
int ofd, status = 0;
|
||||
char* zoneIdentifierStr = NULL;
|
||||
size_t zoneIdentifierLen = strlen("[ZoneTransfer]\nZoneId=") + 1 + 1;
|
||||
|
||||
zoneIdentifierStr = malloc(zoneIdentifierLen * sizeof(char));
|
||||
|
||||
if (zoneIdentifierStr == NULL) {
|
||||
status = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
sprintf_s(zoneIdentifierStr, zoneIdentifierLen, "[ZoneTransfer]\nZoneId=%d", motw_zone_id);
|
||||
|
||||
// create zone identifer file stream and then write the Mark of the Web to it
|
||||
if ((ofd = open(fileStreamPath, O_WRONLY | O_CREAT, USHRT_MAX)) == -1) {
|
||||
status = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (atomicio(vwrite, ofd, zoneIdentifierStr, zoneIdentifierLen) != zoneIdentifierLen) {
|
||||
status = -1;
|
||||
}
|
||||
|
||||
if (close(ofd) == -1) {
|
||||
status = -1;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
free(fileStreamPath);
|
||||
if (zoneIdentifierStr)
|
||||
free(zoneIdentifierStr);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Gets the zone identifier value based on the provided hostname,
|
||||
and sets the global motw_zone_id variable with that value. */
|
||||
void get_zone_identifier(const char* hostname) {
|
||||
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
debug("CoInitializeEx for MapUrlToZone failed");
|
||||
return;
|
||||
}
|
||||
IInternetSecurityManager *pIISM = NULL;
|
||||
// CLSID_InternetSecurityManager & IID_IInternetSecurityManager declared in urlmon.h
|
||||
hr = CoCreateInstance(&CLSID_InternetSecurityManager, NULL,
|
||||
CLSCTX_ALL, &IID_IInternetSecurityManager, (void**)&pIISM);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
debug("CoCreateInstance for MapUrlToZone failed");
|
||||
goto out;
|
||||
}
|
||||
wchar_t *hostname_w = NULL, *hostformat_w = NULL;
|
||||
hostname_w = utf8_to_utf16(hostname);
|
||||
if (hostname_w == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
size_t hostname_w_len = wcslen(hostname_w) + wcslen(L"ftp://") + 1;
|
||||
hostformat_w = malloc(hostname_w_len * sizeof(wchar_t));
|
||||
if (hostformat_w == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
swprintf_s(hostformat_w, hostname_w_len, L"ftp://%s", hostname_w);
|
||||
hr = pIISM->lpVtbl->MapUrlToZone(pIISM, hostformat_w, &motw_zone_id, 0);
|
||||
if (hr == S_OK) {
|
||||
debug("MapUrlToZone zone identifier value: %d", motw_zone_id);
|
||||
}
|
||||
else {
|
||||
motw_zone_id = 5;
|
||||
debug("MapUrlToZone failed, resetting motw_zone_id to invalid value");
|
||||
}
|
||||
cleanup:
|
||||
if (pIISM)
|
||||
pIISM->lpVtbl->Release(pIISM);
|
||||
if (hostname_w)
|
||||
free(hostname_w);
|
||||
if (hostformat_w)
|
||||
free(hostformat_w);
|
||||
out:
|
||||
CoUninitialize();
|
||||
}
|
||||
|
|
|
@ -49,9 +49,6 @@ extern char* chroot_path;
|
|||
extern int chroot_path_len;
|
||||
extern wchar_t* chroot_pathw;
|
||||
|
||||
/* motw zone_id */
|
||||
extern DWORD motw_zone_id;
|
||||
|
||||
/* removes first '/' for Windows paths that are unix styled. Ex: /c:/ab.cd */
|
||||
wchar_t * resolved_path_utf16(const char *);
|
||||
char* resolved_path_utf8(const char *);
|
||||
|
@ -86,5 +83,3 @@ int lookup_principal_name(const wchar_t * sam_account_name, wchar_t * user_princ
|
|||
BOOL is_bash_test_env();
|
||||
int bash_to_win_path(const char *in, char *out, const size_t out_len);
|
||||
void debug_assert_internal();
|
||||
int add_mark_of_web(const char* filename);
|
||||
void get_zone_identifier(const char* hostname);
|
||||
|
|
14
scp.c
14
scp.c
|
@ -138,9 +138,6 @@
|
|||
|
||||
#include "sftp-common.h"
|
||||
#include "sftp-client.h"
|
||||
#ifdef WINDOWS
|
||||
#include "misc_internal.h"
|
||||
#endif // WINDOWS
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
|
@ -1215,9 +1212,6 @@ do_sftp_connect(char *host, char *user, int port, char *sftp_direct,
|
|||
reminp, remoutp, pidp) < 0)
|
||||
return NULL;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
get_zone_identifier(host);
|
||||
#endif // WINDOWS
|
||||
return do_init(*reminp, *remoutp,
|
||||
sftp_copy_buflen, sftp_nrequests, limit_kbps);
|
||||
}
|
||||
|
@ -1517,9 +1511,6 @@ tolocal(int argc, char **argv, enum scp_mode_e mode, char *sftp_direct)
|
|||
continue;
|
||||
}
|
||||
/* SCP */
|
||||
#ifdef WINDOWS
|
||||
get_zone_identifier(host);
|
||||
#endif // WINDOWS
|
||||
xasprintf(&bp, "%s -f %s%s",
|
||||
cmd, *src == '-' ? "-- " : "", src);
|
||||
if (do_cmd(ssh_program, host, suser, sport, 0, bp,
|
||||
|
@ -2174,11 +2165,6 @@ sink(int argc, char **argv, const char *src)
|
|||
omode = mode;
|
||||
mode |= S_IWUSR;
|
||||
#ifdef WINDOWS
|
||||
// only attempt mark of the web for pull case (from remote to local)
|
||||
if (!iamremote && add_mark_of_web(np) == -1) {
|
||||
debug3_f("%s: add_mark_of_web failed\n", np);
|
||||
}
|
||||
|
||||
// In windows, we would like to inherit the parent folder permissions by setting mode to USHRT_MAX.
|
||||
if ((ofd = open(np, O_WRONLY|O_CREAT, USHRT_MAX)) == -1) {
|
||||
#else
|
||||
|
|
|
@ -1837,11 +1837,6 @@ do_download(struct sftp_conn *conn, const char *remote_path,
|
|||
status = SSH2_FX_FAILURE;
|
||||
else
|
||||
status = SSH2_FX_OK;
|
||||
#ifdef WINDOWS
|
||||
if (add_mark_of_web(local_path) == -1) {
|
||||
debug("%s: failed to add mark of the web", local_path);
|
||||
}
|
||||
#endif // WINDOWS
|
||||
/* Override umask and utimes if asked */
|
||||
#ifdef HAVE_FCHMOD
|
||||
if (preserve_flag && fchmod(local_fd, mode) == -1)
|
||||
|
|
|
@ -56,9 +56,6 @@
|
|||
|
||||
#include "sftp.h"
|
||||
#include "sftp-common.h"
|
||||
#ifdef WINDOWS
|
||||
#include "misc_internal.h"
|
||||
#endif // WINDOWS
|
||||
|
||||
char *sftp_realpath(const char *, char *); /* sftp-realpath.c */
|
||||
|
||||
|
@ -2087,10 +2084,6 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
|
|||
logit("session opened for local user %s from [%s]",
|
||||
pw->pw_name, client_addr);
|
||||
|
||||
#ifdef WINDOWS
|
||||
get_zone_identifier(client_addr);
|
||||
#endif // WINDOWS
|
||||
|
||||
in = STDIN_FILENO;
|
||||
out = STDOUT_FILENO;
|
||||
|
||||
|
|
Loading…
Reference in New Issue