version 1.4, 2005/05/29 08:54:13 |
version 1.5, 2005/05/29 09:10:23 |
|
|
sign(int argc, char *argv[]) |
sign(int argc, char *argv[]) |
{ |
{ |
struct key *key; |
struct key *key; |
char *gzipfile, tmpfile[MAXPATHLEN]; |
char *gzipfile, tmppath[MAXPATHLEN]; |
FILE *fin, *fout; |
FILE *fin, *fout; |
int i, fd, error, qflag; |
int i, fd, error, qflag; |
|
|
|
|
gzipfile, strerror(errno)); |
gzipfile, strerror(errno)); |
continue; |
continue; |
} |
} |
snprintf(tmpfile, sizeof(tmpfile), "%s.XXXXXX", gzipfile); |
snprintf(tmppath, sizeof(tmppath), "%s.XXXXXX", gzipfile); |
|
|
if ((fd = mkstemp(tmpfile)) < 0) { |
if ((fd = mkstemp(tmppath)) < 0) { |
fprintf(stderr, "Error creating %s: %s\n", |
fprintf(stderr, "Error creating %s: %s\n", |
tmpfile, strerror(errno)); |
tmppath, strerror(errno)); |
fclose(fin); |
fclose(fin); |
continue; |
continue; |
} |
} |
if ((fout = fdopen(fd, "w")) == NULL) { |
if ((fout = fdopen(fd, "w")) == NULL) { |
fprintf(stderr, "Error opening %s: %s\n", |
fprintf(stderr, "Error opening %s: %s\n", |
tmpfile, strerror(errno)); |
tmppath, strerror(errno)); |
fclose(fin); |
fclose(fin); |
close(fd); |
close(fd); |
continue; |
continue; |
} |
} |
if (copy_permissions(gzipfile, tmpfile) < 0) { |
if (copy_permissions(gzipfile, tmppath) < 0) { |
fprintf(stderr, "Error initializing %s: %s\n", |
fprintf(stderr, "Error initializing %s: %s\n", |
tmpfile, strerror(errno)); |
tmppath, strerror(errno)); |
fclose(fin); |
fclose(fin); |
fclose(fout); |
fclose(fout); |
continue; |
continue; |
|
|
fclose(fout); |
fclose(fout); |
|
|
if (!error) { |
if (!error) { |
if (rename(tmpfile, gzipfile) < 0) { |
if (rename(tmppath, gzipfile) < 0) { |
unlink(tmpfile); |
unlink(tmppath); |
fatal(1, "Couldn't sign %s", gzipfile); |
fatal(1, "Couldn't sign %s", gzipfile); |
} |
} |
if (!qflag) |
if (!qflag) |
fprintf(stderr, "Signed %s\n", gzipfile); |
fprintf(stderr, "Signed %s\n", gzipfile); |
} else { |
} else { |
unlink(tmpfile); |
unlink(tmppath); |
fatal(1, "Couldn't sign %s", gzipfile); |
fatal(1, "Couldn't sign %s", gzipfile); |
} |
} |
} |
} |