| ︙ | | | ︙ | |
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
int dact_shutdown(int retval);
char *dact_getoutfilename(const char *orig, const int mode);
uint32_t dact_process_other(int src, const int dest, const uint32_t magic, const char *options);
int main(int argc, char **argv);
extern char *optarg;
extern int optind, opterr, optopt;
uint32_t DACT_BLK_SIZE=0;
char dact_nonetwork=0;
int print_help(int argc, char **argv) {
printf("DACT %i.%i.%i-%s by Keene Enterprises <dact@rkeene.org>\n", DACT_VER_MAJOR, DACT_VER_MINOR, DACT_VER_REVISION, DACT_VER_SUB);
printf("usage: %s [options...] [file ...]\n",argv[0]);
printf("Options:\n");
printf(" -d Decompress instead of compressing.\n");
|
<
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
int dact_shutdown(int retval);
char *dact_getoutfilename(const char *orig, const int mode);
uint32_t dact_process_other(int src, const int dest, const uint32_t magic, const char *options);
int main(int argc, char **argv);
extern char *optarg;
extern int optind, opterr, optopt;
char dact_nonetwork=0;
int print_help(int argc, char **argv) {
printf("DACT %i.%i.%i-%s by Keene Enterprises <dact@rkeene.org>\n", DACT_VER_MAJOR, DACT_VER_MINOR, DACT_VER_REVISION, DACT_VER_SUB);
printf("usage: %s [options...] [file ...]\n",argv[0]);
printf("Options:\n");
printf(" -d Decompress instead of compressing.\n");
|
| ︙ | | | ︙ | |
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
if (toupper(buf[0])!='Y') {
PRINTERR("Failed to upgrade DACT.");
free(buf);
return(-1);
}
free(buf);
#ifdef WIN32
#error "Windows has no fork(), CreateProcess() instead"
#endif
if (fork()==0) {
execl("/usr/bin/apt-get","apt-get","update",NULL);
return(-1); /* Couldn't run binary. */
} else {
i=wait(&status);
if (WIFEXITED(status)) {
if (WEXITSTATUS(status)) {
|
<
<
<
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
if (toupper(buf[0])!='Y') {
PRINTERR("Failed to upgrade DACT.");
free(buf);
return(-1);
}
free(buf);
if (fork()==0) {
execl("/usr/bin/apt-get","apt-get","update",NULL);
return(-1); /* Couldn't run binary. */
} else {
i=wait(&status);
if (WIFEXITED(status)) {
if (WEXITSTATUS(status)) {
|
| ︙ | | | ︙ | |
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
PERROR_L(outFd, "open_net");
return(-1);
}
if ((inFd=open_net(urlsubst, O_RDONLY, 0))<0) {
PERROR_L(inFd, "open_net");
return(-1);
}
if (!dact_process_file(inFd, outFd, DACT_MODE_DECMP, options, "dact", crcs,-1)) {
close(inFd);
close(outFd);
unlink(dact_binfile);
PRINTERR("Failed to upgrade DACT.");
return(-1);
}
close(inFd);
|
|
|
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
PERROR_L(outFd, "open_net");
return(-1);
}
if ((inFd=open_net(urlsubst, O_RDONLY, 0))<0) {
PERROR_L(inFd, "open_net");
return(-1);
}
if (!dact_process_file(inFd, outFd, DACT_MODE_DECMP, options, "dact", crcs, DACT_BLK_SIZE_DEF, -1)) {
close(inFd);
close(outFd);
unlink(dact_binfile);
PRINTERR("Failed to upgrade DACT.");
return(-1);
}
close(inFd);
|
| ︙ | | | ︙ | |
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
* -- Roy Keene <dact@rkeene.org>
*/
if (lseek_net(src, 0, SEEK_SET)<0) {
PRINTERR("This should not be happening.");
/*
* lseek_net() should make this obsolete.
* ... EXCEPT! when reading from stdin.
*
*/
tmpfd=mkstemp(tmpbuf);
write_de(tmpfd, magic, 4);
buf=malloc(1024);
while (1) {
x=read_f(src, buf, 1024);
write(tmpfd, buf, x);
|
<
|
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
* -- Roy Keene <dact@rkeene.org>
*/
if (lseek_net(src, 0, SEEK_SET)<0) {
PRINTERR("This should not be happening.");
/*
* lseek_net() should make this obsolete.
* ... EXCEPT! when reading from stdin.
*/
tmpfd=mkstemp(tmpbuf);
write_de(tmpfd, magic, 4);
buf=malloc(1024);
while (1) {
x=read_f(src, buf, 1024);
write(tmpfd, buf, x);
|
| ︙ | | | ︙ | |
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
signed char opt;
struct stat stat_buf;
char **in_files, *in_file=NULL, *out_file=NULL;
char dact_binfilebuf[256], *dact_binfile;
int filecnt=0;
int in_fd, out_fd;
int mode=DACT_MODE_COMPR, ciphernum=-1;
uint32_t crcs[6]={0,0,0,0,0,0};
uint32_t i,x;
dact_ui_init();
/* hack, to make upgrade work even if DACT_OPT_BINCHK is enabled, we must
* get the new version before executing it.
*/
if (argv[1]!=NULL) {
if (!strcmp(argv[1],"-N")) return(dact_upgrade(options));
if (!strcmp(argv[1],"-a")) options[DACT_OPT_UPGRADE]=1;
}
dact_config_loadfile(DACT_CONFIG_FILE, options);
#if !defined(GO32) && !defined(__WIN32__)
dact_binfilebuf[0]='\0';
if (getenv("HOME")) {
strncpy(dact_binfilebuf,getenv("HOME"),sizeof(dact_binfilebuf)-1);
}
strncat(dact_binfilebuf,"/.dact/dact.conf",sizeof(dact_binfilebuf)-strlen(dact_binfilebuf)-1);
dact_config_loadfile(dact_binfilebuf, options);
#endif
if (options[DACT_OPT_BINCHK]) {
dact_binfile=parse_url_subst(DACT_BIN, "");
if (strcmp(argv[0],dact_binfile)) {
if (!access(dact_binfile,X_OK)) {
argv[0]=dact_binfile;
#ifndef __MINGW32__
execv(dact_binfile, argv);
#else
execv(dact_binfile, (const char **) argv);
#endif
}
}
|
>
|
|
|
>
|
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
signed char opt;
struct stat stat_buf;
char **in_files, *in_file=NULL, *out_file=NULL;
char dact_binfilebuf[256], *dact_binfile;
int filecnt=0;
int in_fd, out_fd;
int mode=DACT_MODE_COMPR, ciphernum=-1;
uint32_t dact_blk_size=0;
uint32_t crcs[6]={0,0,0,0,0,0};
uint32_t i,x;
dact_ui_init();
/* hack, to make upgrade work even if DACT_OPT_BINCHK is enabled, we must
* get the new version before executing it.
*/
if (argv[1]!=NULL) {
if (!strcmp(argv[1],"-N")) return(dact_upgrade(options));
if (!strcmp(argv[1],"-a")) options[DACT_OPT_UPGRADE]=1;
}
dact_config_loadfile(DACT_CONFIG_FILE, options, &dact_blk_size);
#ifndef NO_BINCHECK
dact_binfilebuf[0]='\0';
if (getenv("HOME")) {
strncpy(dact_binfilebuf,getenv("HOME"),sizeof(dact_binfilebuf)-1);
}
strncat(dact_binfilebuf,"/.dact/dact.conf",sizeof(dact_binfilebuf)-strlen(dact_binfilebuf)-1);
dact_config_loadfile(dact_binfilebuf, options, &dact_blk_size);
#endif
if (options[DACT_OPT_BINCHK]) {
dact_binfile=parse_url_subst(DACT_BIN, "");
if (strcmp(argv[0],dact_binfile)) {
if (!access(dact_binfile,X_OK)) {
argv[0]=dact_binfile;
/* This fixes a strange warning..*/
#ifndef __MINGW32__
execv(dact_binfile, argv);
#else
execv(dact_binfile, (const char **) argv);
#endif
}
}
|
| ︙ | | | ︙ | |
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
dact_ui_setopt(DACT_UI_OPT_PASSSTDIN, 1);
break;
case 'c':
options[DACT_OPT_STDOUT]=!options[DACT_OPT_STDOUT];
break;
case 'b':
i=atoi2(optarg);
if (i<DACT_BLK_SIZE_MAX) DACT_BLK_SIZE=i;
break;
case 'v':
options[DACT_OPT_VERB]++;
dact_ui_setopt(DACT_UI_OPT_LEVEL,dact_ui_getopt(DACT_UI_OPT_LEVEL)+1);
break;
case 'n':
options[DACT_OPT_NOCRC]=!options[DACT_OPT_NOCRC];
break;
case 'p':
PRINT_LINE; fprintf(stderr, "dact: %s\n",parse_url_subst(optarg,"@@file@@"));
mode=DACT_MODE_RET;
break;
case 'C':
options[DACT_OPT_COMPLN]++;
break;
case 'm':
dact_config_loadfile(optarg, options);
break;
case 'e':
i=(atoi(optarg)&0xff);
algorithms[i]=DACT_FAILED_ALGO;
break;
case 'H':
options[DACT_OPT_HDONLY]=!options[DACT_OPT_HDONLY];
break;
case 'o':
out_file=parse_url_subst(optarg, "");
break;
case 'M':
dact_config_execute(optarg, options);
break;
case 'N':
PRINTERR("The `-N\' option must be the first and only argument passed to dact.");
return(0);
break;
case 'E':
strtolower(optarg);
|
|
|
|
|
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
|
dact_ui_setopt(DACT_UI_OPT_PASSSTDIN, 1);
break;
case 'c':
options[DACT_OPT_STDOUT]=!options[DACT_OPT_STDOUT];
break;
case 'b':
i=atoi2(optarg);
if (i<DACT_BLK_SIZE_MAX) dact_blk_size=i;
break;
case 'v':
options[DACT_OPT_VERB]++;
dact_ui_setopt(DACT_UI_OPT_LEVEL,dact_ui_getopt(DACT_UI_OPT_LEVEL)+1);
break;
case 'n':
options[DACT_OPT_NOCRC]=!options[DACT_OPT_NOCRC];
break;
case 'p':
PRINT_LINE; fprintf(stderr, "dact: %s\n",parse_url_subst(optarg,"@@file@@"));
mode=DACT_MODE_RET;
break;
case 'C':
options[DACT_OPT_COMPLN]++;
break;
case 'm':
dact_config_loadfile(optarg, options, &dact_blk_size);
break;
case 'e':
i=(atoi(optarg)&0xff);
algorithms[i]=DACT_FAILED_ALGO;
break;
case 'H':
options[DACT_OPT_HDONLY]=!options[DACT_OPT_HDONLY];
break;
case 'o':
out_file=parse_url_subst(optarg, "");
break;
case 'M':
dact_config_execute(optarg, options, &dact_blk_size);
break;
case 'N':
PRINTERR("The `-N\' option must be the first and only argument passed to dact.");
return(0);
break;
case 'E':
strtolower(optarg);
|
| ︙ | | | ︙ | |
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
|
in_fd=STDIN_FILENO;
}
}
/* Okay, we're all done, now pass these to something to do the real stuff */
if (in_fd!=-1 && (out_fd!=-1 || mode==DACT_MODE_STAT)) {
crcs[1]=crcs[0]=0;
if (dact_process_file(in_fd, out_fd, mode, options, in_file, crcs, ciphernum)==0) {
close(in_fd);
close(out_fd);
if (out_fd!=STDOUT_FILENO) {
unlink(out_file);
}
return(dact_shutdown(-1));
}
|
|
|
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
in_fd=STDIN_FILENO;
}
}
/* Okay, we're all done, now pass these to something to do the real stuff */
if (in_fd!=-1 && (out_fd!=-1 || mode==DACT_MODE_STAT)) {
crcs[1]=crcs[0]=0;
if (dact_process_file(in_fd, out_fd, mode, options, in_file, crcs, dact_blk_size, ciphernum)==0) {
close(in_fd);
close(out_fd);
if (out_fd!=STDOUT_FILENO) {
unlink(out_file);
}
return(dact_shutdown(-1));
}
|
| ︙ | | | ︙ | |