mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-30 20:35:03 +01:00
Compare commits
146
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17d68b04ff | ||
|
|
ce6a5b7bc2 | ||
|
|
c2b805c3e2 | ||
|
|
3bd426de32 | ||
|
|
725728d3f1 | ||
|
|
6d14058c93 | ||
|
|
0732cb7664 | ||
|
|
1dc3787975 | ||
|
|
336a99a142 | ||
|
|
e7573d045e | ||
|
|
54eacce011 | ||
|
|
95f3479e86 | ||
|
|
d4b8a803d2 | ||
|
|
3edb5b8243 | ||
|
|
9e1e69007e | ||
|
|
6b131fd325 | ||
|
|
96f6ce831d | ||
|
|
722da8795b | ||
|
|
2a161a564f | ||
|
|
ef6315440d | ||
|
|
257b64e655 | ||
|
|
5400a1d50b | ||
|
|
cb6db0be82 | ||
|
|
efc20b9b20 | ||
|
|
3a4a0410ce | ||
|
|
89ff02f2cd | ||
|
|
a395a8ddaa | ||
|
|
c02d319382 | ||
|
|
e8170c615e | ||
|
|
86f0017da6 | ||
|
|
0f2f75d4cd | ||
|
|
760b3ff032 | ||
|
|
2007fa5423 | ||
|
|
2826b97699 | ||
|
|
cad0dd6541 | ||
|
|
a7536a22f1 | ||
|
|
ec8cca06a4 | ||
|
|
956e27c432 | ||
|
|
365e7a5627 | ||
|
|
036dc9deb5 | ||
|
|
588b2ee1f4 | ||
|
|
4e0d7f1eeb | ||
|
|
41865c3eb8 | ||
|
|
6a1d5c6111 | ||
|
|
ae96b458b8 | ||
|
|
53cdd7b2cc | ||
|
|
138d328594 | ||
|
|
779181d670 | ||
|
|
ea440f5a8c | ||
|
|
00647e5628 | ||
|
|
582231348c | ||
|
|
b23677495a | ||
|
|
c34d79a043 | ||
|
|
3a27de6a11 | ||
|
|
6b98c5e881 | ||
|
|
d5eb22b779 | ||
|
|
f7a19e923f | ||
|
|
c259a2c856 | ||
|
|
2ec38507c3 | ||
|
|
d3c6824031 | ||
|
|
cd5baeac25 | ||
|
|
b12d22be7d | ||
|
|
2bf0e027c9 | ||
|
|
ee11a1bf89 | ||
|
|
6a1cb1770f | ||
|
|
1ee8ce5356 | ||
|
|
b8498bde4a | ||
|
|
28aa8fa144 | ||
|
|
aad26cb372 | ||
|
|
9e6e907a18 | ||
|
|
dccedb5e05 | ||
|
|
3ec2d329a6 | ||
|
|
44075fb26d | ||
|
|
019765e155 | ||
|
|
13c01cc282 | ||
|
|
b8680a4f43 | ||
|
|
bc879ddf95 | ||
|
|
8f3fec335d | ||
|
|
b3c2e1fc0f | ||
|
|
78b2207ca1 | ||
|
|
ed00024f56 | ||
|
|
f2b4a33021 | ||
|
|
9451b7b706 | ||
|
|
864e2d4780 | ||
|
|
d4cc0dd698 | ||
|
|
19ea613108 | ||
|
|
1f8e33d2b6 | ||
|
|
f500949472 | ||
|
|
ad461bea1f | ||
|
|
aa1af3afc4 | ||
|
|
3a888d6a17 | ||
|
|
89b9ab35d9 | ||
|
|
32bc8b104a | ||
|
|
03675f50e3 | ||
|
|
2241cdc84a | ||
|
|
10bc76be64 | ||
|
|
0ecdbb412d | ||
|
|
ff8eca7f6e | ||
|
|
f21c1795b5 | ||
|
|
fd65bb44b6 | ||
|
|
4af1c15ea4 | ||
|
|
13c72f074c | ||
|
|
296ea871fa | ||
|
|
3c56cf9a5f | ||
|
|
06176b545f | ||
|
|
fb5aed6a17 | ||
|
|
1fd9820da2 | ||
|
|
a2d44b961b | ||
|
|
972b9cf163 | ||
|
|
7c5e88b7dc | ||
|
|
748e263e1d | ||
|
|
d737fb0b8e | ||
|
|
7b1fa34c8d | ||
|
|
6acd4084ec | ||
|
|
7a5430c00e | ||
|
|
adc988f73d | ||
|
|
1352103803 | ||
|
|
257c17f29a | ||
|
|
d5f02160ba | ||
|
|
ed288be5ba | ||
|
|
e92eaf1075 | ||
|
|
5e3393116c | ||
|
|
093b091bd8 | ||
|
|
9474c9643e | ||
|
|
5e5326a1ba | ||
|
|
378c58eff0 | ||
|
|
05d21356fb | ||
|
|
cfb83353fd | ||
|
|
8cd360ec17 | ||
|
|
1bf5c58257 | ||
|
|
f54ce65bb9 | ||
|
|
ac613515db | ||
|
|
289746cecf | ||
|
|
625b109de1 | ||
|
|
a42a785e4d | ||
|
|
207002ac9e | ||
|
|
29388f8fe8 | ||
|
|
c470a93b9f | ||
|
|
9808520bd1 | ||
|
|
69111243d3 | ||
|
|
f176719027 | ||
|
|
6f8161632a | ||
|
|
c0b59cd1b1 | ||
|
|
5d53a74cd7 | ||
|
|
6d9a276234 | ||
|
|
52b82940fc |
No files matched your search
@@ -1,4 +1,15 @@
|
||||
# @(#)Makefile.inc 8.1 (Berkeley) 5/31/93
|
||||
# $Id: Makefile.inc,v 1.7 1996/09/22 21:51:04 wosch Exp $
|
||||
|
||||
BINDIR?= /bin
|
||||
NOSHARED?= YES
|
||||
|
||||
.if exists (${.CURDIR}/../../secure)
|
||||
|
||||
.if exists(${.CURDIR}/../../secure/lib/libcipher/obj)
|
||||
CIPHEROBJDIR= ${.CURDIR}/../../secure/lib/libcipher/obj
|
||||
.else
|
||||
CIPHEROBJDIR= ${.CURDIR}/../../secure/lib/libcipher
|
||||
.endif
|
||||
|
||||
.endif
|
||||
+9
-2
@@ -1,8 +1,15 @@
|
||||
# $Id: Makefile,v 1.10 1994/12/18 15:15:10 jkh Exp $
|
||||
# $Id: Makefile,v 1.13 1995/10/22 20:14:13 ache Exp $
|
||||
|
||||
PROG= ed
|
||||
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
|
||||
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
|
||||
LINKS= ${BINDIR}/ed ${BINDIR}/red
|
||||
MLINKS= ed.1 red.1
|
||||
|
||||
.if exists(../../secure) && !defined(NOCRYPT) && !defined(NOSECURE)
|
||||
DISTRIBUTION=des
|
||||
CFLAGS+=-DDES
|
||||
LDADD+= -L${CIPHEROBJDIR} -lcipher
|
||||
DPADD+= ${CIPHEROBJDIR}/libcipher.a
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
+10
-6
@@ -33,7 +33,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: main.c,v 1.2 1994/09/24 02:57:48 davidg Exp $
|
||||
* $Id: main.c,v 1.3 1995/05/30 00:07:18 rgrimes Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@@ -152,14 +152,18 @@ main(argc, argv) char **argv; {
|
||||
read_profile("/etc/profile");
|
||||
state1:
|
||||
state = 2;
|
||||
read_profile(".profile");
|
||||
if (privileged == 0)
|
||||
read_profile(".profile");
|
||||
else
|
||||
read_profile("/etc/suid_profile");
|
||||
}
|
||||
state2:
|
||||
state = 3;
|
||||
if ((shinit = lookupvar("ENV")) != NULL &&
|
||||
*shinit != '\0') {
|
||||
state = 3;
|
||||
read_profile(shinit);
|
||||
if (privileged == 0) {
|
||||
if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
|
||||
state = 3;
|
||||
read_profile(shinit);
|
||||
}
|
||||
}
|
||||
state3:
|
||||
state = 4;
|
||||
|
||||
+10
-1
@@ -33,7 +33,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: options.c,v 1.3.4.2 1995/10/02 07:55:18 davidg Exp $
|
||||
* $Id: options.c,v 1.3.4.3 1995/10/10 01:04:38 davidg Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@@ -91,6 +91,7 @@ procargs(argc, argv)
|
||||
argptr++;
|
||||
for (i = 0; i < NOPTS; i++)
|
||||
optlist[i].val = 2;
|
||||
privileged = (getuid() != geteuid() || getgid() != getegid());
|
||||
options(1);
|
||||
if (*argptr == NULL && minusc == NULL)
|
||||
sflag = 1;
|
||||
@@ -177,6 +178,10 @@ options(cmdline) {
|
||||
if (*argptr)
|
||||
argptr++;
|
||||
} else {
|
||||
if (c == 'p' && !val && privileged) {
|
||||
(void) setuid(getuid());
|
||||
(void) setgid(getgid());
|
||||
}
|
||||
setoption(c, val);
|
||||
}
|
||||
}
|
||||
@@ -198,6 +203,10 @@ minus_o(name, val)
|
||||
} else {
|
||||
for (i = 0; i < NOPTS; i++)
|
||||
if (equal(name, optlist[i].name)) {
|
||||
if (!val && privileged && equal(name, "privileged")) {
|
||||
(void) setuid(getuid());
|
||||
(void) setgid(getgid());
|
||||
}
|
||||
setoption(optlist[i].letter, val);
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-2
@@ -34,7 +34,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)options.h 8.1 (Berkeley) 5/31/93
|
||||
* $Id$
|
||||
* $Id: options.h,v 1.2 1994/09/24 02:58:05 davidg Exp $
|
||||
*/
|
||||
|
||||
struct shparam {
|
||||
@@ -62,8 +62,9 @@ struct shparam {
|
||||
#define aflag optlist[12].val
|
||||
#define bflag optlist[13].val
|
||||
#define uflag optlist[14].val
|
||||
#define privileged optlist[15].val
|
||||
|
||||
#define NOPTS 15
|
||||
#define NOPTS 16
|
||||
|
||||
struct optent {
|
||||
const char *name;
|
||||
@@ -88,6 +89,7 @@ struct optent optlist[NOPTS] = {
|
||||
"allexport", 'a', 0,
|
||||
"notify", 'b', 0,
|
||||
"nounset", 'u', 0,
|
||||
"privileged", 'p', 0,
|
||||
};
|
||||
#else
|
||||
extern struct optent optlist[NOPTS];
|
||||
|
||||
+11
-2
@@ -33,7 +33,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)sh.1 8.4 (Berkeley) 4/18/94
|
||||
.\" $Id: sh.1,v 1.5 1995/10/21 00:47:32 joerg Exp $
|
||||
.\" $Id: sh.1,v 1.3.4.1 1995/12/11 23:04:55 joerg Exp $
|
||||
.\"
|
||||
.\"
|
||||
.\"
|
||||
@@ -42,7 +42,7 @@
|
||||
.SH NAME
|
||||
sh \- command interpreter (shell)
|
||||
.SH SYNOPSIS
|
||||
sh [-/+aCefnuvxIimsVEb] [-/+o longname] [arg ...]
|
||||
sh [-/+aCefnpuvxIimsVEb] [-/+o longname] [arg ...]
|
||||
.SH DESCRIPTION
|
||||
.LP
|
||||
Sh is the standard command interpreter for the system.
|
||||
@@ -161,6 +161,15 @@ If not interactive, read commands but do not
|
||||
execute them. This is useful for checking the
|
||||
syntax of shell scripts.
|
||||
.TP
|
||||
-p privileged
|
||||
Turn on privileged mode. This mode is enabled on startup
|
||||
if either the effective user or group id is not equal to the
|
||||
real user or group id. Turning this mode off sets the
|
||||
effective user and group ids to the real user and group ids.
|
||||
Also on interactive shells and when enabled, this mode sources
|
||||
/etc/suid_profile (instead of ~/.profile) after /etc/profile
|
||||
and ignores the contents of the \fBENV\fP variable.
|
||||
.TP
|
||||
-u nounset
|
||||
Write a message to standard error when attempting
|
||||
to expand a variable that is not set, and if the
|
||||
|
||||
@@ -81,7 +81,8 @@ if [ ! -f $bak/master.passwd.bak ] ; then
|
||||
fi
|
||||
if cmp -s $bak/master.passwd.bak /etc/master.passwd; then :; else
|
||||
echo "$host passwd diffs:"
|
||||
diff $bak/master.passwd.bak /etc/master.passwd
|
||||
diff $bak/master.passwd.bak /etc/master.passwd |\
|
||||
sed 's/^\([<>] [^:]*\):[^:]*:/\1:(password):/'
|
||||
mv $bak/master.passwd.bak $bak/master.passwd.bak2
|
||||
cp -p /etc/master.passwd $bak/master.passwd.bak
|
||||
fi
|
||||
|
||||
@@ -191,6 +191,6 @@ mta3230|mo230|IBM MTA-3230 230 Meg 3.5inch Magneto-Optical:\
|
||||
:pc#444384:oc#0:
|
||||
|
||||
minimum:ty=mfs:se#512:nt#1:rm#300:\
|
||||
:ns#2400:nc#1:\
|
||||
:pa#2400:oa#0:ba#4096:fa#512:\
|
||||
:pc#2400:oc#0:bc#4096:fc#512:
|
||||
:ns#2880:nc#1:\
|
||||
:pa#2880:oa#0:ba#4096:fa#512:\
|
||||
:pc#2880:oc#0:bc#4096:fc#512:
|
||||
@@ -1,4 +1,4 @@
|
||||
# $Id: BSD.local.dist,v 1.11.4.4 1996/06/11 22:04:55 asami Exp $
|
||||
# $Id: BSD.local.dist,v 1.11.4.5 1996/06/16 22:33:58 asami Exp $
|
||||
#
|
||||
|
||||
/set type=dir uname=bin gname=bin mode=0755
|
||||
@@ -38,6 +38,54 @@
|
||||
..
|
||||
catl uname=man
|
||||
..
|
||||
catn uname=man
|
||||
..
|
||||
ja_JP.EUC
|
||||
cat1 uname=man
|
||||
..
|
||||
cat2 uname=man
|
||||
..
|
||||
cat3 uname=man
|
||||
..
|
||||
cat4 uname=man
|
||||
..
|
||||
cat5 uname=man
|
||||
..
|
||||
cat6 uname=man
|
||||
..
|
||||
cat7 uname=man
|
||||
..
|
||||
cat8 uname=man
|
||||
..
|
||||
cat9 uname=man
|
||||
..
|
||||
catl uname=man
|
||||
..
|
||||
catn uname=man
|
||||
..
|
||||
man1
|
||||
..
|
||||
man2
|
||||
..
|
||||
man3
|
||||
..
|
||||
man4
|
||||
..
|
||||
man5
|
||||
..
|
||||
man6
|
||||
..
|
||||
man7
|
||||
..
|
||||
man8
|
||||
..
|
||||
man9
|
||||
..
|
||||
manl
|
||||
..
|
||||
mann
|
||||
..
|
||||
..
|
||||
man1
|
||||
..
|
||||
man2
|
||||
@@ -58,12 +106,20 @@
|
||||
..
|
||||
manl
|
||||
..
|
||||
mann
|
||||
..
|
||||
..
|
||||
sbin
|
||||
..
|
||||
share
|
||||
dict
|
||||
..
|
||||
doc
|
||||
..
|
||||
examples
|
||||
..
|
||||
misc
|
||||
..
|
||||
nls
|
||||
C
|
||||
..
|
||||
@@ -103,6 +159,8 @@
|
||||
..
|
||||
ja_JP.EUC
|
||||
..
|
||||
lt_LN.ASCII
|
||||
..
|
||||
lt_LN.ISO_8859-1
|
||||
..
|
||||
nl_BE.ISO_8859-1
|
||||
@@ -113,6 +171,8 @@
|
||||
..
|
||||
pt_PT.ISO_8859-1
|
||||
..
|
||||
ru_SU.CP866
|
||||
..
|
||||
ru_SU.KOI8-R
|
||||
..
|
||||
sv_SE.ISO_8859-1
|
||||
|
||||
+12
-2
@@ -12,8 +12,8 @@
|
||||
; submenu InterNIC Registration Archives
|
||||
; file named.root
|
||||
;
|
||||
; last update: Nov 8, 1995
|
||||
; related version of root zone: 1995110800
|
||||
; last update: Jan 22, 1997
|
||||
; related version of root zone: 1997012200
|
||||
;
|
||||
;
|
||||
; formerly NS.INTERNIC.NET
|
||||
@@ -60,4 +60,14 @@ H.ROOT-SERVERS.NET. 3600000 A 128.63.2.53
|
||||
;
|
||||
. 3600000 NS I.ROOT-SERVERS.NET.
|
||||
I.ROOT-SERVERS.NET. 3600000 A 192.36.148.17
|
||||
;
|
||||
; temporarily housed at NSI (InterNIC)
|
||||
;
|
||||
. 3600000 NS J.ROOT-SERVERS.NET.
|
||||
J.ROOT-SERVERS.NET. 3600000 A 198.41.0.10
|
||||
;
|
||||
; temporarily housed at NSI (InterNIC)
|
||||
;
|
||||
. 3600000 NS K.ROOT-SERVERS.NET.
|
||||
K.ROOT-SERVERS.NET. 3600000 A 198.41.0.11
|
||||
; End of File
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# @(#)security 5.3 (Berkeley) 5/28/91
|
||||
# $Id: security,v 1.8.4.2 1996/06/05 02:36:37 jkh Exp $
|
||||
# $Id: security,v 1.8.4.3 1996/06/17 09:17:12 jkh Exp $
|
||||
#
|
||||
PATH=/sbin:/bin:/usr/bin
|
||||
LC_ALL=C; export LC_ALL
|
||||
@@ -10,7 +10,7 @@ host=`hostname -s`
|
||||
echo "Subject: $host security check output"
|
||||
|
||||
LOG=/var/log
|
||||
TMP=/tmp/_secure.$$
|
||||
TMP=/var/run/_secure.$$
|
||||
|
||||
umask 027
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Really quick and evil Makefile for building all the tests. I wish that bmake was friendlier to
|
||||
# the concept of multiple progs/libs in the same directory.
|
||||
# $Id: Makefile,v 1.1.2.1 1996/01/02 06:42:45 jkh Exp $
|
||||
# $Id$
|
||||
|
||||
PROGS= msg yesno prgbox gauge dselect fselect text menu1 menu2 menu3 \
|
||||
input1 check1 check2 check3 radio1 radio2 radio3
|
||||
input1 input2 check1 check2 check3 radio1 radio2 radio3
|
||||
|
||||
CFLAGS+= -Wall -Wstrict-prototypes
|
||||
LDFLAGS += -ldialog -lncurses -lmytinfo
|
||||
@@ -13,55 +13,4 @@ all: ${PROGS}
|
||||
clean:
|
||||
rm -f ${PROGS}
|
||||
|
||||
msg: ${.CURDIR}/msg.c
|
||||
${CC} ${.CURDIR}/msg.c -o msg ${LDFLAGS}
|
||||
|
||||
yesno: ${.CURDIR}/yesno.c
|
||||
${CC} ${.CURDIR}/yesno.c -o yesno ${LDFLAGS}
|
||||
|
||||
prgbox: ${.CURDIR}/prgbox.c
|
||||
${CC} ${.CURDIR}/prgbox.c -o prgbox ${LDFLAGS}
|
||||
|
||||
gauge: ${.CURDIR}/gauge.c
|
||||
${CC} ${.CURDIR}/gauge.c -o gauge ${LDFLAGS}
|
||||
|
||||
dselect: ${.CURDIR}/dselect.c
|
||||
${CC} ${.CURDIR}/dselect.c -o dselect ${LDFLAGS}
|
||||
|
||||
fselect: ${.CURDIR}/fselect.c
|
||||
${CC} ${.CURDIR}/fselect.c -o fselect ${LDFLAGS}
|
||||
|
||||
text: ${.CURDIR}/text.c
|
||||
${CC} ${.CURDIR}/text.c -o text ${LDFLAGS}
|
||||
|
||||
menu1: ${.CURDIR}/menu1.c
|
||||
${CC} ${.CURDIR}/menu1.c -o menu1 ${LDFLAGS}
|
||||
|
||||
menu2: ${.CURDIR}/menu2.c
|
||||
${CC} ${.CURDIR}/menu2.c -o menu2 ${LDFLAGS}
|
||||
|
||||
menu3: ${.CURDIR}/menu3.c
|
||||
${CC} ${.CURDIR}/menu3.c -o menu3 ${LDFLAGS}
|
||||
|
||||
input1: ${.CURDIR}/input1.c
|
||||
${CC} ${.CURDIR}/input1.c -o input1 ${LDFLAGS}
|
||||
|
||||
check1: ${.CURDIR}/check1.c
|
||||
${CC} ${.CURDIR}/check1.c -o check1 ${LDFLAGS}
|
||||
|
||||
check2: ${.CURDIR}/check2.c
|
||||
${CC} ${.CURDIR}/check2.c -o check2 ${LDFLAGS}
|
||||
|
||||
check3: ${.CURDIR}/check3.c
|
||||
${CC} ${.CURDIR}/check3.c -o check3 ${LDFLAGS}
|
||||
|
||||
radio1: ${.CURDIR}/radio1.c
|
||||
${CC} ${.CURDIR}/radio1.c -o radio1 ${LDFLAGS}
|
||||
|
||||
radio2: ${.CURDIR}/radio2.c
|
||||
${CC} ${.CURDIR}/radio2.c -o radio2 ${LDFLAGS}
|
||||
|
||||
radio3: ${.CURDIR}/radio3.c
|
||||
${CC} ${.CURDIR}/radio3.c -o radio3 ${LDFLAGS}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* small test-driver for new dialog functionality
|
||||
*
|
||||
* Copyright (c) 1995, Jordan Hubbard
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code may be used, modified, copied, distributed, and
|
||||
* sold, in both source and binary form provided that the above
|
||||
* copyright and these terms are retained, verbatim, as the first
|
||||
* lines of this file. Under no circumstances is the author
|
||||
* responsible for the proper functioning of the software nor does
|
||||
* the author assume any responsibility for damages incurred with
|
||||
* its use.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <dialog.h>
|
||||
|
||||
/* Kick it off, James! */
|
||||
int
|
||||
main(int argc, unsigned char *argv[])
|
||||
{
|
||||
int retval;
|
||||
unsigned char result[128];
|
||||
|
||||
init_dialog();
|
||||
|
||||
result[0]='\0';
|
||||
DialogInputAttrs |= DITEM_NO_ECHO;
|
||||
retval = dialog_inputbox("this is dialog_inputbox() in action, test #2 (no echo)",
|
||||
"Enter something really secret below, please.",
|
||||
-1, -1, result);
|
||||
DialogInputAttrs &= DITEM_NO_ECHO;
|
||||
dialog_clear();
|
||||
fprintf(stderr, "returned value for dialog_inputbox was %d (%s)\n", retval, result);
|
||||
|
||||
end_dialog();
|
||||
return 0;
|
||||
}
|
||||
@@ -40,9 +40,10 @@ int
|
||||
dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width,
|
||||
int list_height, int cnt, void *it, unsigned char *result)
|
||||
{
|
||||
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
|
||||
l, k, scroll = 0, max_choice, item_no = 0, *status;
|
||||
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice,
|
||||
l, k, scroll, max_choice, item_no = 0, *status;
|
||||
int redraw_menu = FALSE;
|
||||
int rval = 0;
|
||||
char okButton, cancelButton;
|
||||
WINDOW *dialog, *list;
|
||||
unsigned char **items = NULL;
|
||||
@@ -56,6 +57,7 @@ dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int wi
|
||||
}
|
||||
|
||||
draw:
|
||||
choice = scroll = button = 0;
|
||||
/* Previous calling syntax, e.g. just a list of strings? */
|
||||
if (cnt >= 0) {
|
||||
items = it;
|
||||
@@ -170,14 +172,14 @@ draw:
|
||||
|
||||
/* Print the list */
|
||||
for (i = 0; i < max_choice; i++)
|
||||
print_item(list, items[i*3], items[i*3 + 1], status[i], i, i == choice, DREF(ditems, i));
|
||||
print_item(list, items[i * 3], items[i * 3 + 1], status[i], i, i == choice, DREF(ditems, i));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
|
||||
display_helpline(dialog, height-1, width);
|
||||
display_helpline(dialog, height - 1, width);
|
||||
|
||||
x = width/2-11;
|
||||
y = height-2;
|
||||
x = width / 2 - 11;
|
||||
y = height - 2;
|
||||
/* Is this a fancy new style argument string where we get to override
|
||||
* the buttons, or an old style one where they're fixed?
|
||||
*/
|
||||
@@ -225,12 +227,13 @@ draw:
|
||||
}
|
||||
}
|
||||
}
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
return 0;
|
||||
rval = 0;
|
||||
key = ESC; /* Lemme out! */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Shortcut to cancel? */
|
||||
else if (toupper(key) == cancelButton) {
|
||||
if (toupper(key) == cancelButton) {
|
||||
if (ditems && result && ditems[CANCEL_BUTTON].fire) {
|
||||
int st;
|
||||
WINDOW *save;
|
||||
@@ -244,9 +247,9 @@ draw:
|
||||
}
|
||||
delwin(save);
|
||||
}
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
return 1;
|
||||
rval = 1;
|
||||
key = ESC; /* I gotta go! */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if key pressed matches first character of any item tag in list */
|
||||
@@ -254,26 +257,28 @@ draw:
|
||||
if (key < 0x100 && toupper(key) == toupper(items[(scroll+i)*3][0]))
|
||||
break;
|
||||
|
||||
if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) || key == KEY_UP ||
|
||||
key == KEY_DOWN || key == ' ' || key == '+' || key == '-' ) {
|
||||
if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) ||
|
||||
KEY_IS_UP(key) || KEY_IS_DOWN(key) || key == ' ') {
|
||||
|
||||
if (key >= '1' && key <= MIN('9', '0'+max_choice))
|
||||
i = key - '1';
|
||||
|
||||
else if (key == KEY_UP || key == '-') {
|
||||
else if (KEY_IS_UP(key)) {
|
||||
if (!choice) {
|
||||
if (scroll) {
|
||||
/* Scroll list down */
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
if (list_height > 1) {
|
||||
/* De-highlight current first item before scrolling down */
|
||||
print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0, FALSE, DREF(ditems, scroll));
|
||||
print_item(list, items[scroll * 3], items[scroll * 3 + 1], status[scroll], 0,
|
||||
FALSE, DREF(ditems, scroll));
|
||||
scrollok(list, TRUE);
|
||||
wscrl(list, -1);
|
||||
scrollok(list, FALSE);
|
||||
}
|
||||
scroll--;
|
||||
print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0, TRUE, DREF(ditems, scroll));
|
||||
print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0,
|
||||
TRUE, DREF(ditems, scroll));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
@@ -283,22 +288,26 @@ draw:
|
||||
else
|
||||
i = choice - 1;
|
||||
}
|
||||
else if (key == KEY_DOWN || key == '+') {
|
||||
else if (KEY_IS_DOWN(key)) {
|
||||
if (choice == max_choice - 1) {
|
||||
if (scroll+choice < item_no-1) {
|
||||
if (scroll + choice < item_no - 1) {
|
||||
/* Scroll list up */
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
if (list_height > 1) {
|
||||
/* De-highlight current last item before scrolling up */
|
||||
print_item(list, items[(scroll+max_choice-1)*3], items[(scroll+max_choice-1)*3 + 1],
|
||||
status[scroll+max_choice-1], max_choice-1, FALSE, DREF(ditems, scroll + max_choice - 1));
|
||||
print_item(list, items[(scroll + max_choice - 1) * 3],
|
||||
items[(scroll + max_choice - 1) * 3 + 1],
|
||||
status[scroll + max_choice - 1], max_choice - 1,
|
||||
FALSE, DREF(ditems, scroll + max_choice - 1));
|
||||
scrollok(list, TRUE);
|
||||
scroll(list);
|
||||
scrollok(list, FALSE);
|
||||
}
|
||||
scroll++;
|
||||
print_item(list, items[(scroll+max_choice-1)*3], items[(scroll+max_choice-1)*3 + 1],
|
||||
status[scroll+max_choice-1], max_choice-1, TRUE, DREF(ditems, scroll + max_choice - 1));
|
||||
print_item(list, items[(scroll + max_choice - 1) * 3],
|
||||
items[(scroll + max_choice - 1) * 3 + 1],
|
||||
status[scroll + max_choice - 1], max_choice - 1, TRUE,
|
||||
DREF(ditems, scroll + max_choice - 1));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
@@ -317,13 +326,14 @@ draw:
|
||||
WINDOW *save;
|
||||
|
||||
save = dupwin(newscr);
|
||||
st = ditems[scroll + choice].fire(&ditems[scroll + choice]);
|
||||
st = ditems[scroll + choice].fire(&ditems[scroll + choice]); /* Call "fire" action */
|
||||
if (st & DITEM_RESTORE) {
|
||||
touchwin(save);
|
||||
wrefresh(save);
|
||||
}
|
||||
delwin(save);
|
||||
if (st & DITEM_REDRAW) {
|
||||
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */
|
||||
wclear(list);
|
||||
for (i = 0; i < item_no; i++)
|
||||
status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE;
|
||||
for (i = 0; i < max_choice; i++) {
|
||||
@@ -335,10 +345,10 @@ draw:
|
||||
cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
}
|
||||
delwin(save);
|
||||
if (st & DITEM_LEAVE_MENU) {
|
||||
/* Allow a fire action to take us out of the menu */
|
||||
key = ESC;
|
||||
rval = 0;
|
||||
break;
|
||||
}
|
||||
else if (st & DITEM_RECREATE) {
|
||||
@@ -365,7 +375,7 @@ draw:
|
||||
rbra = ']';
|
||||
if (!mark)
|
||||
mark = 'X';
|
||||
wprintw(list, "%c%c%c", lbra, status[scroll+choice] ? mark : ' ', rbra);
|
||||
wprintw(list, "%c%c%c", lbra, status[scroll + choice] ? mark : ' ', rbra);
|
||||
wnoutrefresh(list);
|
||||
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */
|
||||
wrefresh(dialog);
|
||||
@@ -375,13 +385,13 @@ draw:
|
||||
if (i != choice) {
|
||||
/* De-highlight current item */
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
print_item(list, items[(scroll+choice)*3], items[(scroll+choice)*3 + 1], status[scroll+choice], choice, FALSE,
|
||||
DREF(ditems, scroll + choice));
|
||||
print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1],
|
||||
status[scroll + choice], choice, FALSE, DREF(ditems, scroll + choice));
|
||||
|
||||
/* Highlight new item */
|
||||
choice = i;
|
||||
print_item(list, items[(scroll+choice)*3], items[(scroll+choice)*3 + 1], status[scroll+choice], choice, TRUE,
|
||||
DREF(ditems, scroll + choice));
|
||||
print_item(list, items[(scroll + choice) * 3], items[(scroll + choice) * 3 + 1],
|
||||
status[scroll + choice], choice, TRUE, DREF(ditems, scroll + choice));
|
||||
wnoutrefresh(list);
|
||||
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */
|
||||
wrefresh(dialog);
|
||||
@@ -469,26 +479,27 @@ draw:
|
||||
}
|
||||
}
|
||||
}
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
return button;
|
||||
rval = button;
|
||||
key = ESC; /* Bail out! */
|
||||
break;
|
||||
|
||||
/* Let me outta here! */
|
||||
case ESC:
|
||||
rval = -1;
|
||||
break;
|
||||
|
||||
/* Help! */
|
||||
case KEY_F(1):
|
||||
case '?':
|
||||
display_helpfile();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (redraw_menu) {
|
||||
wclear(list);
|
||||
for (i = 0; i < max_choice; i++)
|
||||
print_item(list, items[(scroll+i)*3], items[(scroll+i)*3 + 1], status[scroll+i], i, i == choice,
|
||||
DREF(ditems, scroll + i));
|
||||
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i],
|
||||
i, i == choice, DREF(ditems, scroll + i));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
@@ -497,9 +508,8 @@ draw:
|
||||
}
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
return -1; /* ESC pressed */
|
||||
return rval;
|
||||
}
|
||||
/* End of dialog_checklist() */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
#define DITEM_RESTORE (1 << 19)
|
||||
#define DITEM_CONTINUE (1 << 20)
|
||||
|
||||
/* Attributes as used by entry fields right now */
|
||||
#define DITEM_NO_ECHO 0x0001
|
||||
|
||||
|
||||
/* negative offsets for buttons in item lists, if specified */
|
||||
#define OK_BUTTON -2
|
||||
@@ -77,7 +80,7 @@ typedef struct _dmenu_item {
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
|
||||
extern int DialogX, DialogY;
|
||||
extern int DialogX, DialogY, DialogInputAttrs;
|
||||
|
||||
/*
|
||||
* Attribute names
|
||||
@@ -122,7 +125,7 @@ extern bool use_shadow;
|
||||
void draw_shadow(WINDOW *win, int y, int x, int height, int width);
|
||||
#endif
|
||||
void draw_box(WINDOW *win, int y, int x, int height, int width, chtype box, chtype border);
|
||||
int line_edit(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, chtype attrs, int first, unsigned char *result);
|
||||
int line_edit(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, chtype attrs, int first, unsigned char *result, int attr_mask);
|
||||
int strheight(const char *p);
|
||||
int strwidth(const char *p);
|
||||
|
||||
|
||||
@@ -85,6 +85,10 @@
|
||||
#endif
|
||||
#endif /* HAVE_NCURSES */
|
||||
|
||||
/* Travel key conventions */
|
||||
#define KEY_IS_UP(key) ((key) == KEY_UP || (key) == '-' || key == '\020' /* ^P */)
|
||||
#define KEY_IS_DOWN(key) ((key) == KEY_DOWN || (key) == '+' || key == '\016' /* ^N */)
|
||||
|
||||
/*
|
||||
* Global variables
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Program: dir.c
|
||||
@@ -22,20 +21,21 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if !defined sgi
|
||||
#include <unistd.h> /* XXX for _POSIX_VERSION ifdefs */
|
||||
|
||||
#if !defined sgi && !defined _POSIX_VERSION
|
||||
#include <sys/dir.h>
|
||||
#endif
|
||||
#if defined __sun__
|
||||
#include <sys/dirent.h>
|
||||
#endif
|
||||
#if defined sgi
|
||||
#if defined sgi || defined _POSIX_VERSION
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fnmatch.h>
|
||||
#include <sys/param.h>
|
||||
#include "dir.h"
|
||||
|
||||
@@ -106,7 +106,7 @@ int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int
|
||||
while (key != ESC) {
|
||||
|
||||
if (button == -1) { /* Input box selected */
|
||||
key = line_edit(dialog, box_y, box_x, -1, box_width, inputbox_attr, first, instr);
|
||||
key = line_edit(dialog, box_y, box_x, -1, box_width, inputbox_attr, first, instr, DialogInputAttrs);
|
||||
first = 0;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -90,6 +90,9 @@
|
||||
*/
|
||||
int DialogX, DialogY;
|
||||
|
||||
/* This "secret" global allows you to change the behavior of an input field */
|
||||
int DialogInputAttrs;
|
||||
|
||||
/*
|
||||
* Do some initialization for dialog
|
||||
*/
|
||||
@@ -328,14 +331,12 @@ void print_button(WINDOW *win, unsigned char *label, int y, int x, int selected)
|
||||
waddstr(win, selected ? "[" : " ");
|
||||
temp = strspn(label, " ");
|
||||
label += temp;
|
||||
wattrset(win, selected ? button_label_active_attr : button_label_inactive_attr);
|
||||
for (i = 0; i < temp; i++)
|
||||
waddch(win, ' ');
|
||||
wattrset(win, selected ? button_key_active_attr : button_key_inactive_attr);
|
||||
waddch(win, label[0]);
|
||||
wattrset(win, selected ? button_label_active_attr : button_label_inactive_attr);
|
||||
waddstr(win, label+1);
|
||||
wattrset(win, selected ? button_active_attr : button_inactive_attr);
|
||||
waddstr(win, label+1);
|
||||
waddstr(win, selected ? "]" : " ");
|
||||
wmove(win, y, x+temp+1);
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
#include <dialog.h>
|
||||
#include "dialog.priv.h"
|
||||
|
||||
static void redraw_field(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, unsigned char instr[], int input_x, int scroll, chtype attr, chtype old_attr, int fexit);
|
||||
static void redraw_field(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, unsigned char instr[], int input_x, int scroll, chtype attr, chtype old_attr, int fexit, int attr_mask);
|
||||
|
||||
/*
|
||||
* Line editor
|
||||
*/
|
||||
int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, chtype attr, int first, unsigned char *result)
|
||||
int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, chtype attr, int first, unsigned char *result, int attr_mask)
|
||||
{
|
||||
int i, key;
|
||||
chtype old_attr;
|
||||
@@ -53,7 +53,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
/* scroll = i - input_x;*/
|
||||
scroll = (i > box_width) ? i - box_width + 1: 0;
|
||||
}
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
|
||||
for (;;) {
|
||||
wattrset(dialog, attr);
|
||||
@@ -86,12 +86,12 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
case '\013':
|
||||
case KEY_EOL:
|
||||
memset(instr + scroll + input_x, '\0', sizeof(instr) - scroll - input_x);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
continue;
|
||||
case '\001':
|
||||
case KEY_HOME:
|
||||
input_x = scroll = 0;
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
continue;
|
||||
case '\005':
|
||||
case KEY_END:
|
||||
@@ -100,7 +100,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
i++;
|
||||
input_x = i % box_width;
|
||||
scroll = i - input_x;
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
continue;
|
||||
case '\002':
|
||||
case KEY_LEFT:
|
||||
@@ -109,7 +109,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
int oldscroll = scroll;
|
||||
scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1);
|
||||
input_x = oldscroll - 1 - scroll;
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
} else {
|
||||
input_x--;
|
||||
wmove(dialog, box_y, input_x + box_x);
|
||||
@@ -126,7 +126,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
instr[scroll+input_x] = ' ';
|
||||
if (input_x == box_width-1) {
|
||||
scroll++;
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
}
|
||||
else {
|
||||
wmove(dialog, box_y, input_x + box_x);
|
||||
@@ -149,7 +149,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
input_x = oldscroll - 1 - scroll;
|
||||
} else
|
||||
input_x--;
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
} else
|
||||
beep();
|
||||
continue;
|
||||
@@ -163,7 +163,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
continue;
|
||||
}
|
||||
memmove(instr+scroll+input_x, instr+scroll+input_x+1, i-(scroll+input_x));
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
continue;
|
||||
default:
|
||||
if (CCEQ(key, erase_char))
|
||||
@@ -182,7 +182,7 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
scroll++;
|
||||
else
|
||||
input_x++;
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, FALSE, attr_mask);
|
||||
} else
|
||||
beep(); /* Alarm user about overflow */
|
||||
continue;
|
||||
@@ -190,14 +190,14 @@ int line_edit(WINDOW* dialog, int box_y, int box_x, int flen, int box_width, cht
|
||||
}
|
||||
}
|
||||
ret:
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, TRUE);
|
||||
redraw_field(dialog, box_y, box_x, flen, box_width, instr, input_x, scroll, attr, old_attr, TRUE, attr_mask);
|
||||
wrefresh(dialog);
|
||||
strcpy(result, instr);
|
||||
return key;
|
||||
}
|
||||
|
||||
static void
|
||||
redraw_field(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, unsigned char instr[], int input_x, int scroll, chtype attr, chtype old_attr, int fexit)
|
||||
redraw_field(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, unsigned char instr[], int input_x, int scroll, chtype attr, chtype old_attr, int fexit, int attr_mask)
|
||||
{
|
||||
int i, fix_len;
|
||||
|
||||
@@ -205,9 +205,9 @@ redraw_field(WINDOW *dialog, int box_y, int box_x, int flen, int box_width, unsi
|
||||
wmove(dialog, box_y, box_x);
|
||||
fix_len = flen >= 0 ? MIN(flen-scroll,box_width) : box_width;
|
||||
for (i = 0; i < fix_len; i++)
|
||||
waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' ');
|
||||
waddch(dialog, instr[scroll+i] ? ((attr_mask & DITEM_NO_ECHO) ? '*' : instr[scroll+i]) : ' ');
|
||||
wattrset(dialog, old_attr);
|
||||
for ( ; i < box_width; i++)
|
||||
waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' ');
|
||||
waddch(dialog, instr[scroll+i] ? ((attr_mask & DITEM_NO_ECHO) ? '*' : instr[scroll+i]) : ' ');
|
||||
wmove(dialog, box_y, input_x + box_x);
|
||||
}
|
||||
+74
-65
@@ -39,18 +39,18 @@ int
|
||||
dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height,
|
||||
int cnt, void *it, unsigned char *result, int *ch, int *sc)
|
||||
{
|
||||
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
|
||||
l, k, scroll = 0, max_choice, item_no, redraw_menu = FALSE;
|
||||
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice,
|
||||
l, k, scroll, max_choice, item_no, redraw_menu = FALSE;
|
||||
char okButton, cancelButton;
|
||||
int rval = 0;
|
||||
WINDOW *dialog, *menu;
|
||||
unsigned char **items = NULL;
|
||||
dialogMenuItem *ditems;
|
||||
|
||||
draw:
|
||||
if (ch) /* restore menu item info */
|
||||
choice = *ch;
|
||||
if (sc)
|
||||
scroll = *sc;
|
||||
choice = ch ? *ch : 0;
|
||||
scroll = sc ? *sc : 0;
|
||||
button = 0;
|
||||
|
||||
/* If item_no is a positive integer, use old item specification format */
|
||||
if (cnt >= 0) {
|
||||
@@ -77,30 +77,30 @@ draw:
|
||||
item_x = 0;
|
||||
/* Find length of longest item in order to center menu */
|
||||
for (i = 0; i < item_no; i++) {
|
||||
l = strlen(items[i*2]);
|
||||
l = strlen(items[i * 2]);
|
||||
for (j = 0; j < item_no; j++) {
|
||||
k = strlen(items[j*2 + 1]);
|
||||
k = strlen(items[j * 2 + 1]);
|
||||
tag_x = MAX(tag_x, l + k + 2);
|
||||
}
|
||||
item_x = MAX(item_x, l);
|
||||
}
|
||||
if (height < 0)
|
||||
height = strheight(prompt)+menu_height+4+2;
|
||||
height = strheight(prompt) + menu_height + 4 + 2;
|
||||
if (width < 0) {
|
||||
i = strwidth(prompt);
|
||||
j = ((title != NULL) ? strwidth(title) : 0);
|
||||
width = MAX(i,j);
|
||||
width = MAX(width,tag_x+4)+4;
|
||||
width = MAX(i, j);
|
||||
width = MAX(width, tag_x + 4) + 4;
|
||||
}
|
||||
width = MAX(width,24);
|
||||
width = MAX(width, 24);
|
||||
|
||||
if (width > COLS)
|
||||
width = COLS;
|
||||
if (height > LINES)
|
||||
height = LINES;
|
||||
/* center dialog box on screen */
|
||||
x = DialogX ? DialogX : (COLS - width)/2;
|
||||
y = DialogY ? DialogY : (LINES - height)/2;
|
||||
x = DialogX ? DialogX : (COLS - width) / 2;
|
||||
y = DialogY ? DialogY : (LINES - height) / 2;
|
||||
|
||||
#ifdef HAVE_NCURSES
|
||||
if (use_shadow)
|
||||
@@ -109,45 +109,46 @@ draw:
|
||||
dialog = newwin(height, width, y, x);
|
||||
if (dialog == NULL) {
|
||||
endwin();
|
||||
fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height,width,y,x);
|
||||
fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height, width, y, x);
|
||||
return -1;
|
||||
}
|
||||
keypad(dialog, TRUE);
|
||||
|
||||
draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
|
||||
wattrset(dialog, border_attr);
|
||||
wmove(dialog, height-3, 0);
|
||||
wmove(dialog, height - 3, 0);
|
||||
waddch(dialog, ACS_LTEE);
|
||||
for (i = 0; i < width-2; i++)
|
||||
for (i = 0; i < width - 2; i++)
|
||||
waddch(dialog, ACS_HLINE);
|
||||
wattrset(dialog, dialog_attr);
|
||||
waddch(dialog, ACS_RTEE);
|
||||
wmove(dialog, height-2, 1);
|
||||
for (i = 0; i < width-2; i++)
|
||||
wmove(dialog, height - 2, 1);
|
||||
for (i = 0; i < width - 2; i++)
|
||||
waddch(dialog, ' ');
|
||||
|
||||
if (title != NULL) {
|
||||
wattrset(dialog, title_attr);
|
||||
wmove(dialog, 0, (width - strlen(title))/2 - 1);
|
||||
wmove(dialog, 0, (width - strlen(title)) / 2 - 1);
|
||||
waddch(dialog, ' ');
|
||||
waddstr(dialog, title);
|
||||
waddch(dialog, ' ');
|
||||
}
|
||||
wattrset(dialog, dialog_attr);
|
||||
wmove(dialog, 1, 2);
|
||||
print_autowrap(dialog, prompt, height-1, width-2, width, 1, 2, TRUE, FALSE);
|
||||
print_autowrap(dialog, prompt, height - 1, width - 2, width, 1, 2, TRUE, FALSE);
|
||||
|
||||
menu_width = width-6;
|
||||
menu_width = width - 6;
|
||||
getyx(dialog, cur_y, cur_x);
|
||||
box_y = cur_y + 1;
|
||||
box_x = (width - menu_width)/2 - 1;
|
||||
box_x = (width - menu_width) / 2 - 1;
|
||||
|
||||
/* create new window for the menu */
|
||||
menu = subwin(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1);
|
||||
if (menu == NULL) {
|
||||
delwin(dialog);
|
||||
endwin();
|
||||
fprintf(stderr, "\nsubwin(dialog,%d,%d,%d,%d) failed, maybe wrong dims\n", menu_height,menu_width,y+box_y+1,x+box_x+1);
|
||||
fprintf(stderr, "\nsubwin(dialog,%d,%d,%d,%d) failed, maybe wrong dims\n", menu_height, menu_width,
|
||||
y + box_y + 1, x + box_x + 1);
|
||||
return -1;
|
||||
}
|
||||
keypad(menu, TRUE);
|
||||
@@ -160,14 +161,15 @@ draw:
|
||||
|
||||
/* Print the menu */
|
||||
for (i = 0; i < max_choice; i++)
|
||||
print_item(menu, items[(scroll+i)*2], items[(scroll+i)*2 + 1], i, i == choice, DREF(ditems, scroll + i));
|
||||
print_item(menu, items[(scroll + i) * 2], items[(scroll + i) * 2 + 1], i,
|
||||
i == choice, DREF(ditems, scroll + i));
|
||||
wnoutrefresh(menu);
|
||||
print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y);
|
||||
|
||||
display_helpline(dialog, height-1, width);
|
||||
display_helpline(dialog, height - 1, width);
|
||||
|
||||
x = width/2-11;
|
||||
y = height-2;
|
||||
x = width / 2 - 11;
|
||||
y = height - 2;
|
||||
|
||||
if (ditems && result) {
|
||||
cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]);
|
||||
@@ -185,7 +187,6 @@ draw:
|
||||
}
|
||||
|
||||
wrefresh(dialog);
|
||||
|
||||
while (key != ESC) {
|
||||
key = wgetch(dialog);
|
||||
|
||||
@@ -207,12 +208,13 @@ draw:
|
||||
}
|
||||
else if (result)
|
||||
strcpy(result, items[(scroll + choice) * 2]);
|
||||
delwin(menu);
|
||||
delwin(dialog);
|
||||
return 0;
|
||||
rval = 0;
|
||||
key = ESC; /* Punt! */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Shortcut to cancel? */
|
||||
else if (toupper(key) == cancelButton) {
|
||||
if (toupper(key) == cancelButton) {
|
||||
if (ditems && result && ditems[CANCEL_BUTTON].fire) {
|
||||
int status;
|
||||
WINDOW *save;
|
||||
@@ -225,34 +227,33 @@ draw:
|
||||
}
|
||||
delwin(save);
|
||||
}
|
||||
delwin(menu);
|
||||
delwin(dialog);
|
||||
return 1;
|
||||
rval = 1;
|
||||
key = ESC; /* Run away! */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Check if key pressed matches first character of any item tag in menu */
|
||||
for (i = 0; i < max_choice; i++)
|
||||
if (key < 0x100 && toupper(key) == toupper(items[(scroll+i)*2][0]))
|
||||
if (key < 0x100 && toupper(key) == toupper(items[(scroll + i) * 2][0]))
|
||||
break;
|
||||
|
||||
if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) ||
|
||||
key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+') {
|
||||
if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) || KEY_IS_UP(key) || KEY_IS_DOWN(key)) {
|
||||
if (key >= '1' && key <= MIN('9', '0'+max_choice))
|
||||
i = key - '1';
|
||||
else if (key == KEY_UP || key == '-') {
|
||||
else if (KEY_IS_UP(key)) {
|
||||
if (!choice) {
|
||||
if (scroll) {
|
||||
/* Scroll menu down */
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
if (menu_height > 1) {
|
||||
/* De-highlight current first item before scrolling down */
|
||||
print_item(menu, items[scroll*2], items[scroll*2 + 1], 0, FALSE, DREF(ditems, scroll));
|
||||
print_item(menu, items[scroll * 2], items[scroll * 2 + 1], 0, FALSE, DREF(ditems, scroll));
|
||||
scrollok(menu, TRUE);
|
||||
wscrl(menu, -1);
|
||||
scrollok(menu, FALSE);
|
||||
}
|
||||
scroll--;
|
||||
print_item(menu, items[scroll*2], items[scroll*2 + 1], 0, TRUE, DREF(ditems, scroll));
|
||||
print_item(menu, items[scroll * 2], items[scroll * 2 + 1], 0, TRUE, DREF(ditems, scroll));
|
||||
wnoutrefresh(menu);
|
||||
print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
@@ -262,21 +263,23 @@ draw:
|
||||
else
|
||||
i = choice - 1;
|
||||
}
|
||||
else if (key == KEY_DOWN || key == '+')
|
||||
else if (KEY_IS_DOWN(key))
|
||||
if (choice == max_choice - 1) {
|
||||
if (scroll+choice < item_no-1) {
|
||||
if (scroll + choice < item_no - 1) {
|
||||
/* Scroll menu up */
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
if (menu_height > 1) {
|
||||
/* De-highlight current last item before scrolling up */
|
||||
print_item(menu, items[(scroll + max_choice - 1) * 2], items[(scroll + max_choice - 1) * 2 + 1],
|
||||
print_item(menu, items[(scroll + max_choice - 1) * 2],
|
||||
items[(scroll + max_choice - 1) * 2 + 1],
|
||||
max_choice-1, FALSE, DREF(ditems, scroll + max_choice - 1));
|
||||
scrollok(menu, TRUE);
|
||||
scroll(menu);
|
||||
scrollok(menu, FALSE);
|
||||
}
|
||||
scroll++;
|
||||
print_item(menu, items[(scroll + max_choice - 1) * 2], items[(scroll + max_choice - 1) * 2 + 1],
|
||||
print_item(menu, items[(scroll + max_choice - 1) * 2],
|
||||
items[(scroll + max_choice - 1) * 2 + 1],
|
||||
max_choice - 1, TRUE, DREF(ditems, scroll + max_choice - 1));
|
||||
wnoutrefresh(menu);
|
||||
print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y);
|
||||
@@ -304,16 +307,10 @@ draw:
|
||||
continue; /* wait for another key press */
|
||||
}
|
||||
|
||||
/* save info about menu item position */
|
||||
if (ch)
|
||||
*ch = choice;
|
||||
if (sc)
|
||||
*sc = scroll;
|
||||
|
||||
switch (key) {
|
||||
case KEY_PPAGE:
|
||||
if (scroll > height-4) { /* can we go up? */
|
||||
scroll -= (height-4);
|
||||
if (scroll > height - 4) { /* can we go up? */
|
||||
scroll -= (height - 4);
|
||||
} else {
|
||||
scroll = 0;
|
||||
}
|
||||
@@ -323,7 +320,8 @@ draw:
|
||||
case KEY_NPAGE:
|
||||
if (scroll + menu_height >= item_no-1 - menu_height) { /* can we go down a full page? */
|
||||
scroll = item_no - menu_height;
|
||||
if (scroll < 0) scroll = 0;
|
||||
if (scroll < 0)
|
||||
scroll = 0;
|
||||
} else {
|
||||
scroll += menu_height;
|
||||
}
|
||||
@@ -338,7 +336,8 @@ draw:
|
||||
|
||||
case KEY_END:
|
||||
scroll = item_no - menu_height;
|
||||
if (scroll < 0) scroll = 0;
|
||||
if (scroll < 0)
|
||||
scroll = 0;
|
||||
choice = max_choice - 1;
|
||||
redraw_menu = TRUE;
|
||||
break;
|
||||
@@ -381,7 +380,12 @@ draw:
|
||||
delwin(save);
|
||||
if (status & DITEM_CONTINUE)
|
||||
continue;
|
||||
else if (status & DITEM_RECREATE && !(status & DITEM_LEAVE_MENU)) {
|
||||
else if (status & DITEM_LEAVE_MENU) {
|
||||
/* Allow a fire action to take us out of the menu */
|
||||
key = ESC;
|
||||
break;
|
||||
}
|
||||
else if (status & DITEM_RECREATE) {
|
||||
delwin(menu);
|
||||
delwin(dialog);
|
||||
dialog_clear();
|
||||
@@ -392,19 +396,26 @@ draw:
|
||||
else if (result)
|
||||
strcpy(result, items[(scroll+choice)*2]);
|
||||
}
|
||||
delwin(menu);
|
||||
delwin(dialog);
|
||||
return button;
|
||||
rval = button;
|
||||
key = ESC;
|
||||
break;
|
||||
|
||||
case ESC:
|
||||
rval = -1;
|
||||
break;
|
||||
|
||||
case KEY_F(1):
|
||||
case '?':
|
||||
display_helpfile();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
/* save info about menu item position */
|
||||
if (ch)
|
||||
*ch = choice;
|
||||
if (sc)
|
||||
*sc = scroll;
|
||||
|
||||
if (redraw_menu) {
|
||||
for (i = 0; i < max_choice; i++) {
|
||||
print_item(menu, items[(scroll + i) * 2], items[(scroll + i) * 2 + 1], i, i == choice,
|
||||
@@ -416,12 +427,10 @@ draw:
|
||||
redraw_menu = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
delwin(menu);
|
||||
delwin(dialog);
|
||||
return -1; /* ESC pressed */
|
||||
return rval;
|
||||
}
|
||||
/* End of dialog_menu() */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -93,7 +93,7 @@ int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int w
|
||||
for (i = 0; i < width-2; i++)
|
||||
waddch(dialog, ' ');
|
||||
display_helpline(dialog, height-1, width);
|
||||
print_button(dialog, " OK ", height-2, width/2-4, TRUE);
|
||||
print_button(dialog, " OK ", height-2, width/2-6, TRUE);
|
||||
wrefresh(dialog);
|
||||
while (key != ESC && key != '\n' && key != ' ' && key != '\r')
|
||||
key = wgetch(dialog);
|
||||
@@ -171,7 +171,7 @@ dialog_mesgbox(unsigned char *title, unsigned char *prompt, int height, int widt
|
||||
for (i = 0; i < width-2; i++)
|
||||
waddch(dialog, ' ');
|
||||
display_helpline(dialog, height-1, width);
|
||||
print_button(dialog, " CONTINUE ", height-2, width/2-8, TRUE);
|
||||
print_button(dialog, " OK ", height-2, width/2-6, TRUE);
|
||||
wattrset(dialog, dialog_attr);
|
||||
|
||||
theight = height - 4;
|
||||
@@ -193,9 +193,11 @@ dialog_mesgbox(unsigned char *title, unsigned char *prompt, int height, int widt
|
||||
startline = max_lines - theight;
|
||||
if (startline < 0) startline = 0;
|
||||
break;
|
||||
case '\020': /* ^P */
|
||||
case KEY_UP:
|
||||
if (startline > 0) startline--;
|
||||
break;
|
||||
case '\016': /* ^N */
|
||||
case KEY_DOWN:
|
||||
if (startline < max_lines - theight) startline++;
|
||||
break;
|
||||
|
||||
@@ -130,7 +130,7 @@ int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, i
|
||||
for (i = 0; i < width-2; i++)
|
||||
waddch(dialog, ' ');
|
||||
display_helpline(dialog, height-1, width);
|
||||
print_button(dialog, " OK ", height-2, width/2-4, TRUE);
|
||||
print_button(dialog, " OK ", height-2, width/2-6, TRUE);
|
||||
wrefresh(dialog);
|
||||
while (key != ESC && key != '\n' && key != ' ' && key != '\r')
|
||||
key = wgetch(dialog);
|
||||
|
||||
@@ -40,9 +40,10 @@ int
|
||||
dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height,
|
||||
int cnt, void *it, unsigned char *result)
|
||||
{
|
||||
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
|
||||
l, k, scroll = 0, max_choice, *status, item_no = 0, was_on = 0;
|
||||
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button, choice,
|
||||
l, k, scroll, max_choice, *status, item_no = 0, was_on = 0;
|
||||
int redraw_menu = FALSE;
|
||||
int rval = 0;
|
||||
char okButton, cancelButton;
|
||||
WINDOW *dialog, *list;
|
||||
unsigned char **items = NULL;
|
||||
@@ -56,6 +57,7 @@ dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int wi
|
||||
}
|
||||
|
||||
draw:
|
||||
button = choice = scroll = 0;
|
||||
/* Previous calling syntax, e.g. just a list of strings? */
|
||||
if (cnt >= 0) {
|
||||
items = it;
|
||||
@@ -98,30 +100,30 @@ draw:
|
||||
item_x = 0;
|
||||
/* Find length of longest item in order to center radiolist */
|
||||
for (i = 0; i < item_no; i++) {
|
||||
l = strlen(items[i*3]);
|
||||
l = strlen(items[i * 3]);
|
||||
for (j = 0; j < item_no; j++) {
|
||||
k = strlen(items[j*3 + 1]);
|
||||
k = strlen(items[j * 3 + 1]);
|
||||
check_x = MAX(check_x, l + k + 6);
|
||||
}
|
||||
item_x = MAX(item_x, l);
|
||||
}
|
||||
if (height < 0)
|
||||
height = strheight(prompt)+list_height+4+2;
|
||||
height = strheight(prompt) + list_height + 4 + 2;
|
||||
if (width < 0) {
|
||||
i = strwidth(prompt);
|
||||
j = ((title != NULL) ? strwidth(title) : 0);
|
||||
width = MAX(i,j);
|
||||
width = MAX(width,check_x+4)+4;
|
||||
width = MAX(i, j);
|
||||
width = MAX(width, check_x + 4) + 4;
|
||||
}
|
||||
width = MAX(width,24);
|
||||
width = MAX(width, 24);
|
||||
|
||||
if (width > COLS)
|
||||
width = COLS;
|
||||
if (height > LINES)
|
||||
height = LINES;
|
||||
/* center dialog box on screen */
|
||||
x = DialogX ? DialogX : (COLS - width)/2;
|
||||
y = DialogY ? DialogY : (LINES - height)/2;
|
||||
x = DialogX ? DialogX : (COLS - width) / 2;
|
||||
y = DialogY ? DialogY : (LINES - height) / 2;
|
||||
|
||||
#ifdef HAVE_NCURSES
|
||||
if (use_shadow)
|
||||
@@ -130,45 +132,46 @@ draw:
|
||||
dialog = newwin(height, width, y, x);
|
||||
if (dialog == NULL) {
|
||||
endwin();
|
||||
fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height,width,y,x);
|
||||
fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height, width, y, x);
|
||||
return -1;
|
||||
}
|
||||
keypad(dialog, TRUE);
|
||||
|
||||
draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
|
||||
wattrset(dialog, border_attr);
|
||||
wmove(dialog, height-3, 0);
|
||||
wmove(dialog, height - 3, 0);
|
||||
waddch(dialog, ACS_LTEE);
|
||||
for (i = 0; i < width-2; i++)
|
||||
for (i = 0; i < width - 2; i++)
|
||||
waddch(dialog, ACS_HLINE);
|
||||
wattrset(dialog, dialog_attr);
|
||||
waddch(dialog, ACS_RTEE);
|
||||
wmove(dialog, height-2, 1);
|
||||
for (i = 0; i < width-2; i++)
|
||||
wmove(dialog, height - 2, 1);
|
||||
for (i = 0; i < width - 2; i++)
|
||||
waddch(dialog, ' ');
|
||||
|
||||
if (title != NULL) {
|
||||
wattrset(dialog, title_attr);
|
||||
wmove(dialog, 0, (width - strlen(title))/2 - 1);
|
||||
wmove(dialog, 0, (width - strlen(title)) / 2 - 1);
|
||||
waddch(dialog, ' ');
|
||||
waddstr(dialog, title);
|
||||
waddch(dialog, ' ');
|
||||
}
|
||||
wattrset(dialog, dialog_attr);
|
||||
wmove(dialog, 1, 2);
|
||||
print_autowrap(dialog, prompt, height-1, width-2, width, 1, 2, TRUE, FALSE);
|
||||
print_autowrap(dialog, prompt, height - 1, width - 2, width, 1, 2, TRUE, FALSE);
|
||||
|
||||
list_width = width-6;
|
||||
list_width = width - 6;
|
||||
getyx(dialog, cur_y, cur_x);
|
||||
box_y = cur_y + 1;
|
||||
box_x = (width - list_width)/2 - 1;
|
||||
box_x = (width - list_width) / 2 - 1;
|
||||
|
||||
/* create new window for the list */
|
||||
list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1);
|
||||
if (list == NULL) {
|
||||
delwin(dialog);
|
||||
endwin();
|
||||
fprintf(stderr, "\nsubwin(dialog,%d,%d,%d,%d) failed, maybe wrong dims\n", list_height,list_width,y+box_y+1,x+box_x+1);
|
||||
fprintf(stderr, "\nsubwin(dialog,%d,%d,%d,%d) failed, maybe wrong dims\n", list_height, list_width,
|
||||
y + box_y + 1,x + box_x + 1);
|
||||
return -1;
|
||||
}
|
||||
keypad(list, TRUE);
|
||||
@@ -181,14 +184,14 @@ draw:
|
||||
|
||||
/* Print the list */
|
||||
for (i = 0; i < max_choice; i++)
|
||||
print_item(list, items[i*3], items[i*3 + 1], status[i], i, i == choice, DREF(ditems, i));
|
||||
print_item(list, items[i * 3], items[i * 3 + 1], status[i], i, i == choice, DREF(ditems, i));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
|
||||
display_helpline(dialog, height-1, width);
|
||||
|
||||
x = width/2-11;
|
||||
y = height-2;
|
||||
x = width/ 2 - 11;
|
||||
y = height - 2;
|
||||
if (ditems && result) {
|
||||
cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]);
|
||||
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
|
||||
@@ -203,8 +206,8 @@ draw:
|
||||
okButton = 'O';
|
||||
print_button(dialog, " OK ", y, x, TRUE);
|
||||
}
|
||||
|
||||
wrefresh(dialog);
|
||||
|
||||
while (key != ESC) {
|
||||
key = wgetch(dialog);
|
||||
|
||||
@@ -233,12 +236,13 @@ draw:
|
||||
}
|
||||
}
|
||||
}
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
return 0;
|
||||
rval = 0;
|
||||
key = ESC;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Shortcut to cancel */
|
||||
else if (toupper(key) == cancelButton) {
|
||||
if (toupper(key) == cancelButton) {
|
||||
if (ditems && result && ditems[CANCEL_BUTTON].fire) {
|
||||
int st;
|
||||
WINDOW *save;
|
||||
@@ -251,9 +255,9 @@ draw:
|
||||
}
|
||||
delwin(save);
|
||||
}
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
return 1;
|
||||
rval = 1;
|
||||
key = ESC;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check if key pressed matches first character of any item tag in list */
|
||||
@@ -262,23 +266,25 @@ draw:
|
||||
break;
|
||||
|
||||
if (i < max_choice || (key >= '1' && key <= MIN('9', '0' + max_choice)) ||
|
||||
key == KEY_UP || key == KEY_DOWN || key == ' ' || key == '+' || key == '-' ) {
|
||||
KEY_IS_UP(key) || KEY_IS_DOWN(key) || key == ' ') {
|
||||
if (key >= '1' && key <= MIN('9', '0' + max_choice))
|
||||
i = key - '1';
|
||||
else if (key == KEY_UP || key == '-') {
|
||||
else if (KEY_IS_UP(key)) {
|
||||
if (!choice) {
|
||||
if (scroll) {
|
||||
/* Scroll list down */
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
if (list_height > 1) {
|
||||
/* De-highlight current first item before scrolling down */
|
||||
print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0, FALSE, DREF(ditems, scroll));
|
||||
print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0,
|
||||
FALSE, DREF(ditems, scroll));
|
||||
scrollok(list, TRUE);
|
||||
wscrl(list, -1);
|
||||
scrollok(list, FALSE);
|
||||
}
|
||||
scroll--;
|
||||
print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0, TRUE, DREF(ditems, scroll));
|
||||
print_item(list, items[scroll*3], items[scroll*3 + 1], status[scroll], 0,
|
||||
TRUE, DREF(ditems, scroll));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
@@ -288,22 +294,26 @@ draw:
|
||||
else
|
||||
i = choice - 1;
|
||||
}
|
||||
else if (key == KEY_DOWN || key == '+') {
|
||||
else if (KEY_IS_DOWN(key)) {
|
||||
if (choice == max_choice - 1) {
|
||||
if (scroll + choice < item_no - 1) {
|
||||
/* Scroll list up */
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
if (list_height > 1) {
|
||||
/* De-highlight current last item before scrolling up */
|
||||
print_item(list, items[(scroll + max_choice - 1) * 3], items[(scroll + max_choice - 1) * 3 + 1],
|
||||
status[scroll + max_choice - 1], max_choice - 1, FALSE, DREF(ditems, scroll + max_choice - 1));
|
||||
print_item(list, items[(scroll + max_choice - 1) * 3],
|
||||
items[(scroll + max_choice - 1) * 3 + 1],
|
||||
status[scroll + max_choice - 1], max_choice - 1,
|
||||
FALSE, DREF(ditems, scroll + max_choice - 1));
|
||||
scrollok(list, TRUE);
|
||||
scroll(list);
|
||||
scrollok(list, FALSE);
|
||||
}
|
||||
scroll++;
|
||||
print_item(list, items[(scroll + max_choice - 1) * 3], items[(scroll + max_choice - 1) * 3 + 1],
|
||||
status[scroll + max_choice - 1], max_choice - 1, TRUE, DREF(ditems, scroll + max_choice - 1));
|
||||
print_item(list, items[(scroll + max_choice - 1) * 3],
|
||||
items[(scroll + max_choice - 1) * 3 + 1],
|
||||
status[scroll + max_choice - 1], max_choice - 1,
|
||||
TRUE, DREF(ditems, scroll + max_choice - 1));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
@@ -327,7 +337,9 @@ draw:
|
||||
touchwin(save);
|
||||
wrefresh(save);
|
||||
}
|
||||
delwin(save);
|
||||
if (st & DITEM_REDRAW) {
|
||||
wclear(list);
|
||||
for (i = 0; i < item_no; i++)
|
||||
status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE;
|
||||
|
||||
@@ -340,7 +352,6 @@ draw:
|
||||
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */
|
||||
wrefresh(dialog);
|
||||
}
|
||||
delwin(save);
|
||||
if (st & DITEM_LEAVE_MENU) {
|
||||
/* Allow a fire action to take us out of the menu */
|
||||
key = ESC;
|
||||
@@ -363,8 +374,8 @@ draw:
|
||||
}
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
for (i = 0; i < max_choice; i++)
|
||||
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice,
|
||||
DREF(ditems, scroll + i));
|
||||
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1],
|
||||
status[scroll + i], i, i == choice, DREF(ditems, scroll + i));
|
||||
wnoutrefresh(list);
|
||||
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */
|
||||
wrefresh(dialog);
|
||||
@@ -464,24 +475,24 @@ draw:
|
||||
}
|
||||
}
|
||||
}
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
return button;
|
||||
rval = button;
|
||||
key = ESC;
|
||||
break;
|
||||
|
||||
case ESC:
|
||||
rval = -1;
|
||||
break;
|
||||
|
||||
case KEY_F(1):
|
||||
case '?':
|
||||
display_helpfile();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (redraw_menu) {
|
||||
for (i = 0; i < max_choice; i++)
|
||||
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i], i, i == choice,
|
||||
DREF(ditems, scroll + i));
|
||||
print_item(list, items[(scroll + i) * 3], items[(scroll + i) * 3 + 1], status[scroll + i],
|
||||
i, i == choice, DREF(ditems, scroll + i));
|
||||
wnoutrefresh(list);
|
||||
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
|
||||
wrefresh(dialog);
|
||||
@@ -491,11 +502,8 @@ draw:
|
||||
|
||||
delwin(list);
|
||||
delwin(dialog);
|
||||
free(status);
|
||||
return -1; /* ESC pressed */
|
||||
return rval; /* ESC pressed */
|
||||
}
|
||||
/* End of dialog_radiolist() */
|
||||
|
||||
|
||||
/*
|
||||
* Print list item
|
||||
|
||||
@@ -136,7 +136,7 @@ int dialog_textbox(unsigned char *title, unsigned char *file, int height, int wi
|
||||
}
|
||||
display_helpline(dialog, height-1, width);
|
||||
|
||||
print_button(dialog, " CONTINUE ", height-2, width/2-8, TRUE);
|
||||
print_button(dialog, " OK ", height-2, width/2-6, TRUE);
|
||||
wnoutrefresh(dialog);
|
||||
getyx(dialog, cur_y, cur_x); /* Save cursor position */
|
||||
|
||||
@@ -219,6 +219,7 @@ int dialog_textbox(unsigned char *title, unsigned char *file, int height, int wi
|
||||
break;
|
||||
case 'K': /* Previous line */
|
||||
case 'k':
|
||||
case '\020': /* ^P */
|
||||
case KEY_UP:
|
||||
if (!begin_reached) {
|
||||
back_lines(page_length+1);
|
||||
@@ -266,6 +267,7 @@ int dialog_textbox(unsigned char *title, unsigned char *file, int height, int wi
|
||||
break;
|
||||
case 'J': /* Next line */
|
||||
case 'j':
|
||||
case '\016': /* ^N */
|
||||
case KEY_DOWN:
|
||||
if (!end_reached) {
|
||||
begin_reached = 0;
|
||||
@@ -657,7 +659,7 @@ static int get_search_term(WINDOW *win, unsigned char *search_term, int height,
|
||||
|
||||
first = 1;
|
||||
while (key != ESC) {
|
||||
key = line_edit(win, y+1, x+1, -1, box_width-2, searchbox_attr, first, search_term);
|
||||
key = line_edit(win, y+1, x+1, -1, box_width-2, searchbox_attr, first, search_term, 0);
|
||||
first = 0;
|
||||
switch (key) {
|
||||
case '\n':
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#define ESC 27
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Obj routines
|
||||
@@ -122,6 +121,7 @@ ReadObj(ComposeObj *Obj)
|
||||
break;
|
||||
}
|
||||
switch(ret) {
|
||||
case KEY_DOWN:
|
||||
case SEL_CR:
|
||||
case SEL_TAB: /* move to the next object in the list */
|
||||
if (o->next != NULL) {
|
||||
@@ -130,6 +130,8 @@ ReadObj(ComposeObj *Obj)
|
||||
o = Obj; /* beginning of the list */
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
case SEL_BACKTAB: /* move to the previous object in the list */
|
||||
if (o->prev != NULL) {
|
||||
o = o->prev; /* previous object */
|
||||
@@ -137,6 +139,7 @@ ReadObj(ComposeObj *Obj)
|
||||
o = last; /* end of the list */
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_F(1): /* display help_file */
|
||||
case '?':
|
||||
display_helpfile();
|
||||
@@ -177,6 +180,7 @@ PollObj(ComposeObj **Obj)
|
||||
break;
|
||||
}
|
||||
switch(ret) {
|
||||
case KEY_DOWN:
|
||||
case SEL_CR:
|
||||
case SEL_TAB: /* move to the next object in the list */
|
||||
if ((*Obj)->next != NULL) {
|
||||
@@ -185,6 +189,8 @@ PollObj(ComposeObj **Obj)
|
||||
*Obj = first; /* beginning of the list */
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
case SEL_BACKTAB: /* move to the previous object in the list */
|
||||
if ((*Obj)->prev != NULL) {
|
||||
*Obj = (*Obj)->prev; /* previous object */
|
||||
@@ -232,6 +238,22 @@ DelObj(ComposeObj *Obj)
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
static void
|
||||
outstr(WINDOW *win, char *str, int attrs)
|
||||
{
|
||||
if (attrs & DITEM_NO_ECHO) {
|
||||
char *cpy;
|
||||
int n = strlen(str);
|
||||
|
||||
cpy = alloca(n + 1);
|
||||
memset(cpy, '*', n);
|
||||
cpy[n] = '\0';
|
||||
waddstr(win, cpy);
|
||||
}
|
||||
else
|
||||
waddstr(win, str);
|
||||
}
|
||||
|
||||
void
|
||||
RefreshStringObj(StringObj *so)
|
||||
/*
|
||||
@@ -249,9 +271,9 @@ RefreshStringObj(StringObj *so)
|
||||
wmove(so->win, so->y+2, so->x+1);
|
||||
if (strlen(so->s) > so->w-2) {
|
||||
strncpy(tmp, (char *) so->s + strlen(so->s) - so->w + 2, so->w - 1);
|
||||
waddstr(so->win, tmp);
|
||||
outstr(so->win, tmp, so->attr_mask);
|
||||
} else {
|
||||
waddstr(so->win, so->s);
|
||||
outstr(so->win, so->s, so->attr_mask);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -285,6 +307,7 @@ NewStringObj(WINDOW *win, char *title, char *s, int y, int x, int w, int len)
|
||||
so->w = w;
|
||||
so->len = len;
|
||||
so->win = win;
|
||||
so->attr_mask = DialogInputAttrs; /* Grossly use a global to avoid changing API */
|
||||
|
||||
/* Draw it on the screen */
|
||||
RefreshStringObj(so);
|
||||
@@ -303,7 +326,7 @@ SelectStringObj(StringObj *so)
|
||||
|
||||
strcpy(tmp, so->s);
|
||||
key = line_edit(so->win, so->y+2, so->x+1,
|
||||
so->len, so->w-2, inputbox_attr, TRUE, tmp);
|
||||
so->len, so->w-2, inputbox_attr, TRUE, tmp, so->attr_mask);
|
||||
if ((key == '\n') || (key == '\r') || (key == '\t') || key == (KEY_BTAB) ) {
|
||||
strcpy(so->s, tmp);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ typedef struct {
|
||||
int x, y, w, len; /* the (y, x) position of the upperleft */
|
||||
/* corner and the width <w> of the display */
|
||||
/* and length <len> of the field */
|
||||
int attr_mask; /* special attributes */
|
||||
} StringObj;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ldconfig.c,v 1.12 1996/02/26 02:22:33 pst Exp $
|
||||
* $Id: ldconfig.c,v 1.9.4.3 1996/04/02 13:10:30 phk Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@@ -39,6 +39,8 @@
|
||||
#include <sys/resource.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <ar.h>
|
||||
#include <ranlib.h>
|
||||
@@ -114,7 +116,7 @@ char *argv[];
|
||||
return rval;
|
||||
if (justread) {
|
||||
listhints();
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +290,7 @@ buildhints()
|
||||
hdr.hh_ehints = hdr.hh_strtab + hdr.hh_strtab_sz;
|
||||
|
||||
if (verbose)
|
||||
printf("Totals: entries %d, buckets %d, string size %d\n",
|
||||
printf("Totals: entries %d, buckets %ld, string size %d\n",
|
||||
nhints, hdr.hh_nbucket, strtab_sz);
|
||||
|
||||
/* Allocate buckets and string table */
|
||||
|
||||
+243
-131
@@ -16,11 +16,16 @@
|
||||
|
||||
#define MAN_MAIN
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#ifdef __FreeBSD__
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include "config.h"
|
||||
#include "gripes.h"
|
||||
@@ -57,14 +62,7 @@ extern int fclose ();
|
||||
extern char *sprintf ();
|
||||
#endif
|
||||
|
||||
extern char *strdup ();
|
||||
|
||||
extern char **glob_vector ();
|
||||
extern char **glob_filename ();
|
||||
extern int access ();
|
||||
extern int unlink ();
|
||||
extern int system ();
|
||||
extern int chmod ();
|
||||
extern int is_newer ();
|
||||
extern int is_directory ();
|
||||
extern int do_system_command ();
|
||||
@@ -131,6 +129,10 @@ main (argc, argv)
|
||||
|
||||
prognam = mkprogname (argv[0]);
|
||||
|
||||
unsetenv("IFS");
|
||||
#ifdef __FreeBSD__
|
||||
(void) setlocale(LC_ALL, "");
|
||||
#endif
|
||||
man_getopt (argc, argv);
|
||||
|
||||
if (optind == argc)
|
||||
@@ -175,10 +177,14 @@ main (argc, argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (apropos)
|
||||
if (apropos) {
|
||||
do_apropos (nextarg);
|
||||
else if (whatis)
|
||||
status = (status ? 0 : 1); /* reverts status, see below */
|
||||
}
|
||||
else if (whatis) {
|
||||
do_whatis (nextarg);
|
||||
status = (status ? 0 : 1); /* reverts status, see below */
|
||||
}
|
||||
else
|
||||
{
|
||||
status = man (nextarg);
|
||||
@@ -313,6 +319,8 @@ man_getopt (argc, argv)
|
||||
break;
|
||||
case 'P':
|
||||
pager = strdup (optarg);
|
||||
if (setenv("PAGER", pager, 1) != 0)
|
||||
(void)fprintf(stderr, "setenv PAGER=%s\n", pager);
|
||||
break;
|
||||
case 'S':
|
||||
colon_sep_section_list = strdup (optarg);
|
||||
@@ -411,6 +419,10 @@ man_getopt (argc, argv)
|
||||
mp = manpathlist;
|
||||
for (p = manp; ; p = end+1)
|
||||
{
|
||||
if (mp == manpathlist + MAXDIRS - 1) {
|
||||
fprintf (stderr, "Warning: too many directories in manpath, truncated!\n");
|
||||
break;
|
||||
}
|
||||
if ((end = strchr (p, ':')) != NULL)
|
||||
*end = '\0';
|
||||
|
||||
@@ -423,9 +435,7 @@ man_getopt (argc, argv)
|
||||
fprintf (stderr, "Alternate system `%s' specified\n",
|
||||
alt_system_name);
|
||||
|
||||
strcpy (buf, p);
|
||||
strcat (buf, "/");
|
||||
strcat (buf, alt_system_name);
|
||||
snprintf(buf, sizeof(buf), "%s/%s", p, alt_system_name);
|
||||
|
||||
mp = add_dir_to_mpath_list (mp, buf);
|
||||
}
|
||||
@@ -525,15 +535,17 @@ convert_name (name, to_cat)
|
||||
#ifdef DO_COMPRESS
|
||||
if (to_cat)
|
||||
{
|
||||
int len = strlen (name) + 3;
|
||||
int olen = strlen(name);
|
||||
int cextlen = strlen(COMPRESS_EXT);
|
||||
int len = olen + cextlen;
|
||||
|
||||
to_name = (char *) malloc (len);
|
||||
to_name = malloc (len+1);
|
||||
if (to_name == NULL)
|
||||
gripe_alloc (len, "to_name");
|
||||
gripe_alloc (len+1, "to_name");
|
||||
strcpy (to_name, name);
|
||||
olen -= cextlen;
|
||||
/* Avoid tacking it on twice */
|
||||
if (strcmp(name + (len - (3 + cextlen)), COMPRESS_EXT))
|
||||
if (olen >= 1 && strcmp(name + olen, COMPRESS_EXT) != 0)
|
||||
strcat (to_name, COMPRESS_EXT);
|
||||
}
|
||||
else
|
||||
@@ -591,9 +603,9 @@ glob_for_file (path, section, name, cat)
|
||||
char **gf;
|
||||
|
||||
if (cat)
|
||||
sprintf (pathname, "%s/cat%s/%s.%s*", path, section, name, section);
|
||||
snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%s*", path, section, name, section);
|
||||
else
|
||||
sprintf (pathname, "%s/man%s/%s.%s*", path, section, name, section);
|
||||
snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%s*", path, section, name, section);
|
||||
|
||||
if (debug)
|
||||
fprintf (stderr, "globbing %s\n", pathname);
|
||||
@@ -603,18 +615,18 @@ glob_for_file (path, section, name, cat)
|
||||
if ((gf == (char **) -1 || *gf == NULL) && isdigit (*section))
|
||||
{
|
||||
if (cat)
|
||||
sprintf (pathname, "%s/cat%s/%s.%c*", path, section, name, *section);
|
||||
snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.%c*", path, section, name, *section);
|
||||
else
|
||||
sprintf (pathname, "%s/man%s/%s.%c*", path, section, name, *section);
|
||||
snprintf (pathname, sizeof(pathname), "%s/man%s/%s.%c*", path, section, name, *section);
|
||||
|
||||
gf = glob_filename (pathname);
|
||||
}
|
||||
if ((gf == (char **) -1 || *gf == NULL) && isdigit (*section))
|
||||
{
|
||||
if (cat)
|
||||
sprintf (pathname, "%s/cat%s/%s.0*", path, section, name);
|
||||
snprintf (pathname, sizeof(pathname), "%s/cat%s/%s.0*", path, section, name);
|
||||
else
|
||||
sprintf (pathname, "%s/man%s/%s.0*", path, section, name);
|
||||
snprintf (pathname, sizeof(pathname), "%s/man%s/%s.0*", path, section, name);
|
||||
if (debug)
|
||||
fprintf (stderr, "globbing %s\n", pathname);
|
||||
gf = glob_filename (pathname);
|
||||
@@ -638,9 +650,9 @@ make_name (path, section, name, cat)
|
||||
char buf[FILENAME_MAX];
|
||||
|
||||
if (cat)
|
||||
sprintf (buf, "%s/cat%s/%s.%s", path, section, name, section);
|
||||
snprintf (buf, sizeof(buf), "%s/cat%s/%s.%s", path, section, name, section);
|
||||
else
|
||||
sprintf (buf, "%s/man%s/%s.%s", path, section, name, section);
|
||||
snprintf (buf, sizeof(buf), "%s/man%s/%s.%s", path, section, name, section);
|
||||
|
||||
if (access (buf, R_OK) == 0)
|
||||
names[i++] = strdup (buf);
|
||||
@@ -653,9 +665,9 @@ make_name (path, section, name, cat)
|
||||
if (section[1] != '\0')
|
||||
{
|
||||
if (cat)
|
||||
sprintf (buf, "%s/cat%c/%s.%s", path, section[0], name, section);
|
||||
snprintf (buf, sizeof(buf), "%s/cat%c/%s.%s", path, section[0], name, section);
|
||||
else
|
||||
sprintf (buf, "%s/man%c/%s.%s", path, section[0], name, section);
|
||||
snprintf (buf, sizeof(buf), "%s/man%c/%s.%s", path, section[0], name, section);
|
||||
|
||||
if (access (buf, R_OK) == 0)
|
||||
names[i++] = strdup (buf);
|
||||
@@ -708,9 +720,9 @@ display_cat_file (file)
|
||||
char *expander = get_expander (file);
|
||||
|
||||
if (expander != NULL)
|
||||
sprintf (command, "%s %s | %s", expander, file, pager);
|
||||
snprintf (command, sizeof(command), "%s %s | %s", expander, file, pager);
|
||||
else
|
||||
sprintf (command, "%s %s", pager, file);
|
||||
snprintf (command, sizeof(command), "%s %s", pager, file);
|
||||
|
||||
found = do_system_command (command);
|
||||
}
|
||||
@@ -737,18 +749,20 @@ ultimate_source (name, path)
|
||||
char *beg;
|
||||
char *end;
|
||||
|
||||
strcpy (ult, name);
|
||||
strcpy (buf, name);
|
||||
strncpy (ult, name, sizeof(ult)-1);
|
||||
ult[sizeof(ult)-1] = '\0';
|
||||
strncpy (buf, name, sizeof(buf)-1);
|
||||
ult[sizeof(buf)-1] = '\0';
|
||||
|
||||
next:
|
||||
|
||||
if ((fp = fopen (ult, "r")) == NULL)
|
||||
return buf;
|
||||
|
||||
if (fgets (buf, BUFSIZ, fp) == NULL)
|
||||
return ult;
|
||||
|
||||
if (strlen (buf) < 5)
|
||||
end = fgets (buf, BUFSIZ, fp);
|
||||
fclose(fp);
|
||||
|
||||
if (!end || strlen (buf) < 5)
|
||||
return ult;
|
||||
|
||||
beg = buf;
|
||||
@@ -763,11 +777,8 @@ ultimate_source (name, path)
|
||||
|
||||
*end = '\0';
|
||||
|
||||
strcpy (ult, path);
|
||||
strcat (ult, "/");
|
||||
strcat (ult, beg);
|
||||
|
||||
strcpy (buf, ult);
|
||||
snprintf(ult, sizeof(ult), "%s/%s", path, beg);
|
||||
snprintf(buf, sizeof(buf), "%s", ult);
|
||||
|
||||
goto next;
|
||||
}
|
||||
@@ -779,34 +790,34 @@ ultimate_source (name, path)
|
||||
}
|
||||
|
||||
void
|
||||
add_directive (first, d, file, buf)
|
||||
add_directive (first, d, file, buf, bufsize)
|
||||
int *first;
|
||||
char *d;
|
||||
char *file;
|
||||
char *buf;
|
||||
int bufsize;
|
||||
{
|
||||
if (strcmp (d, "") != 0)
|
||||
{
|
||||
if (*first)
|
||||
{
|
||||
*first = 0;
|
||||
strcpy (buf, d);
|
||||
strcat (buf, " ");
|
||||
strcat (buf, file);
|
||||
snprintf(buf, bufsize, "%s %s", d, file);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat (buf, " | ");
|
||||
strcat (buf, d);
|
||||
strncat (buf, " | ", bufsize-strlen(buf)-1);
|
||||
strncat (buf, d, bufsize-strlen(buf)-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
parse_roff_directive (cp, file, buf)
|
||||
parse_roff_directive (cp, file, buf, bufsize)
|
||||
char *cp;
|
||||
char *file;
|
||||
char *buf;
|
||||
int bufsize;
|
||||
{
|
||||
char c;
|
||||
int first = 1;
|
||||
@@ -822,9 +833,9 @@ parse_roff_directive (cp, file, buf)
|
||||
fprintf (stderr, "found eqn(1) directive\n");
|
||||
|
||||
if (troff)
|
||||
add_directive (&first, EQN, file, buf);
|
||||
add_directive (&first, EQN, file, buf, bufsize);
|
||||
else
|
||||
add_directive (&first, NEQN, file, buf);
|
||||
add_directive (&first, NEQN, file, buf, bufsize);
|
||||
|
||||
break;
|
||||
|
||||
@@ -833,7 +844,7 @@ parse_roff_directive (cp, file, buf)
|
||||
if (debug)
|
||||
fprintf (stderr, "found grap(1) directive\n");
|
||||
|
||||
add_directive (&first, GRAP, file, buf);
|
||||
add_directive (&first, GRAP, file, buf, bufsize);
|
||||
|
||||
break;
|
||||
|
||||
@@ -842,7 +853,7 @@ parse_roff_directive (cp, file, buf)
|
||||
if (debug)
|
||||
fprintf (stderr, "found pic(1) directive\n");
|
||||
|
||||
add_directive (&first, PIC, file, buf);
|
||||
add_directive (&first, PIC, file, buf, bufsize);
|
||||
|
||||
break;
|
||||
|
||||
@@ -852,7 +863,7 @@ parse_roff_directive (cp, file, buf)
|
||||
fprintf (stderr, "found tbl(1) directive\n");
|
||||
|
||||
tbl_found++;
|
||||
add_directive (&first, TBL, file, buf);
|
||||
add_directive (&first, TBL, file, buf, bufsize);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
@@ -860,7 +871,7 @@ parse_roff_directive (cp, file, buf)
|
||||
if (debug)
|
||||
fprintf (stderr, "found vgrind(1) directive\n");
|
||||
|
||||
add_directive (&first, VGRIND, file, buf);
|
||||
add_directive (&first, VGRIND, file, buf, bufsize);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
@@ -868,7 +879,7 @@ parse_roff_directive (cp, file, buf)
|
||||
if (debug)
|
||||
fprintf (stderr, "found refer(1) directive\n");
|
||||
|
||||
add_directive (&first, REFER, file, buf);
|
||||
add_directive (&first, REFER, file, buf, bufsize);
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
@@ -891,19 +902,19 @@ parse_roff_directive (cp, file, buf)
|
||||
#ifdef HAS_TROFF
|
||||
if (troff)
|
||||
{
|
||||
strcat (buf, " | ");
|
||||
strcat (buf, TROFF);
|
||||
strncat (buf, " | ", bufsize-strlen(buf)-1);
|
||||
strncat (buf, TROFF, bufsize-strlen(buf)-1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
strcat (buf, " | ");
|
||||
strcat (buf, NROFF);
|
||||
strncat (buf, " | ", bufsize-strlen(buf)-1);
|
||||
strncat (buf, NROFF, bufsize-strlen(buf)-1);
|
||||
}
|
||||
if (tbl_found && !troff && strcmp (COL, "") != 0)
|
||||
{
|
||||
strcat (buf, " | ");
|
||||
strcat (buf, COL);
|
||||
strncat (buf, " | ", bufsize-strlen(buf)-1);
|
||||
strncat (buf, COL, bufsize-strlen(buf)-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -924,7 +935,7 @@ make_roff_command (file)
|
||||
if (debug)
|
||||
fprintf (stderr, "parsing directive from command line\n");
|
||||
|
||||
status = parse_roff_directive (roff_directive, file, buf);
|
||||
status = parse_roff_directive (roff_directive, file, buf, sizeof(buf));
|
||||
|
||||
if (status == 0)
|
||||
return buf;
|
||||
@@ -936,15 +947,14 @@ make_roff_command (file)
|
||||
if ((fp = fopen (file, "r")) != NULL)
|
||||
{
|
||||
cp = line;
|
||||
fgets (line, 100, fp);
|
||||
fgets (line, BUFSIZ, fp);
|
||||
fclose(fp);
|
||||
if (*cp++ == '\'' && *cp++ == '\\' && *cp++ == '"' && *cp++ == ' ')
|
||||
{
|
||||
if (debug)
|
||||
fprintf (stderr, "parsing directive from file\n");
|
||||
|
||||
status = parse_roff_directive (cp, file, buf);
|
||||
|
||||
fclose (fp);
|
||||
status = parse_roff_directive (cp, file, buf, sizeof(buf));
|
||||
|
||||
if (status == 0)
|
||||
return buf;
|
||||
@@ -968,7 +978,7 @@ make_roff_command (file)
|
||||
if (debug)
|
||||
fprintf (stderr, "parsing directive from environment\n");
|
||||
|
||||
status = parse_roff_directive (cp, file, buf);
|
||||
status = parse_roff_directive (cp, file, buf, sizeof(buf));
|
||||
|
||||
if (status == 0)
|
||||
return buf;
|
||||
@@ -981,20 +991,20 @@ make_roff_command (file)
|
||||
fprintf (stderr, "using default preprocessor sequence\n");
|
||||
|
||||
if ((cp = get_expander(file)) == NULL)
|
||||
cp = "cat";
|
||||
sprintf(buf, "%s %s | ", cp, file);
|
||||
cp = "/bin/cat";
|
||||
snprintf(buf, sizeof(buf), "%s %s | ", cp, file);
|
||||
#ifdef HAS_TROFF
|
||||
if (troff)
|
||||
{
|
||||
if (strcmp (TBL, "") != 0)
|
||||
{
|
||||
strcat (buf, TBL);
|
||||
strcat (buf, " | ");
|
||||
strcat (buf, TROFF);
|
||||
strncat(buf, TBL, sizeof(buf)-strlen(buf)-1);
|
||||
strncat(buf, " | ", sizeof(buf)-strlen(buf)-1);
|
||||
strncat(buf, TROFF, sizeof(buf)-strlen(buf)-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat (buf, TROFF);
|
||||
strncat(buf, TROFF, sizeof(buf)-strlen(buf)-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1002,101 +1012,202 @@ make_roff_command (file)
|
||||
{
|
||||
if (strcmp (TBL, "") != 0)
|
||||
{
|
||||
strcat (buf, TBL);
|
||||
strcat (buf, " | ");
|
||||
strcat (buf, NROFF);
|
||||
strncat(buf, TBL, sizeof(buf)-strlen(buf)-1);
|
||||
strncat(buf, " | ", sizeof(buf)-strlen(buf)-1);
|
||||
strncat(buf, NROFF, sizeof(buf)-strlen(buf)-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy (buf, NROFF);
|
||||
strncpy (buf, NROFF, sizeof(buf));
|
||||
}
|
||||
|
||||
if (strcmp (COL, "") != 0)
|
||||
{
|
||||
strcat (buf, " | ");
|
||||
strcat (buf, COL);
|
||||
strncat (buf, " | ", sizeof(buf)-strlen(buf)-1);
|
||||
strncat (buf, COL, sizeof(buf)-strlen(buf)-1);
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
sig_t ohup, oint, oquit, oterm;
|
||||
static char temp[FILENAME_MAX];
|
||||
|
||||
void cleantmp()
|
||||
{
|
||||
unlink(temp);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
set_sigs()
|
||||
{
|
||||
ohup = signal(SIGHUP, cleantmp);
|
||||
oint = signal(SIGINT, cleantmp);
|
||||
oquit = signal(SIGQUIT, cleantmp);
|
||||
oterm = signal(SIGTERM, cleantmp);
|
||||
}
|
||||
|
||||
void
|
||||
restore_sigs()
|
||||
{
|
||||
signal(SIGHUP, ohup);
|
||||
signal(SIGINT, oint);
|
||||
signal(SIGQUIT, oquit);
|
||||
signal(SIGTERM, oterm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to format the man page and create a new formatted file. Return
|
||||
* 1 for success and 0 for failure.
|
||||
*/
|
||||
int
|
||||
make_cat_file (path, man_file, cat_file)
|
||||
make_cat_file (path, man_file, cat_file, manid)
|
||||
register char *path;
|
||||
register char *man_file;
|
||||
register char *cat_file;
|
||||
{
|
||||
int status;
|
||||
int mode;
|
||||
FILE *fp;
|
||||
int s, f;
|
||||
FILE *fp, *pp;
|
||||
char *roff_command;
|
||||
char command[FILENAME_MAX];
|
||||
char temp[FILENAME_MAX];
|
||||
|
||||
sprintf(temp, "%s.tmp", cat_file);
|
||||
if ((fp = fopen (temp, "w")) != NULL)
|
||||
{
|
||||
fclose (fp);
|
||||
unlink (temp);
|
||||
|
||||
roff_command = make_roff_command (man_file);
|
||||
if (roff_command == NULL)
|
||||
return 0;
|
||||
else
|
||||
|
||||
snprintf(temp, sizeof(temp), "%s.tmpXXXXXX", cat_file);
|
||||
if ((f = mkstemp(temp)) >= 0 && (fp = fdopen(f, "w")) != NULL)
|
||||
{
|
||||
set_sigs();
|
||||
|
||||
if (fchmod (f, CATMODE) < 0) {
|
||||
perror("fchmod");
|
||||
unlink(temp);
|
||||
restore_sigs();
|
||||
fclose(fp);
|
||||
return 0;
|
||||
} else if (debug)
|
||||
fprintf (stderr, "mode of %s is now %o\n", temp, CATMODE);
|
||||
|
||||
#ifdef DO_COMPRESS
|
||||
sprintf (command, "(cd %s ; %s | %s > %s)", path,
|
||||
roff_command, COMPRESSOR, temp);
|
||||
snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
|
||||
roff_command, COMPRESSOR);
|
||||
#else
|
||||
sprintf (command, "(cd %s ; %s > %s)", path,
|
||||
roff_command, temp);
|
||||
snprintf (command, sizeof(command), "(cd %s ; %s)", path,
|
||||
roff_command);
|
||||
#endif
|
||||
/*
|
||||
* Don't let the user interrupt the system () call and screw up
|
||||
* the formatted man page if we're not done yet.
|
||||
*/
|
||||
fprintf (stderr, "Formatting page, please wait...");
|
||||
fflush(stderr);
|
||||
|
||||
status = do_system_command (command);
|
||||
|
||||
if (status <= 0) {
|
||||
fprintf(stderr, "Failed.\n");
|
||||
unlink(temp);
|
||||
exit(1);
|
||||
}
|
||||
if (debug)
|
||||
fprintf (stderr, "\ntrying command: %s\n", command);
|
||||
else {
|
||||
if (rename(temp, cat_file) == -1) {
|
||||
/* FS might be sticky */
|
||||
sprintf(command, "cp %s %s", temp, cat_file);
|
||||
if (system(command))
|
||||
|
||||
#ifdef SETREUID
|
||||
if (manid) {
|
||||
setreuid(-1, ruid);
|
||||
setregid(-1, rgid);
|
||||
}
|
||||
#endif
|
||||
if ((pp = popen(command, "r")) == NULL) {
|
||||
s = errno;
|
||||
fprintf(stderr, "Failed.\n");
|
||||
errno = s;
|
||||
perror("popen");
|
||||
#ifdef SETREUID
|
||||
if (manid) {
|
||||
setreuid(-1, euid);
|
||||
setregid(-1, egid);
|
||||
}
|
||||
#endif
|
||||
unlink(temp);
|
||||
restore_sigs();
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
#ifdef SETREUID
|
||||
if (manid) {
|
||||
setreuid(-1, euid);
|
||||
setregid(-1, egid);
|
||||
}
|
||||
#endif
|
||||
|
||||
while ((s = getc(pp)) != EOF)
|
||||
putc(s, fp);
|
||||
|
||||
if ((s = pclose(pp)) == -1) {
|
||||
s = errno;
|
||||
fprintf(stderr, "Failed.\n");
|
||||
errno = s;
|
||||
perror("pclose");
|
||||
unlink(temp);
|
||||
restore_sigs();
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s != 0) {
|
||||
fprintf(stderr, "Failed.\n");
|
||||
gripe_system_command(s);
|
||||
unlink(temp);
|
||||
restore_sigs();
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (debug)
|
||||
unlink(temp);
|
||||
else if (rename(temp, cat_file) == -1) {
|
||||
s = errno;
|
||||
fprintf(stderr,
|
||||
"\nHmm! Can't seem to rename %s to %s, check permissions on man dir!\n",
|
||||
temp, cat_file);
|
||||
errno = s;
|
||||
perror("rename");
|
||||
unlink(temp);
|
||||
restore_sigs();
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "Done.\n");
|
||||
if (status == 1)
|
||||
{
|
||||
mode = CATMODE;
|
||||
chmod (cat_file, mode);
|
||||
restore_sigs();
|
||||
|
||||
if (debug)
|
||||
fprintf (stderr, "mode of %s is now %o\n", cat_file, mode);
|
||||
if (fclose(fp)) {
|
||||
s = errno;
|
||||
if (!debug)
|
||||
unlink(cat_file);
|
||||
fprintf(stderr, "Failed.\n");
|
||||
errno = s;
|
||||
perror("fclose");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
fprintf(stderr, "No output, debug mode.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Done.\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (debug)
|
||||
fprintf (stderr, "Couldn't open %s for writing.\n", cat_file);
|
||||
if (f >= 0) {
|
||||
s = errno;
|
||||
unlink(temp);
|
||||
errno = s;
|
||||
}
|
||||
if (debug) {
|
||||
s = errno;
|
||||
fprintf (stderr, "Couldn't open %s for writing.\n", temp);
|
||||
errno = s;
|
||||
}
|
||||
if (f >= 0) {
|
||||
perror("fdopen");
|
||||
close(f);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1132,7 +1243,7 @@ format_and_display (path, man_file, cat_file)
|
||||
if (roff_command == NULL)
|
||||
return 0;
|
||||
else
|
||||
sprintf (command, "(cd %s ; %s)", path, roff_command);
|
||||
snprintf (command, sizeof(command), "(cd %s ; %s)", path, roff_command);
|
||||
|
||||
found = do_system_command (command);
|
||||
}
|
||||
@@ -1158,10 +1269,10 @@ format_and_display (path, man_file, cat_file)
|
||||
#ifdef SETREUID
|
||||
setreuid(-1, euid);
|
||||
setregid(-1, egid);
|
||||
found = make_cat_file (path, man_file, cat_file, 1);
|
||||
#else
|
||||
found = make_cat_file (path, man_file, cat_file, 0);
|
||||
#endif
|
||||
|
||||
found = make_cat_file (path, man_file, cat_file);
|
||||
|
||||
#ifdef SETREUID
|
||||
setreuid(-1, ruid);
|
||||
setregid(-1, rgid);
|
||||
@@ -1173,7 +1284,7 @@ format_and_display (path, man_file, cat_file)
|
||||
effective group (user) ID == real group (user) ID
|
||||
except for the call above, I believe the problems
|
||||
of reading private man pages is avoided. */
|
||||
found = make_cat_file (path, man_file, cat_file);
|
||||
found = make_cat_file (path, man_file, cat_file, 0);
|
||||
}
|
||||
#endif
|
||||
#ifdef SECURE_MAN_UID
|
||||
@@ -1192,7 +1303,7 @@ format_and_display (path, man_file, cat_file)
|
||||
*/
|
||||
setuid (getuid ());
|
||||
|
||||
found = make_cat_file (path, man_file, cat_file);
|
||||
found = make_cat_file (path, man_file, cat_file, 0);
|
||||
}
|
||||
#endif
|
||||
if (found)
|
||||
@@ -1212,7 +1323,7 @@ format_and_display (path, man_file, cat_file)
|
||||
if (roff_command == NULL)
|
||||
return 0;
|
||||
else
|
||||
sprintf (command, "(cd %s ; %s | %s)", path,
|
||||
snprintf (command, sizeof(command), "(cd %s ; %s | %s)", path,
|
||||
roff_command, pager);
|
||||
|
||||
found = do_system_command (command);
|
||||
@@ -1401,7 +1512,8 @@ get_section_list ()
|
||||
int i;
|
||||
char *p;
|
||||
char *end;
|
||||
static char *tmp_section_list[100];
|
||||
#define TMP_SECTION_LIST_SIZE 100
|
||||
static char *tmp_section_list[TMP_SECTION_LIST_SIZE];
|
||||
|
||||
if (colon_sep_section_list == NULL)
|
||||
{
|
||||
@@ -1416,7 +1528,7 @@ get_section_list ()
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (p = colon_sep_section_list; ; p = end+1)
|
||||
for (p = colon_sep_section_list; i < TMP_SECTION_LIST_SIZE ; p = end+1)
|
||||
{
|
||||
if ((end = strchr (p, ':')) != NULL)
|
||||
*end = '\0';
|
||||
|
||||
@@ -1135,7 +1135,7 @@ again:
|
||||
if (nlp->fake)
|
||||
{
|
||||
if (nlp->change_dir && chdir (nlp->change_dir))
|
||||
msg_perror ("Can't change to directory %d", nlp->change_dir);
|
||||
msg_perror ("Can't change to directory %s", nlp->change_dir);
|
||||
namelist = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
+1
-6
@@ -27,7 +27,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: crt0.c,v 1.16.4.2 1995/09/28 13:16:24 davidg Exp $
|
||||
* $Id: crt0.c,v 1.16.4.4 1996/06/05 02:45:01 jkh Exp $
|
||||
*/
|
||||
|
||||
|
||||
@@ -39,9 +39,7 @@ extern void exit();
|
||||
int _callmain();
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
extern void _startup_setlocale __P((int, const char *));
|
||||
|
||||
#ifdef DYNAMIC
|
||||
#include <sys/types.h>
|
||||
@@ -179,9 +177,6 @@ asm("eprol:");
|
||||
monstartup(&eprol, &etext);
|
||||
#endif /* MCRT0 */
|
||||
|
||||
if (getenv("ENABLE_STARTUP_LOCALE") != NULL)
|
||||
_startup_setlocale(LC_ALL, "");
|
||||
|
||||
asm ("__callmain:"); /* Defined for the benefit of debuggers */
|
||||
exit(main(kfp->kargc, argv, environ));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: collate.c,v 1.4 1995/05/30 05:40:40 rgrimes Exp $
|
||||
* $Id: collate.c,v 1.4.4.2 1996/06/05 02:47:55 jkh Exp $
|
||||
*/
|
||||
|
||||
#include <rune.h>
|
||||
@@ -64,7 +64,7 @@ __collate_load_tables(encoding)
|
||||
__collate_load_error = 1;
|
||||
if (!encoding)
|
||||
return -1;
|
||||
if (!path_locale && !(path_locale = getenv("PATH_LOCALE")))
|
||||
if (!path_locale)
|
||||
path_locale = _PATH_LOCALE;
|
||||
strcpy(buf, path_locale);
|
||||
strcat(buf, "/");
|
||||
|
||||
@@ -71,7 +71,7 @@ setrunelocale(encoding)
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
|
||||
if (!PathLocale)
|
||||
PathLocale = _PATH_LOCALE;
|
||||
|
||||
(void) strcpy(name, PathLocale);
|
||||
|
||||
@@ -58,7 +58,7 @@ setlocale(category, locale)
|
||||
int found, i, len;
|
||||
char *env, *r;
|
||||
|
||||
if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
|
||||
if (!PathLocale)
|
||||
PathLocale = _PATH_LOCALE;
|
||||
|
||||
if (category < 0 || category >= _LC_LAST)
|
||||
|
||||
@@ -23,7 +23,7 @@ _startup_setlocale(category, locale)
|
||||
int found, i, len;
|
||||
char *env, *r;
|
||||
|
||||
if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
|
||||
if (!PathLocale)
|
||||
PathLocale = _PATH_LOCALE;
|
||||
|
||||
if (category < 0 || category >= _LC_LAST)
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
|
||||
static char rcsid[] = "$Id: gethostbydns.c,v 1.8 1996/01/13 09:03:40 peter Exp $";
|
||||
static char rcsid[] = "$Id: gethostbydns.c,v 1.4.4.5 1996/11/20 18:36:37 pst Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@@ -305,12 +305,11 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
|
||||
cp += n;
|
||||
continue; /* XXX - had_error++ ? */
|
||||
}
|
||||
if (haveanswer) {
|
||||
if (n != host.h_length) {
|
||||
cp += n;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (n != host.h_length) {
|
||||
cp += n;
|
||||
continue;
|
||||
}
|
||||
if (!haveanswer) {
|
||||
register int nn;
|
||||
|
||||
host.h_length = n;
|
||||
@@ -393,6 +392,8 @@ _gethostbydnsname(name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
host.h_length = INT32SZ;
|
||||
|
||||
/*
|
||||
* if there aren't any dots, it could be a user-level alias.
|
||||
* this is also done in res_query() since we are not the only
|
||||
|
||||
+2
-2
@@ -99,7 +99,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
|
||||
}
|
||||
fcntl(s, F_SETOWN, pid);
|
||||
sin.sin_family = hp->h_addrtype;
|
||||
bcopy(hp->h_addr_list[0], &sin.sin_addr, hp->h_length);
|
||||
bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length,sizeof(sin.sin_addr)));
|
||||
sin.sin_port = rport;
|
||||
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)
|
||||
break;
|
||||
@@ -121,7 +121,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
|
||||
errno = oerrno;
|
||||
perror(0);
|
||||
hp->h_addr_list++;
|
||||
bcopy(hp->h_addr_list[0], &sin.sin_addr, hp->h_length);
|
||||
bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr));
|
||||
(void)fprintf(stderr, "Trying %s...\n",
|
||||
inet_ntoa(sin.sin_addr));
|
||||
continue;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# $Id: Makefile,v 1.11.4.6 1996/06/05 02:52:27 jkh Exp $
|
||||
# $Id: Makefile,v 1.11.4.7 1996/07/09 12:18:58 jkh Exp $
|
||||
|
||||
LIB= disk
|
||||
SRCS= blocks.c disklabel.c dkcksum.c chunk.c disk.c change.c \
|
||||
@@ -37,7 +37,8 @@ MLINKS+= libdisk.3 Open_Disk.3 \
|
||||
libdisk.3 MakeDev.3 \
|
||||
libdisk.3 MakeDevDisk.3 \
|
||||
libdisk.3 ShowChunkFlags.3 \
|
||||
libdisk.3 ChunkCanBeRoot.3
|
||||
libdisk.3 ChunkCanBeRoot.3 \
|
||||
libdisk.3 slice_type_name.3
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
||||
|
||||
+40
-20
@@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: change.c,v 1.10 1995/12/07 10:33:18 peter Exp $
|
||||
* $Id: change.c,v 1.9.2.2 1996/05/28 22:51:09 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -19,23 +19,6 @@
|
||||
#include <sys/types.h>
|
||||
#include "libdisk.h"
|
||||
|
||||
#if 0
|
||||
struct disk *
|
||||
Set_Phys_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
|
||||
{
|
||||
struct disk *d = Int_Open_Disk(disk->name,cyl*hd*sect);
|
||||
d->real_cyl = cyl;
|
||||
d->real_hd = hd;
|
||||
d->real_sect = sect;
|
||||
d->bios_cyl = disk->bios_cyl;
|
||||
d->bios_hd = disk->bios_hd;
|
||||
d->bios_sect = disk->bios_sect;
|
||||
d->flags = disk->flags;
|
||||
Free_Disk(disk);
|
||||
return d;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
|
||||
{
|
||||
@@ -45,6 +28,38 @@ Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
|
||||
Bios_Limit_Chunk(disk->chunks,1024*hd*sect);
|
||||
}
|
||||
|
||||
void
|
||||
Sanitize_Bios_Geom(struct disk *disk)
|
||||
{
|
||||
int sane = 1;
|
||||
|
||||
if (disk->bios_cyl > 1024)
|
||||
sane = 0;
|
||||
if (disk->bios_hd > 16)
|
||||
sane = 0;
|
||||
if (disk->bios_sect > 63)
|
||||
sane = 0;
|
||||
if (disk->bios_cyl*disk->bios_hd*disk->bios_sect !=
|
||||
disk->chunks->size)
|
||||
sane = 0;
|
||||
if (sane)
|
||||
return;
|
||||
|
||||
/* First try something that IDE can handle */
|
||||
disk->bios_sect = 63;
|
||||
disk->bios_hd = 16;
|
||||
disk->bios_cyl = disk->chunks->size/(disk->bios_sect*disk->bios_hd);
|
||||
|
||||
if (disk->bios_cyl < 1024)
|
||||
return;
|
||||
|
||||
/* Hmm, try harder... */
|
||||
disk->bios_hd = 255;
|
||||
disk->bios_cyl = disk->chunks->size/(disk->bios_sect*disk->bios_hd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
All_FreeBSD(struct disk *d, int force_all)
|
||||
{
|
||||
@@ -57,6 +72,11 @@ All_FreeBSD(struct disk *d, int force_all)
|
||||
goto again;
|
||||
}
|
||||
c=d->chunks;
|
||||
Create_Chunk(d,c->offset,c->size,freebsd,0xa5,
|
||||
force_all? CHUNK_FORCE_ALL: 0);
|
||||
if (force_all) {
|
||||
Sanitize_Bios_Geom(d);
|
||||
Create_Chunk(d,c->offset,c->size,freebsd,0xa5,
|
||||
CHUNK_FORCE_ALL);
|
||||
} else {
|
||||
Create_Chunk(d,c->offset,c->size,freebsd,0xa5, 0);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: create_chunk.c,v 1.24 1996/04/29 05:03:01 jkh Exp $
|
||||
* $Id: create_chunk.c,v 1.21.2.8 1996/05/28 22:51:12 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -257,6 +257,8 @@ MakeDev(struct chunk *c1, const char *path)
|
||||
bmaj = 0, cmaj = 3;
|
||||
else if (!strncmp(p, "sd", 2))
|
||||
bmaj = 4, cmaj = 13;
|
||||
else if (!strncmp(p, "od", 2))
|
||||
bmaj = 20, cmaj = 70;
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+42
-3
@@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: disk.c,v 1.22 1996/04/29 05:03:02 jkh Exp $
|
||||
* $Id: disk.c,v 1.20.2.2 1996/05/28 22:51:14 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -231,7 +231,9 @@ Debug_Disk(struct disk *d)
|
||||
#if 0
|
||||
printf(" real_geom=%lu/%lu/%lu",d->real_cyl,d->real_hd,d->real_sect);
|
||||
#endif
|
||||
printf(" bios_geom=%lu/%lu/%lu\n",d->bios_cyl,d->bios_hd,d->bios_sect);
|
||||
printf(" bios_geom=%lu/%lu/%lu = %lu\n",
|
||||
d->bios_cyl,d->bios_hd,d->bios_sect,
|
||||
d->bios_cyl*d->bios_hd*d->bios_sect);
|
||||
printf(" boot1=%p, boot2=%p, bootmgr=%p\n",
|
||||
d->boot1,d->boot2,d->bootmgr);
|
||||
Debug_Chunk(d->chunks);
|
||||
@@ -283,7 +285,7 @@ Collapse_Disk(struct disk *d)
|
||||
}
|
||||
#endif
|
||||
|
||||
static char * device_list[] = {"wd","sd",0};
|
||||
static char * device_list[] = {"wd","sd","od",0};
|
||||
|
||||
char **
|
||||
Disk_Names()
|
||||
@@ -345,3 +347,40 @@ Set_Boot_Blocks(struct disk *d, const u_char *b1, const u_char *b2)
|
||||
if(!d->boot2) err(1,"malloc failed");
|
||||
memcpy(d->boot2,b2,15*512);
|
||||
}
|
||||
|
||||
const char *
|
||||
slice_type_name( int type, int subtype )
|
||||
{
|
||||
switch (type) {
|
||||
case 0: return "whole";
|
||||
case 1: switch (subtype) {
|
||||
case 1: return "fat (12-bit)";
|
||||
case 2: return "XENIX /";
|
||||
case 3: return "XENIX /usr";
|
||||
case 4: return "fat (16-bit)";
|
||||
case 5: return "extended DOS";
|
||||
case 6: return "fat (>32Mb)";
|
||||
case 7: return "NTFS/HPFS";
|
||||
case 10: return "OS/2 bootmgr";
|
||||
case 84: return "OnTrack diskmgr";
|
||||
case 100: return "Netware 2.x";
|
||||
case 101: return "Netware 3.x";
|
||||
case 128: return "Minix 1.1";
|
||||
case 129: return "Minix 1.5";
|
||||
case 130: return "linux_swap";
|
||||
case 131: return "ext2fs";
|
||||
case 183: return "bsd/os";
|
||||
case 184: return "bsd/os swap";
|
||||
default: return "unknown";
|
||||
}
|
||||
case 2: return "fat";
|
||||
case 3: switch (subtype) {
|
||||
case 165: return "freebsd";
|
||||
default: return "unknown";
|
||||
}
|
||||
case 4: return "extended";
|
||||
case 5: return "part";
|
||||
case 6: return "unused";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
+20
-1
@@ -25,7 +25,7 @@
|
||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $Id: libdisk.3,v 1.2 1996/03/24 18:55:38 joerg Exp $
|
||||
.\" $Id: libdisk.3,v 1.1.2.2 1996/05/28 22:51:15 jkh Exp $
|
||||
.\" "
|
||||
.Dd March 15, 1996
|
||||
.Dt LIBDISK 3
|
||||
@@ -57,11 +57,19 @@
|
||||
.Nm MakeDevDisk ,
|
||||
.Nm ShowChunkFlags ,
|
||||
.Nm ChunkCanBeRoot ,
|
||||
.Nm chunk_n ,
|
||||
.Nm slice_type_name
|
||||
.Nd library interface to slice and partition labels
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/types.h>
|
||||
.Fd #include <libdisk.h>
|
||||
.Dv extern const u_char *boot1, boot2;
|
||||
.\" What is the correct way to cause a single line break ???
|
||||
.Bd -literal
|
||||
.Dv extern const char *chunk_n[];
|
||||
.Ed
|
||||
.Ft const char *
|
||||
.Fn slice_type_name "int type" "int subtype"
|
||||
.Ft struct disk *
|
||||
.Fn Open_Disk "const char *devname"
|
||||
.Ft struct disk *
|
||||
@@ -310,6 +318,17 @@ returns a string to show flags.
|
||||
.Pp
|
||||
.Fn ChunkCanBeRoot
|
||||
returns NULL if chunk can be
|
||||
.Pp
|
||||
Chunk name strings can be accessed directly using the external array
|
||||
.Va chunk_n .
|
||||
.Pp
|
||||
.Fn slice_type_name
|
||||
returns the name strings associated with the specified
|
||||
.Ql type .
|
||||
.Ql subtype .
|
||||
If
|
||||
.Fn slice_type_name
|
||||
returns "unknown" for slices it isn't familar with.
|
||||
.Ql / .
|
||||
.Sh AUTHOR
|
||||
.Nm Libdisk
|
||||
|
||||
+12
-15
@@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: libdisk.h,v 1.22 1996/04/29 06:45:33 jkh Exp $
|
||||
* $Id: libdisk.h,v 1.19.2.4 1996/05/28 22:51:17 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -28,11 +28,6 @@ struct disk {
|
||||
char *name;
|
||||
u_long flags;
|
||||
# define DISK_ON_TRACK 1
|
||||
#if 0
|
||||
u_long real_cyl;
|
||||
u_long real_hd;
|
||||
u_long real_sect;
|
||||
#endif
|
||||
u_long bios_cyl;
|
||||
u_long bios_hd;
|
||||
u_long bios_sect;
|
||||
@@ -91,6 +86,11 @@ struct chunk {
|
||||
extern const char *chunk_n[];
|
||||
extern const u_char boot1[], boot2[];
|
||||
|
||||
const char *
|
||||
slice_type_name( int type, int subtype );
|
||||
/* "chunk_n" for subtypes too
|
||||
*/
|
||||
|
||||
struct disk *
|
||||
Open_Disk(const char *devname);
|
||||
/* Will open the named disk, and return populated tree.
|
||||
@@ -111,19 +111,16 @@ Debug_Disk(struct disk *disk);
|
||||
/* Print the content of the tree to stdout
|
||||
*/
|
||||
|
||||
#if 0
|
||||
struct disk *
|
||||
Set_Phys_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
|
||||
/* Use a different physical geometry. Makes sense for ST506 disks only.
|
||||
* The tree returned is read from the disk, using this geometry.
|
||||
*/
|
||||
#endif
|
||||
|
||||
void
|
||||
Set_Bios_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
|
||||
/* Set the geometry the bios uses.
|
||||
*/
|
||||
|
||||
void
|
||||
Sanitize_Bios_Geom(struct disk *disk);
|
||||
/* Set the bios geometry to something sane
|
||||
*/
|
||||
|
||||
int
|
||||
Delete_Chunk(struct disk *disk, struct chunk *);
|
||||
/* Free a chunk of disk_space
|
||||
@@ -278,7 +275,7 @@ __END_DECLS
|
||||
*
|
||||
*Sample output from tst01:
|
||||
*
|
||||
* Debug_Disk(wd0) flags=0 real_geom=0/0/0 bios_geom=0/0/0
|
||||
* Debug_Disk(wd0) flags=0 bios_geom=0/0/0
|
||||
* >> 0x3d040 0 1411200 1411199 wd0 0 whole 0 0
|
||||
* >>>> 0x3d080 0 960120 960119 wd0s1 3 freebsd 0 8
|
||||
* >>>>>> 0x3d100 0 40960 40959 wd0s1a 5 part 0 0
|
||||
|
||||
+5
-21
@@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: tst01.c,v 1.15.2.3 1996/05/28 22:51:18 jkh Exp $
|
||||
* $Id: tst01.c,v 1.15.2.4 1996/07/09 12:19:03 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -196,6 +196,10 @@ main(int argc, char **argv)
|
||||
All_FreeBSD(d, 1);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(*cmds,"sanitize")) {
|
||||
Sanitize_Bios_Geom(d);
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp(*cmds,"bios") && ncmd == 4) {
|
||||
Set_Bios_Geom(d,
|
||||
strtol(cmds[1],0,0),
|
||||
@@ -203,26 +207,6 @@ main(int argc, char **argv)
|
||||
strtol(cmds[3],0,0));
|
||||
continue;
|
||||
}
|
||||
#if 0
|
||||
if (!strcasecmp(*cmds,"phys") && ncmd == 4) {
|
||||
d = Set_Phys_Geom(d,
|
||||
strtol(cmds[1],0,0),
|
||||
strtol(cmds[2],0,0),
|
||||
strtol(cmds[3],0,0));
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
if (!strcasecmp(*cmds,"collapse")) {
|
||||
if (cmds[1])
|
||||
while (Collapse_Chunk(d,
|
||||
(struct chunk *)strtol(cmds[1],0,0)))
|
||||
;
|
||||
else
|
||||
Collapse_Disk(d);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (!strcasecmp(*cmds,"list")) {
|
||||
cp = Disk_Names();
|
||||
printf("Disks:");
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: write_disk.c,v 1.17 1996/04/29 05:03:02 jkh Exp $
|
||||
* $Id: write_disk.c,v 1.14.2.3 1996/05/28 22:51:19 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -80,15 +80,9 @@ Write_FreeBSD(int fd, struct disk *new, struct disk *old, struct chunk *c1)
|
||||
|
||||
dl->d_secsize = 512;
|
||||
dl->d_secperunit = new->chunks->size;
|
||||
#if 0
|
||||
dl->d_ncylinders = new->real_cyl ? new->real_cyl : new->bios_cyl;
|
||||
dl->d_ntracks = new->real_hd ? new->real_hd : new->bios_hd;
|
||||
dl->d_nsectors = new->real_sect ? new->real_sect : new->bios_sect;
|
||||
#else
|
||||
dl->d_ncylinders = new->bios_cyl;
|
||||
dl->d_ntracks = new->bios_hd;
|
||||
dl->d_nsectors = new->bios_sect;
|
||||
#endif
|
||||
dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors;
|
||||
|
||||
dl->d_npartitions = MAXPARTITIONS;
|
||||
|
||||
+19
-1
@@ -1,10 +1,28 @@
|
||||
LIB= ftpio
|
||||
CFLAGS+= -I${.CURDIR} -Wall
|
||||
SRCS= ftpio.c
|
||||
SRCS= ftpio.c ftperr.c
|
||||
MAN3= ftpio.3
|
||||
CLEANFILES+= ftperr.c
|
||||
|
||||
SHLIB_MAJOR= 4
|
||||
SHLIB_MINOR= 0
|
||||
|
||||
beforeinstall:
|
||||
cd ${.CURDIR}; cmp -s ftpio.h ${DESTDIR}/usr/include/ftpio.h || \
|
||||
${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 ftpio.h ${DESTDIR}/usr/include
|
||||
|
||||
ftperr.c: ftp.errors
|
||||
@echo '#include <stdio.h>' > ${.TARGET}
|
||||
@echo '#include "ftpio.h"' >> ${.TARGET}
|
||||
@echo "struct ftperr ftpErrList[] = {" \ >> ${.TARGET}
|
||||
@cat ${.ALLSRC} \
|
||||
| grep -v ^# \
|
||||
| sort \
|
||||
| while read NUM STRING; do \
|
||||
echo " { $${NUM}, \"$${STRING}\" },"; \
|
||||
done >> ${.TARGET}
|
||||
@echo "};" >> ${.TARGET}
|
||||
@echo -n "int const ftpErrListLength = " >> ${.TARGET}
|
||||
@echo "sizeof(ftpErrList) / sizeof(*ftpErrList);" >> ${.TARGET}
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
@@ -0,0 +1,44 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
# This list is taken from RFC 959.
|
||||
# It probably needs a going over.
|
||||
#
|
||||
110 Restart marker reply
|
||||
120 Service ready in a few minutes
|
||||
125 Data connection already open; transfer starting
|
||||
150 File status okay; about to open data connection
|
||||
200 Command okay
|
||||
202 Command not implemented, superfluous at this site
|
||||
211 System status, or system help reply
|
||||
212 Directory status
|
||||
213 File status
|
||||
214 Help message
|
||||
215 Set system type
|
||||
220 Service ready for new user
|
||||
221 Service closing control connection
|
||||
225 Data connection open; no transfer in progress
|
||||
226 Requested file action successful
|
||||
227 Entering Passive Mode
|
||||
230 User logged in, proceed
|
||||
250 Requested file action okay, completed
|
||||
257 File/directory created
|
||||
331 User name okay, need password
|
||||
332 Need account for login
|
||||
350 Requested file action pending further information
|
||||
421 Service not available, closing control connection
|
||||
425 Can't open data connection
|
||||
426 Connection closed; transfer aborted
|
||||
450 File unavailable (e.g., file busy)
|
||||
451 Requested action aborted: local error in processing
|
||||
452 Insufficient storage space in system
|
||||
500 Syntax error, command unrecognized
|
||||
501 Syntax error in parameters or arguments
|
||||
502 Command not implemented
|
||||
503 Bad sequence of commands
|
||||
504 Command not implemented for that parameter
|
||||
530 Not logged in
|
||||
532 Need account for storing files
|
||||
550 File unavailable (e.g., file not found, no access)
|
||||
551 Requested action aborted. Page type unknown
|
||||
552 Exceeded storage allocation
|
||||
553 File name not allowed
|
||||
@@ -1,257 +0,0 @@
|
||||
/*
|
||||
* Copyright (c)1995, 1996 Jordan Hubbard
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code may be used, modified, copied, distributed, and
|
||||
* sold, in both source and binary form provided that the above
|
||||
* copyright and these terms are retained, verbatim, as the first
|
||||
* lines of this file. Under no circumstances is the author
|
||||
* responsible for the proper functioning of the software nor does
|
||||
* the author assume any responsibility for damages incurred with
|
||||
* its use.
|
||||
*
|
||||
* $Id: ftp_pkg.c,v 1.1.1.1 1996/06/17 12:26:06 jkh Exp $
|
||||
*
|
||||
* TCL Interface code for functions provided by the ftp library.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ftpio.h>
|
||||
#include "ftp_pkg.h"
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (1)
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
|
||||
#define CHECK_ARGS(cnt, myname, str) \
|
||||
if (argc <= (cnt)) { sprintf(interp->result, "usage: %s %s", myname, str); return TCL_ERROR; }
|
||||
|
||||
#define USAGE(myname, msg) \
|
||||
{ fprintf(stderr, "%s: %s\n", myname, msg); return TCL_ERROR; }
|
||||
|
||||
|
||||
/* Registration function */
|
||||
int
|
||||
Ftp_Init(Tcl_Interp *interp)
|
||||
{
|
||||
Tcl_CreateCommand (interp, "ftp_login", Ftp_login, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_chdir", Ftp_chdir, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_getsize", Ftp_getsize, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_get", Ftp_get, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_put", Ftp_put, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_binary", Ftp_binary, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_passive", Ftp_passive, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_get_url", Ftp_get_url, NULL, NULL);
|
||||
Tcl_CreateCommand (interp, "ftp_put_url", Ftp_put_url, NULL, NULL);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_login host user passwd port
|
||||
* -- returns new fileId
|
||||
*
|
||||
*/
|
||||
int
|
||||
Ftp_login(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *user, *pass;
|
||||
int port;
|
||||
|
||||
CHECK_ARGS(1, argv[0], "host [user] [passwd] [port]");
|
||||
|
||||
user = (argc > 2) ? argv[2] : "ftp";
|
||||
pass = (argc > 3) ? argv[3] : "setup@";
|
||||
port = (argc > 4) ? atoi(argv[4]) : 21;
|
||||
/* Debug("ftp_pkg: attempt login to host %s using %s/%s (port %d)", argv[1], user, pass, port); */
|
||||
fp = ftpLogin(argv[1], user, pass, port);
|
||||
if (fp) {
|
||||
/* Debug("ftp_pkg: logged successfully into host %s", argv[1]); */
|
||||
Tcl_EnterFile(interp, fp, TCL_FILE_READABLE | TCL_FILE_WRITABLE);
|
||||
return TCL_OK;
|
||||
}
|
||||
/* Debug("ftp_pkg: login operation failed for host %s", argv[1]); */
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_chdir file-handle newdir
|
||||
* -- returns status
|
||||
*/
|
||||
int
|
||||
Ftp_chdir(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
CHECK_ARGS(2, argv[0], "fileId directory");
|
||||
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
/* Debug("ftp_pkg: attempt chdir to dir %s", argv[2]); */
|
||||
if (!ftpChdir(fp, argv[2])) {
|
||||
/* Debug("ftp_pkg: chdir successful"); */
|
||||
return TCL_OK;
|
||||
}
|
||||
/* Debug("ftp_pkg: chdir failed"); */
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_getsize file-handle filename
|
||||
* -- returns size
|
||||
*/
|
||||
int
|
||||
Ftp_getsize(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
int sz;
|
||||
|
||||
CHECK_ARGS(2, argv[0], "fileId filename");
|
||||
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
/* Debug("ftp_pkg: attempt to get size of %s", argv[2]); */
|
||||
if ((sz = ftpGetSize(fp, argv[2])) >= 0) {
|
||||
/* Debug("ftp_pkg: getsize successful (%d)", sz); */
|
||||
sprintf(interp->result, "%d", sz);
|
||||
return TCL_OK;
|
||||
}
|
||||
/* Debug("ftp_pkg: chdir failed"); */
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_get fileId filename
|
||||
* -- returns new fileId for filename
|
||||
*
|
||||
*/
|
||||
int
|
||||
Ftp_get(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp, *fp2;
|
||||
|
||||
CHECK_ARGS(2, argv[0], "fileId filename");
|
||||
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
/* Debug("ftp_pkg: attempt to get file %s", argv[2]); */
|
||||
fp2 = ftpGet(fp, argv[2]);
|
||||
if (fp2) {
|
||||
/* Debug("ftp_pkg: get operation successful for: %s", argv[2]); */
|
||||
Tcl_EnterFile(interp, fp2, TCL_FILE_READABLE);
|
||||
return TCL_OK;
|
||||
}
|
||||
/* Debug("ftp_pkg: get operation failed for file %s", argv[2]); */
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_put fileId filename
|
||||
* -- returns new fileId for filename
|
||||
*
|
||||
*/
|
||||
int
|
||||
Ftp_put(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp, *fp2;
|
||||
|
||||
CHECK_ARGS(2, argv[0], "fileId filename");
|
||||
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
/* Debug("ftp_pkg: attempt to put file %s", argv[2]); */
|
||||
fp2 = ftpPut(fp, argv[2]);
|
||||
if (fp2) {
|
||||
/* Debug("ftp_pkg: put operation successful for: %s", argv[2]); */
|
||||
Tcl_EnterFile(interp, fp2, TCL_FILE_READABLE);
|
||||
return TCL_OK;
|
||||
}
|
||||
/* Debug("ftp_pkg: put operation failed for file %s", argv[2]); */
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_binary fileId value
|
||||
* -- Set binary mode to truth value for FTP session represented by fileId
|
||||
*
|
||||
*/
|
||||
int
|
||||
Ftp_binary(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
CHECK_ARGS(1, argv[0], "fileId");
|
||||
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
/* Debug("ftp_pkg: set binary mode"); */
|
||||
ftpBinary(fp);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_passive fileId value
|
||||
* -- Set passive mode to truth value for FTP session represented by fileId
|
||||
*
|
||||
*/
|
||||
int
|
||||
Ftp_passive(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
CHECK_ARGS(2, argv[0], "fileId bool");
|
||||
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
|
||||
return TCL_ERROR;
|
||||
/* Debug("ftp_pkg: set passive mode to %d", atoi(argv[2])); */
|
||||
ftpPassive(fp, atoi(argv[2]));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_get_url URL user pass
|
||||
* -- Return new fileId for open URL (using user and pass to log in)
|
||||
*
|
||||
*/
|
||||
int
|
||||
Ftp_get_url(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *user, *pass;
|
||||
|
||||
CHECK_ARGS(1, argv[0], "URL [username] [password]");
|
||||
user = (argc > 2) ? argv[2] : "ftp";
|
||||
pass = (argc > 3) ? argv[3] : "setup@";
|
||||
/* Debug("ftp_pkg: attempt to get URL %s as %s/%s", argv[1], user, pass); */
|
||||
fp = ftpGetURL(argv[1], user, pass);
|
||||
if (fp) {
|
||||
/* Debug("ftp_pkg: get URL successful"); */
|
||||
Tcl_EnterFile(interp, fp, TCL_FILE_READABLE);
|
||||
return TCL_OK;
|
||||
}
|
||||
/* Debug("ftp_pkg: get URL failed"); */
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* ftp_put_url URL user pass
|
||||
* -- Return new fileId for open url (using user and pass to log in)
|
||||
*
|
||||
*/
|
||||
int
|
||||
Ftp_put_url(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *user, *pass;
|
||||
|
||||
CHECK_ARGS(1, argv[0], "URL [username] [password]");
|
||||
user = (argc > 2) ? argv[2] : "ftp";
|
||||
pass = (argc > 3) ? argv[3] : "setup@";
|
||||
/* Debug("ftp_pkg: attempt to put URL %s as %s/%s", argv[1], user, pass); */
|
||||
fp = ftpPutURL(argv[1], user, pass);
|
||||
if (fp) {
|
||||
/* Debug("ftp_pkg: put URL successful"); */
|
||||
Tcl_EnterFile(interp, fp, TCL_FILE_READABLE);
|
||||
return TCL_OK;
|
||||
}
|
||||
/* Debug("ftp_pkg: put URL failed"); */
|
||||
return TCL_ERROR;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef _FTP_PKG_H
|
||||
#define _FTP_PKG_H
|
||||
|
||||
/*
|
||||
* Copyright (c)1995, 1996 Jordan Hubbard
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code may be used, modified, copied, distributed, and
|
||||
* sold, in both source and binary form provided that the above
|
||||
* copyright and these terms are retained, verbatim, as the first
|
||||
* lines of this file. Under no circumstances is the author
|
||||
* responsible for the proper functioning of the software nor does
|
||||
* the author assume any responsibility for damages incurred with
|
||||
* its use.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* TCL Interface code for functions provided by the ftp library.
|
||||
*/
|
||||
|
||||
#include <tcl.h>
|
||||
#include <ftpio.h>
|
||||
|
||||
extern int Ftp_login (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_chdir (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_getsize (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_get (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_put (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_binary (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_passive (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_get_url (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
extern int Ftp_put_url (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
|
||||
|
||||
#endif /* _FTP_PKG_H */
|
||||
+19
-14
@@ -22,6 +22,7 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $Id$
|
||||
.\"
|
||||
.Dd June 17, 1996
|
||||
.Dt ftpio 3
|
||||
@@ -43,11 +44,13 @@
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <ftpio.h>
|
||||
.Ft FILE *
|
||||
.Fn ftpLogin "char *host, char *user, char *passwd, int ftp_port"
|
||||
.Fn ftpLogin "char *host" "char *user" "char *passwd" "int ftp_port" "int verbose" "int *retcode"
|
||||
.Ft int
|
||||
.Fn ftpChdir "FILE *stream, char *dirname"
|
||||
.Ft int
|
||||
.Fn ftpErrno "FILE *stream"
|
||||
.Ft const char *
|
||||
.Fn ftpErrString "int errno"
|
||||
.Ft time_t
|
||||
.Fn ftpGetModtime "FILE *stream, char *file"
|
||||
.Ft size_t
|
||||
@@ -65,9 +68,9 @@
|
||||
.Ft void
|
||||
.Fn ftpVerbose "FILE *stream, int status"
|
||||
.Ft FILE *
|
||||
.Fn ftpGetURL "char *url, char *user, char *passwd"
|
||||
.Fn ftpGetURL "char *url, char *user, char *passwd, int *retcode"
|
||||
.Ft FILE *
|
||||
.Fn ftpPutURL "char *url, char *user, char *passwd"
|
||||
.Fn ftpPutURL "char *url, char *user, char *passwd, int *retcode"
|
||||
|
||||
.Sh DESCRIPTION
|
||||
These functions implement a high-level library for managing FTP connections.
|
||||
@@ -75,25 +78,28 @@ These functions implement a high-level library for managing FTP connections.
|
||||
.Fn ftpLogin
|
||||
attempts to log in using the supplied
|
||||
.Fa user ,
|
||||
.Fa passwd
|
||||
and
|
||||
.Fa passwd,
|
||||
.Fa ftp_port
|
||||
fields (if passed as 0,
|
||||
(if passed as 0,
|
||||
.Fa ftp_port
|
||||
defaults to the standard ftp port of 21). If it is successful, a
|
||||
defaults to the standard ftp port of 21) and
|
||||
.Fa verbose
|
||||
fields. If it is successful, a
|
||||
standard stream descriptor is returned which should be passed to
|
||||
subsequent FTP operations. On failure, NULL is returned and
|
||||
.Fn ftpErrno
|
||||
will return the error code returned by the foreign server.
|
||||
.Fa retcode
|
||||
will have the error code returned by the foreign server.
|
||||
.Pp
|
||||
.Fn ftpChdir
|
||||
attempts to issue a server CD command to the the directory named in
|
||||
attempts to issue a server CD command to the directory named in
|
||||
.Fa dir.
|
||||
On success, zero is returned. On failure, the error code from the server.
|
||||
.Pp
|
||||
.Fn ftpErrno
|
||||
returns the server failure code for the last operation (useful for seeing
|
||||
more about what happened if you're familiar with FTP error codes).
|
||||
.Fn ftpErrString
|
||||
returns a human readable version of the supplied server failure code.
|
||||
.Pp
|
||||
.Fn ftpGet
|
||||
attempts to retreive the file named by the
|
||||
@@ -108,7 +114,7 @@ as a restart point for the file, that is to say that the stream
|
||||
returned will point
|
||||
.Fa *seekto
|
||||
bytes into the file gotten (this is handy for restarting failed
|
||||
transfers efficiently). If the seek operation succeeds, the value
|
||||
transfers efficiently). If the seek operation fails, the value
|
||||
of
|
||||
.Fa *seekto
|
||||
will be zero'd.
|
||||
@@ -186,8 +192,7 @@ all my tests.
|
||||
.Sh HISTORY
|
||||
Started life as Poul-Henning Kamp's ftp driver for the system installation
|
||||
utility, later significantly mutated into a more general form as an
|
||||
extension of stdio and given a TCL interface (not enabled by default)
|
||||
by Jordan Hubbard. Also incorporates some ideas and extensions from
|
||||
Jean-Marc Zucconi.
|
||||
extension of stdio by Jordan Hubbard. Also incorporates some ideas and
|
||||
extensions from Jean-Marc Zucconi.
|
||||
.Sh AUTHORS
|
||||
Jordan Hubbard, Poul-Henning Kamp and Jean-Marc Zucconi
|
||||
+209
-81
@@ -14,26 +14,27 @@
|
||||
* Turned inside out. Now returns xfers as new file ids, not as a special
|
||||
* `state' of FTP_t
|
||||
*
|
||||
* $Id: ftpio.c,v 1.4.2.2 1996/06/24 02:30:36 jkh Exp $
|
||||
* $Id: ftpio.c,v 1.4.2.3 1996/07/04 05:47:30 jkh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <ftpio.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SUCCESS 0
|
||||
#define FAILURE -1
|
||||
@@ -44,7 +45,7 @@
|
||||
#endif
|
||||
|
||||
/* How to see by a given code whether or not the connection has timed out */
|
||||
#define FTP_TIMEOUT(code) (code == 421)
|
||||
#define FTP_TIMEOUT(code) (FtpTimedOut || code == FTP_TIMED_OUT)
|
||||
|
||||
/* Internal routines - deal only with internal FTP_t type */
|
||||
static FTP_t ftp_new(void);
|
||||
@@ -57,23 +58,32 @@ static __inline char *get_a_line(FTP_t ftp);
|
||||
static int get_a_number(FTP_t ftp, char **q);
|
||||
static int botch(char *func, char *botch_state);
|
||||
static int cmd(FTP_t ftp, const char *fmt, ...);
|
||||
static int ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port);
|
||||
static int ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *seekto);
|
||||
static int ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port, int verbose);
|
||||
static int ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, off_t *seekto);
|
||||
static int ftp_close(FTP_t ftp);
|
||||
static int get_url_info(char *url_in, char *host_ret, int *port_ret, char *name_ret);
|
||||
static void ftp_timeout(int sig);
|
||||
static void ftp_set_timeout(void);
|
||||
static void ftp_clear_timeout(void);
|
||||
|
||||
|
||||
/* Global status variable - ick */
|
||||
int FtpTimedOut;
|
||||
|
||||
/* FTP status codes */
|
||||
#define FTP_ASCII_HAPPY 200
|
||||
#define FTP_BINARY_HAPPY 200
|
||||
#define FTP_PORT_HAPPY 200
|
||||
/* FTP happy status codes */
|
||||
#define FTP_GENERALLY_HAPPY 200
|
||||
#define FTP_ASCII_HAPPY FTP_GENERALLY_HAPPY
|
||||
#define FTP_BINARY_HAPPY FTP_GENERALLY_HAPPY
|
||||
#define FTP_PORT_HAPPY FTP_GENERALLY_HAPPY
|
||||
#define FTP_HAPPY_COMMENT 220
|
||||
#define FTP_QUIT_HAPPY 221
|
||||
#define FTP_TRANSFER_HAPPY 226
|
||||
#define FTP_PASSIVE_HAPPY 227
|
||||
#define FTP_CHDIR_HAPPY 250
|
||||
|
||||
/* FTP unhappy status codes */
|
||||
#define FTP_TIMED_OUT 421
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* gross! evil! bad! We really need an access primitive for cookie in stdio itself.
|
||||
@@ -97,11 +107,11 @@ check_code(FTP_t ftp, int var, int preferred)
|
||||
while (1) {
|
||||
if (var == preferred)
|
||||
return 0;
|
||||
else if (var == 226) /* last operation succeeded */
|
||||
else if (var == FTP_TRANSFER_HAPPY) /* last operation succeeded */
|
||||
var = get_a_number(ftp, NULL);
|
||||
else if (var == 220) /* chit-chat */
|
||||
else if (var == FTP_HAPPY_COMMENT) /* chit-chat */
|
||||
var = get_a_number(ftp, NULL);
|
||||
else if (var == 200) /* success codes */
|
||||
else if (var == FTP_GENERALLY_HAPPY) /* general success code */
|
||||
var = get_a_number(ftp, NULL);
|
||||
else {
|
||||
ftp->errno = var;
|
||||
@@ -165,22 +175,42 @@ ftpErrno(FILE *fp)
|
||||
return ftp->errno;
|
||||
}
|
||||
|
||||
size_t
|
||||
const char *
|
||||
ftpErrString(int errno)
|
||||
{
|
||||
int k;
|
||||
|
||||
if (errno == -1)
|
||||
return("connection in wrong state");
|
||||
for (k = 0; k < ftpErrListLength; k++)
|
||||
if (ftpErrList[k].num == errno)
|
||||
return(ftpErrList[k].string);
|
||||
return("Unknown error");
|
||||
}
|
||||
|
||||
off_t
|
||||
ftpGetSize(FILE *fp, char *name)
|
||||
{
|
||||
int i;
|
||||
char p[BUFSIZ], *cp;
|
||||
char p[BUFSIZ], *cp, *ep;
|
||||
FTP_t ftp = fcookie(fp);
|
||||
off_t size;
|
||||
|
||||
check_passive(fp);
|
||||
sprintf(p, "SIZE %s\r\n", name);
|
||||
i = writes(ftp->fd_ctrl, p);
|
||||
if (i)
|
||||
return (size_t)-1;
|
||||
if (ftp->is_verbose)
|
||||
fprintf(stderr, "Sending %s", p);
|
||||
if (writes(ftp->fd_ctrl, p))
|
||||
return (off_t)-1;
|
||||
i = get_a_number(ftp, &cp);
|
||||
if (check_code(ftp, i, 213))
|
||||
return (size_t)-1;
|
||||
return (size_t)atoi(cp);
|
||||
return (off_t)-1;
|
||||
|
||||
errno = 0; /* to check for ERANGE */
|
||||
size = (off_t)strtoq(cp, &ep, 10);
|
||||
if (*ep != '\0' || errno == ERANGE)
|
||||
return (off_t)-1;
|
||||
return size;
|
||||
}
|
||||
|
||||
time_t
|
||||
@@ -194,8 +224,9 @@ ftpGetModtime(FILE *fp, char *name)
|
||||
|
||||
check_passive(fp);
|
||||
sprintf(p, "MDTM %s\r\n", name);
|
||||
i = writes(ftp->fd_ctrl, p);
|
||||
if (i)
|
||||
if (ftp->is_verbose)
|
||||
fprintf(stderr, "Sending %s", p);
|
||||
if (writes(ftp->fd_ctrl, p))
|
||||
return (time_t)0;
|
||||
i = get_a_number(ftp, &cp);
|
||||
if (check_code(ftp, i, 213))
|
||||
@@ -215,7 +246,7 @@ ftpGetModtime(FILE *fp, char *name)
|
||||
}
|
||||
|
||||
FILE *
|
||||
ftpGet(FILE *fp, char *file, int *seekto)
|
||||
ftpGet(FILE *fp, char *file, off_t *seekto)
|
||||
{
|
||||
FILE *fp2;
|
||||
FTP_t ftp = fcookie(fp);
|
||||
@@ -231,20 +262,40 @@ ftpGet(FILE *fp, char *file, int *seekto)
|
||||
|
||||
/* Returns a standard FILE pointer type representing an open control connection */
|
||||
FILE *
|
||||
ftpLogin(char *host, char *user, char *passwd, int port)
|
||||
ftpLogin(char *host, char *user, char *passwd, int port, int verbose, int *retcode)
|
||||
{
|
||||
FTP_t n;
|
||||
FILE *fp;
|
||||
|
||||
if (retcode)
|
||||
*retcode = 0;
|
||||
if (networkInit() != SUCCESS)
|
||||
return NULL;
|
||||
|
||||
n = ftp_new();
|
||||
fp = NULL;
|
||||
if (n && ftp_login_session(n, host, user, passwd, port) == SUCCESS) {
|
||||
if (n && ftp_login_session(n, host, user, passwd, port, verbose) == SUCCESS) {
|
||||
fp = funopen(n, ftp_read_method, ftp_write_method, NULL, ftp_close_method); /* BSD 4.4 function! */
|
||||
fp->_file = n->fd_ctrl;
|
||||
}
|
||||
if (retcode) {
|
||||
if (!n)
|
||||
*retcode = (FtpTimedOut ? FTP_TIMED_OUT : -1);
|
||||
/* Poor attempt at mapping real errnos to FTP error codes */
|
||||
else switch(n->errno) {
|
||||
case EADDRNOTAVAIL:
|
||||
*retcode = FTP_TIMED_OUT; /* Actually no such host, but we have no way of saying that. :-( */
|
||||
break;
|
||||
|
||||
case ETIMEDOUT:
|
||||
*retcode = FTP_TIMED_OUT;
|
||||
break;
|
||||
|
||||
default:
|
||||
*retcode = n->errno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
@@ -269,7 +320,7 @@ ftpPassive(FILE *fp, int st)
|
||||
|
||||
if (ftp->is_passive == st)
|
||||
return SUCCESS;
|
||||
i = cmd(ftp, "PASSIVE");
|
||||
i = cmd(ftp, "PASV");
|
||||
if (i < 0)
|
||||
return i;
|
||||
ftp->is_passive = !ftp->is_passive;
|
||||
@@ -277,21 +328,49 @@ ftpPassive(FILE *fp, int st)
|
||||
}
|
||||
|
||||
FILE *
|
||||
ftpGetURL(char *url, char *user, char *passwd)
|
||||
ftpGetURL(char *url, char *user, char *passwd, int *retcode)
|
||||
{
|
||||
char host[255], name[255];
|
||||
int port;
|
||||
static FILE *fp = NULL;
|
||||
FILE *fp2;
|
||||
static FILE *fp = NULL;
|
||||
static char *prev_host;
|
||||
|
||||
if (fp) { /* Close previous managed connection */
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
}
|
||||
if (retcode)
|
||||
*retcode = 0;
|
||||
if (get_url_info(url, host, &port, name) == SUCCESS) {
|
||||
fp = ftpLogin(host, user, passwd, port);
|
||||
if (fp && prev_host) {
|
||||
if (!strcmp(prev_host, host)) {
|
||||
/* Try to use cached connection */
|
||||
fp2 = ftpGet(fp, name, NULL);
|
||||
if (!fp2) {
|
||||
/* Connection timed out or was no longer valid */
|
||||
fclose(fp);
|
||||
free(prev_host);
|
||||
prev_host = NULL;
|
||||
}
|
||||
else
|
||||
return fp2;
|
||||
}
|
||||
else {
|
||||
/* It's a different host now, flush old */
|
||||
fclose(fp);
|
||||
free(prev_host);
|
||||
prev_host = NULL;
|
||||
}
|
||||
}
|
||||
fp = ftpLogin(host, user, passwd, port, 0, retcode);
|
||||
if (fp) {
|
||||
fp2 = ftpGet(fp, name, NULL);
|
||||
if (!fp2) {
|
||||
/* Connection timed out or was no longer valid */
|
||||
if (retcode)
|
||||
*retcode = ftpErrno(fp);
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
}
|
||||
else
|
||||
prev_host = strdup(host);
|
||||
return fp2;
|
||||
}
|
||||
}
|
||||
@@ -299,21 +378,29 @@ ftpGetURL(char *url, char *user, char *passwd)
|
||||
}
|
||||
|
||||
FILE *
|
||||
ftpPutURL(char *url, char *user, char *passwd)
|
||||
ftpPutURL(char *url, char *user, char *passwd, int *retcode)
|
||||
{
|
||||
char host[255], name[255];
|
||||
int port;
|
||||
static FILE *fp = NULL;
|
||||
FILE *fp2;
|
||||
|
||||
if (retcode)
|
||||
*retcode = 0;
|
||||
if (fp) { /* Close previous managed connection */
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
}
|
||||
if (get_url_info(url, host, &port, name) == SUCCESS) {
|
||||
fp = ftpLogin(host, user, passwd, port);
|
||||
fp = ftpLogin(host, user, passwd, port, 0, retcode);
|
||||
if (fp) {
|
||||
fp2 = ftpPut(fp, name);
|
||||
if (!fp2) {
|
||||
if (retcode)
|
||||
*retcode = ftpErrno(fp);
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
}
|
||||
return fp2;
|
||||
}
|
||||
}
|
||||
@@ -411,27 +498,48 @@ check_passive(FILE *fp)
|
||||
}
|
||||
|
||||
static void
|
||||
ftp_timeout()
|
||||
ftp_timeout(int sig)
|
||||
{
|
||||
FtpTimedOut = TRUE;
|
||||
/* Debug("ftp_pkg: ftp_timeout called - operation timed out"); */
|
||||
}
|
||||
|
||||
static struct sigaction new;
|
||||
|
||||
static void
|
||||
ftp_set_timeout(void)
|
||||
{
|
||||
char *cp;
|
||||
int ival;
|
||||
|
||||
FtpTimedOut = FALSE;
|
||||
new.sa_handler = ftp_timeout;
|
||||
sigaction(SIGALRM, &new, NULL);
|
||||
cp = getenv("FTP_TIMEOUT");
|
||||
if (!cp || !(ival = atoi(cp)))
|
||||
ival = 120;
|
||||
alarm(ival);
|
||||
}
|
||||
|
||||
static void
|
||||
ftp_clear_timeout(void)
|
||||
{
|
||||
alarm(0);
|
||||
new.sa_handler = SIG_DFL;
|
||||
sigaction(SIGALRM, &new, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
writes(int fd, char *s)
|
||||
{
|
||||
int n, i = strlen(s);
|
||||
|
||||
/* Set the timer */
|
||||
FtpTimedOut = FALSE;
|
||||
signal(SIGALRM, ftp_timeout);
|
||||
alarm(120);
|
||||
/* Debug("ftp_pkg: writing \"%s\" to ftp connection %d", s, fd); */
|
||||
ftp_set_timeout();
|
||||
n = write(fd, s, i);
|
||||
alarm(0);
|
||||
if (i != n)
|
||||
return FAILURE;
|
||||
return SUCCESS;
|
||||
ftp_clear_timeout();
|
||||
if (FtpTimedOut || i != n)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static __inline char *
|
||||
@@ -440,23 +548,19 @@ get_a_line(FTP_t ftp)
|
||||
static char buf[BUFSIZ];
|
||||
int i,j;
|
||||
|
||||
/* Set the timer */
|
||||
FtpTimedOut = FALSE;
|
||||
signal(SIGALRM, ftp_timeout);
|
||||
|
||||
/* Debug("ftp_pkg: trying to read a line from %d", ftp->fd_ctrl); */
|
||||
for(i = 0; i < BUFSIZ;) {
|
||||
alarm(120);
|
||||
ftp_set_timeout();
|
||||
j = read(ftp->fd_ctrl, buf + i, 1);
|
||||
alarm(0);
|
||||
if (j != 1)
|
||||
ftp_clear_timeout();
|
||||
if (FtpTimedOut || j != 1)
|
||||
return NULL;
|
||||
if (buf[i] == '\r' || buf[i] == '\n') {
|
||||
if (!i)
|
||||
continue;
|
||||
buf[i] = '\0';
|
||||
if (ftp->is_verbose == TRUE)
|
||||
printf("%s\n",buf+4);
|
||||
fprintf(stderr, "%s\n",buf+4);
|
||||
return buf;
|
||||
}
|
||||
i++;
|
||||
@@ -475,6 +579,8 @@ get_a_number(FTP_t ftp, char **q)
|
||||
p = get_a_line(ftp);
|
||||
if (!p) {
|
||||
ftp_close(ftp);
|
||||
if (FtpTimedOut)
|
||||
return FTP_TIMED_OUT;
|
||||
return FAILURE;
|
||||
}
|
||||
if (!(isdigit(p[0]) && isdigit(p[1]) && isdigit(p[2])))
|
||||
@@ -504,11 +610,14 @@ ftp_close(FTP_t ftp)
|
||||
int i;
|
||||
|
||||
if (ftp->con_state == isopen) {
|
||||
/* Debug("ftp_pkg: in ftp_close(), sending QUIT"); */
|
||||
i = cmd(ftp, "QUIT");
|
||||
ftp->con_state = quit;
|
||||
/* If last operation timed out, don't try to quit - just close */
|
||||
if (ftp->errno != FTP_TIMED_OUT)
|
||||
i = cmd(ftp, "QUIT");
|
||||
else
|
||||
i = FTP_QUIT_HAPPY;
|
||||
close(ftp->fd_ctrl);
|
||||
ftp->fd_ctrl = -1;
|
||||
ftp->con_state = init;
|
||||
if (check_code(ftp, i, FTP_QUIT_HAPPY)) {
|
||||
ftp->errno = i;
|
||||
return FAILURE;
|
||||
@@ -538,19 +647,23 @@ cmd(FTP_t ftp, const char *fmt, ...)
|
||||
(void)vsnprintf(p, sizeof p, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (ftp->con_state != isopen)
|
||||
if (ftp->con_state == init)
|
||||
return botch("cmd", "open");
|
||||
|
||||
strcat(p, "\r\n");
|
||||
i = writes(ftp->fd_ctrl, p);
|
||||
if (i)
|
||||
if (ftp->is_verbose)
|
||||
fprintf(stderr, "Sending: %s", p);
|
||||
if (writes(ftp->fd_ctrl, p)) {
|
||||
if (FtpTimedOut)
|
||||
return FTP_TIMED_OUT;
|
||||
return FAILURE;
|
||||
while ((i = get_a_number(ftp, NULL)) == 220);
|
||||
}
|
||||
while ((i = get_a_number(ftp, NULL)) == FTP_HAPPY_COMMENT);
|
||||
return i;
|
||||
}
|
||||
|
||||
static int
|
||||
ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port)
|
||||
ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port, int verbose)
|
||||
{
|
||||
struct hostent *he = NULL;
|
||||
struct sockaddr_in sin;
|
||||
@@ -563,6 +676,7 @@ ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port)
|
||||
|
||||
if (ftp->con_state != init) {
|
||||
ftp_close(ftp);
|
||||
ftp->errno = -1;
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@@ -582,37 +696,45 @@ ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port)
|
||||
}
|
||||
else {
|
||||
he = gethostbyname(host);
|
||||
if (!he)
|
||||
if (!he) {
|
||||
ftp->errno = 0;
|
||||
return FAILURE;
|
||||
}
|
||||
ftp->addrtype = sin.sin_family = he->h_addrtype;
|
||||
bcopy(he->h_addr, (char *)&sin.sin_addr, he->h_length);
|
||||
}
|
||||
|
||||
sin.sin_port = htons(port);
|
||||
|
||||
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
|
||||
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0) {
|
||||
ftp->errno = -1;
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
|
||||
(void)close(s);
|
||||
ftp->errno = errno;
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
ftp->fd_ctrl = s;
|
||||
ftp->con_state = isopen;
|
||||
ftp->is_verbose = verbose;
|
||||
|
||||
i = cmd(ftp, "USER %s", user);
|
||||
if (i >= 300 && i < 400)
|
||||
i = cmd(ftp, "PASS %s", passwd);
|
||||
if (i >= 299 || i < 0) {
|
||||
ftp_close(ftp);
|
||||
if (i > 0)
|
||||
ftp->errno = i;
|
||||
return FAILURE;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *seekto)
|
||||
ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, off_t *seekto)
|
||||
{
|
||||
int i,s;
|
||||
char *q;
|
||||
@@ -627,13 +749,19 @@ ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *
|
||||
if (ftp->con_state != isopen)
|
||||
return botch("ftp_file_op", "open");
|
||||
|
||||
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
|
||||
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0) {
|
||||
ftp->errno = errno;
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (ftp->is_passive) {
|
||||
if (ftp->is_verbose)
|
||||
fprintf(stderr, "Sending PASV\n");
|
||||
if (writes(ftp->fd_ctrl, "PASV\r\n")) {
|
||||
ftp_close(ftp);
|
||||
return FAILURE;
|
||||
if (FtpTimedOut)
|
||||
ftp->errno = FTP_TIMED_OUT;
|
||||
return FTP_TIMED_OUT;
|
||||
}
|
||||
i = get_a_number(ftp, &q);
|
||||
if (check_code(ftp, i, FTP_PASSIVE_HAPPY)) {
|
||||
@@ -659,15 +787,15 @@ ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *
|
||||
(void)close(s);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (seekto && *seekto) {
|
||||
i = cmd(ftp, "RETR %d", *seekto);
|
||||
i = cmd(ftp, "REST %d", *seekto);
|
||||
if (i < 0 || FTP_TIMEOUT(i)) {
|
||||
close(s);
|
||||
ftp->errno = i;
|
||||
*seekto = (off_t)0;
|
||||
return i;
|
||||
}
|
||||
else if (i != 350)
|
||||
*seekto = 0;
|
||||
}
|
||||
i = cmd(ftp, "%s %s", operation, file);
|
||||
if (i < 0 || i > 299) {
|
||||
@@ -685,7 +813,7 @@ ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *
|
||||
sin.sin_port = 0;
|
||||
i = sizeof sin;
|
||||
if (bind(s, (struct sockaddr *)&sin, i) < 0) {
|
||||
close (s);
|
||||
close(s);
|
||||
return FAILURE;
|
||||
}
|
||||
getsockname(s,(struct sockaddr *)&sin,&i);
|
||||
@@ -706,14 +834,14 @@ ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *
|
||||
return i;
|
||||
}
|
||||
if (seekto && *seekto) {
|
||||
i = cmd(ftp, "RETR %d", *seekto);
|
||||
i = cmd(ftp, "REST %d", *seekto);
|
||||
if (i < 0 || FTP_TIMEOUT(i)) {
|
||||
close(s);
|
||||
ftp->errno = i;
|
||||
return i;
|
||||
}
|
||||
else if (i != 350)
|
||||
*seekto = 0;
|
||||
*seekto = (off_t)0;
|
||||
}
|
||||
i = cmd(ftp, "%s %s", operation, file);
|
||||
if (i < 0 || i > 299) {
|
||||
|
||||
+17
-7
@@ -2,6 +2,7 @@
|
||||
#define _FTP_H_INCLUDE
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
/*
|
||||
@@ -20,12 +21,12 @@
|
||||
* Turned inside out. Now returns xfers as new file ids, not as a special
|
||||
* `state' of FTP_t
|
||||
*
|
||||
* $Id: ftpio.h,v 1.2.2.2 1996/06/26 20:33:57 gpalmer Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/* Internal housekeeping data structure for FTP sessions */
|
||||
typedef struct {
|
||||
enum { init, isopen } con_state;
|
||||
enum { init, isopen, quit } con_state;
|
||||
int fd_ctrl;
|
||||
int addrtype;
|
||||
char *host;
|
||||
@@ -36,19 +37,28 @@ typedef struct {
|
||||
int is_verbose;
|
||||
} *FTP_t;
|
||||
|
||||
/* Structure we use to match FTP error codes with readable strings */
|
||||
struct ftperr {
|
||||
const int num;
|
||||
const char *string;
|
||||
};
|
||||
extern struct ftperr ftpErrList[];
|
||||
extern int const ftpErrListLength;
|
||||
|
||||
/* Exported routines - deal only with FILE* type */
|
||||
extern FILE *ftpLogin(char *host, char *user, char *passwd, int port);
|
||||
extern FILE *ftpLogin(char *host, char *user, char *passwd, int port, int verbose, int *retcode);
|
||||
extern int ftpChdir(FILE *fp, char *dir);
|
||||
extern int ftpErrno(FILE *fp);
|
||||
extern size_t ftpGetSize(FILE *fp, char *file);
|
||||
extern FILE *ftpGet(FILE *fp, char *file, int *seekto);
|
||||
extern off_t ftpGetSize(FILE *fp, char *file);
|
||||
extern FILE *ftpGet(FILE *fp, char *file, off_t *seekto);
|
||||
extern FILE *ftpPut(FILE *fp, char *file);
|
||||
extern int ftpAscii(FILE *fp);
|
||||
extern int ftpBinary(FILE *fp);
|
||||
extern int ftpPassive(FILE *fp, int status);
|
||||
extern void ftpVerbose(FILE *fp, int status);
|
||||
extern FILE *ftpGetURL(char *url, char *user, char *passwd);
|
||||
extern FILE *ftpPutURL(char *url, char *user, char *passwd);
|
||||
extern FILE *ftpGetURL(char *url, char *user, char *passwd, int *retcode);
|
||||
extern FILE *ftpPutURL(char *url, char *user, char *passwd, int *retcode);
|
||||
extern time_t ftpGetModtime(FILE *fp, char *s);
|
||||
extern const char *ftpErrString(int errno);
|
||||
|
||||
#endif /* _FTP_H_INCLUDE */
|
||||
@@ -49,7 +49,6 @@ static char sccsid[] = "@(#)genget.c 8.1 (Berkeley) 6/4/93";
|
||||
isprefix(s1, s2)
|
||||
register char *s1, *s2;
|
||||
{
|
||||
register int n = 0;
|
||||
char *os1;
|
||||
register char c1, c2;
|
||||
|
||||
|
||||
@@ -35,9 +35,12 @@
|
||||
static char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static char *area;
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
getent(cp, name)
|
||||
char *cp, *name;
|
||||
{
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "misc.h"
|
||||
|
||||
char *RemoteHostName;
|
||||
|
||||
+6
-3
@@ -1,5 +1,5 @@
|
||||
# @(#)Makefile 5.1beta 93/09/24
|
||||
# $Id: Makefile,v 1.4 1995/03/08 01:41:40 bde Exp $
|
||||
# $Id: Makefile,v 1.5.4.1 1997/02/15 05:38:02 bde Exp $
|
||||
#
|
||||
# ====================================================
|
||||
# Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
@@ -46,14 +46,17 @@
|
||||
.PATH: ${.CURDIR}/i387
|
||||
ARCH_SRCS = e_acos.S e_asin.S e_atan2.S e_exp.S e_fmod.S e_log.S e_log10.S \
|
||||
e_remainder.S e_scalb.S e_sqrt.S s_atan.S s_ceil.S s_copysign.S \
|
||||
s_cos.S s_finite.S s_floor.S s_ilogb.S s_log1p.S s_logb.S \
|
||||
s_cos.S s_finite.S s_floor.S s_ilogb.S s_logb.S \
|
||||
s_rint.S s_scalbn.S s_significand.S s_sin.S s_tan.S
|
||||
|
||||
# Broken
|
||||
# ARCH_SRCS+= s_log1p.S
|
||||
.endif
|
||||
|
||||
.PATH: ${.CURDIR}/man
|
||||
.PATH: ${.CURDIR}/src
|
||||
|
||||
CFLAGS+= -D_MULTI_LIBM -D_POSIX_MODE -D_IEEE_LIBM
|
||||
CFLAGS+= -D_IEEE_LIBM
|
||||
|
||||
LIB= m
|
||||
COMMON_SRCS = e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \
|
||||
|
||||
@@ -35,10 +35,11 @@
|
||||
|
||||
#include <machine/asmacros.h>
|
||||
|
||||
RCSID("$Id: e_scalb.S,v 1.1.1.1 1994/08/19 09:40:00 jkh Exp $")
|
||||
RCSID("$Id: e_scalb.S,v 1.2 1994/08/19 11:14:19 jkh Exp $")
|
||||
|
||||
ENTRY(__ieee754_scalb)
|
||||
fldl 12(%esp)
|
||||
fldl 4(%esp)
|
||||
fscale
|
||||
fstp %st(1)
|
||||
ret
|
||||
@@ -35,24 +35,24 @@
|
||||
|
||||
#include <machine/asmacros.h>
|
||||
|
||||
RCSID("$Id: s_ceil.S,v 1.1.1.1 1994/08/19 09:40:00 jkh Exp $")
|
||||
RCSID("$Id: s_ceil.S,v 1.2 1994/08/19 11:14:21 jkh Exp $")
|
||||
|
||||
ENTRY(ceil)
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
subl $8,%esp
|
||||
|
||||
fstcw -12(%ebp) /* store fpu control word */
|
||||
movw -12(%ebp),%dx
|
||||
fstcw -4(%ebp) /* store fpu control word */
|
||||
movw -4(%ebp),%dx
|
||||
orw $0x0800,%dx /* round towards +oo */
|
||||
andw $0xfbff,%dx
|
||||
movw %dx,-16(%ebp)
|
||||
fldcw -16(%ebp) /* load modfied control word */
|
||||
movw %dx,-8(%ebp)
|
||||
fldcw -8(%ebp) /* load modfied control word */
|
||||
|
||||
fldl 8(%ebp); /* round */
|
||||
frndint
|
||||
|
||||
fldcw -12(%ebp) /* restore original control word */
|
||||
fldcw -4(%ebp) /* restore original control word */
|
||||
|
||||
leave
|
||||
ret
|
||||
@@ -35,24 +35,24 @@
|
||||
|
||||
#include <machine/asmacros.h>
|
||||
|
||||
RCSID("$Id: s_floor.S,v 1.1.1.1 1994/08/19 09:40:01 jkh Exp $")
|
||||
RCSID("$Id: s_floor.S,v 1.2 1994/08/19 11:14:25 jkh Exp $")
|
||||
|
||||
ENTRY(floor)
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
subl $8,%esp
|
||||
|
||||
fstcw -12(%ebp) /* store fpu control word */
|
||||
movw -12(%ebp),%dx
|
||||
fstcw -4(%ebp) /* store fpu control word */
|
||||
movw -4(%ebp),%dx
|
||||
orw $0x0400,%dx /* round towards -oo */
|
||||
andw $0xf7ff,%dx
|
||||
movw %dx,-16(%ebp)
|
||||
fldcw -16(%ebp) /* load modfied control word */
|
||||
movw %dx,-8(%ebp)
|
||||
fldcw -8(%ebp) /* load modfied control word */
|
||||
|
||||
fldl 8(%ebp); /* round */
|
||||
frndint
|
||||
|
||||
fldcw -12(%ebp) /* restore original control word */
|
||||
fldcw -4(%ebp) /* restore original control word */
|
||||
|
||||
leave
|
||||
ret
|
||||
@@ -35,10 +35,11 @@
|
||||
|
||||
#include <machine/asmacros.h>
|
||||
|
||||
RCSID("$Id: s_scalbn.S,v 1.1.1.1 1994/08/19 09:40:01 jkh Exp $")
|
||||
RCSID("$Id: s_scalbn.S,v 1.2 1994/08/19 11:14:30 jkh Exp $")
|
||||
|
||||
ENTRY(scalbn)
|
||||
fildl 12(%esp)
|
||||
fldl 4(%esp)
|
||||
fscale
|
||||
fstp %st(1)
|
||||
ret
|
||||
+41
-22
@@ -66,10 +66,11 @@ static char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94";
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
extern struct sockaddr_in data_dest;
|
||||
extern struct sockaddr_in data_dest, his_addr;
|
||||
extern int logged_in;
|
||||
extern struct passwd *pw;
|
||||
extern int guest;
|
||||
extern int paranoid;
|
||||
extern int logging;
|
||||
extern int type;
|
||||
extern int form;
|
||||
@@ -148,18 +149,32 @@ cmd
|
||||
pass($3);
|
||||
free($3);
|
||||
}
|
||||
| PORT SP host_port CRLF
|
||||
| PORT check_login SP host_port CRLF
|
||||
{
|
||||
usedefault = 0;
|
||||
if (pdata >= 0) {
|
||||
(void) close(pdata);
|
||||
pdata = -1;
|
||||
if ($2) {
|
||||
if (paranoid &&
|
||||
((ntohs(data_dest.sin_port) <
|
||||
IPPORT_RESERVED) ||
|
||||
memcmp(&data_dest.sin_addr,
|
||||
&his_addr.sin_addr,
|
||||
sizeof(data_dest.sin_addr)))) {
|
||||
usedefault = 1;
|
||||
reply(500,
|
||||
"Illegal PORT range rejected.");
|
||||
} else {
|
||||
usedefault = 0;
|
||||
if (pdata >= 0) {
|
||||
(void) close(pdata);
|
||||
pdata = -1;
|
||||
}
|
||||
reply(200, "PORT command successful.");
|
||||
}
|
||||
}
|
||||
reply(200, "PORT command successful.");
|
||||
}
|
||||
| PASV CRLF
|
||||
| PASV check_login CRLF
|
||||
{
|
||||
passive();
|
||||
if ($2)
|
||||
passive();
|
||||
}
|
||||
| TYPE SP type_code CRLF
|
||||
{
|
||||
@@ -291,16 +306,18 @@ cmd
|
||||
if ($4 != NULL)
|
||||
free($4);
|
||||
}
|
||||
| RNTO SP pathname CRLF
|
||||
| RNTO check_login SP pathname CRLF
|
||||
{
|
||||
if (fromname) {
|
||||
renamecmd(fromname, $3);
|
||||
free(fromname);
|
||||
fromname = (char *) 0;
|
||||
} else {
|
||||
reply(503, "Bad sequence of commands.");
|
||||
if ($2) {
|
||||
if (fromname) {
|
||||
renamecmd(fromname, $4);
|
||||
free(fromname);
|
||||
fromname = (char *) 0;
|
||||
} else {
|
||||
reply(503, "Bad sequence of commands.");
|
||||
}
|
||||
}
|
||||
free($3);
|
||||
free($4);
|
||||
}
|
||||
| ABOR CRLF
|
||||
{
|
||||
@@ -490,8 +507,9 @@ cmd
|
||||
struct tm *t;
|
||||
t = gmtime(&stbuf.st_mtime);
|
||||
reply(213,
|
||||
"19%02d%02d%02d%02d%02d%02d",
|
||||
t->tm_year, t->tm_mon+1, t->tm_mday,
|
||||
"%04d%02d%02d%02d%02d%02d",
|
||||
1900 + t->tm_year,
|
||||
t->tm_mon+1, t->tm_mday,
|
||||
t->tm_hour, t->tm_min, t->tm_sec);
|
||||
}
|
||||
}
|
||||
@@ -552,11 +570,12 @@ host_port
|
||||
{
|
||||
char *a, *p;
|
||||
|
||||
a = (char *)&data_dest.sin_addr;
|
||||
a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;
|
||||
data_dest.sin_len = sizeof(struct sockaddr_in);
|
||||
data_dest.sin_family = AF_INET;
|
||||
p = (char *)&data_dest.sin_port;
|
||||
p[0] = $9; p[1] = $11;
|
||||
data_dest.sin_family = AF_INET;
|
||||
a = (char *)&data_dest.sin_addr;
|
||||
a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ Internet File Transfer Protocol server
|
||||
.Sh SYNOPSIS
|
||||
.Nm ftpd
|
||||
.Op Fl dl
|
||||
.Op Fl R
|
||||
.Op Fl S
|
||||
.Op Fl U
|
||||
.Op Fl T Ar maxtimeout
|
||||
@@ -68,6 +69,17 @@ session is logged using syslog with a facility of LOG_FTP.
|
||||
If this option is specified twice, the retrieve (get), store (put), append,
|
||||
delete, make directory, remove directory and rename operations and
|
||||
their filename arguments are also logged.
|
||||
.It Fl R
|
||||
With this option set,
|
||||
.Nm ftpd
|
||||
will revert to historical behavior with regard to security checks on
|
||||
user operations and restrictions on PORT requests.
|
||||
Currently,
|
||||
.Nm ftpd
|
||||
will only honor PORT commands directed to unprivileged ports on the
|
||||
remote user's host (which violates the FTP protocol specification but
|
||||
closes some security holes).
|
||||
.
|
||||
.It Fl S
|
||||
With this option set,
|
||||
.Nm ftpd
|
||||
|
||||
+8
-3
@@ -30,7 +30,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ftpd.c,v 1.10.4.2 1995/09/01 03:07:17 davidg Exp $
|
||||
* $Id: ftpd.c,v 1.10.4.3 1996/03/18 11:10:16 davidg Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@@ -114,6 +114,7 @@ int timeout = 900; /* timeout after 15 minutes of inactivity */
|
||||
int maxtimeout = 7200;/* don't allow idle time to be set beyond 2 hours */
|
||||
int logging;
|
||||
int restricted_data_ports = 1;
|
||||
int paranoid = 1;
|
||||
int guest;
|
||||
#ifdef STATS
|
||||
int stats;
|
||||
@@ -259,9 +260,9 @@ main(argc, argv, envp)
|
||||
|
||||
|
||||
#ifdef STATS
|
||||
while ((ch = getopt(argc, argv, "dlSt:T:u:v")) != EOF) {
|
||||
while ((ch = getopt(argc, argv, "RdlSt:T:u:v")) != EOF) {
|
||||
#else
|
||||
while ((ch = getopt(argc, argv, "dlUt:T:u:v")) != EOF) {
|
||||
while ((ch = getopt(argc, argv, "RdlUt:RT:u:v")) != EOF) {
|
||||
#endif
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
@@ -272,6 +273,10 @@ main(argc, argv, envp)
|
||||
logging++; /* > 1 == extra logging */
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
paranoid = 0;
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
restricted_data_ports = 0;
|
||||
break;
|
||||
|
||||
+12
-5
@@ -33,11 +33,14 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: popen.c,v 1.5 1996/11/20 22:12:50 pst Exp $
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -52,6 +55,9 @@ static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define MAXUSRARGS 100
|
||||
#define MAXGLOBARGS 1000
|
||||
|
||||
/*
|
||||
* Special version of popen which avoids call to shell. This ensures noone
|
||||
* may create a pipe to a hidden program as a side effect of a list or dir
|
||||
@@ -67,9 +73,9 @@ ftpd_popen(program, type)
|
||||
char *cp;
|
||||
FILE *iop;
|
||||
int argc, gargc, pdes[2], pid;
|
||||
char **pop, *argv[100], *gargv[1000];
|
||||
char **pop, *argv[MAXUSRARGS], *gargv[MAXGLOBARGS];
|
||||
|
||||
if (*type != 'r' && *type != 'w' || type[1])
|
||||
if (((*type != 'r') && (*type != 'w')) || type[1])
|
||||
return (NULL);
|
||||
|
||||
if (!pids) {
|
||||
@@ -83,13 +89,13 @@ ftpd_popen(program, type)
|
||||
return (NULL);
|
||||
|
||||
/* break up string into pieces */
|
||||
for (argc = 0, cp = program;; cp = NULL)
|
||||
for (argc = 0, cp = program; argc < MAXUSRARGS; cp = NULL)
|
||||
if (!(argv[argc++] = strtok(cp, " \t\n")))
|
||||
break;
|
||||
|
||||
/* glob each piece */
|
||||
gargv[0] = argv[0];
|
||||
for (gargc = argc = 1; argv[argc]; argc++) {
|
||||
for (gargc = argc = 1; argv[argc] && gargc < (MAXGLOBARGS-1); argc++) {
|
||||
glob_t gl;
|
||||
int flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
|
||||
|
||||
@@ -97,7 +103,8 @@ ftpd_popen(program, type)
|
||||
if (glob(argv[argc], flags, NULL, &gl))
|
||||
gargv[gargc++] = strdup(argv[argc]);
|
||||
else
|
||||
for (pop = gl.gl_pathv; *pop; pop++)
|
||||
for (pop = gl.gl_pathv; *pop && gargc < (MAXGLOBARGS-1);
|
||||
pop++)
|
||||
gargv[gargc++] = strdup(*pop);
|
||||
globfree(&gl);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/4/93
|
||||
# $Id: Makefile,v 1.6 1996/09/22 21:54:40 wosch Exp $
|
||||
|
||||
PROG= rexecd
|
||||
MAN8= rexecd.8
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)rexecd.8 8.2 (Berkeley) 12/11/93
|
||||
.\" $Id: rexecd.8,v 1.3 1996/09/22 21:54:42 wosch Exp $
|
||||
.\"
|
||||
.Dd September 23, 1994
|
||||
.Dt REXECD 8
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: rexecd.c,v 1.5.4.4 1996/11/22 09:01:35 pst Exp $
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
@@ -287,7 +289,7 @@ error(fmt, a1, a2, a3)
|
||||
char buf[BUFSIZ];
|
||||
|
||||
buf[0] = 1;
|
||||
(void) sprintf(buf+1, fmt, a1, a2, a3);
|
||||
(void) snprintf(buf+1, sizeof(buf) - 1, fmt, a1, a2, a3);
|
||||
(void) write(2, buf, strlen(buf));
|
||||
}
|
||||
|
||||
|
||||
+14
-14
@@ -241,9 +241,8 @@ doit(f, fromp)
|
||||
}
|
||||
#ifdef IP_OPTIONS
|
||||
{
|
||||
u_char optbuf[BUFSIZ/3], *cp;
|
||||
char lbuf[BUFSIZ], *lp;
|
||||
int optsize = sizeof(optbuf), ipproto;
|
||||
u_char optbuf[BUFSIZ/3];
|
||||
int optsize = sizeof(optbuf), ipproto, i;
|
||||
struct protoent *ip;
|
||||
|
||||
if ((ip = getprotobyname("ip")) != NULL)
|
||||
@@ -252,17 +251,18 @@ doit(f, fromp)
|
||||
ipproto = IPPROTO_IP;
|
||||
if (getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf,
|
||||
&optsize) == 0 && optsize != 0) {
|
||||
lp = lbuf;
|
||||
for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
|
||||
sprintf(lp, " %2.2x", *cp);
|
||||
syslog(LOG_NOTICE,
|
||||
"Connection received using IP options (ignored):%s",
|
||||
lbuf);
|
||||
if (setsockopt(0, ipproto, IP_OPTIONS,
|
||||
(char *)NULL, optsize) != 0) {
|
||||
syslog(LOG_ERR,
|
||||
"setsockopt IP_OPTIONS NULL: %m");
|
||||
exit(1);
|
||||
for (i = 0; i < optsize; ) {
|
||||
u_char c = optbuf[i];
|
||||
if (c == IPOPT_LSRR || c == IPOPT_SSRR) {
|
||||
syslog(LOG_NOTICE,
|
||||
"Connection refused from %s with IP option %s",
|
||||
inet_ntoa(fromp->sin_addr),
|
||||
c == IPOPT_LSRR ? "LSRR" : "SSRR");
|
||||
exit(1);
|
||||
}
|
||||
if (c == IPOPT_EOL)
|
||||
break;
|
||||
i += (c == IPOPT_NOP) ? 1 : optbuf[i+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# $Id: Makefile,v 1.2 1993/11/10 03:46:04 smace Exp $
|
||||
# $Id: Makefile,v 1.1.1.1 1994/08/28 14:53:44 csgr Exp $
|
||||
|
||||
PROG = rpc.rusersd
|
||||
SRCS = rusersd.c rusers_proc.c
|
||||
@@ -9,7 +9,7 @@ LDADD= -lrpcsvc -lutil
|
||||
|
||||
.if exists(/usr/include/X11/extensions/xidle.h)
|
||||
CFLAGS+= -DXIDLE
|
||||
LDADD+= -L/usr/X386/lib -lXext -lX11
|
||||
LDADD+= -L${X11BASE}/lib -lXext -lX11
|
||||
.endif
|
||||
|
||||
|
||||
|
||||
+34
-18
@@ -54,7 +54,9 @@ static char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94";
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
@@ -200,6 +202,7 @@ doit(fromp)
|
||||
char *cp, sig, buf[BUFSIZ];
|
||||
char cmdbuf[NCARGS+1], locuser[16], remuser[16];
|
||||
char remotehost[2 * MAXHOSTNAMELEN + 1];
|
||||
char fromhost[2 * MAXHOSTNAMELEN + 1];
|
||||
|
||||
#ifdef KERBEROS
|
||||
AUTH_DAT *kdata = (AUTH_DAT *) NULL;
|
||||
@@ -233,9 +236,8 @@ doit(fromp)
|
||||
}
|
||||
#ifdef IP_OPTIONS
|
||||
{
|
||||
u_char optbuf[BUFSIZ/3], *cp;
|
||||
char lbuf[BUFSIZ], *lp;
|
||||
int optsize = sizeof(optbuf), ipproto;
|
||||
u_char optbuf[BUFSIZ/3];
|
||||
int optsize = sizeof(optbuf), ipproto, i;
|
||||
struct protoent *ip;
|
||||
|
||||
if ((ip = getprotobyname("ip")) != NULL)
|
||||
@@ -244,16 +246,18 @@ doit(fromp)
|
||||
ipproto = IPPROTO_IP;
|
||||
if (!getsockopt(0, ipproto, IP_OPTIONS, (char *)optbuf, &optsize) &&
|
||||
optsize != 0) {
|
||||
lp = lbuf;
|
||||
for (cp = optbuf; optsize > 0; cp++, optsize--, lp += 3)
|
||||
sprintf(lp, " %2.2x", *cp);
|
||||
syslog(LOG_NOTICE,
|
||||
"Connection received from %s using IP options (ignored):%s",
|
||||
inet_ntoa(fromp->sin_addr), lbuf);
|
||||
if (setsockopt(0, ipproto, IP_OPTIONS,
|
||||
(char *)NULL, optsize) != 0) {
|
||||
syslog(LOG_ERR, "setsockopt IP_OPTIONS NULL: %m");
|
||||
exit(1);
|
||||
for (i = 0; i < optsize; ) {
|
||||
u_char c = optbuf[i];
|
||||
if (c == IPOPT_LSRR || c == IPOPT_SSRR) {
|
||||
syslog(LOG_NOTICE,
|
||||
"Connection refused from %s with IP option %s",
|
||||
inet_ntoa(fromp->sin_addr),
|
||||
c == IPOPT_LSRR ? "LSRR" : "SSRR");
|
||||
exit(1);
|
||||
}
|
||||
if (c == IPOPT_EOL)
|
||||
break;
|
||||
i += (c == IPOPT_NOP) ? 1 : optbuf[i+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,7 +335,9 @@ doit(fromp)
|
||||
* in a remote net; look up the name and check that this
|
||||
* address corresponds to the name.
|
||||
*/
|
||||
hostname = hp->h_name;
|
||||
strncpy(fromhost, hp->h_name, sizeof(fromhost) - 1);
|
||||
fromhost[sizeof(fromhost) - 1] = 0;
|
||||
hostname = fromhost;
|
||||
#ifdef KERBEROS
|
||||
if (!use_kerberos)
|
||||
#endif
|
||||
@@ -346,7 +352,10 @@ doit(fromp)
|
||||
remotehost);
|
||||
errorstr =
|
||||
"Couldn't look up address for your host (%s)\n";
|
||||
hostname = inet_ntoa(fromp->sin_addr);
|
||||
strncpy(fromhost, inet_ntoa(fromp->sin_addr),
|
||||
sizeof(fromhost) - 1);
|
||||
fromhost[sizeof(fromhost) - 1] = 0;
|
||||
hostname = fromhost;
|
||||
} else for (; ; hp->h_addr_list++) {
|
||||
if (hp->h_addr_list[0] == NULL) {
|
||||
syslog(LOG_NOTICE,
|
||||
@@ -355,7 +364,10 @@ doit(fromp)
|
||||
hp->h_name);
|
||||
errorstr =
|
||||
"Host address mismatch for %s\n";
|
||||
hostname = inet_ntoa(fromp->sin_addr);
|
||||
strncpy(fromhost, inet_ntoa(fromp->sin_addr),
|
||||
sizeof(fromhost) - 1);
|
||||
fromhost[sizeof(fromhost) - 1] = 0;
|
||||
hostname = fromhost;
|
||||
break;
|
||||
}
|
||||
if (!bcmp(hp->h_addr_list[0],
|
||||
@@ -366,8 +378,12 @@ doit(fromp)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
errorhost = hostname = inet_ntoa(fromp->sin_addr);
|
||||
} else {
|
||||
strncpy(fromhost, inet_ntoa(fromp->sin_addr),
|
||||
sizeof(fromhost) - 1);
|
||||
fromhost[sizeof(fromhost) - 1] = 0;
|
||||
errorhost = hostname = fromhost;
|
||||
}
|
||||
|
||||
#ifdef KERBEROS
|
||||
if (use_kerberos) {
|
||||
|
||||
+23
-16
@@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)announce.c 8.2 (Berkeley) 1/7/94";
|
||||
static char sccsid[] = "@(#)announce.c 8.3 (Berkeley) 4/28/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -41,15 +41,18 @@ static char sccsid[] = "@(#)announce.c 8.2 (Berkeley) 1/7/94";
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <protocols/talkd.h>
|
||||
#include <sgtty.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <paths.h>
|
||||
|
||||
#include <vis.h>
|
||||
|
||||
extern char hostname[];
|
||||
|
||||
/*
|
||||
@@ -77,7 +80,7 @@ announce(request, remote_machine)
|
||||
|
||||
#define max(a,b) ( (a) > (b) ? (a) : (b) )
|
||||
#define N_LINES 5
|
||||
#define N_CHARS 120
|
||||
#define N_CHARS 256
|
||||
|
||||
/*
|
||||
* Build a block of characters containing the message.
|
||||
@@ -99,33 +102,37 @@ print_mesg(tty, tf, request, remote_machine)
|
||||
char line_buf[N_LINES][N_CHARS];
|
||||
int sizes[N_LINES];
|
||||
char big_buf[N_LINES*N_CHARS];
|
||||
char *bptr, *lptr, *ttymsg();
|
||||
char *bptr, *lptr, *vis_user;
|
||||
int i, j, max_size;
|
||||
|
||||
i = 0;
|
||||
max_size = 0;
|
||||
gettimeofday(&clock, &zone);
|
||||
localclock = localtime( &clock.tv_sec );
|
||||
(void)sprintf(line_buf[i], " ");
|
||||
(void)snprintf(line_buf[i], N_CHARS, " ");
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
(void)sprintf(line_buf[i], "Message from Talk_Daemon@%s at %d:%02d ...",
|
||||
hostname, localclock->tm_hour , localclock->tm_min );
|
||||
(void)snprintf(line_buf[i], N_CHARS,
|
||||
"Message from Talk_Daemon@%s at %d:%02d ...",
|
||||
hostname, localclock->tm_hour , localclock->tm_min );
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
(void)sprintf(line_buf[i], "talk: connection requested by %s@%s",
|
||||
request->l_name, remote_machine);
|
||||
|
||||
vis_user = malloc(strlen(request->l_name) * 4 + 1);
|
||||
strvis(vis_user, request->l_name, VIS_CSTYLE);
|
||||
(void)snprintf(line_buf[i], N_CHARS,
|
||||
"talk: connection requested by %s@%s", vis_user, remote_machine);
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
(void)sprintf(line_buf[i], "talk: respond with: talk %s@%s",
|
||||
request->l_name, remote_machine);
|
||||
(void)snprintf(line_buf[i], N_CHARS, "talk: respond with: talk %s@%s",
|
||||
vis_user, remote_machine);
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
(void)sprintf(line_buf[i], " ");
|
||||
(void)snprintf(line_buf[i], N_CHARS, " ");
|
||||
sizes[i] = strlen(line_buf[i]);
|
||||
max_size = max(max_size, sizes[i]);
|
||||
i++;
|
||||
|
||||
@@ -69,7 +69,7 @@ int debug = 0;
|
||||
void timeout();
|
||||
long lastmsgtime;
|
||||
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
char hostname[MAXHOSTNAMELEN + 1];
|
||||
|
||||
#define TIMEOUT 30
|
||||
#define MAXIDLE 120
|
||||
@@ -110,6 +110,7 @@ main(argc, argv)
|
||||
lastmsgtime = time(0);
|
||||
process_request(mp, &response);
|
||||
/* can block here, is this what I want? */
|
||||
mp->ctl_addr.sa_family = htons(mp->ctl_addr.sa_family);
|
||||
cc = sendto(sockt, (char *)&response,
|
||||
sizeof (response), 0, (struct sockaddr *)&mp->ctl_addr,
|
||||
sizeof (mp->ctl_addr));
|
||||
|
||||
@@ -9,10 +9,10 @@ CFLAGS+=-I${.CURDIR}/../../lib
|
||||
SRCS= global.c slc.c state.c sys_term.c telnetd.c \
|
||||
termstat.c utility.c
|
||||
#SRCS+= authenc.c
|
||||
DPADD= ${LIBUTIL} ${LIBTERMCAP}
|
||||
DPADD= ${LIBUTIL} ${LIBTERMCAP} ${LIBTELNET}
|
||||
LDADD= -lutil -ltermcap -ltelnet
|
||||
#DPADD+= $LIBKRB} ${LIBDES}
|
||||
#LDADD+= -lkrb -ldes
|
||||
MAN8= telnetd.8
|
||||
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
@@ -42,6 +42,8 @@ static char sccsid[] = "@(#)sys_term.c 8.2 (Berkeley) 12/15/93";
|
||||
#include <libtelnet/auth.h>
|
||||
#endif
|
||||
|
||||
extern char *altlogin;
|
||||
|
||||
#if defined(CRAY) || defined(__hpux)
|
||||
# define PARENT_DOES_UTMP
|
||||
#endif
|
||||
@@ -1620,6 +1622,7 @@ start_login(host, autologin, name)
|
||||
if (auth_level >= 0 && autologin == AUTH_VALID) {
|
||||
# if !defined(NO_LOGIN_F)
|
||||
argv = addarg(argv, "-f");
|
||||
argv = addarg(argv, "--");
|
||||
argv = addarg(argv, name);
|
||||
# else
|
||||
# if defined(LOGIN_R)
|
||||
@@ -1692,17 +1695,14 @@ start_login(host, autologin, name)
|
||||
pty = xpty;
|
||||
}
|
||||
# else
|
||||
argv = addarg(argv, "--");
|
||||
argv = addarg(argv, name);
|
||||
# endif
|
||||
# endif
|
||||
} else
|
||||
#endif
|
||||
if (user = getenv("USER")) {
|
||||
if (strchr(user, '-')) {
|
||||
syslog(LOG_ERR, "tried to pass user \"%s\" to login",
|
||||
user);
|
||||
fatal(net, "invalid user");
|
||||
}
|
||||
if (getenv("USER")) {
|
||||
argv = addarg(argv, "--");
|
||||
argv = addarg(argv, getenv("USER"));
|
||||
#if defined(LOGIN_ARGS) && defined(NO_LOGIN_P)
|
||||
{
|
||||
@@ -1728,10 +1728,14 @@ start_login(host, autologin, name)
|
||||
close(pty);
|
||||
#endif
|
||||
closelog();
|
||||
execv(_PATH_LOGIN, argv);
|
||||
|
||||
syslog(LOG_ERR, "%s: %m\n", _PATH_LOGIN);
|
||||
fatalperror(net, _PATH_LOGIN);
|
||||
if (altlogin == NULL) {
|
||||
altlogin = _PATH_LOGIN;
|
||||
}
|
||||
execv(altlogin, argv);
|
||||
|
||||
syslog(LOG_ERR, "%s: %m\n", altlogin);
|
||||
fatalperror(net, altlogin);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ protocol server
|
||||
.Op Fl X Ar authtype
|
||||
.Op Fl a Ar authmode
|
||||
.Op Fl edebug
|
||||
.Op Fl P Ar loginprog
|
||||
.Op Fl r Ns Ar lowpty-highpty
|
||||
.Op Fl u Ar len
|
||||
.Op Fl debug Op Ar port
|
||||
@@ -187,6 +188,11 @@ If
|
||||
has been compiled with support for data encryption, then the
|
||||
.Fl edebug
|
||||
option may be used to enable encryption debugging code.
|
||||
.It Fl P Ar loginprog
|
||||
Specifies an alternate
|
||||
.Xr login 1
|
||||
command to run to complete the login. The alternate command must
|
||||
understand the same command arguments as the standard login.
|
||||
.It Fl h
|
||||
Disables the printing of host-specific information before
|
||||
login has been completed.
|
||||
@@ -217,7 +223,7 @@ will operate in character at a time mode.
|
||||
It will still support kludge linemode, but will only
|
||||
go into kludge linemode if the remote client requests
|
||||
it.
|
||||
(This is done by by the client sending
|
||||
(This is done by the client sending
|
||||
.Dv DONT SUPPRESS-GO-AHEAD
|
||||
and
|
||||
.Dv DONT ECHO . )
|
||||
@@ -479,7 +485,7 @@ about the speed of the serial line to which
|
||||
the client is attached.
|
||||
.It "DO XDISPLOC"
|
||||
Indicates a desire to be able to request the name
|
||||
of the X windows display that is associated with
|
||||
of the X Window System display that is associated with
|
||||
the telnet client.
|
||||
.It "DO NEW-ENVIRON"
|
||||
Indicates a desire to be able to request environment
|
||||
@@ -530,9 +536,9 @@ the data stream.
|
||||
.Pa /usr/ucb/bftp
|
||||
(if supported)
|
||||
.Sh "SEE ALSO"
|
||||
.Xr telnet 1 ,
|
||||
.Xr bftp 1 ,
|
||||
.Xr login 1 ,
|
||||
.Xr bftp 1
|
||||
.Xr telnet 1
|
||||
(if supported)
|
||||
.Sh STANDARDS
|
||||
.Bl -tag -compact -width RFC-1572
|
||||
|
||||
@@ -124,6 +124,7 @@ int lowpty = 0, highpty; /* low, high pty numbers */
|
||||
int debug = 0;
|
||||
int keepalive = 1;
|
||||
char *progname;
|
||||
char *altlogin;
|
||||
|
||||
extern void usage P((void));
|
||||
|
||||
@@ -133,7 +134,7 @@ extern void usage P((void));
|
||||
* passed off to getopt().
|
||||
*/
|
||||
char valid_opts[] = {
|
||||
'd', ':', 'h', 'k', 'n', 'S', ':', 'u', ':', 'U',
|
||||
'd', ':', 'h', 'k', 'n', 'p', ':', 'S', ':', 'u', ':', 'U',
|
||||
#ifdef AUTHENTICATION
|
||||
'a', ':', 'X', ':',
|
||||
#endif
|
||||
@@ -284,6 +285,10 @@ main(argc, argv)
|
||||
keepalive = 0;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
altlogin = optarg;
|
||||
break;
|
||||
|
||||
#ifdef CRAY
|
||||
case 'r':
|
||||
{
|
||||
@@ -661,12 +666,14 @@ getterminaltype(name)
|
||||
* we have to just go with what we (might) have already gotten.
|
||||
*/
|
||||
if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
|
||||
(void) strncpy(first, terminaltype, sizeof(first));
|
||||
(void) strncpy(first, terminaltype, sizeof(first)-1);
|
||||
first[sizeof(first)-1] = '\0';
|
||||
for(;;) {
|
||||
/*
|
||||
* Save the unknown name, and request the next name.
|
||||
*/
|
||||
(void) strncpy(last, terminaltype, sizeof(last));
|
||||
(void) strncpy(last, terminaltype, sizeof(last)-1);
|
||||
last[sizeof(last)-1] = '\0';
|
||||
_gettermname();
|
||||
if (terminaltypeok(terminaltype))
|
||||
break;
|
||||
@@ -684,8 +691,10 @@ getterminaltype(name)
|
||||
* the start of the list.
|
||||
*/
|
||||
_gettermname();
|
||||
if (strncmp(first, terminaltype, sizeof(first)) != 0)
|
||||
(void) strncpy(terminaltype, first, sizeof(first));
|
||||
if (strncmp(first, terminaltype, sizeof(first)) != 0) {
|
||||
(void) strncpy(terminaltype, first, sizeof(terminaltype)-1);
|
||||
terminaltype[sizeof(terminaltype)-1] = '\0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ stilloob(s)
|
||||
do {
|
||||
FD_ZERO(&excepts);
|
||||
FD_SET(s, &excepts);
|
||||
memset((char *)&timeout, 0, sizeof timeout);
|
||||
value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
|
||||
} while ((value == -1) && (errno == EINTR));
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: snake_saver.c,v 1.4.4.2 1996/08/05 02:55:15 alex Exp $
|
||||
* $Id: snake_saver.c,v 1.4.4.3 1996/11/11 14:15:08 jkh Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@@ -45,7 +45,7 @@ void (*old_saver)();
|
||||
static void
|
||||
snake_saver(int blank)
|
||||
{
|
||||
const char saves[] = {"FreeBSD-2.1.6"};
|
||||
const char saves[] = {"FreeBSD-2.1.7"};
|
||||
static u_char *savs[sizeof(saves)-1];
|
||||
static int dirx, diry;
|
||||
int f;
|
||||
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
# $Id: Makefile,v 1.193.2.67 1996/11/13 13:15:43 jkh Exp $
|
||||
# $Id: Makefile,v 1.193.2.69 1997/02/17 11:04:30 jkh Exp $
|
||||
#
|
||||
# How to roll a release:
|
||||
#
|
||||
@@ -11,10 +11,10 @@
|
||||
# that on a 14.4 line just yet...
|
||||
#
|
||||
# SET THIS !!!
|
||||
BUILDNAME=2.1.6-RELEASE
|
||||
BUILDNAME=2.1.7-RELEASE
|
||||
#CHROOTDIR=/junk/release
|
||||
# If this is a RELEASE, then set
|
||||
RELEASETAG=RELENG_2_1_0
|
||||
RELEASETAG=RELENG_2_1_7_RELEASE
|
||||
|
||||
# Things which without too much trouble can be considered variables
|
||||
|
||||
@@ -120,6 +120,8 @@ rerelease release:
|
||||
.if make(rerelease)
|
||||
echo "make all install" >> ${CHROOTDIR}/mk
|
||||
.endif
|
||||
echo "cd /usr/src/release/sysinstall" >> ${CHROOTDIR}/mk
|
||||
echo "make obj" >> ${CHROOTDIR}/mk
|
||||
echo "cd /usr/src/release" >> ${CHROOTDIR}/mk
|
||||
echo "make obj OBJLINK=yes" >> ${CHROOTDIR}/mk
|
||||
echo "cd obj" >> ${CHROOTDIR}/mk
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# $Id: boot_crunch.conf,v 1.20.2.7 1996/11/03 05:46:54 jkh Exp $
|
||||
# $Id: boot_crunch.conf,v 1.20.2.8 1996/11/03 11:55:49 jkh Exp $
|
||||
|
||||
srcdirs /usr/src/bin /usr/src/sbin /usr/src/release /usr/src/usr.bin
|
||||
srcdirs /usr/src/gnu/usr.bin /usr/src/usr.sbin /usr/src/sbin/i386
|
||||
@@ -11,5 +11,5 @@ ln gzip gunzip
|
||||
ln gzip zcat
|
||||
ln sh -sh
|
||||
|
||||
libs -ll -ledit -lutil -lkvm -lmd -lcrypt
|
||||
libs -ll -ledit -lutil -lkvm -lmd -lcrypt -lftpio
|
||||
libs -ldialog -lncurses -lmytinfo -L/usr/src/release/libdisk/obj -ldisk
|
||||
@@ -0,0 +1,108 @@
|
||||
#
|
||||
# Network services, Internet style
|
||||
#
|
||||
# Stripped-down version.
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# WELL KNOWN PORT NUMBERS
|
||||
#
|
||||
echo 7/tcp
|
||||
echo 7/udp
|
||||
discard 9/tcp sink null
|
||||
discard 9/udp sink null
|
||||
systat 11/tcp users #Active Users
|
||||
systat 11/udp users #Active Users
|
||||
daytime 13/tcp
|
||||
daytime 13/udp
|
||||
chargen 19/tcp ttytst source #Character Generator
|
||||
chargen 19/udp ttytst source #Character Generator
|
||||
ftp-data 20/tcp #File Transfer [Default Data]
|
||||
ftp-data 20/udp #File Transfer [Default Data]
|
||||
ftp 21/tcp #File Transfer [Control]
|
||||
ftp 21/udp #File Transfer [Control]
|
||||
ssh 22/tcp #Secure Shell Login
|
||||
ssh 22/udp #Secure Shell Login
|
||||
telnet 23/tcp
|
||||
telnet 23/udp
|
||||
# 24/tcp any private mail system
|
||||
# 24/udp any private mail system
|
||||
smtp 25/tcp mail #Simple Mail Transfer
|
||||
smtp 25/udp mail #Simple Mail Transfer
|
||||
time 37/tcp timserver
|
||||
time 37/udp timserver
|
||||
domain 53/tcp #Domain Name Server
|
||||
domain 53/udp #Domain Name Server
|
||||
bootps 67/tcp dhcps #Bootstrap Protocol Server
|
||||
bootps 67/udp dhcps #Bootstrap Protocol Server
|
||||
bootpc 68/tcp dhcpc #Bootstrap Protocol Client
|
||||
bootpc 68/udp dhcpc #Bootstrap Protocol Client
|
||||
tftp 69/tcp #Trivial File Transfer
|
||||
tftp 69/udp #Trivial File Transfer
|
||||
gopher 70/tcp
|
||||
gopher 70/udp
|
||||
finger 79/tcp
|
||||
finger 79/udp
|
||||
http 80/tcp www www-http #World Wide Web HTTP
|
||||
http 80/udp www www-http #World Wide Web HTTP
|
||||
sunrpc 111/tcp rpcbind #SUN Remote Procedure Call
|
||||
sunrpc 111/udp rpcbind #SUN Remote Procedure Call
|
||||
auth 113/tcp ident tap #Authentication Service
|
||||
auth 113/udp ident tap #Authentication Service
|
||||
nntp 119/tcp usenet #Network News Transfer Protocol
|
||||
nntp 119/udp usenet #Network News Transfer Protocol
|
||||
rmt 411/tcp #Remote MT Protocol
|
||||
rmt 411/udp #Remote MT Protocol
|
||||
https 443/tcp
|
||||
https 443/udp
|
||||
#
|
||||
# Berkeley-specific services
|
||||
#
|
||||
exec 512/tcp #remote process execution;
|
||||
# authentication performed using
|
||||
# passwords and UNIX loppgin names
|
||||
biff 512/udp comsat #used by mail system to notify users
|
||||
# of new mail received; currently
|
||||
# receives messages only from
|
||||
# processes on the same machine
|
||||
login 513/tcp #remote login a la telnet;
|
||||
# automatic authentication performed
|
||||
# based on priviledged port numbers
|
||||
# and distributed data bases which
|
||||
# identify "authentication domains"
|
||||
who 513/udp whod #maintains data bases showing who's
|
||||
# logged in to machines on a local
|
||||
# net and the load average of the
|
||||
# machine
|
||||
cmd 514/tcp shell #like exec, but automatic
|
||||
# authentication is performed as for
|
||||
# login server
|
||||
syslog 514/udp
|
||||
printer 515/tcp spooler
|
||||
printer 515/udp spooler
|
||||
talk 517/tcp #like tenex link, but across
|
||||
# machine - unfortunately, doesn't
|
||||
# use link protocol (this is actually
|
||||
# just a rendezvous port from which a
|
||||
# tcp connection is established)
|
||||
talk 517/udp #like tenex link, but across
|
||||
# machine - unfortunately, doesn't
|
||||
# use link protocol (this is actually
|
||||
# just a rendezvous port from which a
|
||||
# tcp connection is established)
|
||||
ntalk 518/tcp
|
||||
ntalk 518/udp
|
||||
utime 519/tcp unixtime
|
||||
utime 519/udp unixtime
|
||||
efs 520/tcp #extended file name server
|
||||
router 520/udp route routed #local routing process (on site);
|
||||
# uses variant of Xerox NS routing
|
||||
# information protocol
|
||||
uucp 540/tcp uucpd
|
||||
uucp 540/udp uucpd
|
||||
uucp-rlogin 541/tcp
|
||||
uucp-rlogin 541/udp
|
||||
klogin 543/tcp # Kerberos (v4/v5)
|
||||
klogin 543/udp # Kerberos (v4/v5)
|
||||
kshell 544/tcp krcmd # Kerberos (v4/v5)
|
||||
kshell 544/udp krcmd # Kerberos (v4/v5)
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
if [ "`id -u`" != "0" ]; then
|
||||
echo "Sorry, this must be done as root."
|
||||
exit 1
|
||||
fi
|
||||
tar --unlink -xpzf compat21.tgz -C /
|
||||
exit 0
|
||||
@@ -7,22 +7,23 @@ CLEANFILES+= keymap.tmp keymap.h
|
||||
.PATH: ${.CURDIR}/../disklabel ${.CURDIR}/../../usr.bin/cksum
|
||||
|
||||
SRCS= anonFTP.c apache.c attr.c cdrom.c command.c config.c devices.c \
|
||||
disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c ftp.c \
|
||||
ftp_strat.c globals.c index.c install.c installUpgrade.c \
|
||||
disks.c dispatch.c dist.c dmenu.c doc.c dos.c dosio.c floppy.c ftp.c \
|
||||
globals.c index.c install.c installUpgrade.c \
|
||||
keymap.c label.c lndir.c main.c makedevs.c media.c menus.c misc.c \
|
||||
msg.c network.c nfs.c options.c package.c samba.c system.c \
|
||||
tape.c tcpip.c termcap.c ufs.c variable.c wizard.c \
|
||||
tape.c tcpip.c termcap.c ufs.c user.c variable.c wizard.c \
|
||||
uc_eisa.c uc_isa.c uc_kmem.c uc_list.c uc_main.c uc_pci.c \
|
||||
uc_scsi.c
|
||||
uc_scsi.c keymap.h
|
||||
|
||||
CFLAGS+= -Wall -I${.CURDIR}/../../gnu/lib/libdialog -I${.OBJDIR} -I/sys
|
||||
CFLAGS+= -DUC_PRIVATE -DKERN_NO_SYMBOLS -DSAVE_USERCONFIG
|
||||
|
||||
#CFLAGS+= -DLOAD_CONFIG_FILE=\"install.cfg\"
|
||||
|
||||
DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} ${LIBUTIL} ${LIBDISK}
|
||||
LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk
|
||||
.if defined(LOAD_CONFIG_FILE)
|
||||
CFLAGS+= -DLOAD_CONFIG_FILE=\"${LOAD_CONFIG_FILE}\"
|
||||
.endif
|
||||
|
||||
DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} ${LIBUTIL} ${LIBDISK} ${LIBFTPIO}
|
||||
LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio
|
||||
|
||||
makedevs.c: Makefile rtermcap keymap.h
|
||||
rm -f makedevs.tmp
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* The new sysinstall program.
|
||||
*
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Coranth Gryphon. All rights reserved.
|
||||
* Copyright (c) 1996
|
||||
* Jordan K. Hubbard. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer,
|
||||
* verbatim and that no modifications are made prior to this
|
||||
* point in the file.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR THEIR PETS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sysinstall.h"
|
||||
#include <sys/param.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
/* This doesn't change until FTP itself changes */
|
||||
|
||||
#define FTP_NAME "ftp"
|
||||
#define MOTD_FILE "ftpmotd"
|
||||
|
||||
/* These change if we want to use different defaults */
|
||||
|
||||
#define FTP_UID 14
|
||||
#define FTP_GID 5
|
||||
#define FTP_GROUP "operator"
|
||||
#define FTP_UPLOAD "incoming"
|
||||
#define FTP_COMMENT "Anonymous FTP Admin"
|
||||
#define FTP_HOMEDIR "/var/ftp"
|
||||
|
||||
#define ANONFTP_HELPFILE "anonftp"
|
||||
|
||||
/* Set up the structure to hold configuration information */
|
||||
/* Note that this is only what we could fit onto the one screen */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char homedir[64]; /* Home Dir for Anon FTP */
|
||||
char group[32]; /* Group */
|
||||
char uid[8]; /* UID */
|
||||
char comment[64]; /* PWD Comment */
|
||||
char upload[32]; /* Upload Dir */
|
||||
} FTPConf;
|
||||
|
||||
static FTPConf tconf;
|
||||
|
||||
#define ANONFTP_HOMEDIR_LEN 64
|
||||
#define ANONFTP_COMMENT_LEN 64
|
||||
#define ANONFTP_UPLOAD_LEN 32
|
||||
#define ANONFTP_GROUP_LEN 32
|
||||
#define ANONFTP_UID_LEN 8
|
||||
|
||||
static int okbutton, cancelbutton;
|
||||
|
||||
/* What the screen size is meant to be */
|
||||
#define ANONFTP_DIALOG_Y 0
|
||||
#define ANONFTP_DIALOG_X 8
|
||||
#define ANONFTP_DIALOG_WIDTH COLS - 16
|
||||
#define ANONFTP_DIALOG_HEIGHT LINES - 2
|
||||
|
||||
static Layout layout[] = {
|
||||
#define LAYOUT_UID 0
|
||||
{ 2, 3, 8, ANONFTP_UID_LEN - 1,
|
||||
"UID:", "What user ID to assign to FTP Admin",
|
||||
tconf.uid, STRINGOBJ, NULL },
|
||||
#define LAYOUT_GROUP 1
|
||||
{ 2, 15, 15, ANONFTP_GROUP_LEN - 1,
|
||||
"Group:", "Group name that ftp process belongs to",
|
||||
tconf.group, STRINGOBJ, NULL },
|
||||
#define LAYOUT_COMMENT 2
|
||||
{ 2, 35, 24, ANONFTP_COMMENT_LEN - 1,
|
||||
"Comment:", "Password file comment for FTP Admin",
|
||||
tconf.comment, STRINGOBJ, NULL },
|
||||
#define LAYOUT_HOMEDIR 3
|
||||
{ 9, 10, 43, ANONFTP_HOMEDIR_LEN - 1,
|
||||
"FTP Root Directory:",
|
||||
"The top directory to chroot to when doing anonymous ftp",
|
||||
tconf.homedir, STRINGOBJ, NULL },
|
||||
#define LAYOUT_UPLOAD 4
|
||||
{ 14, 20, 22, ANONFTP_UPLOAD_LEN - 1,
|
||||
"Upload Subdirectory:", "Designated sub-directory that holds uploads",
|
||||
tconf.upload, STRINGOBJ, NULL },
|
||||
#define LAYOUT_OKBUTTON 5
|
||||
{ 19, 15, 0, 0,
|
||||
"OK", "Select this if you are happy with these settings",
|
||||
&okbutton, BUTTONOBJ, NULL },
|
||||
#define LAYOUT_CANCELBUTTON 6
|
||||
{ 19, 35, 0, 0,
|
||||
"CANCEL", "Select this if you wish to cancel this screen",
|
||||
&cancelbutton, BUTTONOBJ, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
int
|
||||
createFtpUser(void)
|
||||
{
|
||||
struct passwd *tpw;
|
||||
struct group *tgrp;
|
||||
char pwline[256];
|
||||
char *tptr;
|
||||
int gid;
|
||||
FILE *fptr;
|
||||
|
||||
if ((gid = atoi(tconf.group)) <= 0) {
|
||||
if (!(tgrp = getgrnam(tconf.group))) {
|
||||
/* group does not exist, create it by name */
|
||||
|
||||
tptr = msgGetInput("14", "What group ID to use for group %s ?", tconf.group);
|
||||
if (tptr && *tptr && ((gid = atoi(tptr)) > 0)) {
|
||||
if ((fptr = fopen(_PATH_GROUP,"a"))) {
|
||||
fprintf(fptr,"%s:*:%d:%s\n",tconf.group,gid,FTP_NAME);
|
||||
fclose(fptr);
|
||||
}
|
||||
}
|
||||
else
|
||||
gid = FTP_GID;
|
||||
}
|
||||
else
|
||||
gid = tgrp->gr_gid;
|
||||
}
|
||||
else if (!getgrgid(gid)) {
|
||||
/* group does not exist, create it by number */
|
||||
|
||||
tptr = msgGetInput("14", "What group name to use for gid %d ?", gid);
|
||||
if (tptr && *tptr) {
|
||||
SAFE_STRCPY(tconf.group, tptr);
|
||||
if ((tgrp = getgrnam(tconf.group))) {
|
||||
gid = tgrp->gr_gid;
|
||||
}
|
||||
else if ((fptr = fopen(_PATH_GROUP,"a"))) {
|
||||
fprintf(fptr,"%s:*:%d:%s\n",tconf.group,gid,FTP_NAME);
|
||||
fclose(fptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((tpw = getpwnam(FTP_NAME))) {
|
||||
if (tpw->pw_uid != FTP_UID)
|
||||
msgConfirm("FTP user already exists with a different uid.");
|
||||
|
||||
return DITEM_SUCCESS; /* succeeds if already exists */
|
||||
}
|
||||
|
||||
sprintf(pwline, "%s::%s:%d::0:0:%s:%s:/bin/date\n", FTP_NAME, tconf.uid, gid, tconf.comment, tconf.homedir);
|
||||
|
||||
fptr = fopen(_PATH_MASTERPASSWD,"a");
|
||||
if (! fptr) {
|
||||
msgConfirm("Could not open master password file.");
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
fprintf(fptr, pwline);
|
||||
fclose(fptr);
|
||||
msgNotify("Remaking password file: %s", _PATH_MASTERPASSWD);
|
||||
vsystem("pwd_mkdb -p %s", _PATH_MASTERPASSWD);
|
||||
return DITEM_SUCCESS;
|
||||
}
|
||||
|
||||
/* This is it - how to get the setup values */
|
||||
static int
|
||||
anonftpOpenDialog(void)
|
||||
{
|
||||
WINDOW *ds_win;
|
||||
ComposeObj *obj = NULL;
|
||||
int n = 0, cancel = FALSE;
|
||||
int max;
|
||||
char title[80];
|
||||
|
||||
/* We need a curses window */
|
||||
if (!(ds_win = openLayoutDialog(ANONFTP_HELPFILE, " Anonymous FTP Configuration ",
|
||||
ANONFTP_DIALOG_X, ANONFTP_DIALOG_Y, ANONFTP_DIALOG_WIDTH, ANONFTP_DIALOG_HEIGHT))) {
|
||||
beep();
|
||||
msgConfirm("Cannot open anonymous ftp dialog window!!");
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
|
||||
/* Draw a sub-box for the path configuration */
|
||||
draw_box(ds_win, ANONFTP_DIALOG_Y + 7, ANONFTP_DIALOG_X + 8,
|
||||
ANONFTP_DIALOG_HEIGHT - 11, ANONFTP_DIALOG_WIDTH - 17,
|
||||
dialog_attr, border_attr);
|
||||
wattrset(ds_win, dialog_attr);
|
||||
sprintf(title, " Path Configuration ");
|
||||
mvwaddstr(ds_win, ANONFTP_DIALOG_Y + 7, ANONFTP_DIALOG_X + 22, title);
|
||||
|
||||
/** Initialize the config Data Structure **/
|
||||
bzero(&tconf, sizeof(tconf));
|
||||
|
||||
SAFE_STRCPY(tconf.group, FTP_GROUP);
|
||||
SAFE_STRCPY(tconf.upload, FTP_UPLOAD);
|
||||
SAFE_STRCPY(tconf.comment, FTP_COMMENT);
|
||||
SAFE_STRCPY(tconf.homedir, FTP_HOMEDIR);
|
||||
sprintf(tconf.uid, "%d", FTP_UID);
|
||||
|
||||
/* Some more initialisation before we go into the main input loop */
|
||||
obj = initLayoutDialog(ds_win, layout, ANONFTP_DIALOG_X, ANONFTP_DIALOG_Y, &max);
|
||||
|
||||
cancelbutton = okbutton = 0;
|
||||
while (layoutDialogLoop(ds_win, layout, &obj, &n, max, &cancelbutton, &cancel));
|
||||
|
||||
/* Clear this crap off the screen */
|
||||
dialog_clear_norefresh();
|
||||
use_helpfile(NULL);
|
||||
|
||||
if (cancel)
|
||||
return DITEM_FAILURE;
|
||||
return DITEM_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
configAnonFTP(dialogMenuItem *self)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Be optimistic */
|
||||
i = DITEM_SUCCESS;
|
||||
|
||||
dialog_clear_norefresh();
|
||||
i = anonftpOpenDialog();
|
||||
if (DITEM_STATUS(i) != DITEM_SUCCESS) {
|
||||
msgConfirm("Configuration of Anonymous FTP cancelled per user request.");
|
||||
return i | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
/*** Use defaults for any invalid values ***/
|
||||
if (atoi(tconf.uid) <= 0)
|
||||
sprintf(tconf.uid, "%d", FTP_UID);
|
||||
|
||||
if (!tconf.group[0])
|
||||
SAFE_STRCPY(tconf.group, FTP_GROUP);
|
||||
|
||||
if (!tconf.upload[0])
|
||||
SAFE_STRCPY(tconf.upload, FTP_UPLOAD);
|
||||
|
||||
/*** If the user did not specify a directory, use default ***/
|
||||
|
||||
if (tconf.homedir[strlen(tconf.homedir) - 1] == '/')
|
||||
tconf.homedir[strlen(tconf.homedir) - 1] = '\0';
|
||||
|
||||
if (!tconf.homedir[0])
|
||||
SAFE_STRCPY(tconf.homedir, FTP_HOMEDIR);
|
||||
|
||||
/*** If HomeDir does not exist, create it ***/
|
||||
|
||||
if (!directory_exists(tconf.homedir))
|
||||
vsystem("mkdir -p %s", tconf.homedir);
|
||||
|
||||
if (directory_exists(tconf.homedir)) {
|
||||
msgNotify("Configuring %s for use by anon FTP.", tconf.homedir);
|
||||
vsystem("chmod 555 %s && chown root.%s %s", tconf.homedir, tconf.group, tconf.homedir);
|
||||
vsystem("mkdir %s/bin && chmod 555 %s/bin", tconf.homedir, tconf.homedir);
|
||||
vsystem("cp /bin/ls %s/bin && chmod 111 %s/bin/ls", tconf.homedir, tconf.homedir);
|
||||
vsystem("cp /bin/date %s/bin && chmod 111 %s/bin/date", tconf.homedir, tconf.homedir);
|
||||
vsystem("mkdir %s/etc && chmod 555 %s/etc", tconf.homedir, tconf.homedir);
|
||||
vsystem("mkdir -p %s/pub", tconf.homedir);
|
||||
vsystem("mkdir -p %s/%s", tconf.homedir, tconf.upload);
|
||||
vsystem("chmod 1777 %s/%s", tconf.homedir, tconf.upload);
|
||||
|
||||
if (DITEM_STATUS(createFtpUser()) == DITEM_SUCCESS) {
|
||||
msgNotify("Copying password information for anon FTP.");
|
||||
vsystem("cp /etc/pwd.db %s/etc && chmod 444 %s/etc/pwd.db", tconf.homedir, tconf.homedir);
|
||||
vsystem("cp /etc/passwd %s/etc && chmod 444 %s/etc/passwd", tconf.homedir, tconf.homedir);
|
||||
vsystem("cp /etc/group %s/etc && chmod 444 %s/etc/group", tconf.homedir, tconf.homedir);
|
||||
vsystem("chown -R root.%s %s/pub", tconf.group, tconf.homedir);
|
||||
}
|
||||
else {
|
||||
msgConfirm("Unable to create FTP user! Anonymous FTP setup failed.");
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
|
||||
if (!msgYesNo("Create a welcome message file for anonymous FTP users?")) {
|
||||
char cmd[256];
|
||||
dialog_clear();
|
||||
vsystem("echo Your welcome message here. > %s/etc/%s", tconf.homedir, MOTD_FILE);
|
||||
sprintf(cmd, "%s %s/etc/%s", variable_get(VAR_EDITOR), tconf.homedir, MOTD_FILE);
|
||||
if (!systemExecute(cmd))
|
||||
i = DITEM_SUCCESS;
|
||||
else
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
msgConfirm("Invalid Directory: %s\n"
|
||||
"Anonymous FTP will not be set up.", tconf.homedir);
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
if (DITEM_STATUS(i) == DITEM_SUCCESS)
|
||||
variable_set2("anon_ftp", "YES");
|
||||
return i | DITEM_RESTORE;
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
/*
|
||||
* The new sysinstall program.
|
||||
*
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Coranth Gryphon. All rights reserved.
|
||||
* Copyright (c) 1996
|
||||
* Jordan K. Hubbard. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer,
|
||||
* verbatim and that no modifications are made prior to this
|
||||
* point in the file.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR THEIR PETS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sysinstall.h"
|
||||
#include <sys/param.h>
|
||||
|
||||
|
||||
#define APACHE_HELPFILE "apache"
|
||||
#define FREEBSD_GIF "http://www.freebsd.org/gifs/powerlogo.gif"
|
||||
|
||||
/* These change if the package uses different defaults */
|
||||
|
||||
#define DEFAULT_USER "bin"
|
||||
#define DEFAULT_GROUP "bin"
|
||||
#define WELCOME_FILE "index.html"
|
||||
#define USER_HOMEDIR "public_html"
|
||||
|
||||
#define APACHE_BASE "/usr/local/www"
|
||||
#define DATA_SUBDIR "data"
|
||||
#define CONFIG_SUBDIR "server/conf"
|
||||
|
||||
#define LOGS_SUBDIR "/var/log"
|
||||
#define ACCESS_LOGNAME "httpd.access"
|
||||
#define ERROR_LOGNAME "httpd.error"
|
||||
|
||||
/* Set up the structure to hold configuration information */
|
||||
/* Note that this is only what we could fit onto the one screen */
|
||||
|
||||
typedef struct {
|
||||
char docroot[128]; /* DocumentRoot */
|
||||
char userdir[128]; /* UserDir */
|
||||
char welcome[32]; /* Welcome Doc */
|
||||
char email[64]; /* ServerAdmin */
|
||||
char hostname[64]; /* ServerName */
|
||||
char logdir[64]; /* Where to put Logs */
|
||||
char accesslog[32]; /* access_log */
|
||||
char errorlog[32]; /* error_log */
|
||||
char defuser[16]; /* default user id */
|
||||
char defgroup[16]; /* default group id */
|
||||
} ApacheConf;
|
||||
|
||||
static ApacheConf tconf;
|
||||
|
||||
#define APACHE_DOCROOT_LEN 128
|
||||
#define APACHE_USERDIR_LEN 128
|
||||
#define APACHE_WELCOME_LEN 32
|
||||
#define APACHE_EMAIL_LEN 64
|
||||
#define APACHE_HOSTNAME_LEN 64
|
||||
#define APACHE_LOGDIR_LEN 64
|
||||
#define APACHE_ACCESSLOG_LEN 32
|
||||
#define APACHE_ERRORLOG_LEN 32
|
||||
#define APACHE_DEFUSER_LEN 16
|
||||
#define APACHE_DEFGROUP_LEN 16
|
||||
|
||||
static int okbutton, cancelbutton;
|
||||
|
||||
/* What the screen size is meant to be */
|
||||
#define APACHE_DIALOG_Y 0
|
||||
#define APACHE_DIALOG_X 0
|
||||
#define APACHE_DIALOG_WIDTH COLS
|
||||
#define APACHE_DIALOG_HEIGHT LINES - 2
|
||||
|
||||
static Layout layout[] = {
|
||||
#define LAYOUT_HOSTNAME 0
|
||||
{ 1, 2, 30, HOSTNAME_FIELD_LEN - 1,
|
||||
"Host Name:",
|
||||
"What name to report this host as to client browsers",
|
||||
tconf.hostname, STRINGOBJ, NULL },
|
||||
#define LAYOUT_EMAIL 1
|
||||
{ 1, 40, 32, APACHE_EMAIL_LEN - 1,
|
||||
"Email Address:",
|
||||
"The email address of the site maintainer, e.g. [email protected]",
|
||||
tconf.email, STRINGOBJ, NULL },
|
||||
#define LAYOUT_WELCOME 2
|
||||
{ 5, 5, 20, APACHE_WELCOME_LEN - 1,
|
||||
"Default Document:",
|
||||
"The name of the default document found in each directory",
|
||||
tconf.welcome, STRINGOBJ, NULL },
|
||||
#define LAYOUT_DEFUSER 3
|
||||
{ 5, 40, 14, APACHE_DEFUSER_LEN - 1,
|
||||
"Default UserID:", "Default UID for access to web pages",
|
||||
tconf.defuser, STRINGOBJ, NULL },
|
||||
#define LAYOUT_DEFGROUP 4
|
||||
{ 5, 60, 14, APACHE_DEFGROUP_LEN - 1,
|
||||
"Default Group ID:", "Default GID for access to web pages",
|
||||
tconf.defgroup, STRINGOBJ, NULL },
|
||||
#define LAYOUT_DOCROOT 5
|
||||
{ 10, 4, 36, APACHE_DOCROOT_LEN - 1,
|
||||
"Root Document Path:",
|
||||
"The top directory that holds the system web pages",
|
||||
tconf.docroot, STRINGOBJ, NULL },
|
||||
#define LAYOUT_USERDIR 6
|
||||
{ 10, 50, 14, APACHE_USERDIR_LEN - 1,
|
||||
"User Directory:",
|
||||
"Personal sub-directory that holds users' web pages (eg. ~/Web)",
|
||||
tconf.userdir, STRINGOBJ, NULL },
|
||||
#define LAYOUT_LOGDIR 7
|
||||
{ 14, 4, 28, APACHE_LOGDIR_LEN - 1,
|
||||
"Log Dir:", "Directory to put httpd log files",
|
||||
tconf.logdir, STRINGOBJ, NULL },
|
||||
#define LAYOUT_ACCESSLOG 8
|
||||
{ 14, 38, 16, APACHE_ACCESSLOG_LEN - 1,
|
||||
"Access Log:", "Name of log file to report access",
|
||||
tconf.accesslog, STRINGOBJ, NULL },
|
||||
#define LAYOUT_ERRORLOG 9
|
||||
{ 14, 60, 16, APACHE_ERRORLOG_LEN - 1,
|
||||
"Error Log:", "Name of log file to report errors",
|
||||
tconf.errorlog, STRINGOBJ, NULL },
|
||||
#define LAYOUT_OKBUTTON 10
|
||||
{ 19, 15, 0, 0,
|
||||
"OK", "Select this if you are happy with these settings",
|
||||
&okbutton, BUTTONOBJ, NULL },
|
||||
#define LAYOUT_CANCELBUTTON 11
|
||||
{ 19, 45, 0, 0,
|
||||
"CANCEL", "Select this if you wish to cancel this screen",
|
||||
&cancelbutton, BUTTONOBJ, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
/* This is it - how to get Apache setup values */
|
||||
static int
|
||||
apacheOpenDialog(void)
|
||||
{
|
||||
WINDOW *ds_win;
|
||||
ComposeObj *obj = NULL;
|
||||
int n = 0, cancel = FALSE;
|
||||
int max;
|
||||
char *tmp;
|
||||
char title[80];
|
||||
|
||||
/* We need a curses window */
|
||||
if (!(ds_win = openLayoutDialog(APACHE_HELPFILE, " Apache HTTPD Configuration ",
|
||||
APACHE_DIALOG_X, APACHE_DIALOG_Y, APACHE_DIALOG_WIDTH, APACHE_DIALOG_HEIGHT))) {
|
||||
beep();
|
||||
msgConfirm("Cannot open apache dialog window!!");
|
||||
return DITEM_SUCCESS;
|
||||
}
|
||||
|
||||
/* Draw a sub-box for the path configuration */
|
||||
draw_box(ds_win, APACHE_DIALOG_Y + 9, APACHE_DIALOG_X + 1, APACHE_DIALOG_HEIGHT - 13, APACHE_DIALOG_WIDTH - 2,
|
||||
dialog_attr, border_attr);
|
||||
wattrset(ds_win, dialog_attr);
|
||||
sprintf(title, " Path Configuration ");
|
||||
mvwaddstr(ds_win, APACHE_DIALOG_Y + 9, APACHE_DIALOG_X + 22, title);
|
||||
|
||||
/** Initialize the config Data Structure **/
|
||||
bzero(&tconf, sizeof(tconf));
|
||||
|
||||
tmp = variable_get(VAR_DOMAINNAME);
|
||||
if (tmp) {
|
||||
sprintf(tconf.email, "webmaster@%s", tmp);
|
||||
sprintf(tconf.hostname, "www.%s", tmp);
|
||||
}
|
||||
|
||||
SAFE_STRCPY(tconf.defuser, DEFAULT_USER);
|
||||
SAFE_STRCPY(tconf.defgroup, DEFAULT_GROUP);
|
||||
|
||||
SAFE_STRCPY(tconf.userdir, USER_HOMEDIR);
|
||||
SAFE_STRCPY(tconf.welcome, WELCOME_FILE);
|
||||
|
||||
SAFE_STRCPY(tconf.logdir, LOGS_SUBDIR);
|
||||
SAFE_STRCPY(tconf.accesslog, ACCESS_LOGNAME);
|
||||
SAFE_STRCPY(tconf.errorlog, ERROR_LOGNAME);
|
||||
|
||||
sprintf(tconf.docroot, "%s/%s", APACHE_BASE,DATA_SUBDIR);
|
||||
|
||||
/* Some more initialisation before we go into the main input loop */
|
||||
obj = initLayoutDialog(ds_win, layout, APACHE_DIALOG_X, APACHE_DIALOG_Y, &max);
|
||||
|
||||
cancelbutton = okbutton = 0;
|
||||
while (layoutDialogLoop(ds_win, layout, &obj, &n, max, &cancelbutton, &cancel)) {
|
||||
if (n == LAYOUT_HOSTNAME) {
|
||||
if ((tmp = index(tconf.hostname, '.')) != NULL) {
|
||||
sprintf(tconf.email, "webmaster@%s", tmp + 1);
|
||||
RefreshStringObj(layout[LAYOUT_EMAIL].obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear this crap off the screen */
|
||||
dialog_clear_norefresh();
|
||||
use_helpfile(NULL);
|
||||
|
||||
if (cancel)
|
||||
return DITEM_FAILURE | DITEM_RESTORE;
|
||||
return DITEM_SUCCESS | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
int
|
||||
configApache(dialogMenuItem *self)
|
||||
{
|
||||
int i;
|
||||
char company[64], file[128];
|
||||
char *tptr;
|
||||
FILE *fptr;
|
||||
|
||||
/* Be optimistic */
|
||||
i = DITEM_SUCCESS;
|
||||
|
||||
dialog_clear_norefresh();
|
||||
msgConfirm("Since you elected to install the WEB server, we'll now add the\n"
|
||||
"Apache HTTPD package and set up a few configuration files.");
|
||||
i = package_add(variable_get(VAR_APACHE_PKG));
|
||||
if (DITEM_STATUS(i) != DITEM_SUCCESS) {
|
||||
msgConfirm("Hmmmmm. Looks like we weren't able to fetch the Apache WEB server\n"
|
||||
"package. You may wish to fetch and configure it by hand by looking\n"
|
||||
"in /usr/ports/net/apache (in the ports collection) or looking for the\n"
|
||||
"precompiled apache package in packages/networking/%s.", PACKAGE_APACHE);
|
||||
return i | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
dialog_clear_norefresh();
|
||||
i = apacheOpenDialog();
|
||||
if (DITEM_STATUS(i) != DITEM_SUCCESS) {
|
||||
msgConfirm("Configuration of the Apache WEB server was cancelled per\n"
|
||||
"user request.");
|
||||
return i;
|
||||
}
|
||||
/*** Fix defaults for invalid value ***/
|
||||
if (!tconf.logdir[0])
|
||||
SAFE_STRCPY(tconf.logdir, LOGS_SUBDIR);
|
||||
if (!tconf.accesslog[0])
|
||||
SAFE_STRCPY(tconf.accesslog, ACCESS_LOGNAME);
|
||||
if (!tconf.errorlog[0])
|
||||
SAFE_STRCPY(tconf.errorlog, ERROR_LOGNAME);
|
||||
|
||||
if (!tconf.welcome[0])
|
||||
SAFE_STRCPY(tconf.welcome, WELCOME_FILE);
|
||||
if (!tconf.userdir[0])
|
||||
SAFE_STRCPY(tconf.userdir, USER_HOMEDIR);
|
||||
|
||||
if (!tconf.defuser[0])
|
||||
SAFE_STRCPY(tconf.defuser, DEFAULT_USER);
|
||||
if (!tconf.defgroup[0])
|
||||
SAFE_STRCPY(tconf.defgroup, DEFAULT_GROUP);
|
||||
|
||||
/*** If the user did not specify a directory, use default ***/
|
||||
|
||||
if (tconf.docroot[strlen(tconf.docroot) - 1] == '/')
|
||||
tconf.docroot[strlen(tconf.docroot) - 1] = '\0';
|
||||
|
||||
if (!tconf.docroot[0])
|
||||
sprintf(tconf.docroot, "%s/%s", APACHE_BASE, DATA_SUBDIR);
|
||||
|
||||
/*** If DocRoot does not exist, create it ***/
|
||||
|
||||
if (!directory_exists(tconf.docroot))
|
||||
vsystem("mkdir -p %s", tconf.docroot);
|
||||
|
||||
if (directory_exists(tconf.docroot)) {
|
||||
sprintf(file, "%s/%s", tconf.docroot, tconf.welcome);
|
||||
if (!file_readable(file)) {
|
||||
tptr = msgGetInput(NULL, "What is your company name?");
|
||||
if (tptr && tptr[0])
|
||||
SAFE_STRCPY(company, tptr);
|
||||
else
|
||||
SAFE_STRCPY(company, "our Web Page");
|
||||
|
||||
msgNotify("Creating sample web page...");
|
||||
fptr = fopen(file,"w");
|
||||
if (fptr) {
|
||||
fprintf(fptr, "<CENTER>\n<TITLE>Welcome Page</TITLE>\n");
|
||||
fprintf(fptr, "<H1>Welcome to %s </H1>\n</CENTER>\n",company);
|
||||
fprintf(fptr, "<P><HR SIZE=4>\n<CENTER>\n");
|
||||
fprintf(fptr, "<A HREF=\"http://www.FreeBSD.org/What\">\n");
|
||||
fprintf(fptr, "<IMG SRC=\"%s\" ALIGN=CENTER BORDER=0 ", FREEBSD_GIF);
|
||||
fprintf(fptr, " ALT=\"Powered by FreeBSD\"></A>\n");
|
||||
if (!tconf.email[0]) {
|
||||
if ((tptr = variable_get(VAR_DOMAINNAME)))
|
||||
sprintf(tconf.email, "root@%s", tptr);
|
||||
}
|
||||
if (tconf.email[0]) {
|
||||
fprintf(fptr, "<ADDRESS><H4>\n");
|
||||
fprintf(fptr, " For questions or comments, please send mail to:\n");
|
||||
fprintf(fptr, " <A HREF=\"mailto:%s\">%s</A>\n",
|
||||
tconf.email, tconf.email);
|
||||
fprintf(fptr, "</H4></ADDRESS>\n");
|
||||
}
|
||||
fprintf(fptr, "</CENTER>\n\n");
|
||||
fclose(fptr);
|
||||
}
|
||||
else {
|
||||
msgConfirm("Unable to create sample Web Page.");
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
msgConfirm("Unable to create Document Root Directory.");
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
|
||||
msgNotify("Writing configuration files....");
|
||||
|
||||
(void)vsystem("mkdir -p %s/%s", APACHE_BASE, CONFIG_SUBDIR);
|
||||
sprintf(file, "%s/%s/access.conf", APACHE_BASE, CONFIG_SUBDIR);
|
||||
if (file_readable(file))
|
||||
vsystem("mv -f %s %s.ORIG", file, file);
|
||||
|
||||
fptr = fopen(file,"w");
|
||||
if (fptr) {
|
||||
fprintf(fptr, "<Directory %s/cgi-bin>\n", APACHE_BASE);
|
||||
fprintf(fptr, "Options Indexes FollowSymLinks\n");
|
||||
fprintf(fptr, "</Directory>\n");
|
||||
fprintf(fptr, "\n");
|
||||
fprintf(fptr, "<Directory %s>\n", tconf.docroot);
|
||||
fprintf(fptr, "Options Indexes FollowSymLinks\n");
|
||||
fprintf(fptr, "AllowOverride All\n");
|
||||
fprintf(fptr, "</Directory>\n");
|
||||
fprintf(fptr, "\n");
|
||||
fclose(fptr);
|
||||
}
|
||||
else {
|
||||
msgConfirm("Could not create %s",file);
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
|
||||
sprintf(file, "%s/%s/httpd.conf", APACHE_BASE, CONFIG_SUBDIR);
|
||||
if (file_readable(file))
|
||||
vsystem("mv -f %s %s.ORIG", file, file);
|
||||
|
||||
fptr = fopen(file,"w");
|
||||
if (fptr) {
|
||||
fprintf(fptr, "ServerType standalone\n");
|
||||
fprintf(fptr, "Port 80\n");
|
||||
fprintf(fptr, "TimeOut 400\n");
|
||||
fprintf(fptr, "\n");
|
||||
fprintf(fptr, "ErrorLog %s/%s\n", LOGS_SUBDIR, ERROR_LOGNAME);
|
||||
fprintf(fptr, "TransferLog %s/%s\n", LOGS_SUBDIR, ACCESS_LOGNAME);
|
||||
fprintf(fptr, "PidFile /var/run/httpd.pid\n");
|
||||
fprintf(fptr, "\n");
|
||||
fprintf(fptr, "StartServers 5\n");
|
||||
fprintf(fptr, "MinSpareServers 5\n");
|
||||
fprintf(fptr, "MaxSpareServers 10\n");
|
||||
fprintf(fptr, "MaxRequestsPerChild 30\n");
|
||||
fprintf(fptr, "MaxClients 150\n");
|
||||
fprintf(fptr, "\n");
|
||||
fprintf(fptr, "User %s\n",tconf.defuser);
|
||||
fprintf(fptr, "Group %s\n",tconf.defgroup);
|
||||
fprintf(fptr, "\n");
|
||||
|
||||
if (tconf.email[0])
|
||||
fprintf(fptr, "ServerAdmin %s\n", tconf.email);
|
||||
if (tconf.hostname[0])
|
||||
fprintf(fptr, "ServerName %s\n", tconf.hostname);
|
||||
|
||||
fclose(fptr);
|
||||
}
|
||||
else {
|
||||
msgConfirm("Could not create %s",file);
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
|
||||
sprintf(file, "%s/%s/srm.conf", APACHE_BASE, CONFIG_SUBDIR);
|
||||
if (file_readable(file))
|
||||
vsystem("mv -f %s %s.ORIG", file, file);
|
||||
fptr = fopen(file,"w");
|
||||
if (fptr) {
|
||||
fprintf(fptr, "FancyIndexing on\n");
|
||||
fprintf(fptr, "DefaultType text/plain\n");
|
||||
fprintf(fptr, "IndexIgnore */.??* *~ *# */HEADER* */README* */RCS\n");
|
||||
fprintf(fptr, "HeaderName HEADER\n");
|
||||
fprintf(fptr, "ReadmeName README\n");
|
||||
fprintf(fptr, "AccessFileName .htaccess\n");
|
||||
fprintf(fptr, "\n");
|
||||
fprintf(fptr, "AddEncoding x-compress Z\n");
|
||||
fprintf(fptr, "AddEncoding x-gzip gz\n");
|
||||
fprintf(fptr, "DefaultIcon /icons/unknown.gif\n");
|
||||
fprintf(fptr, "\n");
|
||||
fprintf(fptr, "AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip\n");
|
||||
fprintf(fptr, "AddIconByType (TXT,/icons/text.gif) text/*\n");
|
||||
fprintf(fptr, "AddIconByType (IMG,/icons/image2.gif) image/*\n");
|
||||
fprintf(fptr, "AddIconByType (SND,/icons/sound2.gif) audio/*\n");
|
||||
fprintf(fptr, "AddIconByType (VID,/icons/movie.gif) video/*\n");
|
||||
fprintf(fptr, "\n");
|
||||
|
||||
fprintf(fptr, "AddIcon /icons/text.gif .ps .shtml\n");
|
||||
fprintf(fptr, "AddIcon /icons/movie.gif .mpg .qt\n");
|
||||
fprintf(fptr, "AddIcon /icons/binary.gif .bin\n");
|
||||
fprintf(fptr, "AddIcon /icons/burst.gif .wrl\n");
|
||||
fprintf(fptr, "AddIcon /icons/binhex.gif .hqx .sit\n");
|
||||
fprintf(fptr, "AddIcon /icons/uu.gif .uu\n");
|
||||
fprintf(fptr, "AddIcon /icons/tar.gif .tar\n");
|
||||
fprintf(fptr, "AddIcon /icons/back.gif ..\n");
|
||||
fprintf(fptr, "AddIcon /icons/dir.gif ^^DIRECTORY^^\n");
|
||||
fprintf(fptr, "AddIcon /icons/blank.gif ^^BLANKICON^^\n");
|
||||
fprintf(fptr, "\n");
|
||||
|
||||
fprintf(fptr, "ScriptAlias /cgi_bin/ %s/cgi_bin/\n",APACHE_BASE);
|
||||
fprintf(fptr, "Alias /icons/ %s/icons/\n",APACHE_BASE);
|
||||
fprintf(fptr, "DocumentRoot %s\n",tconf.docroot);
|
||||
fprintf(fptr, "UserDir %s\n", tconf.userdir);
|
||||
fprintf(fptr, "DirectoryIndex %s\n", tconf.welcome);
|
||||
fprintf(fptr, "\n");
|
||||
|
||||
fclose(fptr);
|
||||
}
|
||||
else {
|
||||
msgConfirm("Could not create %s",file);
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
if (DITEM_STATUS(i) == DITEM_SUCCESS)
|
||||
variable_set2("apache_httpd", "YES");
|
||||
return i | DITEM_RESTORE;
|
||||
}
|
||||
+19
-25
@@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated to essentially a complete rewrite.
|
||||
*
|
||||
* $Id: attr.c,v 1.8 1996/09/08 01:39:23 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -38,36 +38,36 @@
|
||||
|
||||
#include "sysinstall.h"
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
int
|
||||
attr_parse_file(Attribs *attr, char *file)
|
||||
{
|
||||
int fd, status;
|
||||
int status;
|
||||
FILE *fp;
|
||||
|
||||
if ((fd = open(file, O_RDONLY)) == -1) {
|
||||
if ((fp = fopen(file, "r")) == NULL) {
|
||||
msgConfirm("Cannot open the information file `%s': %s (%d)", file, strerror(errno), errno);
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
status = attr_parse(attr, fd);
|
||||
close(fd);
|
||||
status = attr_parse(attr, fp);
|
||||
fclose(fp);
|
||||
return status;
|
||||
}
|
||||
|
||||
int
|
||||
attr_parse(Attribs *attr, int fd)
|
||||
attr_parse(Attribs *attr, FILE *fp)
|
||||
{
|
||||
char hold_n[MAX_NAME+1];
|
||||
char hold_v[MAX_VALUE+1];
|
||||
int n, v;
|
||||
enum { LOOK, COMMENT, NAME, VALUE, COMMIT } state;
|
||||
int lno, num_attribs;
|
||||
char ch;
|
||||
int ch;
|
||||
|
||||
n = v = lno = num_attribs = 0;
|
||||
state = LOOK;
|
||||
while (state == COMMIT || (read(fd, &ch, 1) == 1)) {
|
||||
while (state == COMMIT || (fread(&ch, 1, 1, fp) == 1)) {
|
||||
/* Count lines */
|
||||
if (ch == '\n')
|
||||
++lno;
|
||||
@@ -116,7 +116,7 @@ attr_parse(Attribs *attr, int fd)
|
||||
continue;
|
||||
else if (ch == '{') {
|
||||
/* multiline value */
|
||||
while (read(fd, &ch, 1) == 1 && ch != '}') {
|
||||
while (fread(&ch, 1, 1, fp) == 1 && ch != '}') {
|
||||
if (v == MAX_VALUE)
|
||||
msgFatal("Value length overflow at line %d", lno);
|
||||
hold_v[v++] = ch;
|
||||
@@ -137,22 +137,23 @@ attr_parse(Attribs *attr, int fd)
|
||||
break;
|
||||
|
||||
case COMMIT:
|
||||
strcpy(attr[num_attribs].name, hold_n);
|
||||
strcpy(attr[num_attribs].value, hold_v);
|
||||
SAFE_STRCPY(attr[num_attribs].name, hold_n);
|
||||
SAFE_STRCPY(attr[num_attribs].value, hold_v);
|
||||
state = LOOK;
|
||||
v = n = 0;
|
||||
++num_attribs;
|
||||
if (++num_attribs >= MAX_ATTRIBS)
|
||||
msgFatal("Attribute limit overflow; encountered a bad attributes file!");
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
msgFatal("Unknown state at line %d??", lno);
|
||||
}
|
||||
}
|
||||
attr[num_attribs].name[0] = '\0'; /* end marker */
|
||||
attr[num_attribs].value[0] = '\0'; /* end marker */
|
||||
attr[num_attribs].name[0] = NULL; /* end marker */
|
||||
attr[num_attribs].value[0] = NULL; /* end marker */
|
||||
if (isDebug())
|
||||
msgDebug("Finished parsing %d attributes.\n", num_attribs);
|
||||
|
||||
|
||||
return DITEM_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -164,19 +165,12 @@ attr_match(Attribs *attr, char *name)
|
||||
if (isDebug())
|
||||
msgDebug("Trying to match attribute `%s'\n", name);
|
||||
|
||||
for (n = 0; attr[n].name[0] && strcasecmp(attr[n].name, name) != 0; n++) {
|
||||
if (isDebug())
|
||||
msgDebug("Skipping attribute %u\n", n);
|
||||
}
|
||||
|
||||
if (isDebug())
|
||||
msgDebug("Stopped on attribute %u\n", n);
|
||||
for (n = 0; attr[n].name[0] && strcasecmp(attr[n].name, name); n++);
|
||||
|
||||
if (attr[n].name[0]) {
|
||||
if (isDebug())
|
||||
msgDebug("Returning `%s'\n", attr[n].value);
|
||||
return(attr[n].value);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
+62
-58
@@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated to essentially a complete rewrite.
|
||||
*
|
||||
* $Id: cdrom.c,v 1.26 1996/10/14 21:32:22 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -51,13 +51,7 @@
|
||||
#include <sys/mount.h>
|
||||
#undef CD9660
|
||||
|
||||
/*
|
||||
* This isn't a boolean like the others since we have 3 states for it:
|
||||
* 0 = cdrom isn't mounted, 1 = cdrom is mounted and we mounted it, 2 = cdrom
|
||||
* was already mounted when we came in and we should leave it that way when
|
||||
* we leave.
|
||||
*/
|
||||
static int cdromMounted;
|
||||
static Boolean cdromMounted;
|
||||
|
||||
Boolean
|
||||
mediaInitCDROM(Device *dev)
|
||||
@@ -65,9 +59,10 @@ mediaInitCDROM(Device *dev)
|
||||
struct iso_args args;
|
||||
Attribs *cd_attr;
|
||||
char *cp;
|
||||
Boolean dontRead;
|
||||
Boolean readInfo = TRUE;
|
||||
char *mountpoint = "/dist";
|
||||
|
||||
if (cdromMounted != CD_UNMOUNTED)
|
||||
if (cdromMounted)
|
||||
return TRUE;
|
||||
|
||||
bzero(&args, sizeof(args));
|
||||
@@ -76,83 +71,92 @@ mediaInitCDROM(Device *dev)
|
||||
|
||||
cd_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS);
|
||||
cp = NULL;
|
||||
dontRead = FALSE;
|
||||
/* If this cdrom's not already mounted or can't be mounted, yell */
|
||||
if (!file_readable("/cdrom/cdrom.inf")) {
|
||||
Mkdir("/cdrom");
|
||||
if (mount(MOUNT_CD9660, "/cdrom", MNT_RDONLY, (caddr_t) &args) == -1) {
|
||||
if (errno != EBUSY) {
|
||||
msgConfirm("Error mounting %s on /cdrom: %s (%u)", dev->devname, strerror(errno), errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Mkdir(mountpoint);
|
||||
|
||||
if (mount(MOUNT_CD9660, mountpoint, MNT_RDONLY, (caddr_t) &args) == -1) {
|
||||
if (errno == EINVAL) {
|
||||
msgConfirm("The CD in your drive looks more like an Audio CD than a FreeBSD release.");
|
||||
return FALSE;
|
||||
}
|
||||
if (!file_readable("/cdrom/cdrom.inf")) {
|
||||
if (msgYesNo("Warning: The CD currently in the drive is either not a FreeBSD\n"
|
||||
"CD or it is an older (pre 2.1.5) FreeBSD CD which does not\n"
|
||||
"have a version number on it. Do you wish to use this CD anyway?") != 0) {
|
||||
unmount("/cdrom", MNT_FORCE);
|
||||
return FALSE;
|
||||
}
|
||||
dontRead = TRUE;
|
||||
else if (errno != EBUSY) {
|
||||
msgConfirm("Error mounting %s on %s: %s (%u)", dev->devname, mountpoint, strerror(errno), errno);
|
||||
return FALSE;
|
||||
}
|
||||
cdromMounted = CD_WE_MOUNTED_IT;
|
||||
cdromMounted = TRUE;
|
||||
}
|
||||
else
|
||||
cdromMounted = CD_ALREADY_MOUNTED;
|
||||
if (!dontRead && (DITEM_STATUS(attr_parse_file(cd_attr, "/cdrom/cdrom.inf")) == DITEM_FAILURE ||
|
||||
!(cp = attr_match(cd_attr, "CD_VERSION")) || strcmp(cp, variable_get(VAR_RELNAME)))) {
|
||||
unmount("/cdrom", MNT_FORCE);
|
||||
|
||||
if (!file_readable(string_concat(mountpoint, "/cdrom.inf"))) {
|
||||
if (msgYesNo("Warning: The CD currently in the drive is either not a FreeBSD\n"
|
||||
"CD or it is an older (pre 2.1.5) FreeBSD CD which does not\n"
|
||||
"have a version number on it. Do you wish to use this CD anyway?") != 0) {
|
||||
unmount(mountpoint, MNT_FORCE);
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
readInfo = FALSE;
|
||||
}
|
||||
|
||||
if (readInfo &&
|
||||
(DITEM_STATUS(attr_parse_file(cd_attr, string_concat(mountpoint, "/cdrom.inf"))) == DITEM_FAILURE ||
|
||||
!(cp = attr_match(cd_attr, "CD_VERSION")) || (strcmp(cp, variable_get(VAR_RELNAME)) && strcmp("none", variable_get(VAR_RELNAME))))) {
|
||||
if (!cp)
|
||||
msgConfirm("Unable to find a /cdrom/cdrom.inf file.\n"
|
||||
msgConfirm("Unable to find a %s/cdrom.inf file.\n"
|
||||
"Either this is not a FreeBSD CDROM, there is a problem with\n"
|
||||
"the CDROM driver or something is wrong with your hardware.\n"
|
||||
"Please fix this problem (check the console logs on VTY2) and\n"
|
||||
"try again.");
|
||||
"try again.", mountpoint);
|
||||
else
|
||||
msgConfirm("Warning: The version of the FreeBSD CD currently in the drive\n"
|
||||
"(%s) does not match the version of this boot floppy\n"
|
||||
"(%s) does not match the version of the boot floppy\n"
|
||||
"(%s).\n\n"
|
||||
"If this is intentional, then please visit the Options editor\n"
|
||||
"to set the boot floppy version string to match that of the CD\n"
|
||||
"before selecting it as an installation media to avoid this warning", cp, variable_get(VAR_RELNAME));
|
||||
"If this is intentional, to avoid this message in the future\n"
|
||||
"please visit the Options editor to set the boot floppy version\n"
|
||||
"string to match that of the CD before selecting it as your\n"
|
||||
"installation media.", cp, variable_get(VAR_RELNAME));
|
||||
|
||||
if (msgYesNo("Would you like to try and use this CDROM anyway?") != 0) {
|
||||
unmount(mountpoint, MNT_FORCE);
|
||||
cdromMounted = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
msgDebug("Mounted FreeBSD CDROM on device %s as /cdrom\n", dev->devname);
|
||||
msgDebug("Mounted FreeBSD CDROM from device %s\n", dev->devname);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
FILE *
|
||||
mediaGetCDROM(Device *dev, char *file, Boolean probe)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
|
||||
if (isDebug())
|
||||
msgDebug("Request for %s from CDROM\n", file);
|
||||
snprintf(buf, PATH_MAX, "/cdrom/%s", file);
|
||||
snprintf(buf, PATH_MAX, "/dist/%s", file);
|
||||
if (file_readable(buf))
|
||||
return open(buf, O_RDONLY);
|
||||
snprintf(buf, PATH_MAX, "/cdrom/dists/%s", file);
|
||||
return fopen(buf, "r");
|
||||
snprintf(buf, PATH_MAX, "/dist/dists/%s", file);
|
||||
if (file_readable(buf))
|
||||
return open(buf, O_RDONLY);
|
||||
snprintf(buf, PATH_MAX, "/cdrom/%s/%s", variable_get(VAR_RELNAME), file);
|
||||
return fopen(buf, "r");
|
||||
snprintf(buf, PATH_MAX, "/dist/%s/%s", variable_get(VAR_RELNAME), file);
|
||||
if (file_readable(buf))
|
||||
return open(buf, O_RDONLY);
|
||||
snprintf(buf, PATH_MAX, "/cdrom/%s/dists/%s", variable_get(VAR_RELNAME), file);
|
||||
return open(buf, O_RDONLY);
|
||||
return fopen(buf, "r");
|
||||
snprintf(buf, PATH_MAX, "/dist/%s/dists/%s", variable_get(VAR_RELNAME), file);
|
||||
return fopen(buf, "r");
|
||||
}
|
||||
|
||||
void
|
||||
mediaShutdownCDROM(Device *dev)
|
||||
{
|
||||
/* Only undo it if we did it */
|
||||
if (cdromMounted != CD_WE_MOUNTED_IT)
|
||||
char *mountpoint = "/dist";
|
||||
|
||||
if (!cdromMounted)
|
||||
return;
|
||||
msgDebug("Unmounting %s from /cdrom\n", dev->devname);
|
||||
if (unmount("/cdrom", MNT_FORCE) != 0) {
|
||||
msgConfirm("Could not unmount the CDROM from /cdrom: %s", strerror(errno));
|
||||
cdromMounted = CD_ALREADY_MOUNTED; /* Guess somebody else got it */
|
||||
}
|
||||
msgDebug("Unmounting %s from %s\n", dev->devname, mountpoint);
|
||||
if (unmount(mountpoint, MNT_FORCE) != 0)
|
||||
msgConfirm("Could not unmount the CDROM from %s: %s", mountpoint, strerror(errno));
|
||||
else {
|
||||
msgDebug("Unmount successful\n");
|
||||
cdromMounted = CD_UNMOUNTED;
|
||||
msgDebug("Unmount of CDROM successful\n");
|
||||
cdromMounted = FALSE;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: command.c,v 1.14 1996/04/13 13:31:24 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
|
||||
+205
-83
@@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: config.c,v 1.16.2.64 1996/11/07 09:16:37 jkh Exp $
|
||||
* $Id: config.c,v 1.16.2.72 1997/02/16 23:36:12 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
static Chunk *chunk_list[MAX_CHUNKS];
|
||||
static int nchunks;
|
||||
static int rootdev_is_od;
|
||||
|
||||
/* arg to sort */
|
||||
static int
|
||||
@@ -85,6 +86,21 @@ chunk_sort(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_rootdev(Chunk **list, int n)
|
||||
{
|
||||
int i;
|
||||
Chunk *c;
|
||||
|
||||
rootdev_is_od = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
c = *list++;
|
||||
if (c->type == part && (c->flags & CHUNK_IS_ROOT)
|
||||
&& strncmp(c->disk->name, "od", 2) == 0)
|
||||
rootdev_is_od = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
name_of(Chunk *c1)
|
||||
{
|
||||
@@ -127,21 +143,33 @@ static char *
|
||||
fstype_short(Chunk *c1)
|
||||
{
|
||||
if (c1->type == part) {
|
||||
if (c1->subtype != FS_SWAP)
|
||||
return "rw";
|
||||
if (c1->subtype != FS_SWAP) {
|
||||
if (rootdev_is_od == 0 && strncmp(c1->name, "od", 2) == 0)
|
||||
return "rw,noauto";
|
||||
else
|
||||
return "rw";
|
||||
}
|
||||
else
|
||||
return "sw";
|
||||
}
|
||||
else if (c1->type == fat)
|
||||
return "ro";
|
||||
else if (c1->type == fat) {
|
||||
if (strncmp(c1->name, "od", 2) == 0)
|
||||
return "ro,noauto";
|
||||
else
|
||||
return "ro";
|
||||
}
|
||||
return "bog";
|
||||
}
|
||||
|
||||
static int
|
||||
seq_num(Chunk *c1)
|
||||
{
|
||||
if (c1->type == part && c1->subtype != FS_SWAP)
|
||||
return 1;
|
||||
if (c1->type == part && c1->subtype != FS_SWAP) {
|
||||
if (rootdev_is_od == 0 && strncmp(c1->name, "od", 2) == 0)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -199,13 +227,17 @@ configFstab(void)
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
|
||||
check_rootdev(chunk_list, nchunks);
|
||||
|
||||
/* Go for the burn */
|
||||
msgDebug("Generating /etc/fstab file\n");
|
||||
fprintf(fstab, "# Device\t\tMountpoint\tFStype\tOptions\t\tDump?\tfsck pass#\n");
|
||||
fprintf(fstab, "#\t\t\t\t\t\t\t\t\t(0=no) (0=no fsck)\n");
|
||||
for (i = 0; i < nchunks; i++)
|
||||
fprintf(fstab, "/dev/%s\t\t\t%s\t\t%s\t%s %d %d\n", name_of(chunk_list[i]), mount_point(chunk_list[i]),
|
||||
fprintf(fstab, "/dev/%s\t\t%s\t\t%s\t%s\t\t%d\t%d\n", name_of(chunk_list[i]), mount_point(chunk_list[i]),
|
||||
fstype(chunk_list[i]), fstype_short(chunk_list[i]), seq_num(chunk_list[i]), seq_num(chunk_list[i]));
|
||||
Mkdir("/proc");
|
||||
fprintf(fstab, "proc\t\t\t\t/proc\t\tprocfs\trw 0 0\n");
|
||||
fprintf(fstab, "proc\t\t\t/proc\t\tprocfs\t\trw\t0\t0\n");
|
||||
|
||||
/* Now look for the CDROMs */
|
||||
devs = deviceFind(NULL, DEVICE_TYPE_CDROM);
|
||||
@@ -217,7 +249,7 @@ configFstab(void)
|
||||
msgConfirm("Unable to make mount point for: /cdrom");
|
||||
}
|
||||
else
|
||||
fprintf(fstab, "/dev/%s\t\t\t/cdrom\t\tcd9660\tro,noauto 0 0\n", devs[0]->name);
|
||||
fprintf(fstab, "/dev/%s\t\t/cdrom\tcd9660\t\tro,noauto\t0\t0\n", devs[0]->name);
|
||||
}
|
||||
|
||||
/* Write the others out as /cdrom<n> */
|
||||
@@ -229,7 +261,7 @@ configFstab(void)
|
||||
msgConfirm("Unable to make mount point for: %s", cdname);
|
||||
}
|
||||
else
|
||||
fprintf(fstab, "/dev/%s\t\t\t%s\t\tcd9660\tro,noauto 0 0\n", devs[i]->name, cdname);
|
||||
fprintf(fstab, "/dev/%s\t\t%s\tcd9660\t\tro,noauto\t0\t0\n", devs[i]->name, cdname);
|
||||
}
|
||||
fclose(fstab);
|
||||
if (isDebug())
|
||||
@@ -237,86 +269,163 @@ configFstab(void)
|
||||
return DITEM_SUCCESS;
|
||||
}
|
||||
|
||||
/* Do the work of sucking in a config file.
|
||||
* config is the filename to read in.
|
||||
* lines is a fixed (max) sized array of char *.
|
||||
* returns number of lines read. line contents
|
||||
* are malloc'd and must be freed by the caller.
|
||||
*/
|
||||
int
|
||||
readConfig(char *config, char **lines, int max)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[256];
|
||||
int i, nlines;
|
||||
|
||||
fp = fopen(config, "r");
|
||||
if (!fp)
|
||||
return -1;
|
||||
|
||||
nlines = 0;
|
||||
/* Read in the entire file */
|
||||
for (i = 0; i < max; i++) {
|
||||
if (!fgets(line, sizeof line, fp))
|
||||
break;
|
||||
lines[nlines++] = strdup(line);
|
||||
}
|
||||
fclose(fp);
|
||||
if (isDebug())
|
||||
msgDebug("readConfig: Read %d lines from %s.\n", nlines, config);
|
||||
return nlines;
|
||||
}
|
||||
|
||||
#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
|
||||
|
||||
/* Load the environment from a sysconfig file */
|
||||
void
|
||||
configEnvironmentSysconfig(char *config)
|
||||
{
|
||||
char *lines[MAX_LINES], *cp, *cp2;
|
||||
int i, j, nlines;
|
||||
|
||||
nlines = readConfig(config, lines, MAX_LINES);
|
||||
if (nlines == -1)
|
||||
return;
|
||||
|
||||
for (i = 0; i < nlines; i++) {
|
||||
/* Skip the comments & non-variable settings */
|
||||
if (lines[i][0] == '#' || !(cp = index(lines[i], '='))) {
|
||||
free(lines[i]);
|
||||
continue;
|
||||
}
|
||||
*cp++ = '\0';
|
||||
(void)string_prune(lines[i]);
|
||||
cp = string_skipwhite(string_prune(cp));
|
||||
if ((cp2 = index(cp, '"'))) /* Eliminate leading quote if it's quoted */
|
||||
cp = cp2 + 1;
|
||||
j = strlen(cp) - 1;
|
||||
if (cp[j] == '"') /* And trailing one */
|
||||
cp[j] = '\0';
|
||||
if (strlen(cp))
|
||||
variable_set2(lines[i], cp);
|
||||
free(lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Load the environment from a resolv.conf file */
|
||||
void
|
||||
configEnvironmentResolv(char *config)
|
||||
{
|
||||
char *lines[MAX_LINES];
|
||||
int i, nlines;
|
||||
|
||||
nlines = readConfig(config, lines, MAX_LINES);
|
||||
if (nlines == -1)
|
||||
return;
|
||||
for (i = 0; i < nlines; i++) {
|
||||
Boolean name_set = FALSE;
|
||||
|
||||
if (!strncmp(lines[i], "domain", 6))
|
||||
variable_set2(VAR_DOMAINNAME, string_skipwhite(lines[i] + 6));
|
||||
else if (!strncmp(lines[i], "nameserver", 10) && !name_set) {
|
||||
/* Only take the first nameserver setting - we're lame */
|
||||
variable_set2(VAR_NAMESERVER, string_skipwhite(lines[i] + 10));
|
||||
name_set = TRUE;
|
||||
}
|
||||
free(lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This sucks in /etc/sysconfig, substitutes anything needing substitution, then
|
||||
* writes it all back out. It's pretty gross and needs re-writing at some point.
|
||||
*/
|
||||
|
||||
#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
|
||||
void
|
||||
configSysconfig(char *config)
|
||||
{
|
||||
FILE *fp;
|
||||
char *lines[MAX_LINES], *cp;
|
||||
char line[256];
|
||||
Variable *v;
|
||||
int i, nlines;
|
||||
|
||||
fp = fopen(config, "r");
|
||||
if (!fp) {
|
||||
nlines = readConfig(config, lines, MAX_LINES);
|
||||
if (nlines == -1) {
|
||||
msgConfirm("Unable to open %s file! This is bad!", config);
|
||||
return;
|
||||
}
|
||||
msgNotify("Writing configuration changes to %s file..", config);
|
||||
|
||||
nlines = 0;
|
||||
/* Read in the entire file */
|
||||
for (i = 0; i < MAX_LINES; i++) {
|
||||
if (!fgets(line, 255, fp))
|
||||
break;
|
||||
lines[nlines++] = strdup(line);
|
||||
}
|
||||
msgDebug("Read %d lines from %s.\n", nlines, config);
|
||||
/* Now do variable substitutions */
|
||||
for (v = VarHead; v; v = v->next) {
|
||||
for (i = 0; i < nlines; i++) {
|
||||
char tmp[256];
|
||||
char line[512];
|
||||
|
||||
/* Skip the comments */
|
||||
if (lines[i][0] == '#')
|
||||
for (i = 0; i < nlines; i++) {
|
||||
/* Skip the comments & non-variable settings */
|
||||
if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
|
||||
continue;
|
||||
strcpy(tmp, lines[i]);
|
||||
cp = index(tmp, '=');
|
||||
if (!cp)
|
||||
continue;
|
||||
*(cp++) = '\0';
|
||||
if (!strcmp(tmp, v->name)) {
|
||||
sstrncpy(line, lines[i], cp - lines[i]);
|
||||
if (!strcmp(line, v->name)) {
|
||||
free(lines[i]);
|
||||
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + 5);
|
||||
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
|
||||
msgDebug("Variable substitution on: %s\n", lines[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now write it all back out again */
|
||||
fclose(fp);
|
||||
if (Fake) {
|
||||
msgDebug("Writing %s out to debugging screen..\n", config);
|
||||
if (isDebug())
|
||||
msgDebug("Writing configuration changes to %s file..", config);
|
||||
if (Fake)
|
||||
fp = fdopen(DebugFD, "w");
|
||||
}
|
||||
else
|
||||
else {
|
||||
(void)vsystem("cp %s %s.previous", config, config);
|
||||
fp = fopen(config, "w");
|
||||
}
|
||||
for (i = 0; i < nlines; i++) {
|
||||
static Boolean firstTime = TRUE;
|
||||
|
||||
fprintf(fp, lines[i]);
|
||||
/* Stand by for bogus special case handling - we try to dump the interface specs here */
|
||||
if (firstTime && !strncmp(lines[i], VAR_INTERFACES, strlen(VAR_INTERFACES))) {
|
||||
if (!strncmp(lines[i], VAR_INTERFACES, strlen(VAR_INTERFACES))) {
|
||||
Device **devp;
|
||||
int j, cnt;
|
||||
|
||||
devp = deviceFind(NULL, DEVICE_TYPE_NETWORK);
|
||||
cnt = deviceCount(devp);
|
||||
for (j = 0; j < cnt; j++) {
|
||||
char iname[255];
|
||||
char iname[255], toadd[512];
|
||||
int k, addit = TRUE;
|
||||
|
||||
snprintf(iname, 255, "%s%s", VAR_IFCONFIG, devp[j]->name);
|
||||
if ((cp = variable_get(iname))) {
|
||||
fprintf(fp, "%s=\"%s\"\n", iname, cp);
|
||||
snprintf(toadd, sizeof toadd, "%s=\"%s\"\n", iname, cp);
|
||||
for (k = 0; k < nlines; k++) {
|
||||
if (!strcmp(lines[k], toadd)) {
|
||||
addit = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (addit)
|
||||
fprintf(fp, toadd);
|
||||
}
|
||||
}
|
||||
firstTime = FALSE;
|
||||
}
|
||||
free(lines[i]);
|
||||
}
|
||||
@@ -354,16 +463,38 @@ configNTP(dialogMenuItem *self)
|
||||
return status | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
int
|
||||
configUsers(dialogMenuItem *self)
|
||||
{
|
||||
dialog_clear_norefresh();
|
||||
dmenuOpenSimple(&MenuUsermgmt, FALSE);
|
||||
dialog_clear();
|
||||
return DITEM_SUCCESS | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
int
|
||||
configXFree86(dialogMenuItem *self)
|
||||
{
|
||||
if (file_executable("/usr/X11R6/bin/XF86Setup")) {
|
||||
char *config, *execfile;
|
||||
|
||||
dialog_clear_norefresh();
|
||||
dmenuOpenSimple(&MenuXF86Config, FALSE);
|
||||
|
||||
config = variable_get(VAR_XF86_CONFIG);
|
||||
if (!config)
|
||||
return DITEM_FAILURE | DITEM_RESTORE;
|
||||
execfile = string_concat("/usr/X11R6/bin/", config);
|
||||
if (file_executable(execfile)) {
|
||||
dialog_clear_norefresh();
|
||||
if (!file_readable("/dev/mouse") && !msgYesNo("Does this system have a mouse attached to it?"))
|
||||
dmenuOpenSimple(&MenuMouse, FALSE);
|
||||
dialog_clear();
|
||||
systemExecute("/sbin/ldconfig /usr/lib /usr/X11R6/lib /usr/local/lib /usr/lib/compat");
|
||||
systemExecute("/usr/X11R6/bin/XF86Setup");
|
||||
systemExecute(execfile);
|
||||
return DITEM_SUCCESS | DITEM_RESTORE;
|
||||
}
|
||||
else {
|
||||
dialog_clear_norefresh();
|
||||
msgConfirm("XFree86 does not appear to be installed! Please install\n"
|
||||
"The XFree86 distribution before attempting to configure it.");
|
||||
return DITEM_FAILURE;
|
||||
@@ -376,23 +507,13 @@ configResolv(void)
|
||||
FILE *fp;
|
||||
char *cp, *dp, *hp;
|
||||
|
||||
if (!RunningAsInit || file_readable("/etc/resolv.conf"))
|
||||
return;
|
||||
|
||||
if (Mkdir("/etc")) {
|
||||
msgConfirm("Unable to create /etc directory. Network configuration\n"
|
||||
"files will therefore not be written!");
|
||||
return;
|
||||
}
|
||||
|
||||
cp = variable_get(VAR_NAMESERVER);
|
||||
if (!cp || !*cp)
|
||||
goto skip;
|
||||
Mkdir("/etc");
|
||||
fp = fopen("/etc/resolv.conf", "w");
|
||||
if (!fp) {
|
||||
msgConfirm("Unable to open /etc/resolv.conf! You will need to do this manually.");
|
||||
if (!fp)
|
||||
return;
|
||||
}
|
||||
if (variable_get(VAR_DOMAINNAME))
|
||||
fprintf(fp, "domain\t%s\n", variable_get(VAR_DOMAINNAME));
|
||||
fprintf(fp, "nameserver\t%s\n", cp);
|
||||
@@ -401,23 +522,23 @@ configResolv(void)
|
||||
msgDebug("Wrote out /etc/resolv.conf\n");
|
||||
|
||||
skip:
|
||||
/* Tack ourselves into /etc/hosts */
|
||||
fp = fopen("/etc/hosts", "w");
|
||||
|
||||
/* Add an entry for localhost */
|
||||
dp = variable_get(VAR_DOMAINNAME);
|
||||
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
|
||||
|
||||
/* Now the host entries, if applicable */
|
||||
cp = variable_get(VAR_IPADDR);
|
||||
hp = variable_get(VAR_HOSTNAME);
|
||||
/* Tack ourselves into /etc/hosts */
|
||||
fp = fopen("/etc/hosts", "w");
|
||||
if (!fp)
|
||||
return;
|
||||
/* Add an entry for localhost */
|
||||
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
|
||||
/* Now the host entries, if applicable */
|
||||
if (cp && cp[0] != '0' && hp) {
|
||||
char cp2[255];
|
||||
|
||||
if (!index(hp, '.'))
|
||||
cp2[0] = '\0';
|
||||
else {
|
||||
strcpy(cp2, hp);
|
||||
SAFE_STRCPY(cp2, hp);
|
||||
*(index(cp2, '.')) = '\0';
|
||||
}
|
||||
fprintf(fp, "%s\t\t%s %s\n", cp, hp, cp2);
|
||||
@@ -425,7 +546,7 @@ skip:
|
||||
}
|
||||
fclose(fp);
|
||||
if (isDebug())
|
||||
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
|
||||
msgDebug("Wrote out /etc/hosts\n");
|
||||
}
|
||||
|
||||
int
|
||||
@@ -440,7 +561,7 @@ configRouter(dialogMenuItem *self)
|
||||
"will attempt to load if you select gated. Any other\n"
|
||||
"choice of routing daemon will be assumed to be something\n"
|
||||
"the user intends to install themselves before rebooting\n"
|
||||
"the system. If you don't want any routing daemon, say NO") ?
|
||||
"the system. If you don't want any routing daemon, choose NO") ?
|
||||
DITEM_SUCCESS : DITEM_FAILURE;
|
||||
|
||||
if (ret == DITEM_SUCCESS) {
|
||||
@@ -449,9 +570,9 @@ configRouter(dialogMenuItem *self)
|
||||
cp = variable_get(VAR_ROUTER);
|
||||
if (strcmp(cp, "NO")) {
|
||||
if (!strcmp(cp, "gated")) {
|
||||
if (package_add(PACKAGE_GATED) != DITEM_SUCCESS) {
|
||||
msgConfirm("Unable to load gated package. Falling back to routed.");
|
||||
variable_set2(VAR_ROUTER, "routed");
|
||||
if (package_add(variable_get(VAR_GATED_PKG)) != DITEM_SUCCESS) {
|
||||
msgConfirm("Unable to load gated package. Falling back to no router.");
|
||||
variable_set2(VAR_ROUTER, "NO");
|
||||
}
|
||||
}
|
||||
/* Now get the flags, if they chose a router */
|
||||
@@ -473,7 +594,7 @@ configPackages(dialogMenuItem *self)
|
||||
static PkgNode top, plist;
|
||||
static Boolean index_initted = FALSE;
|
||||
PkgNodePtr tmp;
|
||||
int fd;
|
||||
FILE *fp;
|
||||
|
||||
if (!mediaVerify())
|
||||
return DITEM_FAILURE;
|
||||
@@ -483,8 +604,8 @@ configPackages(dialogMenuItem *self)
|
||||
|
||||
if (!index_initted) {
|
||||
msgNotify("Attempting to fetch packages/INDEX file from selected media.");
|
||||
fd = mediaDevice->get(mediaDevice, "packages/INDEX", TRUE);
|
||||
if (fd < 0) {
|
||||
fp = mediaDevice->get(mediaDevice, "packages/INDEX", TRUE);
|
||||
if (!fp) {
|
||||
dialog_clear_norefresh();
|
||||
msgConfirm("Unable to get packages/INDEX file from selected media.\n"
|
||||
"This may be because the packages collection is not available at\n"
|
||||
@@ -493,17 +614,18 @@ configPackages(dialogMenuItem *self)
|
||||
"(or path to media) and try again. If your local site does not\n"
|
||||
"carry the packages collection, then we recommend either a CD\n"
|
||||
"distribution or the master distribution on ftp.freebsd.org.");
|
||||
mediaDevice->shutdown(mediaDevice);
|
||||
return DITEM_FAILURE | DITEM_RESTORE;
|
||||
}
|
||||
msgNotify("Got INDEX successfully, now building packages menu..");
|
||||
msgNotify("Located INDEX, now reading package data from it...");
|
||||
index_init(&top, &plist);
|
||||
if (index_read(fd, &top)) {
|
||||
if (index_read(fp, &top)) {
|
||||
msgConfirm("I/O or format error on packages/INDEX file.\n"
|
||||
"Please verify media (or path to media) and try again.");
|
||||
mediaDevice->close(mediaDevice, fd);
|
||||
fclose(fp);
|
||||
return DITEM_FAILURE | DITEM_RESTORE;
|
||||
}
|
||||
mediaDevice->close(mediaDevice, fd);
|
||||
fclose(fp);
|
||||
index_sort(&top);
|
||||
index_initted = TRUE;
|
||||
}
|
||||
@@ -539,7 +661,7 @@ configPackages(dialogMenuItem *self)
|
||||
tmp = tmp2;
|
||||
}
|
||||
index_init(NULL, &plist);
|
||||
return DITEM_SUCCESS | DITEM_RESTORE | DITEM_RECREATE;
|
||||
return DITEM_SUCCESS | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
#ifdef NETCON_EXTENTIONS
|
||||
@@ -573,7 +695,7 @@ configPCNFSD(dialogMenuItem *self)
|
||||
if (variable_get(VAR_PCNFSD))
|
||||
variable_unset(VAR_PCNFSD);
|
||||
else {
|
||||
ret = package_add(PACKAGE_PCNFSD);
|
||||
ret = package_add(variable_get(VAR_PCNFSD_PKG));
|
||||
if (DITEM_STATUS(ret) == DITEM_SUCCESS) {
|
||||
variable_set2(VAR_PCNFSD, "YES");
|
||||
variable_set2("weak_mountd_authentication", "YES");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: devices.c,v 1.49 1996/10/05 11:56:47 jkh Exp $
|
||||
* $Id: devices.c,v 1.36.2.23 1997/02/07 04:25:35 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -35,19 +35,17 @@
|
||||
*/
|
||||
|
||||
#include "sysinstall.h"
|
||||
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
static Device *Devices[DEV_MAX];
|
||||
@@ -68,26 +66,28 @@ static struct {
|
||||
{ DEVICE_TYPE_TAPE, "rwt0", "Wangtek tape drive" },
|
||||
{ DEVICE_TYPE_DISK, "sd", "SCSI disk device" },
|
||||
{ DEVICE_TYPE_DISK, "wd", "IDE/ESDI/MFM/ST506 disk device" },
|
||||
{ DEVICE_TYPE_DISK, "od", "SCSI optical disk device" },
|
||||
{ DEVICE_TYPE_FLOPPY, "fd0", "floppy drive unit A" },
|
||||
{ DEVICE_TYPE_FLOPPY, "fd1", "floppy drive unit B" },
|
||||
{ DEVICE_TYPE_FLOPPY, "od0", "SCSI optical disk/floppy format" },
|
||||
{ DEVICE_TYPE_NETWORK, "cuaa0", "%s on serial port 0 (COM1)" },
|
||||
{ DEVICE_TYPE_NETWORK, "cuaa1", "%s on serial port 1 (COM2)" },
|
||||
{ DEVICE_TYPE_NETWORK, "cuaa2", "%s on serial port 2 (COM3)" },
|
||||
{ DEVICE_TYPE_NETWORK, "cuaa3", "%s on serial port 3 (COM4)" },
|
||||
{ DEVICE_TYPE_NETWORK, "lp0", "Parallel Port IP (PLIP) using laplink cable" },
|
||||
{ DEVICE_TYPE_NETWORK, "lo", "Loop-back (local) network interface" },
|
||||
{ DEVICE_TYPE_NETWORK, "sl", "Serial-line IP (SLIP) interface" },
|
||||
{ DEVICE_TYPE_NETWORK, "ppp", "Point-to-Point Protocol (PPP) interface" },
|
||||
{ DEVICE_TYPE_NETWORK, "de", "DEC DE435 PCI NIC or other DC21040-AA based card" },
|
||||
{ DEVICE_TYPE_NETWORK, "fxp", "Intel EtherExpress Pro/100B PCI Fast Ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "ed", "WD/SMC 80xx; Novell NE1000/2000; 3Com 3C503 cards" },
|
||||
{ DEVICE_TYPE_NETWORK, "ed", "WD/SMC 80xx; Novell NE1000/2000; 3Com 3C503 card" },
|
||||
{ DEVICE_TYPE_NETWORK, "ep", "3Com 3C509 ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "el", "3Com 3C501 ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "ex", "Intel EtherExpress Pro/10 ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "fe", "Fujitsu MB86960A/MB86965A ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "ie", "AT&T StarLAN 10 and EN100; 3Com 3C507; NI5210" },
|
||||
{ DEVICE_TYPE_NETWORK, "ix", "Intel Etherexpress ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "le", "DEC EtherWorks 2 or 3 ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "lnc", "Lance/PCnet (Isolan/Novell NE2100/NE32-VL) ethernet" },
|
||||
{ DEVICE_TYPE_NETWORK, "vx", "3COM 3c590 / 3c595 / 3c9xx ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "ze", "IBM/National Semiconductor PCMCIA ethernet card" },
|
||||
{ DEVICE_TYPE_NETWORK, "zp", "3Com Etherlink III PCMCIA ethernet card" },
|
||||
{ NULL },
|
||||
@@ -101,7 +101,7 @@ new_device(char *name)
|
||||
dev = safe_malloc(sizeof(Device));
|
||||
bzero(dev, sizeof(Device));
|
||||
if (name)
|
||||
strcpy(dev->name, name);
|
||||
SAFE_STRCPY(dev->name, name);
|
||||
return dev;
|
||||
}
|
||||
|
||||
@@ -112,18 +112,10 @@ dummyInit(Device *dev)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
FILE *
|
||||
dummyGet(Device *dev, char *dist, Boolean probe)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
Boolean
|
||||
dummyClose(Device *dev, int fd)
|
||||
{
|
||||
if (!close(fd))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -138,21 +130,21 @@ deviceTry(char *name, char *try)
|
||||
int fd;
|
||||
|
||||
snprintf(try, FILENAME_MAX, "/dev/%s", name);
|
||||
fd = open(try, O_RDWR);
|
||||
fd = open(try, O_RDONLY);
|
||||
if (fd > 0)
|
||||
return fd;
|
||||
if (errno == EBUSY)
|
||||
return -1;
|
||||
snprintf(try, FILENAME_MAX, "/mnt/dev/%s", name);
|
||||
fd = open(try, O_RDWR);
|
||||
fd = open(try, O_RDONLY);
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* Register a new device in the devices array */
|
||||
Device *
|
||||
deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled,
|
||||
Boolean (*init)(Device *), int (*get)(Device *, char *, Boolean),
|
||||
Boolean (*close)(Device *, int), void (*shutdown)(Device *), void *private)
|
||||
Boolean (*init)(Device *), FILE * (*get)(Device *, char *, Boolean),
|
||||
void (*shutdown)(Device *), void *private)
|
||||
{
|
||||
Device *newdev = NULL;
|
||||
|
||||
@@ -166,7 +158,6 @@ deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean e
|
||||
newdev->enabled = enabled;
|
||||
newdev->init = init ? init : dummyInit;
|
||||
newdev->get = get ? get : dummyGet;
|
||||
newdev->close = close ? close : dummyClose;
|
||||
newdev->shutdown = shutdown ? shutdown : dummyShutdown;
|
||||
newdev->private = private;
|
||||
Devices[numDevs] = newdev;
|
||||
@@ -198,8 +189,8 @@ deviceGetAll(void)
|
||||
if (!d)
|
||||
msgFatal("Unable to open disk %s", names[i]);
|
||||
|
||||
(void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, NULL, NULL, NULL, NULL, d);
|
||||
msgDebug("Found a device of type disk named: %s\n", names[i]);
|
||||
(void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, NULL, NULL, NULL, d);
|
||||
msgDebug("Found a disk device named %s\n", names[i]);
|
||||
|
||||
/* Look for existing DOS partitions to register */
|
||||
for (c1 = d->chunks->part; c1; c1 = c1->next) {
|
||||
@@ -210,7 +201,7 @@ deviceGetAll(void)
|
||||
/* Got one! */
|
||||
sprintf(devname, "/dev/%s", c1->name);
|
||||
dev = deviceRegister(c1->name, c1->name, strdup(devname), DEVICE_TYPE_DOS, TRUE,
|
||||
mediaInitDOS, mediaGetDOS, NULL, mediaShutdownDOS, NULL);
|
||||
mediaInitDOS, mediaGetDOS, mediaShutdownDOS, NULL);
|
||||
dev->private = c1;
|
||||
msgDebug("Found a DOS partition %s on drive %s\n", c1->name, d->name);
|
||||
}
|
||||
@@ -226,11 +217,11 @@ deviceGetAll(void)
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
msgConfirm("ifconfig: socket");
|
||||
return;
|
||||
goto skipif; /* Jump over network iface probing */
|
||||
}
|
||||
if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
|
||||
msgConfirm("ifconfig (SIOCGIFCONF)");
|
||||
return;
|
||||
goto skipif; /* Jump over network iface probing */
|
||||
}
|
||||
ifflags = ifc.ifc_req->ifr_flags;
|
||||
end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
|
||||
@@ -240,12 +231,21 @@ deviceGetAll(void)
|
||||
/* If it's not a link entry, forget it */
|
||||
if (ifptr->ifr_ifru.ifru_addr.sa_family != AF_LINK)
|
||||
continue;
|
||||
|
||||
/* Eliminate network devices that don't make sense */
|
||||
if (!strncmp(ifptr->ifr_name, "tun", 3)
|
||||
|| !strncmp(ifptr->ifr_name, "lo0", 3))
|
||||
if (!strncmp(ifptr->ifr_name, "lo0", 3))
|
||||
continue;
|
||||
descr = NULL;
|
||||
for (i = 0; device_names[i].name; i++) {
|
||||
|
||||
/* If we have a slip device, don't register it */
|
||||
if (!strncmp(ifptr->ifr_name, "sl", 2)) {
|
||||
continue;
|
||||
}
|
||||
/* And the same for ppp */
|
||||
if (!strncmp(ifptr->ifr_name, "tun", 3) || !strncmp(ifptr->ifr_name, "ppp", 3)) {
|
||||
continue;
|
||||
}
|
||||
/* Try and find its description */
|
||||
for (i = 0, descr = NULL; device_names[i].name; i++) {
|
||||
int len = strlen(device_names[i].name);
|
||||
|
||||
if (!strncmp(ifptr->ifr_name, device_names[i].name, len)) {
|
||||
@@ -255,9 +255,10 @@ deviceGetAll(void)
|
||||
}
|
||||
if (!descr)
|
||||
descr = "<unknown network interface type>";
|
||||
|
||||
deviceRegister(ifptr->ifr_name, descr, strdup(ifptr->ifr_name), DEVICE_TYPE_NETWORK, TRUE,
|
||||
mediaInitNetwork, NULL, NULL, mediaShutdownNetwork, NULL);
|
||||
msgDebug("Found a device of type network named: %s\n", ifptr->ifr_name);
|
||||
mediaInitNetwork, NULL, mediaShutdownNetwork, NULL);
|
||||
msgDebug("Found a network device named %s\n", ifptr->ifr_name);
|
||||
close(s);
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
msgConfirm("ifconfig: socket");
|
||||
@@ -267,6 +268,7 @@ deviceGetAll(void)
|
||||
ifptr = (struct ifreq *)((caddr_t)ifptr + ifptr->ifr_addr.sa_len - sizeof(struct sockaddr));
|
||||
}
|
||||
|
||||
skipif:
|
||||
/* Finally, try to find all the types of devices one might need
|
||||
* during the second stage of the installation.
|
||||
*/
|
||||
@@ -280,30 +282,30 @@ deviceGetAll(void)
|
||||
if (fd >= 0 || errno == EBUSY) { /* EBUSY if already mounted */
|
||||
if (fd >= 0) close(fd);
|
||||
(void)deviceRegister(device_names[i].name, device_names[i].description, strdup(try),
|
||||
DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM, NULL,
|
||||
DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM,
|
||||
mediaShutdownCDROM, NULL);
|
||||
msgDebug("Found a device of type CDROM named: %s\n", device_names[i].name);
|
||||
msgDebug("Found a CDROM device named %s\n", device_names[i].name);
|
||||
}
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_TAPE:
|
||||
fd = deviceTry(device_names[i].name, try);
|
||||
if (fd >= 0) {
|
||||
if (fd) close(fd);
|
||||
close(fd);
|
||||
deviceRegister(device_names[i].name, device_names[i].description, strdup(try),
|
||||
DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, NULL, mediaShutdownTape, NULL);
|
||||
msgDebug("Found a device of type TAPE named: %s\n", device_names[i].name);
|
||||
DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, mediaShutdownTape, NULL);
|
||||
msgDebug("Found a TAPE device named %s\n", device_names[i].name);
|
||||
}
|
||||
break;
|
||||
|
||||
case DEVICE_TYPE_FLOPPY:
|
||||
fd = deviceTry(device_names[i].name, try);
|
||||
if (fd >= 0) {
|
||||
if (fd) close(fd);
|
||||
close(fd);
|
||||
deviceRegister(device_names[i].name, device_names[i].description, strdup(try),
|
||||
DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy, NULL,
|
||||
DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy,
|
||||
mediaShutdownFloppy, NULL);
|
||||
msgDebug("Found a device of type floppy named: %s\n", device_names[i].name);
|
||||
msgDebug("Found a floppy device named %s\n", device_names[i].name);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -313,20 +315,19 @@ deviceGetAll(void)
|
||||
if (fd >= 0) {
|
||||
char *newdesc, *cp;
|
||||
|
||||
if (fd)
|
||||
close(fd);
|
||||
|
||||
/* Serial devices get a slip and ppp device each */
|
||||
close(fd);
|
||||
cp = device_names[i].description;
|
||||
/* Serial devices get a slip and ppp device each, if supported */
|
||||
newdesc = safe_malloc(strlen(cp) + 40);
|
||||
sprintf(newdesc, cp, "SLIP interface");
|
||||
deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
|
||||
NULL, NULL, mediaShutdownNetwork, NULL);
|
||||
NULL, mediaShutdownNetwork, NULL);
|
||||
msgDebug("Add mapping for %s on %s to sl0\n", device_names[i].name, try);
|
||||
newdesc = safe_malloc(strlen(cp) + 50);
|
||||
sprintf(newdesc, cp, "PPP interface");
|
||||
deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
|
||||
NULL, NULL, mediaShutdownNetwork, NULL);
|
||||
msgDebug("Found a device of type network named: %s\n", device_names[i].name);
|
||||
NULL, mediaShutdownNetwork, NULL);
|
||||
msgDebug("Add mapping for %s on %s to ppp0\n", device_names[i].name, try);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -347,7 +348,8 @@ deviceFind(char *name, DeviceType class)
|
||||
static Device *found[DEV_MAX];
|
||||
int i, j;
|
||||
|
||||
for (i = 0, j = 0; i < numDevs; i++) {
|
||||
j = 0;
|
||||
for (i = 0; i < numDevs; i++) {
|
||||
if ((!name || !strcmp(Devices[i]->name, name))
|
||||
&& (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
|
||||
found[j++] = Devices[i];
|
||||
@@ -356,6 +358,23 @@ deviceFind(char *name, DeviceType class)
|
||||
return j ? found : NULL;
|
||||
}
|
||||
|
||||
Device **
|
||||
deviceFindDescr(char *name, char *desc, DeviceType class)
|
||||
{
|
||||
static Device *found[DEV_MAX];
|
||||
int i, j;
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < numDevs; i++) {
|
||||
if ((!name || !strcmp(Devices[i]->name, name)) &&
|
||||
(!desc || !strcmp(Devices[i]->description, desc)) &&
|
||||
(class == DEVICE_TYPE_ANY || class == Devices[i]->type))
|
||||
found[j++] = Devices[i];
|
||||
}
|
||||
found[j] = NULL;
|
||||
return j ? found : NULL;
|
||||
}
|
||||
|
||||
int
|
||||
deviceCount(Device **devs)
|
||||
{
|
||||
|
||||
+44
-43
@@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: disks.c,v 1.31.2.51 1996/11/07 09:16:44 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -77,20 +77,15 @@ print_chunks(Disk *d)
|
||||
|
||||
for (i = Total = 0; chunk_info[i]; i++)
|
||||
Total += chunk_info[i]->size;
|
||||
if (d->bios_hd <= 1 && d->bios_sect <= 1) {
|
||||
All_FreeBSD(d, TRUE);
|
||||
d->bios_hd = d->bios_sect = d->bios_cyl = 1;
|
||||
}
|
||||
else if (d->bios_cyl > 65536 || d->bios_hd > 256 || d->bios_sect >= 64) {
|
||||
if (d->bios_cyl > 65536 || d->bios_hd > 256 || d->bios_sect >= 64) {
|
||||
dialog_clear_norefresh();
|
||||
msgConfirm("WARNING: A geometry of %d/%d/%d for %s is incorrect. Using\n"
|
||||
"a default geometry of 64 heads and 32 sectors. If this geometry\n"
|
||||
"is incorrect or you are unsure as to whether or not it's correct,\n"
|
||||
"please consult the Hardware Guide in the Documentation submenu\n"
|
||||
"or use the (G)eometry command to change it now.", d->bios_cyl, d->bios_hd, d->bios_sect, d->name);
|
||||
d->bios_hd = 64;
|
||||
d->bios_sect = 32;
|
||||
d->bios_cyl = Total / ONE_MEG;
|
||||
"a more likely geometry. If this geometry is incorrect or you\n"
|
||||
"are unsure as to whether or not it's correct, please consult\n"
|
||||
"the Hardware Guide in the Documentation submenu or use the\n"
|
||||
" (G)eometry command to change it now.",
|
||||
d->bios_cyl, d->bios_hd, d->bios_sect, d->name);
|
||||
Sanitize_Bios_Geom(d);
|
||||
}
|
||||
attrset(A_NORMAL);
|
||||
mvaddstr(0, 0, "Disk name:\t");
|
||||
@@ -98,8 +93,9 @@ print_chunks(Disk *d)
|
||||
attrset(A_REVERSE); addstr(d->name); attrset(A_NORMAL);
|
||||
attrset(A_REVERSE); mvaddstr(0, 55, "FDISK Partition Editor"); attrset(A_NORMAL);
|
||||
mvprintw(1, 0,
|
||||
"DISK Geometry:\t%lu cyls/%lu heads/%lu sectors",
|
||||
d->bios_cyl, d->bios_hd, d->bios_sect);
|
||||
"DISK Geometry:\t%lu cyls/%lu heads/%lu sectors = %lu sectors",
|
||||
d->bios_cyl, d->bios_hd, d->bios_sect,
|
||||
d->bios_cyl * d->bios_hd * d->bios_sect);
|
||||
mvprintw(3, 1, "%10s %10s %10s %8s %8s %8s %8s %8s",
|
||||
"Offset", "Size", "End", "Name", "PType", "Desc",
|
||||
"Subtype", "Flags");
|
||||
@@ -109,7 +105,8 @@ print_chunks(Disk *d)
|
||||
mvprintw(row, 2, "%10ld %10lu %10lu %8s %8d %8s %8d\t%-6s",
|
||||
chunk_info[i]->offset, chunk_info[i]->size,
|
||||
chunk_info[i]->end, chunk_info[i]->name,
|
||||
chunk_info[i]->type, chunk_n[chunk_info[i]->type],
|
||||
chunk_info[i]->type,
|
||||
slice_type_name(chunk_info[i]->type, chunk_info[i]->subtype),
|
||||
chunk_info[i]->subtype, ShowChunkFlags(chunk_info[i]));
|
||||
if (i == current_chunk)
|
||||
attrset(A_NORMAL);
|
||||
@@ -120,11 +117,11 @@ static void
|
||||
print_command_summary()
|
||||
{
|
||||
mvprintw(14, 0, "The following commands are supported (in upper or lower case):");
|
||||
mvprintw(16, 0, "A = Use Entire Disk B = Bad Block Scan C = Create Partition");
|
||||
mvprintw(17, 0, "D = Delete Partition G = Set Drive Geometry S = Set Bootable");
|
||||
mvprintw(16, 0, "A = Use Entire Disk B = Bad Block Scan C = Create Slice");
|
||||
mvprintw(17, 0, "D = Delete Slice G = Set Drive Geometry S = Set Bootable");
|
||||
mvprintw(18, 0, "U = Undo All Changes Q = Finish");
|
||||
if (!RunningAsInit)
|
||||
mvprintw(18, 46, "W = Write Changes");
|
||||
mvprintw(18, 48, "W = Write Changes");
|
||||
mvprintw(21, 0, "Use F1 or ? to get more help, arrow keys to select.");
|
||||
move(0, 0);
|
||||
}
|
||||
@@ -193,7 +190,8 @@ diskPartition(Device *dev, Disk *d)
|
||||
char *val, geometry[80];
|
||||
|
||||
/* Now print our overall state */
|
||||
print_chunks(d);
|
||||
if (d)
|
||||
print_chunks(d);
|
||||
print_command_summary();
|
||||
if (msg) {
|
||||
attrset(title_attr); mvprintw(23, 0, msg); attrset(A_NORMAL);
|
||||
@@ -213,12 +211,14 @@ diskPartition(Device *dev, Disk *d)
|
||||
msg = NULL;
|
||||
break;
|
||||
|
||||
case '\020': /* ^P */
|
||||
case KEY_UP:
|
||||
case '-':
|
||||
if (current_chunk != 0)
|
||||
--current_chunk;
|
||||
break;
|
||||
|
||||
case '\016': /* ^N */
|
||||
case KEY_DOWN:
|
||||
case '+':
|
||||
case '\r':
|
||||
@@ -263,8 +263,6 @@ diskPartition(Device *dev, Disk *d)
|
||||
if (rv == -1)
|
||||
rv = 0;
|
||||
All_FreeBSD(d, rv);
|
||||
if (rv)
|
||||
d->bios_hd = d->bios_sect = d->bios_cyl = 1;
|
||||
variable_set2(DISK_PARTITIONED, "yes");
|
||||
record_chunks(d);
|
||||
clear();
|
||||
@@ -272,7 +270,7 @@ diskPartition(Device *dev, Disk *d)
|
||||
|
||||
case 'B':
|
||||
if (chunk_info[current_chunk]->type != freebsd)
|
||||
msg = "Can only scan for bad blocks in FreeBSD partition.";
|
||||
msg = "Can only scan for bad blocks in FreeBSD slice.";
|
||||
else if (strncmp(d->name, "sd", 2) ||
|
||||
!msgYesNo("This typically makes sense only for ESDI, IDE or MFM drives.\n"
|
||||
"Are you sure you want to do this on a SCSI disk?")) {
|
||||
@@ -286,14 +284,14 @@ diskPartition(Device *dev, Disk *d)
|
||||
|
||||
case 'C':
|
||||
if (chunk_info[current_chunk]->type != unused)
|
||||
msg = "Partition in use, delete it first or move to an unused one.";
|
||||
msg = "Slice in use, delete it first or move to an unused one.";
|
||||
else {
|
||||
char *val, tmp[20], *cp;
|
||||
int size, subtype;
|
||||
chunk_e partitiontype;
|
||||
|
||||
snprintf(tmp, 20, "%d", chunk_info[current_chunk]->size);
|
||||
val = msgGetInput(tmp, "Please specify the size for new FreeBSD partition in blocks\n"
|
||||
val = msgGetInput(tmp, "Please specify the size for new FreeBSD slice in blocks\n"
|
||||
"or append a trailing `M' for megabytes (e.g. 20M).");
|
||||
if (val && (size = strtol(val, &cp, 0)) > 0) {
|
||||
if (*cp && toupper(*cp) == 'M')
|
||||
@@ -301,7 +299,7 @@ diskPartition(Device *dev, Disk *d)
|
||||
strcpy(tmp, "165");
|
||||
val = msgGetInput(tmp, "Enter type of partition to create:\n\n"
|
||||
"Pressing Enter will choose the default, a native FreeBSD\n"
|
||||
"partition (type 165). You can choose other types, 6 for a\n"
|
||||
"slice (type 165). You can choose other types, 6 for a\n"
|
||||
"DOS partition or 131 for a Linux partition, for example.\n\n"
|
||||
"Note: If you choose a non-FreeBSD partition type, it will not\n"
|
||||
"be formatted or otherwise prepared, it will simply reserve space\n"
|
||||
@@ -327,7 +325,7 @@ diskPartition(Device *dev, Disk *d)
|
||||
case KEY_DC:
|
||||
case 'D':
|
||||
if (chunk_info[current_chunk]->type == unused)
|
||||
msg = "Partition is already unused!";
|
||||
msg = "Slice is already unused!";
|
||||
else {
|
||||
Delete_Chunk(d, chunk_info[current_chunk]);
|
||||
variable_set2(DISK_PARTITIONED, "yes");
|
||||
@@ -341,9 +339,11 @@ diskPartition(Device *dev, Disk *d)
|
||||
"Don't forget to use the two slash (/) separator characters!\n"
|
||||
"It's not possible to parse the field without them.");
|
||||
if (val) {
|
||||
d->bios_cyl = strtol(val, &val, 0);
|
||||
d->bios_hd = strtol(val + 1, &val, 0);
|
||||
d->bios_sect = strtol(val + 1, 0, 0);
|
||||
long nc, nh, ns;
|
||||
nc = strtol(val, &val, 0);
|
||||
nh = strtol(val + 1, &val, 0);
|
||||
ns = strtol(val + 1, 0, 0);
|
||||
Set_Bios_Geom(d, nc, nh, ns);
|
||||
}
|
||||
clear();
|
||||
break;
|
||||
@@ -359,17 +359,18 @@ diskPartition(Device *dev, Disk *d)
|
||||
"can't undo it.");
|
||||
}
|
||||
else if (!msgYesNo("Are you SURE you want to Undo everything?")) {
|
||||
d = Open_Disk(d->name);
|
||||
if (!d) {
|
||||
msgConfirm("Can't reopen disk %s! Internal state is probably corrupted", d->name);
|
||||
clear();
|
||||
break;
|
||||
}
|
||||
char cp[BUFSIZ];
|
||||
|
||||
sstrncpy(cp, d->name, sizeof cp);
|
||||
Free_Disk(dev->private);
|
||||
d = Open_Disk(cp);
|
||||
if (!d)
|
||||
msgConfirm("Can't reopen disk %s! Internal state is probably corrupted", cp);
|
||||
dev->private = d;
|
||||
variable_unset(DISK_PARTITIONED);
|
||||
variable_unset(DISK_LABELLED);
|
||||
record_chunks(d);
|
||||
if (d)
|
||||
record_chunks(d);
|
||||
}
|
||||
clear();
|
||||
break;
|
||||
@@ -391,8 +392,7 @@ diskPartition(Device *dev, Disk *d)
|
||||
* disk (i.e., the disklabel starts at sector 0), even in cases where the user has requested
|
||||
* booteasy or a "standard" MBR -- both would be fatal in this case.
|
||||
*/
|
||||
if ((d->chunks->part->flags & CHUNK_FORCE_ALL) != CHUNK_FORCE_ALL
|
||||
&& (mbrContents = getBootMgr(d->name)) != NULL)
|
||||
if (!(d->chunks->part->flags & CHUNK_FORCE_ALL) && (mbrContents = getBootMgr(d->name)) != NULL)
|
||||
Set_Boot_Mgr(d, mbrContents);
|
||||
|
||||
if (DITEM_STATUS(diskPartitionWrite(NULL)) != DITEM_SUCCESS)
|
||||
@@ -417,6 +417,7 @@ diskPartition(Device *dev, Disk *d)
|
||||
clear();
|
||||
break;
|
||||
|
||||
case '\033': /* ESC */
|
||||
case 'Q':
|
||||
chunking = FALSE;
|
||||
/* Don't trash the MBR if the first (and therefore only) chunk is marked for a truly dedicated
|
||||
@@ -439,9 +440,9 @@ diskPartition(Device *dev, Disk *d)
|
||||
char buf[FILENAME_MAX];
|
||||
|
||||
dialog_clear_norefresh();
|
||||
use_helpline("Press F1 to read more about disk partitioning.");
|
||||
use_helpline("Press F1 to read more about disk slices.");
|
||||
use_helpfile(systemHelpFile("partition", buf));
|
||||
dialog_mesgbox("Disk partitioning warning:", p, -1, -1);
|
||||
dialog_mesgbox("Disk slicing warning:", p, -1, -1);
|
||||
free(p);
|
||||
}
|
||||
restorescr(w);
|
||||
@@ -514,7 +515,7 @@ diskPartitionEditor(dialogMenuItem *self)
|
||||
i = dmenuOpenSimple(menu, FALSE) ? DITEM_SUCCESS : DITEM_FAILURE;
|
||||
free(menu);
|
||||
}
|
||||
i = i | DITEM_RECREATE;
|
||||
i = i | DITEM_RESTORE;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
@@ -559,7 +560,7 @@ diskPartitionWrite(dialogMenuItem *self)
|
||||
if (c1->flags & CHUNK_BAD144) {
|
||||
int ret;
|
||||
|
||||
msgNotify("Running bad block scan on partition %s", c1->name);
|
||||
msgNotify("Running bad block scan on slice %s", c1->name);
|
||||
if (!Fake) {
|
||||
ret = vsystem("bad144 -v /dev/r%s 1234", c1->name);
|
||||
if (ret)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: dispatch.c,v 1.6 1996/11/04 12:56:20 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -37,6 +37,8 @@
|
||||
#include "sysinstall.h"
|
||||
#include <ctype.h>
|
||||
|
||||
static int _shutdown(dialogMenuItem *unused);
|
||||
|
||||
static struct _word {
|
||||
char *name;
|
||||
int (*handler)(dialogMenuItem *self);
|
||||
@@ -83,6 +85,9 @@ static struct _word {
|
||||
{ "mediaSetCPIOVerbosity", mediaSetCPIOVerbosity },
|
||||
{ "mediaGetType", mediaGetType },
|
||||
{ "optionsEditor", optionsEditor },
|
||||
{ "addGroup", userAddGroup },
|
||||
{ "addUser", userAddUser },
|
||||
{ "shutdown", _shutdown },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
@@ -102,6 +107,13 @@ call_possible_resword(char *name, dialogMenuItem *value, int *status)
|
||||
return rval;
|
||||
}
|
||||
|
||||
/* Just convenience */
|
||||
static int _shutdown(dialogMenuItem *unused)
|
||||
{
|
||||
systemShutdown(0);
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
|
||||
/* For a given string, call it or spit out an undefined command diagnostic */
|
||||
int
|
||||
dispatchCommand(char *str)
|
||||
@@ -113,16 +125,22 @@ dispatchCommand(char *str)
|
||||
msgConfirm("Null or zero-length string passed to dispatchCommand");
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
/* If it's got a newline, trim it */
|
||||
if ((cp = index(str, '\n')) != NULL)
|
||||
*cp = '\0';
|
||||
|
||||
/* A command might be a pathname if it's encoded in argv[0], as we also support */
|
||||
if (index(str, '=')) {
|
||||
variable_set(str);
|
||||
return DITEM_SUCCESS;
|
||||
i = DITEM_SUCCESS;
|
||||
}
|
||||
else if ((cp = index(str, '/')) != NULL)
|
||||
str = cp + 1;
|
||||
if (!call_possible_resword(str, NULL, &i)) {
|
||||
msgConfirm("No such command: %s", str);
|
||||
return DITEM_FAILURE;
|
||||
else {
|
||||
if ((cp = index(str, '/')) != NULL)
|
||||
str = cp + 1;
|
||||
if (!call_possible_resword(str, NULL, &i)) {
|
||||
msgConfirm("No such command: %s", str);
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
+124
-55
@@ -4,7 +4,7 @@
|
||||
* This is probably the last program in the `sysinstall' line - the next
|
||||
* generation being essentially a complete rewrite.
|
||||
*
|
||||
* $Id: dist.c,v 1.36.2.42 1996/11/07 09:16:51 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -34,8 +34,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include "sysinstall.h"
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
|
||||
unsigned int Dists;
|
||||
unsigned int DESDists;
|
||||
@@ -65,6 +66,7 @@ static Distribution DistTable[] = {
|
||||
{ "doc", "/", &Dists, DIST_DOC, NULL },
|
||||
{ "games", "/", &Dists, DIST_GAMES, NULL },
|
||||
{ "manpages", "/", &Dists, DIST_MANPAGES, NULL },
|
||||
{ "catpages", "/", &Dists, DIST_CATPAGES, NULL },
|
||||
{ "proflibs", "/", &Dists, DIST_PROFLIBS, NULL },
|
||||
{ "dict", "/", &Dists, DIST_DICT, NULL },
|
||||
{ "info", "/", &Dists, DIST_INFO, NULL },
|
||||
@@ -73,8 +75,6 @@ static Distribution DistTable[] = {
|
||||
{ "compat1x", "/", &Dists, DIST_COMPAT1X, NULL },
|
||||
{ "compat20", "/", &Dists, DIST_COMPAT20, NULL },
|
||||
{ "compat21", "/", &Dists, DIST_COMPAT21, NULL },
|
||||
{ "commerce", "/usr/local", &Dists, DIST_COMMERCIAL, NULL },
|
||||
{ "xperimnt", "/usr/local", &Dists, DIST_EXPERIMENTAL, NULL },
|
||||
{ "XF8632", "/usr", &Dists, DIST_XF86, XF86DistTable },
|
||||
{ NULL },
|
||||
};
|
||||
@@ -270,7 +270,7 @@ distSetDES(dialogMenuItem *self)
|
||||
}
|
||||
else
|
||||
i = DITEM_FAILURE;
|
||||
return i | DITEM_RECREATE | DITEM_RESTORE;
|
||||
return i | DITEM_RECREATE;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -301,7 +301,7 @@ distMaybeSetDES(dialogMenuItem *self)
|
||||
else
|
||||
i = DITEM_FAILURE;
|
||||
}
|
||||
return i | DITEM_RECREATE | DITEM_RESTORE;
|
||||
return i | DITEM_RECREATE;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -317,7 +317,7 @@ distSetSrc(dialogMenuItem *self)
|
||||
}
|
||||
else
|
||||
i = DITEM_FAILURE;
|
||||
return i | DITEM_RECREATE | DITEM_RESTORE;
|
||||
return i | DITEM_RECREATE;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -337,25 +337,53 @@ distSetXF86(dialogMenuItem *self)
|
||||
}
|
||||
else
|
||||
i = DITEM_FAILURE;
|
||||
return i | DITEM_RECREATE | DITEM_RESTORE;
|
||||
return i | DITEM_RECREATE;
|
||||
}
|
||||
|
||||
static Boolean got_intr = FALSE;
|
||||
|
||||
/* timeout handler */
|
||||
static void
|
||||
handle_intr(int sig)
|
||||
{
|
||||
msgDebug("User generated interrupt.\n");
|
||||
got_intr = TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
check_for_interrupt(void)
|
||||
{
|
||||
if (got_intr) {
|
||||
got_intr = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static Boolean
|
||||
distExtract(char *parent, Distribution *me)
|
||||
{
|
||||
int i, status, total;
|
||||
int cpid, zpid, fd, fd2, chunk, numchunks;
|
||||
int i, status, total, intr;
|
||||
int cpid, zpid, fd2, chunk, numchunks;
|
||||
char *path, *dist, buf[BUFSIZ];
|
||||
const char *tmp;
|
||||
FILE *fp;
|
||||
Attribs *dist_attr;
|
||||
WINDOW *w = savescr();
|
||||
struct timeval start, stop;
|
||||
struct sigaction old, new;
|
||||
|
||||
status = TRUE;
|
||||
dialog_clear_norefresh();
|
||||
if (isDebug())
|
||||
msgDebug("distExtract: parent: %s, me: %s\n", parent ? parent : "(none)", me->my_name);
|
||||
|
||||
/* Make ^C fake a sudden timeout */
|
||||
new.sa_handler = handle_intr;
|
||||
new.sa_flags = 0;
|
||||
new.sa_mask = 0;
|
||||
sigaction(SIGINT, &new, &old);
|
||||
|
||||
/* Loop through to see if we're in our parent's plans */
|
||||
for (i = 0; me[i].my_name; i++) {
|
||||
dist = me[i].my_name;
|
||||
@@ -384,53 +412,79 @@ distExtract(char *parent, Distribution *me)
|
||||
*/
|
||||
dist_attr = NULL;
|
||||
numchunks = 0;
|
||||
|
||||
snprintf(buf, sizeof buf, "%s/%s.inf", path, dist);
|
||||
fd = mediaDevice->get(mediaDevice, buf, TRUE);
|
||||
if (fd >= 0) {
|
||||
|
||||
getinfo:
|
||||
fp = mediaDevice->get(mediaDevice, buf, TRUE);
|
||||
intr = check_for_interrupt();
|
||||
if (fp > 0) {
|
||||
int status;
|
||||
|
||||
if (isDebug())
|
||||
msgDebug("Parsing attributes file for distribution %s\n", dist);
|
||||
dist_attr = safe_malloc(sizeof(Attribs) * MAX_ATTRIBS);
|
||||
if (DITEM_STATUS(attr_parse(dist_attr, fd)) == DITEM_FAILURE)
|
||||
msgConfirm("Cannot parse information file for the %s distribution!\n"
|
||||
"Please verify that your media is valid and try again.", dist);
|
||||
dist_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS);
|
||||
|
||||
status = attr_parse(dist_attr, fp);
|
||||
intr = check_for_interrupt();
|
||||
if (intr || DITEM_STATUS(status) == DITEM_FAILURE)
|
||||
msgConfirm("Cannot parse information file for the %s distribution: %s\n"
|
||||
"Please verify that your media is valid and try again.",
|
||||
dist, !intr ? "I/O error" : "User interrupt");
|
||||
else {
|
||||
if (isDebug())
|
||||
msgDebug("Looking for attribute `pieces'\n");
|
||||
tmp = attr_match(dist_attr, "pieces");
|
||||
if (tmp)
|
||||
numchunks = strtol(tmp, 0, 0);
|
||||
}
|
||||
safe_free(dist_attr);
|
||||
mediaDevice->close(mediaDevice, fd);
|
||||
fclose(fp);
|
||||
if (!numchunks)
|
||||
continue;
|
||||
}
|
||||
else if (fd == IO_ERROR) { /* Hard error, can't continue */
|
||||
mediaDevice->shutdown(mediaDevice);
|
||||
status = FALSE;
|
||||
goto done;
|
||||
else if (fp == (FILE *)IO_ERROR || intr) { /* Hard error, can't continue */
|
||||
if (!msgYesNo("Unable to open %s: %s.\nReinitialize media?",
|
||||
buf, !intr ? "I/O error." : "User interrupt.")) {
|
||||
mediaDevice->shutdown(mediaDevice);
|
||||
if (!mediaDevice->init(mediaDevice)) {
|
||||
status = FALSE;
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
goto getinfo;
|
||||
}
|
||||
else {
|
||||
status = FALSE;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Try to get the distribution as a single file */
|
||||
snprintf(buf, 512, "%s/%s.tgz", path, dist);
|
||||
snprintf(buf, sizeof buf, "%s/%s.tgz", path, dist);
|
||||
/*
|
||||
* Passing TRUE as 3rd parm to get routine makes this a "probing" get, for which errors
|
||||
* are not considered too significant.
|
||||
*/
|
||||
fd = mediaDevice->get(mediaDevice, buf, TRUE);
|
||||
if (fd >= 0) {
|
||||
getsingle:
|
||||
fp = mediaDevice->get(mediaDevice, buf, TRUE);
|
||||
intr = check_for_interrupt();
|
||||
if (fp > 0) {
|
||||
char *dir = root_bias(me[i].my_dir);
|
||||
|
||||
msgNotify("Extracting %s into %s directory...", dist, dir);
|
||||
status = mediaExtractDist(dir, fd);
|
||||
mediaDevice->close(mediaDevice, fd);
|
||||
status = mediaExtractDist(dir, dist, fp);
|
||||
fclose(fp);
|
||||
goto done;
|
||||
}
|
||||
else if (fd == IO_ERROR) { /* Hard error, can't continue */
|
||||
else if (fp == (FILE *)IO_ERROR || intr) { /* Hard error, can't continue */
|
||||
if (intr) /* result of an interrupt */
|
||||
msgConfirm("Unable to open %s: User interrupt", buf);
|
||||
else
|
||||
msgConfirm("Unable to open %s: I/O error", buf);
|
||||
mediaDevice->shutdown(mediaDevice);
|
||||
status = FALSE;
|
||||
goto done;
|
||||
if (!mediaDevice->init(mediaDevice)) {
|
||||
status = FALSE;
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
goto getsingle;
|
||||
}
|
||||
else
|
||||
numchunks = 0;
|
||||
@@ -446,30 +500,48 @@ distExtract(char *parent, Distribution *me)
|
||||
total = 0;
|
||||
(void)gettimeofday(&start, (struct timezone *)0);
|
||||
|
||||
/* We have one or more chunks, go pick them up */
|
||||
/* We have one or more chunks, initialize unpackers... */
|
||||
mediaExtractDistBegin(root_bias(me[i].my_dir), &fd2, &zpid, &cpid);
|
||||
|
||||
/* And go for all the chunks */
|
||||
for (chunk = 0; chunk < numchunks; chunk++) {
|
||||
int n, retval, last_msg;
|
||||
char prompt[80];
|
||||
|
||||
last_msg = 0;
|
||||
|
||||
snprintf(buf, 512, "%s/%s.%c%c", path, dist, (chunk / 26) + 'a', (chunk % 26) + 'a');
|
||||
getchunk:
|
||||
snprintf(buf, sizeof buf, "%s/%s.%c%c", path, dist, (chunk / 26) + 'a', (chunk % 26) + 'a');
|
||||
if (isDebug())
|
||||
msgDebug("trying for piece %d of %d: %s\n", chunk + 1, numchunks, buf);
|
||||
fd = mediaDevice->get(mediaDevice, buf, FALSE);
|
||||
if (fd < 0) {
|
||||
msgConfirm("failed to retreive piece file %s!\n"
|
||||
"Aborting the transfer", buf);
|
||||
goto punt;
|
||||
fp = mediaDevice->get(mediaDevice, buf, FALSE);
|
||||
intr = check_for_interrupt();
|
||||
if (fp <= (FILE *)0 || intr) {
|
||||
if (fp == (FILE *)0)
|
||||
msgConfirm("Failed to find %s on this media. Reinitializing media.", buf);
|
||||
else
|
||||
msgConfirm("failed to retreive piece file %s.\n"
|
||||
"%s: Reinitializing media.", buf, !intr ? "I/O error" : "User interrupt");
|
||||
mediaDevice->shutdown(mediaDevice);
|
||||
if (!mediaDevice->init(mediaDevice))
|
||||
goto punt;
|
||||
else
|
||||
goto getchunk;
|
||||
}
|
||||
snprintf(prompt, 80, "Extracting %s into %s directory...", dist, root_bias(me[i].my_dir));
|
||||
|
||||
snprintf(prompt, sizeof prompt, "Extracting %s into %s directory...", dist, root_bias(me[i].my_dir));
|
||||
dialog_gauge("Progress", prompt, 8, 15, 6, 50, (int)((float)(chunk + 1) / numchunks * 100));
|
||||
|
||||
while (1) {
|
||||
int seconds;
|
||||
|
||||
n = read(fd, buf, BUFSIZ);
|
||||
if (n <= 0)
|
||||
n = fread(buf, 1, BUFSIZ, fp);
|
||||
if (check_for_interrupt()) {
|
||||
msgConfirm("Media read error: User interrupt.");
|
||||
fclose(fp);
|
||||
goto punt;
|
||||
}
|
||||
else if (n <= 0)
|
||||
break;
|
||||
total += n;
|
||||
|
||||
@@ -490,13 +562,13 @@ distExtract(char *parent, Distribution *me)
|
||||
}
|
||||
retval = write(fd2, buf, n);
|
||||
if (retval != n) {
|
||||
mediaDevice->close(mediaDevice, fd);
|
||||
fclose(fp);
|
||||
dialog_clear_norefresh();
|
||||
msgConfirm("Write failure on transfer! (wrote %d bytes of %d bytes)", retval, n);
|
||||
goto punt;
|
||||
}
|
||||
}
|
||||
mediaDevice->close(mediaDevice, fd);
|
||||
fclose(fp);
|
||||
}
|
||||
close(fd2);
|
||||
status = mediaExtractDistEnd(zpid, cpid);
|
||||
@@ -523,13 +595,17 @@ distExtract(char *parent, Distribution *me)
|
||||
status = msgYesNo("Unable to transfer the %s distribution from\n%s.\n\n"
|
||||
"Do you want to try to retrieve it again?",
|
||||
me[i].my_name, mediaDevice->name);
|
||||
dialog_clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Extract was successful, remove ourselves from further consideration */
|
||||
if (status)
|
||||
*(me[i].my_mask) &= ~(me[i].my_bit);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
sigaction(SIGINT, &old, NULL); /* Restore signal handler */
|
||||
restorescr(w);
|
||||
return status;
|
||||
}
|
||||
@@ -568,16 +644,10 @@ distExtractAll(dialogMenuItem *self)
|
||||
int retries = 0;
|
||||
char buf[512];
|
||||
|
||||
/* First try to initialize the state of things */
|
||||
if (!Dists) {
|
||||
msgConfirm("You haven't selected any distributions to extract.");
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
if (!mediaVerify())
|
||||
/* paranoia */
|
||||
if (!Dists || !mediaVerify() || !mediaDevice->init(mediaDevice))
|
||||
return DITEM_FAILURE;
|
||||
|
||||
if (!mediaDevice->init(mediaDevice))
|
||||
return DITEM_FAILURE;
|
||||
dialog_clear_norefresh();
|
||||
msgNotify("Attempting to install all selected distributions..");
|
||||
/* Try for 3 times around the loop, then give up. */
|
||||
@@ -593,8 +663,7 @@ distExtractAll(dialogMenuItem *self)
|
||||
msgConfirm("Couldn't extract the following distributions. This may\n"
|
||||
"be because they were not available on the installation\n"
|
||||
"media you've chosen:\n\n\t%s", buf);
|
||||
return DITEM_FAILURE | DITEM_RESTORE;
|
||||
return DITEM_SUCCESS | DITEM_RESTORE;
|
||||
}
|
||||
return DITEM_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
#define DIST_COMPAT20 0x0200
|
||||
#define DIST_COMPAT21 0x0400
|
||||
#define DIST_XF86 0x0800
|
||||
#define DIST_COMMERCIAL 0x1000
|
||||
#define DIST_DES 0x2000
|
||||
#define DIST_EXPERIMENTAL 0x4000
|
||||
#define DIST_ALL 0xFFFF
|
||||
#define DIST_DES 0x1000
|
||||
#define DIST_CATPAGES 0x2000
|
||||
#define DIST_ALL 0x3FFF
|
||||
|
||||
/* Canned distribution sets */
|
||||
#define _DIST_DEVELOPER \
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated for what's essentially a complete rewrite.
|
||||
*
|
||||
* $Id: dmenu.c,v 1.12.2.17 1996/11/07 09:16:57 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -36,7 +36,6 @@
|
||||
|
||||
#include "sysinstall.h"
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAX_MENU 15
|
||||
|
||||
@@ -53,7 +52,7 @@ int
|
||||
dmenuSubmenu(dialogMenuItem *tmp)
|
||||
{
|
||||
return (dmenuOpenSimple((DMenu *)(tmp->data), FALSE) ? DITEM_SUCCESS : DITEM_FAILURE) |
|
||||
DITEM_RECREATE;
|
||||
DITEM_RESTORE;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -182,7 +181,7 @@ dmenuVarCheck(dialogMenuItem *item)
|
||||
w = (char *)item->data;
|
||||
if (!w)
|
||||
return FALSE;
|
||||
strncpy(tmp, w, 256);
|
||||
SAFE_STRCPY(tmp, w);
|
||||
if ((cp = index(tmp, '=')) != NULL) {
|
||||
*(cp++) = '\0';
|
||||
if ((cp3 = index(cp, ',')) != NULL)
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* The new sysinstall program.
|
||||
*
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated for what's essentially a complete rewrite.
|
||||
*
|
||||
* $Id: doc.c,v 1.22 1997/02/07 04:25:53 jkh Exp $
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer,
|
||||
* verbatim and that no modifications are made prior to this
|
||||
* point in the file.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sysinstall.h"
|
||||
|
||||
/*
|
||||
* This is called from the main menu. Try to find a copy of Lynx from somewhere
|
||||
* and fire it up on the first copy of the handbook we can find.
|
||||
*/
|
||||
int
|
||||
docBrowser(dialogMenuItem *self)
|
||||
{
|
||||
int ret;
|
||||
char *browser = variable_get(VAR_BROWSER_PACKAGE);
|
||||
|
||||
if (RunningAsInit && !strstr(variable_get(SYSTEM_STATE), "install")) {
|
||||
msgConfirm("This option may only be used after the system is installed, sorry!");
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
|
||||
/* First, make sure we have whatever browser we've chosen is here */
|
||||
if (!package_exists(browser)) {
|
||||
ret = package_add(browser);
|
||||
if (DITEM_STATUS(ret) != DITEM_SUCCESS) {
|
||||
msgConfirm("Unable to install the %s HTML browser package. You may\n"
|
||||
"wish to verify that your media is configured correctly and\n"
|
||||
"try again.", browser);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file_executable(variable_get(VAR_BROWSER_BINARY))) {
|
||||
if (!msgYesNo("Hmmm. The %s package claims to have installed, but I can't\n"
|
||||
"find its binary in %s! You may wish to try a different\n"
|
||||
"location to load the package from (go to Media menu) and see if that\n"
|
||||
"makes a difference.\n\n"
|
||||
"I suggest that we remove the version that was extracted since it does\n"
|
||||
"not appear to be correct. Would you like me to do that now?",
|
||||
browser, variable_get(VAR_BROWSER_BINARY)))
|
||||
vsystem("pkg_delete %s %s", !strcmp(variable_get(VAR_CPIO_VERBOSITY), "high") ? "-v" : "", browser);
|
||||
return DITEM_FAILURE | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
/* Run browser on the appropriate doc */
|
||||
if (dmenuOpenSimple(&MenuHTMLDoc, FALSE))
|
||||
return DITEM_SUCCESS | DITEM_RESTORE;
|
||||
else
|
||||
return DITEM_FAILURE | DITEM_RESTORE;
|
||||
}
|
||||
|
||||
/* Try to show one of the documents requested from the HTML doc menu */
|
||||
int
|
||||
docShowDocument(dialogMenuItem *self)
|
||||
{
|
||||
char tmp[512], target[512];
|
||||
char *where = NULL;
|
||||
char *browser = variable_get(VAR_BROWSER_BINARY);
|
||||
char *str = self->prompt;
|
||||
|
||||
if (!file_executable(browser)) {
|
||||
msgConfirm("Can't find the browser in %s! Please ensure that it's\n"
|
||||
"properly set in the Options editor.", browser);
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
if (!strcmp(str, "Home"))
|
||||
where = "http://www.freebsd.org";
|
||||
else if (!strcmp(str, "Other"))
|
||||
where = msgGetInput("http://www.freebsd.org", "Please enter the URL of the location you wish to visit.");
|
||||
else if (!strcmp(str, "FAQ")) {
|
||||
strcpy(target, "/usr/share/doc/FAQ/FAQ.html");
|
||||
if (!file_readable(target))
|
||||
strcpy(target, "http://www.freebsd.org/FAQ");
|
||||
where = target;
|
||||
}
|
||||
else if (!strcmp(str, "Handbook")) {
|
||||
strcpy(target, "/usr/share/doc/handbook/handbook.html");
|
||||
if (!file_readable(target))
|
||||
strcpy(target, "http://www.freebsd.org/handbook");
|
||||
where = target;
|
||||
}
|
||||
if (where) {
|
||||
sprintf(tmp, "%s %s", browser, where);
|
||||
dialog_clear();
|
||||
systemExecute(tmp);
|
||||
return DITEM_SUCCESS | DITEM_RESTORE;
|
||||
}
|
||||
else {
|
||||
msgConfirm("Hmmmmm! I can't seem to access the documentation you selected!\n"
|
||||
"Have you loaded the bin distribution? Is your network connected?");
|
||||
return DITEM_FAILURE;
|
||||
}
|
||||
}
|
||||
+31
-37
@@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated to essentially a complete rewrite.
|
||||
*
|
||||
* $Id: dos.c,v 1.14 1996/08/23 07:55:58 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -44,57 +44,52 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include "dosio.h"
|
||||
|
||||
#define MSDOSFS
|
||||
#include <sys/mount.h>
|
||||
#undef MSDOSFS
|
||||
|
||||
static DOS_FS DOSFS;
|
||||
static Boolean DOSMounted;
|
||||
|
||||
Boolean
|
||||
mediaInitDOS(Device *dev)
|
||||
{
|
||||
struct msdosfs_args args;
|
||||
|
||||
if (!RunningAsInit || DOSMounted)
|
||||
return TRUE;
|
||||
|
||||
if (DITEM_STATUS(Mkdir("/dos")) != DITEM_SUCCESS)
|
||||
return FALSE;
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.fspec = dev->devname;
|
||||
args.uid = args.gid = 0;
|
||||
args.mask = 0777;
|
||||
|
||||
if (mount(MOUNT_MSDOS, "/dos", MNT_RDONLY, (caddr_t)&args) == -1) {
|
||||
msgConfirm("Error mounting %s on /dos: %s (%u)", args.fspec, strerror(errno), errno);
|
||||
if (dos_mount(&DOSFS, dev->devname)) {
|
||||
msgConfirm("Error mounting DOS partition %s : %s (%u)", dev->devname, strerror(errno), errno);
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
msgDebug("Mounted DOS device (%s) on /dos.\n", args.fspec);
|
||||
DOSMounted = TRUE;
|
||||
msgDebug("DOS partition %s mounted\n", dev->devname);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
FILE *
|
||||
mediaGetDOS(Device *dev, char *file, Boolean probe)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
char buf[PATH_MAX];
|
||||
FILE *fp;
|
||||
|
||||
if (!DOSMounted) {
|
||||
msgDebug("Can't get DOS file %s - DOSFS currently unmounted!\n", file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (isDebug())
|
||||
msgDebug("Request for %s from DOS\n", file);
|
||||
snprintf(buf, PATH_MAX, "/dos/freebsd/%s", file);
|
||||
if (file_readable(buf))
|
||||
return open(buf, O_RDONLY);
|
||||
snprintf(buf, PATH_MAX, "/dos/freebsd/dists/%s", file);
|
||||
if (file_readable(buf))
|
||||
return open(buf, O_RDONLY);
|
||||
snprintf(buf, PATH_MAX, "/dos/%s", file);
|
||||
if (file_readable(buf))
|
||||
return open(buf, O_RDONLY);
|
||||
snprintf(buf, PATH_MAX, "/dos/dists/%s", file);
|
||||
return open(buf, O_RDONLY);
|
||||
snprintf(buf, PATH_MAX, "/freebsd/%s", file);
|
||||
if ((fp = dos_open(&DOSFS, buf)))
|
||||
return fp;
|
||||
snprintf(buf, PATH_MAX, "/freebsd/dists/%s", file);
|
||||
if ((fp = dos_open(&DOSFS, buf)))
|
||||
return fp;
|
||||
snprintf(buf, PATH_MAX, "/%s", file);
|
||||
if ((fp = dos_open(&DOSFS, buf)))
|
||||
return fp;
|
||||
snprintf(buf, PATH_MAX, "/dists/%s", file);
|
||||
if ((fp = dos_open(&DOSFS, buf)))
|
||||
return fp;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -102,11 +97,10 @@ mediaShutdownDOS(Device *dev)
|
||||
{
|
||||
if (!RunningAsInit || !DOSMounted)
|
||||
return;
|
||||
msgDebug("Unmounting %s from /dos\n", dev->name);
|
||||
if (unmount("/dos", MNT_FORCE) != 0)
|
||||
msgConfirm("Could not unmount the DOS partition: %s", strerror(errno));
|
||||
if (isDebug())
|
||||
msgDebug("Unmount successful\n");
|
||||
if (dos_unmount(&DOSFS))
|
||||
msgConfirm("Could not unmount DOS partition %s : %s", dev->devname, strerror(errno));
|
||||
else if (isDebug())
|
||||
msgDebug("Unmount of DOS partition on %s successful\n", dev->devname);
|
||||
DOSMounted = FALSE;
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,674 @@
|
||||
/*
|
||||
* Copyright (c) 1996 Robert Nordier
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "dosio.h"
|
||||
|
||||
#define SECSIZ 512 /* sector size */
|
||||
#define SSHIFT 9 /* SECSIZ shift */
|
||||
#define DEPSEC 16 /* directory entries per sector */
|
||||
#define DSHIFT 4 /* DEPSEC shift */
|
||||
#define NFATS 2 /* number of FATs */
|
||||
#define DENMSZ 8 /* DE name size */
|
||||
#define DEXTSZ 3 /* DE extension size */
|
||||
#define DENXSZ 11 /* DE name + extension size */
|
||||
#define LOCLUS 2 /* lowest cluster number */
|
||||
|
||||
/* DOS "BIOS Parameter Block" */
|
||||
typedef struct {
|
||||
u_char secsiz[2]; /* sector size */
|
||||
u_char spc; /* sectors per cluster */
|
||||
u_char ressec[2]; /* reserved sectors */
|
||||
u_char fats; /* FATs */
|
||||
u_char dirents[2]; /* root directory entries */
|
||||
u_char secs[2]; /* total sectors */
|
||||
u_char media; /* media descriptor */
|
||||
u_char spf[2]; /* sectors per FAT */
|
||||
u_char spt[2]; /* sectors per track */
|
||||
u_char heads[2]; /* drive heads */
|
||||
u_char hidsec[4]; /* hidden sectors */
|
||||
u_char lsecs[4]; /* huge sectors */
|
||||
} DOS_BPB;
|
||||
|
||||
/* Fixed portion of DOS boot sector */
|
||||
typedef struct {
|
||||
u_char jmp[3]; /* usually 80x86 'jmp' opcode */
|
||||
u_char oem[8]; /* OEM name and version */
|
||||
DOS_BPB bpb; /* BPB */
|
||||
u_char drive; /* drive number */
|
||||
u_char reserved; /* reserved */
|
||||
u_char extsig; /* extended boot signature */
|
||||
u_char volid[4]; /* volume ID */
|
||||
u_char label[11]; /* volume label */
|
||||
u_char fstype[8]; /* file system type */
|
||||
} DOS_BS;
|
||||
|
||||
/* Supply missing "." and ".." root directory entries */
|
||||
static DOS_DE dot[2] = {
|
||||
{". ", " ", FA_DIR, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0}, {0x21, 0}, {0, 0}, {0, 0, 0, 0} },
|
||||
{".. ", " ", FA_DIR, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0}, {0x21, 0}, {0, 0}, {0, 0, 0, 0} }
|
||||
};
|
||||
|
||||
/* I/O error handler address */
|
||||
int (*dos_ioerr)(int op) = NULL;
|
||||
|
||||
/* The usual conversion macros to avoid multiplication and division */
|
||||
#define bytsec(n) ((n) >> (SSHIFT))
|
||||
#define secbyt(s) ((u_long)(s) << (SSHIFT))
|
||||
#define entsec(e) ((e) >> (DSHIFT))
|
||||
#define bytblk(fs, n) ((n) >> (fs)->bshift)
|
||||
#define blkbyt(fs, b) ((u_long)(b) << (fs)->bshift)
|
||||
#define blksec(fs, b) ((u_long)(b) << ((fs)->bshift - (SSHIFT)))
|
||||
|
||||
/* Convert cluster number to offset within filesystem */
|
||||
#define blkoff(fs, b) secbyt((fs)->lsndta) + blkbyt(fs, (b) - (LOCLUS))
|
||||
|
||||
/* Convert cluster number to logical sector number */
|
||||
#define blklsn(fs, b) ((fs)->lsndta + blksec(fs, (b) - (LOCLUS)))
|
||||
|
||||
/* Convert cluster number to offset within FAT */
|
||||
#define fatoff(fat12, c) ((u_long)(c) + ((fat12) ? (c) >> 1 : (c)))
|
||||
|
||||
/* Does cluster number reference a valid data cluster? */
|
||||
#define okclus(fs, c) ((c) >= (LOCLUS) && (c) <= (fs)->xclus)
|
||||
|
||||
/* Return on error */
|
||||
#define RETERR(err) { \
|
||||
errno = err; \
|
||||
return -1; \
|
||||
}
|
||||
|
||||
static int dosunmount(DOS_FS *fs);
|
||||
static int dosstat(DOS_FS *fs, DOS_DE *de, struct stat *sb);
|
||||
static int parsebs(DOS_FS *fs, DOS_BS *bs);
|
||||
static int namede(DOS_FS *fs, const char *path, DOS_DE **dep);
|
||||
static DOS_DE *lookup(DOS_FS *fs, unsigned c, const u_char *nx, int *err);
|
||||
static off_t fsize(DOS_FS *fs, DOS_DE *de);
|
||||
static u_short fatget(DOS_FS *fs, u_short c);
|
||||
static int fatend(int fat12, u_short c);
|
||||
static int fatcnt(DOS_FS *fs, u_short c);
|
||||
static int ioread(int fd, off_t offset, void *buf, size_t nbytes);
|
||||
static int ioget(int fd, u_long lsec, void *buf, u_int nsec);
|
||||
static u_char *nxname(const char *name, char **endptr);
|
||||
static int sepchar(int c);
|
||||
static int wildchar(int c);
|
||||
static int doschar(int c);
|
||||
|
||||
/*
|
||||
* Mount DOS filesystem
|
||||
*/
|
||||
int
|
||||
dos_mount(DOS_FS *fs, const char *devname)
|
||||
{
|
||||
char buf[SECSIZ];
|
||||
int err;
|
||||
|
||||
memset(fs, 0, sizeof(DOS_FS));
|
||||
if ((fs->fd = open(devname, O_RDONLY)) == -1)
|
||||
RETERR(errno);
|
||||
if (!(err = ioget(fs->fd, 0, buf, 1)) &&
|
||||
!(err = parsebs(fs, (DOS_BS *)buf)))
|
||||
if (!(fs->fat = malloc(secbyt(fs->spf))))
|
||||
err = errno;
|
||||
else
|
||||
err = ioget(fs->fd, fs->lsnfat, fs->fat, fs->spf);
|
||||
if (err) {
|
||||
dosunmount(fs);
|
||||
RETERR(err);
|
||||
}
|
||||
fs->bsize = secbyt(fs->spc);
|
||||
fs->bshift = ffs(fs->bsize) - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmount mounted filesystem
|
||||
*/
|
||||
int
|
||||
dos_unmount(DOS_FS *fs)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (fs->links)
|
||||
RETERR(EBUSY);
|
||||
if ((err = dosunmount(fs)))
|
||||
RETERR(err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Common code shared by dos_mount() and dos_unmount()
|
||||
*/
|
||||
static
|
||||
int dosunmount(DOS_FS *fs)
|
||||
{
|
||||
if (fs->fat)
|
||||
free(fs->fat);
|
||||
return close(fs->fd) ? errno : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine free data space in filesystem (in bytes)
|
||||
*/
|
||||
u_long
|
||||
dos_free(DOS_FS *fs)
|
||||
{
|
||||
unsigned n, c;
|
||||
|
||||
n = 0;
|
||||
for (c = LOCLUS; c <= fs->xclus; c++)
|
||||
if (!fatget(fs, c))
|
||||
n++;
|
||||
return blkbyt(fs, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close open file
|
||||
*/
|
||||
int
|
||||
dos_close(void *v)
|
||||
{
|
||||
DOS_FILE *f = v;
|
||||
|
||||
f->fs->links--;
|
||||
free(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reposition with file
|
||||
*/
|
||||
fpos_t
|
||||
dos_seek(void *v, fpos_t offset, int whence)
|
||||
{
|
||||
off_t off;
|
||||
u_long size;
|
||||
DOS_FILE *f = v;
|
||||
|
||||
size = cv4(f->de.size);
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
off = 0;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
off = f->offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
off = size;
|
||||
break;
|
||||
default:
|
||||
RETERR(EINVAL);
|
||||
}
|
||||
off += offset;
|
||||
if (off < 0 || off > size)
|
||||
RETERR(EINVAL);
|
||||
f->offset = off;
|
||||
f->c = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from file
|
||||
*/
|
||||
int
|
||||
dos_read(void *v, char *buf, int nbytes)
|
||||
{
|
||||
off_t size;
|
||||
u_long off, cnt, n;
|
||||
unsigned clus, c;
|
||||
int err;
|
||||
DOS_FILE *f = v;
|
||||
|
||||
if ((size = fsize(f->fs, &f->de)) == -1)
|
||||
RETERR(EBADFS);
|
||||
if (nbytes > (n = size - f->offset))
|
||||
nbytes = n;
|
||||
off = f->offset;
|
||||
if ((clus = cv2(f->de.clus)))
|
||||
off &= f->fs->bsize - 1;
|
||||
c = f->c;
|
||||
cnt = nbytes;
|
||||
while (cnt) {
|
||||
n = 0;
|
||||
if (!c) {
|
||||
if ((c = clus))
|
||||
n = bytblk(f->fs, f->offset);
|
||||
} else if (!off)
|
||||
n++;
|
||||
while (n--) {
|
||||
c = fatget(f->fs, c);
|
||||
if (!okclus(f->fs, c))
|
||||
RETERR(EBADFS);
|
||||
}
|
||||
if (!clus || (n = f->fs->bsize - off) > cnt)
|
||||
n = cnt;
|
||||
if ((err = ioread(f->fs->fd, (c ? blkoff(f->fs, c) :
|
||||
secbyt(f->fs->lsndir)) + off,
|
||||
buf, n)))
|
||||
RETERR(err);
|
||||
f->offset += n;
|
||||
f->c = c;
|
||||
off = 0;
|
||||
buf += n;
|
||||
cnt -= n;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get file status
|
||||
*/
|
||||
int
|
||||
dos_stat(DOS_FS *fs, const char *path, struct stat *sb)
|
||||
{
|
||||
DOS_DE *de;
|
||||
int err;
|
||||
|
||||
if ((err = namede(fs, path, &de)) || (err = dosstat(fs, de, sb)))
|
||||
RETERR(err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get file status of open file
|
||||
*/
|
||||
int
|
||||
dos_fstat(DOS_FILE *f, struct stat *sb)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = dosstat(f->fs, &f->de, sb)))
|
||||
RETERR(err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* File status primitive
|
||||
*/
|
||||
static int
|
||||
dosstat(DOS_FS *fs, DOS_DE *de, struct stat *sb)
|
||||
{
|
||||
|
||||
memset(sb, 0, sizeof(struct stat));
|
||||
sb->st_mode = (de->attr & FA_DIR) ? S_IFDIR | 0777 : S_IFREG | 0666;
|
||||
if (de->attr & FA_RDONLY)
|
||||
sb->st_mode &= ~0222;
|
||||
if (de->attr & FA_HIDDEN)
|
||||
sb->st_mode &= ~0007;
|
||||
if (de->attr & FA_SYSTEM)
|
||||
sb->st_mode &= ~0077;
|
||||
sb->st_nlink = 1;
|
||||
dos_cvtime(&sb->st_atime, cv2(de->date), cv2(de->time));
|
||||
sb->st_mtime = sb->st_atime;
|
||||
sb->st_ctime = sb->st_atime;
|
||||
if ((sb->st_size = fsize(fs, de)) == -1)
|
||||
return EBADFS;
|
||||
if (!(de->attr & FA_DIR) || cv2(de->clus))
|
||||
sb->st_blocks = bytblk(fs, sb->st_size + fs->bsize - 1);
|
||||
sb->st_blksize = fs->bsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert from DOS date and time
|
||||
*/
|
||||
void
|
||||
dos_cvtime(time_t *timer, u_short ddate, u_short dtime)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm.tm_sec = (dtime & 0x1f) << 1;
|
||||
tm.tm_min = dtime >> 5 & 0x3f;
|
||||
tm.tm_hour = dtime >> 11;
|
||||
tm.tm_mday = ddate & 0x1f;
|
||||
tm.tm_mon = (ddate >> 5 & 0xf) - 1;
|
||||
tm.tm_year = 80 + (ddate >> 9);
|
||||
*timer = mktime(&tm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open DOS file
|
||||
*/
|
||||
FILE *
|
||||
dos_open(DOS_FS *fs, const char *path)
|
||||
{
|
||||
DOS_DE *de;
|
||||
DOS_FILE *f;
|
||||
u_long size;
|
||||
u_int clus;
|
||||
int err;
|
||||
FILE *fp;
|
||||
|
||||
if ((err = namede(fs, path, &de)))
|
||||
return NULL;
|
||||
clus = cv2(de->clus);
|
||||
size = cv4(de->size);
|
||||
if ((clus && (!okclus(fs, clus) || (!(de->attr & FA_DIR) && !size))) ||
|
||||
(!clus && !(de->attr & FA_DIR) && size))
|
||||
return NULL;
|
||||
f = (DOS_FILE *)malloc(sizeof(DOS_FILE));
|
||||
memset(f, 0, sizeof(DOS_FILE));
|
||||
f->fs = fs;
|
||||
fs->links++;
|
||||
f->de = *de;
|
||||
fp = funopen(f, dos_read, NULL, dos_seek, dos_close);
|
||||
return fp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse DOS boot sector
|
||||
*/
|
||||
static int
|
||||
parsebs(DOS_FS *fs, DOS_BS *bs)
|
||||
{
|
||||
u_long sc;
|
||||
|
||||
if ((bs->jmp[0] != 0xe9 && (bs->jmp[0] != 0xeb || bs->jmp[2] != 0x90)) ||
|
||||
bs->bpb.media < 0xf0 ||
|
||||
cv2(bs->bpb.secsiz) != SECSIZ ||
|
||||
!bs->bpb.spc || (bs->bpb.spc ^ (bs->bpb.spc - 1)) < bs->bpb.spc)
|
||||
return EINVAL;
|
||||
fs->spf = cv2(bs->bpb.spf);
|
||||
fs->dirents = cv2(bs->bpb.dirents);
|
||||
fs->spc = bs->bpb.spc;
|
||||
sc = cv2(bs->bpb.secs);
|
||||
if (!sc && bs->extsig == 0x29)
|
||||
sc = cv4(bs->bpb.lsecs);
|
||||
if (!sc || bs->bpb.fats != NFATS || bs->bpb.spc > 64)
|
||||
return EINVAL;
|
||||
if (!fs->dirents || fs->dirents & (DEPSEC - 1))
|
||||
return EINVAL;
|
||||
fs->lsnfat = cv2(bs->bpb.ressec);
|
||||
fs->lsndir = fs->lsnfat + (u_long)fs->spf * NFATS;
|
||||
fs->lsndta = fs->lsndir + entsec(fs->dirents);
|
||||
if (fs->lsndta > sc || !(sc = (sc - fs->lsndta) / fs->spc) || sc >= 0xfff6)
|
||||
return EINVAL;
|
||||
fs->fat12 = sc < 0xff6;
|
||||
fs->xclus = sc + 1;
|
||||
if (fs->spf < bytsec(fatoff(fs->fat12, fs->xclus) + SECSIZ))
|
||||
return EINVAL;
|
||||
if (bs->extsig == 0x29)
|
||||
fs->volid = cv4(bs->volid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return directory entry from path
|
||||
*/
|
||||
static int
|
||||
namede(DOS_FS *fs, const char *path, DOS_DE **dep)
|
||||
{
|
||||
DOS_DE *de;
|
||||
u_char *nx;
|
||||
int err;
|
||||
|
||||
err = 0;
|
||||
de = dot;
|
||||
if (*path == '/')
|
||||
path++;
|
||||
while (*path) {
|
||||
if (!(nx = nxname(path, (char **)&path)))
|
||||
return EINVAL;
|
||||
if (!(de->attr & FA_DIR))
|
||||
return ENOTDIR;
|
||||
if (!(de = lookup(fs, cv2(de->clus), nx, &err)))
|
||||
return err ? err : ENOENT;
|
||||
if (*path == '/')
|
||||
path++;
|
||||
}
|
||||
*dep = de;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lookup path segment
|
||||
*/
|
||||
static DOS_DE *
|
||||
lookup(DOS_FS *fs, unsigned c, const u_char *nx, int *err)
|
||||
{
|
||||
static DOS_DE dir[DEPSEC];
|
||||
u_long lsec;
|
||||
u_int nsec;
|
||||
int s, e;
|
||||
|
||||
if (!c)
|
||||
for (e = 0; e < 2; e++)
|
||||
if (!memcmp(dot + e, nx, DENXSZ))
|
||||
return dot + e;
|
||||
nsec = !c ? entsec(fs->dirents) : fs->spc;
|
||||
lsec = 0;
|
||||
do {
|
||||
if (!c && !lsec)
|
||||
lsec = fs->lsndir;
|
||||
else if okclus(fs, c)
|
||||
lsec = blklsn(fs, c);
|
||||
else {
|
||||
*err = EBADFS;
|
||||
return NULL;
|
||||
}
|
||||
for (s = 0; s < nsec; s++) {
|
||||
if ((e = ioget(fs->fd, lsec + s, dir, 1))) {
|
||||
*err = e;
|
||||
return NULL;
|
||||
}
|
||||
for (e = 0; e < DEPSEC; e++) {
|
||||
if (!*dir[e].name)
|
||||
return NULL;
|
||||
if (*dir[e].name == 0xe5 || dir[e].attr & FA_LABEL)
|
||||
continue;
|
||||
if (!memcmp(dir + e, nx, DENXSZ))
|
||||
return dir + e;
|
||||
}
|
||||
}
|
||||
} while (c && !fatend(fs->fat12, c = fatget(fs, c)));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return size of file in bytes
|
||||
*/
|
||||
static off_t
|
||||
fsize(DOS_FS *fs, DOS_DE *de)
|
||||
{
|
||||
u_long size;
|
||||
u_int c;
|
||||
int n;
|
||||
|
||||
if (!(size = cv4(de->size)) && de->attr & FA_DIR)
|
||||
if (!(c = cv2(de->clus)))
|
||||
size = fs->dirents * sizeof(DOS_DE);
|
||||
else {
|
||||
if ((n = fatcnt(fs, c)) == -1)
|
||||
return n;
|
||||
size = blkbyt(fs, n);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return next cluster in cluster chain
|
||||
*/
|
||||
static u_short
|
||||
fatget(DOS_FS *fs, u_short c)
|
||||
{
|
||||
u_short x;
|
||||
|
||||
x = cv2(fs->fat + fatoff(fs->fat12, c));
|
||||
return fs->fat12 ? c & 1 ? x >> 4 : x & 0xfff : x;
|
||||
}
|
||||
|
||||
/*
|
||||
* Count number of clusters in chain
|
||||
*/
|
||||
static int
|
||||
fatcnt(DOS_FS *fs, u_short c)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; okclus(fs, c); n++)
|
||||
c = fatget(fs, c);
|
||||
return fatend(fs->fat12, c) ? n : -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Is cluster an end-of-chain marker?
|
||||
*/
|
||||
static int
|
||||
fatend(int fat12, u_short c)
|
||||
{
|
||||
return c > (fat12 ? 0xff7 : 0xfff7) || c == 0xfff0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Offset-based I/O primitive
|
||||
*/
|
||||
static int
|
||||
ioread(int fd, off_t offset, void *buf, size_t nbytes)
|
||||
{
|
||||
char tmp[SECSIZ];
|
||||
u_int off, n;
|
||||
int err;
|
||||
|
||||
if ((off = offset & (SECSIZ - 1))) {
|
||||
offset -= off;
|
||||
if ((err = ioget(fd, bytsec(offset), tmp, 1)))
|
||||
return err;
|
||||
offset += SECSIZ;
|
||||
if ((n = SECSIZ - off) > nbytes)
|
||||
n = nbytes;
|
||||
memcpy(buf, tmp + off, n);
|
||||
buf += n;
|
||||
nbytes -= n;
|
||||
}
|
||||
n = nbytes & (SECSIZ - 1);
|
||||
if (nbytes -= n) {
|
||||
if ((err = ioget(fd, bytsec(offset), buf, bytsec(nbytes))))
|
||||
return err;
|
||||
offset += nbytes;
|
||||
buf += nbytes;
|
||||
}
|
||||
if (n) {
|
||||
if ((err = ioget(fd, bytsec(offset), tmp, 1)))
|
||||
return err;
|
||||
memcpy(buf, tmp, n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sector-based I/O primitive
|
||||
*/
|
||||
static int
|
||||
ioget(int fd, u_long lsec, void *buf, u_int nsec)
|
||||
{
|
||||
size_t nbytes;
|
||||
ssize_t n;
|
||||
|
||||
nbytes = secbyt(nsec);
|
||||
do {
|
||||
if (lseek(fd, secbyt(lsec), SEEK_SET) == -1)
|
||||
return errno;
|
||||
n = read(fd, buf, nbytes);
|
||||
} while (n == -1 && errno == EIO && dos_ioerr && dos_ioerr(0));
|
||||
if (n != nbytes)
|
||||
return n == -1 ? errno : EIO;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert name to DOS directory (name + extension) format
|
||||
*/
|
||||
static u_char *
|
||||
nxname(const char *name, char **endptr)
|
||||
{
|
||||
static u_char nx[DENXSZ];
|
||||
int i;
|
||||
|
||||
memset(nx, ' ', sizeof(nx));
|
||||
for (i = 0; i < DENMSZ && doschar(*name); i++)
|
||||
nx[i] = toupper(*name++);
|
||||
if (i) {
|
||||
if (i == DENMSZ)
|
||||
while (!sepchar(*name))
|
||||
name++;
|
||||
if (*name == '.') {
|
||||
name++;
|
||||
for (i = 0; i < DEXTSZ && doschar(*name); i++)
|
||||
nx[DENMSZ + i] = toupper(*name++);
|
||||
if (i == DEXTSZ)
|
||||
while(!sepchar(*name))
|
||||
name++;
|
||||
}
|
||||
} else if (*name == '.') {
|
||||
nx[0] = *name++;
|
||||
if (*name == '.')
|
||||
nx[1] = *name++;
|
||||
}
|
||||
if ((*name && *name != '/') || *nx == ' ')
|
||||
return NULL;
|
||||
if (*nx == 0xe5)
|
||||
*nx = 5;
|
||||
*endptr = (char *)name;
|
||||
return nx;
|
||||
}
|
||||
|
||||
/*
|
||||
* Is character a path-separator?
|
||||
*/
|
||||
static int
|
||||
sepchar(int c)
|
||||
{
|
||||
return !wildchar(c) && !doschar(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Is character a wildcard?
|
||||
*/
|
||||
static int
|
||||
wildchar(int c)
|
||||
{
|
||||
return c == '*' || c == '?';
|
||||
}
|
||||
|
||||
/*
|
||||
* Is character valid in a DOS name?
|
||||
*/
|
||||
static int
|
||||
doschar(int c)
|
||||
{
|
||||
return c & 0x80 || (c >= ' ' && !strchr("\"*+,./:;<=>?[\\]|", c));
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 1996 Robert Nordier
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef DOSIO_H
|
||||
#define DOSIO_H
|
||||
|
||||
/*
|
||||
* DOS file attributes
|
||||
*/
|
||||
|
||||
#define FA_RDONLY 0x01 /* read-only */
|
||||
#define FA_HIDDEN 0x02 /* hidden file */
|
||||
#define FA_SYSTEM 0x04 /* system file */
|
||||
#define FA_LABEL 0x08 /* volume label */
|
||||
#define FA_DIR 0x10 /* directory */
|
||||
#define FA_ARCH 0x20 /* archive (file modified) */
|
||||
|
||||
/*
|
||||
* Error number to overload if filesystem errors are detected during
|
||||
* routine processing
|
||||
*/
|
||||
|
||||
#define EBADFS EINVAL
|
||||
|
||||
/*
|
||||
* Macros to convert DOS-format 16-bit and 32-bit quantities
|
||||
*/
|
||||
|
||||
#define cv2(p) ((u_short)(p)[0] | \
|
||||
((u_short)(p)[1] << 010))
|
||||
|
||||
#define cv4(p) ((u_long)(p)[0] | \
|
||||
((u_long)(p)[1] << 010) | \
|
||||
((u_long)(p)[2] << 020) | \
|
||||
((u_long)(p)[3] << 030))
|
||||
|
||||
/*
|
||||
* DOS directory structure
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
u_char name[8]; /* name */
|
||||
u_char ext[3]; /* extension */
|
||||
u_char attr; /* attributes */
|
||||
u_char reserved[10]; /* reserved */
|
||||
u_char time[2]; /* time */
|
||||
u_char date[2]; /* date */
|
||||
u_char clus[2]; /* starting cluster */
|
||||
u_char size[4]; /* file size */
|
||||
} DOS_DE;
|
||||
|
||||
typedef struct {
|
||||
u_char *fat; /* FAT */
|
||||
u_long volid; /* volume id */
|
||||
u_long lsnfat; /* logical sector number: fat */
|
||||
u_long lsndir; /* logical sector number: dir */
|
||||
u_long lsndta; /* logical sector number: data area */
|
||||
short fd; /* file descriptor */
|
||||
short fat12; /* 12-bit FAT entries */
|
||||
u_short spf; /* sectors per fat */
|
||||
u_short dirents; /* root directory entries */
|
||||
u_short spc; /* sectors per cluster */
|
||||
u_short xclus; /* maximum cluster number */
|
||||
u_short bsize; /* cluster size in bytes */
|
||||
u_short bshift; /* cluster conversion shift */
|
||||
u_short links; /* active links to structure */
|
||||
} DOS_FS;
|
||||
|
||||
typedef struct {
|
||||
DOS_FS *fs; /* associated filesystem */
|
||||
DOS_DE de; /* directory entry */
|
||||
u_long offset; /* current offset */
|
||||
u_short c; /* last cluster read */
|
||||
} DOS_FILE;
|
||||
|
||||
/*
|
||||
* The following variable can be set to the address of an error-handling
|
||||
* routine which will be invoked when a read() returns EIO. The handler
|
||||
* should return 1 to retry the read, otherwise 0.
|
||||
*/
|
||||
|
||||
extern int (*dos_ioerr)(int op);
|
||||
|
||||
int dos_mount(DOS_FS *fs, const char *devname);
|
||||
int dos_unmount(DOS_FS *fs);
|
||||
u_long dos_free(DOS_FS *fs);
|
||||
FILE *dos_open(DOS_FS *fs, const char *path);
|
||||
int dos_close(void *v);
|
||||
fpos_t dos_seek(void *v, fpos_t offset, int whence);
|
||||
int dos_read(void *v, char *buf, int nbytes);
|
||||
int dos_stat(DOS_FS *fs, const char *path, struct stat *sb);
|
||||
int dos_fstat(DOS_FILE *f, struct stat *sb);
|
||||
void dos_cvtime(time_t *timer, u_short ddate, u_short dtime);
|
||||
|
||||
#endif /* !DOSIO_H */
|
||||
+26
-21
@@ -4,7 +4,7 @@
|
||||
* This is probably the last attempt in the `sysinstall' line, the next
|
||||
* generation being slated to essentially a complete rewrite.
|
||||
*
|
||||
* $Id: floppy.c,v 1.16 1996/10/09 09:53:30 jkh Exp $
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 1995
|
||||
* Jordan Hubbard. All rights reserved.
|
||||
@@ -117,18 +117,20 @@ mediaInitFloppy(Device *dev)
|
||||
{
|
||||
struct msdosfs_args dosargs;
|
||||
struct ufs_args u_args;
|
||||
char *mountpoint = "/dist";
|
||||
|
||||
if (floppyMounted)
|
||||
return TRUE;
|
||||
|
||||
if (Mkdir("/dist")) {
|
||||
msgConfirm("Unable to make directory mountpoint for %s!", dev->devname);
|
||||
if (Mkdir(mountpoint)) {
|
||||
msgConfirm("Unable to make %s directory mountpoint for %s!", mountpoint, dev->devname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
msgDebug("Init floppy called for %s distribution.\n", distWanted ? distWanted : "some");
|
||||
if (!distWanted)
|
||||
msgConfirm("Please insert floppy for %s", dev->description);
|
||||
else if (distWanted != (char *)1) /* 1 is kludge for "don't ask!" */
|
||||
else
|
||||
msgConfirm("Please insert floppy containing %s for %s", distWanted, dev->description);
|
||||
|
||||
memset(&dosargs, 0, sizeof dosargs);
|
||||
@@ -139,55 +141,58 @@ mediaInitFloppy(Device *dev)
|
||||
memset(&u_args, 0, sizeof(u_args));
|
||||
u_args.fspec = dev->devname;
|
||||
|
||||
if (mount(MOUNT_MSDOS, "/dist", MNT_RDONLY, (caddr_t)&dosargs) == -1) {
|
||||
if (mount(MOUNT_UFS, "/dist", MNT_RDONLY, (caddr_t)&u_args) == -1) {
|
||||
if (distWanted != (char *)1)
|
||||
msgConfirm("Error mounting floppy %s (%s) on /dist : %s", dev->name, dev->devname, strerror(errno));
|
||||
if (mount(MOUNT_MSDOS, mountpoint, MNT_RDONLY, (caddr_t)&dosargs) == -1) {
|
||||
if (mount(MOUNT_UFS, mountpoint, MNT_RDONLY, (caddr_t)&u_args) == -1) {
|
||||
msgConfirm("Error mounting floppy %s (%s) on %s : %s", dev->name, dev->devname, mountpoint,
|
||||
strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
msgDebug("initFloppy: mounted floppy %s successfully on /dist\n", dev->devname);
|
||||
msgDebug("initFloppy: mounted floppy %s successfully on %s\n", dev->devname, mountpoint);
|
||||
floppyMounted = TRUE;
|
||||
distWanted = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
FILE *
|
||||
mediaGetFloppy(Device *dev, char *file, Boolean probe)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
int fd;
|
||||
int nretries = 5;
|
||||
char buf[PATH_MAX];
|
||||
FILE *fp;
|
||||
int nretries = 5;
|
||||
|
||||
snprintf(buf, PATH_MAX, "/dist/%s", file);
|
||||
|
||||
msgDebug("Request for %s from floppy on /dist, probe is %d.\n", buf, probe);
|
||||
if (isDebug())
|
||||
msgDebug("Request for %s from floppy on /dist, probe is %d.\n", buf, probe);
|
||||
if (!file_readable(buf)) {
|
||||
if (probe)
|
||||
return -1;
|
||||
return NULL;
|
||||
else {
|
||||
while (!file_readable(buf)) {
|
||||
if (!--nretries) {
|
||||
msgConfirm("GetFloppy: Failed to get %s after retries;\ngiving up.", buf);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
distWanted = buf;
|
||||
mediaShutdownFloppy(dev);
|
||||
if (!mediaInitFloppy(dev))
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
fd = open(buf, O_RDONLY);
|
||||
return fd;
|
||||
fp = fopen(buf, "r");
|
||||
return fp;
|
||||
}
|
||||
|
||||
void
|
||||
mediaShutdownFloppy(Device *dev)
|
||||
{
|
||||
char *mountpoint = "/dist";
|
||||
|
||||
if (floppyMounted) {
|
||||
if (unmount("/dist", MNT_FORCE) != 0)
|
||||
msgDebug("Umount of floppy on /dist failed: %s (%d)\n", strerror(errno), errno);
|
||||
if (unmount(mountpoint, MNT_FORCE) != 0)
|
||||
msgDebug("Umount of floppy on %s failed: %s (%d)\n", mountpoint, strerror(errno), errno);
|
||||
else {
|
||||
floppyMounted = FALSE;
|
||||
msgDebug("Floppy unmounted successfully.\n");
|
||||
|
||||
Loaded 100 of 411 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user