@@ -3230,3 +3230,92 @@ TEST_IMPL(fs_exclusive_sharing_mode) {
32303230 return 0 ;
32313231}
32323232#endif
3233+
3234+ #ifdef _WIN32
3235+ int call_icacls (const char * command , ...) {
3236+ uv_process_t handle ;
3237+ uv_process_options_t options ;
3238+ char icacls_command [1024 ];
3239+ char * icacls_args [3 ];
3240+ va_list args ;
3241+
3242+ va_start (args , command );
3243+ vsnprintf (icacls_command , ARRAYSIZE (icacls_command ), command , args );
3244+ va_end (args );
3245+ return system (icacls_command );
3246+ }
3247+
3248+ TEST_IMPL (fs_open_readonly_acl ) {
3249+ uv_passwd_t pwd ;
3250+ uv_fs_t req ;
3251+ int r ;
3252+
3253+ /*
3254+ Based on Node.js test from
3255+ https://github.com/nodejs/node/commit/3ba81e34e86a5c32658e218cb6e65b13e8326bc5
3256+
3257+ If anything goes wrong, you can delte the test_fle_icacls with:
3258+
3259+ icacls test_file_icacls /remove "%USERNAME%" /inheritance:e
3260+ attrib -r test_file_icacls
3261+ del test_file_icacls
3262+ */
3263+
3264+ /* Setup - clear the ACL and remove the file */
3265+ loop = uv_default_loop ();
3266+ r = uv_os_get_passwd (& pwd );
3267+ ASSERT (r == 0 );
3268+ call_icacls ("icacls test_file_icacls /remove \"%s\" /inheritance:e" ,
3269+ pwd .username );
3270+ uv_fs_chmod (loop , & req , "test_file_icacls" , S_IWUSR , NULL );
3271+ unlink ("test_file_icacls" );
3272+
3273+ /* Create the file */
3274+ r = uv_fs_open (loop ,
3275+ & open_req1 ,
3276+ "test_file_icacls" ,
3277+ O_RDONLY | O_CREAT ,
3278+ S_IRUSR ,
3279+ NULL );
3280+ ASSERT (r >= 0 );
3281+ ASSERT (open_req1 .result >= 0 );
3282+ uv_fs_req_cleanup (& open_req1 );
3283+ r = uv_fs_close (NULL , & close_req , open_req1 .result , NULL );
3284+ ASSERT (r == 0 );
3285+ ASSERT (close_req .result == 0 );
3286+ uv_fs_req_cleanup (& close_req );
3287+
3288+ /* Set up ACL */
3289+ r = call_icacls ("icacls test_file_icacls /inheritance:r /remove \"%s\"" ,
3290+ pwd .username );
3291+ if (r != 0 ) {
3292+ goto acl_cleanup ;
3293+ }
3294+ r = call_icacls ("icacls test_file_icacls /grant \"%s\":RX" , pwd .username );
3295+ if (r != 0 ) {
3296+ goto acl_cleanup ;
3297+ }
3298+
3299+ /* Try opening the file */
3300+ r = uv_fs_open (NULL , & open_req1 , "test_file_icacls" , O_RDONLY , 0 , NULL );
3301+ if (r < 0 ) {
3302+ goto acl_cleanup ;
3303+ }
3304+ uv_fs_req_cleanup (& open_req1 );
3305+ r = uv_fs_close (NULL , & close_req , open_req1 .result , NULL );
3306+ if (r != 0 ) {
3307+ goto acl_cleanup ;
3308+ }
3309+ uv_fs_req_cleanup (& close_req );
3310+
3311+ acl_cleanup :
3312+ /* Cleanup */
3313+ call_icacls ("icacls test_file_icacls /remove \"%s\" /inheritance:e" ,
3314+ pwd .username );
3315+ unlink ("test_file_icacls" );
3316+ uv_os_free_passwd (& pwd );
3317+ ASSERT (r == 0 );
3318+ MAKE_VALGRIND_HAPPY ();
3319+ return 0 ;
3320+ }
3321+ #endif
0 commit comments