diff options
| author | Eli Zaretskii | 2013-11-23 13:55:22 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2013-11-23 13:55:22 +0200 |
| commit | 66124e6165642bc44a4742d5a878badd0a2c9353 (patch) | |
| tree | 8a61178335b4fee99bb41e79c53d6d4de550e7f0 /src | |
| parent | eeccd06f852001648e0307ce07f2687029b18889 (diff) | |
| download | emacs-66124e6165642bc44a4742d5a878badd0a2c9353.tar.gz emacs-66124e6165642bc44a4742d5a878badd0a2c9353.zip | |
File ACL functions converted and tested.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 83 |
1 files changed, 63 insertions, 20 deletions
| @@ -299,7 +299,8 @@ static BOOL g_b_init_get_security_descriptor_dacl; | |||
| 299 | static BOOL g_b_init_convert_sd_to_sddl; | 299 | static BOOL g_b_init_convert_sd_to_sddl; |
| 300 | static BOOL g_b_init_convert_sddl_to_sd; | 300 | static BOOL g_b_init_convert_sddl_to_sd; |
| 301 | static BOOL g_b_init_is_valid_security_descriptor; | 301 | static BOOL g_b_init_is_valid_security_descriptor; |
| 302 | static BOOL g_b_init_set_file_security; | 302 | static BOOL g_b_init_set_file_security_w; |
| 303 | static BOOL g_b_init_set_file_security_a; | ||
| 303 | static BOOL g_b_init_get_adapters_info; | 304 | static BOOL g_b_init_get_adapters_info; |
| 304 | 305 | ||
| 305 | /* | 306 | /* |
| @@ -366,8 +367,12 @@ typedef BOOL (WINAPI * GetFileSecurityA_Proc) ( | |||
| 366 | PSECURITY_DESCRIPTOR pSecurityDescriptor, | 367 | PSECURITY_DESCRIPTOR pSecurityDescriptor, |
| 367 | DWORD nLength, | 368 | DWORD nLength, |
| 368 | LPDWORD lpnLengthNeeded); | 369 | LPDWORD lpnLengthNeeded); |
| 369 | typedef BOOL (WINAPI *SetFileSecurity_Proc) ( | 370 | typedef BOOL (WINAPI *SetFileSecurityW_Proc) ( |
| 370 | LPCTSTR lpFileName, | 371 | LPCWSTR lpFileName, |
| 372 | SECURITY_INFORMATION SecurityInformation, | ||
| 373 | PSECURITY_DESCRIPTOR pSecurityDescriptor); | ||
| 374 | typedef BOOL (WINAPI *SetFileSecurityA_Proc) ( | ||
| 375 | LPCSTR lpFileName, | ||
| 371 | SECURITY_INFORMATION SecurityInformation, | 376 | SECURITY_INFORMATION SecurityInformation, |
| 372 | PSECURITY_DESCRIPTOR pSecurityDescriptor); | 377 | PSECURITY_DESCRIPTOR pSecurityDescriptor); |
| 373 | typedef BOOL (WINAPI * GetSecurityDescriptorOwner_Proc) ( | 378 | typedef BOOL (WINAPI * GetSecurityDescriptorOwner_Proc) ( |
| @@ -751,32 +756,60 @@ get_file_security (const char *lpFileName, | |||
| 751 | } | 756 | } |
| 752 | 757 | ||
| 753 | static BOOL WINAPI | 758 | static BOOL WINAPI |
| 754 | set_file_security (LPCTSTR lpFileName, | 759 | set_file_security (const char *lpFileName, |
| 755 | SECURITY_INFORMATION SecurityInformation, | 760 | SECURITY_INFORMATION SecurityInformation, |
| 756 | PSECURITY_DESCRIPTOR pSecurityDescriptor) | 761 | PSECURITY_DESCRIPTOR pSecurityDescriptor) |
| 757 | { | 762 | { |
| 758 | static SetFileSecurity_Proc s_pfn_Set_File_Security = NULL; | 763 | static SetFileSecurityW_Proc s_pfn_Set_File_SecurityW = NULL; |
| 764 | static SetFileSecurityA_Proc s_pfn_Set_File_SecurityA = NULL; | ||
| 759 | HMODULE hm_advapi32 = NULL; | 765 | HMODULE hm_advapi32 = NULL; |
| 760 | if (is_windows_9x () == TRUE) | 766 | if (is_windows_9x () == TRUE) |
| 761 | { | 767 | { |
| 762 | errno = ENOTSUP; | 768 | errno = ENOTSUP; |
| 763 | return FALSE; | 769 | return FALSE; |
| 764 | } | 770 | } |
| 765 | if (g_b_init_set_file_security == 0) | 771 | if (w32_unicode_filenames) |
| 766 | { | 772 | { |
| 767 | g_b_init_set_file_security = 1; | 773 | wchar_t filename_w[MAX_PATH]; |
| 768 | hm_advapi32 = LoadLibrary ("Advapi32.dll"); | 774 | |
| 769 | s_pfn_Set_File_Security = | 775 | if (g_b_init_set_file_security_w == 0) |
| 770 | (SetFileSecurity_Proc) GetProcAddress ( | 776 | { |
| 771 | hm_advapi32, "SetFileSecurityA"); | 777 | g_b_init_set_file_security_w = 1; |
| 778 | hm_advapi32 = LoadLibrary ("Advapi32.dll"); | ||
| 779 | s_pfn_Set_File_SecurityW = | ||
| 780 | (SetFileSecurityW_Proc) GetProcAddress (hm_advapi32, | ||
| 781 | "SetFileSecurityW"); | ||
| 782 | } | ||
| 783 | if (s_pfn_Set_File_SecurityW == NULL) | ||
| 784 | { | ||
| 785 | errno = ENOTSUP; | ||
| 786 | return FALSE; | ||
| 787 | } | ||
| 788 | filename_to_utf16 (lpFileName, filename_w); | ||
| 789 | return (s_pfn_Set_File_SecurityW (filename_w, SecurityInformation, | ||
| 790 | pSecurityDescriptor)); | ||
| 772 | } | 791 | } |
| 773 | if (s_pfn_Set_File_Security == NULL) | 792 | else |
| 774 | { | 793 | { |
| 775 | errno = ENOTSUP; | 794 | char filename_a[MAX_PATH]; |
| 776 | return FALSE; | 795 | |
| 796 | if (g_b_init_set_file_security_a == 0) | ||
| 797 | { | ||
| 798 | g_b_init_set_file_security_a = 1; | ||
| 799 | hm_advapi32 = LoadLibrary ("Advapi32.dll"); | ||
| 800 | s_pfn_Set_File_SecurityA = | ||
| 801 | (SetFileSecurityA_Proc) GetProcAddress (hm_advapi32, | ||
| 802 | "SetFileSecurityA"); | ||
| 803 | } | ||
| 804 | if (s_pfn_Set_File_SecurityA == NULL) | ||
| 805 | { | ||
| 806 | errno = ENOTSUP; | ||
| 807 | return FALSE; | ||
| 808 | } | ||
| 809 | filename_to_ansi (lpFileName, filename_a); | ||
| 810 | return (s_pfn_Set_File_SecurityA (filename_a, SecurityInformation, | ||
| 811 | pSecurityDescriptor)); | ||
| 777 | } | 812 | } |
| 778 | return (s_pfn_Set_File_Security (lpFileName, SecurityInformation, | ||
| 779 | pSecurityDescriptor)); | ||
| 780 | } | 813 | } |
| 781 | 814 | ||
| 782 | static BOOL WINAPI | 815 | static BOOL WINAPI |
| @@ -5643,7 +5676,11 @@ acl_get_file (const char *fname, acl_type_t type) | |||
| 5643 | } | 5676 | } |
| 5644 | } | 5677 | } |
| 5645 | else if (err == ERROR_FILE_NOT_FOUND | 5678 | else if (err == ERROR_FILE_NOT_FOUND |
| 5646 | || err == ERROR_PATH_NOT_FOUND) | 5679 | || err == ERROR_PATH_NOT_FOUND |
| 5680 | /* ERROR_INVALID_NAME is what we get if | ||
| 5681 | w32-unicode-filenames is nil and the file cannot | ||
| 5682 | be encoded in the current ANSI codepage. */ | ||
| 5683 | || err == ERROR_INVALID_NAME) | ||
| 5647 | errno = ENOENT; | 5684 | errno = ENOENT; |
| 5648 | else | 5685 | else |
| 5649 | errno = EIO; | 5686 | errno = EIO; |
| @@ -5721,7 +5758,7 @@ acl_set_file (const char *fname, acl_type_t type, acl_t acl) | |||
| 5721 | 5758 | ||
| 5722 | e = errno; | 5759 | e = errno; |
| 5723 | errno = 0; | 5760 | errno = 0; |
| 5724 | if (!set_file_security ((char *)fname, flags, (PSECURITY_DESCRIPTOR)acl)) | 5761 | if (!set_file_security (fname, flags, (PSECURITY_DESCRIPTOR)acl)) |
| 5725 | { | 5762 | { |
| 5726 | err = GetLastError (); | 5763 | err = GetLastError (); |
| 5727 | 5764 | ||
| @@ -5754,7 +5791,12 @@ acl_set_file (const char *fname, acl_type_t type, acl_t acl) | |||
| 5754 | acl_free (current_acl); | 5791 | acl_free (current_acl); |
| 5755 | } | 5792 | } |
| 5756 | } | 5793 | } |
| 5757 | else if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) | 5794 | else if (err == ERROR_FILE_NOT_FOUND |
| 5795 | || err == ERROR_PATH_NOT_FOUND | ||
| 5796 | /* ERROR_INVALID_NAME is what we get if | ||
| 5797 | w32-unicode-filenames is nil and the file cannot be | ||
| 5798 | encoded in the current ANSI codepage. */ | ||
| 5799 | || err == ERROR_INVALID_NAME) | ||
| 5758 | errno = ENOENT; | 5800 | errno = ENOENT; |
| 5759 | else | 5801 | else |
| 5760 | errno = EACCES; | 5802 | errno = EACCES; |
| @@ -8501,7 +8543,8 @@ globals_of_w32 (void) | |||
| 8501 | g_b_init_convert_sd_to_sddl = 0; | 8543 | g_b_init_convert_sd_to_sddl = 0; |
| 8502 | g_b_init_convert_sddl_to_sd = 0; | 8544 | g_b_init_convert_sddl_to_sd = 0; |
| 8503 | g_b_init_is_valid_security_descriptor = 0; | 8545 | g_b_init_is_valid_security_descriptor = 0; |
| 8504 | g_b_init_set_file_security = 0; | 8546 | g_b_init_set_file_security_w = 0; |
| 8547 | g_b_init_set_file_security_a = 0; | ||
| 8505 | g_b_init_get_adapters_info = 0; | 8548 | g_b_init_get_adapters_info = 0; |
| 8506 | num_of_processors = 0; | 8549 | num_of_processors = 0; |
| 8507 | /* The following sets a handler for shutdown notifications for | 8550 | /* The following sets a handler for shutdown notifications for |