More fix of sftp scp file permission and test cases (#222)

More fix of sftp scp file permission and test cases
This commit is contained in:
bagajjal 2017-10-16 14:46:37 -07:00 committed by Yanbing
parent c9c715e707
commit 97959981f6
2 changed files with 39 additions and 14 deletions

View File

@ -1321,13 +1321,13 @@ get_final_mode(int allow_mode, int deny_mode)
if (!allow_mode) return allow_mode;
if(deny_mode & S_IROTH)
allow_mode = (allow_mode | S_IROTH) ^ S_IROTH;
allow_mode = allow_mode & ~S_IROTH;
if (deny_mode & S_IWOTH)
allow_mode = (allow_mode | S_IWOTH) ^ S_IWOTH;
allow_mode = allow_mode & ~S_IWOTH;
if (deny_mode & S_IXOTH)
allow_mode = (allow_mode | S_IXOTH) ^ S_IXOTH;
allow_mode = allow_mode & ~S_IXOTH;
return allow_mode;
}
@ -1368,18 +1368,20 @@ get_others_file_permissions(wchar_t * file_name, int isReadOnlyFile)
current_aceHeader = (PACE_HEADER)current_ace;
/* only interested in Allow ACE */
if (!(current_aceHeader->AceType == ACCESS_ALLOWED_ACE_TYPE ||
current_aceHeader->AceType == ACCESS_DENIED_ACE_TYPE))
continue;
PACCESS_ALLOWED_ACE pAllowedAce = (PACCESS_ALLOWED_ACE)current_ace;
current_trustee_sid = &(pAllowedAce->SidStart);
if (current_aceHeader->AceType == ACCESS_ALLOWED_ACE_TYPE) {
PACCESS_ALLOWED_ACE pAllowedAce = (PACCESS_ALLOWED_ACE)current_ace;
current_trustee_sid = &(pAllowedAce->SidStart);
current_access_mask = pAllowedAce->Mask;
} else if (current_aceHeader->AceType == ACCESS_DENIED_ACE_TYPE) {
PACCESS_DENIED_ACE pDeniedAce = (PACCESS_DENIED_ACE)current_ace;
current_trustee_sid = &(pDeniedAce->SidStart);
current_access_mask = pDeniedAce->Mask;
} else continue;
if (!(IsWellKnownSid(current_trustee_sid, WinWorldSid) ||
IsWellKnownSid(current_trustee_sid, WinAuthenticatedUserSid)))
continue;
current_access_mask = pAllowedAce->Mask;
if ((current_access_mask & READ_PERMISSIONS) == READ_PERMISSIONS)
mode_tmp |= S_IROTH;
@ -1399,7 +1401,7 @@ get_others_file_permissions(wchar_t * file_name, int isReadOnlyFile)
allow_mode_auth_users |= mode_tmp;
else
deny_mode_auth_users |= mode_tmp;
}
}
}
allow_mode_world = get_final_mode(allow_mode_world, deny_mode_world);

View File

@ -123,7 +123,7 @@ void file_simple_fileio()
retValue = stat(tmp_filename, &st);
ASSERT_INT_EQ(retValue, 0);
ASSERT_INT_EQ(st.st_size, strlen(small_write_buf));
ASSERT_INT_EQ(st.st_mode & 0777, 0666);
ASSERT_INT_EQ(st.st_mode & 0777, 0600);
char mode[12];
strmode(st.st_mode, mode);
ASSERT_CHAR_EQ(mode[0], '-');
@ -463,6 +463,29 @@ file_miscellaneous_tests()
retValue = w32_allocate_fd_for_handle(h, FALSE);
ASSERT_HANDLE(h);
f = open(tmp_filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
ASSERT_INT_NE(f, -1);
wchar_t *t = utf8_to_utf16(tmp_filename);
ASSERT_PTR_NE(t, NULL);
int perm = get_others_file_permissions(t, 0);
ASSERT_INT_EQ(perm, 7);
free(t);
close(f);
retValue = unlink(tmp_filename);
ASSERT_INT_EQ(retValue, 0);
f = open(tmp_filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
ASSERT_INT_NE(f, -1);
t = utf8_to_utf16(tmp_filename);
ASSERT_PTR_NE(t, NULL);
perm = get_others_file_permissions(t, 1);
ASSERT_INT_EQ(perm, 5);
free(t);
close(f);
retValue = unlink(tmp_filename);
ASSERT_INT_EQ(retValue, 0);
TEST_DONE();
}