This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 267715
Collapse All | Expand All

(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteDirectory.java (-21 / +1 lines)
Lines 554-579 Link Here
554
        }
554
        }
555
    }
555
    }
556
556
557
    private boolean isProhibited() {
558
        final String path = getPath();
559
        if (path.equals("/proc") || getPath().equals("/dev")) { //NOI18N
560
            return true;
561
        }
562
        if (path.equals("/run")) { //NOI18N
563
        if (HostInfoUtils.isHostInfoAvailable(getExecutionEnvironment())) {
564
                try {
565
                    HostInfo hi = HostInfoUtils.getHostInfo(getExecutionEnvironment());
566
                    if (hi.getOSFamily() == HostInfo.OSFamily.LINUX) {
567
                        return true;
568
                    }
569
                } catch (IOException | ConnectionManager.CancellationException ex) {
570
                    Exceptions.printStackTrace(ex); // should never be the case if isHostInfoAvailable retured true
571
                }
572
            }
573
        }
574
        return false;
575
    }
576
577
    private void warmupDirs() {
557
    private void warmupDirs() {
578
        if (RemoteFileSystemUtils.getBoolean("remote.warmup", true)) {
558
        if (RemoteFileSystemUtils.getBoolean("remote.warmup", true)) {
579
            setFlag(MASK_WARMUP, true);
559
            setFlag(MASK_WARMUP, true);
Lines 627-633 Link Here
627
607
628
    private Map<String, DirEntry> readEntries(DirectoryStorage oldStorage, boolean forceRefresh, String childName) 
608
    private Map<String, DirEntry> readEntries(DirectoryStorage oldStorage, boolean forceRefresh, String childName) 
629
            throws TimeoutException, IOException, InterruptedException, ExecutionException, CancellationException {
609
            throws TimeoutException, IOException, InterruptedException, ExecutionException, CancellationException {
630
        if (isProhibited()) {
610
        if (getFileSystem().isProhibitedToEnter(getPath())) {
631
            return Collections.<String, DirEntry>emptyMap();
611
            return Collections.<String, DirEntry>emptyMap();
632
        }
612
        }
633
        readEntryReqs.incrementAndGet();
613
        readEntryReqs.incrementAndGet();
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/RemoteFileSystem.java (+26 lines)
Lines 69-74 Link Here
69
import org.netbeans.api.annotations.common.NonNull;
69
import org.netbeans.api.annotations.common.NonNull;
70
import org.netbeans.modules.dlight.libs.common.PathUtilities;
70
import org.netbeans.modules.dlight.libs.common.PathUtilities;
71
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
71
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
72
import org.netbeans.modules.nativeexecution.api.HostInfo;
72
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
73
import org.netbeans.modules.nativeexecution.api.util.CommonTasksSupport;
73
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener;
74
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener;
74
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
75
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
Lines 230-235 Link Here
230
        }
231
        }
231
    }
232
    }
232
233
234
    public List<String> getDirsProhibitedToStat(String path) {
235
        synchronized (autoMounts) {
236
            return Collections.unmodifiableList(autoMounts);
237
        }
238
    }
239
240
    public boolean isProhibitedToEnter(String path) {
241
        if (path.equals("/proc") || path.equals("/dev")) { //NOI18N
242
            return true;
243
        }
244
        if (path.equals("/run")) { //NOI18N
245
        if (HostInfoUtils.isHostInfoAvailable(getExecutionEnvironment())) {
246
                try {
247
                    HostInfo hi = HostInfoUtils.getHostInfo(getExecutionEnvironment());
248
                    if (hi.getOSFamily() == HostInfo.OSFamily.LINUX) {
249
                        return true;
250
                    }
251
                } catch (IOException | ConnectionManager.CancellationException ex) {
252
                    Exceptions.printStackTrace(ex); // should never be the case if isHostInfoAvailable retured true
253
                }
254
            }
255
        }
256
        return false;
257
    }
258
233
    public boolean isDirectAutoMountChild(String path) {
259
    public boolean isDirectAutoMountChild(String path) {
234
        String parent = PathUtilities.getDirName(path);
260
        String parent = PathUtilities.getDirName(path);
235
        if (parent != null && ! parent.isEmpty()) {
261
        if (parent != null && ! parent.isEmpty()) {
(-)a/dlight.remote.impl/src/org/netbeans/modules/remote/impl/fs/server/FSSDispatcher.java (-5 / +30 lines)
Lines 82-87 Link Here
82
import org.netbeans.modules.remote.impl.RemoteLogger;
82
import org.netbeans.modules.remote.impl.RemoteLogger;
83
import org.netbeans.modules.remote.impl.fs.RefreshManager;
83
import org.netbeans.modules.remote.impl.fs.RefreshManager;
84
import org.netbeans.modules.remote.impl.fs.RemoteExceptions;
84
import org.netbeans.modules.remote.impl.fs.RemoteExceptions;
85
import org.netbeans.modules.remote.impl.fs.RemoteFileSystem;
85
import org.netbeans.modules.remote.impl.fs.RemoteFileSystemManager;
86
import org.netbeans.modules.remote.impl.fs.RemoteFileSystemManager;
86
import org.netbeans.modules.remote.impl.fs.RemoteFileSystemUtils;
87
import org.netbeans.modules.remote.impl.fs.RemoteFileSystemUtils;
87
import org.netbeans.modules.remote.impl.fs.ui.RemoteNotifier;
88
import org.netbeans.modules.remote.impl.fs.ui.RemoteNotifier;
Lines 134-140 Link Here
134
    
135
    
135
    private volatile FileSystemProvider.AccessCheckType accessCheckType;
136
    private volatile FileSystemProvider.AccessCheckType accessCheckType;
136
    
137
    
137
    private static final String MIN_SERVER_VERSION = "1.7.0"; // NOI18N
138
    private static final String MIN_SERVER_VERSION = "1.10.0"; // NOI18N
138
    
139
    
139
    private FSSDispatcher(ExecutionEnvironment env) {
140
    private FSSDispatcher(ExecutionEnvironment env) {
140
        this.env = env;
141
        this.env = env;
Lines 147-156 Link Here
147
    }
148
    }
148
    
149
    
149
    private void addToRefresh(String path) {
150
    private void addToRefresh(String path) {
150
        RefreshManager refreshManager = RemoteFileSystemManager.getInstance().getFileSystem(env).getRefreshManager();
151
        RefreshManager refreshManager = getFileSystem().getRefreshManager();
151
        refreshManager.scheduleRefreshExistent(Arrays.asList(path), false);
152
        refreshManager.scheduleRefreshExistent(Arrays.asList(path), false);
152
    }
153
    }
153
    
154
155
    private RemoteFileSystem getFileSystem() {
156
        return RemoteFileSystemManager.getInstance().getFileSystem(env);
157
    }
158
154
    public static FSSDispatcher getInstance(ExecutionEnvironment env) {
159
    public static FSSDispatcher getInstance(ExecutionEnvironment env) {
155
        synchronized (instanceLock) {
160
        synchronized (instanceLock) {
156
            FSSDispatcher instance = instances.get(env);
161
            FSSDispatcher instance = instances.get(env);
Lines 169-175 Link Here
169
    public void connected() {
174
    public void connected() {
170
        boolean wasValid  = valid;
175
        boolean wasValid  = valid;
171
        valid = true;
176
        valid = true;
172
        if (wasValid && RemoteFileSystemManager.getInstance().getFileSystem(env).getRoot().getImplementor().hasCache()) {
177
        if (wasValid && getFileSystem().getRoot().getImplementor().hasCache()) {
173
            RP.post(new ConnectTask());
178
            RP.post(new ConnectTask());
174
        }
179
        }
175
    }
180
    }
Lines 597-602 Link Here
597
                RP.post(new ErrorReader(server.getProcess().getErrorStream()));
602
                RP.post(new ErrorReader(server.getProcess().getErrorStream()));
598
                try {
603
                try {
599
                    handShake();
604
                    handShake();
605
                    setupProhibitedToLstat();
600
                } catch (InitializationException ex) {
606
                } catch (InitializationException ex) {
601
                    server = null;
607
                    server = null;
602
                    setInvalid(true);
608
                    setInvalid(true);
Lines 608-613 Link Here
608
        }
614
        }
609
    }
615
    }
610
    
616
    
617
    private void setupProhibitedToLstat() {
618
        List<String> forbiddenPaths = getFileSystem().getDirsProhibitedToStat(traceName);
619
        if(forbiddenPaths == null || forbiddenPaths.isEmpty()) {
620
            return;
621
        }
622
        FsServer srv = server;
623
        if (srv == null) {
624
            return; // this should not happen, but server is not final => need to check
625
        }
626
        StringBuilder sb = new StringBuilder("dirs-forbidden-to-stat=");
627
        boolean first = true;
628
        for (String path : forbiddenPaths) {
629
            sb.append(path).append(first ? "" : ":");
630
            first = false;
631
        }
632
        FSSRequest req = new FSSRequest(FSSRequestKind.FS_REQ_OPTION, sb.toString());
633
        sendRequest(server.getWriter(), req);
634
    }
635
611
    private void handShake() throws IOException, InitializationException, InterruptedException {
636
    private void handShake() throws IOException, InitializationException, InterruptedException {
612
        FSSRequest infoReq = new FSSRequest(FSSRequestKind.FS_REQ_SERVER_INFO, "");
637
        FSSRequest infoReq = new FSSRequest(FSSRequestKind.FS_REQ_SERVER_INFO, "");
613
        sendRequest(server.getWriter(), infoReq);
638
        sendRequest(server.getWriter(), infoReq);
Lines 770-776 Link Here
770
            if (cleanupUponStart) {
795
            if (cleanupUponStart) {
771
                argsList.add("-c"); // NOI18N
796
                argsList.add("-c"); // NOI18N
772
            } else {
797
            } else {
773
                if (!RemoteFileSystemManager.getInstance().getFileSystem(env).getRoot().getImplementor().hasCache()) {
798
                if (!getFileSystem().getRoot().getImplementor().hasCache()) {
774
                    // there is no cache locally => clean remote cache as well
799
                    // there is no cache locally => clean remote cache as well
775
                    argsList.add("-c"); // NOI18N
800
                    argsList.add("-c"); // NOI18N
776
                }
801
                }
(-)a/dlight.remote.impl/tools/fs_server/nbproject/configurations.xml (-6 / +3 lines)
Lines 38-44 Link Here
38
38
39
Contributor(s):
39
Contributor(s):
40
-->
40
-->
41
<configurationDescriptor version="97">
41
<configurationDescriptor version="100">
42
  <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">
42
  <logicalFolder name="root" displayName="root" projectFiles="true" kind="ROOT">
43
    <df root="." name="0">
43
    <df root="." name="0">
44
      <df name="src">
44
      <df name="src">
Lines 134-140 Link Here
134
    </conf>
134
    </conf>
135
    <conf name="Solaris-x86" type="0" platformSpecific="true">
135
    <conf name="Solaris-x86" type="0" platformSpecific="true">
136
      <toolsSet>
136
      <toolsSet>
137
        <compilerSet>OracleSolarisStudio|OracleSolarisStudio</compilerSet>
137
        <compilerSet>OracleDeveloperStudio|OracleDeveloperStudio</compilerSet>
138
        <platform>1</platform>
138
        <platform>1</platform>
139
        <dependencyChecking>false</dependencyChecking>
139
        <dependencyChecking>false</dependencyChecking>
140
        <rebuildPropChanged>false</rebuildPropChanged>
140
        <rebuildPropChanged>false</rebuildPropChanged>
Lines 344-350 Link Here
344
    </conf>
344
    </conf>
345
    <conf name="Solaris-SPARC" type="0" platformSpecific="true">
345
    <conf name="Solaris-SPARC" type="0" platformSpecific="true">
346
      <toolsSet>
346
      <toolsSet>
347
        <compilerSet>OracleSolarisStudio|OracleSolarisStudio</compilerSet>
347
        <compilerSet>OracleDeveloperStudio|OracleDeveloperStudio</compilerSet>
348
        <platform>0</platform>
348
        <platform>0</platform>
349
        <dependencyChecking>false</dependencyChecking>
349
        <dependencyChecking>false</dependencyChecking>
350
        <rebuildPropChanged>false</rebuildPropChanged>
350
        <rebuildPropChanged>false</rebuildPropChanged>
Lines 535-546 Link Here
535
            </incDir>
535
            </incDir>
536
            <preprocessorList>
536
            <preprocessorList>
537
              <Elem>LINUX</Elem>
537
              <Elem>LINUX</Elem>
538
              <Elem>NDEBUG</Elem>
539
              <Elem>_GNU_SOURCE</Elem>
538
              <Elem>_GNU_SOURCE</Elem>
540
              <Elem>_POSIX_PTHREAD_SEMANTICS</Elem>
541
              <Elem>_REENTRANT</Elem>
539
              <Elem>_REENTRANT</Elem>
542
              <Elem>_XOPEN_SOURCE=700</Elem>
540
              <Elem>_XOPEN_SOURCE=700</Elem>
543
              <Elem>__EXTENSIONS__</Elem>
544
            </preprocessorList>
541
            </preprocessorList>
545
          </cTool>
542
          </cTool>
546
        </makeTool>
543
        </makeTool>
(-)a/dlight.remote.impl/tools/fs_server/src/fs_server.c (-7 / +105 lines)
Lines 95-101 Link Here
95
//static bool shutting_down = false;
95
//static bool shutting_down = false;
96
96
97
#define FS_SERVER_MAJOR_VERSION 1
97
#define FS_SERVER_MAJOR_VERSION 1
98
#define FS_SERVER_MID_VERSION 9
98
#define FS_SERVER_MID_VERSION 10
99
#define FS_SERVER_MINOR_VERSION 0
99
#define FS_SERVER_MINOR_VERSION 0
100
100
101
typedef struct fs_entry {
101
typedef struct fs_entry {
Lines 221-226 Link Here
221
    return result;
221
    return result;
222
}
222
}
223
223
224
/// a mutex that guards both dirs_forbidden_to_stat and dirs_forbidden_to_stat_data
225
static pthread_mutex_t forbidden_dirs_mutex = PTHREAD_MUTEX_INITIALIZER;
226
227
/// directories that are forbidden to stat; the last element is null
228
static const char** dirs_forbidden_to_stat = NULL;
229
230
/// just a buffer to keep strings in dirs_forbidden_to_stat
231
static char* dirs_forbidden_to_stat_buffer = NULL;
232
233
static void free_dirs_forbidden_to_stat() {
234
    mutex_lock_wrapper(&forbidden_dirs_mutex);
235
    if (dirs_forbidden_to_stat) {
236
        free(dirs_forbidden_to_stat);
237
    }
238
    if (dirs_forbidden_to_stat_buffer) {
239
        free(dirs_forbidden_to_stat_buffer);
240
    }
241
    mutex_unlock_wrapper(&forbidden_dirs_mutex);
242
}
243
244
static bool is_dir_forbidden_to_stat(const char* path2check) {
245
    bool forbidden = false;
246
    mutex_lock_wrapper(&forbidden_dirs_mutex);
247
    if (dirs_forbidden_to_stat) {
248
        for(const char** path = dirs_forbidden_to_stat; *path; path++) {
249
            if (strcmp(path2check, *path) == 0) {
250
                forbidden = true;
251
            }
252
        }
253
    }
254
    mutex_unlock_wrapper(&forbidden_dirs_mutex);
255
    return forbidden;
256
}
257
258
static void set_dirs_forbidden_to_stat(const char* dir_list) {
259
    mutex_lock_wrapper(&forbidden_dirs_mutex);
260
    dirs_forbidden_to_stat_buffer = strdup(dir_list);
261
    int cnt = 1;
262
    for(const char* p = dirs_forbidden_to_stat_buffer; *p; p++) {
263
        if (*p == ':') {
264
            cnt++;
265
        }
266
    }
267
    dirs_forbidden_to_stat = calloc(cnt+1, sizeof(char*)); // cnt+1 reserves space for trailing null
268
    const char** curr_path = dirs_forbidden_to_stat;
269
    *curr_path = dirs_forbidden_to_stat_buffer;
270
    for(char* p = dirs_forbidden_to_stat_buffer; *p; p++) {
271
        if (*p == ':') {
272
            *p = '\0';
273
            curr_path++;
274
            *curr_path = p+1;
275
        }
276
    }
277
    mutex_unlock_wrapper(&forbidden_dirs_mutex);
278
}
279
280
static void dump_dirs_forbidden_to_stat(TraceLevel level) {
281
    if (is_traceable(level)) {
282
        trace(level, "Directories forbidden to stat:\n");
283
        mutex_lock_wrapper(&forbidden_dirs_mutex);
284
        for(const char** path = dirs_forbidden_to_stat; *path; path++) {
285
            trace(level, "%s\n", *path);
286
        }
287
        mutex_unlock_wrapper(&forbidden_dirs_mutex);
288
    }
289
}
290
291
static void fill_dummy_stat(struct stat *stat_buf) {
292
    memset(stat_buf, '\0', sizeof(struct stat));
293
    stat_buf->st_uid = 0;
294
    stat_buf->st_mode = __S_IFDIR;
295
    stat_buf->st_size = 0;
296
    stat_buf->st_dev = 0;
297
    stat_buf->st_ino = 0;
298
}
299
300
static int lstat_wrapper(const char *path, struct stat *stat_buf) {
301
    if (is_dir_forbidden_to_stat(path)) {
302
        fill_dummy_stat(stat_buf);
303
        return 0;
304
    } else {
305
        return lstat(path, stat_buf);
306
    }
307
}
308
309
static int stat_wrapper(const char *path, struct stat *stat_buf) {
310
    if (is_dir_forbidden_to_stat(path)) {
311
        fill_dummy_stat(stat_buf);
312
        return 0;
313
    } else {
314
        return stat(path, stat_buf);
315
    }
316
}
317
224
#define DECLARE_DECODE(type, type_name, maxlen) \
318
#define DECLARE_DECODE(type, type_name, maxlen) \
225
static const char* decode_##type_name (const char* text, type* result) { \
319
static const char* decode_##type_name (const char* text, type* result) { \
226
    *result = 0; \
320
    *result = 0; \
Lines 711-717 Link Here
711
        const char *abspath, const char *basename,
805
        const char *abspath, const char *basename,
712
        buffer work_buf) {
806
        buffer work_buf) {
713
    struct stat stat_buf;
807
    struct stat stat_buf;
714
    if (lstat(abspath, &stat_buf) == 0) {
808
    if (lstat_wrapper(abspath, &stat_buf) == 0) {
715
809
716
        //int escaped_name_size = escape_strlen(entry->d_name);
810
        //int escaped_name_size = escape_strlen(entry->d_name);
717
        escape_strcpy(work_buf.data, basename);
811
        escape_strcpy(work_buf.data, basename);
Lines 882-888 Link Here
882
    }
976
    }
883
977
884
    struct stat stat_buf;
978
    struct stat stat_buf;
885
    if (lstat(path, &stat_buf) == 0) {
979
    if (lstat_wrapper(path, &stat_buf) == 0) {
886
        if (S_ISDIR(stat_buf.st_mode)) {
980
        if (S_ISDIR(stat_buf.st_mode)) {
887
            if (!clean_dir(path)) {
981
            if (!clean_dir(path)) {
888
                response_error(request_id, path, errno, "can't remote directory content");
982
                response_error(request_id, path, errno, "can't remote directory content");
Lines 942-948 Link Here
942
1036
943
static void response_stat(int request_id, const char* path) {
1037
static void response_stat(int request_id, const char* path) {
944
    struct stat stat_buf;
1038
    struct stat stat_buf;
945
    if (stat(path, &stat_buf) == 0) {
1039
    if (stat_wrapper(path, &stat_buf) == 0) {
946
        int buf_size = MAXNAMLEN * 2 + 80; // *2 because of escaping. TODO: accurate size calculation
1040
        int buf_size = MAXNAMLEN * 2 + 80; // *2 because of escaping. TODO: accurate size calculation
947
        char* escaped_name = malloc_wrapper(buf_size);
1041
        char* escaped_name = malloc_wrapper(buf_size);
948
        const char* basename = get_basename(path);
1042
        const char* basename = get_basename(path);
Lines 984-995 Link Here
984
1078
985
    // if file exists, return error
1079
    // if file exists, return error
986
    struct stat stat_buf;
1080
    struct stat stat_buf;
987
    if (lstat(request->path2, &stat_buf) == 0) {
1081
    if (lstat_wrapper(request->path2, &stat_buf) == 0) {
988
        response_error(request->id, request->path2, 0, "file already exists");
1082
        response_error(request->id, request->path2, 0, "file already exists");
989
        response_end(request->id, request->path2);
1083
        response_end(request->id, request->path2);
990
        return;
1084
        return;
991
    }
1085
    }
992
    if (lstat(request->path, &stat_buf) == -1) {
1086
    if (lstat_wrapper(request->path, &stat_buf) == -1) {
993
        response_error(request->id, request->path, errno, err_to_string(errno));
1087
        response_error(request->id, request->path, errno, err_to_string(errno));
994
        response_end(request->id, request->path2);
1088
        response_end(request->id, request->path2);
995
        return;
1089
        return;
Lines 1170-1176 Link Here
1170
    // check whether it is directory and print clear error message
1264
    // check whether it is directory and print clear error message
1171
    // (copy_plain_file will print unclear "Operation not permitted" in this case)
1265
    // (copy_plain_file will print unclear "Operation not permitted" in this case)
1172
    struct stat stat_buf;
1266
    struct stat stat_buf;
1173
    if (lstat(request->path, &stat_buf) == -1) {
1267
    if (lstat_wrapper(request->path, &stat_buf) == -1) {
1174
        response_error(request->id, request->path, errno, err_to_string(errno));
1268
        response_error(request->id, request->path, errno, err_to_string(errno));
1175
        return;
1269
        return;
1176
    }
1270
    }
Lines 1472-1477 Link Here
1472
        } else {
1566
        } else {
1473
            report_error("Unexpected option value: %s=%s\n", option, value);
1567
            report_error("Unexpected option value: %s=%s\n", option, value);
1474
        }
1568
        }
1569
    } else if (strcmp(option, "dirs-forbidden-to-stat") == 0) {
1570
        set_dirs_forbidden_to_stat(value);
1571
        dump_dirs_forbidden_to_stat(TRACE_FINER);
1475
    } else {
1572
    } else {
1476
        report_error("Unexpected option key: %s\n", option);
1573
        report_error("Unexpected option key: %s\n", option);
1477
    }
1574
    }
Lines 1983-1988 Link Here
1983
    dirtab_free();
2080
    dirtab_free();
1984
    log_close();
2081
    log_close();
1985
    err_shutdown();
2082
    err_shutdown();
2083
    free_dirs_forbidden_to_stat();
1986
    trace(TRACE_INFO, "Shut down.\n");
2084
    trace(TRACE_INFO, "Shut down.\n");
1987
    exit(0);
2085
    exit(0);
1988
}
2086
}
(-)a/dlight.remote.impl/tools/fs_server/src/util.c (-3 / +7 lines)
Lines 477-485 Link Here
477
        int buf_size = PATH_MAX;
477
        int buf_size = PATH_MAX;
478
        char *abspath = malloc_wrapper(buf_size);
478
        char *abspath = malloc_wrapper(buf_size);
479
        char *link = malloc_wrapper(buf_size);
479
        char *link = malloc_wrapper(buf_size);
480
        // TODO: error processing (malloc() can return null)
480
        int base_len;
481
        int base_len = strlen(path);
481
        if (path[0] == '/' && path[1] == '\0') {
482
        strcpy(abspath, path);
482
            base_len = 0;
483
        } else {
484
            base_len = strlen(path);
485
            strcpy(abspath, path);
486
        }
483
        abspath[base_len] = '/';
487
        abspath[base_len] = '/';
484
        struct dirent *entry;
488
        struct dirent *entry;
485
        while (true) {
489
        while (true) {

Return to bug 267715