View | Details | Raw Unified | Return to bug 16070
Collapse All | Expand All

(-)sysinstall/dist.c (-12 / +37 lines)
Lines 573-586 Link Here
573
static Boolean
573
static Boolean
574
distExtract(char *parent, Distribution *me)
574
distExtract(char *parent, Distribution *me)
575
{
575
{
576
    int i, status, total, intr;
576
    int i,j, status, total, intr;
577
    int cpid, zpid, fd2, chunk, numchunks;
577
    int cpid, zpid, fd2, chunk, numchunks;
578
    char *path, *dist, buf[BUFSIZ];
578
    char *path, *dist, buf[300000];
579
    const char *tmp;
579
    const char *tmp;
580
    FILE *fp;
580
    FILE *fp;
581
    WINDOW *w = savescr();
581
    WINDOW *w = savescr();
582
    struct timeval start, stop;
582
    struct timeval start, stop;
583
    struct sigaction old, new;
583
    struct sigaction old, new;
584
    properties dist_attr;
584
585
585
    status = TRUE;
586
    status = TRUE;
586
    if (isDebug())
587
    if (isDebug())
Lines 643-650 Link Here
643
	    }
644
	    }
644
	}
645
	}
645
	else if (fp > 0) {
646
	else if (fp > 0) {
646
	    properties dist_attr;
647
648
	    if (isDebug())
647
	    if (isDebug())
649
		msgDebug("Parsing attributes file for distribution %s\n", dist);
648
		msgDebug("Parsing attributes file for distribution %s\n", dist);
650
649
Lines 661-667 Link Here
661
		    numchunks = strtol(tmp, 0, 0);
660
		    numchunks = strtol(tmp, 0, 0);
662
	    }
661
	    }
663
	    fclose(fp);
662
	    fclose(fp);
664
	    properties_free(dist_attr);
665
	    if (!numchunks)
663
	    if (!numchunks)
666
		continue;
664
		continue;
667
	}
665
	}
Lines 717-728 Link Here
717
	/* And go for all the chunks */
715
	/* And go for all the chunks */
718
	dialog_clear_norefresh();
716
	dialog_clear_norefresh();
719
	for (chunk = 0; chunk < numchunks; chunk++) {
717
	for (chunk = 0; chunk < numchunks; chunk++) {
720
	    int n, retval, last_msg;
718
	    int n, retval, last_msg, chunksize, realsize;
721
	    char prompt[80];
719
	    char prompt[80];
722
720
723
	    last_msg = 0;
721
	    last_msg = 0;
724
722
725
	getchunk:
723
	getchunk:
724
	    snprintf(buf, sizeof buf, "cksum.%c%c",  (chunk / 26) + 'a', (chunk % 26) + 'a');
725
	    tmp = property_find(dist_attr, buf);
726
	    chunksize=0;
727
	    if (tmp) {
728
		tmp=index(tmp, ' ');
729
		chunksize = strtol(tmp, 0, 0);
730
	    }
726
	    snprintf(buf, sizeof buf, "%s/%s.%c%c", path, dist, (chunk / 26) + 'a', (chunk % 26) + 'a');
731
	    snprintf(buf, sizeof buf, "%s/%s.%c%c", path, dist, (chunk / 26) + 'a', (chunk % 26) + 'a');
727
	    if (isDebug())
732
	    if (isDebug())
728
		msgDebug("trying for piece %d of %d: %s\n", chunk + 1, numchunks, buf);
733
		msgDebug("trying for piece %d of %d: %s\n", chunk + 1, numchunks, buf);
Lines 744-753 Link Here
744
	    snprintf(prompt, sizeof prompt, "Extracting %s into %s directory...", dist, root_bias(me[i].my_dir));
749
	    snprintf(prompt, sizeof prompt, "Extracting %s into %s directory...", dist, root_bias(me[i].my_dir));
745
	    dialog_gauge("Progress", prompt, 8, 15, 6, 50, (int)((float)(chunk + 1) / numchunks * 100));
750
	    dialog_gauge("Progress", prompt, 8, 15, 6, 50, (int)((float)(chunk + 1) / numchunks * 100));
746
751
752
	    realsize=0;
747
	    while (1) {
753
	    while (1) {
748
		int seconds;
754
		int seconds;
749
755
750
		n = fread(buf, 1, BUFSIZ, fp);
756
		n =fread(buf+realsize, 1, BUFSIZ, fp);
751
		if (check_for_interrupt()) {
757
		if (check_for_interrupt()) {
752
		    msgConfirm("Media read error:  User interrupt.");
758
		    msgConfirm("Media read error:  User interrupt.");
753
		    fclose(fp);
759
		    fclose(fp);
Lines 756-761 Link Here
756
		else if (n <= 0)
762
		else if (n <= 0)
757
		    break;
763
		    break;
758
		total += n;
764
		total += n;
765
		realsize += n;
759
766
760
		/* Print statistics about how we're doing */
767
		/* Print statistics about how we're doing */
761
		(void) gettimeofday(&stop, (struct timezone *)0);
768
		(void) gettimeofday(&stop, (struct timezone *)0);
Lines 772-790 Link Here
772
		    msgInfo("%10d bytes read from %s dist, chunk %2d of %2d @ %.1f KB/sec.",
779
		    msgInfo("%10d bytes read from %s dist, chunk %2d of %2d @ %.1f KB/sec.",
773
			    total, dist, chunk + 1, numchunks, (total / seconds) / 1024.0);
780
			    total, dist, chunk + 1, numchunks, (total / seconds) / 1024.0);
774
		}
781
		}
775
		retval = write(fd2, buf, n);
782
	    }
776
		if (retval != n) {
783
	    fclose(fp);
784
            
785
		if (!chunksize || (realsize == chunksize)) {
786
		/* No substitution necessary */
787
		retval = write(fd2, buf, realsize);
788
		if (retval != realsize) {
777
		    fclose(fp);
789
		    fclose(fp);
778
		    dialog_clear_norefresh();
790
		    dialog_clear_norefresh();
779
		    msgConfirm("Write failure on transfer! (wrote %d bytes of %d bytes)", retval, n);
791
		    msgConfirm("Write failure on transfer! (wrote %d bytes of %d bytes)", retval, realsize);
780
		    goto punt;
792
		    goto punt;
781
		}
793
		}
794
	    } else {
795
		for(j=0; j<realsize; j++) {
796
		    /*  On finding CRLF, skip the CR; don't exceed end of buffer. */
797
		    if ((buf[j]!=0x0d) || (j== total-1) || (buf[j+1]!=0x0a)) {
798
			retval = write(fd2, buf+j, 1);
799
			if (retval != 1) {
800
			    fclose(fp);
801
			    dialog_clear_norefresh();
802
			    msgConfirm("Write failure on transfer! (wrote %d bytes of %d bytes)", j, chunksize);
803
			    goto punt;
804
			}
805
		    }
806
		}
782
	    }
807
	    }
783
	    fclose(fp);
784
	}
808
	}
785
	close(fd2);
809
	close(fd2);
786
	status = mediaExtractDistEnd(zpid, cpid);
810
	status = mediaExtractDistEnd(zpid, cpid);
787
        goto done;
811
	goto done;
788
812
789
    punt:
813
    punt:
790
	close(fd2);
814
	close(fd2);
Lines 814-819 Link Here
814
	else
838
	else
815
	    continue;
839
	    continue;
816
    }
840
    }
841
    properties_free(dist_attr);
817
    sigaction(SIGINT, &old, NULL);	/* Restore signal handler */
842
    sigaction(SIGINT, &old, NULL);	/* Restore signal handler */
818
    restorescr(w);
843
    restorescr(w);
819
    return status;
844
    return status;
(-)sysinstall/http.c (-90 / +87 lines)
Lines 11-48 Link Here
11
mediaInitHTTP(Device *dev)
11
mediaInitHTTP(Device *dev)
12
{
12
{
13
/* 
13
/* 
14
 * Some proxies think that files with the extension ".ai" are postscript
14
 * Some proxies fetch files with certain extensions in "ascii mode" instead
15
 * files and use "ascii mode" instead of "binary mode" for ftp.
15
 * of "binary mode" for FTP. The FTP server then translates all LF to CRLF.
16
 * The FTP server then translates all LF to CRLF.
17
 * I don't know how to handle this elegantly...
18
 * Squid uses ascii mode, ftpget uses binary mode and both tell us:
19
 * "Content-Type: application/postscript"
20
 *
21
 * Probably the safest way would be to get the file, look at its checksum
22
 * and, if it doesn't match, replace all CRLF by LF and check again.
23
 *
16
 *
24
 * You can force Squid to use binary mode by appending ";type=i" to the URL,
17
 * You can force Squid to use binary mode by appending ";type=i" to the URL,
25
 * which is what I do here.
18
 * which is what I do here. For other proxies, the LF->CRLF substitution
26
 *
19
 * is reverted in distExtract().
27
 */
20
 */
28
21
29
    extern int h_errno;
22
    extern int h_errno;
30
    int rv,s;
23
    int rv,s;
31
    bool el;                    /* end of header line */
24
    bool el;		    /* end of header line */
32
    char *cp, buf[PATH_MAX], req[1000];
25
    char *cp, buf[PATH_MAX], req[BUFSIZ];
33
    struct sockaddr_in peer;
26
    struct sockaddr_in peer;
34
    struct hostent *peer_in;
27
    struct hostent *peer_in;
35
28
36
    s=socket(PF_INET, SOCK_STREAM, 6);    /* tcp */
29
    s=socket(PF_INET, SOCK_STREAM, 6);    /* tcp */
37
    if (s == -1) {
30
    if (s == -1) {
38
      msgConfirm("Network error");
31
	msgConfirm("Network error");
39
      return FALSE;
32
	return FALSE;
40
    }
33
    }
41
34
42
    peer_in=gethostbyname(variable_get(VAR_HTTP_HOST));
35
    peer_in=gethostbyname(variable_get(VAR_HTTP_HOST));
43
    if (peer_in == NULL) {
36
    if (peer_in == NULL) {
44
      msgConfirm("%s",hstrerror(h_errno));
37
	msgConfirm("%s",hstrerror(h_errno));
45
      return FALSE;
38
	return FALSE;
46
    }
39
    }
47
40
48
    peer.sin_len=peer_in->h_length;
41
    peer.sin_len=peer_in->h_length;
Lines 52-60 Link Here
52
45
53
    rv=connect(s,(struct sockaddr *)&peer,sizeof(peer));
46
    rv=connect(s,(struct sockaddr *)&peer,sizeof(peer));
54
    if (rv == -1) {
47
    if (rv == -1) {
55
      msgConfirm("Couldn't connect to proxy %s:%s",
48
	msgConfirm("Couldn't connect to proxy %s:%s",
56
                  variable_get(VAR_HTTP_HOST),variable_get(VAR_FTP_PORT));
49
		    variable_get(VAR_HTTP_HOST),variable_get(VAR_HTTP_PORT));
57
      return FALSE;
50
	return FALSE;
58
    }
51
    }
59
52
60
    sprintf(req,"GET / HTTP/1.0\r\n\r\n");
53
    sprintf(req,"GET / HTTP/1.0\r\n\r\n");
Lines 69-96 Link Here
69
    rv=read(s,cp,1);
62
    rv=read(s,cp,1);
70
    variable_set2(VAR_HTTP_FTP_MODE,"",0);
63
    variable_set2(VAR_HTTP_FTP_MODE,"",0);
71
    while (rv>0) {
64
    while (rv>0) {
72
      if ((*cp == '\012') && el) { 
65
	if ((*cp == '\012') && el) { 
73
        /* reached end of a header line */
66
	    /* reached end of a header line */
74
        if (!strncmp(buf,"Server: ",8)) {
67
	    if (!strncmp(buf,"Server: ",8)) {
75
          if (!strncmp(buf,"Server: Squid",13)) {
68
		if (!strncmp(buf,"Server: Squid",13)) {
76
            variable_set2(VAR_HTTP_FTP_MODE,";type=i",1);
69
		    variable_set2(VAR_HTTP_FTP_MODE,";type=i",0);
77
          } else {
70
		} else {
78
            variable_set2(VAR_HTTP_FTP_MODE,"",1);
71
		    variable_set2(VAR_HTTP_FTP_MODE,"",0);
79
          }
72
		}
80
        }
73
	    }
81
        /* ignore other headers */
74
	    /* ignore other headers */
82
        /* check for "\015\012" at beginning of line, i.e. end of headers */
75
	    /* check for "\015\012" at beginning of line, i.e. end of headers */
83
        if ((cp-buf) == 1)
76
	    if ((cp-buf) == 1)
84
          break;
77
		break;
85
        cp=buf;
78
	    cp=buf;
86
        rv=read(s,cp,1);
79
	    rv=read(s,cp,1);
87
      } else {
80
	} else {
88
        el=FALSE;
81
	    el=FALSE;
89
        if (*cp == '\015')
82
	    if (*cp == '\015')
90
          el=TRUE;
83
		el=TRUE;
91
        cp++;
84
	    cp++;
92
        rv=read(s,cp,1);
85
	    rv=read(s,cp,1);
93
      }
86
	}
94
    }
87
    }
95
    close(s);
88
    close(s);
96
    return TRUE;
89
    return TRUE;
Lines 103-116 Link Here
103
    FILE *fp;
96
    FILE *fp;
104
    int rv,s;
97
    int rv,s;
105
    bool el;			/* end of header line */
98
    bool el;			/* end of header line */
106
    char *cp, buf[PATH_MAX], req[1000];
99
    char *cp, buf[PATH_MAX], req[BUFSIZ];
107
    struct sockaddr_in peer;
100
    struct sockaddr_in peer;
108
    struct hostent *peer_in;
101
    struct hostent *peer_in;
109
102
110
    s=socket(PF_INET, SOCK_STREAM, 6);    /* tcp */
103
    s=socket(PF_INET, SOCK_STREAM, 6);    /* tcp */
111
    if (s == -1) {
104
    if (s == -1) {
112
      msgConfirm("Network error");
105
	msgConfirm("Network error");
113
      return NULL;
106
	return NULL;
114
    }
107
    }
115
      
108
      
116
    peer_in=gethostbyname(variable_get(VAR_HTTP_HOST));
109
    peer_in=gethostbyname(variable_get(VAR_HTTP_HOST));
Lines 121-136 Link Here
121
114
122
    rv=connect(s,(struct sockaddr *)&peer,sizeof(peer));
115
    rv=connect(s,(struct sockaddr *)&peer,sizeof(peer));
123
    if (rv == -1) {
116
    if (rv == -1) {
124
      msgConfirm("Couldn't connect to proxy %s:%s",
117
	msgConfirm("Couldn't connect to proxy %s:%s",
125
                  variable_get(VAR_HTTP_HOST),variable_get(VAR_FTP_PORT));
118
		    variable_get(VAR_HTTP_HOST),variable_get(VAR_FTP_PORT));
126
      return NULL;
119
	return NULL;
127
    }
120
    }
128
                                                   
121
						   
129
    sprintf(req,"GET ftp://%s:%s%s%s/%s%s HTTP/1.0\r\n\r\n",
122
    sprintf(req,"GET %s/%s/%s%s HTTP/1.0\r\n\r\n",
130
            variable_get(VAR_FTP_HOST), variable_get(VAR_FTP_PORT),
123
	    variable_get(VAR_FTP_PATH), variable_get(VAR_RELNAME),
131
            "/pub/FreeBSD/", variable_get(VAR_RELNAME),
124
	    file, variable_get(VAR_HTTP_FTP_MODE));
132
            file,variable_get(VAR_HTTP_FTP_MODE));
125
133
    msgDebug("sending http request: %s",req);
126
    if (isDebug()) {
127
	msgDebug("sending http request: %s",req);
128
    }
134
    write(s,req,strlen(req));
129
    write(s,req,strlen(req));
135
130
136
/*
131
/*
Lines 142-182 Link Here
142
    el=FALSE;
137
    el=FALSE;
143
    rv=read(s,cp,1);
138
    rv=read(s,cp,1);
144
    while (rv>0) {
139
    while (rv>0) {
145
      if ((*cp == '\012') && el) {
140
	if ((*cp == '\012') && el) {
146
        /* reached end of a header line */
141
  	    /* reached end of a header line */
147
        if (!strncmp(buf,"HTTP",4)) {
142
  	    if (!strncmp(buf,"HTTP",4)) {
148
          rv=strtol((char *)(buf+9),0,0);
143
		rv=strtol((char *)(buf+9),0,0);
149
          *(cp-1)='\0';		/* chop the CRLF off */
144
		*(cp-1)='\0';		/* chop the CRLF off */
150
          if (rv >= 500) {
145
		if (probe && (rv != 200)) {
151
            msgConfirm("Server error %s, you could try an other server",buf);
146
		    return NULL;
152
            return NULL;
147
		} else if (rv >= 500) {
153
          } else if (rv == 404) {
148
		    msgConfirm("Server error %s when sending %s, you could try an other server",buf, req);
154
            msgConfirm("%s was not found, maybe directory or release-version are wrong?",req);
149
		    return NULL;
155
            return NULL;
150
		} else if (rv == 404) {
156
          } else if (rv >= 400) {
151
		    msgConfirm("%s was not found, maybe directory or release-version are wrong?",req);
157
            msgConfirm("Client error %s, you could try an other server",buf);
152
		    return NULL;
158
            return NULL;
153
		} else if (rv >= 400) {
159
          } else if (rv >= 300) {
154
		    msgConfirm("Client error %s, you could try an other server",buf);
160
            msgConfirm("Error %s,",buf);
155
		    return NULL;
161
            return NULL;
156
		} else if (rv >= 300) {
162
          } else if (rv != 200) {
157
		    msgConfirm("Error %s,",buf);
163
            msgConfirm("Error %s when trying to fetch %s",buf,req);
158
		    return NULL;
164
            return NULL;
159
		} else if (rv != 200) {
165
          }
160
		    msgConfirm("Error %s when sending %s, you could try an other server",buf, req);
166
        }
161
		    return NULL;
167
        /* ignore other headers */
162
		}
168
        /* check for "\015\012" at beginning of line, i.e. end of headers */
163
	    }
169
        if ((cp-buf) == 1) 
164
	    /* ignore other headers */
170
          break;
165
	    /* check for "\015\012" at beginning of line, i.e. end of headers */
171
        cp=buf;
166
	    if ((cp-buf) == 1) 
172
        rv=read(s,cp,1);
167
		break;
173
      } else {
168
	    cp=buf;
174
        el=FALSE;
169
	    rv=read(s,cp,1);
175
        if (*cp == '\015')
170
	} else {
176
          el=TRUE;
171
	    el=FALSE;
177
        cp++;
172
	    if (*cp == '\015')
178
        rv=read(s,cp,1);
173
		el=TRUE;
179
      }
174
	    cp++;
175
	    rv=read(s,cp,1);
176
	}
180
    }
177
    }
181
    fp=fdopen(s,"r");
178
    fp=fdopen(s,"r");
182
    return fp;
179
    return fp;
(-)sysinstall/media.c (-6 / +5 lines)
Lines 445-451 Link Here
445
    if (DITEM_STATUS(result) != DITEM_SUCCESS)
445
    if (DITEM_STATUS(result) != DITEM_SUCCESS)
446
	return result;
446
	return result;
447
 
447
 
448
    variable_set2(VAR_HTTP_PATH, "", 0);
449
    cp = variable_get_value(VAR_HTTP_PATH,
448
    cp = variable_get_value(VAR_HTTP_PATH,
450
	"Please enter the address of the HTTP proxy in this format:\n"
449
	"Please enter the address of the HTTP proxy in this format:\n"
451
	" hostname:port (the ':port' is optional, default is 3128)",0);
450
	" hostname:port (the ':port' is optional, default is 3128)",0);
Lines 461-471 Link Here
461
460
462
    variable_set2(VAR_HTTP_HOST, hostname, 0);
461
    variable_set2(VAR_HTTP_HOST, hostname, 0);
463
    variable_set2(VAR_HTTP_PORT, itoa(HttpPort), 0);
462
    variable_set2(VAR_HTTP_PORT, itoa(HttpPort), 0);
464
    msgDebug("VAR_HTTP_HOST, _PORT: %s:%s",variable_get(VAR_HTTP_HOST),
463
    if (isDebug()) {
465
                                           variable_get(VAR_HTTP_PORT));
464
      msgDebug("VAR_FTP_PATH : %s",variable_get(VAR_FTP_PATH));
466
465
      msgDebug("VAR_HTTP_HOST, _PORT: %s:%s",variable_get(VAR_HTTP_HOST),
467
    msgDebug("VAR_FTP_HOST, _PORT: %s:%s", variable_get(VAR_FTP_HOST),
466
                                             variable_get(VAR_HTTP_PORT));
468
                                           variable_get(VAR_FTP_PORT));
467
    }
469
468
470
    /* mediaDevice has been set by mediaSetFTP(), overwrite partly: */
469
    /* mediaDevice has been set by mediaSetFTP(), overwrite partly: */
471
    mediaDevice->type = DEVICE_TYPE_HTTP;
470
    mediaDevice->type = DEVICE_TYPE_HTTP;
(-)sysinstall/sysinstall.8 (+15 lines)
Lines 675-680 Link Here
675
Select a tape device as the installation media.
675
Select a tape device as the installation media.
676
.Pp
676
.Pp
677
\fBVariables:\fR None
677
\fBVariables:\fR None
678
679
.\" XXX
680
678
.It mediaSetFTP
681
.It mediaSetFTP
679
Select an FTP site as the installation media.
682
Select an FTP site as the installation media.
680
.Pp
683
.Pp
Lines 719-724 Link Here
719
.Pp
722
.Pp
720
\fBVariables:\fR Same as for
723
\fBVariables:\fR Same as for
721
.Ar mediaSetFTP .
724
.Ar mediaSetFTP .
725
.It mediaSetHTTP
726
Alias for
727
.Ar mediaSetFTP
728
using an HTTP proxy.
729
.Pp
730
\fBVariables:\fR See
731
.Ar mediaSetFTP ,
732
plus
733
.Bl -tag -width indent
734
.It _httpPath
735
The proxy to use (host:port) (non-optional).
736
.El
722
.It mediaSetUFS
737
.It mediaSetUFS
723
Select an existing UFS partition (mounted with the label editor) as
738
Select an existing UFS partition (mounted with the label editor) as
724
the installation media.
739
the installation media.

Return to bug 16070