808 |
} |
} |
809 |
|
|
810 |
|
|
811 |
|
/* Check if the device where file @fname is stored on, is write-protected. */ |
|
/* Check if the device file @fname is stored on, is write-protected. */ |
|
812 |
static int |
static int |
813 |
my_access (const char *fname) |
check_file_access (const char *fname, int mode) |
814 |
{ |
{ |
815 |
HANDLE hd; |
HANDLE hd; |
816 |
|
|
817 |
hd = CreateFile (fname, GENERIC_WRITE, FILE_SHARE_WRITE, |
if (!mode) |
818 |
|
mode = FILE_SHARE_WRITE; |
819 |
|
hd = CreateFile (fname, GENERIC_WRITE, mode, |
820 |
NULL, OPEN_EXISTING, 0, NULL); |
NULL, OPEN_EXISTING, 0, NULL); |
821 |
if (hd == INVALID_HANDLE_VALUE) |
if (hd == INVALID_HANDLE_VALUE) |
822 |
return -1; |
return -1; |
824 |
return 0; |
return 0; |
825 |
} |
} |
826 |
|
|
827 |
|
|
828 |
|
/* Check the device where the file @fname is stored on, is either |
829 |
|
write-protected or if the file is already opened by another process |
830 |
|
exclusively. And as a result, we cannot use the file for output. */ |
831 |
|
int |
832 |
|
gpg_check_file_permissions (const char *fname, int mode) |
833 |
|
{ |
834 |
|
int api_mode; |
835 |
|
|
836 |
|
switch (mode) { |
837 |
|
case 0: api_mode = FILE_SHARE_READ; break; |
838 |
|
case 1: api_mode = FILE_SHARE_WRITE; break; |
839 |
|
case 2: api_mode = FILE_SHARE_WRITE|FILE_SHARE_READ; break; |
840 |
|
} |
841 |
|
|
842 |
|
return check_file_access (fname, api_mode); |
843 |
|
} |
844 |
|
|
845 |
|
|
846 |
/* Check the file permissions of the public keyring. |
/* Check the file permissions of the public keyring. |
847 |
If @showmsg is 1 output a message in case of errors. |
If @showmsg is 1 output a message in case of errors. |
876 |
failed = 1; |
failed = 1; |
877 |
} |
} |
878 |
} |
} |
879 |
if (my_access (name)) { |
if (gpg_check_file_permissions (name, 1)) { |
880 |
if (showmsg) |
if (showmsg) |
881 |
msg_box (NULL, |
msg_box (NULL, |
882 |
_("You do not have file access to modify the contents of\n" |
_("You do not have file access to modify the contents of\n" |