Skip to content

Commit e4b56ec

Browse files
authored
revert motw entirely for scp and sftp (#668)
* revert motw entirely for scp and sftp * revert scp
1 parent 29ad502 commit e4b56ec

File tree

6 files changed

+0
-135
lines changed

6 files changed

+0
-135
lines changed

contrib/win32/win32compat/misc.c

-101
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
#include "w32fd.h"
6161
#include "inc\string.h"
6262
#include "inc\time.h"
63-
#include "..\..\..\atomicio.h"
64-
#include "urlmon.h"
6563

6664
#include <wchar.h>
6765

@@ -137,9 +135,6 @@ int chroot_path_len = 0;
137135
/* UTF-16 version of the above */
138136
wchar_t* chroot_pathw = NULL;
139137

140-
/* motw zone_id initialized to invalid value */
141-
DWORD motw_zone_id = 5;
142-
143138
int
144139
usleep(unsigned int useconds)
145140
{
@@ -2158,99 +2153,3 @@ strrstr(const char *inStr, const char *pattern)
21582153
return last;
21592154
}
21602155

2161-
int
2162-
add_mark_of_web(const char* filename)
2163-
{
2164-
if (motw_zone_id > 4) {
2165-
return -1;
2166-
}
2167-
char* fileStreamPath = NULL;
2168-
size_t fileStreamPathLen = strlen(filename) + strlen(":Zone.Identifier") + 1;
2169-
2170-
fileStreamPath = malloc(fileStreamPathLen * sizeof(char));
2171-
2172-
if (fileStreamPath == NULL) {
2173-
return -1;
2174-
}
2175-
2176-
sprintf_s(fileStreamPath, fileStreamPathLen, "%s:Zone.Identifier", filename);
2177-
2178-
int ofd, status = 0;
2179-
char* zoneIdentifierStr = NULL;
2180-
size_t zoneIdentifierLen = strlen("[ZoneTransfer]\nZoneId=") + 1 + 1;
2181-
2182-
zoneIdentifierStr = malloc(zoneIdentifierLen * sizeof(char));
2183-
2184-
if (zoneIdentifierStr == NULL) {
2185-
status = -1;
2186-
goto cleanup;
2187-
}
2188-
2189-
sprintf_s(zoneIdentifierStr, zoneIdentifierLen, "[ZoneTransfer]\nZoneId=%d", motw_zone_id);
2190-
2191-
// create zone identifer file stream and then write the Mark of the Web to it
2192-
if ((ofd = open(fileStreamPath, O_WRONLY | O_CREAT, USHRT_MAX)) == -1) {
2193-
status = -1;
2194-
goto cleanup;
2195-
}
2196-
2197-
if (atomicio(vwrite, ofd, zoneIdentifierStr, zoneIdentifierLen) != zoneIdentifierLen) {
2198-
status = -1;
2199-
}
2200-
2201-
if (close(ofd) == -1) {
2202-
status = -1;
2203-
}
2204-
2205-
cleanup:
2206-
free(fileStreamPath);
2207-
if (zoneIdentifierStr)
2208-
free(zoneIdentifierStr);
2209-
return status;
2210-
}
2211-
2212-
/* Gets the zone identifier value based on the provided hostname,
2213-
and sets the global motw_zone_id variable with that value. */
2214-
void get_zone_identifier(const char* hostname) {
2215-
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
2216-
if (!SUCCEEDED(hr)) {
2217-
debug("CoInitializeEx for MapUrlToZone failed");
2218-
return;
2219-
}
2220-
IInternetSecurityManager *pIISM = NULL;
2221-
// CLSID_InternetSecurityManager & IID_IInternetSecurityManager declared in urlmon.h
2222-
hr = CoCreateInstance(&CLSID_InternetSecurityManager, NULL,
2223-
CLSCTX_ALL, &IID_IInternetSecurityManager, (void**)&pIISM);
2224-
if (!SUCCEEDED(hr)) {
2225-
debug("CoCreateInstance for MapUrlToZone failed");
2226-
goto out;
2227-
}
2228-
wchar_t *hostname_w = NULL, *hostformat_w = NULL;
2229-
hostname_w = utf8_to_utf16(hostname);
2230-
if (hostname_w == NULL) {
2231-
goto cleanup;
2232-
}
2233-
size_t hostname_w_len = wcslen(hostname_w) + wcslen(L"ftp://") + 1;
2234-
hostformat_w = malloc(hostname_w_len * sizeof(wchar_t));
2235-
if (hostformat_w == NULL) {
2236-
goto cleanup;
2237-
}
2238-
swprintf_s(hostformat_w, hostname_w_len, L"ftp://%s", hostname_w);
2239-
hr = pIISM->lpVtbl->MapUrlToZone(pIISM, hostformat_w, &motw_zone_id, 0);
2240-
if (hr == S_OK) {
2241-
debug("MapUrlToZone zone identifier value: %d", motw_zone_id);
2242-
}
2243-
else {
2244-
motw_zone_id = 5;
2245-
debug("MapUrlToZone failed, resetting motw_zone_id to invalid value");
2246-
}
2247-
cleanup:
2248-
if (pIISM)
2249-
pIISM->lpVtbl->Release(pIISM);
2250-
if (hostname_w)
2251-
free(hostname_w);
2252-
if (hostformat_w)
2253-
free(hostformat_w);
2254-
out:
2255-
CoUninitialize();
2256-
}

contrib/win32/win32compat/misc_internal.h

-5
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ extern char* chroot_path;
4949
extern int chroot_path_len;
5050
extern wchar_t* chroot_pathw;
5151

52-
/* motw zone_id */
53-
extern DWORD motw_zone_id;
54-
5552
/* removes first '/' for Windows paths that are unix styled. Ex: /c:/ab.cd */
5653
wchar_t * resolved_path_utf16(const char *);
5754
char* resolved_path_utf8(const char *);
@@ -86,5 +83,3 @@ int lookup_principal_name(const wchar_t * sam_account_name, wchar_t * user_princ
8683
BOOL is_bash_test_env();
8784
int bash_to_win_path(const char *in, char *out, const size_t out_len);
8885
void debug_assert_internal();
89-
int add_mark_of_web(const char* filename);
90-
void get_zone_identifier(const char* hostname);

scp.c

-14
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@
138138

139139
#include "sftp-common.h"
140140
#include "sftp-client.h"
141-
#ifdef WINDOWS
142-
#include "misc_internal.h"
143-
#endif // WINDOWS
144141

145142
extern char *__progname;
146143

@@ -1215,9 +1212,6 @@ do_sftp_connect(char *host, char *user, int port, char *sftp_direct,
12151212
reminp, remoutp, pidp) < 0)
12161213
return NULL;
12171214
}
1218-
#ifdef WINDOWS
1219-
get_zone_identifier(host);
1220-
#endif // WINDOWS
12211215
return do_init(*reminp, *remoutp,
12221216
sftp_copy_buflen, sftp_nrequests, limit_kbps);
12231217
}
@@ -1517,9 +1511,6 @@ tolocal(int argc, char **argv, enum scp_mode_e mode, char *sftp_direct)
15171511
continue;
15181512
}
15191513
/* SCP */
1520-
#ifdef WINDOWS
1521-
get_zone_identifier(host);
1522-
#endif // WINDOWS
15231514
xasprintf(&bp, "%s -f %s%s",
15241515
cmd, *src == '-' ? "-- " : "", src);
15251516
if (do_cmd(ssh_program, host, suser, sport, 0, bp,
@@ -2174,11 +2165,6 @@ sink(int argc, char **argv, const char *src)
21742165
omode = mode;
21752166
mode |= S_IWUSR;
21762167
#ifdef WINDOWS
2177-
// only attempt mark of the web for pull case (from remote to local)
2178-
if (!iamremote && add_mark_of_web(np) == -1) {
2179-
debug3_f("%s: add_mark_of_web failed\n", np);
2180-
}
2181-
21822168
// In windows, we would like to inherit the parent folder permissions by setting mode to USHRT_MAX.
21832169
if ((ofd = open(np, O_WRONLY|O_CREAT, USHRT_MAX)) == -1) {
21842170
#else

sftp-client.c

-5
Original file line numberDiff line numberDiff line change
@@ -1837,11 +1837,6 @@ do_download(struct sftp_conn *conn, const char *remote_path,
18371837
status = SSH2_FX_FAILURE;
18381838
else
18391839
status = SSH2_FX_OK;
1840-
#ifdef WINDOWS
1841-
if (add_mark_of_web(local_path) == -1) {
1842-
debug("%s: failed to add mark of the web", local_path);
1843-
}
1844-
#endif // WINDOWS
18451840
/* Override umask and utimes if asked */
18461841
#ifdef HAVE_FCHMOD
18471842
if (preserve_flag && fchmod(local_fd, mode) == -1)

sftp-server.c

-7
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@
5656

5757
#include "sftp.h"
5858
#include "sftp-common.h"
59-
#ifdef WINDOWS
60-
#include "misc_internal.h"
61-
#endif // WINDOWS
6259

6360
char *sftp_realpath(const char *, char *); /* sftp-realpath.c */
6461

@@ -2087,10 +2084,6 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
20872084
logit("session opened for local user %s from [%s]",
20882085
pw->pw_name, client_addr);
20892086

2090-
#ifdef WINDOWS
2091-
get_zone_identifier(client_addr);
2092-
#endif // WINDOWS
2093-
20942087
in = STDIN_FILENO;
20952088
out = STDOUT_FILENO;
20962089

sftp.c

-3
Original file line numberDiff line numberDiff line change
@@ -2735,9 +2735,6 @@ main(int argc, char **argv)
27352735
freeargs(&args);
27362736

27372737
conn = do_init(in, out, copy_buffer_len, num_requests, limit_kbps);
2738-
#ifdef WINDOWS
2739-
get_zone_identifier(host);
2740-
#endif //WINDOWS
27412738
if (conn == NULL)
27422739
fatal("Couldn't initialise connection to server");
27432740

0 commit comments

Comments
 (0)