75
75
/* Here is another Windoze bug?:
76
76
* you cant rename("pubring.kbx.tmp", "pubring.kbx");
77
77
* but rename("pubring.kbx.tmp", "pubring.aaa");
78
* works. So we replace .kbx by .bak or .tmp
78
* works. So we replace ".kbx" by ".kb_" or ".k__". Note that we
79
* can't use ".bak" and ".tmp", because these suffixes are used by
80
* gpg and would lead to a sharing violation or data corruption.
80
82
if (strlen (template) > 4
81
83
&& !strcmp (template+strlen(template)-4, EXTSEP_S "kbx") )
83
85
bakfname = xtrymalloc (strlen (template) + 1);
85
return gpg_error (gpg_err_code_from_errno (errno));
87
return gpg_error_from_syserror ();
86
88
strcpy (bakfname, template);
87
strcpy (bakfname+strlen(template)-4, EXTSEP_S "bak");
89
strcpy (bakfname+strlen(template)-4, EXTSEP_S "kb_");
89
91
tmpfname = xtrymalloc (strlen (template) + 1);
92
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
94
gpg_error_t tmperr = gpg_error_from_syserror ();
96
98
strcpy (tmpfname,template);
97
strcpy (tmpfname + strlen (template)-4, EXTSEP_S "tmp");
99
strcpy (tmpfname + strlen (template)-4, EXTSEP_S "k__");
100
{ /* File does not end with kbx; hmmm. */
102
{ /* File does not end with kbx, thus we hope we are working on a
103
modern file system and appending a suffix works. */
101
104
bakfname = xtrymalloc ( strlen (template) + 5);
103
return gpg_error (gpg_err_code_from_errno (errno));
104
strcpy (stpcpy (bakfname, template), EXTSEP_S "bak");
106
return gpg_error_from_syserror ();
107
strcpy (stpcpy (bakfname, template), EXTSEP_S "kb_");
106
109
tmpfname = xtrymalloc ( strlen (template) + 5);
109
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
112
gpg_error_t tmperr = gpg_error_from_syserror ();
110
113
xfree (bakfname);
113
strcpy (stpcpy (tmpfname, template), EXTSEP_S "tmp");
116
strcpy (stpcpy (tmpfname, template), EXTSEP_S "k__");
115
118
# else /* Posix file names */
116
119
bakfname = xtrymalloc (strlen (template) + 2);
118
return gpg_error (gpg_err_code_from_errno (errno));
121
return gpg_error_from_syserror ();
119
122
strcpy (stpcpy (bakfname,template),"~");
121
124
tmpfname = xtrymalloc ( strlen (template) + 5);
124
gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
127
gpg_error_t tmperr = gpg_error_from_syserror ();
125
128
xfree (bakfname);
167
170
/* iobuf_ioctl (NULL, 2, 0, (char*)bakfname ); */
168
171
/* iobuf_ioctl (NULL, 2, 0, (char*)fname ); */
170
/* first make a backup file except for secret keyboxs */
173
/* First make a backup file except for secret keyboxes. */
173
176
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
176
179
if (rename (fname, bakfname) )
178
return gpg_error (gpg_err_code_from_errno (errno));
181
return gpg_error_from_syserror ();
182
/* then rename the file */
185
/* Then rename the file. */
183
186
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
186
189
if (rename (tmpfname, fname) )
188
rc = gpg_error (gpg_err_code_from_errno (errno));
191
rc = gpg_error_from_syserror ();
191
194
/* log_info ("WARNING: 2 files with confidential" */
221
224
/* Open the source file. Because we do a rename, we have to check the
222
225
permissions of the file */
223
226
if (access (fname, W_OK))
224
return gpg_error (gpg_err_code_from_errno (errno));
227
return gpg_error_from_syserror ();
226
229
fp = fopen (fname, "rb");
227
230
if (mode == 1 && !fp && errno == ENOENT)
387
390
/* Close this one otherwise we will mess up the position for a next
388
391
search. Fixme: it would be better to adjust the position after
389
the write opertions. */
392
the write operation. */
393
_keybox_close_file (hd);
396
395
rc = _keybox_create_x509_blob (&blob, cert, sha1_digest, hd->ephemeral);
399
rc = blob_filecopy (1, fname, blob, hd->secret, 0, 0 );
398
rc = blob_filecopy (1, fname, blob, hd->secret, 0);
400
399
_keybox_release_blob (blob);
401
400
/* if (!rc && !hd->secret && kb_offtbl) */
460
_keybox_close_file (hd);
461
461
fp = fopen (hd->kb->fname, "r+b");
463
return gpg_error (gpg_err_code_from_errno (errno));
463
return gpg_error_from_syserror ();
466
466
if (fseeko (fp, off, SEEK_SET))
467
ec = gpg_error (gpg_err_code_from_errno (errno));
467
ec = gpg_error_from_syserror ();
470
470
unsigned char tmp[4];
522
522
return gpg_error (GPG_ERR_GENERAL);
525
_keybox_close_file (hd);
531
526
fp = fopen (hd->kb->fname, "r+b");
533
return gpg_error (gpg_err_code_from_errno (errno));
528
return gpg_error_from_syserror ();
535
530
if (fseeko (fp, off, SEEK_SET))
536
rc = gpg_error (gpg_err_code_from_errno (errno));
531
rc = gpg_error_from_syserror ();
537
532
else if (putc (0, fp) == EOF)
538
rc = gpg_error (gpg_err_code_from_errno (errno));
533
rc = gpg_error_from_syserror ();
545
rc = gpg_error (gpg_err_code_from_errno (errno));
540
rc = gpg_error_from_syserror ();
576
571
return gpg_error (GPG_ERR_INV_HANDLE);
573
_keybox_close_file (hd);
584
575
/* Open the source file. Because we do a rename, we have to check the
585
576
permissions of the file */
586
577
if (access (fname, W_OK))
587
return gpg_error (gpg_err_code_from_errno (errno));
578
return gpg_error_from_syserror ();
589
580
fp = fopen (fname, "rb");
590
581
if (!fp && errno == ENOENT)
591
582
return 0; /* Ready. File has been deleted right after the access above. */
594
rc = gpg_error (gpg_err_code_from_errno (errno));
585
rc = gpg_error_from_syserror ();