git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8

This commit is contained in:
ipfire
2006-02-15 21:15:54 +00:00
parent 6d63f4c4b3
commit cd1a292722
1206 changed files with 185026 additions and 0 deletions

12
src/CVS/Entries Normal file
View File

@@ -0,0 +1,12 @@
/ROOTFILES.alpha/1.12.2.136/Thu Feb 2 14:23:24 2006//TIPCOP_v1_4_0
/ROOTFILES.i386/1.23.2.157/Thu Feb 2 14:23:24 2006//TIPCOP_v1_4_0
D/ibod////
D/install+setup////
D/misc-progs////
D/nash////
D/patches////
D/pcmcia////
D/ppp////
D/rc.d////
D/scripts////
D/uClibc////

1
src/CVS/Repository Normal file
View File

@@ -0,0 +1 @@
ipcop/src

1
src/CVS/Root Normal file
View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop

1
src/CVS/Tag Normal file
View File

@@ -0,0 +1 @@
TIPCOP_v1_4_0

24080
src/ROOTFILES.alpha Normal file

File diff suppressed because it is too large Load Diff

24748
src/ROOTFILES.i386 Normal file

File diff suppressed because it is too large Load Diff

4
src/ibod/CVS/Entries Normal file
View File

@@ -0,0 +1,4 @@
/ibod.c/1.1.1.1.8.1/Sat May 7 12:46:16 2005//TIPCOP_v1_4_0
/ibod.cf/1.1.1.1/Tue Nov 27 08:08:03 2001//TIPCOP_v1_4_0
/ibod.h/1.1.1.1/Tue Nov 27 08:08:03 2001//TIPCOP_v1_4_0
D

1
src/ibod/CVS/Repository Normal file
View File

@@ -0,0 +1 @@
ipcop/src/ibod

1
src/ibod/CVS/Root Normal file
View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop

1
src/ibod/CVS/Tag Normal file
View File

@@ -0,0 +1 @@
TIPCOP_v1_4_0

367
src/ibod/ibod.c Normal file
View File

@@ -0,0 +1,367 @@
/* Customised version of ibod - GUI code removed by Mark Wormgoor
* Buffer overflow fixes by Robert Kerr
*
* ibod originally by Bjoern Smith
*/
static char *rcsId = "$Id: ibod.c,v 1.1.1.1.8.1 2005/05/07 12:46:16 rkerr Exp $";
static char *rcsSymbol = "$Symbol$";
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/isdn.h>
#include <syslog.h>
#include <errno.h>
#include "ibod.h"
static int setattr();
static void reread(int sig);
static void pipehndl(int sig);
static void setinterval();
static void get_if_state();
static int bring_up_slave();
static int bring_down_slave();
static Conf cf;
static struct timeval timeout, tv_last, tv_up;
static int usageflags[ISDN_MAX_CHANNELS];
static char phone[ISDN_MAX_CHANNELS][20];
static Siobytes iobytes[ISDN_MAX_CHANNELS];
static unsigned long in_bytes_last, out_bytes_last;
static unsigned long in_bytes_per_sec, out_bytes_per_sec;
static unsigned long channels_last;
static int channels_now;
main(int argc, char *argv[])
{
openlog("ibod", LOG_PID, LOG_DAEMON);
channels_last = -1;
/* Setup initial attributes */
if (setattr() == -1) {
closelog();
exit(1);
}
setinterval();
/* Setup handlig of signal SIGHUP and SIGPIPE */
signal(SIGHUP, reread);
signal(SIGPIPE, pipehndl);
do {
setinterval();
usleep(timeout.tv_usec);
/* Gate state of interface */
get_if_state();
} while (1);
}
static int setattr()
{
FILE *fd;
char config_filename[MAX_STR_LEN] = IBOD_DEFAULT_DIR "/ibod.cf";
char linebuf[MAX_STR_LEN];
char *key, *value;
int val;
strcpy(cf.dev, DEVICE);
cf.enable = ENABLE;
cf.interval = INTERVAL;
cf.filter = FILTER;
cf.limit = LIMIT;
cf.stayup = STAYUP;
cf.stayup_time = STAYUP_TIME;
/* Open config file */
if ((fd = fopen(config_filename, "r")) == NULL) {
syslog(LOG_ERR, "%s: %s\n", config_filename, strerror(errno));
return -1;
}
/* Loop over the config file to setup attributes */
while (fgets(linebuf, MAX_STR_LEN, fd) != NULL) {
if (*linebuf == '#') /* Ignore comments */
continue;
key = strtok(linebuf, " \t");
value = strtok(NULL, " \t\n");
if (strcmp(key, "DEVICE") == 0) {
if (strcmp(cf.dev, value) != 0)
syslog(LOG_NOTICE,
"Parameter DEVICE reconfigured to %s\n", value);
snprintf(cf.dev, 32,"%s", value);
}
if (strcmp(key, "ENABLE") == 0) {
val = atoi(value);
if (cf.enable != val)
syslog(LOG_NOTICE,
"Parameter ENABLE reconfigured to %d\n", val);
cf.enable = val;
}
if (strcmp(key, "INTERVAL") == 0) {
val = atoi(value);
if (cf.interval != val)
syslog(LOG_NOTICE,
"Parameter INTERVAL reconfigured to %d\n", val);
cf.interval = atoi(value);
}
if (strcmp(key, "FILTER") == 0) {
val = atoi(value);
if (cf.filter != val)
syslog(LOG_NOTICE,
"Parameter FILTER reconfigured to %d\n", val);
cf.filter = atoi(value);
}
if (strcmp(key, "LIMIT") == 0) {
val = atoi(value);
if (cf.limit != val)
syslog(LOG_NOTICE,
"Parameter LIMIT reconfigured to %d\n", val);
cf.limit = atoi(value);
}
if (strcmp(key, "STAYUP") == 0) {
val = atoi(value);
if (cf.stayup != val)
syslog(LOG_NOTICE,
"Parameter STAYUP reconfigured to %d\n", val);
cf.stayup = atoi(value);
}
if (strcmp(key, "STAYUP_TIME") == 0) {
val = atoi(value);
if (cf.stayup_time != val)
syslog(LOG_NOTICE,
"Parameter STAYUP_TIME reconfigured to %d\n", val);
cf.stayup_time = atoi(value);
}
}
fclose(fd);
return 0;
}
static void setinterval()
{
timeout.tv_sec = cf.interval / 1000;
timeout.tv_usec = (cf.interval % 1000) * 1000;
}
static void reread(int sig)
{
(void) setattr();
setinterval();
signal(SIGHUP, reread);
}
static void pipehndl(int sig)
{
syslog(LOG_ERR, "caught SIGPIPE: %s\n", sys_errlist[errno]);
signal(SIGPIPE, pipehndl);
}
static void get_if_state()
{
static char buf[4096];
struct timeval tv_now;
int ms_delta;
int in_bytes_now, out_bytes_now;
int fd;
int i;
/* Open the info device */
if ((fd = open(ISDN_INFO_DEV, O_RDONLY | O_NDELAY)) < 0) {
syslog(LOG_ERR, "%s: %s\n", ISDN_INFO_DEV, sys_errlist[errno]);
closelog();
exit(1);
}
/* Whats the time now */
gettimeofday(&tv_now, NULL);
ms_delta = (tv_now.tv_sec * 1000 + tv_now.tv_usec / 1000) -
(tv_last.tv_sec * 1000 + tv_last.tv_usec / 1000);
tv_last = tv_now;
/* Get info from interface */
if (read(fd, buf, sizeof(buf))> 0) {
sscanf(strstr(buf, "usage:"),
"usage: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
&usageflags[0], &usageflags[1], &usageflags[2], &usageflags[3],
&usageflags[4], &usageflags[5], &usageflags[6], &usageflags[7],
&usageflags[8], &usageflags[9], &usageflags[10], &usageflags[11],
&usageflags[12], &usageflags[13], &usageflags[14], &usageflags[15]);
sscanf(strstr(buf, "phone:"),
"phone: %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
phone[0], phone[1], phone[2], phone[3],
phone[4], phone[5], phone[6], phone[7],
phone[8], phone[8], phone[10], phone[11],
phone[12], phone[13], phone[14], phone[15]);
}
in_bytes_now = 0;
out_bytes_now = 0;
channels_now = 0;
/* Get byte in/out for all channels */
if (ioctl(fd, IIOCGETCPS, &iobytes)) {
syslog(LOG_ERR, "%s: %s\n", IIOCGETCPS, sys_errlist[errno]);
closelog();
exit(1);
}
close(fd);
/* Count number of open channes and total in/out bytes */
for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
if (usageflags[i]) {
channels_now++;
in_bytes_now += iobytes[i].ibytes;
out_bytes_now += iobytes[i].obytes;
}
}
if (channels_last == -1 || channels_now < channels_last) {
channels_last = channels_now;
in_bytes_last = in_bytes_now;
out_bytes_last = out_bytes_now;
return;
}
/* Calculate the total through put in bytes/sec */
if (cf.filter < 1) {
in_bytes_per_sec =
(in_bytes_now - in_bytes_last) * 1000 / ms_delta;
out_bytes_per_sec =
(out_bytes_now - out_bytes_last) * 1000 / ms_delta;
}
else {
in_bytes_per_sec = (in_bytes_per_sec * (cf.filter - 1) +
(in_bytes_now - in_bytes_last) * 1000 / ms_delta) / cf.filter;
out_bytes_per_sec = (out_bytes_per_sec * (cf.filter - 1) +
(out_bytes_now - out_bytes_last) * 1000 / ms_delta) / cf.filter;
}
in_bytes_last = in_bytes_now;
out_bytes_last = out_bytes_now;
if (channels_now == 0) {
channels_last = channels_now;
return;
}
/* Take up or down slave channel */
if (cf.enable == 0) {
channels_last = channels_now;
return;
}
if (channels_now == 1 &&
(in_bytes_per_sec > cf.limit || out_bytes_per_sec > cf.limit)) {
/* Bring up slave interface */
if (bring_up_slave() == -1)
exit(1);
/* Start stay up timer */
gettimeofday(&tv_up, NULL);
}
if ((channels_now > 1) &&
(in_bytes_per_sec <= cf.limit) &&
(out_bytes_per_sec <= cf.limit) &&
(cf.stayup == 0)) {
/* Check that the min stay up timer has expired */
gettimeofday(&tv_now, NULL);
if (tv_now.tv_sec - tv_up.tv_sec > cf.stayup_time) {
/* Bring down slave interface */
if (bring_down_slave() == -1)
exit(1);
}
}
channels_last = channels_now;
}
static int bring_up_slave()
{
int fd, rc;
if ((fd = open(ISDN_CTLR_DEV, O_RDWR)) < 0) {
syslog(LOG_ERR, "%s: %s\n", ISDN_CTLR_DEV, sys_errlist[errno]);
closelog();
return -1;
}
if ((rc = ioctl(fd, IIOCNETALN, cf.dev)) < 0) {
syslog(LOG_ERR, "%s: %s\n", cf.dev, sys_errlist[errno]);
closelog();
return -1;
}
close(fd);
if (! rc) {
syslog(LOG_NOTICE, "added new link\n");
channels_now = 2;
}
return 0;
}
static int bring_down_slave()
{
int fd, rc;
if ((fd = open(ISDN_CTLR_DEV, O_RDWR)) < 0) {
syslog(LOG_ERR, "%s: %s\n", ISDN_CTLR_DEV, sys_errlist[errno]);
closelog();
return -1;
}
if ((rc = ioctl(fd, IIOCNETDLN, cf.dev)) < 0) {
syslog(LOG_ERR, "%s: %s\n", cf.dev, sys_errlist[errno]);
closelog();
return -1;
}
close(fd);
if (rc)
syslog(LOG_ERR, "unable to remove additional link: %d\n", rc);
else {
syslog(LOG_NOTICE, "removed link\n");
}
return 0;
}

58
src/ibod/ibod.cf Normal file
View File

@@ -0,0 +1,58 @@
# $Id: ibod.cf,v 1.1.1.1 2001/11/27 08:08:03 riddles Exp $
# $Symbol$
#
#
#
# Configuration file for ibod (ISDN Bandwidth On Demand)
#
# This file contain the initial configuration values for the
# ibod daemon. Each line contain a keyword and a value.
#
# Boolean attributes are set with 0 or 1 which corresponds to
# false and true respectively. A boolean attribute not specified
# at all is allways false.
#
# Lines beginning with # are treated as comments and are ignored.
#
# IMPORTANT RULES!
#
# 1. Keywords are case sensitive.
# 2. Kewords must begin at first column.
# 3. Keyword and value must be separated by exctly one (1)
# space ot tab chracter.
#
# This file is re-read every time ibod receives SIGHUP (1) signal.
#
# DEVICE <name> Name of ISDN PPP device.
# Default is ippp0.
#
# ENABLE 1|0 Enable/disable bandwidth-on-demand.
# Default is enable (1).
#
# INTERVAL <n> Specify the sample time interval in ms.
# Default is 500 ms.
#
# FILTER <n> Defines "filtering factor". A value of 10 means
# that the average bytes/sec value measured over 10
# intervals must pass the limit defined by LIMIT
# to bring up or down the slave link.
# Default is 5.
#
# LIMIT <n> Transfer rate limit in bytes/sec for bringing
# up or down isdn slave channel.
# Default is 5000.
#
# STAYUP 0|1 Enable/disable slave channel stay up function.
# If enabled the 2:nd cannel (slave link) will stay
# up even if the average bytes/sec decrease the value
# defined by LIMIT. In this case the slave link will
# stay up until hangup time is reached.
# (Example: isdnctrl huptimeout ippp1 60)
# If disabled the slave link will be brought down in
# the same way it is brought up.
# Default is 0.
#
# STAYUP_TIME <n> Defines the minimum time in seconds the 2:nd
# channel will unconditionally stay up after it has
# been brought up. Default value is 30.
#

39
src/ibod/ibod.h Normal file
View File

@@ -0,0 +1,39 @@
/* $Id: ibod.h,v 1.1.1.1 2001/11/27 08:08:03 riddles Exp $
* $Symbol$
*/
#define DEVICE "ippp0"
#define ENABLE 1
#define INTERVAL 500
#define FILTER 5
#define LIMIT 7000
#define STAYUP 0
#define STAYUP_TIME 30
#define IBOD_DEFAULT_DIR "/etc/ppp"
#define MAX_STR_LEN 512
#define ISDN_INFO_DEV "/dev/isdninfo"
#define ISDN_CTLR_DEV "/dev/isdnctrl"
#define IBOD_PORT 6050
#define CMD_OPEN 0
#define CMD_CLOSE 1
#define CMD_ENABLE 2
#define CMD_DISABLE 3
#define CMD_UP2 4
#define CMD_DOWN2 5
typedef struct {
char dev[32];
int enable;
int interval;
int limit;
int filter;
int stayup;
int stayup_time;
} Conf;
typedef struct {
unsigned long ibytes;
unsigned long obytes;
} Siobytes;

View File

@@ -0,0 +1,3 @@
D/install////
D/libsmooth////
D/setup////

View File

@@ -0,0 +1 @@
ipcop/src/install+setup

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop

View File

@@ -0,0 +1 @@
TIPCOP_v1_4_0

View File

@@ -0,0 +1,18 @@
/Makefile/1.6.2.2/Wed Jan 11 01:01:38 2006//TIPCOP_v1_4_0
/cdrom.c/1.6.2.1/Wed Apr 14 22:05:39 2004//TIPCOP_v1_4_0
/config.c/1.6.2.3/Wed Dec 7 20:42:48 2005//TIPCOP_v1_4_0
/grubbatch/1.1.2.5/Mon Sep 13 17:00:53 2004//TIPCOP_v1_4_0
/ide.c/1.4/Thu Dec 11 11:25:53 2003//TIPCOP_v1_4_0
/install.h/1.10.2.4/Wed Jan 11 01:01:38 2006//TIPCOP_v1_4_0
/install2.c/1.1.2.3/Tue Jan 31 00:51:50 2006//TIPCOP_v1_4_0
/main.c/1.63.2.64/Wed Jan 11 01:01:38 2006//TIPCOP_v1_4_0
/net.c/1.8.2.2/Wed Apr 14 22:05:40 2004//TIPCOP_v1_4_0
/nic.c/1.8.2.2/Sat Dec 24 09:08:26 2005//TIPCOP_v1_4_0
/pcmcia.c/1.6.2.4/Thu Dec 8 02:12:28 2005//TIPCOP_v1_4_0
/pcmcia.h/1.1/Sun Jan 25 09:34:59 2004//TIPCOP_v1_4_0
/probescsi.sh/1.8.2.4/Mon Sep 20 19:42:32 2004//TIPCOP_v1_4_0
/scsi.c/1.2.2.1/Tue Dec 6 18:26:36 2005//TIPCOP_v1_4_0
/upgrade-v12-v13.c/1.2.2.3/Thu Nov 11 09:39:25 2004//TIPCOP_v1_4_0
/upgrade-v130-v140.c/1.12.2.35/Thu Nov 11 09:40:03 2004//TIPCOP_v1_4_0
/usb.c/1.9.2.8/Sat Dec 10 00:18:23 2005//TIPCOP_v1_4_0
D

View File

@@ -0,0 +1 @@
ipcop/src/install+setup/install

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop

View File

@@ -0,0 +1 @@
TIPCOP_v1_4_0

View File

@@ -0,0 +1,72 @@
#
# $Id: Makefile,v 1.6.2.2 2006/01/11 01:01:38 franck78 Exp $
#
CC = gcc
CFLAGS = -Os -Wall
INCLUDE = -I/install/include
LD = gcc
LDFLAGS = -L/install/lib
LIBS = -lnewt -lslang -lpci
COMPILE = $(CC) -c $(INCLUDE) $(CFLAGS)
LINK = $(LD) $(LDFLAGS)
all : programs
programs : install install2
clean :
-rm -f *.o install core
######
# Macro to extract from the full set of translations only what is really used
# into the installer (install&install2). Each needed entry have a "comment
# inside the main source file"
define lang_install
rm $(OBJS3); \
for i in /usr/src/langs/*/install/lang_*.c ; do \
path=$${i%/*}/; \
file=../libsmooth/$${i/$$path/}; \
echo "#include \"libsmooth.h\"" > $$file; \
grep "^char \*" $$i >> $$file; \
echo "#include \"libsmooth.h\"" > $$file; \
grep "^char \*" $$i >> $$file; \
grep "^/\* TR_*" ../install/$$SELECT|xargs -i% grep -FA1 % $$i >> $$file; \
echo "};">>$$file; \
done
#build the tr_strings include file
awk 'BEGIN{ print"enum trstrings{" } \
$$0 ~/\/\* (TR_[A-Z0-9_]*)/ {print $$2"," }\
END{ print "};" }' ../libsmooth/lang_en.c > ../libsmooth/langs.h
endef
lang_install:
SELECT=main.c; \
$(lang_install)
cp ../libsmooth/langs.h main_langs.h
lang_install2:
SELECT=install2.c; \
$(lang_install)
cp ../libsmooth/langs.h install_langs.h
OBJS1=main.o ide.o cdrom.o nic.o net.o config.o pcmcia.o usb.o scsi.o
OBJS2=install2.o upgrade-v12-v13.o upgrade-v130-v140.o
OBJS3=../libsmooth/main.o ../libsmooth/netstuff.o ../libsmooth/varval.o
install: lang_install $(OBJS1) $(OBJS3) install.h ../libsmooth/langs.h ../libsmooth/libsmooth.h /install/include/newt.h
$(LINK) $(OBJS1) $(OBJS3) -o $@ $(LIBS)
install2: lang_install2 $(OBJS2) $(OBJS3)
#strange 'make': even if files $OBJS3 are deleted, they are not recompiled,
#so I explicitly recompile them (needed because langs.h have changed).
$(foreach I, $(OBJS3), $(COMPILE) $(patsubst %.o,%.c,$(I)) -o $(I);)
$(LINK) $(OBJS2) $(OBJS3) -o $@ $(LIBS)
%.o : %.c
$(COMPILE) $< -o $@
.PHONY : lang_install lang_install2 clean

View File

@@ -0,0 +1,36 @@
/* SmoothWall install program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* CDROM menu. Get "misc" driver name etc.
*
* $Id: cdrom.c,v 1.6.2.1 2004/04/14 22:05:39 gespinasse Exp $
*
*/
#include "install.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
/* Ejects the CDROM. returns 0 for failure, 1 for success. */
int ejectcdrom(char *dev)
{
int fd;
if ((fd = open(dev, O_RDONLY|O_NONBLOCK)) == -1)
return 0;
if (ioctl(fd, CDROMEJECT) == -1)
{
close(fd);
return 0;
}
close(fd);
return 1;
}

View File

@@ -0,0 +1,125 @@
/* SmoothWall install program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Write the config and get password stuff.
*
* $Id: config.c,v 1.6.2.3 2005/12/07 20:42:48 franck78 Exp $
*
*/
#include "install.h"
extern char **ctr; // text translation table
/* called to write out all config files using the keyvalue interface. */
int write_disk_configs(struct devparams *dp)
{
char devnode[STRING_SIZE];
char partition[STRING_SIZE];
char *messages[5] = { NULL,
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK1],
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK2],
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK3],
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK4]
};
/* dev node links. */
sprintf(devnode, "%s", dp->devnode_disk_run);
if (symlink(devnode, "/harddisk/dev/harddisk"))
{
errorbox(ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK]);
return 0;
}
int j;
for (j=1; j<5; j++) {
sprintf(devnode, "%s%d", dp->devnode_part_run,j);
sprintf(partition,"/harddisk/dev/harddisk%d",j);
if (symlink(devnode, partition))
{
errorbox( messages[j] );
return 0;
}
}
/* Add /dev/root symlink linking to the root filesystem to
* keep updfstab happy */
sprintf(devnode, "%s4", dp->devnode_part_run);
if (symlink(devnode, "/harddisk/dev/root"))
{
errorbox(ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_ROOT]);
return 0;
}
return 1;
}
int write_lang_configs( char *lang)
{
struct keyvalue *kv = initkeyvalues();
/* default stuff for main/settings. */
replacekeyvalue(kv, "LANGUAGE", lang);
replacekeyvalue(kv, "HOSTNAME", SNAME);
writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings");
freekeyvalues(kv);
return 1;
}
int write_ethernet_configs(struct keyvalue *ethernetkv)
{
/* Write out the network settings we got from a few mins ago. */
writekeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings");
return 1;
}
/* Taken from the cdrom one. */
int getpassword(char *password, char *text)
{
char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{
{ ctr[TR_PASSWORD_PROMPT], &values[0], 2 },
{ ctr[TR_AGAIN_PROMPT], &values[1], 2 },
{ NULL, NULL, 0 }
};
char title[STRING_SIZE];
int rc;
int done;
do
{
done = 1;
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
rc = newtWinEntries(title, text,
50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc != 2)
{
if (strlen(values[0]) == 0 || strlen(values[1]) == 0)
{
errorbox(ctr[TR_PASSWORD_CANNOT_BE_BLANK]);
done = 0;
strcpy(values[0], "");
strcpy(values[1], "");
}
else if (strcmp(values[0], values[1]) != 0)
{
errorbox(ctr[TR_PASSWORDS_DO_NOT_MATCH]);
done = 0;
strcpy(values[0], "");
strcpy(values[1], "");
}
}
}
while (!done);
strncpy(password, values[0], STRING_SIZE);
if (values[0]) free(values[0]);
if (values[1]) free(values[1]);
return rc;
}

View File

@@ -0,0 +1,9 @@
#!/bin/sh
/bin/cp -f /usr/share/grub/i386-pc/* /boot/grub
/usr/sbin/grub --no-floppy --batch <<EOT > /dev/null 2> /dev/null
device (hd0) DEVICE
root (hd0,0)
setup (hd0,0)
setup (hd0)
quit
EOT

View File

@@ -0,0 +1,61 @@
/* SmoothWall install program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains some functs for scanning /proc for ide info on CDROMS and
* harddisks.
*
* $Id: ide.c,v 1.4 2003/12/11 11:25:53 riddles Exp $
*
*/
#include "install.h"
/* checkide(). Scans the named drive letter and returns the IDE_??? type. */
int checkide(char letter)
{
FILE *f = NULL;
char filename[STRING_SIZE];
char buffer[STRING_SIZE];
sprintf(filename, "/proc/ide/hd%c/media", letter);
if (!(f = fopen(filename, "r")))
return IDE_EMPTY;
if (!(fgets(buffer, STRING_SIZE, f)))
{
printf("Couldn't read from %s\n", filename);
fclose(f);
return IDE_EMPTY;
}
fclose(f);
stripnl(buffer);
if (strcmp(buffer, "cdrom") == 0)
return IDE_CDROM;
else if (strcmp(buffer, "disk") == 0)
return IDE_HD;
else
return IDE_UNKNOWN;
}
/* findidetype(). Finds the first ide deveice of the given IDE_?? type. */
char findidetype(int type)
{
char letter;
for (letter = 'a'; letter <= 'z'; letter++)
{
if ((checkide(letter)) == type)
{
return letter;
}
}
return '\0';
}

View File

@@ -0,0 +1,92 @@
/* SmoothWall install program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Main include file.
*
* $Id: install.h,v 1.10.2.4 2006/01/11 01:01:38 franck78 Exp $
*
*/
#include "../libsmooth/libsmooth.h"
#define IDE_EMPTY 0
#define IDE_CDROM 1
#define IDE_HD 2
#define IDE_UNKNOWN 3
/* CDROMS and harddisks. */
struct devparams
{
char devnode_disk[30]; // when single partition is addressed
char devnode_part[30]; // when the RAID partition is addressed
char devnode_disk_run[30]; // the same dev but after installation
char devnode_part_run[30];
char modulename[STRING_SIZE];
char options[STRING_SIZE];
// int module;
};
/* ide.c */
int checkide(char letter);
char findidetype(int type);
/* cdrom.c */
int ejectcdrom(char *dev);
/* nic.c */
int networkmenu(struct keyvalue *ethernetkv);
/* net.c */
int checktarball(char *);
/* config.c */
int write_disk_configs(struct devparams *dp);
int write_lang_configs( char *lang);
int write_ethernet_configs(struct keyvalue *ethernetkv);
/* pcmcia.c */
char * initialize_pcmcia (void);
/* upgrade_v12_v13.c */
int upgrade_v12_v13();
/* upgrade_v130_v131.c */
int upgrade_v130_v140();
/* usb.c */
int initialize_usb();
int write_usb_modules_conf();
int checkusb (char *partition);
/* scsi.c */
int try_scsi(char *dev);
int get_boot(char *dev);
/*main.c */
int modprobe (char *mod);
int rmmod (char *mod);
extern char *bz_tr[];
extern char *cs_tr[];
extern char *da_tr[];
extern char *en_tr[];
extern char *es_tr[];
extern char *fi_tr[];
extern char *fr_tr[];
extern char *hu_tr[];
extern char *la_tr[];
extern char *nl_tr[];
extern char *de_tr[];
extern char *tr_tr[];
extern char *it_tr[];
extern char *el_tr[];
extern char *pl_tr[];
extern char *pt_tr[];
extern char *sk_tr[];
extern char *so_tr[];
extern char *sv_tr[];
extern char *no_tr[];
extern char *vi_tr[];

View File

@@ -0,0 +1,424 @@
/* IPCop install2 program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* (c) Franck Bourdonnec, 2006
* Contains update/restore code
*
* $Id: install2.c,v 1.1.2.3 2006/01/31 00:51:50 franck78 Exp $
*
*/
#include "install.h"
FILE *flog = NULL;
char *mylog;
char **ctr;
/*
To include a translated string in the final installer, you must reference
it here with a simplr comment. This save a lot a space in the installer
*/
/* TR_BUILDING_INITRD */
/* TR_HELPLINE */
/* TR_SKIP */
/* TR_RESTORE_CONFIGURATION */
/* TR_RESTORE */
/* TR_OK */
/* TR_CANCEL */
/* TR_ERROR */
/* TR_INSTALLING_FILES */
/* TR_FAILED_TO_FIND */
/* TR_UNABLE_TO_INSTALL_FILES */
/* TR_LOADING_PCMCIA */
//libsmooth
/* TR_INTERFACE */
/* TR_ENTER_THE_IP_ADDRESS_INFORMATION */
/* TR_STATIC */
/* TR_DHCP_HOSTNAME */
/* TR_IP_ADDRESS_PROMPT */
/* TR_NETMASK_PROMPT */
/* TR_INVALID_FIELDS */
/* TR_IP_ADDRESS_CR */
/* TR_NETWORK_MASK_CR */
/* TR_DHCP_HOSTNAME_CR */
/* TR_LOOKING_FOR_NIC */
/* TR_MANUAL */
/* TR_SELECT_NETWORK_DRIVER */
/* TR_SELECT_NETWORK_DRIVER_LONG */
/* TR_UNABLE_TO_LOAD_DRIVER_MODULE */
/* TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED */
/* TR_MODULE_PARAMETERS */
/* TR_LOADING_MODULE */
/* TR_MODULE_NAME_CANNOT_BE_BLANK */
//upgrade 120
/* TR_UNABLE_TO_OPEN_SETTINGS_FILE */
/* TR_DOMAINNAME */
/* TR_ENTER_DOMAINNAME */
/* TR_DOMAINNAME_CANNOT_CONTAIN_SPACES */
/* TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM */
/* TR_UNABLE_TO_WRITE_ETC_FSTAB */
// dir to find files, chrooted or not...
#define TMP_EXTRACT_CH "/tmp/ipcop"
#define TMP_EXTRACT "/harddisk" TMP_EXTRACT_CH
#define MOUNT_BACKUP_CH "/mnt/usb"
#define MOUNT_BACKUP "/harddisk" MOUNT_BACKUP_CH
/*
return 0 when dev contains a backup set
leave dev mounted
*/
int try_mount (char *dev, char *testfile) {
char commandstring[STRING_SIZE];
mysystem("/bin/umount " MOUNT_BACKUP);
sprintf(commandstring, "/bin/mount -t vfat -o ro %s " MOUNT_BACKUP, dev);
mysystem(commandstring);
/*verify it's what we want */
sprintf(commandstring, MOUNT_BACKUP "/%s.dat", testfile);
FILE *handle = fopen(commandstring, "r");
if (handle == NULL) {
return 1; /* bad disk ! */
}
fclose(handle);
handle = fopen(MOUNT_BACKUP "/backup.key", "r");
if (handle == NULL) {
return 1; /* bad disk ! */
}
fclose(handle);
return 0; //success
}
/* try to mount usb device until backup.tgz is found except the
destination device (scsi names are identical with usb key)
check "sda sdb sdc sdd"
*/
int mountbackup (char *testfile, char *destination_device) {
char sourcedev[30];
char i,j;
for (i = 'a'; i < 'e'; i++) {
sprintf (sourcedev,"/dev/sd%c ",i);
if (strcmp (destination_device, sourcedev) != 0) {
if (!try_mount (sourcedev, testfile)) return 0;
}
for (j = '1'; j < '5'; j++) {
sourcedev[8] = j;
if (strcmp (destination_device, sourcedev) != 0) {
if (!try_mount (sourcedev, testfile)) return 0;
}
}
}
return 1;
}
int floppy_locate() {
/* Temporarily mount /proc under /harddisk/proc,
run updfstab to locate the floppy, and unmount /harddisk/proc
again. This should be run each time the user tries to restore
so it can properly detect removable devices */
if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]);
return 1;
}
if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]);
return 1;
}
mysystem("/bin/umount /harddisk/proc");
return 0;
}
/* Check the SQUID acl file exists, if not use our 1.4 copy */
void fixup_squidacl() {
FILE *aclreadfile;
if ((aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) {
unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4");
fclose(aclreadfile);
} else {
rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4",
"/harddisk" CONFIG_ROOT "/proxy/acl");
}
chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99);
}
/* if we detected SCSI then fixup */
void fixup_initrd() {
FILE *handle;
char line[STRING_SIZE];
char commandstring[STRING_SIZE];
if (!(handle = fopen("/scsidriver", "r")))
return;
char *driver;
fgets(line, STRING_SIZE-1, handle);
fclose(handle);
line[strlen(line) - 1] = 0;
driver = strtok(line, ".");
fprintf(flog, "Detected SCSI driver %s\n", driver);
if (!strlen(driver) > 1)
return;
fprintf(flog, "Fixing up ipcoprd.img\n");
mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd"
" --with=scsi_mod --with=%s --with=sd_mod"
" --with=sr_mod --with=libata"
" --with=ataraid /boot/ipcoprd.img "KERNEL_VERSION,
driver );
runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
#ifdef __i386__
sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd"
" --with=scsi_mod --with=%s --with=sd_mod"
" --with=sr_mod --with=libata"
" --with=ataraid /boot/ipcoprd-smp.img "KERNEL_VERSION"-smp",
driver );
runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
#endif
#ifdef __alpha__
runcommandwithstatus("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf", ctr[TR_BUILDING_INITRD]);
#endif
}
/* when backup is ready in tmpdir, move files to definitive location */
void do_copy_files(int upgrade_level) {
mysystem("/bin/chroot /harddisk /bin/cp -af "TMP_EXTRACT_CH"/. /");
/* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
switch (upgrade_level) {
case 1:
upgrade_v12_v13();
upgrade_v130_v140();
case 2: //some 1.4 files format changed
//between 1.4.0 & 1.4.11 If possible de determine backup/version
//the update code should go here
}
}
int main(int argc, char *argv[]) {
#define LANG argv[1]
#define DEST_DEV argv[2]
#define WGET argv[3]
#ifdef LANG_EN_ONLY
char **langtrs[] = { en_tr, NULL };
#else
char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL };
#endif
char message[1000];
char title[STRING_SIZE];
char commandstring[STRING_SIZE];
setlocale (LC_ALL, "");
/* Log file/terminal stuff. */
mylog = "/dev/tty2";
ctr = langtrs[ atoi(LANG) ];
if (!(flog = fopen(mylog, "w+")))
{
printf("Couldn't open log terminal\n");
return 0;
}
fprintf(flog, "Install2 program started.\n");
newtInit();
newtCls();
strcpy (title, NAME " v" VERSION " - " SLOGAN);
newtDrawRootText(14, 0, title);
newtPushHelpLine(ctr[TR_HELPLINE]);
/*
// build now the device node
runcommandwithstatus("echo 'cd /dev; ./make_devices'>/harddisk/X;"
"chroot /harddisk chmod +x /X;"
"chroot /harddisk /X;"
"chroot /harddisk rm /X"
, ctr[TR_INSTALLING_FILES]);
*/
/* working dirs... */
mkdir(MOUNT_BACKUP, S_IRWXU|S_IRWXG|S_IRWXO);
//create the GUI screen and objects
newtComponent form, header, labelfile, labelkey, file, key, radio0, radio1, radio2, radio3, radio4, ok;
newtCenteredWindow (55,20,ctr[TR_RESTORE]);
form = newtForm (NULL, NULL,0);
sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME);
header = newtTextboxReflowed (2,1,message,51,0,0,0);
newtFormAddComponent(form, header);
// The four method of restauration
int start1=1, start2=0, start3=0, start4=0;
radio1 = newtRadiobutton (17, 5, ctr[TR_SKIP], start1, NULL);
radio2 = newtRadiobutton (17, 6, "Floppy (legacy)", start2, radio1);
radio3 = newtRadiobutton (17, 7, "Usb-storage/CDROM", start3, radio2);
if (strcmp(WGET,"none"))
radio4 = newtRadiobutton (17, 8, "HTTP/FTP", start4, radio3);
else
radio4 = NULL;
newtFormAddComponents(form, radio1, radio2, radio3, radio4, NULL);
// The optionnal filename for 'backup'
labelfile=newtTextbox(12, 10, 35, 1, 0);
newtTextboxSetText (labelfile, "Filename");
newtFormAddComponent(form, labelfile);
char *filevalue;
char fileinit[STRING_SIZE] = "backup";
file = newtEntry (17, 11, fileinit, 20, &filevalue, 0);
newtFormAddComponent(form, file);
// The optionnal password for the key
labelkey=newtTextbox(12, 13, 35, 1, 0);
newtTextboxSetText (labelkey, "Backup key password");
newtFormAddComponent(form, labelkey);
char *keyvalue;
char keyinit[STRING_SIZE] = "";
key = newtEntry (17, 14, keyinit, 20, &keyvalue, 0);
newtFormAddComponent(form, key);
// The OK button
ok=newtButton (23, 16, ctr[TR_OK]);
newtFormAddComponent(form, ok);
/* loop until succeeds or user skips out */
int retcode = -1;
while ( retcode<0 ) {
// run the windows
struct newtExitStruct reponse;
newtFormRun (form, &reponse);
radio0 = newtRadioGetCurrent(radio1);
int radio;
radio = radio0 == radio1 ? 1 : radio0 == radio2 ? 2 : radio0 == radio3 ? 3 : radio0 == radio4 ? 4 : 0;
strcpy(keyinit,keyvalue); //reuse actual value
strcpy(fileinit,filevalue);
if (radio==1) {
retcode = 1; // no restore: nothing special
break; // out of the while loop
}
mkdir(TMP_EXTRACT, S_IRWXU|S_IRWXG|S_IRWXO);
statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]);
switch (radio) {
case 4: // network
sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.dat", WGET, filevalue);
mysystem (commandstring);
sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.key", WGET, filevalue);
if (mysystem (commandstring)) {
errorbox(ctr[TR_FAILED_TO_FIND]);
break;
};
goto COMMON;
case 3: // normal backup
if (mountbackup( filevalue, DEST_DEV )) {
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=no device with backup found
break;
};
// link files to a COMMON location
sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.dat " TMP_EXTRACT_CH "/%s.dat", filevalue, filevalue);
mysystem (commandstring);
sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.key " TMP_EXTRACT_CH "/%s.key", filevalue, filevalue);
mysystem (commandstring);
COMMON: // DECRYPT THE TARBALL
// Copy the key to a new location because we decrypt it!
if (strcmp(keyvalue, "")) { // password provided: decrypt the key
sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl enc"
" -a -d -aes256 -salt"
" -pass pass:%s"
" -in " TMP_EXTRACT_CH "/%s.key"
" -out " TMP_EXTRACT_CH "/__tmp.key",
keyvalue, filevalue);
} else { //just copy to new name
sprintf(commandstring, "/bin/chroot /harddisk cp"
" " TMP_EXTRACT_CH "/%s.key"
" " TMP_EXTRACT_CH "/__tmp.key",
filevalue);
}
mysystem (commandstring);
sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl des3"
" -d -salt"
" -in " TMP_EXTRACT_CH "/%s.dat"
" -out " TMP_EXTRACT_CH "/backup.tgz"
" -kfile " TMP_EXTRACT_CH "/__tmp.key",
filevalue);
if (mysystem (commandstring)) {
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=decrypt error:invalid key?
break;
}
strcpy(commandstring, "/bin/chroot /harddisk /bin/tar"
" -X " CONFIG_ROOT "/backup/exclude.system"
" -C " TMP_EXTRACT_CH
" -xzf " TMP_EXTRACT_CH "/backup.tgz");
if (mysystem(commandstring)) {
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
break;
}
sprintf(commandstring, TMP_EXTRACT "/%s.dat", filevalue);
unlink(commandstring ); //dont need them anymore
unlink( TMP_EXTRACT "/backup.tgz");
sprintf(commandstring, TMP_EXTRACT "/%s.key", filevalue);
unlink(commandstring );
unlink( TMP_EXTRACT "/__tmp.key");
/* Now copy to correct location */
do_copy_files(0);
retcode = 0; /* successfully restored */
break;
case 2:
// diskette change
if (floppy_locate()) {
retcode = 2; // this an error!
break;
}
/* Always extract to /tmp/ipcop for temporary extraction
just in case floppy fails.
try a compressed backup first because it's quicker to fail.
In exclude.system, files name must be without leading / or
on extraction, name will never match
*/
sprintf(commandstring,
"/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvzf /dev/floppy > %s 2> /dev/null", mylog);
if (system(commandstring)) {
/* if it's not compressed, try uncompressed first before failing*/
sprintf(commandstring,
"/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvf /dev/floppy > %s 2> /dev/null", mylog);
if (system(commandstring)) {
/* command failed trying to read from floppy */
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
break;
}
}
/* Now copy to correct location */
do_copy_files(1);
retcode = 0; /* successfully restored */
}//switch
/* remove possible badly restored files */
mysystem("/bin/chroot /harddisk /bin/rm -rf " TMP_EXTRACT_CH );
newtPopWindow(); // close windows
}//while
newtFormDestroy(form);
/* cleanup */
mysystem("/bin/umount " MOUNT_BACKUP);
mysystem("/bin/chroot /harddisk /bin/rmdir " MOUNT_BACKUP_CH);
/* others operations moved from install to install2 */
fixup_squidacl();
fixup_initrd();
fprintf(flog, "Install2 program ended.\n");
fflush(flog);
fclose(flog);
newtFinished();
return retcode;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
/* SmoothWall install program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Stuff for downloading the smoothwall tarball using wget.
*
* $Id: net.c,v 1.8.2.2 2004/04/14 22:05:40 gespinasse Exp $
*
*/
#include "install.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
static int got_url = 0;
char url[STRING_SIZE];
static int gettarballurl();
int checktarball(char *file)
{
int done;
int tries = 0;
char commandstring[STRING_SIZE];
done = 0;
while (!done)
{
if (!got_url && gettarballurl() != 1)
return 0;
/* remove any successive /'s */
while (url[strlen(url)-1] == '/') { url[strlen(url)-1] = '\0'; }
snprintf(commandstring, STRING_SIZE, "/bin/wget -s -O /dev/null %s/%s", url, file);
if (!(runcommandwithstatus(commandstring, ctr[TR_CHECKING])))
{
done = 1;
got_url = 1;
}
else
{
errorbox(ctr[TR_FAILED_TO_FIND]);
got_url = 0;
if (tries == 3)
return 0;
}
tries++;
}
return 1;
}
static int gettarballurl()
{
char *values[] = { NULL, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
char title[STRING_SIZE];
char message[1000];
int rc;
sprintf(message, ctr[TR_ENTER_URL]);
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
rc = newtWinEntries(title, message,
60, 5, 5, 50, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
strncpy(url, values[0], STRING_SIZE);
return rc;
}

View File

@@ -0,0 +1,98 @@
/* SmoothWall install program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains stuff related to firing up the network card, including a crude
* autodector.
*
* $Id: nic.c,v 1.8.2.2 2005/12/24 09:08:26 franck78 Exp $
*
*/
#include "install.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern struct nic nics[];
int networkmenu(struct keyvalue *ethernetkv)
{
int rc;
char driver[STRING_SIZE] = "";
char driveroptions[STRING_SIZE] = "";
int result = 0;
char commandstring[STRING_SIZE];
char address[STRING_SIZE], netmask[STRING_SIZE];
int done;
char description[1000];
char message[1000];
char title[STRING_SIZE];
done = 0;
while (!done)
{
rc = newtWinTernary(ctr[TR_CONFIGURE_NETWORKING], ctr[TR_PROBE],
ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_CONFIGURE_NETWORKING_LONG]);
if (rc == 0 || rc == 1)
{
probecards(driver, driveroptions);
if (!strlen(driver))
errorbox(ctr[TR_PROBE_FAILED]);
else
{
findnicdescription(driver, description);
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
sprintf(message, ctr[TR_FOUND_NIC], NAME, description);
newtWinMessage(title, ctr[TR_OK], message);
}
}
else if (rc == 2)
choosecards(driver, driveroptions);
else
done = 1;
if (strlen(driver))
done = 1;
}
if (!strlen(driver))
goto EXIT;
/* Default is a GREEN nic only. */
/* Smoothie is not untarred yet, so we have to delay actually writing the
* settings till later. */
replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0");
replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver);
replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions);
replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver);
if (!(changeaddress(ethernetkv, "GREEN", 0, "")))
goto EXIT;
strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address);
strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask);
snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up",
address, netmask);
if (mysystem(commandstring))
{
errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]);
goto EXIT;
}
result = 1;
EXIT:
return result;
}

View File

@@ -0,0 +1,332 @@
/*
* PCMCIA bridge device probe
*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The initial developer of the original code is David A. Hinds
* <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
* are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
*
* $Id: pcmcia.c,v 1.6.2.4 2005/12/08 02:12:28 franck78 Exp $
*
*/
#include "install.h"
#include "pcmcia.h"
#ifdef __GLIBC__
#include <sys/io.h>
#else
#include <asm/io.h>
#endif
extern FILE *flog;
extern int modprobe(char *);
/*====================================================================*/
typedef struct {
u_short vendor, device;
char *modname;
char *name;
} pci_id_t;
pci_id_t pci_id[] = {
{ 0x1013, 0x1100, "i82365", "Cirrus Logic CL 6729" },
{ 0x1013, 0x1110, "yenta_socket", "Cirrus Logic PD 6832" },
{ 0x10b3, 0xb106, "yenta_socket", "SMC 34C90" },
{ 0x1180, 0x0465, "yenta_socket", "Ricoh RL5C465" },
{ 0x1180, 0x0466, "yenta_socket", "Ricoh RL5C466" },
{ 0x1180, 0x0475, "yenta_socket", "Ricoh RL5C475" },
{ 0x1180, 0x0476, "yenta_socket", "Ricoh RL5C476" },
{ 0x1180, 0x0477, "yenta_socket", "Ricoh RL5C477" },
{ 0x1180, 0x0478, "yenta_socket", "Ricoh RL5C478" },
{ 0x104c, 0xac12, "yenta_socket", "Texas Instruments PCI1130" },
{ 0x104c, 0xac13, "yenta_socket", "Texas Instruments PCI1031" },
{ 0x104c, 0xac15, "yenta_socket", "Texas Instruments PCI1131" },
{ 0x104c, 0xac1a, "yenta_socket", "Texas Instruments PCI1210" },
{ 0x104c, 0xac1e, "yenta_socket", "Texas Instruments PCI1211" },
{ 0x104c, 0xac17, "yenta_socket", "Texas Instruments PCI1220" },
{ 0x104c, 0xac19, "yenta_socket", "Texas Instruments PCI1221" },
{ 0x104c, 0xac1c, "yenta_socket", "Texas Instruments PCI1225" },
{ 0x104c, 0xac16, "yenta_socket", "Texas Instruments PCI1250" },
{ 0x104c, 0xac1d, "yenta_socket", "Texas Instruments PCI1251A" },
{ 0x104c, 0xac1f, "yenta_socket", "Texas Instruments PCI1251B" },
{ 0x104c, 0xac50, "yenta_socket", "Texas Instruments PCI1410" },
{ 0x104c, 0xac51, "yenta_socket", "Texas Instruments PCI1420" },
{ 0x104c, 0xac1b, "yenta_socket", "Texas Instruments PCI1450" },
{ 0x104c, 0xac52, "yenta_socket", "Texas Instruments PCI1451" },
{ 0x104c, 0xac56, "yenta_socket", "Texas Instruments PCI1510" },
{ 0x104c, 0xac55, "yenta_socket", "Texas Instruments PCI1520" },
{ 0x104c, 0xac54, "yenta_socket", "Texas Instruments PCI1620" },
{ 0x104c, 0xac41, "yenta_socket", "Texas Instruments PCI4410" },
{ 0x104c, 0xac40, "yenta_socket", "Texas Instruments PCI4450" },
{ 0x104c, 0xac42, "yenta_socket", "Texas Instruments PCI4451" },
{ 0x104c, 0xac44, "yenta_socket", "Texas Instruments PCI4510" },
{ 0x104c, 0xac46, "yenta_socket", "Texas Instruments PCI4520" },
{ 0x104c, 0xac49, "yenta_socket", "Texas Instruments PCI7410" },
{ 0x104c, 0xac47, "yenta_socket", "Texas Instruments PCI7510" },
{ 0x104c, 0xac48, "yenta_socket", "Texas Instruments PCI7610" },
{ 0x1217, 0x6729, "i82365", "O2 Micro 6729" },
{ 0x1217, 0x673a, "i82365", "O2 Micro 6730" },
{ 0x1217, 0x6832, "yenta_socket", "O2 Micro 6832/6833" },
{ 0x1217, 0x6836, "yenta_socket", "O2 Micro 6836/6860" },
{ 0x1217, 0x6872, "yenta_socket", "O2 Micro 6812" },
{ 0x1217, 0x6925, "yenta_socket", "O2 Micro 6922" },
{ 0x1217, 0x6933, "yenta_socket", "O2 Micro 6933" },
{ 0x1217, 0x6972, "yenta_socket", "O2 Micro 6912" },
{ 0x1179, 0x0603, "i82365", "Toshiba ToPIC95-A" },
{ 0x1179, 0x060a, "yenta_socket", "Toshiba ToPIC95-B" },
{ 0x1179, 0x060f, "yenta_socket", "Toshiba ToPIC97" },
{ 0x1179, 0x0617, "yenta_socket", "Toshiba ToPIC100" },
{ 0x119b, 0x1221, "i82365", "Omega Micro 82C092G" },
{ 0x8086, 0x1221, "i82092", "Intel 82092AA_0" },
{ 0x8086, 0x1222, "i82092", "Intel 82092AA_1" },
{ 0x1524, 0x1211, "yenta_socket", "ENE 1211" },
{ 0x1524, 0x1225, "yenta_socket", "ENE 1225" },
{ 0x1524, 0x1410, "yenta_socket", "ENE 1410" },
{ 0x1524, 0x1420, "yenta_socket", "ENE 1420" },
};
#define PCI_COUNT (sizeof(pci_id)/sizeof(pci_id_t))
static char * pci_probe()
{
char s[256], *modname = NULL;
u_int device, vendor, i;
FILE *f;
if ((f = fopen("/proc/bus/pci/devices", "r")) != NULL) {
while (fgets(s, 256, f) != NULL) {
u_int n = strtoul(s+5, NULL, 16);
vendor = (n >> 16); device = (n & 0xffff);
for (i = 0; i < PCI_COUNT; i++)
if ((vendor == pci_id[i].vendor) &&
(device == pci_id[i].device)) break;
if (i < PCI_COUNT) {
modname = pci_id[i].modname;
break;
}
}
}
return modname;
}
/*====================================================================*/
#ifndef __alpha__
typedef u_short ioaddr_t;
static ioaddr_t i365_base = 0x03e0;
static u_char i365_get(u_short sock, u_short reg)
{
u_char val = I365_REG(sock, reg);
outb(val, i365_base); val = inb(i365_base+1);
return val;
}
#if 0 // the following code do nothing usefull, it ends with return 0 anyway
static void i365_set(u_short sock, u_short reg, u_char data)
{
u_char val = I365_REG(sock, reg);
outb(val, i365_base); outb(data, i365_base+1);
}
static void i365_bset(u_short sock, u_short reg, u_char mask)
{
u_char d = i365_get(sock, reg);
d |= mask;
i365_set(sock, reg, d);
}
static void i365_bclr(u_short sock, u_short reg, u_char mask)
{
u_char d = i365_get(sock, reg);
d &= ~mask;
i365_set(sock, reg, d);
}
#endif
int i365_probe()
{
int val, slot, sock, done;
// char *name = "i82365sl";
ioperm(i365_base, 4, 1);
ioperm(0x80, 1, 1);
for (slot = 0; slot < 2; slot++) {
for (sock = done = 0; sock < 2; sock++) {
val = i365_get(sock, I365_IDENT);
switch (val) {
case 0x82:
// name = "i82365sl A step";
// break;
case 0x83:
// name = "i82365sl B step";
// break;
case 0x84:
// name = "VLSI 82C146";
// break;
case 0x88: case 0x89: case 0x8a:
// name = "IBM Clone";
// break;
case 0x8b: case 0x8c:
break;
default:
done = 1;
}
if (done) break;
}
if (done && sock) break;
i365_base += 2;
}
if (sock == 0) {
return -1;
}
#if 0 // the following code do nothing usefull, it ends with return 0 anyway
if ((sock == 2) && (strcmp(name, "VLSI 82C146") == 0))
name = "i82365sl DF";
/* Check for Vadem chips */
outb(0x0e, i365_base);
outb(0x37, i365_base);
i365_bset(0, VG468_MISC, VG468_MISC_VADEMREV);
val = i365_get(0, I365_IDENT);
if (val & I365_IDENT_VADEM) {
if ((val & 7) < 4)
name = "Vadem VG-468";
else
name = "Vadem VG-469";
i365_bclr(0, VG468_MISC, VG468_MISC_VADEMREV);
}
/* Check for Cirrus CL-PD67xx chips */
i365_set(0, PD67_CHIP_INFO, 0);
val = i365_get(0, PD67_CHIP_INFO);
if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) {
val = i365_get(0, PD67_CHIP_INFO);
if ((val & PD67_INFO_CHIP_ID) == 0) {
if (val & PD67_INFO_SLOTS)
name = "Cirrus CL-PD672x";
else {
name = "Cirrus CL-PD6710";
sock = 1;
}
i365_set(0, PD67_EXT_INDEX, 0xe5);
if (i365_get(0, PD67_EXT_INDEX) != 0xe5)
name = "VIA VT83C469";
}
}
#endif
return 0;
} /* i365_probe */
#endif
/*====================================================================*/
#ifndef __alpha__
static u_short tcic_getw(ioaddr_t base, u_char reg)
{
u_short val = inw(base+reg);
return val;
}
static void tcic_setw(ioaddr_t base, u_char reg, u_short data)
{
outw(data, base+reg);
}
int tcic_probe_at(ioaddr_t base)
{
int i;
u_short old;
/* Anything there?? */
for (i = 0; i < 0x10; i += 2)
if (tcic_getw(base, i) == 0xffff)
return -1;
/* Try to reset the chip */
tcic_setw(base, TCIC_SCTRL, TCIC_SCTRL_RESET);
tcic_setw(base, TCIC_SCTRL, 0);
/* Can we set the addr register? */
old = tcic_getw(base, TCIC_ADDR);
tcic_setw(base, TCIC_ADDR, 0);
if (tcic_getw(base, TCIC_ADDR) != 0) {
tcic_setw(base, TCIC_ADDR, old);
return -2;
}
tcic_setw(base, TCIC_ADDR, 0xc3a5);
if (tcic_getw(base, TCIC_ADDR) != 0xc3a5)
return -3;
return 2;
}
int tcic_probe(ioaddr_t base)
{
int sock;
ioperm(base, 16, 1);
ioperm(0x80, 1, 1);
sock = tcic_probe_at(base);
if (sock <= 0) {
return -1;
}
return 0;
} /* tcic_probe */
#endif
/*====================================================================*/
char * initialize_pcmcia (void)
{
#ifndef __alpha__
ioaddr_t tcic_base = TCIC_BASE;
#endif
char* pcmcia;
if ((pcmcia = pci_probe()))
return pcmcia; /* we're all done */
#ifndef __alpha__
else if (i365_probe() == 0)
return "i82365";
else if (tcic_probe(tcic_base) == 0)
return "tcic";
#endif
else {
/* Detect ISAPNP based i82365 controllers */
FILE *f;
modprobe("i82365");
if ((f = fopen("/proc/bus/pccard/00/info", "r"))) {
fclose(f);
return "i82365";
}
}
return NULL;
}

View File

@@ -0,0 +1,614 @@
/*
* PCMCIA bridge device probe
*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The initial developer of the original code is David A. Hinds
* <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
* are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
*
* $Id: pcmcia.h,v 1.1 2004/01/25 09:34:59 riddles Exp $
*
*/
#define TCIC_BASE 0x240
/* offsets of registers from TCIC_BASE */
#define TCIC_DATA 0x00
#define TCIC_ADDR 0x02
#define TCIC_SCTRL 0x06
#define TCIC_SSTAT 0x07
#define TCIC_MODE 0x08
#define TCIC_PWR 0x09
#define TCIC_EDC 0x0A
#define TCIC_ICSR 0x0C
#define TCIC_IENA 0x0D
#define TCIC_AUX 0x0E
#define TCIC_SS_SHFT 12
#define TCIC_SS_MASK 0x7000
/* Flags for TCIC_ADDR */
#define TCIC_ADR2_REG 0x8000
#define TCIC_ADR2_INDREG 0x0800
#define TCIC_ADDR_REG 0x80000000
#define TCIC_ADDR_SS_SHFT (TCIC_SS_SHFT+16)
#define TCIC_ADDR_SS_MASK (TCIC_SS_MASK<<16)
#define TCIC_ADDR_INDREG 0x08000000
#define TCIC_ADDR_IO 0x04000000
#define TCIC_ADDR_MASK 0x03ffffff
/* Flags for TCIC_SCTRL */
#define TCIC_SCTRL_ENA 0x01
#define TCIC_SCTRL_INCMODE 0x18
#define TCIC_SCTRL_INCMODE_HOLD 0x00
#define TCIC_SCTRL_INCMODE_WORD 0x08
#define TCIC_SCTRL_INCMODE_REG 0x10
#define TCIC_SCTRL_INCMODE_AUTO 0x18
#define TCIC_SCTRL_EDCSUM 0x20
#define TCIC_SCTRL_RESET 0x80
/* Flags for TCIC_SSTAT */
#define TCIC_SSTAT_6US 0x01
#define TCIC_SSTAT_10US 0x02
#define TCIC_SSTAT_PROGTIME 0x04
#define TCIC_SSTAT_LBAT1 0x08
#define TCIC_SSTAT_LBAT2 0x10
#define TCIC_SSTAT_RDY 0x20 /* Inverted */
#define TCIC_SSTAT_WP 0x40
#define TCIC_SSTAT_CD 0x80 /* Card detect */
/* Flags for TCIC_MODE */
#define TCIC_MODE_PGMMASK 0x1f
#define TCIC_MODE_NORMAL 0x00
#define TCIC_MODE_PGMWR 0x01
#define TCIC_MODE_PGMRD 0x02
#define TCIC_MODE_PGMCE 0x04
#define TCIC_MODE_PGMDBW 0x08
#define TCIC_MODE_PGMWORD 0x10
#define TCIC_MODE_AUXSEL_MASK 0xe0
/* Registers accessed through TCIC_AUX, by setting TCIC_MODE */
#define TCIC_AUX_TCTL (0<<5)
#define TCIC_AUX_PCTL (1<<5)
#define TCIC_AUX_WCTL (2<<5)
#define TCIC_AUX_EXTERN (3<<5)
#define TCIC_AUX_PDATA (4<<5)
#define TCIC_AUX_SYSCFG (5<<5)
#define TCIC_AUX_ILOCK (6<<5)
#define TCIC_AUX_TEST (7<<5)
/* Flags for TCIC_PWR */
#define TCIC_PWR_VCC(sock) (0x01<<(sock))
#define TCIC_PWR_VCC_MASK 0x03
#define TCIC_PWR_VPP(sock) (0x08<<(sock))
#define TCIC_PWR_VPP_MASK 0x18
#define TCIC_PWR_CLIMENA 0x40
#define TCIC_PWR_CLIMSTAT 0x80
/* Flags for TCIC_ICSR */
#define TCIC_ICSR_CLEAR 0x01
#define TCIC_ICSR_SET 0x02
#define TCIC_ICSR_JAM (TCIC_ICSR_CLEAR|TCIC_ICSR_SET)
#define TCIC_ICSR_STOPCPU 0x04
#define TCIC_ICSR_ILOCK 0x08
#define TCIC_ICSR_PROGTIME 0x10
#define TCIC_ICSR_ERR 0x20
#define TCIC_ICSR_CDCHG 0x40
#define TCIC_ICSR_IOCHK 0x80
/* Flags for TCIC_IENA */
#define TCIC_IENA_CFG_MASK 0x03
#define TCIC_IENA_CFG_OFF 0x00 /* disabled */
#define TCIC_IENA_CFG_OD 0x01 /* active low, open drain */
#define TCIC_IENA_CFG_LOW 0x02 /* active low, totem pole */
#define TCIC_IENA_CFG_HIGH 0x03 /* active high, totem pole */
#define TCIC_IENA_ILOCK 0x08
#define TCIC_IENA_PROGTIME 0x10
#define TCIC_IENA_ERR 0x20 /* overcurrent or iochk */
#define TCIC_IENA_CDCHG 0x40
/* Flags for TCIC_AUX_WCTL */
#define TCIC_WAIT_COUNT_MASK 0x001f
#define TCIC_WAIT_ASYNC 0x0020
#define TCIC_WAIT_SENSE 0x0040
#define TCIC_WAIT_SRC 0x0080
#define TCIC_WCTL_WR 0x0100
#define TCIC_WCTL_RD 0x0200
#define TCIC_WCTL_CE 0x0400
#define TCIC_WCTL_LLBAT1 0x0800
#define TCIC_WCTL_LLBAT2 0x1000
#define TCIC_WCTL_LRDY 0x2000
#define TCIC_WCTL_LWP 0x4000
#define TCIC_WCTL_LCD 0x8000
/* Flags for TCIC_AUX_SYSCFG */
#define TCIC_SYSCFG_IRQ_MASK 0x000f
#define TCIC_SYSCFG_MCSFULL 0x0010
#define TCIC_SYSCFG_IO1723 0x0020
#define TCIC_SYSCFG_MCSXB 0x0040
#define TCIC_SYSCFG_ICSXB 0x0080
#define TCIC_SYSCFG_NOPDN 0x0100
#define TCIC_SYSCFG_MPSEL_SHFT 9
#define TCIC_SYSCFG_MPSEL_MASK 0x0e00
#define TCIC_SYSCFG_MPSENSE 0x2000
#define TCIC_SYSCFG_AUTOBUSY 0x4000
#define TCIC_SYSCFG_ACC 0x8000
#define TCIC_ILOCK_OUT 0x01
#define TCIC_ILOCK_SENSE 0x02
#define TCIC_ILOCK_CRESET 0x04
#define TCIC_ILOCK_CRESENA 0x08
#define TCIC_ILOCK_CWAIT 0x10
#define TCIC_ILOCK_CWAITSNS 0x20
#define TCIC_ILOCK_HOLD_MASK 0xc0
#define TCIC_ILOCK_HOLD_CCLK 0xc0
#define TCIC_ILOCKTEST_ID_SH 8
#define TCIC_ILOCKTEST_ID_MASK 0x7f00
#define TCIC_ILOCKTEST_MCIC_1 0x8000
#define TCIC_ID_DB86082 0x02
#define TCIC_ID_DB86082A 0x03
#define TCIC_ID_DB86084 0x04
#define TCIC_ID_DB86084A 0x08
#define TCIC_ID_DB86072 0x15
#define TCIC_ID_DB86184 0x14
#define TCIC_ID_DB86082B 0x17
#define TCIC_TEST_DIAG 0x8000
/*
* Indirectly addressed registers
*/
#define TCIC_SCF1(sock) ((sock)<<3)
#define TCIC_SCF2(sock) (((sock)<<3)+2)
/* Flags for SCF1 */
#define TCIC_SCF1_IRQ_MASK 0x000f
#define TCIC_SCF1_IRQ_OFF 0x0000
#define TCIC_SCF1_IRQOC 0x0010
#define TCIC_SCF1_PCVT 0x0020
#define TCIC_SCF1_IRDY 0x0040
#define TCIC_SCF1_ATA 0x0080
#define TCIC_SCF1_DMA_SHIFT 8
#define TCIC_SCF1_DMA_MASK 0x0700
#define TCIC_SCF1_DMA_OFF 0
#define TCIC_SCF1_DREQ2 2
#define TCIC_SCF1_IOSTS 0x0800
#define TCIC_SCF1_SPKR 0x1000
#define TCIC_SCF1_FINPACK 0x2000
#define TCIC_SCF1_DELWR 0x4000
#define TCIC_SCF1_HD7IDE 0x8000
/* Flags for SCF2 */
#define TCIC_SCF2_RI 0x0001
#define TCIC_SCF2_IDBR 0x0002
#define TCIC_SCF2_MDBR 0x0004
#define TCIC_SCF2_MLBAT1 0x0008
#define TCIC_SCF2_MLBAT2 0x0010
#define TCIC_SCF2_MRDY 0x0020
#define TCIC_SCF2_MWP 0x0040
#define TCIC_SCF2_MCD 0x0080
#define TCIC_SCF2_MALL 0x00f8
/* Indirect addresses for memory window registers */
#define TCIC_MWIN(sock,map) (0x100+(((map)+((sock)<<2))<<3))
#define TCIC_MBASE_X 2
#define TCIC_MMAP_X 4
#define TCIC_MCTL_X 6
#define TCIC_MBASE_4K_BIT 0x4000
#define TCIC_MBASE_HA_SHFT 12
#define TCIC_MBASE_HA_MASK 0x0fff
#define TCIC_MMAP_REG 0x8000
#define TCIC_MMAP_CA_SHFT 12
#define TCIC_MMAP_CA_MASK 0x3fff
#define TCIC_MCTL_WSCNT_MASK 0x001f
#define TCIC_MCTL_WCLK 0x0020
#define TCIC_MCTL_WCLK_CCLK 0x0000
#define TCIC_MCTL_WCLK_BCLK 0x0020
#define TCIC_MCTL_QUIET 0x0040
#define TCIC_MCTL_WP 0x0080
#define TCIC_MCTL_ACC 0x0100
#define TCIC_MCTL_KE 0x0200
#define TCIC_MCTL_EDC 0x0400
#define TCIC_MCTL_B8 0x0800
#define TCIC_MCTL_SS_SHFT TCIC_SS_SHFT
#define TCIC_MCTL_SS_MASK TCIC_SS_MASK
#define TCIC_MCTL_ENA 0x8000
/* Indirect addresses for I/O window registers */
#define TCIC_IWIN(sock,map) (0x200+(((map)+((sock)<<1))<<2))
#define TCIC_IBASE_X 0
#define TCIC_ICTL_X 2
#define TCIC_ICTL_WSCNT_MASK TCIC_MCTL_WSCNT_MASK
#define TCIC_ICTL_QUIET TCIC_MCTL_QUIET
#define TCIC_ICTL_1K 0x0080
#define TCIC_ICTL_PASS16 0x0100
#define TCIC_ICTL_ACC TCIC_MCTL_ACC
#define TCIC_ICTL_TINY 0x0200
#define TCIC_ICTL_B16 0x0400
#define TCIC_ICTL_B8 TCIC_MCTL_B8
#define TCIC_ICTL_BW_MASK (TCIC_ICTL_B16|TCIC_ICTL_B8)
#define TCIC_ICTL_BW_DYN 0
#define TCIC_ICTL_BW_8 TCIC_ICTL_B8
#define TCIC_ICTL_BW_16 TCIC_ICTL_B16
#define TCIC_ICTL_BW_ATA (TCIC_ICTL_B16|TCIC_ICTL_B8)
#define TCIC_ICTL_SS_SHFT TCIC_SS_SHFT
#define TCIC_ICTL_SS_MASK TCIC_SS_MASK
#define TCIC_ICTL_ENA TCIC_MCTL_ENA
/* register definitions for the Intel 82365SL PCMCIA controller */
/* Offsets for PCIC registers */
#define I365_IDENT 0x00 /* Identification and revision */
#define I365_STATUS 0x01 /* Interface status */
#define I365_POWER 0x02 /* Power and RESETDRV control */
#define I365_INTCTL 0x03 /* Interrupt and general control */
#define I365_CSC 0x04 /* Card status change */
#define I365_CSCINT 0x05 /* Card status change interrupt control */
#define I365_ADDRWIN 0x06 /* Address window enable */
#define I365_IOCTL 0x07 /* I/O control */
#define I365_GENCTL 0x16 /* Card detect and general control */
#define I365_GBLCTL 0x1E /* Global control register */
/* Offsets for I/O and memory window registers */
#define I365_IO(map) (0x08+((map)<<2))
#define I365_MEM(map) (0x10+((map)<<3))
#define I365_W_START 0
#define I365_W_STOP 2
#define I365_W_OFF 4
/* Flags for I365_STATUS */
#define I365_CS_BVD1 0x01
#define I365_CS_STSCHG 0x01
#define I365_CS_BVD2 0x02
#define I365_CS_SPKR 0x02
#define I365_CS_DETECT 0x0C
#define I365_CS_WRPROT 0x10
#define I365_CS_READY 0x20 /* Inverted */
#define I365_CS_POWERON 0x40
#define I365_CS_GPI 0x80
/* Flags for I365_POWER */
#define I365_PWR_OFF 0x00 /* Turn off the socket */
#define I365_PWR_OUT 0x80 /* Output enable */
#define I365_PWR_NORESET 0x40 /* Disable RESETDRV on resume */
#define I365_PWR_AUTO 0x20 /* Auto pwr switch enable */
#define I365_VCC_MASK 0x18 /* Mask for turning off Vcc */
/* There are different layouts for B-step and DF-step chips: the B
step has independent Vpp1/Vpp2 control, and the DF step has only
Vpp1 control, plus 3V control */
#define I365_VCC_5V 0x10 /* Vcc = 5.0v */
#define I365_VCC_3V 0x18 /* Vcc = 3.3v */
#define I365_VPP2_MASK 0x0c /* Mask for turning off Vpp2 */
#define I365_VPP2_5V 0x04 /* Vpp2 = 5.0v */
#define I365_VPP2_12V 0x08 /* Vpp2 = 12.0v */
#define I365_VPP1_MASK 0x03 /* Mask for turning off Vpp1 */
#define I365_VPP1_5V 0x01 /* Vpp2 = 5.0v */
#define I365_VPP1_12V 0x02 /* Vpp2 = 12.0v */
/* Flags for I365_INTCTL */
#define I365_RING_ENA 0x80
#define I365_PC_RESET 0x40
#define I365_PC_IOCARD 0x20
#define I365_INTR_ENA 0x10
#define I365_IRQ_MASK 0x0F
/* Flags for I365_CSC and I365_CSCINT*/
#define I365_CSC_BVD1 0x01
#define I365_CSC_STSCHG 0x01
#define I365_CSC_BVD2 0x02
#define I365_CSC_READY 0x04
#define I365_CSC_DETECT 0x08
#define I365_CSC_ANY 0x0F
#define I365_CSC_GPI 0x10
/* Flags for I365_ADDRWIN */
#define I365_ADDR_MEMCS16 0x20
#define I365_ENA_IO(map) (0x40 << (map))
#define I365_ENA_MEM(map) (0x01 << (map))
/* Flags for I365_IOCTL */
#define I365_IOCTL_MASK(map) (0x0F << (map<<2))
#define I365_IOCTL_WAIT(map) (0x08 << (map<<2))
#define I365_IOCTL_0WS(map) (0x04 << (map<<2))
#define I365_IOCTL_IOCS16(map) (0x02 << (map<<2))
#define I365_IOCTL_16BIT(map) (0x01 << (map<<2))
/* Flags for I365_GENCTL */
#define I365_CTL_16DELAY 0x01
#define I365_CTL_RESET 0x02
#define I365_CTL_GPI_ENA 0x04
#define I365_CTL_GPI_CTL 0x08
#define I365_CTL_RESUME 0x10
#define I365_CTL_SW_IRQ 0x20
/* Flags for I365_GBLCTL */
#define I365_GBL_PWRDOWN 0x01
#define I365_GBL_CSC_LEV 0x02
#define I365_GBL_WRBACK 0x04
#define I365_GBL_IRQ_0_LEV 0x08
#define I365_GBL_IRQ_1_LEV 0x10
/* Flags for memory window registers */
#define I365_MEM_16BIT 0x8000 /* In memory start high byte */
#define I365_MEM_0WS 0x4000
#define I365_MEM_WS1 0x8000 /* In memory stop high byte */
#define I365_MEM_WS0 0x4000
#define I365_MEM_WRPROT 0x8000 /* In offset high byte */
#define I365_MEM_REG 0x4000
#define I365_REG(slot, reg) (((slot) << 6) | (reg))
/* Default ISA interrupt mask */
#define I365_ISA_IRQ_MASK 0xdeb8 /* irq's 3-5,7,9-12,14,15 */
/* Device ID's for PCI-to-PCMCIA bridges */
#ifndef PCI_VENDOR_ID_INTEL
#define PCI_VENDOR_ID_INTEL 0x8086
#endif
#ifndef PCI_DEVICE_ID_INTEL_82092AA_0
#define PCI_DEVICE_ID_INTEL_82092AA_0 0x1221
#endif
#ifndef PCI_VENDOR_ID_OMEGA
#define PCI_VENDOR_ID_OMEGA 0x119b
#endif
#ifndef PCI_DEVICE_ID_OMEGA_82C092G
#define PCI_DEVICE_ID_OMEGA_82C092G 0x1221
#endif
#ifndef PCI_VENDOR_ID_CIRRUS
#define PCI_VENDOR_ID_CIRRUS 0x1013
#endif
#ifndef PCI_DEVICE_ID_CIRRUS_6729
#define PCI_DEVICE_ID_CIRRUS_6729 0x1100
#endif
#ifndef PCI_DEVICE_ID_CIRRUS_6832
#define PCI_DEVICE_ID_CIRRUS_6832 0x1110
#endif
#define PD67_MISC_CTL_1 0x16 /* Misc control 1 */
#define PD67_FIFO_CTL 0x17 /* FIFO control */
#define PD67_MISC_CTL_2 0x1E /* Misc control 2 */
#define PD67_CHIP_INFO 0x1f /* Chip information */
#define PD67_ATA_CTL 0x026 /* 6730: ATA control */
#define PD67_EXT_INDEX 0x2e /* Extension index */
#define PD67_EXT_DATA 0x2f /* Extension data */
#define pd67_ext_get(s, r) \
(i365_set(s, PD67_EXT_INDEX, r), i365_get(s, PD67_EXT_DATA))
#define pd67_ext_set(s, r, v) \
(i365_set(s, PD67_EXT_INDEX, r), i365_set(s, PD67_EXT_DATA, v))
/* PD6722 extension registers -- indexed in PD67_EXT_INDEX */
#define PD67_DATA_MASK0 0x01 /* Data mask 0 */
#define PD67_DATA_MASK1 0x02 /* Data mask 1 */
#define PD67_DMA_CTL 0x03 /* DMA control */
/* PD6730 extension registers -- indexed in PD67_EXT_INDEX */
#define PD67_EXT_CTL_1 0x03 /* Extension control 1 */
#define PD67_MEM_PAGE(n) ((n)+5) /* PCI window bits 31:24 */
#define PD67_EXTERN_DATA 0x0a
#define PD67_EXT_CTL_2 0x0b
#define PD67_MISC_CTL_3 0x25
#define PD67_SMB_PWR_CTL 0x26
/* I/O window address offset */
#define PD67_IO_OFF(w) (0x36+((w)<<1))
/* Timing register sets */
#define PD67_TIME_SETUP(n) (0x3a + 3*(n))
#define PD67_TIME_CMD(n) (0x3b + 3*(n))
#define PD67_TIME_RECOV(n) (0x3c + 3*(n))
/* Flags for PD67_MISC_CTL_1 */
#define PD67_MC1_5V_DET 0x01 /* 5v detect */
#define PD67_MC1_MEDIA_ENA 0x01 /* 6730: Multimedia enable */
#define PD67_MC1_VCC_3V 0x02 /* 3.3v Vcc */
#define PD67_MC1_PULSE_MGMT 0x04
#define PD67_MC1_PULSE_IRQ 0x08
#define PD67_MC1_SPKR_ENA 0x10
#define PD67_MC1_INPACK_ENA 0x80
/* Flags for PD67_FIFO_CTL */
#define PD67_FIFO_EMPTY 0x80
/* Flags for PD67_MISC_CTL_2 */
#define PD67_MC2_FREQ_BYPASS 0x01
#define PD67_MC2_DYNAMIC_MODE 0x02
#define PD67_MC2_SUSPEND 0x04
#define PD67_MC2_5V_CORE 0x08
#define PD67_MC2_LED_ENA 0x10 /* IRQ 12 is LED enable */
#define PD67_MC2_FAST_PCI 0x10 /* 6729: PCI bus > 25 MHz */
#define PD67_MC2_3STATE_BIT7 0x20 /* Floppy change bit */
#define PD67_MC2_DMA_MODE 0x40
#define PD67_MC2_IRQ15_RI 0x80 /* IRQ 15 is ring enable */
/* Flags for PD67_CHIP_INFO */
#define PD67_INFO_SLOTS 0x20 /* 0 = 1 slot, 1 = 2 slots */
#define PD67_INFO_CHIP_ID 0xc0
#define PD67_INFO_REV 0x1c
/* Fields in PD67_TIME_* registers */
#define PD67_TIME_SCALE 0xc0
#define PD67_TIME_SCALE_1 0x00
#define PD67_TIME_SCALE_16 0x40
#define PD67_TIME_SCALE_256 0x80
#define PD67_TIME_SCALE_4096 0xc0
#define PD67_TIME_MULT 0x3f
/* Fields in PD67_DMA_CTL */
#define PD67_DMA_MODE 0xc0
#define PD67_DMA_OFF 0x00
#define PD67_DMA_DREQ_INPACK 0x40
#define PD67_DMA_DREQ_WP 0x80
#define PD67_DMA_DREQ_BVD2 0xc0
#define PD67_DMA_PULLUP 0x20 /* Disable socket pullups? */
/* Fields in PD67_EXT_CTL_1 */
#define PD67_EC1_VCC_PWR_LOCK 0x01
#define PD67_EC1_AUTO_PWR_CLEAR 0x02
#define PD67_EC1_LED_ENA 0x04
#define PD67_EC1_INV_CARD_IRQ 0x08
#define PD67_EC1_INV_MGMT_IRQ 0x10
#define PD67_EC1_PULLUP_CTL 0x20
/* Fields in PD67_EXTERN_DATA */
#define PD67_EXD_VS1(s) (0x01 << ((s)<<1))
#define PD67_EXD_VS2(s) (0x02 << ((s)<<1))
/* Fields in PD67_EXT_CTL_2 */
#define PD67_EC2_GPSTB_TOTEM 0x04
#define PD67_EC2_GPSTB_IOR 0x08
#define PD67_EC2_GPSTB_IOW 0x10
#define PD67_EC2_GPSTB_HIGH 0x20
/* Fields in PD67_MISC_CTL_3 */
#define PD67_MC3_IRQ_MASK 0x03
#define PD67_MC3_IRQ_PCPCI 0x00
#define PD67_MC3_IRQ_EXTERN 0x01
#define PD67_MC3_IRQ_PCIWAY 0x02
#define PD67_MC3_IRQ_PCI 0x03
#define PD67_MC3_PWR_MASK 0x0c
#define PD67_MC3_PWR_SERIAL 0x00
#define PD67_MC3_PWR_TI2202 0x08
#define PD67_MC3_PWR_SMB 0x0c
/* Register definitions for Cirrus PD6832 PCI-to-CardBus bridge */
/* PD6832 extension registers -- indexed in PD67_EXT_INDEX */
#define PD68_PCI_SPACE 0x22
#define PD68_PCCARD_SPACE 0x23
#define PD68_WINDOW_TYPE 0x24
#define PD68_EXT_CSC 0x2e
#define PD68_MISC_CTL_4 0x2f
#define PD68_MISC_CTL_5 0x30
#define PD68_MISC_CTL_6 0x31
/* Extra flags in PD67_MISC_CTL_3 */
#define PD68_MC3_HW_SUSP 0x10
#define PD68_MC3_MM_EXPAND 0x40
#define PD68_MC3_MM_ARM 0x80
/* Bridge Control Register */
#define PD6832_BCR_MGMT_IRQ_ENA 0x0800
/* Socket Number Register */
#define PD6832_SOCKET_NUMBER 0x004c /* 8 bit */
/* Data structure for tracking vendor-specific state */
typedef struct cirrus_state_t {
u_char misc1; /* PD67_MISC_CTL_1 */
u_char misc2; /* PD67_MISC_CTL_2 */
u_char ectl1; /* PD67_EXT_CTL_1 */
u_char timer[6]; /* PD67_TIME_* */
} cirrus_state_t;
#define CIRRUS_PCIC_ID \
IS_PD6729, IS_PD6730, IS_PD6832
#define CIRRUS_PCIC_INFO \
{ "Cirrus PD6729", IS_CIRRUS|IS_PCI, ID(CIRRUS, 6729) }, \
{ "Cirrus PD6730", IS_CIRRUS|IS_PCI, PCI_VENDOR_ID_CIRRUS, -1 }, \
{ "Cirrus PD6832", IS_CIRRUS|IS_CARDBUS, ID(CIRRUS, 6832) }
/* Special bit in I365_IDENT used for Vadem chip detection */
#define I365_IDENT_VADEM 0x08
/* Special definitions in I365_POWER */
#define VG468_VPP2_MASK 0x0c
#define VG468_VPP2_5V 0x04
#define VG468_VPP2_12V 0x08
/* Unique Vadem registers */
#define VG469_VSENSE 0x1f /* Card voltage sense */
#define VG469_VSELECT 0x2f /* Card voltage select */
#define VG468_CTL 0x38 /* Control register */
#define VG468_TIMER 0x39 /* Timer control */
#define VG468_MISC 0x3a /* Miscellaneous */
#define VG468_GPIO_CFG 0x3b /* GPIO configuration */
#define VG469_EXT_MODE 0x3c /* Extended mode register */
#define VG468_SELECT 0x3d /* Programmable chip select */
#define VG468_SELECT_CFG 0x3e /* Chip select configuration */
#define VG468_ATA 0x3f /* ATA control */
/* Flags for VG469_VSENSE */
#define VG469_VSENSE_A_VS1 0x01
#define VG469_VSENSE_A_VS2 0x02
#define VG469_VSENSE_B_VS1 0x04
#define VG469_VSENSE_B_VS2 0x08
/* Flags for VG469_VSELECT */
#define VG469_VSEL_VCC 0x03
#define VG469_VSEL_5V 0x00
#define VG469_VSEL_3V 0x03
#define VG469_VSEL_MAX 0x0c
#define VG469_VSEL_EXT_STAT 0x10
#define VG469_VSEL_EXT_BUS 0x20
#define VG469_VSEL_MIXED 0x40
#define VG469_VSEL_ISA 0x80
/* Flags for VG468_CTL */
#define VG468_CTL_SLOW 0x01 /* 600ns memory timing */
#define VG468_CTL_ASYNC 0x02 /* Asynchronous bus clocking */
#define VG468_CTL_TSSI 0x08 /* Tri-state some outputs */
#define VG468_CTL_DELAY 0x10 /* Card detect debounce */
#define VG468_CTL_INPACK 0x20 /* Obey INPACK signal? */
#define VG468_CTL_POLARITY 0x40 /* VCCEN polarity */
#define VG468_CTL_COMPAT 0x80 /* Compatibility stuff */
#define VG469_CTL_WS_COMPAT 0x04 /* Wait state compatibility */
#define VG469_CTL_STRETCH 0x10 /* LED stretch */
/* Flags for VG468_TIMER */
#define VG468_TIMER_ZEROPWR 0x10 /* Zero power control */
#define VG468_TIMER_SIGEN 0x20 /* Power up */
#define VG468_TIMER_STATUS 0x40 /* Activity timer status */
#define VG468_TIMER_RES 0x80 /* Timer resolution */
#define VG468_TIMER_MASK 0x0f /* Activity timer timeout */
/* Flags for VG468_MISC */
#define VG468_MISC_GPIO 0x04 /* General-purpose IO */
#define VG468_MISC_DMAWSB 0x08 /* DMA wait state control */
#define VG469_MISC_LEDENA 0x10 /* LED enable */
#define VG468_MISC_VADEMREV 0x40 /* Vadem revision control */
#define VG468_MISC_UNLOCK 0x80 /* Unique register lock */
/* Flags for VG469_EXT_MODE_A */
#define VG469_MODE_VPPST 0x03 /* Vpp steering control */
#define VG469_MODE_INT_SENSE 0x04 /* Internal voltage sense */
#define VG469_MODE_CABLE 0x08
#define VG469_MODE_COMPAT 0x10 /* i82365sl B or DF step */
#define VG469_MODE_TEST 0x20
#define VG469_MODE_RIO 0x40 /* Steer RIO to INTR? */
/* Flags for VG469_EXT_MODE_B */
#define VG469_MODE_B_3V 0x01 /* 3.3v for socket B */
/* Data structure for tracking vendor-specific state */
typedef struct vg46x_state_t {
u_char ctl; /* VG468_CTL */
u_char ema; /* VG468_EXT_MODE_A */
} vg46x_state_t;

View File

@@ -0,0 +1,64 @@
#!/bin/sh
OLDDIR=`pwd`
cd /lib/modules/*/kernel/drivers/scsi
/bin/modprobe scsi_mod.o.gz > /dev/null 2>&1
/bin/modprobe sd_mod.o.gz > /dev/null 2>&1
/bin/modprobe sr_mod.o.gz > /dev/null 2>&1
/bin/modprobe sg.o.gz > /dev/null 2>&1
/bin/modprobe libata.o.gz > /dev/null 2>&1
echo "Trying cpqarray";
if /bin/modprobe cpqarray > /dev/null 2>&1; then
echo "cpqarray.o.gz" > /scsidriver;
exit 0;
fi
echo "Trying cciss";
if /bin/modprobe cciss > /dev/null 2>&1; then
echo "cciss.o.gz" > /scsidriver;
exit 0;
fi
echo "Trying DAC960";
if /bin/modprobe DAC960 > /dev/null 2>&1; then
echo "DAC960.o.gz" > /scsidriver;
exit 0;
fi
/bin/modprobe ataraid.o.gz > /dev/null 2>&1
echo "Trying medley";
if /bin/modprobe medley > /dev/null 2>&1; then
echo "medley.o.gz" > /scsidriver;
exit 0;
fi
echo "Trying hptraid";
if /bin/modprobe hptraid > /dev/null 2>&1; then
echo "hptraid.o.gz" > /scsidriver;
exit 0;
fi
echo "Trying pdcraid";
if /bin/modprobe pdcraid > /dev/null 2>&1; then
echo "pdcraid.o.gz" > /scsidriver;
exit 0;
fi
echo "Trying silraid";
if /bin/modprobe silraid > /dev/null 2>&1; then
echo "silraid.o.gz" > /scsidriver;
exit 0;
fi
for i in * message/fusion/mptscsih.o.gz ;
do
# Skip the generic scsi modules and ancillary support modules
# Added eata_dma to skip list because it crashes some machines. Probe last.
if [ $i != "scsi_mod.o.gz" -a $i != "sd_mod.o.gz" -a $i != "sg.o.gz" -a $i != "sr_mod.o.gz" -a $i != "53c700.o.gz" -a $i != "NCR53C9x.o.gz" -a $i != "eata_dma.o.gz" -a $i != "libata.o.gz" ]; then
DRIVER=`echo $i | sed 's/.o.gz//'`
echo "Trying $DRIVER";
if /bin/modprobe $DRIVER > /dev/null 2>&1; then
echo $i > /scsidriver;
/bin/cat /proc/scsi/scsi;
exit 0;
fi;
fi;
done
echo "Trying eata_dma";
if /bin/modprobe eata_dma > /dev/null 2>&1; then
echo "eata_dma.o.gz" > /scsidriver;
exit 0;
fi
cd $OLDDIR

View File

@@ -0,0 +1,28 @@
/* IPCop install program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Alan Hourihane, 2003 <alanh@fairlite.demon.co.uk>
*
* $Id: scsi.c
*
*/
#include "install.h"
int
try_scsi(char *disk_device)
{
int fd;
char dev[10];
sprintf(dev, "/dev/%s", disk_device);
if ((fd = open(dev, O_RDONLY)) < 0)
return 0;
close(fd);
// remove usb scsi
return ( checkusb(disk_device) ? 0:1 );
}

View File

@@ -0,0 +1,340 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
*
* $Id: upgrade-v12-v13.c,v 1.2.2.3 2004/11/11 09:39:25 alanh Exp $
*
*/
#include "install.h"
void _convert_ppp_settings() {
DIR *dirp;
struct dirent *dp;
char filename[STRING_SIZE];
dirp = opendir( "/harddisk/var/ipcop/ppp" );
while ( (dp = readdir( dirp )) != NULL ) {
if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {
snprintf (filename, STRING_SIZE-1, "%s/%s",
"/harddisk/var/ipcop/ppp", dp->d_name);
/* reduce furthur replacements from commands below */
replace (filename, "TYPE=modem", "");
replace (filename, "COMPORT=ttyS0", "TYPE=modem\nCOMPORT=ttyS0");
replace (filename, "COMPORT=ttyS1", "TYPE=modem\nCOMPORT=ttyS1");
replace (filename, "COMPORT=ttyS2", "TYPE=modem\nCOMPORT=ttyS2");
replace (filename, "COMPORT=ttyS3", "TYPE=modem\nCOMPORT=ttyS3");
/* reduce furthur replacements from commands below */
replace (filename, "TYPE=isdn", "");
replace (filename, "COMPORT=isdn1", "TYPE=isdn\nCOMPORT=isdn1");
replace (filename, "COMPORT=isdn2", "TYPE=isdn\nCOMPORT=isdn2");
replace (filename, "COMPORT=pppoe", "TYPE=pppoe");
replace (filename, "COMPORT=pptp", "TYPE=pptp");
replace (filename, "COMPORT=usbadsl", "TYPE=alcatelusb");
replace (filename, "COMPORT=pppoa", "TYPE=pulsardsl");
chown (filename, 99, 99);
}
}
(void) closedir( dirp );
}
int _convert_xtaccess() {
int count=1, count2=0;
FILE *portfw1, *portfw2;
char portsrctemp[STRING_SIZE], portdsttemp[STRING_SIZE];
char *portproto, *portsrcip, *portsrcport, *portdstip, *portdstport, *portenabled, *portremip;
FILE *xtaccess1, *xtaccess2;
char xtsrctemp[STRING_SIZE], xtdsttemp[STRING_SIZE];
char *xtproto, *xtsrcip, *xtdstip, *xtdstport, *xtenabled;
if (!(portfw1 = fopen ("/harddisk/var/ipcop/portfw/config", "r"))) return 1;
if (!(portfw2 = fopen ("/harddisk/var/ipcop/portfw/config.new", "w")))
{
fclose(portfw1);
return 1;
}
while (fgets (portsrctemp, STRING_SIZE, portfw1) != NULL) {
count2 = 0;
portproto = NULL;
portsrcip = NULL;
portsrcport = NULL;
portdstip = NULL;
portdstport = NULL;
portremip = NULL;
portenabled = NULL;
if (!(xtaccess1 = fopen ("/harddisk/var/ipcop/xtaccess/config", "r")))
{
fclose(portfw1);
fclose(portfw2);
return 1;
}
if (!(xtaccess2 = fopen ("/harddisk/var/ipcop/xtaccess/config.new", "w")))
{
fclose(portfw1);
fclose(portfw2);
fclose(xtaccess1);
return 1;
}
if (isdigit (portsrctemp[0])) {
/* Already converted to new format */
fputs(portsrctemp, portfw2);
continue;
}
if (portsrctemp[strlen(portsrctemp) - 1] == '\n')
portsrctemp[strlen(portsrctemp) - 1] = '\0';
portproto = strtok (portsrctemp, ",");
portsrcport = strtok (NULL, ",");
portdstip = strtok (NULL, ",");
portdstport = strtok (NULL, ",");
portenabled = strtok (NULL, ",");
portsrcip = strtok (NULL, ",");
portremip = strtok (NULL, ",");
if (!(portproto && portsrcport && portdstip &&
portdstport && portenabled ))
continue;
if (portsrcip == NULL) portsrcip = strdup ("0.0.0.0");
while (fgets (xtsrctemp, STRING_SIZE, xtaccess1)) {
xtproto = NULL;
xtsrcip = NULL;
xtdstip = NULL;
xtdstport = NULL;
xtenabled = NULL;
if (xtsrctemp[strlen(xtsrctemp) - 1] == '\n')
xtsrctemp[strlen(xtsrctemp) - 1] = '\0';
xtproto = strtok (xtsrctemp, ",");
xtsrcip = strtok (NULL, ",");
xtdstport = strtok (NULL, ",");
xtenabled = strtok (NULL, ",");
xtdstip = strtok (NULL, ",");
if (!(xtproto && xtsrcip && xtdstport && xtenabled)) continue;
if (xtdstip == NULL) xtdstip = strdup ("0.0.0.0");
if (strcmp (portproto, xtproto) == 0 &&
strcmp (portsrcport, xtdstport) == 0 &&
strcmp (portsrcip, xtdstip) == 0) {
portremip = strdup (xtsrcip);
if ((strcmp (portremip, "0.0.0.0/0") == 0) && (count2 == 0)) {
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
count, count2, portproto, portsrcport, portdstip,
portdstport, portenabled, portsrcip, portremip);
fputs(portdsttemp, portfw2);
} else {
if (count2 == 0) {
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%d\n",
count,count2,portproto, portsrcport, portdstip,
portdstport, portenabled, portsrcip, 0);
fputs(portdsttemp, portfw2);
count2++;
}
sprintf (portdsttemp, "%d,%d,%s,%d,%s,%s,%s,%d,%s\n",
count,count2,portproto, 0, portdstip,
portdstport, portenabled, 0, portremip);
fputs(portdsttemp, portfw2);
}
count2++;
} else {
sprintf (xtdsttemp, "%s,%s,%s,%s,%s\n",
xtproto, xtsrcip, xtdstport, xtenabled, xtdstip);
fputs(xtdsttemp, xtaccess2);
}
}
/* Close source and destination xtaccess files */
fclose (xtaccess1);
fclose (xtaccess2);
/* Move the new xtaccess file */
rename ("/harddisk/var/ipcop/xtaccess/config.new",
"/harddisk/var/ipcop/xtaccess/config");
/* If no external access line existed, add a no access line */
if (count2 == 0) {
if (portremip == NULL) portremip = strdup ("127.0.0.1/32");
/* Print new port forwarding line to file */
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
count, count2, portproto, portsrcport, portdstip,
portdstport, portenabled, portsrcip, portremip);
fputs(portdsttemp, portfw2);
}
count++;
}
/* Close source and destination portfw files */
fclose (portfw1);
fclose (portfw2);
/* Move the new portfw file */
rename ("/harddisk/var/ipcop/portfw/config.new",
"/harddisk/var/ipcop/portfw/config");
chown ("/harddisk/var/ipcop/xtaccess/config", 99, 99);
chown ("/harddisk/var/ipcop/portfw/config", 99, 99);
return 0;
}
int _convert_pulsardsl() {
DIR *dirp;
struct dirent *dp;
char filename[STRING_SIZE];
FILE *settings, *pulsardsl;
char line[STRING_SIZE];
if (!(pulsardsl = fopen ("/harddisk/var/ipcop/pciadsl/settings", "r"))) return 1;
dirp = opendir( "/harddisk/var/ipcop/ppp" );
while ( (dp = readdir( dirp )) != NULL ) {
if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {
snprintf (filename, STRING_SIZE-1, "%s/%s",
"/harddisk/var/ipcop/ppp", dp->d_name);
if (!(settings = fopen (filename, "r+"))) {
closedir(dirp);
fclose(pulsardsl);
return 1;
}
while (fgets (line, STRING_SIZE, settings) != NULL) {
if (strstr (line, "TYPE=pulsardsl") == line) {
fseek(settings,0,SEEK_END);
rewind(pulsardsl);
while (fgets(line, STRING_SIZE, pulsardsl) != NULL) {
fputs (line, settings);
}
fclose (settings);
chown (filename, 99, 99);
}
}
}
}
fclose(pulsardsl);
(void) closedir( dirp );
return 0;
}
int _convert_pulsardsl_ethernet() {
DIR *dirp;
struct dirent *dp;
FILE *ethernet, *settings;
char line[STRING_SIZE];
char type[STRING_SIZE];
char ip[STRING_SIZE];
char filename[STRING_SIZE];
if (!(ethernet = fopen ("/harddisk/var/ipcop/ethernet/settings", "r"))) return 1;
while (fgets (line, STRING_SIZE, ethernet) != NULL) {
if (strstr (line, "RED_DRIVER=pciadsl") == line) {
rewind (ethernet);
while (fgets (line, STRING_SIZE, ethernet) != NULL) {
if (strstr (line, "RED_TYPE") == line) {
strcpy (type, line + 9*sizeof(char));
if (type[strlen(type) - 1] == '\n')
type[strlen(type) - 1] = '\0';
}
if (strstr (line, "RED_ADDRESS") == line) {
strcpy (ip, line + 12*sizeof(char));
if (ip[strlen(ip) - 1] == '\n')
type[strlen(ip) - 1] = '\0';
}
fclose (ethernet);
replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth1", "RED_DEV=");
replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=2", "CONFIG_TYPE=0");
replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=3", "CONFIG_TYPE=1");
replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth2", "RED_DEV=");
chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
dirp = opendir( "/harddisk/var/ipcop/ppp" );
while ( (dp = readdir( dirp )) != NULL ) {
if ( strstr( dp->d_name, "settings-" ) == dp->d_name ) {
snprintf (filename, STRING_SIZE-1, "%s/%s",
"/harddisk/var/ipcop/ppp", dp->d_name);
if (!(settings = fopen (filename, "r+")))
{
closedir(dirp);
return 1;
}
while (fgets (line, STRING_SIZE, settings) != NULL) {
if (strstr (line, "TYPE=pulsardsl") == line) {
fseek(settings,0,SEEK_END);
fprintf (settings, "METHOD=%s\n", type);
fprintf (settings, "IP=%s\n", ip);
fclose (settings);
chown (filename, 99, 99);
}
}
}
}
(void) closedir( dirp );
}
}
}
return 0;
}
int upgrade_v12_v13() {
struct stat s;
replace ("/harddisk/var/ipcop/ethernet/settings", "rtl8139", "8139too");
replace ("/harddisk/var/ipcop/vpn/ipsec.conf", "auto=add", "auto=start");
chown ("/harddisk/var/ipcop/vpn/ipsec.conf", 99, 99);
chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
chown ("/harddisk/var/ipcop/main/settings", 99, 99);
_convert_ppp_settings();
_convert_xtaccess();
_convert_pulsardsl();
_convert_pulsardsl_ethernet();
/* Rename usbadsl directory */
stat ("/harddisk/var/ipcop/usbadsl", &s);
if (S_ISDIR(s.st_mode)) {
remove ("/harddisk/var/ipcop/usbadsl/settings");
if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/alcatelusb"))
rename ("/harddisk/var/ipcop/usbadsl", "/harddisk/var/ipcop/alcatelusb");
}
/* Rename pciadsl module and directory */
remove ("/harddisk/var/ipcop/pulsar/settings");
rename ("/harddisk/var/ipcop/pciadsl/pciadsl.o", "/harddisk/var/ipcop/pciadsl/pulsar.o");
stat ("/harddisk/var/ipcop/pciadsl", &s);
if (S_ISDIR(s.st_mode)) {
if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/pulsardsl"))
rename ("/harddisk/var/ipcop/pciadsl", "/harddisk/var/ipcop/pulsardsl");
}
/* Change squid cache directory */
replace ("/harddisk/var/ipcop/proxy/squid.conf", "/var/spool/squid", "/var/log/cache");
chown ("/harddisk/var/ipcop/proxy/squid.conf", 99, 99);
/* Change setup user shell */
replace ("/harddisk/etc/passwd", ":/usr/local/sbin/setup", ":/bin/bash -c /usr/local/sbin/setup");
return 0;
}

View File

@@ -0,0 +1,577 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
*
* $Id: upgrade-v130-v140.c,v 1.12.2.35 2004/11/11 09:40:03 alanh Exp $
*
*/
#include "install.h"
extern char **ctr;
int _handledomainname(void)
{
char domainname[STRING_SIZE] = "localdomain";
struct keyvalue *kv = initkeyvalues();
char *values[] = { domainname, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
int rc;
int result;
if (!(readkeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
findkey(kv, "DOMAINNAME", domainname);
/* already have a domainname */
if (strlen(domainname))
return 0;
for (;;)
{
rc = newtWinEntries(ctr[TR_DOMAINNAME], ctr[TR_ENTER_DOMAINNAME],
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 1)
{
strcpy(domainname, values[0]);
if (strchr(domainname, ' '))
errorbox(ctr[TR_DOMAINNAME_CANNOT_CONTAIN_SPACES]);
else
{
replacekeyvalue(kv, "DOMAINNAME", domainname);
writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings");
result = 1;
break;
}
}
else
{
result = 0;
break;
}
}
free(values[0]);
freekeyvalues(kv);
return result;
}
int _add_logwatch_user() {
mysystem("/bin/chroot /harddisk /usr/sbin/userdel logwatch");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel logwatch");
mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 102 logwatch");
mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 102 -g logwatch -d /var/log/logwatch -s /bin/false logwatch");
return 0;
}
int _fixsquid() {
FILE *squidreadfile;
FILE *squidwritefile;
FILE *aclreadfile;
char hostname[STRING_SIZE] = "";
char domainname[STRING_SIZE] = "";
char squidtemp[STRING_SIZE];
struct keyvalue *kv = initkeyvalues();
int already_upgraded = 0;
int updated = 0;
if (!(squidreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/squid.conf", "r"))) return 1;
if (!(squidwritefile = fopen ("/harddisk" CONFIG_ROOT "/proxy/squid.conf.new", "w")))
{
fclose(squidreadfile);
return 1;
}
if (!(readkeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings")))
{
fclose (squidwritefile);
fclose (squidreadfile);
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 1;
}
findkey(kv, "HOSTNAME", hostname);
findkey(kv, "DOMAINNAME", domainname);
freekeyvalues(kv);
while (fgets (squidtemp, STRING_SIZE, squidreadfile) != NULL) {
/* this will fail if we've already been upgraded, which is ok */
if (!strncmp(squidtemp, "reply_body_max_size 0 KB", 24)) {
sprintf(squidtemp, "reply_body_max_size 0 allow all\n");
}
if (!strncmp(squidtemp, "cache_store_log /var/log/squid/store.log", 40)) {
sprintf(squidtemp, "cache_store_log none\n");
}
fputs(squidtemp, squidwritefile);
/* so for us developers we skip already upgraded squiddies */
if (!strncmp(squidtemp, "visible_hostname", 16)) {
already_upgraded = 1;
}
/* Check for the new acl's */
if (!strncmp(squidtemp, "__GREEN_IP__", 12)) {
updated = 1;
}
}
if (!already_upgraded) {
sprintf(squidtemp, "visible_hostname %s.%s\n", hostname, domainname);
fputs(squidtemp, squidwritefile);
}
fclose (squidwritefile);
fclose (squidreadfile);
rename ("/harddisk" CONFIG_ROOT "/proxy/squid.conf.new",
"/harddisk" CONFIG_ROOT "/proxy/squid.conf");
replace("/harddisk" CONFIG_ROOT "/proxy/squid.conf", "cache_dir ufs", "cache_dir aufs");
if (!updated) {
rename ("/harddisk" CONFIG_ROOT "/proxy/acl",
"/harddisk" CONFIG_ROOT "/proxy/acl.old");
rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4",
"/harddisk" CONFIG_ROOT "/proxy/acl");
} else {
if (!(aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) {
rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4",
"/harddisk" CONFIG_ROOT "/proxy/acl");
} else {
unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4");
fclose(aclreadfile);
}
}
chown ("/harddisk" CONFIG_ROOT "/proxy/squid.conf", 99, 99);
chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99);
return 0;
}
int _fixeagleusb() {
FILE *eaglereadfile;
FILE *eaglewritefile;
char eagletemp[STRING_SIZE];
int already_upgraded = 0;
if (!(eaglereadfile = fopen ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf", "r"))) return 1;
if (!(eaglewritefile = fopen ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf.new", "w")))
{
fclose(eaglereadfile);
return 1;
}
while (fgets (eagletemp, STRING_SIZE, eaglereadfile) != NULL) {
/* so for us developers we skip already upgraded configs */
if (!strncmp(eagletemp, "<eaglectrl>", 11)) {
already_upgraded = 1;
}
}
rewind(eaglereadfile);
if (!already_upgraded)
fprintf(eaglewritefile, "<eaglectrl>\n");
while (fgets (eagletemp, STRING_SIZE, eaglereadfile) != NULL)
fputs(eagletemp, eaglewritefile);
if (!already_upgraded)
fprintf(eaglewritefile, "</eaglectrl>\n");
fclose (eaglewritefile);
fclose (eaglereadfile);
rename ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf.new",
"/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf");
replace("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf", "Linetype=00000001", "Linetype=0A");
chown ("/harddisk" CONFIG_ROOT "/eagle-usb/eagle-usb.conf", 99, 99);
unlink("/harddisk" CONFIG_ROOT "/eagle-usb/dsp_code_pots.bin");
unlink("/harddisk" CONFIG_ROOT "/eagle-usb/dsp_code_isdn.bin");
return 0;
}
int _fixdhcp_30() {
FILE *dhcpreadfile;
FILE *dhcpwritefile;
char dhcptemp[STRING_SIZE];
if (!(dhcpreadfile = fopen ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf", "r"))) return 1;
if (!(dhcpwritefile = fopen ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf.new", "w")))
{
fclose(dhcpreadfile);
return 1;
}
fprintf (dhcpwritefile, "authoritative;\n");
fprintf (dhcpwritefile, "deny bootp;\n");
fprintf (dhcpwritefile, "ddns-update-style none;\n");
while (fgets (dhcptemp, STRING_SIZE, dhcpreadfile) != NULL) {
int write = 1;
/* so for us developers we skip already upgraded dhcp files */
if (!strncmp(dhcptemp, "authoritative", 13)) {
write = 0;
}
/* so for us developers we skip already upgraded dhcp files */
if (!strncmp(dhcptemp, "ddns-update-style", 17)) {
write = 0;
}
/* so for us developers we skip already upgraded dhcp files */
if (!strncmp(dhcptemp, "deny bootp", 10)) {
write = 0;
}
if (write)
fputs(dhcptemp, dhcpwritefile);
}
fclose(dhcpreadfile);
fclose(dhcpwritefile);
rename ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf.new",
"/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf");
chown ("/harddisk" CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
/* This one will get converted again furthur down */
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "WINS=", "WINS1=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "START_ADDR=", "START_ADDR_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "END_ADDR=", "END_ADDR_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DOMAIN_NAME=", "DOMAIN_NAME_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DEFAULT_LEASE_TIME=", "DEFAULT_LEASE_TIME_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "MAX_LEASE_TIME=", "MAX_LEASE_TIME_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DNS1=", "DNS1_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "DNS2=", "DNS2_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "WINS1=", "WINS1_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "WINS2=", "WINS2_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "ENABLE=", "ENABLE_GREEN=");
replace("/harddisk" CONFIG_ROOT "/dhcp/settings", "range dynamic-bootp", "range");
chown ("/harddisk" CONFIG_ROOT "/dhcp/settings", 99, 99);
if ((dhcpreadfile = fopen ("/harddisk" CONFIG_ROOT "/dhcp/enable", "r")))
{
fclose(dhcpreadfile);
rename ("/harddisk" CONFIG_ROOT "/dhcp/enable",
"/harddisk" CONFIG_ROOT "/dhcp/enable_green");
chown ("/harddisk" CONFIG_ROOT "/dhcp/enable_green", 99, 99);
}
return 0;
}
int _add_sshd_user() {
mysystem("/bin/chroot /harddisk /usr/sbin/userdel sshd");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel sshd");
mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 74 sshd");
mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 74 -g sshd -d /var/empty/sshd -s /bin/false -M sshd");
return 0;
}
int _add_dnsmasq_user() {
mysystem("/bin/chroot /harddisk /usr/sbin/userdel dnsmasq");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel dnsmasq");
mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 103 dnsmasq");
mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 103 -g dnsmasq -d / -s /bin/false -M dnsmasq");
return 0;
}
int _add_cron_user() {
mysystem("/bin/chroot /harddisk /usr/sbin/userdel cron");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel cron");
mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 104 cron");
mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 104 -g cron -d / -s /bin/false -M cron");
return 0;
}
int _add_sysklogd_user() {
mysystem("/bin/chroot /harddisk /usr/sbin/userdel syslogd");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel syslogd");
mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 105 syslogd");
mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 105 -g syslogd -d / -s /bin/false -M syslogd");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel klogd");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel klogd");
mysystem("/bin/chroot /harddisk /usr/sbin/groupadd -g 106 klogd");
mysystem("/bin/chroot /harddisk /usr/sbin/useradd -u 106 -g klogd -d / -s /bin/false -M klogd");
return 0;
}
int _del_setup_user() {
mysystem("/bin/chroot /harddisk /usr/sbin/userdel setup");
return 0;
}
int _create_nobody_dir(){
mysystem("/bin/chroot /harddisk /usr/sbin/usermod -d /home/nobody nobody");
return 0;
}
int _del_useless_user_group()
{
mysystem("/bin/chroot /harddisk /usr/sbin/userdel games");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel games");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel news");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel news");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel ftp");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel gopher");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel lp");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel uucp");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel adm");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel adm");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel operator");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel sync");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel shutdown");
mysystem("/bin/chroot /harddisk /usr/sbin/userdel halt");
mysystem("/bin/chroot /harddisk /usr/sbin/groupdel man");
return 0;
}
void _del_pulsardsl_dir()
{
mysystem("/bin/chroot /harddisk /bin/rm -rf " CONFIG_ROOT "/pulsardsl");
}
void _del_fritzdsl_dir()
{
mysystem("/bin/chroot /harddisk /bin/rm -rf " CONFIG_ROOT "/fritzdsl");
}
int _convert_vpn() {
int count=1;
FILE *vpn1, *vpn2;
char vpnip[STRING_SIZE] = "";
char greennetaddr[STRING_SIZE] = "";
struct keyvalue *kv = initkeyvalues();
char vpnsrctemp[STRING_SIZE], vpndsttemp[STRING_SIZE];
char *name, *left, *left_nexthop, *left_subnet, *right, *right_nexthop, *right_subnet, *secret, *enabled, *compression;
if (!(vpn1 = fopen ("/harddisk" CONFIG_ROOT "/vpn/config", "r"))) return 1;
if (!(vpn2 = fopen ("/harddisk" CONFIG_ROOT "/vpn/config.new", "w")))
{
fclose(vpn1);
return 1;
}
if (!(readkeyvalues(kv, "/harddisk" CONFIG_ROOT "/ethernet/settings")))
{
fclose (vpn1);
fclose (vpn2);
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
findkey(kv, "GREEN_NETADDRESS", greennetaddr);
freekeyvalues(kv);
kv = initkeyvalues();
if (!(readkeyvalues(kv, "/harddisk" CONFIG_ROOT "/vpn/settings")))
{
fclose (vpn1);
fclose (vpn2);
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
/* if no VPN_IP is defined, we must turn it off to force the user
* to enter a value once upgraded */
findkey(kv, "VPN_IP", vpnip);
if (strlen(vpnip) == 0) {
replacekeyvalue(kv, "ENABLED", "off");
writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/vpn/settings");
}
freekeyvalues(kv);
while (fgets (vpnsrctemp, STRING_SIZE, vpn1) != NULL) {
if (isdigit (vpnsrctemp[0])) {
/* Already converted to new format */
fputs(vpnsrctemp, vpn2);
continue;
}
name = NULL;
left = NULL;
left_nexthop = NULL;
left_subnet = NULL;
right = NULL;
right_nexthop = NULL;
right_subnet = NULL;
secret = NULL;
enabled = NULL;
compression = NULL;
if (vpnsrctemp[strlen(vpnsrctemp) - 1] == '\n')
vpnsrctemp[strlen(vpnsrctemp) - 1] = '\0';
name = strtok (vpnsrctemp, ",");
left = strtok (NULL, ",");
left_nexthop = strtok (NULL, ",");
left_subnet = strtok (NULL, ",");
right = strtok (NULL, ",");
right_nexthop = strtok (NULL, ",");
right_subnet = strtok (NULL, ",");
secret = strtok (NULL, ",");
enabled = strtok (NULL, ",");
compression = strtok (NULL, ",");
if (!(name && left && left_subnet &&
right && right_subnet &&
secret && enabled && compression ))
continue;
/* Try and guess what side IPCop is on; defaults to left */
if (strstr(greennetaddr, right_subnet)) {
sprintf (vpndsttemp, "%d,%s,%s,,net,psk,%s,right,,%s,,%s,%s,,%s,,,,,,,,,,,,,RED\n",
count, enabled, name, secret, right_subnet,
left, left_subnet, compression);
} else {
sprintf (vpndsttemp, "%d,%s,%s,,net,psk,%s,left,,%s,,%s,%s,,%s,,,,,,,,,,,,,RED\n",
count, enabled, name, secret, left_subnet,
right, right_subnet, compression);
}
fputs(vpndsttemp, vpn2);
count++;
}
/* Close source and destination vpn files */
fclose (vpn1);
fclose (vpn2);
/* Move the new vpn file */
rename ("/harddisk" CONFIG_ROOT "/vpn/config.new",
"/harddisk" CONFIG_ROOT "/vpn/config");
chown ("/harddisk" CONFIG_ROOT "/vpn/config", 99, 99);
return 0;
}
void _convert_ppp_settings_V140() {
DIR *dirp;
struct dirent *dp;
char filename[STRING_SIZE];
dirp = opendir( "/harddisk" CONFIG_ROOT "/ppp" );
while ( (dp = readdir( dirp )) != NULL ) {
if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {
snprintf (filename, STRING_SIZE-1, "%s/%s",
"/harddisk" CONFIG_ROOT "/ppp", dp->d_name);
replace (filename, "PERSISTENT=on", "RECONNECTION=persistent");
replace (filename, "DIALONDEMAND=on", "RECONNECTION=dialondemand");
replace (filename, "MODULATION=GDTM", "MODULATION=GDMT");
chown (filename, 99, 99);
}
}
(void) closedir( dirp );
}
void _convert_net_settings_V140(){
replace ("/harddisk" CONFIG_ROOT "/ethernet/settings", "eepro100", "e100");
chown ("/harddisk" CONFIG_ROOT "/ethernet/settings", 99, 99);
}
void _convert_keymap() {
replace("/harddisk" CONFIG_ROOT "/main/settings", "KEYMAP=/lib/kbd", "KEYMAP=/usr/share/kbd");
replace("/harddisk" CONFIG_ROOT "/main/settings", ".kmap.gz", ".map.gz");
chown ("/harddisk" CONFIG_ROOT "/main/settings", 99, 99);
}
void _convert_speedtouch() {
FILE *speedtchbootfile;
FILE *speedtchfirmfile;
if (( speedtchfirmfile = fopen ("/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v4.bin", "r")))
{
fclose (speedtchfirmfile);
if ((speedtchbootfile = fopen ("/harddisk" CONFIG_ROOT "/alcatelusb/boot.v4.bin", "r"))) {
fclose (speedtchbootfile);
system("/bin/cat /harddisk" CONFIG_ROOT "/alcatelusb/boot.v4.bin "
"/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v4.bin"
"> /harddisk" CONFIG_ROOT "/alcatelusb/firmware.v4_b.bin");
remove ("/harddisk" CONFIG_ROOT "/alcatelusb/boot.v4.bin");
remove ("/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v4.bin");
chown ("/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v4_b.bin", 99, 99);
}
}
if (( speedtchfirmfile = fopen ("/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v123.bin", "r"))) {
fclose (speedtchfirmfile);
system("/bin/cat /harddisk" CONFIG_ROOT "/alcatelusb/boot.v123.bin "
"/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v123.bin"
"> /harddisk" CONFIG_ROOT "/alcatelusb/firmware.v0123.bin");
remove ("/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v123.bin");
}
remove ("/harddisk" CONFIG_ROOT "/alcatelusb/boot.v123.bin");
rename ("/harddisk" CONFIG_ROOT "/alcatelusb/mgmt.o", "/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v0123.bin");
chown ("/harddisk" CONFIG_ROOT "/alcatelusb/firmware.v0123.bin", 99, 99);
}
void _convert_isapnp() {
FILE *isapnpfile;
mkdir ("/harddisk" CONFIG_ROOT "/isapnp", S_IRWXU|S_IRWXG|S_IRWXO );
if (( isapnpfile = fopen ("/harddisk/etc/isapnp.conf", "r"))) {
fclose (isapnpfile);
rename ("/harddisk/etc/isapnp.conf", "/harddisk" CONFIG_ROOT "/isapnp/isapnp.conf");
} else {
if (( isapnpfile = fopen ("/harddisk" CONFIG_ROOT "/isapnp/isapnp.conf", "r"))) {
fclose(isapnpfile);
} else {
isapnpfile = fopen ("/harddisk" CONFIG_ROOT "/isapnp/isapnp.conf", "w");
fclose(isapnpfile);
}
}
}
int upgrade_v130_v140() {
_del_setup_user();
_del_useless_user_group();
_add_logwatch_user();
_add_sshd_user();
_add_dnsmasq_user();
_add_cron_user();
_add_sysklogd_user();
_del_pulsardsl_dir();
_del_fritzdsl_dir();
_convert_vpn();
_handledomainname();
_fixsquid();
_fixeagleusb();
_create_nobody_dir();
_convert_ppp_settings_V140();
_convert_net_settings_V140();
_fixdhcp_30();
_convert_keymap();
_convert_speedtouch();
_convert_isapnp();
return 0;
}

View File

@@ -0,0 +1,141 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
*
* $Id: usb.c,v 1.9.2.8 2005/12/10 00:18:23 franck78 Exp $
*
*/
#include "install.h"
int usbuhci = 0;
int usbohci = 0;
int ehcihcd = 0;
int initialize_usb() {
modprobe("sd_mod");
modprobe("sr_mod");
modprobe("usb-storage");
if (ehcihcd) {
rmmod("ehci-hcd");
ehcihcd = 0;
}
if (usbohci) {
rmmod("usb-ohci");
usbohci = 0;
}
if (usbuhci) {
rmmod("usb-uhci");
usbuhci = 0;
}
if (modprobe("ehci-hcd") == 0) ehcihcd = 1;
if (modprobe("usb-ohci") == 0) usbohci = 1;
if (modprobe("usb-uhci") == 0) usbuhci = 1;
modprobe("hid");
modprobe("keybdev");
return 0;
}
int write_usb_modules_conf() {
int index = 0;
FILE *handle;
if (!(handle = fopen("/harddisk/etc/modules.conf", "a")))
return 0;
#if 0 /* we don't do this yet, because one of the drivers has a problem
* with it */
if (ehcihcd) {
fprintf(handle,"alias usb-controller");
if (index)
fprintf(handle,"%d",index);
fprintf(handle," ehci-hcd\n");
index++;
}
#endif
if (usbohci) {
fprintf(handle,"alias usb-controller");
if (index)
fprintf(handle,"%d",index);
fprintf(handle," usb-ohci\n");
index++;
}
if (usbuhci) {
fprintf(handle,"alias usb-controller");
if (index)
fprintf(handle,"%d",index);
fprintf(handle," usb-uhci\n");
index++;
}
fclose(handle);
return 0;
}
/* checkusb().
Scans the named partitions and returns true if USB-removable.
a bug? in "cat /proc/partitions" with superfloppy scheme device
make them appearing always with four 'false' partitions:
sda and sda1 sda2 sda3 sda4.
No easy way to decide if /dev/sda1 exists or not.
*/
int checkusb(char *partition)
{
FILE *f = NULL;
char filename[STRING_SIZE];
char buffer[STRING_SIZE];
char *pchar = &buffer[0];
if (!(f = fopen("/proc/partitions", "r")))
return 0;
short int major = 0, minor = 0;
while (fgets(buffer, STRING_SIZE, f)) {
/* look for partition*/
if (strstr (buffer, partition)) {
major = atoi (buffer);
if (major != 8) break ; /* not scsi */
//get minor
while (*pchar != '8') pchar++;
minor = atoi (++pchar);
break;
}
}
fclose(f);
if (major != 8) return 0; /* nothing found */
//now check for usb-storage-MINOR
minor >>= 4; // get index from minor
sprintf (filename, "/proc/scsi/usb-storage-%d/%d", minor,minor);
if (!(f = fopen(filename, "r")))
return 0;
int count = 0;
while (fgets(buffer, STRING_SIZE, f)) {
if (strstr(buffer,"usb-storage")) count++;
if (strstr(buffer,"SCSI")) count++;
if (strstr(buffer,"Attached: Yes")) count++;
}
fclose(f);
return (count==3 ? 1 : 0);
}

View File

@@ -0,0 +1,8 @@
/Makefile/1.4.2.1/Wed Jan 11 01:01:38 2006//TIPCOP_v1_4_0
/langs.h.temp/1.4/Thu Dec 11 11:25:53 2003//TIPCOP_v1_4_0
/libsmooth.h/1.4.2.3/Sun Oct 30 23:25:35 2005//TIPCOP_v1_4_0
/main.c/1.6.2.9/Fri Dec 9 22:31:41 2005//TIPCOP_v1_4_0
/makelangs.pl/1.4/Thu Dec 11 11:25:53 2003//TIPCOP_v1_4_0
/netstuff.c/1.19.2.7/Fri Nov 5 23:40:17 2004//TIPCOP_v1_4_0
/varval.c/1.4/Thu Dec 11 11:25:53 2003//TIPCOP_v1_4_0
D

View File

@@ -0,0 +1 @@
ipcop/src/install+setup/libsmooth

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop

View File

@@ -0,0 +1 @@
TIPCOP_v1_4_0

View File

@@ -0,0 +1,41 @@
#
# $Id: Makefile,v 1.4.2.1 2006/01/11 01:01:38 franck78 Exp $
#
CC = gcc
CFLAGS = -O2 -Wall
INCLUDE = -I/install/include
LD = ld
LDFLAGS = -i
COMPILE = $(CC) -c $(INCLUDE) $(CFLAGS)
LINK = $(LD) $(LIBRARY) $(LDFLAGS)
all : programs
programs : lang_smooth libsmooth.o
clean :
-rm -f *.o core langs.h
lang_smooth :
for i in /usr/src/langs/*/install/lang_*.c ; do \
cp $$i ../libsmooth/; \
done
#build the tr_strings include file
awk 'BEGIN{ print"enum trstrings{" } $$0 ~/\/\* (TR_[A-Z0-9_]*)/ {print $$2"," }\
END{ print "};" }'\
../libsmooth/lang_en.c > ../libsmooth/langs.h
######
# Language modules are directly included in main.c
OBJS=main.o netstuff.o varval.o
libsmooth.o: $(OBJS)
$(LINK) $(OBJS) -o $@ $(LIBS)
%.o : %.c
$(COMPILE) $< -o $@

View File

@@ -0,0 +1,15 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* This is a template (basically just a header). langs.h is generated via
* the Makefile, from lang_en.c.
*
* $Id: langs.h.temp,v 1.4 2003/12/11 11:25:53 riddles Exp $
*
*/
enum trstrings
{

View File

@@ -0,0 +1,99 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains prototypes for library functions.
*
* $Id: libsmooth.h,v 1.4.2.3 2005/10/30 23:25:35 franck78 Exp $
*
*/
#ifndef ___LIBSMOOTH_H
#define ___LIBSMOOTH_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <wchar.h>
#include <locale.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <newt.h>
#include <dirent.h>
#include <sys/mount.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include "langs.h"
#define STRING_SIZE 1023
#define ADDRESS 0
#define NETADDRESS 1
#define NETMASK 2
#define DHCP 3
#define NETCHANGE_TOTAL 4
struct keyvalue
{
char key[STRING_SIZE];
char value[STRING_SIZE];
struct keyvalue *next;
};
/* for stuff in net.c */
struct nic
{
char *description;
char *modulename;
};
/* libsmooth.c */
void reboot(void);
void stripnl(char *s);
int mysystem(char *command);
void errorbox(char *message);
void statuswindow(int width, int height, char *title, char *text, ...);
int runcommandwithprogress(int width, int height, char *title, char *command,
int lines, char *text, ...);
int runcommandwithstatus(char *command, char *message);
int runhiddencommandwithstatus(char *command, char *message);
int checkformodule(char *module);
int replace(char filename1[], char *from, char *to);
char* get_version(void);
/* netstuff.c */
int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
char *defaultdhcphostname);
int gettype(char *type);
int setnetaddress(struct keyvalue *kv, char *colour);
void networkdialogcallbacktype(newtComponent cm, void *data);
int interfacecheck(struct keyvalue *kv, char *colour);
int probecards(char *driver, char *driveroptions);
int choosecards(char *driver, char *driveroptions);
int manualdriver(char *driver, char *driveroptions);
int countcards(void);
int findnicdescription(char *modulename, char *description);
/* data.c */
struct keyvalue *initkeyvalues(void);
void freekeyvalues(struct keyvalue *head);
int readkeyvalues(struct keyvalue *head, char *filename);
int writekeyvalues(struct keyvalue *head, char *filename);
int findkey(struct keyvalue *head, char *key, char *value);
void appendkeyvalue(struct keyvalue *head, char *key, char *value);
void replacekeyvalue(struct keyvalue *head, char *key, char *value);
#endif

View File

@@ -0,0 +1,324 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains library functions.
*
* $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $
*
*/
#include "libsmooth.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
/* reboot(). reboots. */
void reboot(void)
{
mysystem("/etc/halt");
}
/* stripnl(). Replaces \n with \0 */
void stripnl(char *s)
{
char *t = strchr(s, '\n');
if (t) *t = '\0';
}
/* Little wrapper. */
int mysystem(char *command)
{
char mycommand[STRING_SIZE];
snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
fprintf(flog, "Running command: %s\n", command);
return system(mycommand);
}
void errorbox(char *message)
{
newtWinMessage(ctr[TR_ERROR], ctr[TR_OK], message);
}
void statuswindow(int width, int height, char *title, char *text, ...)
{
newtComponent t, f;
char *buf = NULL;
int size = 0;
int i = 0;
va_list args;
va_start(args, text);
do {
size += 1000;
if (buf) free(buf);
buf = malloc(size);
i = vsnprintf(buf, size, text, args);
} while (i == size);
va_end(args);
newtCenteredWindow(width, height, title);
t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
newtTextboxSetText(t, buf);
f = newtForm(NULL, NULL, 0);
free(buf);
newtFormAddComponent(f, t);
newtDrawForm(f);
newtRefresh();
newtFormDestroy(f);
}
int runcommandwithstatus(char *command, char *message)
{
int rc;
char title[STRING_SIZE];
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
statuswindow(60, 4, title, message);
rc = mysystem(command);
newtPopWindow();
return rc;
}
int runhiddencommandwithstatus(char *command, char *message)
{
int rc;
char title[STRING_SIZE];
char mycommand[STRING_SIZE];
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
statuswindow(60, 4, title, message);
snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
fprintf(flog, "Running command: ***** HIDDEN *****\n");
rc = system(mycommand);
newtPopWindow();
return rc;
}
/* This one borrowed from redhat installer. */
int runcommandwithprogress(int width, int height, char *title, char *command,
int lines, char *text, ...)
{
newtComponent t, f, s;
char *buf = NULL;
int size = 0;
int i = 0;
va_list args;
int rc = 0;
FILE *p;
char buffer[STRING_SIZE];
int progress = 0;
char mycommand[STRING_SIZE];
va_start(args, text);
do {
size += 1000;
if (buf) free(buf);
buf = malloc(size);
i = vsnprintf(buf, size, text, args);
} while (i == size);
va_end(args);
newtCenteredWindow(width, height, title);
t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
newtTextboxSetText(t, buf);
f = newtForm(NULL, NULL, 0);
free(buf);
newtFormAddComponent(f, t);
s = newtScale(1, 3, width - 2, lines);
newtScaleSet(s, progress);
newtFormAddComponent(f, s);
newtDrawForm(f);
newtRefresh();
snprintf(mycommand, STRING_SIZE, "%s 2>>%s", command, mylog);
fprintf(flog, "Running command: %s\n", command);
if (!(p = popen(command, "r")))
{
rc = 1;
goto EXIT;
}
setvbuf(p, NULL, _IOLBF, 255);
while (fgets(buffer, STRING_SIZE, p))
{
newtScaleSet(s, ++progress);
newtRefresh();
fprintf(flog, "%s", buffer);
}
rc = pclose(p);
EXIT:
newtFormDestroy(f);
newtPopWindow();
return rc;
}
int checkformodule(char *module)
{
FILE *file;
char buffer[STRING_SIZE];
int result = 0;
if (!(file = fopen("/proc/modules", "r")))
{
fprintf(flog, "Unable to open /proc/modules in checkformodule()\n");
return 0;
}
while (fgets(buffer, STRING_SIZE, file))
{
if (strncmp(buffer, module, strlen(module)) == 0)
{
if (buffer[strlen(module)] == ' ')
{
result = 1;
goto EXIT;
}
}
}
EXIT:
fclose(file);
return result;
}
int _replace_string(char string[], char *from, char *to)
{
int fromlen = strlen(from);
int tolen = strlen(to);
char *start, *p1, *p2;
for(start = string; *start != '\0'; start++)
{
p1 = from;
p2 = start;
while(*p1 != '\0')
{
if(*p1 != *p2)
break;
p1++;
p2++;
}
if(*p1 == '\0')
{
if(fromlen != tolen)
{
memmove(start + tolen, start + fromlen,
strlen(start + fromlen) + 1);
}
for(p1 = to; *p1 != '\0'; p1++)
*start++ = *p1;
return 1;
}
}
return 0;
}
int replace(char filename1[], char *from, char *to)
{
FILE *file1, *file2;
char filename2[1000];
char temp[1000];
int ret = 0;
/* Open the source and destination files */
strcpy (filename2, filename1);
strcat (filename2, ".new");
if (!(file1 = fopen (filename1, "r"))) return 1;
if (!(file2 = fopen (filename2, "w"))) {
fclose(file1);
return -1;
}
/* Start reading in lines */
while (fgets (temp, 1000, file1) != NULL) {
if (strlen(to) > 0) {
/* Replace string */
ret = _replace_string (temp, from, to);
/* Write string to new file */
fputs(temp, file2);
} else {
/* Remove string when to is NULL */
if (!strstr(temp, from))
fputs(temp, file2);
}
}
/* Close source and destination */
fclose (file1);
fclose (file2);
/* Move the file */
rename (filename2, filename1);
return (ret);
}
/* Include enabled languages */
#ifdef LANG_EN_ONLY
#include "lang_en.c"
#else
#include "lang_bz.c"
#include "lang_cs.c"
#include "lang_da.c"
#include "lang_de.c"
#include "lang_en.c"
#include "lang_es.c"
#include "lang_fi.c"
#include "lang_fr.c"
#include "lang_el.c"
#include "lang_it.c"
#include "lang_hu.c"
#include "lang_la.c"
#include "lang_nl.c"
#include "lang_no.c"
#include "lang_pl.c"
#include "lang_pt.c"
#include "lang_sk.c"
#include "lang_so.c"
#include "lang_sv.c"
#include "lang_tr.c"
#include "lang_vi.c"
#endif
// returns a pointer to the actual running version number of IPCop.
// Successive updates increase effective version but not VERSION !
char g_title[STRING_SIZE] = "";
char* get_version(void) {
FILE *f_title;
if ((f_title = fopen ("/etc/issue", "r"))) {
fgets (g_title, STRING_SIZE, f_title);
fclose (f_title);
if (g_title[strlen(g_title) - 1] == '\n') g_title[strlen(g_title) - 1] = '\0';
} else {
sprintf (g_title, "%s v%s - %s", NAME, VERSION, SLOGAN);
}
return g_title;
}

View File

@@ -0,0 +1,13 @@
#!/usr/bin/perl
#
# $Id: makelangs.pl,v 1.4 2003/12/11 11:25:53 riddles Exp $
#
# Used to process lang_en.c and build the enum type from comments embeded
# within said source file.
while (<>)
{
if (/\/\* (TR_[A-Z0-9_]*)/) {
print "\t$1,\n"; }
}
print "};\n";

View File

@@ -0,0 +1,638 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains network library functions.
*
* $Id: netstuff.c,v 1.19.2.7 2004/11/05 23:40:17 alanh Exp $
*
*/
#include "libsmooth.h"
#include <signal.h>
extern FILE *flog;
extern char *mylog;
extern char **ctr;
newtComponent networkform;
newtComponent addressentry;
newtComponent netmaskentry;
newtComponent statictyperadio;
newtComponent dhcptyperadio;
newtComponent pppoetyperadio;
newtComponent pptptyperadio;
newtComponent dhcphostnameentry;
/* acceptable character filter for IP and netmaks entry boxes */
static int ip_input_filter(newtComponent entry, void * data, int ch, int cursor)
{
if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '\r' || ch >= NEWT_KEY_EXTRA_BASE)
return ch;
return 0;
}
/* This is a groovie dialog for showing network info. Takes a keyvalue list,
* a colour and a dhcp flag. Shows the current settings, and rewrites them
* if necessary. DHCP flag sets wether to show the dhcp checkbox. */
int changeaddress(struct keyvalue *kv, char *colour, int typeflag,
char *defaultdhcphostname)
{
char *addressresult;
char *netmaskresult;
char *dhcphostnameresult;
struct newtExitStruct es;
newtComponent header;
newtComponent addresslabel;
newtComponent netmasklabel;
newtComponent dhcphostnamelabel;
newtComponent ok, cancel;
char message[1000];
char temp[STRING_SIZE];
char addressfield[STRING_SIZE];
char netmaskfield[STRING_SIZE];
char typefield[STRING_SIZE];
char dhcphostnamefield[STRING_SIZE];
int error;
int result = 0;
char type[STRING_SIZE];
int startstatictype = 0;
int startdhcptype = 0;
int startpppoetype = 0;
int startpptptype = 0;
/* Build some key strings. */
sprintf(addressfield, "%s_ADDRESS", colour);
sprintf(netmaskfield, "%s_NETMASK", colour);
sprintf(typefield, "%s_TYPE", colour);
sprintf(dhcphostnamefield, "%s_DHCP_HOSTNAME", colour);
sprintf(message, ctr[TR_INTERFACE], colour);
newtCenteredWindow(44, (typeflag ? 18 : 12), message);
networkform = newtForm(NULL, NULL, 0);
sprintf(message, ctr[TR_ENTER_THE_IP_ADDRESS_INFORMATION], colour);
header = newtTextboxReflowed(1, 1, message, 42, 0, 0, 0);
newtFormAddComponent(networkform, header);
/* See if we need a dhcp checkbox. If we do, then we shift the contents
* of the window down two rows to make room. */
if (typeflag)
{
strcpy(temp, "STATIC"); findkey(kv, typefield, temp);
if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;
if (strcmp(temp, "PPTP") == 0) startpptptype = 1;
statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL);
dhcptyperadio = newtRadiobutton(2, 5, "DHCP", startdhcptype, statictyperadio);
pppoetyperadio = newtRadiobutton(2, 6, "PPPOE", startpppoetype, dhcptyperadio);
pptptyperadio = newtRadiobutton(2, 7, "PPTP", startpptptype, pppoetyperadio);
newtFormAddComponents(networkform, statictyperadio, dhcptyperadio,
pppoetyperadio, pptptyperadio, NULL);
newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);
newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);
newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);
newtComponentAddCallback(pptptyperadio, networkdialogcallbacktype, NULL);
dhcphostnamelabel = newtTextbox(2, 9, 18, 1, 0);
newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]);
strcpy(temp, defaultdhcphostname);
findkey(kv, dhcphostnamefield, temp);
dhcphostnameentry = newtEntry(20, 9, temp, 20, &dhcphostnameresult, 0);
newtFormAddComponent(networkform, dhcphostnamelabel);
newtFormAddComponent(networkform, dhcphostnameentry);
if (startdhcptype == 0)
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
/* Address */
addresslabel = newtTextbox(2, (typeflag ? 11 : 4) + 0, 18, 1, 0);
newtTextboxSetText(addresslabel, ctr[TR_IP_ADDRESS_PROMPT]);
strcpy(temp, "");
findkey(kv, addressfield, temp);
addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
newtEntrySetFilter(addressentry, ip_input_filter, NULL);
if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtFormAddComponent(networkform, addresslabel);
newtFormAddComponent(networkform, addressentry);
/* Netmask */
netmasklabel = newtTextbox(2, (typeflag ? 11 : 4) + 1, 18, 1, 0);
newtTextboxSetText(netmasklabel, ctr[TR_NETMASK_PROMPT]);
strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtFormAddComponent(networkform, netmasklabel);
newtFormAddComponent(networkform, netmaskentry);
/* Buttons. */
ok = newtButton(8, (typeflag ? 14 : 7), ctr[TR_OK]);
cancel = newtButton(26, (typeflag ? 14 : 7), ctr[TR_CANCEL]);
newtFormAddComponents(networkform, ok, cancel, NULL);
newtRefresh();
newtDrawForm(networkform);
do
{
error = 0;
newtFormRun(networkform, &es);
if (es.u.co == ok)
{
/* OK was pressed; verify the contents of each entry. */
strcpy(message, ctr[TR_INVALID_FIELDS]);
strcpy(type, "STATIC");
if (typeflag)
gettype(type);
if (strcmp(type, "STATIC") == 0 || strcmp(type, "PPTP") == 0 )
{
if (inet_addr(addressresult) == INADDR_NONE)
{
strcat(message, ctr[TR_IP_ADDRESS_CR]);
error = 1;
}
if (inet_addr(netmaskresult) == INADDR_NONE)
{
strcat(message, ctr[TR_NETWORK_MASK_CR]);
error = 1;
}
}
if (strcmp(type, "DHCP") == 0)
{
if (!strlen(dhcphostnameresult))
{
strcat(message, ctr[TR_DHCP_HOSTNAME_CR]);
error = 1;
}
}
if (error)
errorbox(message);
else
{
/* No errors! Set new values, depending on dhcp flag etc. */
if (typeflag)
{
replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0)
{
replacekeyvalue(kv, addressfield, "0.0.0.0");
replacekeyvalue(kv, netmaskfield, "0.0.0.0");
}
else
{
replacekeyvalue(kv, addressfield, addressresult);
replacekeyvalue(kv, netmaskfield, netmaskresult);
}
replacekeyvalue(kv, typefield, type);
}
else
{
replacekeyvalue(kv, addressfield, addressresult);
replacekeyvalue(kv, netmaskfield, netmaskresult);
}
setnetaddress(kv, colour);
result = 1;
}
}
}
while (error);
newtFormDestroy(networkform);
newtPopWindow();
return result;
}
/* for pppoe: return string thats type STATIC, DHCP or PPPOE */
int gettype(char *type)
{
newtComponent selected = newtRadioGetCurrent(statictyperadio);
if (selected == statictyperadio)
strcpy(type, "STATIC");
else if (selected == dhcptyperadio)
strcpy(type, "DHCP");
else if (selected == pppoetyperadio)
strcpy(type, "PPPOE");
else if (selected == pptptyperadio)
strcpy(type, "PPTP");
else
strcpy(type, "ERROR");
return 0;
}
/* 0.9.9: calculates broadcast too. */
int setnetaddress(struct keyvalue *kv, char *colour)
{
char addressfield[STRING_SIZE];
char netaddressfield[STRING_SIZE];
char netmaskfield[STRING_SIZE];
char broadcastfield[STRING_SIZE];
char address[STRING_SIZE];
char netmask[STRING_SIZE];
unsigned long int intaddress;
unsigned long int intnetaddress;
unsigned long int intnetmask;
unsigned long int intbroadcast;
struct in_addr temp;
char *netaddress;
char *broadcast;
/* Build some key strings. */
sprintf(addressfield, "%s_ADDRESS", colour);
sprintf(netaddressfield, "%s_NETADDRESS", colour);
sprintf(netmaskfield, "%s_NETMASK", colour);
sprintf(broadcastfield, "%s_BROADCAST", colour);
strcpy(address, ""); findkey(kv, addressfield, address);
strcpy(netmask, ""); findkey(kv, netmaskfield, netmask);
/* Calculate netaddress. Messy.. */
intaddress = inet_addr(address);
intnetmask = inet_addr(netmask);
intnetaddress = intaddress & intnetmask;
temp.s_addr = intnetaddress;
netaddress = inet_ntoa(temp);
replacekeyvalue(kv, netaddressfield, netaddress);
intbroadcast = intnetaddress | ~intnetmask;
temp.s_addr = intbroadcast;
broadcast = inet_ntoa(temp);
replacekeyvalue(kv, broadcastfield, broadcast);
return 1;
}
/* Called when dhcp flag is toggled. Toggle disabled state of other 3
* controls. */
void networkdialogcallbacktype(newtComponent cm, void *data)
{
char type[STRING_SIZE];
gettype(type);
if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0 )
{
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
else
{
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
}
if (strcmp(type, "DHCP") == 0)
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
else
newtEntrySetFlags(dhcphostnameentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtRefresh();
newtDrawForm(networkform);
}
int interfacecheck(struct keyvalue *kv, char *colour)
{
char temp[STRING_SIZE];
char colourfields[NETCHANGE_TOTAL][STRING_SIZE];
int c;
sprintf(colourfields[ADDRESS], "%s_ADDRESS", colour);
sprintf(colourfields[NETADDRESS], "%s_NETADDRESS", colour);
sprintf(colourfields[NETMASK], "%s_NETMASK", colour);
for (c = 0; c < 3; c++)
{
strcpy(temp, ""); findkey(kv, colourfields[c], temp);
if (!(strlen(temp))) return 0;
}
return 1;
}
/* Network probing! */
struct nic nics[] = {
{ "100VG-AnyLan Network Adapters, HP J2585B, J2585A, etc", "hp100" },
{ "3Com EtherLink III", "3c509" },
{ "3Com 3c501", "3c501" },
{ "3Com ISA EtherLink XL", "3c515" },
{ "3Com 3c503 and 3c503/16", "3c503" },
{ "3Com EtherLink MC (3c523)", "3c523" },
{ "3Com EtherLink MC/32 (3c527)", "3c527" },
{ "3Com EtherLink Plus (3c505)", "3c505" },
{ "3Com EtherLink 16", "3c507" },
{ "3Com \"Corkscrew\" EtherLink PCI III/XL, etc.", "3c59x" },
{ "3Com Typhoon Family (3C990, 3CR990, and variants)", "typhoon" },
{ "Adaptec Starfire/DuraLAN", "starfire" },
{ "Alteon AceNIC/3Com 3C985/Netgear GA620 Gigabit", "acenic" },
{ "AMD8111 based 10/100 Ethernet Controller", "amd8111e" },
{ "AMD LANCE/PCnetAllied Telesis AT1500, J2405A, etc", "lance" },
{ "AMD PCnet32 and AMD PCnetPCI", "pcnet32" },
{ "Ansel Communications EISA 3200", "ac3200" },
{ "Apricot 680x0 VME, 82596 chipset", "82596" },
{ "AT1700/1720", "at1700" },
{ "Broadcom 4400", "b44" },
{ "Broadcom Tigon3", "tg3" },
{ "Cabletron E2100 series ethercards", "e2100" },
{ "CATC USB NetMate-based Ethernet", "catc" },
{ "CDC USB Ethernet", "CDCEther" },
{ "Crystal LAN CS8900/CS8920", "cs89x0" },
{ "Compaq Netelligent 10/100 TX PCI UTP, etc", "tlan" },
{ "D-Link DL2000-based Gigabit Ethernet", "dl2k" },
{ "Digi Intl. RightSwitch SE-X EISA and PCI", "dgrs" },
{ "Digital 21x4x Tulip PCI ethernet cards, etc.", "tulip" },
{ "Digital DEPCA & EtherWORKS,DEPCA, DE100, etc", "depca" },
{ "DM9102 PCI Fast Ethernet Adapter", "dmfe", },
{ "Dummy Network Card (testing)", "dummy", },
{ "EtherWORKS DE425 TP/COAX EISA, DE434 TP PCI, etc.", "de4x5" },
{ "EtherWORKS 3 (DE203, DE204 and DE205)", "ewrk3" },
{ "HP PCLAN/plus", "hp-plus" },
{ "HP LAN ethernet", "hp" },
{ "IBM LANA", "ibmlana" },
{ "ICL EtherTeam 16i/32" ,"eth16i" },
{ "Intel i82557/i82558 PCI EtherExpressPro", "e100" },
{ "Intel EtherExpress Cardbus Ethernet", "eepro100_cb" },
{ "Intel i82595 ISA EtherExpressPro10/10+ driver" ,"eepro" },
{ "Intel EtherExpress 16 (i82586)", "eexpress" },
{ "Intel Panther onboard i82596 driver", "lp486e" },
{ "Intel PRO/1000 Gigabit Ethernet", "e1000" },
{ "KLSI USB KL5USB101-based", "kaweth" },
{ "MiCom-Interlan NI5010 ethercard", "ni5010" },
{ "Mylex EISA LNE390A/B", "lne390", },
{ "Myson MTD-8xx PCI Ethernet", "fealnx" },
{ "National Semiconductor DP8381x" , "natsemi" },
{ "National Semiconductor DP83820" , "ns83820" },
{ "NE/2 MCA", "ne2" },
{ "NE2000 PCI cards, RealTEk RTL-8029, etc", "ne2k-pci" },
{ "NE1000 / NE2000 (non-pci)", "ne" },
{ "NI50 card (i82586 Ethernet chip)", "ni52" },
{ "NI6510, ni6510 EtherBlaster", "ni65" },
{ "Novell/Eagle/Microdyne NE3210 EISA", "ne3210" },
{ "NVidia Nforce2 Driver", "forcedeth" },
{ "Packet Engines Hamachi GNIC-II", "hamachi" },
{ "Packet Engines Yellowfin Gigabit-NIC", "yellowfin" },
{ "Pegasus/Pegasus-II USB ethernet", "pegasus" },
{ "PureData PDUC8028,WD8003 and WD8013 compatibles", "wd" },
{ "Racal-Interlan EISA ES3210", "es3210" },
{ "RealTek RTL-8139 Fast Ethernet", "8139too" },
{ "RealTek RTL-8139C+ series 10/100 PCI Ethernet", "8139cp" },
{ "RealTek RTL-8150 USB ethernet", "rtl8150" },
{ "RealTek RTL-8169 Gigabit Ethernet", "r8169" },
{ "SiS 900 PCI", "sis900" },
{ "SKnet MCA", "sk_mca" },
{ "SMC 9000 series of ethernet cards", "smc9194" },
{ "SMC EtherPower II", "epic100" },
{ "SMC Ultra/EtherEZ ISA/PnP Ethernet", "smc-ultra" },
{ "SMC Ultra32 EISA Ethernet", "smc-ultra32" },
{ "SMC Ultra MCA Ethernet", "smc-mca" },
{ "Sundance Alta", "sundance" },
{ "SysKonnect SK-98xx", "sk98lin" },
{ "Toshiba TC35815 Ethernet", "tc35815" },
{ "Tulip chipset Cardbus Ethernet", "tulip_cb" },
{ "USB Ethernet", "usbnet" },
{ "VIA Rhine PCI Fast Ethernet, etc", "via-rhine" },
{ "Winbond W89c840 Ethernet", "winbond-840" },
{ "Xircom Cardbus Ethernet", "xircom_cb" },
{ "Xircom (tulip-like) Cardbus Ethernet", "xircom_tulip_cb" },
{ NULL, NULL }
};
/* Funky routine for loading all drivers (cept those are already loaded.). */
int probecards(char *driver, char *driveroptions)
{
int c = 0;
int n = 0;
char message[1000];
char commandstring[STRING_SIZE];
n = countcards();
/* PCMCIA Detection */
runcommandwithstatus("cardmgr -o",
ctr[TR_LOADING_PCMCIA]);
if (countcards() > n)
{
strcpy(driver, "pcmcia");
strcpy(driveroptions,"");
return 1;
}
/* Regular module detection */
while (nics[c].modulename)
{
/* Skip dummy driver during autoprobe as it always succeeds */
if (strncmp(nics[c].modulename, "dummy", strlen("dummy")))
{
if (!checkformodule(nics[c].modulename)) {
sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);
sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);
if (runcommandwithstatus(commandstring, message) == 0)
{
if (countcards() > n) {
strcpy(driver, nics[c].modulename);
strcpy(driveroptions, "");
return 1;
}
}
}
}
c++;
}
strcpy(driver, "");
strcpy(driveroptions, "");
return 0;
}
/* A listbox for selected the card... with a * MANUAL * entry at top for
* manual module names. */
int choosecards(char *driver, char *driveroptions)
{
int c;
char **sections;
int drivercount;
int rc;
int choice;
char commandstring[STRING_SIZE];
char message[STRING_SIZE];
int done = 0;
/* Count 'em */
c = 0; drivercount = 0;
while (nics[c].modulename)
{
drivercount++;
c++;
}
drivercount++;
sections = malloc((drivercount + 1) * sizeof(char *));
/* Copy 'em. */
c = 0;
sections[c] = ctr[TR_MANUAL];
c++;
while (nics[c - 1].modulename)
{
sections[c] = nics[c - 1].description;
c++;
}
sections[c] = NULL;
strcpy(driver, "");
strcpy(driveroptions, "");
done = 0; choice = 1;
while (!done)
{
rc = newtWinMenu(ctr[TR_SELECT_NETWORK_DRIVER],
ctr[TR_SELECT_NETWORK_DRIVER_LONG], 50, 5, 5, 6,
sections, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 0 || rc == 1)
{
if (choice > 0)
{
/* Find module number, load module. */
c = choice - 1;
if (!checkformodule(nics[c].modulename))
{
sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);
sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);
if (runcommandwithstatus(commandstring, message) == 0)
{
strcpy(driver, nics[c].modulename);
strcpy(driveroptions, "");
done = 1;
}
else
errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);
}
else
errorbox(ctr[TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED]);
}
else
{
manualdriver(driver, driveroptions);
if (strlen(driver))
done = 1;
}
}
else
done = 1;
}
return 1;
}
/* Manual entry for gurus. */
int manualdriver(char *driver, char *driveroptions)
{
char *values[] = { NULL, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
int rc;
char commandstring[STRING_SIZE];
char *driverend;
strcpy(driver, "");
strcpy(driveroptions, "");
rc = newtWinEntries(ctr[TR_SELECT_NETWORK_DRIVER],
ctr[TR_MODULE_PARAMETERS], 50, 5, 5, 40, entries,
ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 0 || rc == 1)
{
if (strlen(values[0]))
{
sprintf(commandstring, "/sbin/modprobe %s", values[0]);
if (runcommandwithstatus(commandstring, ctr[TR_LOADING_MODULE]) == 0)
{
if ((driverend = strchr(values[0], ' ')))
{
*driverend = '\0';
strcpy(driver, values[0]);
strcpy(driveroptions, driverend + 1);
}
else
{
strcpy(driver, values[0]);
strcpy(driveroptions, "");
}
}
else
errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);
}
else
errorbox(ctr[TR_MODULE_NAME_CANNOT_BE_BLANK]);
}
free(values[0]);
return 1;
}
/* Returns the total number of nics current available as ethX devices. */
int countcards(void)
{
FILE *file;
char buffer[STRING_SIZE];
char *start;
int niccount = 0;
if (!(file = fopen("/proc/net/dev", "r")))
{
fprintf(flog, "Unable to open /proc/net/dev in countnics()\n");
return 0;
}
while (fgets(buffer, STRING_SIZE, file))
{
start = buffer;
while (*start == ' ') start++;
if (strncmp(start, "eth", strlen("eth")) == 0)
niccount++;
if (strncmp(start, "dummy", strlen("dummy")) == 0)
niccount++;
}
fclose(file);
return niccount;
}
/* Finds the listed module name and copies the card description back. */
int findnicdescription(char *modulename, char *description)
{
int c = 0;
if (strcmp(modulename, "pcmcia") == 0) {
strcpy(description, "PCMCIA Ethernet card");
return 0;
}
while (nics[c].description)
{
if (strcmp(nics[c].modulename, modulename) == 0)
{
strcpy(description, nics[c].description);
return 1;
}
c++;
}
strcpy(description, "UNKNOWN");
return 0;
}

View File

@@ -0,0 +1,199 @@
/* SmoothWall libsmooth.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains functions for manipulation files full of VAR=VAL pairs.
*
* 2003-07-27 Robert Kerr - Added cooperative file locking to prevent any
* clashes between setuid programs reading configuration and cgi scripts
* trying to write it
*
* $Id: varval.c,v 1.4 2003/12/11 11:25:53 riddles Exp $
*
*/
#include "libsmooth.h"
/* Sets up the list. First entry is a dummy one to avoid having to special
* case empty lists. */
struct keyvalue *initkeyvalues(void)
{
struct keyvalue *head = malloc(sizeof(struct keyvalue));
strcpy(head->key, "KEY");
strcpy(head->value, "VALUE");
head->next = NULL;
return head;
}
/* Splats all the entries in a list. */
void freekeyvalues(struct keyvalue *head)
{
struct keyvalue *cur = head->next;
struct keyvalue *next;
while (cur)
{
next = cur->next;
free(cur);
cur = next;
}
}
/* Reads from a file into a new list. Uses appendkeyvalue to add entries.
* Will bomb out on a error (eg bad format line). */
int readkeyvalues(struct keyvalue *head, char *filename)
{
FILE *file;
char buffer[STRING_SIZE];
char *temp;
char *key, *value;
if (!(file = fopen(filename, "r")))
return 0;
if (flock(fileno(file), LOCK_SH))
{
fclose(file);
return 0;
}
while (fgets(buffer, STRING_SIZE, file))
{
temp = buffer;
while (*temp)
{
if (*temp =='\n') *temp = '\0';
temp++;
}
if (!strlen(buffer))
continue;
if (!(temp = strchr(buffer, '=')))
{
flock(fileno(file), LOCK_UN);
fclose(file);
return 0;
}
*temp = '\0';
key = buffer; value = temp + 1;
/* See if string is quoted. If so, skip first quote, and
* nuke the one at the end. */
if (value[0] == '\'')
{
value++;
if ((temp = strrchr(value, '\'')))
*temp = '\0';
else
{
flock(fileno(file), LOCK_UN);
fclose(file);
return 0;
}
}
if (strlen(key))
appendkeyvalue(head, key, value);
}
flock(fileno(file), LOCK_UN);
fclose(file);
return 1;
}
/* Writes out a list to a file. Easy. */
int writekeyvalues(struct keyvalue *head, char *filename)
{
FILE *file;
struct keyvalue *cur = head->next;
if (!(file = fopen(filename, "w")))
return 0;
if (flock(fileno(file), LOCK_EX))
{
fclose(file);
return 0;
}
while (cur)
{
/* No space in value? If there is, we need to quote the value
* so the shell can read it. */
if (!strchr(cur->value, ' '))
fprintf(file, "%s=%s\n", cur->key, cur->value);
else
fprintf(file, "%s=\'%s\'\n", cur->key, cur->value);
cur = cur->next;
}
flock(fileno(file), LOCK_UN);
fclose(file);
return 1;
}
/* Finds a key and copies the value back. value must be at least STRING_SIZE
* long. Would be nice to have a func that just returns a pointer to the value?
*/
int findkey(struct keyvalue *head, char *key, char *value)
{
struct keyvalue *cur = head->next;
while (cur)
{
if (strcmp(key, cur->key) == 0)
{
strncpy(value, cur->value, STRING_SIZE);
value[STRING_SIZE-1] = '\0';
return 1;
}
cur = cur->next;
}
return 0;
}
/* Appends a entry. Not very efficent because it rescans the list looking
* for the end. Maybe fix this later. */
void appendkeyvalue(struct keyvalue *head, char *key, char *value)
{
struct keyvalue *new = malloc(sizeof(struct keyvalue));
struct keyvalue *cur = head->next;
struct keyvalue *tail = head;
strncpy(new->key, key, STRING_SIZE);
strncpy(new->value, value, STRING_SIZE);
new->key[STRING_SIZE-1] = '\0';
new->value[STRING_SIZE-1] = '\0';
new->next = NULL;
while (cur)
{
tail = cur;
cur = cur->next;
}
tail->next = new;
}
/* Otherwrites a key with a new value, or if it dosn't exist, appends it
* on the end. */
void replacekeyvalue(struct keyvalue *head, char *key, char *value)
{
struct keyvalue *cur = head->next;
while (cur)
{
if (strcmp(cur->key, key) == 0)
{
strncpy(cur->value, value, STRING_SIZE);
cur->value[STRING_SIZE-1] = '\0';
return;
}
cur = cur->next;
}
appendkeyvalue(head, key, value);
}

View File

@@ -0,0 +1,13 @@
/Makefile/1.3/Thu Dec 11 11:25:54 2003//TIPCOP_v1_4_0
/dhcp.c/1.9.2.3/Fri Dec 3 06:46:50 2004//TIPCOP_v1_4_0
/domainname.c/1.7.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
/hostname.c/1.6.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
/isdn.c/1.6.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
/keymap.c/1.9.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
/main.c/1.4.2.7/Thu Dec 1 20:13:08 2005//TIPCOP_v1_4_0
/misc.c/1.5.2.3/Thu Aug 25 17:51:42 2005//TIPCOP_v1_4_0
/networking.c/1.5.2.6/Mon Feb 6 22:00:13 2006//TIPCOP_v1_4_0
/passwords.c/1.5.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
/setup.h/1.4/Thu Dec 11 11:25:54 2003//TIPCOP_v1_4_0
/timezone.c/1.4.2.1/Wed Apr 14 22:05:41 2004//TIPCOP_v1_4_0
D

View File

@@ -0,0 +1 @@
ipcop/src/install+setup/setup

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop

View File

@@ -0,0 +1 @@
TIPCOP_v1_4_0

View File

@@ -0,0 +1,33 @@
#
# $Id: Makefile,v 1.3 2003/12/11 11:25:54 riddles Exp $
#
CC = gcc
CFLAGS = -O2 -Wall
INCLUDE =
LD = gcc
LDFLAGS =
LIBS = -lnewt -lslang
COMPILE = $(CC) -c $(INCLUDE) $(CFLAGS)
LINK = $(LD) $(LDFLAGS)
all : programs
programs : setup
clean :
-rm -f *.o setup core
######
OBJS=main.o hostname.o domainname.o passwords.o isdn.o networking.o misc.o \
dhcp.o keymap.o timezone.o ../libsmooth/libsmooth.o
setup: $(OBJS)
$(LINK) $(OBJS) -o $@ $(LIBS)
%.o : %.c
$(COMPILE) $< -o $@

View File

@@ -0,0 +1,262 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Stuff for setting up the DHCP server from the setup prog.
*
* $Id: dhcp.c,v 1.9.2.3 2004/12/03 06:46:50 eoberlander Exp $
*
*/
#include "setup.h"
#define TOP 4
#define START_ADDRESS 0
#define END_ADDRESS 1
#define PRIMARY_DNS 2
#define SECONDARY_DNS 3
#define DEFAULT_LEASE_TIME 4
#define MAX_LEASE_TIME 5
#define DOMAIN_NAME_SUFFIX 6
#define MAX_BOXES 7
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
newtComponent dhcpform;
newtComponent entries[MAX_BOXES];
newtComponent enabledcheckbox;
void dhcpdialogcallbackdhcp(newtComponent cm, void *data);
int handledhcp(void)
{
char *results[MAX_BOXES];
char enabledresult;
char startenabled;
struct newtExitStruct es;
newtComponent header;
newtComponent labels[MAX_BOXES];
newtComponent ok, cancel;
char message[1000];
char *labeltexts[MAX_BOXES] = { ctr[TR_START_ADDRESS], ctr[TR_END_ADDRESS],
ctr[TR_PRIMARY_DNS], ctr[TR_SECONDARY_DNS], ctr[TR_DEFAULT_LEASE],
ctr[TR_MAX_LEASE], ctr[TR_DOMAIN_NAME_SUFFIX] };
char *varnames[MAX_BOXES] = { "START_ADDR_GREEN", "END_ADDR_GREEN",
"DNS1_GREEN", "DNS2_GREEN",
"DEFAULT_LEASE_TIME_GREEN", "MAX_LEASE_TIME_GREEN",
"DOMAIN_NAME_GREEN"};
char defaults[MAX_BOXES][STRING_SIZE];
int result;
int c;
char temp[STRING_SIZE];
struct keyvalue *mainkv = initkeyvalues();
struct keyvalue *dhcpkv = initkeyvalues();
struct keyvalue *ethernetkv = initkeyvalues();
int error;
FILE *file;
char greenaddress[STRING_SIZE];
char greennetaddress[STRING_SIZE];
char greennetmask[STRING_SIZE];
memset(defaults, 0, sizeof(char) * STRING_SIZE * MAX_BOXES);
if (!(readkeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings")))
{
freekeyvalues(dhcpkv);
freekeyvalues(ethernetkv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
if (!(readkeyvalues(ethernetkv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(dhcpkv);
freekeyvalues(ethernetkv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
{
freekeyvalues(dhcpkv);
freekeyvalues(ethernetkv);
freekeyvalues(mainkv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
/* Set default values. */
findkey(ethernetkv, "GREEN_ADDRESS", defaults[PRIMARY_DNS]);
findkey(mainkv, "DOMAINNAME", defaults[DOMAIN_NAME_SUFFIX]);
strcpy(defaults[DEFAULT_LEASE_TIME], "60");
strcpy(defaults[MAX_LEASE_TIME], "120");
sprintf(message, ctr[TR_DHCP_SERVER_CONFIGURATION]);
newtCenteredWindow(55, 18, message);
dhcpform = newtForm(NULL, NULL, 0);
sprintf(message, ctr[TR_CONFIGURE_DHCP]);
header = newtTextboxReflowed(1, 1, message, 52, 0, 0, 0);
newtFormAddComponent(dhcpform, header);
strcpy(temp, ""); findkey(dhcpkv, "ENABLE_GREEN", temp);
if (strcmp(temp, "on") == 0)
startenabled = '*';
else
startenabled = ' ';
enabledcheckbox = newtCheckbox(2, TOP + 0, ctr[TR_ENABLED], startenabled, " *", &enabledresult);
newtFormAddComponent(dhcpform, enabledcheckbox);
newtComponentAddCallback(enabledcheckbox, dhcpdialogcallbackdhcp, NULL);
for (c = 0; c < MAX_BOXES; c++)
{
labels[c] = newtTextbox(2, TOP + 2 + c, 33, 1, 0);
newtTextboxSetText(labels[c], labeltexts[c]);
newtFormAddComponent(dhcpform, labels[c]);
strcpy(temp, defaults[c]); findkey(dhcpkv, varnames[c], temp);
entries[c] = newtEntry(34, TOP + 2 + c, temp, 18, &results[c], 0);
newtFormAddComponent(dhcpform, entries[c]);
if (startenabled == ' ')
newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
ok = newtButton(10, c + 7, ctr[TR_OK]);
cancel = newtButton(34, c + 7, ctr[TR_CANCEL]);
newtFormAddComponents(dhcpform, ok, cancel, NULL);
do
{
error = 0;
newtFormRun(dhcpform, &es);
if (es.u.co == ok)
{
/* OK was pressed; verify the contents of each entry. */
if (enabledresult == '*')
{
strcpy(message, ctr[TR_INVALID_FIELDS]);
if (inet_addr(results[START_ADDRESS]) == INADDR_NONE)
{
strcat(message, ctr[TR_START_ADDRESS_CR]);
error = 1;
}
if (inet_addr(results[END_ADDRESS]) == INADDR_NONE)
{
strcat(message, ctr[TR_END_ADDRESS_CR]);
error = 1;
}
if (strlen(results[SECONDARY_DNS]))
{
if (inet_addr(results[PRIMARY_DNS]) == INADDR_NONE)
{
strcat(message, ctr[TR_PRIMARY_DNS_CR]);
error = 1;
}
}
if (strlen(results[SECONDARY_DNS]))
{
if (inet_addr(results[SECONDARY_DNS]) == INADDR_NONE)
{
strcat(message, ctr[TR_SECONDARY_DNS_CR]);
error = 1;
}
}
if (!(atol(results[DEFAULT_LEASE_TIME])))
{
strcat(message, ctr[TR_DEFAULT_LEASE_CR]);
error = 1;
}
if (!(atol(results[MAX_LEASE_TIME])))
{
strcat(message, ctr[TR_MAX_LEASE_CR]);
error = 1;
}
}
if (error)
errorbox(message);
else
{
for (c = 0; c < MAX_BOXES; c++)
replacekeyvalue(dhcpkv, varnames[c], results[c]);
if (enabledresult == '*')
{
replacekeyvalue(dhcpkv, "ENABLE_GREEN", "on");
fclose(fopen(CONFIG_ROOT "/dhcp/enable_green", "w"));
chown(CONFIG_ROOT "/dhcp/enable_green", 99, 99);
}
else
{
replacekeyvalue(dhcpkv, "ENABLE_GREEN", "off");
unlink(CONFIG_ROOT "/dhcp/enable_green");
}
replacekeyvalue(dhcpkv, "VALID", "yes");
writekeyvalues(dhcpkv, CONFIG_ROOT "/dhcp/settings");
findkey(ethernetkv, "GREEN_ADDRESS", greenaddress);
findkey(ethernetkv, "GREEN_NETADDRESS", greennetaddress);
findkey(ethernetkv, "GREEN_NETMASK", greennetmask);
file = fopen(CONFIG_ROOT "/dhcp/dhcpd.conf", "w");
fprintf(file, "ddns-update-style none;\n");
fprintf(file, "subnet %s netmask %s\n", greennetaddress, greennetmask);
fprintf(file, "{\n");
fprintf(file, "\toption subnet-mask %s;\n", greennetmask);
fprintf(file, "\toption domain-name \"%s\";\n", results[DOMAIN_NAME_SUFFIX]);
fprintf(file, "\toption routers %s;\n", greenaddress);
if (strlen(results[PRIMARY_DNS]))
{
fprintf(file, "\toption domain-name-servers ");
fprintf(file, "%s", results[PRIMARY_DNS]);
if (strlen(results[SECONDARY_DNS]))
fprintf(file, ", %s", results[SECONDARY_DNS]);
fprintf(file, ";\n");
}
fprintf(file, "\trange %s %s;\n", results[START_ADDRESS], results[END_ADDRESS]);
fprintf(file, "\tdefault-lease-time %d;\n", (int) atol(results[DEFAULT_LEASE_TIME]) * 60);
fprintf(file, "\tmax-lease-time %d;\n", (int) atol(results[MAX_LEASE_TIME]) * 60);
fprintf(file, "}\n");
fclose(file);
chown(CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
if (automode == 0)
mysystem("/usr/local/bin/restartdhcp");
}
result = 1;
}
else
result = 0;
}
while (error);
newtFormDestroy(dhcpform);
newtPopWindow();
freekeyvalues(dhcpkv);
freekeyvalues(ethernetkv);
freekeyvalues(mainkv);
return result;
}
/* Called when enabled flag is toggled. Toggle disabled state of other 3
* controls. */
void dhcpdialogcallbackdhcp(newtComponent cm, void *data)
{
int c;
for (c = 0; c < MAX_BOXES; c++)
newtEntrySetFlags(entries[c], NEWT_FLAG_DISABLED, NEWT_FLAGS_TOGGLE);
newtRefresh();
newtDrawForm(dhcpform);
}

View File

@@ -0,0 +1,72 @@
/* IPCop setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* $Id: domainname.c
*
*/
#include "setup.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
int handledomainname(void)
{
char domainname[STRING_SIZE] = "localdomain";
struct keyvalue *kv = initkeyvalues();
char *values[] = { domainname, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
int rc;
int result;
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
findkey(kv, "DOMAINNAME", domainname);
for (;;)
{
rc = newtWinEntries(ctr[TR_DOMAINNAME], ctr[TR_ENTER_DOMAINNAME],
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 1)
{
strcpy(domainname, values[0]);
if (!(strlen(domainname)))
errorbox(ctr[TR_DOMAINNAME_CANNOT_BE_EMPTY]);
else if (strchr(domainname, ' '))
errorbox(ctr[TR_DOMAINNAME_CANNOT_CONTAIN_SPACES]);
else if (strlen(domainname) != strspn(domainname,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."))
errorbox(ctr[TR_DOMAINNAME_NOT_VALID_CHARS]);
else
{
replacekeyvalue(kv, "DOMAINNAME", domainname);
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
writehostsfiles();
result = 1;
break;
}
}
else
{
result = 0;
break;
}
}
free(values[0]);
freekeyvalues(kv);
return result;
}

View File

@@ -0,0 +1,76 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Stuff for setting the hostname.
*
* $Id: hostname.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
*
*/
#include "setup.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
int handlehostname(void)
{
char hostname[STRING_SIZE] = "";
struct keyvalue *kv = initkeyvalues();
char *values[] = { hostname, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
int rc;
int result;
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(hostname, SNAME);
findkey(kv, "HOSTNAME", hostname);
for (;;)
{
rc = newtWinEntries(ctr[TR_HOSTNAME], ctr[TR_ENTER_HOSTNAME],
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 1)
{
strcpy(hostname, values[0]);
if (!(strlen(hostname)))
errorbox(ctr[TR_HOSTNAME_CANNOT_BE_EMPTY]);
else if (strchr(hostname, ' '))
errorbox(ctr[TR_HOSTNAME_CANNOT_CONTAIN_SPACES]);
else if (strlen(hostname) != strspn(hostname,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))
errorbox(ctr[TR_HOSTNAME_NOT_VALID_CHARS]);
else
{
replacekeyvalue(kv, "HOSTNAME", hostname);
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
writehostsfiles();
result = 1;
break;
}
}
else
{
result = 0;
break;
}
}
free(values[0]);
freekeyvalues(kv);
return result;
}

View File

@@ -0,0 +1,581 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* ISDN probing.
*
* $Id: isdn.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
*
*/
#include "setup.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
struct card
{
char *name;
int type;
};
struct card cards[] = {
{ "", 0 },
{ "Teles 16.0", 1 },
{ "Teles 8.0", 2 },
{ "Teles 16.3 (non PnP)", 3 },
{ "Teles 16.3c", 14 },
{ "Teles PCI", 21 },
{ "Creatix/Teles PnP", 4 },
{ "AVM A1 (Fritz)", 5 },
{ "AVM ISA/PCI", 27 },
{ "AVM PCI/PNP (EXPERIMENTAL driver)", 999 },
{ "ELSA PCC/PCF cards", 6 },
{ "ELSA Quickstep 1000", 7 },
{ "ELSA Quickstep 1000PCI", 18 },
{ "Eicon Diva ISA Pnp and PCI", 11 },
{ "ASUS COM ISDNLink", 12 },
{ "HFC-2BS0 based cards", 13 },
{ "HFC 2BDS0 PCI", 35 },
{ "Sedlbauer cards", 15 },
{ "USR Sportster internal", 16 },
{ "MIC Card", 17 },
{ "Compaq ISDN S00 ISA", 19 },
{ "NETjet PCI card", 20 },
{ "Dr. Neuhauss Niccy ISA/PCI", 24 },
{ "Teles S0Box", 25 },
{ "Sedlbauer Speed Fax+", 28 },
{ "Siemens I-Surf 1.0", 29 },
{ "ACER P10", 30 },
{ "HST Saphir", 31 },
{ "Telekom A4T", 32 },
{ "Scitel Quadro", 33 },
{ "Gazel ISA/PCI", 34 },
{ "W6692 based PCI cards", 36 },
{ "ITK ix1-micro Rev.2", 9 },
{ "NETspider U PCI card", 38 },
{ "USB ST5481", 998 },
{ NULL, 0 }
};
void handleisdnprotocol(char **protocolnames);
int isdnenabledpressed(void);
int isdndisabledpressed(void);
void handleisdncard(void);
void handlemoduleparams(void);
int probeisdncard(void);
int probeusbisdncard(char *s);
void handleisdnmsn(void);
int handleisdn(void)
{
char *protocolnames[] = { ctr[TR_GERMAN_1TR6], ctr[TR_EURO_EDSS1],
ctr[TR_LEASED_LINE], ctr[TR_US_NI1], NULL };
struct keyvalue *kv;
int rc;
char protocolname[STRING_SIZE] = "";
char cardname[STRING_SIZE] = "";
char msn[STRING_SIZE] = "";
char temps[STRING_SIZE];
int tempd;
char message[1000];
int c;
char *sections[] = { ctr[TR_PROTOCOL_COUNTRY],
ctr[TR_SET_ADDITIONAL_MODULE_PARAMETERS], ctr[TR_ISDN_CARD],
ctr[TR_MSN_CONFIGURATION], NULL };
int choice;
char enableddisabled[STRING_SIZE];
FILE *f;
if ((f = fopen(CONFIG_ROOT "/red/active", "r")))
{
fclose(f);
errorbox(ctr[TR_RED_IN_USE]);
return 1;
}
/* rc.isdn is a small script to bring down ippp0 and kill ipppd
* and removes the ISDN modules. */
mysystem("/etc/rc.d/rc.isdn stop");
choice = 0;
for (;;)
{
kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(enableddisabled, ctr[TR_DISABLED]);
findkey(kv, "ENABLED", temps);
if (strcmp(temps, "on") == 0)
strcpy(enableddisabled, ctr[TR_ENABLED]);
strcpy(temps, "-1");
findkey(kv, "PROTOCOL", temps);
tempd = atol(temps);
if (tempd < 1 || tempd > 4)
strcpy(protocolname, ctr[TR_UNSET]);
else
strcpy(protocolname, protocolnames[tempd - 1]);
strcpy(temps, "-1");
findkey(kv, "TYPE", temps);
tempd = atol(temps);
c = 0;
while (cards[c].name)
{
if (cards[c].type == tempd)
{
strcpy(cardname, cards[c].name);
break;
}
c++;
}
if (!strlen(cardname))
strcpy(cardname, ctr[TR_UNSET]);
strcpy(temps, "");
findkey(kv, "MSN", temps);
if (strlen(temps))
strcpy(msn, temps);
else
strcpy(msn, ctr[TR_UNSET]);
sprintf(message, ctr[TR_ISDN_STATUS], enableddisabled, protocolname,
cardname, msn);
freekeyvalues(kv);
rc = newtWinMenu(ctr[TR_ISDN_CONFIGURATION_MENU], message, 50, 5, 5, 6,
sections, &choice, ctr[TR_OK], ctr[TR_ENABLE_ISDN],
ctr[TR_DISABLE_ISDN], NULL);
if (rc == 1 || rc == 0)
{
switch (choice)
{
case 0:
handleisdnprotocol(protocolnames);
break;
case 1:
handlemoduleparams();
break;
case 2:
handleisdncard();
break;
case 3:
handleisdnmsn();
break;
default:
break;
}
}
else if (rc == 2)
{
if (!isdnenabledpressed())
break;
}
else
{
if (!(isdndisabledpressed()))
break;
}
}
return 1;
}
/* Returns 0 if main ISDN setup loop should exit. */
int isdndisabledpressed(void)
{
struct keyvalue *kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
replacekeyvalue(kv, "ENABLED", "off");
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
freekeyvalues(kv);
return 0;
}
/* Returns 0 if main ISDN setup loop should exit. */
int isdnenabledpressed(void)
{
struct keyvalue *kv = initkeyvalues();
char protocol[STRING_SIZE] = "";
char type[STRING_SIZE] = "";
char msn[STRING_SIZE] = "";
char moduleparams[STRING_SIZE] = "";
char commandstring[STRING_SIZE];
int result = 0;
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
findkey(kv, "PROTOCOL", protocol);
findkey(kv, "TYPE", type);
findkey(kv, "MSN", msn);
findkey(kv, "MODULE_PARAMS", moduleparams);
if (strlen(protocol) && strlen(type) && strlen(msn))
{
if (atol(type) == 998)
{
sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=%s %s",
protocol, moduleparams);
}
else if (atol(type) == 999)
{
sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=%s %s",
protocol, moduleparams);
}
else
{
sprintf(commandstring, "/sbin/modprobe hisax protocol=%s type=%s %s",
protocol, type, moduleparams);
}
if (runcommandwithstatus(commandstring, ctr[TR_INITIALISING_ISDN]) != 0)
{
errorbox(ctr[TR_UNABLE_TO_INITIALISE_ISDN]);
replacekeyvalue(kv, "ENABLED", "off");
result = 1;
}
else
replacekeyvalue(kv, "ENABLED", "on");
}
else
{
errorbox(ctr[TR_ISDN_NOT_SETUP]);
replacekeyvalue(kv, "ENABLED", "off");
result = 1;
}
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
freekeyvalues(kv);
return result;
}
void handleisdnprotocol(char **protocolnames)
{
int rc;
int choice;
struct keyvalue *kv = initkeyvalues();
char temp[STRING_SIZE] = "1";
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return;
}
findkey(kv, "PROTOCOL", temp);
choice = atol(temp) - 1;
rc = newtWinMenu(ctr[TR_ISDN_PROTOCOL_SELECTION], ctr[TR_CHOOSE_THE_ISDN_PROTOCOL],
50, 5, 5, 6, protocolnames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 2)
return;
sprintf(temp, "%d", choice + 1);
replacekeyvalue(kv, "PROTOCOL", temp);
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
freekeyvalues(kv);
}
void handlemoduleparams(void)
{
struct keyvalue *kv = initkeyvalues();
char moduleparams[STRING_SIZE] = "";
char *values[] = { moduleparams, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
char title[STRING_SIZE];
int rc;
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return;
}
findkey(kv, "MODULE_PARAMS", moduleparams);
for (;;)
{
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
rc = newtWinEntries(title, ctr[TR_ENTER_ADDITIONAL_MODULE_PARAMS],
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 1)
{
replacekeyvalue(kv, "MODULE_PARAMS", values[0]);
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
free(values[0]);
break;
}
else
break;
}
freekeyvalues(kv);
}
void handleisdncard(void)
{
char **selection;
int c;
int rc;
int choice;
int type;
struct keyvalue *kv = initkeyvalues();
char temp[STRING_SIZE] = "0";
int card;
char message[STRING_SIZE];
char commandstring[STRING_SIZE];
char moduleparams[STRING_SIZE] = "";
int done = 0;
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return;
}
findkey(kv, "TYPE", temp);
type = atol(temp);
findkey(kv, "MODULE_PARAMS", moduleparams);
/* Count cards. */
c = 0;
while (cards[c].name) c++;
selection = malloc((c + 1) * sizeof(char *));
/* Fill out section. */
c = 0;
selection[c] = ctr[TR_AUTODETECT];
c++;
while (cards[c].name)
{
selection[c] = cards[c].name;
c++;
}
selection[c] = NULL;
/* Determine inital value for choice. */
c = 0; choice = 0;
while (cards[c].name)
{
if (cards[c].type == type)
{
choice = c;
break;
}
c++;
}
while (!done)
{
rc = newtWinMenu(ctr[TR_ISDN_CARD_SELECTION], ctr[TR_CHOOSE_THE_ISDN_CARD_INSTALLED],
50, 5, 5, 10, selection, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 2)
done = 1;
else
{
if (choice == 0)
card = probeisdncard();
else
{
sprintf(message, ctr[TR_CHECKING_FOR], cards[choice].name);
if (cards[choice].type == 998)
{
sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s",
moduleparams);
}
else if (cards[choice].type == 999)
{
sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=1 %s",
moduleparams);
}
else
{
sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s",
cards[choice].type, moduleparams);
}
if (runcommandwithstatus(commandstring, message) == 0)
card = cards[choice].type;
else
{
errorbox(ctr[TR_ISDN_CARD_NOT_DETECTED]);
card = -1;
}
mysystem("/etc/rc.d/rc.isdn stop");
}
if (card != -1)
{
sprintf(temp, "%d", card);
replacekeyvalue(kv, "TYPE", temp);
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
done = 1;
}
}
}
free(selection);
freekeyvalues(kv);
}
int probeusbisdncard(char *s)
{
FILE *file;
char buf[STRING_SIZE];
int found = 0;
if (!(file = fopen("/proc/bus/usb/devices", "r")))
{
fprintf(flog, "Unable to open /proc/bus/usb/devices in probeusbisdncard()\n");
return 0;
}
while (fgets(buf, STRING_SIZE, file)) {
if (strstr(buf, s)) {
found = 1;
}
}
fclose(file);
return found;
}
int probeisdncard(void)
{
int c;
char message[STRING_SIZE];
char commandstring[STRING_SIZE];
char moduleparams[STRING_SIZE] = "";
struct keyvalue *kv = initkeyvalues();
char title[STRING_SIZE];
int result = -1;
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return -1;
}
findkey(kv, "MODULE_PARAMS", moduleparams);
c = 1;
while (cards[c].name)
{
sprintf(message, ctr[TR_CHECKING_FOR], cards[c].name);
if (cards[c].type == 998)
{
/* Try to find if it exists, but should generalize
* probeusbisdncard to pass Vendor and ProdID
* independently, rather than a string
*/
if (probeusbisdncard("Vendor=0483 ProdID=481"))
sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s", moduleparams);
}
else if (cards[c].type == 999)
{
sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=1 %s",
moduleparams);
}
else
{
sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s",
cards[c].type, moduleparams);
}
if (runcommandwithstatus(commandstring, message) == 0)
{
mysystem("/etc/rc.d/rc.isdn stop");
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
sprintf(message, ctr[TR_DETECTED], cards[c].name);
newtWinMessage(title, ctr[TR_OK], message);
result = cards[c].type;
goto EXIT;
}
c++;
}
errorbox(ctr[TR_UNABLE_TO_FIND_AN_ISDN_CARD]);
EXIT:
freekeyvalues(kv);
return result;
}
void handleisdnmsn(void)
{
struct keyvalue *kv = initkeyvalues();
char msn[STRING_SIZE] = "";
char *values[] = { msn, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
char title[STRING_SIZE];
int rc;
if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return;
}
findkey(kv, "MSN", msn);
for (;;)
{
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
rc = newtWinEntries(title, ctr[TR_ENTER_THE_LOCAL_MSN],
50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 1)
{
if (!(strlen(values[0])))
errorbox(ctr[TR_PHONENUMBER_CANNOT_BE_EMPTY]);
else
{
replacekeyvalue(kv, "MSN", values[0]);
writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
free(values[0]);
break;
}
}
else
break;
}
freekeyvalues(kv);
}

View File

@@ -0,0 +1,167 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Stuff for setting the keymap.
*
* $Id: keymap.c,v 1.9.2.1 2004/04/14 22:05:41 gespinasse Exp $
*
*/
#include "setup.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
#define MAX_FILENAMES 5000
#define KEYMAPROOT "/usr/share/kbd/keymaps/i386/"
static int filenamecount;
static char *filenames[MAX_FILENAMES];
static char *displaynames[MAX_FILENAMES];
static int process(char *prefix, char *path);
static int cmp(const void *s1, const void *s2);
int handlekeymap(void)
{
int c;
int choice;
char *temp;
struct keyvalue *kv = initkeyvalues();
int rc;
int result;
char keymap[STRING_SIZE];
char commandstring[STRING_SIZE];
filenamecount = 0;
process(KEYMAPROOT "azerty", "");
process(KEYMAPROOT "dvorak", "");
process(KEYMAPROOT "fgGIod", "");
process(KEYMAPROOT "qwerty", "");
process(KEYMAPROOT "qwertz", "");
filenames[filenamecount] = NULL;
qsort(filenames, filenamecount, sizeof(char *), cmp);
for (c = 0; filenames[c]; c++)
{
displaynames[c] = malloc(STRING_SIZE);
if ((temp = strrchr(filenames[c], '/')))
strcpy(displaynames[c], temp + 1);
else
strcpy(displaynames[c], filenames[c]);
if ((temp = strstr(displaynames[c], ".map.gz")))
*temp = '\0';
}
displaynames[c] = NULL;
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(keymap, "/usr/share/kbd/keymaps/i386/qwerty/us.map.gz");
findkey(kv, "KEYMAP", keymap);
choice = 0;
for (c = 0; filenames[c]; c++)
{
if (strcmp(keymap, filenames[c]) == 0)
choice = c;
}
rc = newtWinMenu(ctr[TR_KEYBOARD_MAPPING], ctr[TR_KEYBOARD_MAPPING_LONG], 50, 5, 5, 6, displaynames, &choice,
ctr[TR_OK], ctr[TR_CANCEL], NULL);
strcpy(keymap, filenames[choice]);
if (rc != 2)
{
replacekeyvalue(kv, "KEYMAP", keymap);
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
sprintf(commandstring, "/bin/loadkeys %s", keymap);
mysystem(commandstring);
result = 1;
}
else
result = 0;
for (c = 0; filenames[c]; c++)
{
free(filenames[c]);
free(displaynames[c]);
}
freekeyvalues(kv);
return result;
}
static int process(char *prefix, char *path)
{
DIR *dir;
struct dirent *de;
char newpath[PATH_MAX];
snprintf(newpath, PATH_MAX, "%s%s", prefix, path);
if (!(dir = opendir(newpath)))
{
if (filenamecount > MAX_FILENAMES)
return 1;
filenames[filenamecount] = (char *) strdup(newpath);
filenamecount++;
return 0;
}
while ((de = readdir(dir)))
{
if (de->d_name[0] == '.') continue;
snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name);
process(prefix, newpath);
}
closedir(dir);
return 1;
}
/* Small wrapper for use with qsort() to sort filename part. */
static int cmp(const void *s1, const void *s2)
{
/* c1 and c2 are copies. */
char *c1 = strdup(* (char **) s1);
char *c2 = strdup(* (char **) s2);
/* point to somewhere in cN. */
char *f1, *f2;
char *temp;
int res;
if ((temp = strrchr(c1, '/')))
f1 = temp + 1;
else
f1 = c1;
if ((temp = strrchr(c2, '/')))
f2 = temp + 1;
else
f2 = c2;
/* bang off the . */
if ((temp = strchr(f1, '.')))
*temp = '\0';
if ((temp = strchr(f2, '.')))
*temp = '\0';
res = strcmp(f1, f2);
free(c1); free(c2);
return res;
}

View File

@@ -0,0 +1,229 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Contains main entry point, and misc functions.
*
* modified 16/11/2002 eoberlander - French language added
*
* $Id: main.c,v 1.4.2.7 2005/12/01 20:13:08 eoberlander Exp $
*
*/
#include "setup.h"
FILE *flog = NULL;
char *mylog;
char **ctr = NULL;
int automode = 0;
extern char *bz_tr[];
extern char *cs_tr[];
extern char *da_tr[];
extern char *en_tr[];
extern char *es_tr[];
extern char *fi_tr[];
extern char *fr_tr[];
extern char *hu_tr[];
extern char *la_tr[];
extern char *nl_tr[];
extern char *de_tr[];
extern char *tr_tr[];
extern char *it_tr[];
extern char *el_tr[];
extern char *sk_tr[];
extern char *so_tr[];
extern char *sv_tr[];
extern char *no_tr[];
extern char *pl_tr[];
extern char *pt_tr[];
extern char *vi_tr[];
int main(int argc, char *argv[])
{
#ifdef LANG_EN_ONLY
char *shortlangnames[] = { "en", NULL };
char **langtrs[] = { en_tr, NULL };
#else
char *shortlangnames[] = { "bz", "cs", "da", "de", "en", "es", "fr", "el", "it", "la", "hu", "nl", "no", "pl", "pt", "sk", "so", "fi", "sv", "tr", "vi", NULL };
char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL };
#endif
int choice;
char *sections[11]; /* need to fill this out AFTER knowning lang */
int rc;
struct keyvalue *kv;
char selectedshortlang[STRING_SIZE] = "en";
char title[STRING_SIZE];
int langcounter;
int autook = 0;
/* Log file/terminal stuff. */
if (argc >= 2)
mylog = argv[1];
else
mylog = strdup("/root/setup.log");
if (!(flog = fopen(mylog, "w+")))
{
printf("Couldn't open log terminal\n");
return 1;
}
if (argc >= 3)
automode = 1;
fprintf(flog, "Setup program started.\n");
kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
{
printf("%s is not properly installed.\n", NAME);
return 1;
}
findkey(kv, "LANGUAGE", selectedshortlang);
for (langcounter = 0; langtrs[langcounter]; langcounter++)
{
if (strcmp(selectedshortlang, shortlangnames[langcounter]) == 0)
{
ctr = langtrs[langcounter];
break;
}
}
if (!ctr)
{
/* zh,lt,ro,ru,th languages not available in setup, so use English */
for (choice = 0; shortlangnames[choice]; choice++)
{
if (strcmp(shortlangnames[choice], "en") == 0)
break;
}
if (!shortlangnames[choice])
goto EXIT;
ctr = langtrs[choice];
}
sections[0] = ctr[TR_KEYBOARD_MAPPING];
sections[1] = ctr[TR_TIMEZONE];
sections[2] = ctr[TR_HOSTNAME];
sections[3] = ctr[TR_DOMAINNAME];
sections[4] = ctr[TR_ISDN_CONFIGURATION];
sections[5] = ctr[TR_NETWORKING];
sections[6] = ctr[TR_ROOT_PASSWORD];
sections[7] = ctr[TR_ADMIN_PASSWORD];
sections[8] = NULL;
newtInit();
newtCls();
FILE *f_title;
if ((f_title = fopen ("/etc/issue", "r")))
{
fgets (title, STRING_SIZE, f_title);
if (title[strlen(title) - 1] == '\n')
title[strlen(title) - 1] = '\0';
fclose (f_title);
} else {
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
}
newtDrawRootText(14, 0, title);
newtPushHelpLine(ctr[TR_HELPLINE]);
if (automode == 0)
{
choice = 0;
for (;;)
{
rc = newtWinMenu(ctr[TR_SECTION_MENU],
ctr[TR_SELECT_THE_ITEM], 50, 5, 5, 11,
sections, &choice, ctr[TR_OK], ctr[TR_QUIT], NULL);
if (rc == 2)
break;
switch (choice)
{
case 0:
handlekeymap();
break;
case 1:
handletimezone();
break;
case 2:
handlehostname();
break;
case 3:
handledomainname();
break;
case 4:
handleisdn();
break;
case 5:
handlenetworking();
break;
case 6:
handlerootpassword();
break;
case 7:
handleadminpassword();
break;
default:
break;
}
}
}
else
{
if (!(handlekeymap()))
goto EXIT;
if (!(handletimezone()))
goto EXIT;
if (!(handlehostname()))
goto EXIT;
if (!(handledomainname()))
goto EXIT;
if (!(handleisdn()))
goto EXIT;
if (!(handlenetworking()))
goto EXIT;
if (!(handledhcp()))
goto EXIT;
if (!(handlerootpassword()))
goto EXIT;
if (!(handleadminpassword()))
goto EXIT;
autook = 1;
}
EXIT:
if (automode != 0)
{
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
if (autook)
newtWinMessage(title, ctr[TR_OK], ctr[TR_SETUP_FINISHED]);
else
newtWinMessage(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_SETUP_NOT_COMPLETE]);
}
fprintf(flog, "Setup program ended.\n");
fflush(flog);
fclose(flog);
newtFinished();
return 0;
}

View File

@@ -0,0 +1,141 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Misc. stuff for the lib.
*
* $Id: misc.c,v 1.5.2.3 2005/08/25 17:51:42 gespinasse Exp $
*
*/
#include "setup.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
/* This will rewrite /etc/hosts, /etc/hosts.*, and the apache ServerName file. */
int writehostsfiles(void)
{
char address[STRING_SIZE] = "";
char netaddress[STRING_SIZE] = "";
char netmask[STRING_SIZE] = "";
char message[1000];
FILE *file, *hosts;
struct keyvalue *kv;
char hostname[STRING_SIZE];
char domainname[STRING_SIZE] = "";
char commandstring[STRING_SIZE];
char buffer[STRING_SIZE];
kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
findkey(kv, "GREEN_ADDRESS", address);
findkey(kv, "GREEN_NETADDRESS", netaddress);
findkey(kv, "GREEN_NETMASK", netmask);
freekeyvalues(kv);
kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(hostname, SNAME );
findkey(kv, "HOSTNAME", hostname);
findkey(kv, "DOMAINNAME", domainname);
freekeyvalues(kv);
if (!(file = fopen(CONFIG_ROOT "/main/hostname.conf", "w")))
{
sprintf (message, ctr[TR_UNABLE_TO_WRITE_VAR_SMOOTHWALL_MAIN_HOSTNAMECONF], CONFIG_ROOT);
errorbox(message);
return 0;
}
fprintf(file, "ServerName %s.%s\n", hostname,domainname);
fclose(file);
if (!(file = fopen(CONFIG_ROOT "/main/hosts", "r")))
{
errorbox(ctr[TR_UNABLE_TO_OPEN_HOSTS_FILE]);
return 0;
}
if (!(hosts = fopen("/etc/hosts", "w")))
{
errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS]);
return 0;
}
fprintf(hosts, "127.0.0.1\tlocalhost\n");
if (strlen(domainname))
fprintf(hosts, "%s\t%s.%s\t%s\n",address,hostname,domainname,hostname);
else
fprintf(hosts, "%s\t%s\n",address,hostname);
while (fgets(buffer, STRING_SIZE, file))
{
char *token, *ip, *host, *domain;
buffer[strlen(buffer) - 1] = 0;
token = strtok(buffer, ",");
ip = strtok(NULL, ",");
host = strtok(NULL, ",");
domain = strtok(NULL, ",");
if (!(ip && host))
break;
if (strlen(ip) < 7 || strlen(ip) > 15
|| strspn(ip, "0123456789.") != strlen(ip))
break;
if (strspn(host, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-") != strlen(host))
break;
if (domain)
fprintf(hosts, "%s\t%s.%s\t%s\n",ip,host,domain,host);
else
fprintf(hosts, "%s\t%s\n",ip,host);
}
fclose(file);
fclose(hosts);
/* TCP wrappers stuff. */
if (!(file = fopen("/etc/hosts.deny", "w")))
{
errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS_DENY]);
return 0;
}
fprintf(file, "ALL : ALL\n");
fclose(file);
if (!(file = fopen("/etc/hosts.allow", "w")))
{
errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_HOSTS_ALLOW]);
return 0;
}
fprintf(file, "sshd : ALL\n");
fprintf(file, "ALL : localhost\n");
fprintf(file, "ALL : %s/%s\n", netaddress, netmask);
fclose(file);
sprintf(commandstring, "/bin/hostname %s.%s", hostname, domainname);
if (mysystem(commandstring))
{
errorbox(ctr[TR_UNABLE_TO_SET_HOSTNAME]);
return 0;
}
return 1;
}

View File

@@ -0,0 +1,806 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* The big one: networking.
*
* $Id: networking.c,v 1.5.2.6 2006/02/06 22:00:13 gespinasse Exp $
*
*/
#include "setup.h"
#define DNS1 0
#define DNS2 1
#define DEFAULT_GATEWAY 2
#define DNSGATEWAY_TOTAL 3
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
#define HAS_ORANGE (configtype == 1 || configtype == 3 || configtype == 5 || configtype == 7)
#define HAS_RED (configtype == 2 || configtype == 3 || configtype == 6 || configtype == 7)
#define HAS_BLUE (configtype == 4 || configtype == 5 || configtype == 6 || configtype == 7)
#define RED_IS_NOT_ETH (configtype == 0 || configtype == 1 || configtype == 4 || configtype == 5)
extern struct nic nics[];
char *configtypenames[] = {
"GREEN (RED is modem/ISDN)",
"GREEN + ORANGE (RED is modem/ISDN)",
"GREEN + RED",
"GREEN + ORANGE + RED",
"GREEN + BLUE (RED is modem/ISDN) ",
"GREEN + ORANGE + BLUE (RED is modem/ISDN)",
"GREEN + BLUE + RED",
"GREEN + ORANGE + BLUE + RED",
NULL };
int netaddresschange;
int oktoleave(char *errormessage);
int firstmenu(void);
int configtypemenu(void);
int drivermenu(void);
int changedrivers(void);
int greenaddressmenu(void);
int addressesmenu(void);
int dnsgatewaymenu(void);
int handlenetworking(void)
{
int done;
int choice;
char errormessage[STRING_SIZE];
netaddresschange = 0;
done = 0;
while (!done)
{
choice = firstmenu();
switch (choice)
{
case 1:
configtypemenu();
break;
case 2:
drivermenu();
break;
case 3:
addressesmenu();
break;
case 4:
dnsgatewaymenu();
break;
case 0:
if (oktoleave(errormessage))
done = 1;
else
errorbox(errormessage);
break;
default:
break;
}
}
if (automode == 0)
{
/* Restart networking! */
if (netaddresschange)
{
runcommandwithstatus("/etc/rc.d/rc.netaddress.down",
ctr[TR_PUSHING_NETWORK_DOWN]);
runcommandwithstatus("/etc/rc.d/rc.netaddress.up",
ctr[TR_PULLING_NETWORK_UP]);
mysystem("/etc/rc.d/rc.pcmcia start");
}
}
return 1;
}
int oktoleave(char *errormessage)
{
struct keyvalue *kv = initkeyvalues();
char temp[STRING_SIZE];
int configtype;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp); configtype = atol(temp);
if (configtype < 0 || configtype > 7) configtype = 0;
if (HAS_BLUE)
{
strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
if (!(strlen(temp)))
{
strcpy(errormessage, ctr[TR_NO_BLUE_INTERFACE]);
goto EXIT;
}
if (!(interfacecheck(kv, "BLUE")))
{
strcpy(errormessage, ctr[TR_MISSING_BLUE_IP]);
goto EXIT;
}
}
if (HAS_ORANGE)
{
strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
if (!(strlen(temp)))
{
strcpy(errormessage, ctr[TR_NO_ORANGE_INTERFACE]);
goto EXIT;
}
if (!(interfacecheck(kv, "ORANGE")))
{
strcpy(errormessage, ctr[TR_MISSING_ORANGE_IP]);
goto EXIT;
}
}
if (HAS_RED)
{
strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
if (!(strlen(temp)))
{
strcpy(errormessage, ctr[TR_NO_RED_INTERFACE]);
goto EXIT;
}
if (!(interfacecheck(kv, "RED")))
{
strcpy(errormessage, ctr[TR_MISSING_RED_IP]);
goto EXIT;
}
}
strcpy(errormessage, "");
EXIT:
freekeyvalues(kv);
if (strlen(errormessage))
return 0;
else
return 1;
}
/* Shows the main menu and a summary of the current settings. */
int firstmenu(void)
{
char *sections[] = { ctr[TR_NETWORK_CONFIGURATION_TYPE],
ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS],
ctr[TR_ADDRESS_SETTINGS],
ctr[TR_DNS_AND_GATEWAY_SETTINGS], NULL };
int rc;
static int choice = 0;
struct keyvalue *kv = initkeyvalues();
char message[1000];
char temp[STRING_SIZE];
int x;
int result;
char networkrestart[STRING_SIZE] = "";
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
if (netaddresschange)
strcpy(networkrestart, ctr[TR_RESTART_REQUIRED]);
strcpy(temp, ""); findkey(kv, "CONFIG_TYPE", temp); x = atol(temp);
if (x < 0 || x > 7) x = 0;
/* Format heading bit. */
snprintf(message, 1000, ctr[TR_CURRENT_CONFIG], configtypenames[x],
networkrestart);
rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_MENU], message, 50, 5, 5, 6,
sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
if (rc == 0 || rc == 1)
result = choice + 1;
else
result = 0;
return result;
}
/* Here they choose general network config, number of nics etc. */
int configtypemenu(void)
{
struct keyvalue *kv = initkeyvalues();
char temp[STRING_SIZE] = "0";
char message[1000];
int choice;
int rc;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
findkey(kv, "CONFIG_TYPE", temp); choice = atol(temp);
sprintf(message, ctr[TR_NETWORK_CONFIGURATION_TYPE_LONG], NAME);
rc = newtWinMenu(ctr[TR_NETWORK_CONFIGURATION_TYPE], message, 50, 5, 5,
6, configtypenames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 0 || rc == 1)
{
runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN",
ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
sprintf(temp, "%d", choice);
replacekeyvalue(kv, "CONFIG_TYPE", temp);
replacekeyvalue(kv, "ORANGE_DEV", "");
replacekeyvalue(kv, "BLUE_DEV", "");
replacekeyvalue(kv, "RED_DEV", "");
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
netaddresschange = 1;
}
freekeyvalues(kv);
return 0;
}
/* Driver menu. Choose drivers.. */
int drivermenu(void)
{
struct keyvalue *kv = initkeyvalues();
char message[1000];
char temp[STRING_SIZE], temp1[STRING_SIZE];
char driver[STRING_SIZE], dev[STRING_SIZE];
int configtype;
int rc;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
configtype = atol(temp);
if (configtype == 0)
{
freekeyvalues(kv);
errorbox(ctr[TR_YOUR_CONFIGURATION_IS_SINGLE_GREEN_ALREADY_HAS_DRIVER]);
return 0;
}
strcpy(message, ctr[TR_CONFIGURE_NETWORK_DRIVERS]);
/* This horrible big formats the heading :( */
strcpy(driver, ""); findkey(kv, "GREEN_DISPLAYDRIVER", driver);
findnicdescription(driver, temp);
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "GREEN_DEV", dev);
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
sprintf(temp1, "GREEN: %s (%s)\n", temp, dev);
strcat(message, temp1);
if (HAS_BLUE)
{
strcpy(driver, ""); findkey(kv, "BLUE_DISPLAYDRIVER", driver);
findnicdescription(driver, temp);
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "BLUE_DEV", dev);
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
sprintf(temp1, "BLUE: %s (%s)\n", temp, dev);
strcat(message, temp1);
}
if (HAS_ORANGE)
{
strcpy(driver, ""); findkey(kv, "ORANGE_DISPLAYDRIVER", driver);
findnicdescription(driver, temp);
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "ORANGE_DEV", dev);
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
sprintf(temp1, "ORANGE: %s (%s)\n", temp, dev);
strcat(message, temp1);
}
if (HAS_RED)
{
strcpy(driver, ""); findkey(kv, "RED_DISPLAYDRIVER", driver);
findnicdescription(driver, temp);
strcpy(dev, ctr[TR_UNSET]); findkey(kv, "RED_DEV", dev);
if (!strlen(dev)) strcpy(dev, ctr[TR_UNSET]);
sprintf(temp1, "RED: %s (%s)\n", temp, dev);
strcat(message, temp1);
}
strcat(message, ctr[TR_DO_YOU_WISH_TO_CHANGE_THESE_SETTINGS]);
rc = newtWinChoice(ctr[TR_DRIVERS_AND_CARD_ASSIGNMENTS], ctr[TR_OK],
ctr[TR_CANCEL], message);
if (rc == 0 || rc == 1)
{
/* Shit, got to do something.. */
changedrivers();
}
freekeyvalues(kv);
return 1;
}
int changedrivers(void)
{
struct keyvalue *kv = initkeyvalues();
char message[1000];
char temp[STRING_SIZE];
char driver[STRING_SIZE];
int configtype;
int rc;
int c;
int needcards, sofarallocated, countofcards, toallocate;
char *orange = "ORANGE";
char *blue = "BLUE";
char *red = "RED";
char *sections[4];
int choice;
char nexteth[STRING_SIZE];
int abort;
char currentdriver[STRING_SIZE], currentdriveroptions[STRING_SIZE];
char displaydriver[STRING_SIZE];
struct stat st;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
configtype = atol(temp);
runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN",
ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]);
/* Remove all modules not needed for green networking. */
c = 0;
strcpy(driver, ""); findkey(kv, "GREEN_DRIVER", driver);
if (strcmp(driver, "pcmcia") != 0) {
stat("/proc/bus/pccard", &st);
mysystem("/etc/rc.d/rc.pcmcia stop");
if (S_ISDIR(st.st_mode)) {
mysystem("/sbin/modprobe pcmcia_core");
mysystem("/sbin/modprobe pcmcia-controller");
mysystem("/sbin/modprobe ds");
}
}
while (nics[c].modulename)
{
if (strcmp(nics[c].modulename, driver) != 0)
{
if (checkformodule(nics[c].modulename))
{
sprintf(temp, "/sbin/rmmod %s", nics[c].modulename);
mysystem(temp);
}
}
c++;
}
/* Blank them so the rc.netaddress.up does not get confused. */
replacekeyvalue(kv, "ORANGE_DEV", "");
replacekeyvalue(kv, "BLUE_DEV", "");
replacekeyvalue(kv, "RED_DEV", "");
if (configtype == 0)
needcards = 1;
else if (configtype == 1 || configtype == 2 || configtype == 4)
needcards = 2;
else if (configtype == 7)
needcards = 4;
else
needcards = 3;
/* This is the green card. */
sofarallocated = 1;
findkey(kv, "GREEN_DRIVER", currentdriver);
findkey(kv, "GREEN_DRIVER_OPTIONS", currentdriveroptions);
strcpy(displaydriver, currentdriver);
if (countcards() > 1)
strcpy(currentdriver, "");
abort = 0;
/* Keep going till all cards are got, or they give up. */
while (sofarallocated < needcards && !abort)
{
countofcards = countcards();
/* This is how many cards were added by the last module. */
toallocate = countofcards - sofarallocated;
while (toallocate > 0 && sofarallocated < needcards)
{
findnicdescription(displaydriver, temp);
sprintf(message, ctr[TR_UNCLAIMED_DRIVER], temp);
c = 0; choice = 0;
strcpy(temp, ""); findkey(kv, "BLUE_DEV", temp);
if (HAS_BLUE && !strlen(temp))
{
sections[c] = blue;
c++;
}
strcpy(temp, ""); findkey(kv, "ORANGE_DEV", temp);
if (HAS_ORANGE && !strlen(temp))
{
sections[c] = orange;
c++;
}
strcpy(temp, ""); findkey(kv, "RED_DEV", temp);
if (HAS_RED && !strlen(temp))
{
sections[c] = red;
c++;
}
sections[c] = NULL;
rc = newtWinMenu(ctr[TR_CARD_ASSIGNMENT],
message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK],
ctr[TR_CANCEL], NULL);
if (rc == 0 || rc == 1)
{
/* Now we see which iface needs its settings changed. */
sprintf(nexteth, "eth%d", sofarallocated);
if (strcmp(sections[choice], blue) == 0)
{
replacekeyvalue(kv, "BLUE_DEV", nexteth);
replacekeyvalue(kv, "BLUE_DRIVER", currentdriver);
replacekeyvalue(kv, "BLUE_DRIVER_OPTIONS", currentdriveroptions);
replacekeyvalue(kv, "BLUE_DISPLAYDRIVER", displaydriver);
sofarallocated++;
toallocate--;
strcpy(currentdriver, "");
strcpy(currentdriveroptions, "");
}
if (strcmp(sections[choice], orange) == 0)
{
replacekeyvalue(kv, "ORANGE_DEV", nexteth);
replacekeyvalue(kv, "ORANGE_DRIVER", currentdriver);
replacekeyvalue(kv, "ORANGE_DRIVER_OPTIONS", currentdriveroptions);
replacekeyvalue(kv, "ORANGE_DISPLAYDRIVER", displaydriver);
sofarallocated++;
toallocate--;
strcpy(currentdriver, "");
strcpy(currentdriveroptions, "");
}
if (strcmp(sections[choice], red) == 0)
{
replacekeyvalue(kv, "RED_DEV", nexteth);
replacekeyvalue(kv, "RED_DRIVER", currentdriver);
replacekeyvalue(kv, "RED_DRIVER_OPTIONS", currentdriveroptions);
replacekeyvalue(kv, "RED_DISPLAYDRIVER", displaydriver);
sofarallocated++;
toallocate--;
strcpy(currentdriver, "");
strcpy(currentdriveroptions, "");
}
}
else
{
break;
}
}
/* Need another module! The nitty gritty code is in libsmooth. */
if (sofarallocated < needcards)
{
rc = newtWinTernary(ctr[TR_CARD_ASSIGNMENT], ctr[TR_PROBE],
ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_NO_UNALLOCATED_CARDS]);
if (rc == 0 || rc == 1)
{
probecards(currentdriver, currentdriveroptions);
if (!strlen(currentdriver))
errorbox(ctr[TR_PROBE_FAILED]);
}
else if (rc == 2)
choosecards(currentdriver, currentdriveroptions);
else
abort = 1;
strcpy(displaydriver, currentdriver);
}
}
countofcards = countcards();
if (countofcards >= needcards)
{
newtWinMessage(ctr[TR_CARD_ASSIGNMENT], ctr[TR_OK],
ctr[TR_ALL_CARDS_SUCCESSFULLY_ALLOCATED]);
}
else
errorbox(ctr[TR_NOT_ENOUGH_CARDS_WERE_ALLOCATED]);
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
freekeyvalues(kv);
netaddresschange = 1;
return 1;
}
/* Let user change GREEN address. */
int greenaddressmenu(void)
{
struct keyvalue *kv = initkeyvalues();
char message[1000];
int rc;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
sprintf(message, ctr[TR_WARNING_LONG], NAME);
rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
if (rc == 0 || rc == 1)
{
if (changeaddress(kv, "GREEN", 0, ""))
{
netaddresschange = 1;
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
writehostsfiles();
}
}
freekeyvalues(kv);
return 0;
}
/* They can change BLUE, ORANGE and GREEN too :) */
int addressesmenu(void)
{
struct keyvalue *kv = initkeyvalues();
struct keyvalue *mainkv = initkeyvalues();
int rc = 0;
char *sections[5];
char *green = "GREEN";
char *orange = "ORANGE";
char *blue = "BLUE";
char *red = "RED";
int c = 0;
char greenaddress[STRING_SIZE];
char oldgreenaddress[STRING_SIZE];
char temp[STRING_SIZE];
char temp2[STRING_SIZE];
char message[1000];
int configtype;
int done;
int choice;
char hostname[STRING_SIZE];
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
freekeyvalues(mainkv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
if (!(readkeyvalues(mainkv, CONFIG_ROOT "/main/settings")))
{
freekeyvalues(kv);
freekeyvalues(mainkv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
configtype = atol(temp);
sections[c] = green;
c++;
if (HAS_BLUE)
{
sections[c] = blue;
c++;
}
if (HAS_ORANGE)
{
sections[c] = orange;
c++;
}
if (HAS_RED)
{
sections[c] = red;
c++;
}
sections[c] = NULL;
choice = 0;
done = 0;
while (!done)
{
rc = newtWinMenu(ctr[TR_ADDRESS_SETTINGS],
ctr[TR_SELECT_THE_INTERFACE_YOU_WISH_TO_RECONFIGURE], 50, 5,
5, 6, sections, &choice, ctr[TR_OK], ctr[TR_DONE], NULL);
if (rc == 0 || rc == 1)
{
if (strcmp(sections[choice], "GREEN") == 0)
{
findkey(kv, "GREEN_ADDRESS", oldgreenaddress);
sprintf(message, ctr[TR_WARNING_LONG], NAME);
rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL],
message);
if (rc == 0 || rc == 1)
{
if (changeaddress(kv, "GREEN", 0, ""))
{
netaddresschange = 1;
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
writehostsfiles();
findkey(kv, "GREEN_ADDRESS", greenaddress);
snprintf(temp, STRING_SIZE-1, "option routers %s", oldgreenaddress);
snprintf(temp2, STRING_SIZE-1, "option routers %s", greenaddress);
replace (CONFIG_ROOT "/dhcp/dhcpd.conf", temp, temp2);
chown (CONFIG_ROOT "/dhcp/dhcpd.conf", 99, 99);
}
}
}
if (strcmp(sections[choice], "BLUE") == 0)
{
if (changeaddress(kv, "BLUE", 0, ""))
netaddresschange = 1;
}
if (strcmp(sections[choice], "ORANGE") == 0)
{
if (changeaddress(kv, "ORANGE", 0, ""))
netaddresschange = 1;
}
if (strcmp(sections[choice], "RED") == 0)
{
strcpy(hostname, "");
findkey(mainkv, "HOSTNAME", hostname);
if (changeaddress(kv, "RED", 1, hostname))
netaddresschange = 1;
}
}
else
done = 1;
}
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
freekeyvalues(kv);
freekeyvalues(mainkv);
return 0;
}
/* DNS and default gateway.... */
int dnsgatewaymenu(void)
{
struct keyvalue *kv = initkeyvalues();
char message[1000];
char temp[STRING_SIZE] = "0";
struct newtWinEntry entries[DNSGATEWAY_TOTAL+1];
char *values[DNSGATEWAY_TOTAL]; /* pointers for the values. */
int error;
int configtype;
int rc;
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(temp, "0"); findkey(kv, "CONFIG_TYPE", temp);
configtype = atol(temp);
if (RED_IS_NOT_ETH)
{
freekeyvalues(kv);
errorbox(ctr[TR_DNS_GATEWAY_WITH_GREEN]);
return 0;
}
entries[DNS1].text = ctr[TR_PRIMARY_DNS];
strcpy(temp, ""); findkey(kv, "DNS1", temp);
values[DNS1] = strdup(temp);
entries[DNS1].value = &values[DNS1];
entries[DNS1].flags = 0;
entries[DNS2].text = ctr[TR_SECONDARY_DNS];
strcpy(temp, ""); findkey(kv, "DNS2", temp);
values[DNS2] = strdup(temp);
entries[DNS2].value = &values[DNS2];
entries[DNS2].flags = 0;
entries[DEFAULT_GATEWAY].text = ctr[TR_DEFAULT_GATEWAY];
strcpy(temp, ""); findkey(kv, "DEFAULT_GATEWAY", temp);
values[DEFAULT_GATEWAY] = strdup(temp);
entries[DEFAULT_GATEWAY].value = &values[DEFAULT_GATEWAY];
entries[DEFAULT_GATEWAY].flags = 0;
entries[DNSGATEWAY_TOTAL].text = NULL;
entries[DNSGATEWAY_TOTAL].value = NULL;
entries[DNSGATEWAY_TOTAL].flags = 0;
do
{
error = 0;
rc = newtWinEntries(ctr[TR_DNS_AND_GATEWAY_SETTINGS],
ctr[TR_DNS_AND_GATEWAY_SETTINGS_LONG], 50, 5, 5, 18, entries,
ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc == 0 || rc == 1)
{
strcpy(message, ctr[TR_INVALID_FIELDS]);
if (strlen(values[DNS1]))
{
if (inet_addr(values[DNS1]) == INADDR_NONE)
{
strcat(message, ctr[TR_PRIMARY_DNS_CR]);
error = 1;
}
}
if (strlen(values[DNS2]))
{
if (inet_addr(values[DNS2]) == INADDR_NONE)
{
strcat(message, ctr[TR_SECONDARY_DNS_CR]);
error = 1;
}
}
if (strlen(values[DEFAULT_GATEWAY]))
{
if (inet_addr(values[DEFAULT_GATEWAY]) == INADDR_NONE)
{
strcat(message, ctr[TR_DEFAULT_GATEWAY_CR]);
error = 1;
}
}
if (!strlen(values[DNS1]) && strlen(values[DNS2]))
{
strcpy(message, ctr[TR_SECONDARY_WITHOUT_PRIMARY_DNS]);
error = 1;
}
if (error)
errorbox(message);
else
{
replacekeyvalue(kv, "DNS1", values[DNS1]);
replacekeyvalue(kv, "DNS2", values[DNS2]);
replacekeyvalue(kv, "DEFAULT_GATEWAY", values[DEFAULT_GATEWAY]);
netaddresschange = 1;
free(values[DNS1]);
free(values[DNS2]);
free(values[DEFAULT_GATEWAY]);
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
}
}
}
while (error);
freekeyvalues(kv);
return 1;
}

View File

@@ -0,0 +1,123 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Password stuff.
*
* $Id: passwords.c,v 1.5.2.1 2004/04/14 22:05:41 gespinasse Exp $
*
*/
#include "setup.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
int getpassword(char *password, char *text);
/* Root password. */
int handlerootpassword(void)
{
char password[STRING_SIZE];
char commandstring[STRING_SIZE];
/* Root password. */
if (getpassword(password, ctr[TR_ENTER_ROOT_PASSWORD]) == 2)
return 0;
snprintf(commandstring, STRING_SIZE,
"/bin/echo 'root:%s' | /usr/sbin/chpasswd", password);
if (runhiddencommandwithstatus(commandstring, ctr[TR_SETTING_ROOT_PASSWORD]))
{
errorbox(ctr[TR_PROBLEM_SETTING_ROOT_PASSWORD]);
return 0;
}
return 1;
}
int handleadminpassword(void)
{
char password[STRING_SIZE];
char commandstring[STRING_SIZE];
char message[1000];
/* web interface admin password. */
sprintf(message, ctr[TR_ENTER_ADMIN_PASSWORD], NAME, NAME);
if (getpassword(password, message) == 2)
return 0;
snprintf(commandstring, STRING_SIZE,
"/usr/bin/htpasswd -c -m -b " CONFIG_ROOT "/auth/users admin '%s'", password);
sprintf(message, ctr[TR_SETTING_ADMIN_PASSWORD], NAME);
if (runhiddencommandwithstatus(commandstring, message))
{
sprintf(message, ctr[TR_PROBLEM_SETTING_ADMIN_PASSWORD], NAME);
errorbox(message);
return 0;
}
return 1;
}
/* Taken from the cdrom one. */
int getpassword(char *password, char *text)
{
char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */
struct newtWinEntry entries[] =
{
{ ctr[TR_PASSWORD_PROMPT], &values[0], 2 },
{ ctr[TR_AGAIN_PROMPT], &values[1], 2 },
{ NULL, NULL, 0 }
};
char title[STRING_SIZE];
int rc;
int done;
do
{
done = 1;
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
rc = newtWinEntries(title, text,
50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
if (rc != 2)
{
if (strlen(values[0]) == 0 || strlen(values[1]) == 0)
{
errorbox(ctr[TR_PASSWORD_CANNOT_BE_BLANK]);
done = 0;
strcpy(values[0], "");
strcpy(values[1], "");
}
else if (strcmp(values[0], values[1]) != 0)
{
errorbox(ctr[TR_PASSWORDS_DO_NOT_MATCH]);
done = 0;
strcpy(values[0], "");
strcpy(values[1], "");
}
else if (strchr(values[0], ' '))
{
errorbox(ctr[TR_PASSWORD_CANNOT_CONTAIN_SPACES]);
done = 0;
strcpy(values[0], "");
strcpy(values[1], "");
}
}
}
while (!done);
strncpy(password, values[0], STRING_SIZE);
if (values[0]) free(values[0]);
if (values[1]) free(values[1]);
return rc;
}

View File

@@ -0,0 +1,42 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Main include file.
*
* $Id: setup.h,v 1.4 2003/12/11 11:25:54 riddles Exp $
*
*/
#include "../libsmooth/libsmooth.h"
/* hostname.c */
int handlehostname(void);
/* domainname.c */
int handledomainname(void);
/* isdn.c */
int handleisdn(void);
/* networking.c */
int handlenetworking(void);
/* dhcp.c */
int handledhcp(void);
/* passwords.c */
int handlerootpassword(void);
int handlesetuppassword(void);
int handleadminpassword(void);
/* misc.c */
int writehostsfiles(void);
/* keymap.c */
int handlekeymap(void);
/* timezone.c */
int handletimezone(void);

View File

@@ -0,0 +1,134 @@
/* SmoothWall setup program.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Stuff for setting the timezone.
*
* $Id: timezone.c,v 1.4.2.1 2004/04/14 22:05:41 gespinasse Exp $
*
*/
#include "setup.h"
extern FILE *flog;
extern char *mylog;
extern char **ctr;
extern int automode;
#define MAX_FILENAMES 5000
#define ZONEFILES "/usr/share/zoneinfo/posix"
static int filenamecount;
static char *filenames[MAX_FILENAMES];
static char *displaynames[MAX_FILENAMES];
static int process(char *prefix, char *path);
static int cmp(const void *s1, const void *s2);
int handletimezone(void)
{
int c;
int choice;
char *temp;
struct keyvalue *kv = initkeyvalues();
int rc;
int result;
char timezone[STRING_SIZE];
filenamecount = 0;
process(ZONEFILES, "");
filenames[filenamecount] = NULL;
qsort(filenames, filenamecount, sizeof(char *), cmp);
for (c = 0; filenames[c]; c++)
{
displaynames[c] = malloc(STRING_SIZE);
if ((temp = strstr(filenames[c], ZONEFILES)))
strcpy(displaynames[c], temp + strlen(ZONEFILES) + 1);
else
strcpy(displaynames[c], filenames[c]);
}
displaynames[c] = NULL;
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
{
freekeyvalues(kv);
errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
return 0;
}
strcpy(timezone, ZONEFILES "/CET");
findkey(kv, "TIMEZONE", timezone);
choice = 0;
for (c = 0; filenames[c]; c++)
{
if (strcmp(timezone, filenames[c]) == 0)
choice = c;
}
rc = newtWinMenu(ctr[TR_TIMEZONE], ctr[TR_TIMEZONE_LONG], 50, 5, 5, 6, displaynames, &choice,
ctr[TR_OK], ctr[TR_CANCEL], NULL);
strcpy(timezone, filenames[choice]);
if (rc != 2)
{
replacekeyvalue(kv, "TIMEZONE", timezone);
writekeyvalues(kv, CONFIG_ROOT "/main/settings");
unlink("/etc/localtime");
link(timezone, "/etc/localtime");
result = 1;
}
else
result = 0;
for (c = 0; filenames[c]; c++)
{
free(filenames[c]);
free(displaynames[c]);
}
freekeyvalues(kv);
return result;
}
static int process(char *prefix, char *path)
{
DIR *dir;
struct dirent *de;
char newpath[PATH_MAX];
snprintf(newpath, PATH_MAX, "%s%s", prefix, path);
if (!(dir = opendir(newpath)))
{
if (filenamecount > MAX_FILENAMES)
return 1;
filenames[filenamecount] = (char *) strdup(newpath);
filenamecount++;
return 0;
}
while ((de = readdir(dir)))
{
if (de->d_name[0] == '.') continue;
snprintf(newpath, PATH_MAX, "%s/%s", path, de->d_name);
process(prefix, newpath);
}
closedir(dir);
return 1;
}
/* Small wrapper for use with qsort(). */
static int cmp(const void *s1, const void *s2)
{
return (strcmp(* (char **) s1, * (char **) s2));
}

View File

@@ -0,0 +1,30 @@
/Makefile/1.5.2.7/Sun Nov 20 23:20:13 2005//TIPCOP_v1_4_0
/installfcdsl.c/1.1.2.4/Sat Dec 11 08:55:37 2004//TIPCOP_v1_4_0
/installpackage.c/1.3.2.6/Mon Aug 22 20:51:38 2005//TIPCOP_v1_4_0
/iowrap.c/1.2/Tue Nov 27 15:20:50 2001//TIPCOP_v1_4_0
/ipcopbackup.c/1.8.2.6/Fri Jan 20 13:30:42 2006//TIPCOP_v1_4_0
/ipcopbkcfg.c/1.2.2.6/Sun Nov 20 23:20:13 2005//TIPCOP_v1_4_0
/ipcopdeath.c/1.2/Thu Dec 11 10:57:34 2003//TIPCOP_v1_4_0
/ipcoprebirth.c/1.2/Thu Dec 11 10:57:34 2003//TIPCOP_v1_4_0
/ipcopreboot.c/1.1.2.2/Mon Oct 24 23:05:50 2005//TIPCOP_v1_4_0
/ipcoprscfg.c/1.2.2.6/Mon Nov 21 00:11:39 2005//TIPCOP_v1_4_0
/ipsecctrl.c/1.5.2.14/Sun May 15 12:58:28 2005//TIPCOP_v1_4_0
/logwatch.c/1.2/Thu Dec 11 11:25:54 2003//TIPCOP_v1_4_0
/rebuildhosts.c/1.3.2.6/Mon Jul 11 10:56:47 2005//TIPCOP_v1_4_0
/restartdhcp.c/1.5.2.1/Wed Nov 3 13:50:26 2004//TIPCOP_v1_4_0
/restartntpd.c/1.5/Fri Dec 19 14:29:09 2003//TIPCOP_v1_4_0
/restartshaping.c/1.2.2.5/Fri Jan 28 13:11:40 2005//TIPCOP_v1_4_0
/restartsnort.c/1.8.2.3/Sun Oct 16 12:36:14 2005//TIPCOP_v1_4_0
/restartsquid.c/1.7.2.8/Fri Apr 22 18:44:37 2005//TIPCOP_v1_4_0
/restartssh.c/1.3/Thu Dec 11 10:57:34 2003//TIPCOP_v1_4_0
/restartsyslogd.c/1.2.2.3/Tue Dec 14 17:56:37 2004//TIPCOP_v1_4_0
/restartwireless.c/1.2.2.5/Mon Jul 11 10:56:47 2005//TIPCOP_v1_4_0
/setaliases.c/1.2.2.4/Sun Aug 22 22:01:44 2004//TIPCOP_v1_4_0
/setdate.c/1.2/Thu Dec 11 11:25:54 2003//TIPCOP_v1_4_0
/setdmzholes.c/1.5.2.3/Tue Oct 18 17:05:27 2005//TIPCOP_v1_4_0
/setfilters.c/1.1.2.2/Tue Feb 7 20:54:16 2006//TIPCOP_v1_4_0
/setportfw.c/1.3.2.6/Wed Aug 24 18:44:19 2005//TIPCOP_v1_4_0
/setuid.c/1.2.2.1/Fri Nov 18 14:51:43 2005//TIPCOP_v1_4_0
/setuid.h/1.4.2.4/Sun Nov 20 23:20:13 2005//TIPCOP_v1_4_0
/setxtaccess.c/1.3.2.1/Tue Jan 4 17:21:40 2005//TIPCOP_v1_4_0
D

View File

@@ -0,0 +1 @@
ipcop/src/misc-progs

1
src/misc-progs/CVS/Root Normal file
View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop

1
src/misc-progs/CVS/Tag Normal file
View File

@@ -0,0 +1 @@
TIPCOP_v1_4_0

82
src/misc-progs/Makefile Normal file
View File

@@ -0,0 +1,82 @@
#
# $Id: Makefile,v 1.5.2.7 2005/11/20 23:20:13 franck78 Exp $
#
CC=gcc
CFLAGS=-O2 -Wall
COMPILE=$(CC) $(CFLAGS)
PROGS = iowrap
SUID_PROGS = setdmzholes setportfw setfilters setxtaccess restartdhcp restartsnort \
restartsquid restartssh ipcopreboot \
ipcopbkcfg ipcoprscfg installpackage installfcdsl ipsecctrl \
setaliases ipcopbackup restartshaping restartntpd \
restartwireless setdate rebuildhosts \
restartsyslogd logwatch
install : all
install -m 755 $(PROGS) /usr/local/bin
install -m 4750 -g nobody $(SUID_PROGS) /usr/local/bin
all : $(PROGS) $(SUID_PROGS)
clean :
-rm -f $(PROGS) $(SUID_PROGS) *.o core
######
% : %.c
$(COMPILE) $< setuid.o -o $@
setuid.o: setuid.c setuid.h
$(COMPILE) $< -c -o $@
$(SUID_PROGS): setuid.o
$(PROGS): setuid.o
logwatch: logwatch.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ logwatch.c setuid.o ../install+setup/libsmooth/varval.o -o $@
setaliases: setaliases.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ setaliases.c setuid.o ../install+setup/libsmooth/varval.o -o $@
setdmzholes: setdmzholes.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ setdmzholes.c setuid.o ../install+setup/libsmooth/varval.o -o $@
setportfw: setportfw.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ setportfw.c setuid.o ../install+setup/libsmooth/varval.o -o $@
setfilters: setfilters.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ setfilters.c setuid.o ../install+setup/libsmooth/varval.o -o $@
rebuildhosts: rebuildhosts.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ rebuildhosts.c setuid.o ../install+setup/libsmooth/varval.o -o $@
restartdhcp: restartdhcp.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ restartdhcp.c setuid.o ../install+setup/libsmooth/varval.o -o $@
restartshaping: restartshaping.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ restartshaping.c setuid.o ../install+setup/libsmooth/varval.o -o $@
restartssh: restartssh.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ restartssh.c setuid.o ../install+setup/libsmooth/varval.o -o $@
restartsquid: restartsquid.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ restartsquid.c setuid.o ../install+setup/libsmooth/varval.o -o $@
restartsnort: restartsnort.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ restartsnort.c setuid.o ../install+setup/libsmooth/varval.o -o $@
restartsyslogd: restartsyslogd.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ restartsyslogd.c setuid.o ../install+setup/libsmooth/varval.o -o $@
restartwireless: restartwireless.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ restartwireless.c setuid.o ../install+setup/libsmooth/varval.o -o $@
ipsecctrl: ipsecctrl.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ ipsecctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
ipcopbackup: ipcopbackup.c setuid.o
$(COMPILE) -lcrypt ipcopbackup.c setuid.o -o $@

View File

@@ -0,0 +1,88 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2004-10-14 Gilles Espinasse <g.esp.ipcop@free.fr>
*
* $Id: installfcdsl.c,v 1.1.2.4 2004/12/11 08:55:37 gespinasse Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <grp.h>
#include "setuid.h"
#define FCDSL_TGZ_PATH "/var/patches/fcdsl-x.tgz"
char command[STRING_SIZE],tmpdir[] = "/tmp/fcdsl_XXXXXX";
void exithandler(void)
{
if(strcmp(tmpdir,"/tmp/fcdsl_XXXXXX"))
{
chdir("/tmp");
snprintf(command, STRING_SIZE - 1, "/bin/rm -rf %s", tmpdir);
if(safe_system(command))
perror("Couldn't remove temp dir");
}
/* remove loaded package */
snprintf (command, STRING_SIZE-1, FCDSL_TGZ_PATH);
unlink (command);
}
int main(void)
{
if (!(initsetuid()))
exit(1);
atexit(exithandler);
if (close(0)) { fprintf(stderr, "Couldn't close 0\n"); exit(1); }
if (open("/dev/zero", O_RDONLY) != 0) {fprintf(stderr, "Couldn't reopen stdin from /dev/zero\n"); exit(1); }
if (close(2)) { fprintf(stderr, "Couldn't close 2\n"); exit(1); }
if (! dup(1)) { fprintf(stderr, "Couldnt redirect stderr to stdout\n"); exit(1); }
/* create temporary directory for testing untar */
if (mkdtemp (tmpdir)==NULL) {
exit(1);
}
/* Test untarring files from compressed archive */
snprintf (command, STRING_SIZE-1, "/bin/tar -C %s -xzf %s lib/modules/*/misc/fcdsl*.o.gz "
"usr/lib/isdn/{fds?base.bin,fd?ubase.frm} etc/fcdsl/fcdsl*.conf etc/drdsl/drdsl* "
"var/run/need-depmod-* > /dev/null 2> /dev/null", tmpdir, FCDSL_TGZ_PATH);
if (safe_system (command)) {
fprintf (stderr, "Invalid archive\n");
exit(1);
}
/* Start (real) untarring files from compressed archive */
snprintf (command, STRING_SIZE-1, "/bin/tar -C / -xzvf %s lib/modules/*/misc/fcdsl*.o.gz "
"usr/lib/isdn/{fds?base.bin,fd?ubase.frm} etc/fcdsl/fcdsl*.conf etc/drdsl/drdsl* "
"var/run/need-depmod-* ", FCDSL_TGZ_PATH);
if (safe_system (command)) {
fprintf (stderr, "Error installing modules\n");
exit(1);
}
exit(0);
}

View File

@@ -0,0 +1,218 @@
/* This file is part of the IPCop Firewall.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* Copyright (C) 2004-05-31 Robert Kerr <rkerr@go.to>
*
* Loosely based on the smoothwall helper program by the same name,
* portions are (c) Lawrence Manning, 2001
*
* $Id: installpackage.c,v 1.3.2.6 2005/08/22 20:51:38 eoberlander Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/file.h>
#include <fcntl.h>
#include <syslog.h>
#include <time.h>
#include "setuid.h"
#define ERR_ANY 1
#define ERR_TMPDIR 2
#define ERR_SIG 3
#define ERR_TAR 4
#define ERR_INFO 5
#define ERR_PACKLIST 6
#define ERR_INSTALLED 7
#define ERR_POPEN 8
#define ERR_SETUP 9
#define ERR_MISSING_PREVIOUS 10
#define ERR_DISK 11
/* The lines in the package information file and the patches/installed list
* are often longer than STRING_SIZE so we use a larger buffer */
#define BUFFER_SIZE 4096
char *info = NULL;
FILE *infofile = NULL;
char command[STRING_SIZE], tmpdir[] = "/var/log/pat_install_XXXXXX";
void exithandler(void)
{
if(info) free(info);
if(infofile)
{
flock(fileno(infofile), LOCK_UN);
fclose(infofile);
}
/* Cleanup tmpdir */
chdir("/var/patches"); /* get out of it before erasing */
snprintf(command, STRING_SIZE - 1, "/bin/rm -rf %s", tmpdir);
if(safe_system(command))
perror("Couldn't remove temp dir");
}
int main(int argc, char *argv[])
{
char buffer[BUFFER_SIZE];
int ret;
FILE *p;
if (!(initsetuid()))
exit(1);
/* Sanitize arguments */
if (argc < 2)
{
fprintf(stderr, "Missing arg\n");
exit(1);
}
if (strspn(argv[1], NUMBERS) != strlen(argv[1]))
{
fprintf(stderr, "Bad arg\n");
exit(1);
}
if(!mkdtemp(tmpdir))
{
perror("Unable to create secure temp dir");
exit(ERR_TMPDIR);
}
/* now exithandler will have something to erase */
atexit(exithandler);
/* verify and extract package */
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE-1, "/usr/bin/gpg --batch --homedir /root/.gnupg -o %s/patch.tar.gz --decrypt /var/patches/patch-%s.tar.gz.gpg", tmpdir, argv[1]);
ret = safe_system(command) >> 8;
if(ret==1) /* 1=> gpg-key error */
{
fprintf(stderr, "Invalid package: signature check failed\n");
exit(ERR_SIG);
}
if(ret==2) /* 2=> gpg pub key not found */
{
fprintf(stderr, "Public signature not found (who signed package?) !\n");
exit(ERR_SIG);
}
if(ret) /* retry extraction on other partition */
{
rmdir(tmpdir);
strcpy (tmpdir,"/var/patches/install_XXXXXX");
if(!mkdtemp(tmpdir))
{
perror("Unable to create secure temp dir");
_exit(ERR_TMPDIR); /* no need exit handler */
}
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE-1, "/usr/bin/gpg --batch --homedir /root/.gnupg -o %s/patch.tar.gz --decrypt /var/patches/patch-%s.tar.gz.gpg", tmpdir, argv[1]);
ret = safe_system(command);
if(ret)
{
fprintf(stderr, "Not enough disk space or gpg error %d !\n",ret);
exit(ERR_DISK);
}
}
/* no more needed gpg-package & make room */
snprintf(command, STRING_SIZE-1, "/var/patches/patch-%s.tar.gz.gpg", argv[1]);
unlink ( command );
/* unzip the package */
chdir (tmpdir);
if(safe_system("/bin/tar xzf patch.tar.gz"))
{
fprintf(stderr, "Invalid package: untar failed\n");
exit(ERR_TAR);
}
/* And read 'information' to check validity */
snprintf(buffer, STRING_SIZE-1, "%s/information", tmpdir);
if(!(infofile = fopen(buffer,"r")))
{
if(errno == ENOENT)
fprintf(stderr, "Invalid package: contains no information file\n");
else
perror("Unable to open package information file");
exit(ERR_INFO);
}
if(!fgets(buffer, BUFFER_SIZE, infofile))
{
perror("Couldn't read package information");
exit(ERR_INFO);
}
fclose(infofile);
if(buffer[strlen(buffer)-1] == '\n')
buffer[strlen(buffer)-1] = '\0';
if(!strchr(buffer,'|'))
{
fprintf(stderr, "Invalid package: malformed information string.\n");
exit(ERR_INFO);
}
info = strdup(buffer);
/* check if package is already installed */
if(!(infofile = fopen(CONFIG_ROOT "/patches/installed","r+")))
{
perror("Unable to open installed package list");
exit(ERR_PACKLIST);
}
/* get exclusive lock to prevent a mess if 2 copies run at once, and set
* close-on-exec flag so the FD doesn't leak to the setup script */
flock(fileno(infofile), LOCK_EX);
fcntl(fileno(infofile), F_SETFD, FD_CLOEXEC);
while(fgets(buffer, BUFFER_SIZE, infofile))
{
if(!strncmp(buffer, info, strlen(info)))
{
fprintf(stderr,"This package is already installed\n");
exit(ERR_INSTALLED);
}
}
/* install package */
openlog("installpackage", LOG_PID, LOG_USER);
snprintf(command, STRING_SIZE - 1, "%s/setup", tmpdir);
/* FIXME: popen suffers from the same environment problems as system() */
if (!(p = popen(command, "r")))
{
fprintf(stderr,"popen() failed\n");
closelog();
exit(ERR_POPEN);
}
setvbuf(p, NULL, _IOLBF, 255);
while (fgets(buffer, STRING_SIZE, p))
{
syslog(LOG_INFO, "%s", buffer);
}
ret = pclose(p);
closelog();
if(ret)
{
fprintf(stderr, "setup script returned exit code %d\n", ret>>8);
exit(ERR_SETUP);
}
/* write to package db */
if(strncmp(info, "000|", 4))
{
time_t curtime = time(NULL);
strftime(buffer, STRING_SIZE, "%Y-%m-%d", gmtime(&curtime));
fprintf(infofile, "%s|%s\n", info, buffer);
flock(fileno(infofile), LOCK_UN);
fclose(infofile);
} else { /* Full system upgrade to new version */
flock(fileno(infofile), LOCK_UN);
fclose(infofile);
unlink(CONFIG_ROOT "/patches/available");
unlink(CONFIG_ROOT "/patches/installed");
}
free(info);
exit(0);
}

44
src/misc-progs/iowrap.c Normal file
View File

@@ -0,0 +1,44 @@
/* SmoothWall helper program - iowrap.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Installer helper for redirecting stdout/stderr to a file/terminal.
* init calls ash through this program to shove it on a tty.
*
* $Id: iowrap.c,v 1.2 2001/11/27 15:20:50 riddles Exp $
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
/* Prog takes one argument. A device to run on (like a getty) */
if (argc >= 2)
{
int fd;
if ((fd = open(argv[1], O_RDWR)) == -1)
{
printf("Couldn't open device\n");
return 0;
}
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
/* Now its sending/reading on that device. */
}
if (argc >= 3)
execvp(argv[2], &argv[2]);
else
printf("No command\n");
return 0;
}

View File

@@ -0,0 +1,290 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2002-06-02 Mark Wormgoor <mark@wormgoor.com>
*
* $Id: ipcopbackup.c,v 1.8.2.6 2006/01/20 13:30:42 franck78 Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
#include <shadow.h>
#include <crypt.h>
#include <glob.h>
#include "setuid.h"
// want a bigger buffer to concatenate a possibly long string
#define COMMAND_SIZE 4000
//Append lines contained in 'inputfile' to 'string'
int catlist(char* inputfile,
char* string ) {
struct stat s; // input file stats
char buffer[STRING_SIZE]; // read buffer
if (stat(inputfile,&s) != 0) return 1;
if (s.st_size+strlen(string)>COMMAND_SIZE) return 1; // too big!
int f = open(inputfile, O_RDONLY);
if (!f) return 1; // cannot open file
int count;
while ((count = read(f, buffer, STRING_SIZE - 1))) {
int j;
for (j=0; j<count; j++) { //replace newlines with spaces
if (buffer[j] == '\n') buffer[j] = ' ';
}
buffer[j] = '\0';
strcat (string,buffer); // append to string
}
close (f);
return 0; //success
}
// make a raw backup to floppy_dev (no partitioning)
int savecfg_floppy(char* floppy_dev) {
char command[COMMAND_SIZE]; // because copy each filename here
// want special output...
if (close(0)) { fprintf(stderr, "Couldn't close 0\n"); exit(1); }
if (open("/dev/zero", O_RDONLY) != 0) {fprintf(stderr, "Couldn't reopen stdin from /dev/zero\n"); exit(1); }
if (close(2)) { fprintf(stderr, "Couldn't close 2\n"); exit(1); }
if (! dup(1)) { fprintf(stderr, "Couldnt redirect stderr to stdout\n"); exit(1); }
/* Make sure floppy device name is up to date */
safe_system ("/usr/sbin/updfstab");
/* Darren Critchley - check for floppy disk in disk drive before continuing */
snprintf (command, STRING_SIZE-1, "dd if=%s of=/dev/null bs=1k count=1 2> /dev/null", floppy_dev);
if (safe_system(command)) {
perror( "Error: No floppy in drive or bad floppy in drive" );
exit(1);
}
/* Clearing disk */
snprintf (command, STRING_SIZE-1, "/bin/dd if=/dev/zero of=%s bs=1k 2> /dev/null", floppy_dev);
safe_system (command);
/* Start tarring files to floppy */
snprintf (command, COMMAND_SIZE-1, "/bin/tar -X " CONFIG_ROOT"/backup/exclude.system "
"-X " CONFIG_ROOT"/backup/exclude.user "
"-C / -cvzf %s "
"-T " CONFIG_ROOT"/backup/include.user ",
floppy_dev);
/* add include.system file content to 'command' */
if (catlist(CONFIG_ROOT "/backup/include.system", command)) {
fprintf(stderr, "Couldn't open backup system include file\n");
exit (1);
}
safe_system (command);
/* Now check it */
snprintf (command, STRING_SIZE-1,"/bin/echo '<b>Checking</b>'; /bin/tar -tzf %s" , floppy_dev);
safe_system (command);
exit(0);
}
// Just verify that root password is ok
int checkrootpass (char* passwd) {
struct passwd *pw;
struct spwd *spwd;
if ((pw = getpwnam("root")) == NULL) {
return (0); // root unknown....!
}
// get shadowed password
spwd = getspnam("root");
//and use it in right place
if (spwd)
pw->pw_passwd = spwd->sp_pwdp;
return (strcmp ( crypt(passwd, pw->pw_passwd), //encrypt cleartext
pw->pw_passwd) == 0 //compare to encrypted version
) ? 1 : 0; // true or false
}
int main (int argc, char *argv[]) {
char command[STRING_SIZE];
if (argc < 3) { // at least two args always needed, avoid some testing.
fprintf (stderr, "Err %s: used from cgi only !\n", argv[0]);
exit (1);
}
if (!initsetuid()){
fprintf (stderr, "Err %s: cannot setuid !\n", argv[0]);
exit (1);
}
// save on normal floppy for use during reinstall ONLY
if ( (strcmp(argv[1],"-savecfg" ) == 0) &&
(strcmp(argv[2],"floppy") == 0) )
savecfg_floppy("/dev/floppy"); // to do: mount usb floppy....
if ( (strcmp(argv[1],"-proc" ) == 0) &&
(strcmp(argv[2],"partitions") == 0) ) { // issue cat /proc/partitions
int fi;
if ( (fi = open("/proc/partitions", O_RDONLY))==-1) exit (1); // cannot open file
char string[STRING_SIZE];
int count;
while ((count = read(fi, string, STRING_SIZE))) {
write (1, string, count);
}
close (fi);
exit (0);
}
// output result of 'glob' function
if ( (strcmp(argv[1],"-glob" ) == 0)) {
glob_t g;
if (glob (argv[2],0,NULL,&g) == 0) {
char** pstr = g.gl_pathv; // base array
while (*pstr) { // while not NULL
printf ("%s\n", *pstr); // pstr is a pointer to array of char*
pstr++; // next pointer
}
globfree (&g);
}
exit (0);
}
// tell if the backup.key is present
if ( (strcmp(argv[1],"-key" ) == 0) &&
(strcmp(argv[2],"exist") == 0) ) { // check key existence
if ( !(file_exists(BACKUP_KEY)) ) {
fprintf (stderr, "Err %s: backup key "BACKUP_KEY" does not exist !\n", argv[0]);
exit (ERR_KEY);
}
exit (0);
}
// cat the backup.key, for saving it
if ( strcmp(argv[1],"-keycat" ) == 0) {
if (! checkrootpass (argv[2])) exit (1); // but only if root pw provided
int fi;
if ( (fi = open(BACKUP_KEY, O_RDONLY))==-1) exit (1); // cannot open file
char string[STRING_SIZE];
int count;
while ((count = read(fi, string, STRING_SIZE))) {
write (1, string, count);
}
close (fi);
exit (0);
}
// generate a new backup.key ONLY if inexistant
if ( (strcmp(argv[1],"-key" ) == 0) &&
(strcmp(argv[2],"new") == 0) ) {
if ( (file_exists(BACKUP_KEY)) ) {
fprintf (stderr, "Err %s: backup key "BACKUP_KEY" already exists !\n", argv[0]);
exit (ERR_KEY);
}
//ok we can generate it
if (safe_system ("/usr/sbin/ipsec ranbits 256 > " BACKUP_KEY)) {
fprintf (stderr, "Err %s: couldn't create key !\n", argv[0]);
exit (ERR_KEY);
}
chmod(BACKUP_KEY, S_IRUSR); // protect it
exit (0);
}
// import a backup.key only if non existent
if ( (strcmp(argv[1],"-key" ) == 0) &&
(strcmp(argv[2],"import") == 0) ) {
if ( (file_exists(BACKUP_KEY)) ) {
unlink (MOUNTPOINT"/key"); // clean anyway
fprintf (stderr, "Err %s: backup key "BACKUP_KEY" already exists !\n", argv[0]);
exit (ERR_KEY);
}
int fi, fo;
if ( (fi = open(MOUNTPOINT"/key", O_RDONLY))==-1) {
fprintf (stderr, "Err %s: no backup key "MOUNTPOINT"/key to import !\n", argv[0]);
exit (ERR_KEY); // cannot open file
}
if ( (fo = open(BACKUP_KEY, O_WRONLY | O_CREAT ))==-1) {
close (fi);
unlink (MOUNTPOINT"/key"); // clean anyway
fprintf (stderr, "Err %s: backup key "BACKUP_KEY" creation error !\n", argv[0]);
exit (ERR_KEY);
}
char buffer[STRING_SIZE];
int count;
while ((count = read(fi, buffer, STRING_SIZE))) {
write (fo, buffer, count);
}
close (fo);
close (fi);
unlink (MOUNTPOINT"/key");
exit (0);
}
// disk functions like mount umount,...
if ((strspn(argv[2], LETTERS_NUMBERS ) == strlen(argv[2])) &&
(strlen(argv[2]) >2) && (strlen(argv[2]) <6)) {
if (strcmp(argv[1],"-M") == 0) { // M sda1 => mount /dev/sda1 /mountpoint
//safe_system("/bin/sync");
snprintf(command, STRING_SIZE - 1,"/bin/mount -t vfat -o,uid=99,gid=99 /dev/%s "MOUNTPOINT, argv[2]);
safe_system(command);
//safe_system("/bin/sync");
}else
if (strcmp(argv[1],"-U") == 0) { // U sda1 => umount /dev/sda1
//safe_system("/bin/sync");
snprintf(command, STRING_SIZE - 1,"/bin/umount /dev/%s", argv[2]);
safe_system(command);
safe_system("/bin/sync");
}else
if (strcmp(argv[1],"-f") == 0) { // f sda1 => mke2fs /dev/sda1
snprintf(command, STRING_SIZE - 1,"/sbin/mke2fs -q /dev/%s", argv[2]);
//safe_system(command);
//safe_system("/bin/sync");
}else
if (strcmp(argv[1],"-F") == 0) { // F sda => fdisk /dev/sda
//safe_system("/bin/sync");
snprintf(command, STRING_SIZE - 1,"/bin/dd if=/dev/zero of=/dev/%s count=2 bs=512", argv[2]);
//safe_system(command);
snprintf(command, STRING_SIZE - 1,"/bin/echo \"n\np\n1\n1\n\nw\nq\n\"|/sbin/fdisk /dev/%s", argv[2]);
//safe_system(command);
snprintf(command, STRING_SIZE - 1,"/sbin/mke2fs -q /dev/%s1", argv[2]); // beware of %s1
//safe_system(command);
//safe_system("/bin/sync");
}else {
fprintf (stderr, "Err %s: bad command !\n", argv[0]);
exit (1);
}
exit (0);
}else {
fprintf (stderr, "Err %s: bad arg !\n", argv[0]);
exit (1);
}
return 0;
}

239
src/misc-progs/ipcopbkcfg.c Normal file
View File

@@ -0,0 +1,239 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2003-06-25 Tim Butterfield <timbutterfield@mindspring.com>
*
* $Id: ipcopbkcfg.c,v 1.2.2.6 2005/11/20 23:20:13 franck78 Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <grp.h>
#include <dirent.h>
#include "setuid.h"
#define EXCLUDE_HARDWARE "exclude.hardware" // exclude file not used on backup but only optionally on restore
#define TMP_TAR "/tmp/backup.tar"
char tempincfilename[STRING_SIZE] = ""; /* temp include file name */
char tempexcfilename[STRING_SIZE] = ""; /* temp exclude file name */
char temptarfilename[STRING_SIZE] = "";
/* add fname contents to outfile */
void add_file(int outfile, const char *fname, int verbose)
{
FILE *freadfile;
char fbuff[STRING_SIZE];
if (!(freadfile = fopen(fname, "r"))) {
/* skip this file */
return;
}
while (fgets(fbuff, STRING_SIZE-1, freadfile) != NULL) {
int offset=0;
char *ch;
char chk_space=1;
/* trim string in place - don't remove spaces in middle */
ch = fbuff;
while (*ch) {
if (*ch == '\r' || *ch == '\n') {
*ch = '\0';
}
if (offset) {
*(ch-offset) = *ch;
}
if (*ch == '\t' || *ch == ' ') {
if (chk_space) {
offset++;
}
} else {
chk_space=0;
}
ch++;
}
/* remove trailing spaces */
ch = fbuff + strlen(fbuff) - 1;
while (*ch) {
if (*ch == '\t' || *ch == ' ') {
*ch = '\0';
--ch;
} else {
break;
}
}
/* validate name and add it */
chdir ("/"); /* support both absolute and relative path */
if (*fbuff) {
if (file_exists_w(fbuff)) {
strcat(fbuff, "\n");
write(outfile, fbuff, strlen(fbuff));
if (verbose)
fprintf(stdout, " %s", fbuff);
}
}
}
fclose(freadfile);
}
/* combine files starting with fnamebase into outfile */
int cmb_files(int outfile, const char *fnamebase, int verbose)
{
/* scan the directory and add matching files */
struct dirent **namelist;
int namecount;
char addfilename[STRING_SIZE];
/* scan the directory and get a count of the files */
if ((namecount=scandir(CONFIG_ROOT"/backup", &namelist, 0, alphasort))<0) {
fprintf(stderr, "No files found\n");
exit(1);
}
/* process the scanned names */
while (namecount--) {
/* check names - compare beginning of name, ignoring case, ignore EXCLUDE_HARDWARE */
if ((strncasecmp(fnamebase, namelist[namecount]->d_name, strlen(fnamebase))==0) &&
(strncmp(EXCLUDE_HARDWARE,namelist[namecount]->d_name, strlen(EXCLUDE_HARDWARE)))) {
/* add the contents for this name to output file */
sprintf(addfilename, CONFIG_ROOT"/backup/%s", namelist[namecount]->d_name);
if (verbose)
fprintf(stdout, "%s\n", namelist[namecount]->d_name);
add_file(outfile, addfilename, verbose);
free(namelist[namecount]);
if (verbose)
fprintf(stdout, "\n");
}
}
free(namelist);
return 0;
}
void exithandler(void)
{
/* clean up temporary files */
if (temptarfilename)
unlink (temptarfilename);
if (tempincfilename)
unlink (tempincfilename);
if (tempexcfilename)
unlink (tempexcfilename);
}
int main(int argc, char**argv)
{
int verbose=0;
char command[STRING_SIZE];
char hostname[STRING_SIZE];
int includefile, excludefile;
if (!(initsetuid()))
exit(1);
if (argc==2 && strcmp(argv[1],"--verbose")==0)
verbose=1; // display to stdout wich (ex|in)clude files are used
gethostname(hostname, STRING_SIZE-1);
if (!file_exists(BACKUP_KEY)) {
fprintf (stderr, "Couldn't locate encryption key\n");
exit (ERR_KEY);
}
/* now exithandler will have something to erase */
atexit(exithandler);
/* combine every include and exclude files in backup directory into two temp file
* at the exception of exclude.hardware only used optionally on restore */
/* create/open temp output file */
// Todo: use -X exclude.files and for include.files, build the list on command line
// to avoid unneccesary files manipulations
strcpy (tempincfilename, "/tmp/backup-inclusion.XXXXXX");
strcpy (tempexcfilename, "/tmp/backup-exclusion.XXXXXX");
if ( (!(includefile = mkstemp (tempincfilename)) > 0) ||
(!(excludefile = mkstemp (tempexcfilename)) > 0) ){
fprintf(stderr, "Couldn't create temporary file.\n");
exit(1);
}
cmb_files(includefile, "include.", verbose);
close(includefile);
cmb_files(excludefile, "exclude.", verbose);
close(excludefile);
/* Create temporary tarfile */
strcpy (temptarfilename, TMP_TAR);
/* Start tarring files to temp archive
W (verify) and z (compress) tar options can't be used together, so separate tar from gzip */
snprintf (command, STRING_SIZE-1, "/bin/tar -T %s -X %s -C / -cWf %s > /dev/null 2> /dev/null",
tempincfilename, tempexcfilename, temptarfilename);
if (safe_system (command)) {
fprintf (stderr, "Couldn't create %s file\n", temptarfilename);
exit (ERR_TAR);
}
unlink (tempincfilename);
strcpy (tempincfilename,"");
unlink (tempexcfilename);
strcpy (tempincfilename,"");
/* Compress archive */
snprintf (command, STRING_SIZE-1, "/bin/gzip -c < %s > "MOUNTPOINT"/%s.tar.gz", temptarfilename, hostname);
if (safe_system (command)) {
fprintf (stderr, "Couldn't create "MOUNTPOINT"%s.tar.gz file\n", hostname);
exit (ERR_GZ);
}
unlink (temptarfilename);
strcpy (temptarfilename,"");
/* Display to stdout include files names */
snprintf (command, STRING_SIZE-1, "/bin/tar -ztf "MOUNTPOINT"/%s.tar.gz", hostname);
if (safe_system (command)) {
fprintf (stderr, "Couldn't read %s.tar.gz file\n", hostname);
exit (ERR_TAR);
}
/* Encrypt archive */
snprintf (command, STRING_SIZE-1,
"/usr/bin/openssl des3 -e -salt -in "MOUNTPOINT"/%s.tar.gz "
"-out "MOUNTPOINT"/%s.dat -kfile " BACKUP_KEY, hostname, hostname);
if (safe_system (command)) {
fprintf (stderr, "Couldn't encrypt archive\n");
exit (ERR_ENCRYPT);
}
snprintf (command, STRING_SIZE-1, MOUNTPOINT"/%s.tar.gz", hostname);
unlink (command);
/* Make sure web can overwrite */
snprintf (command, STRING_SIZE-1, MOUNTPOINT"/%s.dat", hostname);
chown (command, 99, 99);
exit(0);
}

View File

@@ -0,0 +1,25 @@
/* SmoothWall helper program - smoothiedeath
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Simple program intended to be installed setuid(0) that can be used for
* starting shutdown.
*
* $Id: ipcopdeath.c,v 1.2 2003/12/11 10:57:34 riddles Exp $
*
*/
#include <stdlib.h>
#include "setuid.h"
int main(void)
{
if (!(initsetuid()))
exit(1);
safe_system("/sbin/shutdown -h now");
return 0;
}

View File

@@ -0,0 +1,25 @@
/* SmoothWall helper program - smoothierebirth
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Simple program intended to be installed setuid(0) that can be used for
* starting reboot.
*
* $Id: ipcoprebirth.c,v 1.2 2003/12/11 10:57:34 riddles Exp $
*
*/
#include <stdlib.h>
#include "setuid.h"
int main(void)
{
if (!(initsetuid()))
exit(1);
safe_system("/sbin/shutdown -r now");
return 0;
}

View File

@@ -0,0 +1,117 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2005-10-25 Franck Bourdonnec
*
* $Id: ipcopreboot.c,v 1.1.2.2 2005/10/24 23:05:50 franck78 Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "setuid.h"
/* define operations */
#define OP_REBOOT "boot"
#define OP_REBOOT_FS "bootfs" // add filesystem check option (not yet in GUI)
#define OP_SHUTDOWN "down"
#define OP_SCHEDULE_ADD "cron+"
#define OP_SCHEDULE_REM "cron-"
#define OP_SCHEDULE_GET "cron?"
int main(int argc, char**argv)
{
if (!(initsetuid()))
return 1;
// Check what command is asked
if (argc==1)
{
fprintf (stderr, "Missing reboot command!\n");
return 1;
}
if (argc==2 && strcmp(argv[1], OP_SHUTDOWN)==0)
{
safe_system("/sbin/shutdown -h now");
return 0;
}
if (argc==2 && strcmp(argv[1], OP_REBOOT)==0)
{
safe_system("/sbin/shutdown -r now");
return 0;
}
if (argc==2 && strcmp(argv[1], OP_REBOOT_FS)==0)
{
safe_system("/sbin/shutdown -F -r now");
return 0;
}
// output schedule to stdout
if (argc==2 && strcmp(argv[1], OP_SCHEDULE_GET)==0)
{
safe_system("/bin/grep /sbin/shutdown /var/spool/cron/root.orig");
return 0;
}
if (argc==2 && strcmp(argv[1], OP_SCHEDULE_REM)==0)
{
safe_system("/usr/bin/perl -i -p -e 's/^.*\\/sbin\\/shutdown.*$//s' /var/spool/cron/root.orig");
safe_system("/usr/bin/fcrontab -u root -z");
return 0;
}
if (argc==6 && strcmp(argv[1], OP_SCHEDULE_ADD)==0)
{
// check args
if (!( strlen(argv[2])<3 &&
strspn(argv[2], "0123456789") == strlen (argv[2]) &&
strlen(argv[3])<3 &&
strspn(argv[3], "0123456789") == strlen (argv[3]) &&
strlen(argv[4])<14 &&
strspn(argv[4], "1234567,*") == strlen (argv[4]) &&
((strcmp(argv[5], "-r")==0) || //reboot
(strcmp(argv[5], "-h")==0)) ) //hangup
) {
fprintf (stderr, "Bad cron+ parameters!\n");
return 1;
}
// remove old entry
safe_system("/usr/bin/perl -i -p -e 's/^.*\\/sbin\\/shutdown.*$//s' /var/spool/cron/root.orig");
// add new entry
FILE *fd = NULL;
if ((fd = fopen("/var/spool/cron/root.orig", "a")))
{
fprintf (fd,"%s %s * * %s /sbin/shutdown %s 1\n",argv[2],argv[3],argv[4],argv[5]);
fclose (fd);
}
// inform cron
safe_system("/usr/bin/fcrontab -u root -z");
return 0;
}
fprintf (stderr, "Bad reboot command!\n");
return 1;
}

116
src/misc-progs/ipcoprscfg.c Normal file
View File

@@ -0,0 +1,116 @@
/*
* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2003-06-25 Tim Butterfield <timbutterfield@mindspring.com>
*
* $Id: ipcoprscfg.c,v 1.2.2.6 2005/11/21 00:11:39 franck78 Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <grp.h>
#include <dirent.h>
#include "setuid.h"
#define TMP_FILEZ "/tmp/TMPFILE.tar.gz"
#define TMP_FILE "/tmp/TMPFILE.tar"
/* check existence of a data file */
int data_exists(const char *hostname) {
char fname[STRING_SIZE];
snprintf (fname, STRING_SIZE-1, MOUNTPOINT"/%s.dat", hostname);
return file_exists(fname);
}
int main(int argc, char**argv) {
int rshardware=0;
char command[STRING_SIZE];
char hostname[STRING_SIZE];
if (argc==2 && strcmp(argv[1],"--hardware")==0)
rshardware=1; // restore hardware settings
gethostname(hostname, STRING_SIZE-1);
/* Init setuid */
if (!initsetuid())
exit(1);
/* if a key file exists, an encrypted .dat is required */
if (!file_exists(BACKUP_KEY)) {
fprintf (stderr, "Missing encryption key\n");
exit (ERR_DECRYPT);
}
if (!data_exists(hostname)) {
fprintf (stderr, "Missing encrypted archive "MOUNTPOINT"/%s.dat archive\n", hostname);
exit (ERR_DAT);
}
/* decrypt .dat file to tmp file */
snprintf (command, STRING_SIZE-1, "/usr/bin/openssl des3 -d -salt -in "MOUNTPOINT"/%s.dat -out "TMP_FILEZ" -kfile "BACKUP_KEY" > /dev/null 2> /dev/null", hostname);
if (safe_system (command)) {
fprintf (stderr, "Couldn't decrypt "MOUNTPOINT"/%s.dat archive\n", hostname);
exit (ERR_DECRYPT);
}
/* create temporary directory for testing untar */
char tmp_dir[STRING_SIZE];
strcpy (tmp_dir,"cfg_XXXXXXX");
if (mkdtemp (tmp_dir)==NULL) {
unlink (TMP_FILEZ);
exit (ERR_ANY);
}
/* Start (test) untarring files from compressed archive */
snprintf (command, STRING_SIZE-1, "/bin/tar -C %s -xzvf "TMP_FILEZ" > /dev/null 2> /dev/null",tmp_dir);
if (safe_system (command)) {
fprintf (stderr, "Archive have errors!\n");
unlink (TMP_FILEZ);
exit (ERR_UNTARTST);
}
/* remove temporary directory */
snprintf (command, STRING_SIZE-1, "/bin/rm -rf %s > /dev/null 2> /dev/null",tmp_dir);
safe_system (command);
/* Start (real) untarring files from compressed archive */
char extraX[STRING_SIZE] = "";
int retcode = 0;
if (rshardware==0) { /* extra eXclusion from restore */
strcpy (extraX, "-X "CONFIG_ROOT"/backup/exclude.hardware ");
}
snprintf (command, STRING_SIZE-1, "/bin/tar -C / -xzvf "TMP_FILEZ" -X "CONFIG_ROOT"/backup/exclude.system %s > /dev/null 2> /dev/null", extraX);
if (safe_system (command)) {
fprintf (stderr, "Error restoring archive\n");
retcode = ERR_UNTAR;
}
/* remove temporary archive copy */
unlink (TMP_FILEZ);
exit(retcode);
}

332
src/misc-progs/ipsecctrl.c Normal file
View File

@@ -0,0 +1,332 @@
/*
*
* File originally from the Smoothwall project
* (c) 2001 Smoothwall Team
*
* $Id: ipsecctrl.c,v 1.5.2.14 2005/05/15 12:58:28 rkerr Exp $
*
*/
#include "libsmooth.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "setuid.h"
void usage() {
fprintf (stderr, "Usage:\n");
fprintf (stderr, "\tipsecctrl S [connectionkey]\n");
fprintf (stderr, "\tipsecctrl D [connectionkey]\n");
fprintf (stderr, "\tipsecctrl R\n");
fprintf (stderr, "\t\tS : Start/Restart Connection\n");
fprintf (stderr, "\t\tD : Stop Connection\n");
fprintf (stderr, "\t\tR : Reload Certificates and Secrets\n");
}
void loadalgmodules() {
safe_system("/sbin/modprobe ipsec_3des");
safe_system("/sbin/modprobe ipsec_aes");
safe_system("/sbin/modprobe ipsec_blowfish");
safe_system("/sbin/modprobe ipsec_md5");
safe_system("/sbin/modprobe ipsec_serpent");
safe_system("/sbin/modprobe ipsec_sha1");
safe_system("/sbin/modprobe ipsec_sha2");
safe_system("/sbin/modprobe ipsec_twofish");
}
void ipsecrules(char *chain, char *interface)
{
char str[STRING_SIZE];
sprintf(str, "/sbin/iptables -A %s -p 47 -i %s -j ACCEPT", chain, interface);
safe_system(str);
sprintf(str, "/sbin/iptables -A %s -p 50 -i %s -j ACCEPT", chain, interface);
safe_system(str);
sprintf(str, "/sbin/iptables -A %s -p 51 -i %s -j ACCEPT", chain, interface);
safe_system(str);
sprintf(str, "/sbin/iptables -A %s -p udp -i %s --sport 500 --dport 500 -j ACCEPT", chain, interface);
safe_system(str);
sprintf(str, "/sbin/iptables -A %s -p udp -i %s --dport 4500 -j ACCEPT", chain, interface);
safe_system(str);
}
void addaliasinterfaces(char *configtype, char *redtype, char *redif, char *enablered, char*enableblue)
{
FILE *file = NULL;
char s[STRING_SIZE];
char *sptr;
char *aliasip=NULL;
char *enabled=NULL;
char *comment=NULL;
int count=0;
int alias=0;
int add=0;
if ( strcmp(enablered, "on") == 0 )
add += 1;
if ( strcmp(enableblue, "on") == 0 )
add += 1;
/* Check for CONFIG_TYPE=2 or 3 i.e. RED ethernet present. If not,
* exit gracefully. This is not an error... */
if (!((strcmp(configtype, "2")==0) || (strcmp(configtype, "3")==0) || (strcmp(configtype, "6")==0) || (strcmp(configtype, "7")==0)))
return;
/* Now check the RED_TYPE - aliases only work with STATIC. */
if (!(strcmp(redtype, "STATIC")==0))
return;
/* Now set up the new aliases from the config file */
if (!(file = fopen(CONFIG_ROOT "/ethernet/aliases", "r")))
{
fprintf(stderr, "Unable to open aliases configuration file\n");
return;
}
while (fgets(s, STRING_SIZE, file) != NULL && (add+alias) < 16)
{
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
sptr = strtok(s, ",");
count = 0;
aliasip = NULL;
enabled = NULL;
comment = NULL;
while (sptr)
{
if (count == 0)
aliasip = sptr;
if (count == 1)
enabled = sptr;
else
comment = sptr;
count++;
sptr = strtok(NULL, ",");
}
if (!(aliasip && enabled))
continue;
if (!VALID_IP(aliasip))
{
fprintf(stderr, "Bad alias : %s\n", aliasip);
return;
}
if (strcmp(enabled, "on") == 0)
{
memset(s, 0, STRING_SIZE);
snprintf(s, STRING_SIZE-1, "/usr/sbin/ipsec tncfg --attach --virtual ipsec%d --physical %s:%d >/dev/null", alias+add, redif, alias);
safe_system(s);
alias++;
}
}
}
int main(int argc, char *argv[]) {
int count;
char s[STRING_SIZE];
char configtype[STRING_SIZE];
char redtype[STRING_SIZE] = "";
char command[STRING_SIZE];
char *result;
char *key;
char *enabled;
char *name;
char *type;
char *running;
FILE *file = NULL;
struct keyvalue *kv = NULL;
char enablered[STRING_SIZE] = "off";
char enableblue[STRING_SIZE] = "off";
char redif[STRING_SIZE] = "";;
char blueif[STRING_SIZE] = "";
FILE *ifacefile = NULL;
if (!(initsetuid()))
exit(1);
if (argc < 2) {
usage();
exit(1);
}
/* FIXME: workaround for pclose() issue - still no real idea why
* this is happening */
signal(SIGCHLD, SIG_DFL);
/* Init the keyvalue structure */
kv=initkeyvalues();
/* Read in the current values */
if (!readkeyvalues(kv, CONFIG_ROOT "/vpn/settings"))
{
fprintf(stderr, "Cannot read vpn settings\n");
exit(1);
}
findkey(kv, "ENABLED", enablered);
findkey(kv, "ENABLED_BLUE", enableblue);
freekeyvalues(kv);
kv=initkeyvalues();
if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))
{
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
if (!findkey(kv, "CONFIG_TYPE", configtype))
{
fprintf(stderr, "Cannot read CONFIG_TYPE\n");
exit(1);
}
findkey(kv, "RED_TYPE", redtype);
findkey(kv, "BLUE_DEV", blueif);
freekeyvalues(kv);
memset(redif, 0, STRING_SIZE);
if ((ifacefile = fopen(CONFIG_ROOT "/red/iface", "r")))
{
if (fgets(redif, STRING_SIZE, ifacefile))
{
if (redif[strlen(redif) - 1] == '\n')
redif[strlen(redif) - 1] = '\0';
}
fclose (ifacefile);
ifacefile = NULL;
if (!VALID_DEVICE(redif))
{
memset(redif, 0, STRING_SIZE);
}
}
safe_system("/sbin/iptables -F IPSECRED");
if (!strcmp(enablered, "on") && strlen(redif)) {
ipsecrules("IPSECRED", redif);
}
safe_system("/sbin/iptables -F IPSECBLUE");
if (!strcmp(enableblue, "on")) {
if (VALID_DEVICE(blueif))
ipsecrules("IPSECBLUE", blueif);
else
{
fprintf(stderr, "IPSec enabled on blue but blue interface is invalid or not found\n");
exit(1);
}
}
/* Only shutdown pluto if it really is running */
if (argc == 2) {
if (strcmp(argv[1], "D") == 0) {
int fd;
/* Get pluto pid */
if ((fd = open("/var/run/pluto.pid", O_RDONLY)) != -1) {
safe_system("/etc/rc.d/ipsec stop 2> /dev/null >/dev/null");
close(fd);
}
}
}
if ((strcmp(enablered, "on") || !strlen(redif)) && strcmp(enableblue, "on"))
exit(0);
if (argc == 2) {
if (strcmp(argv[1], "S") == 0) {
loadalgmodules();
safe_system("/usr/sbin/ipsec tncfg --clear >/dev/null");
safe_system("/etc/rc.d/ipsec restart >/dev/null");
addaliasinterfaces(configtype, redtype, redif, enablered, enableblue);
} else if (strcmp(argv[1], "R") == 0) {
safe_system("/usr/sbin/ipsec auto --rereadall");
} else {
fprintf(stderr, "Bad arg\n");
usage();
exit(1);
}
} else if (strspn(argv[2], NUMBERS) == strlen(argv[2])) {
if (!(file = fopen(CONFIG_ROOT "/vpn/config", "r"))) {
fprintf(stderr, "Couldn't open vpn settings file");
exit(1);
}
while (fgets(s, STRING_SIZE, file) != NULL) {
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
running = strdup (s);
result = strsep(&running, ",");
count = 0;
key = NULL;
name = NULL;
enabled = NULL;
type = NULL;
while (result) {
if (count == 0)
key = result;
if (count == 1)
enabled = result;
if (count == 2)
name = result;
if (count == 4)
type = result;
count++;
result = strsep(&running, ",");
}
if (strcmp(key, argv[2]) != 0)
continue;
if (!(name && enabled))
continue;
if (strspn(name, LETTERS_NUMBERS) != strlen(name)) {
fprintf(stderr, "Bad connection name: %s\n", name);
goto EXIT;
}
if (! (strcmp(type, "host") == 0 || strcmp(type, "net") == 0)) {
fprintf(stderr, "Bad connection type: %s\n", type);
goto EXIT;
}
if (strcmp(argv[1], "S") == 0 && strcmp(enabled, "on") == 0) {
safe_system("/usr/sbin/ipsec auto --rereadsecrets >/dev/null");
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1,
"/usr/sbin/ipsec auto --replace %s >/dev/null", name);
safe_system(command);
if (strcmp(type, "net") == 0) {
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1,
"/usr/sbin/ipsec auto --asynchronous --up %s >/dev/null", name);
safe_system(command);
}
} else if (strcmp(argv[1], "D") == 0) {
safe_system("/usr/sbin/ipsec auto --rereadsecrets >/dev/null");
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1,
"/usr/sbin/ipsec auto --down %s >/dev/null", name);
safe_system(command);
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1,
"/usr/sbin/ipsec auto --delete %s >/dev/null", name);
safe_system(command);
}
}
} else {
fprintf(stderr, "Bad arg\n");
usage();
exit(1);
}
EXIT:
if (file)
fclose(file);
return 0;
}

112
src/misc-progs/logwatch.c Normal file
View File

@@ -0,0 +1,112 @@
/* This file is part of the IPCop Firewall.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* Copyright (C) 2003-07-12 Robert Kerr <rkerr@go.to>
*
* $Id: logwatch.c,v 1.2 2003/12/11 11:25:54 riddles Exp $
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>
#include <pwd.h>
#include <sys/types.h>
#include "libsmooth.h"
#include "setuid.h"
/* Lots of distros just run logwatch as root from cron, but logwatch doesn't
* need any root privs, just the ability to access it's filter scripts
* (/etc/log.d/) and the log files (under /var/log/). By creating a logwatch
* user and group and ensuring it has read access to the logs we can run
* logwatch unprivileged. Apart from the principle of least privilege running
* logwatch as root turns out to be doubly a bad idea because a flaw in the way
* it works:
*
* http://www.securityfocus.com/archive/1/327833/2003-07-01/2003-07-07/0
*
* This wrapper program should be run as root, but not installed setuid root,
* it's basic aim is to allow a root cron job to safely run logcheck; as such
* it will drop privileges, becoming the locheck user & group then run
* logcheck. In many ways this is much the same as getting cron to run
* su -s /etc/log.d/scripts/logwatch.pl
* the wrapper however is able to read configuration info from /var/ipcop and
* pass the correct args to logwatch
*/
int main(void)
{
char buffer[STRING_SIZE];
struct keyvalue *kv = NULL;
struct passwd *pw;
gid_t groups[2];
char * argv[4];
if(getuid())
{
fprintf(stderr, "logwatch should be ran by root\n");
exit(1);
}
/* Read in and verify config */
kv=initkeyvalues();
if (!readkeyvalues(kv, CONFIG_ROOT "/logging/settings"))
{
fprintf(stderr, "Cannot read syslog settings\n");
exit(1);
}
if (!findkey(kv, "LOGWATCH_LEVEL", buffer))
{
fprintf(stderr, "Cannot read LOGWATCH_LEVEL\n");
exit(1);
}
if (strcmp(buffer,"Low") && strcmp(buffer,"Med") && strcmp(buffer,"High"))
{
fprintf(stderr, "Bad LOGWATCH_LEVEL: %s\n", buffer);
exit(1);
}
freekeyvalues(kv);
/* lookup logwatch user */
if(!(pw = getpwnam("logwatch")))
{
fprintf(stderr,"Couldn't find logwatch user.\n");
exit(1);
}
/* paranoia... */
memset(pw->pw_passwd, 0, strlen(pw->pw_passwd));
endpwent();
/* more paranoia */
if(!pw->pw_uid || !pw->pw_gid)
{
fprintf(stderr,"logwatch user appears to be UID or GID 0, aborting.\n");
exit(1);
}
/* drop privs */
groups[0] = groups[1] = pw->pw_gid;
if (setgroups(1,groups)) { perror("Couldn't clear group list"); exit(1); }
if (setgid(pw->pw_gid)) { perror("Couldn't setgid(logwatch)"); exit(1); }
if (setuid(pw->pw_uid)) { perror("Couldn't setuid(logwatch)"); exit(1); }
/* ok, spawn logwatch */
argv[0] = "logwatch.pl";
argv[1] = "--detail";
argv[2] = buffer;
argv[3] = NULL;
execve("/etc/log.d/scripts/logwatch.pl", argv, trusted_env);
/* shouldn't get here - execve replaces current running process */
perror("logwatch: execve failed");
exit(1);
}

View File

@@ -0,0 +1,154 @@
/* IPCop helper program - rebuildhosts
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Alan Hourihane, 2003
*
*
* $Id: rebuildhosts.c,v 1.3.2.6 2005/07/11 10:56:47 franck78 Exp $
*
*/
#include "libsmooth.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "setuid.h"
FILE *fd = NULL;
FILE *hosts = NULL;
struct keyvalue *kv = NULL;
void exithandler(void)
{
if (kv)
freekeyvalues(kv);
if (fd)
fclose(fd);
if (hosts)
fclose(hosts);
}
int main(int argc, char *argv[])
{
int fdpid;
char hostname[STRING_SIZE];
char domainname[STRING_SIZE] = "";
char buffer[STRING_SIZE];
char address[STRING_SIZE];
char *active, *ip, *host, *domain;
int pid;
if (!(initsetuid()))
exit(1);
atexit(exithandler);
memset(buffer, 0, STRING_SIZE);
kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
fprintf(stderr, "Couldn't read ethernet settings\n");
exit(1);
}
findkey(kv, "GREEN_ADDRESS", address);
freekeyvalues(kv);
kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/main/settings")))
{
fprintf(stderr, "Couldn't read main settings\n");
exit(1);
}
strcpy(hostname, SNAME );
findkey(kv, "HOSTNAME", hostname);
findkey(kv, "DOMAINNAME", domainname);
freekeyvalues(kv);
kv = NULL;
if (!(fd = fopen(CONFIG_ROOT "/main/hosts", "r")))
{
fprintf(stderr, "Couldn't open main hosts file\n");
exit(1);
}
if (!(hosts = fopen("/etc/hosts", "w")))
{
fprintf(stderr, "Couldn't open /etc/hosts file\n");
fclose(fd);
fd = NULL;
exit(1);
}
fprintf(hosts, "127.0.0.1\tlocalhost\n");
if (strlen(domainname))
fprintf(hosts, "%s\t%s.%s\t%s\n",address,hostname,domainname,hostname);
else
fprintf(hosts, "%s\t%s\n",address,hostname);
while (fgets(buffer, STRING_SIZE, fd))
{
buffer[strlen(buffer) - 1] = 0;
if (buffer[0]==',') continue; /* disabled if empty field */
active = strtok(buffer, ",");
if (strcmp(active, "off")==0) continue; /* or 'off' */
ip = strtok(NULL, ",");
host = strtok(NULL, ",");
domain = strtok(NULL, ",");
if (!(ip && host))
continue; // bad line ? skip
if (!VALID_IP(ip))
{
fprintf(stderr, "Bad IP: %s\n", ip);
continue; /* bad ip, skip */
}
if (strspn(host, LETTERS_NUMBERS "-") != strlen(host))
{
fprintf(stderr, "Bad Host: %s\n", host);
continue; /* bad name, skip */
}
if (domain)
fprintf(hosts, "%s\t%s.%s\t%s\n",ip,host,domain,host);
else
fprintf(hosts, "%s\t%s\n",ip,host);
}
fclose(fd);
fd = NULL;
fclose(hosts);
hosts = NULL;
if ((fdpid = open("/var/run/dnsmasq.pid", O_RDONLY)) == -1)
{
fprintf(stderr, "Couldn't open pid file\n");
exit(1);
}
if (read(fdpid, buffer, STRING_SIZE - 1) == -1)
{
fprintf(stderr, "Couldn't read from pid file\n");
close(fdpid);
exit(1);
}
close(fdpid);
pid = atoi(buffer);
if (pid <= 1)
{
fprintf(stderr, "Bad pid value\n");
exit(1);
}
if (kill(pid, SIGHUP) == -1)
{
fprintf(stderr, "Unable to send SIGHUP\n");
exit(1);
}
return 0;
}

View File

@@ -0,0 +1,145 @@
/* SmoothWall helper program - restartdhcp
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Simple program intended to be installed setuid(0) that can be used for
* restarting DHCPd.
*
* $Id: restartdhcp.c,v 1.5.2.1 2004/11/03 13:50:26 alanh Exp $
*
*/
#include "libsmooth.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "setuid.h"
int main(void)
{
int fd = -1;
int fdblue = -1;
char buffer[STRING_SIZE];
char blue_dev[STRING_SIZE] = "", green_dev[STRING_SIZE] = "";
int pid;
struct keyvalue *kv = NULL;
if (!(initsetuid()))
exit(1);
memset(buffer, 0, STRING_SIZE);
/* Init the keyvalue structure */
kv=initkeyvalues();
/* Read in the current values */
if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))
{
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
if (!findkey(kv, "GREEN_DEV", green_dev))
{
fprintf(stderr, "Cannot read GREEN_DEV\n");
exit(1);
}
if (!VALID_DEVICE(green_dev))
{
fprintf(stderr, "Bad GREEN_DEV: %s\n", green_dev);
exit(1);
}
/* Get the BLUE interface details */
findkey(kv, "BLUE_DEV", blue_dev);
freekeyvalues(kv);
if ((fdblue = open(CONFIG_ROOT "/dhcp/enable_blue", O_RDONLY)) != -1)
{
close(fdblue);
if (!VALID_DEVICE(blue_dev))
{
fprintf(stderr, "Bad BLUE_DEV: %s\n", blue_dev);
exit(1);
}
}
if ((fd = open("/var/run/dhcpd.pid", O_RDONLY)) != -1)
{
if (read(fd, buffer, STRING_SIZE - 1) == -1)
fprintf(stderr, "Couldn't read from pid file\n");
else
{
pid = atoi(buffer);
if (pid <= 1)
fprintf(stderr, "Bad pid value\n");
else
{
if (kill(pid, SIGTERM) == -1)
fprintf(stderr, "Unable to send SIGTERM\n");
else
unlink("/var/run/dhcpd.pid");
}
}
safe_system("/bin/killall -KILL dhcpd");
close(fd);
}
safe_system("/sbin/iptables -F DHCPBLUEINPUT");
buffer[0] = '\0';
if ((fd = open(CONFIG_ROOT "/dhcp/enable_green", O_RDONLY)) != -1)
{
close(fd);
if ((fdblue = open(CONFIG_ROOT "/dhcp/enable_blue", O_RDONLY)) != -1)
{
close(fdblue);
snprintf(buffer, STRING_SIZE-1, "/sbin/iptables -A DHCPBLUEINPUT -p tcp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev);
safe_system(buffer);
snprintf(buffer, STRING_SIZE-1, "/sbin/iptables -A DHCPBLUEINPUT -p udp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev);
safe_system(buffer);
snprintf(buffer, STRING_SIZE-1, "/usr/sbin/dhcpd -q %s %s", green_dev, blue_dev);
} else {
snprintf(buffer, STRING_SIZE-1, "/usr/sbin/dhcpd -q %s", green_dev);
}
safe_system(buffer);
} else {
if ((fdblue = open(CONFIG_ROOT "/dhcp/enable_blue", O_RDONLY)) != -1)
{
close(fdblue);
snprintf(buffer, STRING_SIZE-1, "/sbin/iptables -A DHCPBLUEINPUT -p tcp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev);
safe_system(buffer);
snprintf(buffer, STRING_SIZE-1, "/sbin/iptables -A DHCPBLUEINPUT -p udp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev);
safe_system(buffer);
snprintf(buffer, STRING_SIZE-1, "/usr/sbin/dhcpd -q %s", blue_dev);
safe_system(buffer);
}
}
if (buffer[0] != '\0')
{
/* Silly dhcpd creates pids with mode 640 */
sleep (1);
if ((fd = open("/var/run/dhcpd.pid", 0)) == -1)
{
fprintf(stderr, "No pid file\n");
return 1;
}
fchmod(fd, 00644);
close(fd);
}
return 0;
}

View File

@@ -0,0 +1,42 @@
/* Ipcop helper program - restartntpd
*
* Starts or stops the ntpd daemon
*
* (c) Darren Critchley 2003
*
* $Id: restartntpd.c,v 1.5 2003/12/19 14:29:09 riddles Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include "setuid.h"
int main(void)
{
int fd = -1;
int enable = 0;
if (!(initsetuid()))
exit(1);
safe_system("/bin/killall ntpd 2> /dev/null");
sleep(3);
if ((fd = open(CONFIG_ROOT "/time/allowclients", O_RDONLY)) != -1)
{
close(fd);
enable = 1;
}
if (enable)
{
safe_system("/usr/bin/ntpd -Ap /var/run/ntpd.pid -u ntp:ntp");
}
return 0;
}

View File

@@ -0,0 +1,234 @@
/* IPCop helper program - restartshaping
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* Copyright (C) 2002-04-09 Mark Wormgoor <mark@wormgoor.com>
*
* $Id: restartshaping.c,v 1.2.2.5 2005/01/28 13:11:40 riddles Exp $
*
*/
#include "libsmooth.h"
#include "setuid.h"
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *file = NULL, *ifacefile = NULL;
struct keyvalue *kv = NULL;
int uplink, downlink, count = 0, r2q = 10;
char command[STRING_SIZE];
char iface[STRING_SIZE] = "";
char s[STRING_SIZE];
char *result;
char proto[STRING_SIZE];
char *protocol;
char *port;
char *prio;
char *enabled;
if (!(initsetuid())) {
fprintf(stderr, "Cannot run setuid\n");
exit(1);
}
/* Init the keyvalue structure */
kv=initkeyvalues();
/* Read in the current values */
if (!readkeyvalues(kv, CONFIG_ROOT "/shaping/settings"))
{
fprintf(stderr, "Cannot read shaping settings\n");
goto EXIT;
}
/* See what interface there is */
if ((ifacefile = fopen(CONFIG_ROOT "/red/iface", "r")))
{
fgets(iface, STRING_SIZE, ifacefile);
if (iface[strlen(iface) - 1] == '\n')
iface[strlen(iface) - 1] = '\0';
fclose (ifacefile);
} else {
fprintf(stderr, "Couldn't open iface file\n");
return(1);
}
if (strspn(iface, LETTERS_NUMBERS) != strlen(iface))
{
fprintf(stderr, "Bad iface: %s\n", iface);
goto EXIT;
}
/* Find the VALID value */
if (!findkey(kv, "VALID", s))
{
fprintf(stderr, "Cannot read VALID\n");
goto EXIT;
}
/* Check if config is VALID */
if (! strcmp(s, "yes")==0)
goto EXIT;
snprintf(command, STRING_SIZE-1, "/sbin/tc qdisc del dev %s root", iface);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc qdisc del dev %s ingress", iface);
safe_system(command);
/* Find the ENABLE value */
if (!findkey(kv, "ENABLE", s))
{
fprintf(stderr, "Cannot read ENABLE\n");
goto EXIT;
}
/* Check if shaping is ENABLED */
if (! strcmp(s, "on")==0)
goto EXIT;
/* Find the UPLINK value */
if (!findkey(kv, "UPLINK", s))
{
fprintf(stderr, "Cannot read UPLINK\n");
goto EXIT;
}
uplink = atoi(s);
if (! uplink > 0) {
fprintf(stderr, "Invalid value for UPLINK\n");
goto EXIT;
}
/* In some limited testing, it was shown that
r2q = ( uplink * 1024 / 1500 );
* produced error messages from the kernel saying r2q needed to be
* changed. 1500 is taken as the MTU, but it seems that 16384 works
* better. -Alan.
*/
r2q = ( uplink * 1024 / 16384 );
uplink = (uplink * 100) / 101;
/* Find the DOWNLINK value */
if (!findkey(kv, "DOWNLINK", s))
{
fprintf(stderr, "Cannot read DOWNLINK\n");
goto EXIT;
}
downlink = atoi(s);
if (! downlink > 0) {
fprintf(stderr, "Invalid value for DOWNLINK\n");
goto EXIT;
}
downlink = (downlink * 200) / 201;
/* Uplink classes */
snprintf(command, STRING_SIZE-1, "/sbin/tc qdisc add dev %s root handle 1: htb default 20 r2q %d", iface, r2q);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc class add dev %s parent 1: classid 1:1 htb rate %dkbit", iface, uplink);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc class add dev %s parent 1:1 classid 1:10 htb rate %dkbit ceil %dkbit prio 1", iface, (8 * uplink) / 10, uplink);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc class add dev %s parent 1:1 classid 1:20 htb rate %dkbit ceil %dkbit prio 2", iface, (6 * uplink) / 10, uplink);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc class add dev %s parent 1:1 classid 1:30 htb rate %dkbit ceil %dkbit prio 3", iface, (4 * uplink) / 10, uplink);
safe_system(command);
/* Uplink Stochastic fairness queue */
snprintf(command, STRING_SIZE-1, "/sbin/tc qdisc add dev %s parent 1:10 handle 10: sfq perturb 10", iface);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc qdisc add dev %s parent 1:20 handle 20: sfq perturb 10", iface);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc qdisc add dev %s parent 1:30 handle 30: sfq perturb 10", iface);
safe_system(command);
/* TOS Minimum Delay and ICMP traffic for high priority queue */
snprintf(command, STRING_SIZE-1, "/sbin/tc filter add dev %s parent 1:0 protocol ip prio 10 u32 match ip tos 0x10 0xff flowid 1:10", iface);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc filter add dev %s parent 1:0 protocol ip prio 10 u32 match ip protocol 1 0xff flowid 1:10", iface);
safe_system(command);
/* ACK packets for high priority queue (to speed up downloads) */
snprintf(command, STRING_SIZE-1, "/sbin/tc filter add dev %s parent 1: protocol ip prio 10 u32 match ip protocol 6 0xff match u8 0x05 0x0f at 0 match u16 0x0000 0xffc0 at 2 match u8 0x10 0xff at 33 flowid 1:10", iface);
safe_system(command);
file = fopen(CONFIG_ROOT "/shaping/config", "r");
if (file)
{
while (fgets(s, STRING_SIZE, file) != NULL)
{
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
result = strtok(s, ",");
count = 0;
protocol = NULL;
port = NULL;
prio = NULL;
enabled = NULL;
while (result)
{
if (count == 0)
protocol = result;
else if (count == 1)
port = result;
else if (count == 2)
prio = result;
else if (count == 3)
enabled = result;
count++;
result = strtok(NULL, ",");
}
if (!(protocol && port && prio && enabled))
break;
if (strcmp(protocol, "tcp") == 0) {
strcpy(proto, "6");
} else if (strcmp(protocol, "udp") == 0) {
strcpy(proto, "17");
} else {
fprintf(stderr, "Bad protocol: %s\n", protocol);
goto EXIT;
}
if (strspn(port, PORT_NUMBERS) != strlen(port))
{
fprintf(stderr, "Bad port: %s\n", port);
goto EXIT;
}
if (strspn(prio, NUMBERS) != strlen(prio))
{
fprintf(stderr, "Bad priority: %s\n", prio);
goto EXIT;
}
if (strcmp(enabled, "on") == 0)
{
snprintf(command, STRING_SIZE-1, "/sbin/tc filter add dev %s parent 1: protocol ip prio 14 u32 match ip protocol %s 0xff match ip dport %s 0xffff flowid 1:%s", iface, proto, port, prio);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc filter add dev %s parent 1: protocol ip prio 15 u32 match ip protocol %s 0xff match ip sport %s 0xffff flowid 1:%s", iface, proto, port, prio);
safe_system(command);
}
}
}
/* Setting everything else to the default queue */
snprintf(command, STRING_SIZE-1, "/sbin/tc filter add dev %s parent 1: protocol ip prio 18 u32 match ip dst 0.0.0.0/0 flowid 1:20", iface);
safe_system(command);
/* Downlink Section */
snprintf(command, STRING_SIZE-1, "/sbin/tc qdisc add dev %s handle ffff: ingress", iface);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/tc filter add dev %s parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate %dkbit burst 10k drop flowid :1", iface, downlink);
safe_system(command);
EXIT:
if (kv) freekeyvalues(kv);
if (file) fclose(file);
return 0;
}

View File

@@ -0,0 +1,326 @@
/* SmoothWall helper program - restartsnort
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Restarting snort.
*
* $Id: restartsnort.c,v 1.8.2.3 2005/10/16 12:36:14 rkerr Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include "libsmooth.h"
#include "setuid.h"
struct keyvalue *kv = NULL;
FILE *varsfile = NULL;
void exithandler(void)
{
if (varsfile)
fclose (varsfile);
if (kv)
freekeyvalues(kv);
}
int killsnort(char *interface)
{
int fd;
char pidname[STRING_SIZE] = "";
char buffer[STRING_SIZE] = "";
int pid;
sprintf(pidname, "/var/run/snort_%s.pid", interface);
if ((fd = open(pidname, O_RDONLY)) != -1)
{
if (read(fd, buffer, STRING_SIZE - 1) == -1)
fprintf(stderr, "Couldn't read from pid file\n");
else
{
pid = atoi(buffer);
if (pid <= 1)
fprintf(stderr, "Bad pid value\n");
else
{
if (kill(pid, SIGTERM) == -1)
fprintf(stderr, "Unable to send SIGTERM\n");
close (fd);
return 0;
}
}
close(fd);
}
return 1;
}
int main(int argc, char *argv[])
{
int fd = -1;
FILE *ifacefile, *ipfile, *dns1file, *dns2file;
char iface[STRING_SIZE] = "";
char locip[STRING_SIZE] = "";
char dns1[STRING_SIZE] = "";
char dns2[STRING_SIZE] = "";
char command[STRING_SIZE] = "";
char greendev[STRING_SIZE] = "";
char orangedev[STRING_SIZE] = "";
char bluedev[STRING_SIZE] = "";
char greenip[STRING_SIZE] = "";
char orangeip[STRING_SIZE] = "";
char blueip[STRING_SIZE] = "";
struct stat st;
int i;
int restartred = 0, restartgreen = 0, restartblue = 0, restartorange = 0;
if (!(initsetuid()))
exit(1);
atexit(exithandler);
for (i=0; i<argc; i++) {
if (!strcmp(argv[i], "red"))
restartred = 1;
if (!strcmp(argv[i], "orange"))
restartorange = 1;
if (!strcmp(argv[i], "blue"))
restartblue = 1;
if (!strcmp(argv[i], "green"))
restartgreen = 1;
}
kv = initkeyvalues();
if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
exit(1);
if (! findkey(kv, "GREEN_DEV", greendev)) {
fprintf(stderr, "Couldn't find GREEN device\n");
exit(1);
}
if (! strlen (greendev) > 0) {
fprintf(stderr, "Couldn't find GREEN device\n");
exit(1);
}
if (!VALID_DEVICE(greendev))
{
fprintf(stderr, "Bad GREEN_DEV: %s\n", greendev);
exit(1);
}
if (!(findkey(kv, "GREEN_ADDRESS", greenip))) {
fprintf(stderr, "Couldn't find GREEN address\n");
exit(1);
}
if (!VALID_IP(greenip)) {
fprintf(stderr, "Bad GREEN_ADDRESS: %s\n", greenip);
exit(1);
}
if (findkey(kv, "ORANGE_DEV", orangedev) && strlen (orangedev) > 0) {
if (!VALID_DEVICE(orangedev))
{
fprintf(stderr, "Bad ORANGE_DEV: %s\n", orangedev);
exit(1);
}
if (!(findkey(kv, "ORANGE_ADDRESS", orangeip))) {
fprintf(stderr, "Couldn't find ORANGE address\n");
exit(1);
}
if (!VALID_IP(orangeip)) {
fprintf(stderr, "Bad ORANGE_ADDRESS: %s\n", orangeip);
exit(1);
}
}
if (findkey(kv, "BLUE_DEV", bluedev) && strlen (bluedev) > 0) {
if (!VALID_DEVICE(bluedev))
{
fprintf(stderr, "Bad BLUE_DEV: %s\n", bluedev);
exit(1);
}
if (!(findkey(kv, "BLUE_ADDRESS", blueip))) {
fprintf(stderr, "Couldn't find BLUE address\n");
exit(1);
}
if (!VALID_IP(blueip)) {
fprintf(stderr, "Bad BLUE_ADDRESS: %s\n", blueip);
exit(1);
}
}
stat(CONFIG_ROOT "/red/active", &st);
if (S_ISREG(st.st_mode)) {
if (!(ifacefile = fopen(CONFIG_ROOT "/red/iface", "r")))
{
fprintf(stderr, "Couldn't open iface file\n");
exit(0);
}
if (fgets(iface, STRING_SIZE, ifacefile))
{
if (iface[strlen(iface) - 1] == '\n')
iface[strlen(iface) - 1] = '\0';
}
fclose(ifacefile);
if (!VALID_DEVICE(iface))
{
fprintf(stderr, "Bad iface: %s\n", iface);
exit(0);
}
if (!(ipfile = fopen(CONFIG_ROOT "/red/local-ipaddress", "r")))
{
fprintf(stderr, "Couldn't open local ip file\n");
exit(0);
}
if (fgets(locip, STRING_SIZE, ipfile))
{
if (locip[strlen(locip) - 1] == '\n')
locip[strlen(locip) - 1] = '\0';
}
fclose (ipfile);
if (strlen(locip) && !VALID_IP(locip))
{
fprintf(stderr, "Bad local IP: %s\n", locip);
exit(1);
}
if (!(dns1file = fopen(CONFIG_ROOT "/red/dns1", "r")))
{
fprintf(stderr, "Couldn't open dns1 file\n");
exit(0);
}
if (fgets(dns1, STRING_SIZE, dns1file))
{
if (dns1[strlen(dns1) - 1] == '\n')
dns1[strlen(dns1) - 1] = '\0';
}
fclose (dns1file);
if (strlen(dns1) && !VALID_IP(dns1))
{
fprintf(stderr, "Bad DNS1 IP: %s\n", dns1);
exit(1);
}
if (!(dns2file = fopen(CONFIG_ROOT "/red/dns2", "r")))
{
fprintf(stderr, "Couldn't open dns2 file\n");
exit(1);
}
if (fgets(dns2, STRING_SIZE, dns2file))
{
if (dns2[strlen(dns2) - 1] == '\n')
dns2[strlen(dns2) - 1] = '\0';
}
fclose (dns2file);
if (strlen(dns2) && !VALID_IP(dns2))
{
fprintf(stderr, "Bad DNS2 IP: %s\n", dns2);
exit(1);
}
}
if (restartred)
killsnort(iface);
if (restartblue)
killsnort(bluedev);
if (restartorange)
killsnort(orangedev);
if (restartgreen)
killsnort(greendev);
if (!(varsfile = fopen("/etc/snort/vars", "w")))
{
fprintf(stderr, "Couldn't create vars file\n");
exit(1);
}
if (strlen(blueip)) {
if (strlen(orangeip)) {
if (strlen(locip)) {
fprintf(varsfile, "var HOME_NET [%s,%s,%s,%s]\n", greenip, orangeip, blueip, locip);
} else {
fprintf(varsfile, "var HOME_NET [%s,%s,%s]\n", greenip, orangeip, blueip);
}
} else {
if (strlen(locip)) {
fprintf(varsfile, "var HOME_NET [%s,%s,%s]\n", greenip, blueip, locip);
} else {
fprintf(varsfile, "var HOME_NET [%s,%s]\n", greenip, blueip);
}
}
} else {
if (strlen(orangeip)) {
if (strlen(locip)) {
fprintf(varsfile, "var HOME_NET [%s,%s,%s]\n", greenip, orangeip, locip);
} else {
fprintf(varsfile, "var HOME_NET [%s,%s]\n", greenip, orangeip);
}
} else {
if (strlen(locip)) {
fprintf(varsfile, "var HOME_NET [%s,%s]\n", greenip, locip);
} else {
fprintf(varsfile, "var HOME_NET [%s]\n", greenip);
}
}
}
if (strlen(dns1))
{
if (strlen(dns2))
fprintf(varsfile, "var DNS_SERVERS [%s,%s]\n", dns1, dns2);
else
fprintf(varsfile, "var DNS_SERVERS %s\n", dns1);
} else {
fprintf(varsfile, "var DNS_SERVERS []\n");
}
fclose(varsfile);
varsfile = NULL;
if (restartred && strlen(iface) && (fd = open(CONFIG_ROOT "/snort/enable", O_RDONLY)) != -1)
{
close(fd);
snprintf(command, STRING_SIZE -1,
"/usr/sbin/snort -c /etc/snort/snort.conf -D -u snort -g snort -d -e -o -p -b -A fast -m 022 -i %s",
iface);
safe_system(command);
}
if (restartblue && strlen(bluedev) && (fd = open(CONFIG_ROOT "/snort/enable_blue", O_RDONLY)) != -1 && bluedev)
{
close(fd);
snprintf(command, STRING_SIZE -1,
"/usr/sbin/snort -c /etc/snort/snort.conf -D -u snort -g snort -d -e -o -p -b -A fast -m 022 -i %s",
bluedev);
safe_system(command);
}
if (restartorange && strlen(orangedev) && (fd = open(CONFIG_ROOT "/snort/enable_orange", O_RDONLY)) != -1 && orangedev)
{
close(fd);
snprintf(command, STRING_SIZE -1,
"/usr/sbin/snort -c /etc/snort/snort.conf -D -u snort -g snort -d -e -o -p -b -A fast -m 022 -i %s",
orangedev);
safe_system(command);
}
if (restartgreen && (fd = open(CONFIG_ROOT "/snort/enable_green", O_RDONLY)) != -1)
{
close(fd);
snprintf(command, STRING_SIZE -1,
"/usr/sbin/snort -c /etc/snort/snort.conf -D -u snort -g snort -d -e -o -p -b -A fast -m 022 -i %s",
greendev);
safe_system(command);
}
return 0;
}

View File

@@ -0,0 +1,449 @@
/* SmoothWall helper program - restartsquid
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Lawrence Manning, 2001
* Restarting squid with transparent proxying.
*
* 05/02/2004 - Roy Walker <rwalker@miracomnetwork.com>
* Exclude red network from transparent proxy to allow browsing to alias IPs
* Read in VPN settings and exclude each VPN network from transparent proxy
*
* $Id: restartsquid.c,v 1.7.2.8 2005/04/22 18:44:37 rkerr Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "libsmooth.h"
#include "setuid.h"
int main(int argc, char *argv[])
{
int fd = -1;
int enable = 0;
int enablevpn = 0;
int transparent = 0;
int enable_blue = 0;
int transparent_blue = 0;
int running = 0;
struct stat st;
FILE *ipfile;
char localip[STRING_SIZE] = "";
struct keyvalue *net = NULL;
struct keyvalue *squid = NULL;
char buffer[STRING_SIZE];
char proxy_port[STRING_SIZE];
char s[STRING_SIZE];
char green_dev[STRING_SIZE] = "";
char blue_dev[STRING_SIZE] = "";
char red_netaddress[STRING_SIZE] = "";
char red_netmask[STRING_SIZE] = "";
char configtype[STRING_SIZE] = "";
char redtype[STRING_SIZE] = "";
char enableredvpn[STRING_SIZE] = "";
char enablebluevpn[STRING_SIZE] = "";
if (!(initsetuid()))
exit(1);
/* Kill running squid */
safe_system("/sbin/iptables -t nat -F SQUID");
safe_system("/usr/sbin/squid -k shutdown >/dev/null 2>/dev/null");
sleep(5);
safe_system("/bin/killall -9 squid >/dev/null 2>/dev/null");
/* See if proxy is enabled and / or transparent */
if ((fd = open(CONFIG_ROOT "/proxy/enable", O_RDONLY)) != -1)
{
close(fd);
enable = 1;
}
if ((fd = open(CONFIG_ROOT "/proxy/transparent", O_RDONLY)) != -1)
{
close(fd);
transparent = 1;
}
if ((fd = open(CONFIG_ROOT "/proxy/enable_blue", O_RDONLY)) != -1)
{
close(fd);
enable_blue = 1;
}
if ((fd = open(CONFIG_ROOT "/proxy/transparent_blue", O_RDONLY)) != -1)
{
close(fd);
transparent_blue = 1;
}
/* Read the network configuration */
net=initkeyvalues();
if (!readkeyvalues(net, CONFIG_ROOT "/ethernet/settings"))
{
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
if (!findkey(net, "GREEN_DEV", green_dev))
{
fprintf(stderr, "Cannot read GREEN_DEV\n");
exit(1);
}
if (!VALID_DEVICE(green_dev))
{
fprintf(stderr, "Bad GREEN_DEV: %s\n", green_dev);
exit(1);
}
if (!findkey(net, "CONFIG_TYPE", configtype))
{
fprintf(stderr, "Cannot read CONFIG_TYPE\n");
exit(1);
}
findkey(net, "RED_TYPE", redtype);
findkey(net, "RED_NETADDRESS", red_netaddress);
findkey(net, "RED_NETMASK", red_netmask);
findkey(net, "BLUE_DEV", blue_dev);
freekeyvalues(net);
/* See if VPN software is enabled */
net=initkeyvalues();
if (!readkeyvalues(net, CONFIG_ROOT "/vpn/settings"))
{
fprintf(stderr, "Cannot read vpn settings\n");
exit(1);
}
findkey(net, "ENABLED", enableredvpn);
findkey(net, "ENABLED_BLUE", enablebluevpn);
freekeyvalues(net);
if ( (!strcmp(enableredvpn, "on") && VALID_IP(localip)) ||
(!strcmp(enablebluevpn, "on") && VALID_DEVICE(blue_dev)) ) {
enablevpn = 1;
}
/* Retrieve the Squid pid file */
if ((fd = open("/var/run/squid.pid", O_RDONLY)) != -1)
{
close(fd);
running = 1;
}
/* Retrieve the RED ip address */
stat(CONFIG_ROOT "/red/local-ipaddress", &st);
if (S_ISREG(st.st_mode)) {
if (!(ipfile = fopen(CONFIG_ROOT "/red/local-ipaddress", "r")))
{
fprintf(stderr, "Couldn't open ip file\n");
exit(0);
}
if (fgets(localip, STRING_SIZE, ipfile))
{
if (localip[strlen(localip) - 1] == '\n')
localip[strlen(localip) - 1] = '\0';
}
fclose(ipfile);
if (!VALID_IP(localip))
{
fprintf(stderr, "Bad ip: %s\n", localip);
exit(0);
}
}
/* See if we need to flush the cache */
if (argc >=2) {
if (strcmp(argv[1], "-f") == 0) {
if (stat("/var/log/cache/swap.state", &st) == 0) {
struct passwd *pw;
if((pw = getpwnam("squid"))) {
endpwent(); /* probably paranoia, but just in case.. */
unpriv_system("/bin/echo > /var/log/cache/swap.state", pw->pw_uid, pw->pw_gid);
} else { endpwent(); }
}
}
}
if (enable || enable_blue)
{
safe_system("/usr/sbin/squid -D -z");
safe_system("/usr/sbin/squid -D");
}
/* Retrieve the proxy port */
if (transparent || transparent_blue) {
squid=initkeyvalues();
if (!readkeyvalues(squid, CONFIG_ROOT "/proxy/settings"))
{
fprintf(stderr, "Cannot read proxy settings\n");
exit(1);
}
if (!(findkey(squid, "PROXY_PORT", proxy_port)))
{
strcpy (proxy_port, "800");
} else {
if(strspn(proxy_port, NUMBERS) != strlen(proxy_port))
{
fprintf(stderr, "Invalid proxy port: %s, defaulting to 800\n", proxy_port);
strcpy(proxy_port, "800");
}
}
freekeyvalues(squid);
}
if (transparent && enable) {
int count;
char *result;
char *name;
char *type;
char *running;
char *vpn_network_mask;
char *vpn_netaddress;
char *vpn_netmask;
FILE *file = NULL;
char *conn_enabled;
/* Darren Critchley - check to see if RED VPN is enabled before mucking with rules */
if (!strcmp(enableredvpn, "on")) {
/* Read the /vpn/config file - no check to see if VPN is enabled */
if (!(file = fopen(CONFIG_ROOT "/vpn/config", "r"))) {
fprintf(stderr, "Couldn't open vpn config file");
exit(1);
}
while (fgets(s, STRING_SIZE, file) != NULL) {
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
running = strdup (s);
result = strsep(&running, ",");
count = 0;
name = NULL;
type = NULL;
vpn_network_mask = NULL;
conn_enabled = NULL;
while (result) {
if (count == 1)
conn_enabled = result;
if (count == 2)
name = result;
if (count == 4)
type = result;
if (count == 12 )
vpn_network_mask = result;
count++;
result = strsep(&running, ",");
}
if (strspn(name, LETTERS_NUMBERS) != strlen(name)) {
fprintf(stderr, "Bad connection name: %s\n", name);
exit(1);
}
if (! (strcmp(type, "net") == 0)) {
continue;
}
/* Darren Critchley - new check to see if connection is enabled */
if (! (strcmp(conn_enabled, "on") == 0)) {
continue;
}
result = strsep(&vpn_network_mask, "/");
count = 0;
vpn_netaddress = NULL;
vpn_netmask = NULL;
while (result) {
if (count == 0)
vpn_netaddress = result;
if (count == 1)
vpn_netmask = result;
count++;
result = strsep(&vpn_network_mask, "/");
}
if (!VALID_IP(vpn_netaddress)) {
fprintf(stderr, "Bad network for vpn connection %s: %s\n", name, vpn_netaddress);
continue;
}
if ((!VALID_IP(vpn_netmask)) && (!VALID_SHORT_MASK(vpn_netmask))) {
fprintf(stderr, "Bad mask for vpn connection %s: %s\n", name, vpn_netmask);
continue;
}
memset(buffer, 0, STRING_SIZE);
if( snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp -d %s/%s --dport 80 -j RETURN", green_dev, vpn_netaddress, vpn_netmask) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
}
}
memset(buffer, 0, STRING_SIZE);
if ( ( (strcmp(configtype, "2")==0) || (strcmp(configtype, "3")==0) ||
(strcmp(configtype, "6")==0) || (strcmp(configtype, "7")==0) ) &&
(VALID_IP(red_netaddress)) && (VALID_IP(red_netmask)) &&
(strcmp(redtype, "STATIC")==0) )
{
memset(buffer, 0, STRING_SIZE);
if( snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp -d %s/%s --dport 80 -j RETURN", green_dev, red_netaddress, red_netmask) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
} else if (VALID_IP(localip)) {
memset(buffer, 0, STRING_SIZE);
if( snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp -d %s --dport 80 -j RETURN", green_dev, localip) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
}
memset(buffer, 0, STRING_SIZE);
if( snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp --dport 80 -j REDIRECT --to-port %s", green_dev, proxy_port) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
}
if (transparent_blue && enable_blue) {
int count;
char *result;
char *name;
char *type;
char *running;
char *vpn_network_mask;
char *vpn_netaddress;
char *vpn_netmask;
char *conn_enabled;
FILE *file = NULL;
if (! VALID_DEVICE(blue_dev))
{
fprintf(stderr, "Bad BLUE_DEV: %s\n", blue_dev);
exit(1);
}
/* Darren Critchley - check to see if BLUE VPN is enabled before mucking with rules */
if (!strcmp(enablebluevpn, "on")) {
/* Read the /vpn/config file - no check to see if VPN is enabled */
if (!(file = fopen(CONFIG_ROOT "/vpn/config", "r"))) {
fprintf(stderr, "Couldn't open vpn config file");
exit(1);
}
while (fgets(s, STRING_SIZE, file) != NULL) {
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
running = strdup (s);
result = strsep(&running, ",");
count = 0;
name = NULL;
type = NULL;
vpn_network_mask = NULL;
conn_enabled = NULL;
while (result) {
if (count == 1)
conn_enabled = result;
if (count == 2)
name = result;
if (count == 4)
type = result;
if (count == 12 )
vpn_network_mask = result;
count++;
result = strsep(&running, ",");
}
if (strspn(name, LETTERS_NUMBERS) != strlen(name)) {
fprintf(stderr, "Bad connection name: %s\n", name);
exit(1);
}
if (! (strcmp(type, "net") == 0)) {
continue;
}
/* Darren Critchley - new check to see if connection is enabled */
if (! (strcmp(conn_enabled, "on") == 0)) {
continue;
}
result = strsep(&vpn_network_mask, "/");
count = 0;
vpn_netaddress = NULL;
vpn_netmask = NULL;
while (result) {
if (count == 0)
vpn_netaddress = result;
if (count == 1)
vpn_netmask = result;
count++;
result = strsep(&vpn_network_mask, "/");
}
if (!VALID_IP(vpn_netaddress)) {
fprintf(stderr, "Bad network for vpn connection %s: %s\n", name, vpn_netaddress);
continue;
}
if ((!VALID_IP(vpn_netmask)) && (!VALID_SHORT_MASK(vpn_netmask))) {
fprintf(stderr, "Bad mask for vpn connection %s: %s\n", name, vpn_netmask);
continue;
}
memset(buffer, 0, STRING_SIZE);
if (snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp -d %s/%s --dport 80 -j RETURN", blue_dev, vpn_netaddress, vpn_netmask) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
}
}
memset(buffer, 0, STRING_SIZE);
if ( ( (strcmp(configtype, "2")==0) || (strcmp(configtype, "3")==0) ||
(strcmp(configtype, "6")==0) || (strcmp(configtype, "7")==0) ) &&
(VALID_IP(red_netaddress)) && (VALID_IP(red_netmask)) &&
(strcmp(redtype, "STATIC")==0) )
{
memset(buffer, 0, STRING_SIZE);
if( snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp -d %s/%s --dport 80 -j RETURN", blue_dev, red_netaddress, red_netmask) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
} else if (VALID_IP(localip)) {
memset(buffer, 0, STRING_SIZE);
if( snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp -d %s --dport 80 -j RETURN", blue_dev, localip) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
}
memset(buffer, 0, STRING_SIZE);
if( snprintf(buffer, STRING_SIZE - 1, "/sbin/iptables -t nat -A SQUID -i %s -p tcp --dport 80 -j REDIRECT --to-port %s", blue_dev, proxy_port) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
}
return 0;
}

135
src/misc-progs/restartssh.c Normal file
View File

@@ -0,0 +1,135 @@
/* SmoothWall helper program - restartssh
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Mark Wormgoor, 2001
* Simple program intended to be installed setuid(0) that can be used for
* restarting SSHd.
*
* $Id: restartssh.c,v 1.3 2003/12/11 10:57:34 riddles Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include "libsmooth.h"
#include "setuid.h"
int main(void)
{
int fd, config_fd, rc, pid;
char buffer[STRING_SIZE], command[STRING_SIZE] = "/bin/sed -e '";
struct keyvalue *kv = NULL;
if (!(initsetuid()))
exit(1);
kv = initkeyvalues();
if (!readkeyvalues(kv, CONFIG_ROOT "/remote/settings"))
{
fprintf(stderr, "Cannot read remote access settings\n");
exit(1);
}
/* By using O_CREAT with O_EXCL open() will fail if the file already exists,
* this prevents 2 copies of restartssh both trying to edit the config file
* at once. It also prevents race conditions, but these shouldn't be
* possible as /etc/ssh/ should only be writable by root anyhow
*/
if ((config_fd = open( "/etc/ssh/sshd_config.new", O_WRONLY|O_CREAT|O_EXCL, 0644 )) == -1 )
{
perror("Unable to open new config file");
freekeyvalues(kv);
exit(1);
}
if(findkey(kv, "ENABLE_SSH_PROTOCOL1", buffer) && !strcmp(buffer,"on"))
strlcat(command, "s/^Protocol .*$/Protocol 2,1/;", STRING_SIZE - 1 );
else
strlcat(command, "s/^Protocol .*$/Protocol 2/;", STRING_SIZE - 1 );
if(findkey(kv, "ENABLE_SSH_KEYS", buffer) && !strcmp(buffer,"off"))
strlcat(command, "s/^RSAAuthentication .*$/RSAAuthentication no/;"
"s/^PubkeyAuthentication .*$/PubkeyAuthentication no/;",
STRING_SIZE - 1 );
else
strlcat(command, "s/^RSAAuthentication .*$/RSAAuthentication yes/;"
"s/^PubkeyAuthentication .*$/PubkeyAuthentication yes/;",
STRING_SIZE - 1 );
if(findkey(kv, "ENABLE_SSH_PASSWORDS", buffer) && !strcmp(buffer,"off"))
strlcat(command, "s/^PasswordAuthentication .*$/PasswordAuthentication no/;", STRING_SIZE - 1 );
else
strlcat(command, "s/^PasswordAuthentication .*$/PasswordAuthentication yes/;", STRING_SIZE - 1 );
if(findkey(kv, "ENABLE_SSH_PORTFW", buffer) && !strcmp(buffer,"on"))
strlcat(command, "s/^AllowTcpForwarding .*$/AllowTcpForwarding yes/", STRING_SIZE - 1 );
else
strlcat(command, "s/^AllowTcpForwarding .*$/AllowTcpForwarding no/", STRING_SIZE - 1 );
freekeyvalues(kv);
snprintf(buffer, STRING_SIZE - 1, "' /etc/ssh/sshd_config >&%d", config_fd );
strlcat(command, buffer, STRING_SIZE - 1);
if((rc = unpriv_system(command,99,99)) != 0)
{
fprintf(stderr, "sed returned bad exit code: %d\n", rc);
close(config_fd);
unlink("/etc/ssh/sshd_config.new");
exit(1);
}
close(config_fd);
if (rename("/etc/ssh/sshd_config.new","/etc/ssh/sshd_config") != 0)
{
perror("Unable to replace old config file");
unlink("/etc/ssh/sshd_config.new");
exit(1);
}
memset(buffer, 0, STRING_SIZE);
if ((fd = open("/var/run/sshd.pid", O_RDONLY)) != -1)
{
if (read(fd, buffer, STRING_SIZE - 1) == -1)
fprintf(stderr, "Couldn't read from pid file\n");
else
{
pid = atoi(buffer);
if (pid <= 1)
fprintf(stderr, "Bad pid value\n");
else
{
if (kill(pid, SIGTERM) == -1)
fprintf(stderr, "Unable to send SIGTERM\n");
else
unlink("/var/run/sshd.pid");
}
}
close(fd);
}
else
{
if (errno != ENOENT)
{
perror("Unable to open pid file");
exit(1);
}
}
if ((fd = open(CONFIG_ROOT "/remote/enablessh", O_RDONLY)) != -1)
{
close(fd);
safe_system("/usr/sbin/sshd");
}
return 0;
}

View File

@@ -0,0 +1,167 @@
/* This file is part of the IPCop Firewall.
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* Copyright (C) 2003-07-12 Robert Kerr <rkerr@go.to>
*
* $Id: restartsyslogd.c,v 1.2.2.3 2004/12/14 17:56:37 gespinasse Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include "libsmooth.h"
#include "setuid.h"
#define ERR_ANY 1
#define ERR_SETTINGS 2 /* error in settings file */
#define ERR_ETC 3 /* error with /etc permissions */
#define ERR_CONFIG 4 /* error updated sshd_config */
#define ERR_SYSLOG 5 /* error restarting syslogd */
int main(void)
{
char buffer[STRING_SIZE], hostname[STRING_SIZE];
int config_fd,rc,fd,pid;
struct stat st;
struct keyvalue *kv = NULL;
memset(buffer, 0, STRING_SIZE);
memset(hostname, 0, STRING_SIZE);
if (!(initsetuid()))
exit(1);
/* Read in and verify config */
kv=initkeyvalues();
if (!readkeyvalues(kv, CONFIG_ROOT "/logging/settings"))
{
fprintf(stderr, "Cannot read syslog settings\n");
exit(ERR_SETTINGS);
}
if (!findkey(kv, "ENABLE_REMOTELOG", buffer))
{
fprintf(stderr, "Cannot read ENABLE_REMOTELOG\n");
exit(ERR_SETTINGS);
}
if (!findkey(kv, "REMOTELOG_ADDR", hostname))
{
fprintf(stderr, "Cannot read REMOTELOG_ADDR\n");
exit(ERR_SETTINGS);
}
if (strspn(hostname, VALID_FQDN) != strlen(hostname))
{
fprintf(stderr, "Bad REMOTELOG_ADDR: %s\n", hostname);
exit(ERR_SETTINGS);
}
freekeyvalues(kv);
/* If anyone other than root can write to /etc this would be totally
* insecure - same if anyone other than root owns /etc, as they could
* change the file mode to give themselves or anyone else write access. */
if(lstat("/etc",&st))
{
perror("Unable to stat /etc");
exit(ERR_ETC);
}
if(!S_ISDIR(st.st_mode))
{
fprintf(stderr,"/etc is not a directory?!\n");
exit(ERR_ETC);
}
if ( st.st_uid != 0 || st.st_mode & S_IWOTH ||
((st.st_gid != 0) && (st.st_mode & S_IWGRP)) )
{
fprintf(stderr,"/etc is owned/writable by non-root users\n");
exit(ERR_ETC);
}
/* O_CREAT with O_EXCL will make open() fail if the file already exists -
* mostly to prevent 2 copies running at once */
if ((config_fd = open( "/etc/syslog.conf.new", O_WRONLY|O_CREAT|O_EXCL, 0644 )) == -1 )
{
perror("Unable to open new config file");
exit(ERR_CONFIG);
}
if (!strcmp(buffer,"on"))
snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@\\).\\+$/\\1%s/' /etc/syslog.conf >&%d", hostname, config_fd );
else
snprintf(buffer, STRING_SIZE - 1, "/bin/sed -e 's/^#\\?\\(\\*\\.\\*[[:blank:]]\\+@.\\+\\)$/#\\1/' /etc/syslog.conf >&%d", config_fd );
/* if the return code isn't 0 failsafe */
if ((rc = unpriv_system(buffer,99,99)) != 0)
{
fprintf(stderr, "sed returned bad exit code: %d\n", rc);
close(config_fd);
unlink("/etc/syslog.conf.new");
exit(ERR_CONFIG);
}
close(config_fd);
if (rename("/etc/syslog.conf.new","/etc/syslog.conf") == -1)
{
perror("Unable to replace old config file");
unlink("/etc/syslog.conf.new");
exit(ERR_CONFIG);
}
/* Get syslogd to read the new config file */
if ((fd = open("/var/run/syslogd.pid", O_RDONLY)) == -1)
{
if(errno == ENOENT)
{
/* pid file doesn't exists.. restart syslog */
if((rc = safe_system("/usr/sbin/syslogd -m 0")) == 0 )
return 0;
else
{
fprintf(stderr,
"Unable to restart syslogd - returned exit code %d\n", rc);
exit(ERR_SYSLOG);
}
} else {
/* Something odd is going on, failsafe */
perror("Unable to open pid file");
exit(ERR_SYSLOG);
}
}
memset(buffer, 0, STRING_SIZE);
if (read(fd, buffer, STRING_SIZE - 1) == -1)
{
close(fd);
perror("Couldn't read from pid file");
exit(ERR_SYSLOG);
}
close(fd);
/* strtol does sanity checks that atoi doesn't do */
errno = 0;
pid = (int)strtol(buffer, (char **)NULL, 10);
if (errno || pid <= 1)
{
fprintf(stderr, "Bad pid value\n");
exit(ERR_SYSLOG);
}
if (kill(pid, SIGHUP) == -1)
{
fprintf(stderr, "Unable to send SIGHUP\n");
exit(ERR_SYSLOG);
}
return 0;
}

View File

@@ -0,0 +1,147 @@
/* IPCop helper program - restartwireless
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Alan Hourihane, 2003
*
* $Id: restartwireless.c,v 1.2.2.5 2005/07/11 10:56:47 franck78 Exp $
*
*/
#include "libsmooth.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "setuid.h"
FILE *fd = NULL;
char blue_dev[STRING_SIZE] = "";
char command[STRING_SIZE];
void exithandler(void)
{
if(strlen(blue_dev))
{
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSINPUT -i %s -j LOG_DROP", blue_dev);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSFORWARD -i %s -j LOG_DROP", blue_dev);
safe_system(command);
}
if (fd)
fclose(fd);
}
int main(void)
{
char green_dev[STRING_SIZE] = "";
char buffer[STRING_SIZE];
char *index, *ipaddress, *macaddress, *enabled;
struct keyvalue *kv = NULL;
if (!(initsetuid()))
exit(1);
/* flush wireless iptables */
safe_system("/sbin/iptables -F WIRELESSINPUT > /dev/null 2> /dev/null");
safe_system("/sbin/iptables -F WIRELESSFORWARD > /dev/null 2> /dev/null");
memset(buffer, 0, STRING_SIZE);
/* Init the keyvalue structure */
kv=initkeyvalues();
/* Read in the current values */
if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))
{
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
/* Get the GREEN interface details */
if(!findkey(kv, "GREEN_DEV", green_dev))
{
fprintf(stderr, "Cannot read GREEN_DEV\n");
exit(1);
}
if (!VALID_DEVICE(green_dev))
{
fprintf(stderr, "Bad GREEN_DEV: %s\n", green_dev);
exit(1);
}
/* Get the BLUE interface details */
if(!findkey(kv, "BLUE_DEV", blue_dev))
{
fprintf(stderr, "Cannot read BLUE_DEV\n");
exit(1);
}
if (strlen(blue_dev) && !VALID_DEVICE(blue_dev))
{
fprintf(stderr, "Bad BLUE_DEV: %s\n", blue_dev);
exit(1);
}
if(! strlen(blue_dev) > 0)
{
fprintf(stderr, "No BLUE interface\n");
exit(0);
}
/* register exit handler to ensure the block rule is always present */
atexit(exithandler);
if (!(fd = fopen(CONFIG_ROOT "/wireless/config", "r")))
{
exit(0);
}
while (fgets(buffer, STRING_SIZE, fd))
{
buffer[strlen(buffer) - 1] = 0;
index = strtok(buffer, ",");
ipaddress = strtok(NULL, ",");
macaddress = strtok(NULL, ",");
enabled = strtok(NULL, ",");
if (!strncmp(enabled, "on", 2)) {
/* both specified, added security */
if ((strlen(macaddress) == 17) &&
(VALID_IP(ipaddress))) {
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSINPUT -m mac --mac-source %s -s %s -i %s -j ACCEPT", macaddress, ipaddress, blue_dev);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -s %s -i %s -o ! %s -j ACCEPT", macaddress, ipaddress, blue_dev, green_dev);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -s %s -i %s -j DMZHOLES", macaddress, ipaddress, blue_dev);
safe_system(command);
} else {
/* correctly formed mac address is 17 chars */
if (strlen(macaddress) == 17) {
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSINPUT -m mac --mac-source %s -i %s -j ACCEPT", macaddress, blue_dev);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -i %s -o ! %s -j ACCEPT", macaddress, blue_dev, green_dev);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -i %s -j DMZHOLES", macaddress, blue_dev);
safe_system(command);
}
if (VALID_IP(ipaddress)) {
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSINPUT -s %s -i %s -j ACCEPT", ipaddress, blue_dev);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSFORWARD -s %s -i %s -o ! %s -j ACCEPT", ipaddress, blue_dev, green_dev);
safe_system(command);
snprintf(command, STRING_SIZE-1, "/sbin/iptables -A WIRELESSFORWARD -s %s -i %s -j DMZHOLES", ipaddress, blue_dev);
safe_system(command);
}
}
}
}
return 0;
}

186
src/misc-progs/setaliases.c Normal file
View File

@@ -0,0 +1,186 @@
/*
* setaliases - configure red aliased interfaces
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Steve Bootes, 2002/04/15
*
* 21/04/03 Robert Kerr Changed to link directly to libsmooth rather than
* using a copy & paste
*
* $Id: setaliases.c,v 1.2.2.4 2004/08/22 22:01:44 alanh Exp $
*
*/
#include "libsmooth.h"
#include "setuid.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
struct keyvalue *kv = NULL;
FILE *file = NULL;
void exithandler(void)
{
if (kv) freekeyvalues(kv);
if (file) fclose(file);
}
int main(void)
{
char s[STRING_SIZE];
char command[STRING_SIZE];
char red_netmask[STRING_SIZE];
char red_broadcast[STRING_SIZE];
char red_dev[STRING_SIZE];
char default_gateway[STRING_SIZE];
char *aliasip;
char *enabled;
char *sptr;
char *comment;
int alias;
int count;
if (!(initsetuid()))
{
fprintf(stderr, "Cannot run setuid\n");
exit(1);
}
atexit(exithandler);
/* Init the keyvalue structure */
kv=initkeyvalues();
/* Read in the current values */
if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))
{
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
/* Find the CONFIG_TYPE value */
if (!findkey(kv, "CONFIG_TYPE", s))
{
fprintf(stderr, "Cannot read CONFIG_TYPE\n");
exit(1);
}
/* Check for CONFIG_TYPE=2 or 3 i.e. RED ethernet present. If not,
* exit gracefully. This is not an error... */
if (!((strcmp(s, "2")==0) || (strcmp(s, "3")==0) || (strcmp(s, "6")==0) || (strcmp(s, "7")==0)))
exit(0);
/* Now check the RED_TYPE - aliases only work with STATIC.
* At least, that's what /etc/rc.d/rc.netaddress.up thinks.. */
/* Find the RED_TYPE value */
if (!findkey(kv, "RED_TYPE", s))
{
fprintf(stderr, "Cannot read RED_TYPE\n");
exit(1);
}
/* Make sure it's the right type */
if (!(strcmp(s, "STATIC")==0))
exit(0);
/* Get the RED interface details */
if((!findkey(kv, "RED_NETMASK", red_netmask)) || (!findkey(kv, "RED_BROADCAST", red_broadcast)) ||
(!findkey(kv, "RED_DEV", red_dev)) || (!findkey(kv, "DEFAULT_GATEWAY", default_gateway)))
{
fprintf(stderr, "Cannot read RED settings\n");
exit(1);
}
if (!VALID_DEVICE(red_dev))
{
fprintf(stderr, "Bad red_dev: %s\n", red_dev);
exit(1);
}
if (!VALID_IP(red_netmask))
{
fprintf(stderr, "Bad red_netmask : %s\n", red_netmask);
exit(1);
}
if (!VALID_IP(red_broadcast))
{
fprintf(stderr, "Bad red_broadcast : %s\n", red_broadcast);
exit(1);
}
if (!VALID_IP(default_gateway))
{
fprintf(stderr, "Bad default_gateway : %s\n", default_gateway);
exit(1);
}
/* down the aliases in turn until ifconfig complains */
alias=0;
do
{
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE-1, "/sbin/ifconfig %s:%d down 2>/dev/null", red_dev, alias++);
} while (safe_system(command)==0);
/* Now set up the new aliases from the config file */
if (!(file = fopen(CONFIG_ROOT "/ethernet/aliases", "r")))
{
fprintf(stderr, "Unable to open aliases configuration file\n");
exit(1);
}
alias=0;
while (fgets(s, STRING_SIZE, file) != NULL)
{
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
sptr = strtok(s, ",");
count = 0;
aliasip = NULL;
enabled = NULL;
comment = NULL;
while (sptr)
{
if (count == 0)
aliasip = sptr;
if (count == 1)
enabled = sptr;
else
comment = sptr;
count++;
sptr = strtok(NULL, ",");
}
if (!(aliasip && enabled))
continue;
if (!VALID_IP(aliasip))
{
fprintf(stderr, "Bad alias : %s\n", aliasip);
exit(1);
}
if (strcmp(enabled, "on") == 0)
{
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE-1, "/sbin/ifconfig %s:%d %s netmask %s broadcast %s up", red_dev, alias, aliasip, red_netmask, red_broadcast);
safe_system(command);
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE-1, "/usr/sbin/arping -q -c 1 -w 1 -i %s -S %s %s", red_dev, aliasip, default_gateway);
safe_system(command);
alias++;
}
}
return 0;
}

52
src/misc-progs/setdate.c Normal file
View File

@@ -0,0 +1,52 @@
/* Ipcop helper program - setdate.c
*
* Sets the date and time
*
* (c) Darren Critchley 2003
*
* $Id: setdate.c,v 1.2 2003/12/11 11:25:54 riddles Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include "setuid.h"
int main(int argc, char *argv[])
{
char command[STRING_SIZE];
int a,b,c;
if (!(initsetuid()))
exit(1);
if (argc < 3)
{
fprintf(stderr, "Missing arg\n");
exit(1);
}
if (! (strlen(argv[1]) < 11 && sscanf(argv[1], "%d-%d-%d", &a, &b, &c) == 3)
|| (strspn(argv[1], NUMBERS "-" ) != strlen(argv[1])))
{
fprintf(stderr, "Bad arg\n");
exit(1);
}
if (! (strlen(argv[2]) < 6 && sscanf(argv[2], "%d:%d", &a, &b) == 2)
|| (strspn(argv[2], NUMBERS ":" ) != strlen(argv[2])))
{
fprintf(stderr, "Bad arg\n");
exit(1);
}
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1, "/bin/date -s '%s %s' >/dev/null", argv[1], argv[2]);
fprintf(stderr, "Setting Date: %s %s\n", argv[1], argv[2]);
safe_system(command);
return 0;
}

View File

@@ -0,0 +1,162 @@
/* SmoothWall helper program - setdmzhole
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Daniel Goscomb, 2001
*
* Modifications and improvements by Lawrence Manning.
*
* 10/04/01 Aslak added protocol support
* This program reads the list of ports to forward and setups iptables
* and rules in ipmasqadm to enable them.
*
* $Id: setdmzholes.c,v 1.5.2.3 2005/10/18 17:05:27 franck78 Exp $
*
*/
#include "libsmooth.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "setuid.h"
FILE *fwdfile = NULL;
void exithandler(void)
{
if (fwdfile)
fclose(fwdfile);
}
int main(void)
{
int count;
char *protocol;
char *locip;
char *remip;
char *remport;
char *enabled;
char *src_net;
char *dst_net;
char s[STRING_SIZE];
char *result;
struct keyvalue *kv = NULL;
char orange_dev[STRING_SIZE] = "";
char blue_dev[STRING_SIZE] = "";
char green_dev[STRING_SIZE] = "";
char *idev;
char *odev;
char command[STRING_SIZE];
if (!(initsetuid()))
exit(1);
atexit(exithandler);
kv=initkeyvalues();
if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))
{
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
if (!findkey(kv, "GREEN_DEV", green_dev))
{
fprintf(stderr, "Cannot read GREEN_DEV\n");
exit(1);
}
findkey(kv, "BLUE_DEV", blue_dev);
findkey(kv, "ORANGE_DEV", orange_dev);
if (!(fwdfile = fopen(CONFIG_ROOT "/dmzholes/config", "r")))
{
fprintf(stderr, "Couldn't open dmzholes settings file\n");
exit(1);
}
safe_system("/sbin/iptables -F DMZHOLES");
while (fgets(s, STRING_SIZE, fwdfile) != NULL)
{
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
result = strtok(s, ",");
count = 0;
protocol = NULL;
locip = NULL; remip = NULL;
remport = NULL;
enabled = NULL;
src_net = NULL;
dst_net = NULL;
idev = NULL;
odev = NULL;
while (result)
{
if (count == 0)
protocol = result;
else if (count == 1)
locip = result;
else if (count == 2)
remip = result;
else if (count == 3)
remport = result;
else if (count == 4)
enabled = result;
else if (count == 5)
src_net = result;
else if (count == 6)
dst_net = result;
count++;
result = strtok(NULL, ",");
}
if (!(protocol && locip && remip && remport && enabled))
{
fprintf(stderr, "Bad line:\n");
break;
}
if (!VALID_PROTOCOL(protocol))
{
fprintf(stderr, "Bad protocol: %s\n", protocol);
exit(1);
}
if (!VALID_IP_AND_MASK(locip))
{
fprintf(stderr, "Bad local IP: %s\n", locip);
exit(1);
}
if (!VALID_IP_AND_MASK(remip))
{
fprintf(stderr, "Bad remote IP: %s\n", remip);
exit(1);
}
if (!VALID_PORT_RANGE(remport))
{
fprintf(stderr, "Bad remote port: %s\n", remport);
exit(1);
}
if (!src_net) { src_net = strdup ("orange");}
if (!dst_net) { dst_net = strdup ("green");}
if (!strcmp(src_net, "blue")) { idev = blue_dev; }
if (!strcmp(src_net, "orange")) { idev = orange_dev; }
if (!strcmp(dst_net, "blue")) { odev = blue_dev; }
if (!strcmp(dst_net, "green")) { odev = green_dev; }
if (!strcmp(enabled, "on") && strlen(idev) && strlen (odev))
{
char *ctr;
/* If remport contains a - we need to change it to a : */
if ((ctr = strchr(remport,'-')) != NULL){*ctr = ':';}
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A DMZHOLES -p %s -i %s -o %s -s %s -d %s --dport %s -j ACCEPT", protocol, idev, odev, locip, remip, remport);
safe_system(command);
}
}
return 0;
}

100
src/misc-progs/setfilters.c Normal file
View File

@@ -0,0 +1,100 @@
/* Derivated from SmoothWall helper programs
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Daniel Goscomb, 2001
*
* Modifications and improvements by Lawrence Manning.
*
* 19/04/03 Robert Kerr Fixed root exploit
*
* 20/08/05 Achim Weber 20 Modified to have a binary for the new firewall options page in IPCop 1.4.8
*
* 02/10/05 Gilles Espinasse treat only ping actually
*
* $Id: setfilters.c,v 1.1.2.2 2006/02/07 20:54:16 gespinasse Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libsmooth.h"
#include "setuid.h"
struct keyvalue *kv = NULL;
FILE *ifacefile = NULL;
void exithandler(void)
{
if(kv)
freekeyvalues(kv);
}
int main(void)
{
char iface[STRING_SIZE] = "";
char command[STRING_SIZE];
char disableping[STRING_SIZE];
int redAvailable = 1;
if (!(initsetuid()))
exit(1);
atexit(exithandler);
/* Read in and verify config */
kv=initkeyvalues();
if (!readkeyvalues(kv, CONFIG_ROOT "/optionsfw/settings")) {
fprintf(stderr, "Cannot read firewall option settings\n");
exit(1);
}
if (!findkey(kv, "DISABLEPING", disableping)) {
fprintf(stderr, "Cannot read DISABLEPING\n");
exit(1);
}
if (strcmp(disableping, "NO") != 0 && strcmp(disableping, "ONLYRED") != 0 && strcmp(disableping, "ALL") != 0) {
fprintf(stderr, "Bad DISABLEPING: %s\n", disableping);
exit(1);
}
if (!(ifacefile = fopen(CONFIG_ROOT "/red/iface", "r"))) {
redAvailable = 0;
} else {
if (fgets(iface, STRING_SIZE, ifacefile)) {
if (iface[strlen(iface) - 1] == '\n')
iface[strlen(iface) - 1] = '\0';
}
fclose (ifacefile);
if (!VALID_DEVICE(iface)) {
fprintf(stderr, "Bad iface: %s\n", iface);
exit(1);
}
redAvailable = 1;
}
safe_system("/sbin/iptables -F GUIINPUT");
/* don't need to do anything if ping is disabled, so treat only other cases */
if (strcmp(disableping, "NO") == 0
|| (strcmp(disableping, "ONLYRED") == 0 && redAvailable == 0)) {
// We allow ping (icmp type 8) on every interfaces
// or RED is not available, so we can enable it on all (available) Interfaces
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A GUIINPUT -p icmp --icmp-type 8 -j ACCEPT");
safe_system(command);
} else {
// Allow ping only on internal interfaces
if(strcmp(disableping, "ONLYRED") == 0) {
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1,
"/sbin/iptables -A GUIINPUT -i ! %s -p icmp --icmp-type 8 -j ACCEPT", iface);
safe_system(command);
}
}
return 0;
}

369
src/misc-progs/setportfw.c Normal file
View File

@@ -0,0 +1,369 @@
/* SmoothWall helper program - setportfw
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Daniel Goscomb, 2001
* Copyright (c) 2002/04/13 Steve Bootes - Added source ip support for aliases
*
* Modifications and improvements by Lawrence Manning.
*
* 10/04/01 Aslak added protocol support
* This program reads the list of ports to forward and setups iptables
* and rules in ipmasqadm to enable them.
*
* 02/11/03 Darren Critchley modifications to allow it to open multiple
* source ip addresses
* 02/25/03 Darren Critchley modifications to allow port ranges
* 04/01/03 Darren Critchley modifications to allow gre protocol
* 20/04/03 Robert Kerr Fixed root exploit, validated all variables properly,
* tidied up the iptables logic, killed duplicated code,
* removed srciptmp (unecessary)
*
* $Id: setportfw.c,v 1.3.2.6 2005/08/24 18:44:19 gespinasse Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libsmooth.h"
#include "setuid.h"
struct keyvalue *kv = NULL;
FILE *fwdfile = NULL;
void exithandler(void)
{
if(kv)
freekeyvalues(kv);
if (fwdfile)
fclose(fwdfile);
}
int main(void)
{
FILE *ipfile = NULL, *ifacefile = NULL;
int count;
char iface[STRING_SIZE];
char locip[STRING_SIZE];
char greenip[STRING_SIZE], greenmask[STRING_SIZE];
char bluedev[STRING_SIZE], blueip[STRING_SIZE], bluemask[STRING_SIZE];
char orangedev[STRING_SIZE], orangeip[STRING_SIZE], orangemask[STRING_SIZE];
char *protocol;
char *srcip;
char *locport;
char *remip;
char *remport;
char *origip;
char *enabled;
char s[STRING_SIZE];
char *result;
char *key1;
char *key2;
char command[STRING_SIZE];
if (!(initsetuid()))
exit(1);
atexit(exithandler);
/* Read in and verify config */
kv=initkeyvalues();
if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings"))
{
fprintf(stderr, "Cannot read ethernet settings\n");
exit(1);
}
if (!findkey(kv, "GREEN_ADDRESS", greenip))
{
fprintf(stderr, "Cannot read GREEN_ADDRESS\n");
exit(1);
}
if (!VALID_IP(greenip))
{
fprintf(stderr, "Bad GREEN_ADDRESS: %s\n", greenip);
exit(1);
}
if (!findkey(kv, "GREEN_NETMASK", greenmask))
{
fprintf(stderr, "Cannot read GREEN_NETMASK\n");
exit(1);
}
if (!VALID_IP(greenmask))
{
fprintf(stderr, "Bad GREEN_NETMASK: %s\n", greenmask);
exit(1);
}
/* Get the BLUE interface details */
findkey(kv, "BLUE_DEV", bluedev);
if (strlen(bluedev))
{
if (!VALID_DEVICE(bluedev))
{
fprintf(stderr, "Bad BLUE_DEV: %s\n", bluedev);
exit(1);
}
if (!findkey(kv, "BLUE_ADDRESS", blueip))
{
fprintf(stderr, "Cannot read BLUE_ADDRESS\n");
exit(1);
}
if (!VALID_IP(blueip))
{
fprintf(stderr, "Bad BLUE_ADDRESS: %s\n", blueip);
exit(1);
}
if (!findkey(kv, "BLUE_NETMASK", bluemask))
{
fprintf(stderr, "Cannot read BLUE_NETMASK\n");
exit(1);
}
if (!VALID_IP(bluemask))
{
fprintf(stderr, "Bad BLUE_NETMASK: %s\n", bluemask);
exit(1);
}
}
/* Get the ORANGE interface details */
findkey(kv, "ORANGE_DEV", orangedev);
if (strlen(orangedev))
{
if (!VALID_DEVICE(orangedev))
{
fprintf(stderr, "Bad ORANGE_DEV: %s\n", orangedev);
exit(1);
}
if (!findkey(kv, "ORANGE_ADDRESS", orangeip))
{
fprintf(stderr, "Cannot read ORANGE_ADDRESS\n");
exit(1);
}
if (!VALID_IP(orangeip))
{
fprintf(stderr, "Bad ORANGE_ADDRESS: %s\n", orangeip);
exit(1);
}
if (!findkey(kv, "ORANGE_NETMASK", orangemask))
{
fprintf(stderr, "Cannot read ORANGE_NETMASK\n");
exit(1);
}
if (!VALID_IP(orangemask))
{
fprintf(stderr, "Bad ORANGE_NETMASK: %s\n", orangemask);
exit(1);
}
}
if (!(ipfile = fopen(CONFIG_ROOT "/red/local-ipaddress", "r")))
{
fprintf(stderr, "Couldn't open local ip file\n");
exit(1);
}
fgets(locip, STRING_SIZE, ipfile);
if (locip[strlen(locip) - 1] == '\n')
locip[strlen(locip) - 1] = '\0';
fclose (ipfile);
if (!VALID_IP(locip))
{
fprintf(stderr, "Bad local IP: %s\n", locip);
exit(1);
}
if (!(ifacefile = fopen(CONFIG_ROOT "/red/iface", "r")))
{
fprintf(stderr, "Couldn't open iface file\n");
exit(1);
}
fgets(iface, STRING_SIZE, ifacefile);
if (iface[strlen(iface) - 1] == '\n')
iface[strlen(iface) - 1] = '\0';
fclose (ifacefile);
if (!VALID_DEVICE(iface))
{
fprintf(stderr, "Bad iface: %s\n", iface);
exit(1);
}
if (!(fwdfile = fopen(CONFIG_ROOT "/portfw/config", "r")))
{
fprintf(stderr, "Couldn't open portfw settings file\n");
exit(1);
}
safe_system("/sbin/iptables -t nat -F PORTFW");
safe_system("/sbin/iptables -t mangle -F PORTFWMANGLE");
safe_system("/sbin/iptables -F PORTFWACCESS");
while (fgets(s, STRING_SIZE, fwdfile) != NULL)
{
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
result = strtok(s, ",");
count = 0;
key1 = NULL;
key2 = NULL;
protocol = NULL;
srcip = NULL;
locport = NULL;
remip = NULL;
origip = NULL;
remport = NULL;
enabled = NULL;
while (result)
{
if (count == 0)
key1 = result;
else if (count == 1)
key2 = result;
else if (count == 2)
protocol = result;
else if (count == 3)
locport = result;
else if (count == 4)
remip = result;
else if (count == 5)
remport = result;
else if (count == 6)
enabled = result;
else if (count == 7)
srcip = result;
else if (count == 8)
origip = result;
count++;
result = strtok(NULL, ",");
}
if (!(key1 && key2 && protocol && locport && remip && remport && enabled
&& srcip && origip))
break;
if (!VALID_PROTOCOL(protocol))
{
fprintf(stderr, "Bad protocol: %s\n", protocol);
exit(1);
}
if (strcmp(protocol, "gre") == 0)
{
locport = "0";
remport = "0";
}
if (strcmp(origip,"0") && !VALID_IP_AND_MASK(origip))
{
fprintf(stderr, "Bad IP: %s\n", origip);
exit(1);
}
if (!VALID_PORT_RANGE(locport))
{
fprintf(stderr, "Bad local port: %s\n", locport);
exit(1);
}
if (!VALID_IP(remip))
{
fprintf(stderr, "Bad remote IP: %s\n", remip);
exit(1);
}
if (!VALID_PORT_RANGE(remport))
{
fprintf(stderr, "Bad remote port: %s\n", remport);
exit(1);
}
/* check for source ip in config file. If it's there
* and it's not 0.0.0.0, use it; else use the
* local ip address. (This makes sure we can use old-style
* config files without the source ip) */
if (!srcip || !strcmp(srcip, "0.0.0.0"))
srcip = locip;
if (strcmp(srcip,"0") && !VALID_IP(srcip))
{
fprintf(stderr, "Bad source IP: %s\n", srcip);
exit(1);
}
/* This may seem complicated... refer to portfw.pl for an explanation of
* the keys and their meaning in certain circumstances */
if (strcmp(enabled, "on") == 0)
{
/* If key2 is a zero, then it is a portfw command, otherwise it is an
* external access command */
if (strcmp(key2, "0") == 0)
{
memset(command, 0, STRING_SIZE);
if (strcmp(protocol, "gre") == 0)
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -t nat -A PORTFW -p %s -d %s -j DNAT --to %s", protocol, srcip, remip);
else
{
char *ctr;
/* If locport contains a - we need to change it to a : */
if ((ctr = strchr(locport, '-')) != NULL) {*ctr = ':';}
/* If remport contains a : we need to change it to a - */
if ((ctr = strchr(remport,':')) != NULL){*ctr = '-';}
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -t nat -A PORTFW -p %s -d %s --dport %s -j DNAT --to %s:%s", protocol, srcip, locport, remip, remport);
safe_system(command);
/* Now if remport contains a - we need to change it to a : */
if ((ctr = strchr(remport,'-')) != NULL){*ctr = ':';}
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -t mangle -A PORTFWMANGLE -p %s -s %s/%s -d %s --dport %s -j MARK --set-mark 1", protocol, greenip, greenmask, srcip, locport);
if (strlen(bluedev))
{
safe_system(command);
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -t mangle -A PORTFWMANGLE -p %s -s %s/%s -d %s --dport %s -j MARK --set-mark 2", protocol, blueip, bluemask, srcip, locport);
}
if (strlen(orangedev))
{
safe_system(command);
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -t mangle -A PORTFWMANGLE -p %s -s %s/%s -d %s --dport %s -j MARK --set-mark 3", protocol, orangeip, orangemask, srcip, locport);
}
}
safe_system(command);
}
/* if key2 is not "0" then it's an external access rule, if key2 is "0"
* then the portfw rule may contain external access information if origip
* is not "0" (the only defined not 0 value seems to be 0.0.0.0 - open
* to all; again, check portfw.pl for more details) */
if(strcmp(key2, "0") || strcmp(origip,"0") )
{
memset(command, 0, STRING_SIZE);
if (strcmp(protocol, "gre") == 0)
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A PORTFWACCESS -i %s -p %s -s %s -d %s -j ACCEPT", iface, protocol, origip, remip);
else
{
char *ctr;
/* If remport contains a - we need to change it to a : */
if ((ctr = strchr(remport,'-')) != NULL){*ctr = ':';}
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A PORTFWACCESS -i %s -p %s -s %s -d %s --dport %s -j ACCEPT", iface, protocol, origip, remip, remport);
}
safe_system(command);
}
}
}
return 0;
}

204
src/misc-progs/setuid.c Normal file
View File

@@ -0,0 +1,204 @@
/* This file is part of the IPCop Firewall.
*
* IPCop is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* IPCop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with IPCop; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Copyright (C) 2003-04-22 Robert Kerr <rkerr@go.to>
*
* $Id: setuid.c,v 1.2.2.1 2005/11/18 14:51:43 franck78 Exp $
*
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <grp.h>
#include <signal.h>
#include <sys/wait.h>
#include <glob.h>
#include "setuid.h"
#ifndef OPEN_MAX
#define OPEN_MAX 256
#endif
/* Trusted environment for executing commands */
char * trusted_env[4]={
"PATH=/usr/bin:/usr/sbin:/sbin:/bin",
"SHELL=/bin/sh",
"TERM=dumb",
NULL};
/* Spawns a child process that uses /bin/sh to interpret a command.
* This is much the same in use and purpose as system(), yet as it uses execve
* to pass a trusted environment it's immune to attacks based upon changing
* IFS, ENV, BASH_ENV and other such variables.
* Note this does NOT guard against any other attacks, inparticular you MUST
* validate the command you are passing. If the command is formed from user
* input be sure to check this input is what you expect. Nasty things can
* happen if a user can inject ; or `` into your command for example */
int safe_system(char* command)
{
return system_core( command, 0, 0, "safe_system" );
}
/* Much like safe_system but lets you specify a non-root uid and gid to run
* the command as */
int unpriv_system(char* command, uid_t uid, gid_t gid)
{
return system_core(command, uid, gid, "unpriv_system" );
}
int system_core(char* command, uid_t uid, gid_t gid, char *error)
{
int pid, status;
if(!command)
return 1;
switch( pid = fork() )
{
case -1:
return -1;
case 0: /* child */
{
char * argv[4];
if (gid && setgid(gid))
{
fprintf(stderr, "%s: ", error);
perror("Couldn't setgid");
exit(127);
}
if (uid && setuid(uid))
{
fprintf(stderr, "%s: ", error);
perror("Couldn't setuid");
exit(127);
}
argv[0] = "sh";
argv[1] = "-c";
argv[2] = command;
argv[3] = NULL;
execve("/bin/sh", argv, trusted_env);
fprintf(stderr, "%s: ", error);
perror("execve failed");
exit(127);
}
default: /* parent */
do {
if( waitpid(pid, &status, 0) == -1 ) {
if( errno != EINTR )
return -1;
} else
return status;
} while (1);
}
}
/* BSD style safe strcat; from the secure programming cookbook */
size_t strlcat(char *dst, const char *src, size_t len) {
char *dstptr = dst;
size_t dstlen, tocopy = len;
const char *srcptr = src;
while (tocopy-- && *dstptr) dstptr++;
dstlen = dstptr - dst;
if (!(tocopy = len - dstlen)) return (dstlen + strlen(src));
while (*srcptr) {
if (tocopy != 1) {
*dstptr++ = *srcptr;
tocopy--;
}
srcptr++;
}
*dstptr = 0;
return (dstlen + (srcptr - src));
}
/* General routine to initialise a setuid root program, and put the
* environment in a known state. Returns 1 on success, if initsetuid() returns
* 0 then you should exit(1) immediately, DON'T attempt to recover from the
* error */
int initsetuid(void)
{
int fds,i;
struct stat st;
struct rlimit rlim;
/* Prevent signal tricks by ignoring all except SIGKILL and SIGCHILD */
for( i = 0; i < NSIG; i++ ) {
if( i != SIGKILL && i != SIGCHLD )
signal(i, SIG_IGN);
}
/* dump all non-standard file descriptors (a full descriptor table could
* lead to DoS by preventing us opening files) */
if ((fds = getdtablesize()) == -1) fds = OPEN_MAX;
for( i = 3; i < fds; i++ ) close(i);
/* check stdin, stdout & stderr are open before going any further */
for( i = 0; i < 3; i++ )
if( fstat(i, &st) == -1 && ((errno != EBADF) || (close(i), open("/dev/null", O_RDWR, 0)) != i ))
return 0;
/* disable core dumps in case we're processing sensitive information */
rlim.rlim_cur = rlim.rlim_max = 0;
if(setrlimit(RLIMIT_CORE, &rlim))
{ perror("Couldn't disable core dumps"); return 0; }
/* drop any supplementary groups, set uid & gid to root */
if (setgroups(0, NULL)) { perror("Couldn't clear group list"); return 0; }
if (setgid(0)) { perror("Couldn't setgid(0)"); return 0; }
if (setuid(0)) { perror("Couldn't setuid(0)"); return 0; }
return 1;
}
/* check whether a file exists */
int file_exists(const char *fname) {
struct stat st;
stat(fname, &st);
return S_ISREG(st.st_mode) ? 1 : 0;
}
/* check whether a file exists. fname is wildcard eg: file_exists (/tmp/foo*) */
int file_exists_w(const char *fname)
{
/* do a quick check first */
struct stat st;
stat(fname, &st);
if (S_ISREG(st.st_mode))
return 1;
/* check for possible wild cards in name */
glob_t globbuf;
int retval=0;
if (glob(fname, GLOB_ERR, NULL, &globbuf)==0) {
if (globbuf.gl_pathc>0) {
retval=1;
}
}
globfree(&globbuf);
return retval;
}

91
src/misc-progs/setuid.h Normal file
View File

@@ -0,0 +1,91 @@
/* SmoothWall helper program - header file
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
* Simple header file for all setuid progs.
*
* $Id: setuid.h,v 1.4.2.4 2005/11/20 23:20:13 franck78 Exp $
*
*/
#ifndef SETUID_H
#define SETUID_H 1
#include <stdlib.h>
#include <sys/types.h>
/* As nothing in setuid.c uses STRING_SIZE specifically there's no real reason
* to redefine it if it already is set */
#ifndef STRING_SIZE
#define STRING_SIZE 256
#endif
#define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define NUMBERS "0123456789"
#define LETTERS_NUMBERS LETTERS NUMBERS
#define IP_NUMBERS "./" NUMBERS
#define PORT_NUMBERS ":-" NUMBERS
#define VALID_FQDN LETTERS_NUMBERS ".-"
#define VALID_IP(ip) (strlen(ip) > 6 \
&& strlen(ip) < 16 \
&& strspn(ip, NUMBERS ".") == strlen(ip))
#define VALID_IP_AND_MASK(ip) (strlen(ip) > 6 \
&& strlen(ip) < 32 \
&& strspn(ip, IP_NUMBERS) == strlen(ip))
#define VALID_PORT(port) (strlen(port) \
&& strlen(port) < 6 \
&& strspn(port, NUMBERS) == strlen(port))
#define VALID_PORT_RANGE(port) (strlen(port) \
&& strlen(port) < 12 \
&& strspn(port, PORT_NUMBERS) == strlen(port))
#define VALID_SHORT_MASK(ip) (strlen(ip) > 1 \
&& strlen(ip) < 3 \
&& strspn(ip, NUMBERS) == strlen(ip))
/* Can't find any info on valid characters/length hopefully these are
* reasonable guesses */
#define VALID_DEVICE(dev) (strlen(dev) \
&& strlen(dev) < 16 \
&& strspn(dev, LETTERS_NUMBERS ":.") == strlen(dev))
/* Again, can't find any hard and fast rules for protocol names, these
* restrictions are based on the keywords currently listed in
* <http://www.iana.org/assignments/protocol-numbers>
* though currently the ipcop cgis will only pass tcp, udp or gre anyway */
#define VALID_PROTOCOL(prot) (strlen(prot) \
&& strlen(prot) <16 \
&& strspn(prot, LETTERS_NUMBERS "-") == strlen(prot))
extern char * trusted_env[4];
int system_core(char* command, uid_t uid, gid_t gid, char *error);
int safe_system(char* command);
int unpriv_system(char* command, uid_t uid, gid_t gid);
size_t strlcat(char *dst, const char *src, size_t len);
int initsetuid(void);
/* check whether a file exists */
int file_exists(const char *fname);
int file_exists_w(const char *fname); //wildcard filename test
// Backup restore
#define MOUNTPOINT "/home/httpd/html/backup"
#define BACKUP_KEY CONFIG_ROOT"/backup/backup.key"
/* defines for config create/restore return status*/
#define ERR_ANY 1 // unspecified error
#define ERR_KEY 2 // error creating key file
#define ERR_TAR 3 // error creating .tar
#define ERR_GZ 4 // error creating .tar.gz
#define ERR_ENCRYPT 5 // error creating .dat
#define ERR_DECRYPT 6 // error decrypting .dat file
#define ERR_UNTARTST 7 // error (test) untarring .tar.gz
#define ERR_UNTAR 8 // error (real) untarring .tar.gz
#define ERR_DAT 9 // missing .dat file
#endif

View File

@@ -0,0 +1,168 @@
/* SmoothWall helper program - setxtaccess
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* (c) Daniel Goscomb, 2001
*
* Modifications and improvements by Lawrence Manning.
*
* 10/04/01 Aslak added protocol support
*
* (c) Steve Bootes 2002/04/14 - Added source IP support for aliases
*
* 19/04/03 Robert Kerr Fixed root exploit
*
* $Id: setxtaccess.c,v 1.3.2.1 2005/01/04 17:21:40 eoberlander Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "setuid.h"
FILE *ifacefile = NULL;
FILE *fwdfile = NULL;
FILE *ipfile = NULL;
void exithandler(void)
{
if (fwdfile)
fclose(fwdfile);
}
int main(void)
{
char iface[STRING_SIZE] = "";
char locip[STRING_SIZE] = "";
char s[STRING_SIZE] = "";
int count;
char *protocol;
char *destip;
char *remip;
char *locport;
char *enabled;
char *information;
char *result;
char command[STRING_SIZE];
if (!(initsetuid()))
exit(1);
atexit(exithandler);
if (!(ipfile = fopen(CONFIG_ROOT "/red/local-ipaddress", "r")))
{
fprintf(stderr, "Couldn't open local ip file\n");
exit(1);
}
if (fgets(locip, STRING_SIZE, ipfile))
{
if (locip[strlen(locip) - 1] == '\n')
locip[strlen(locip) - 1] = '\0';
}
fclose (ipfile);
if (!VALID_IP(locip))
{
fprintf(stderr, "Bad local IP: %s\n", locip);
exit(1);
}
if (!(ifacefile = fopen(CONFIG_ROOT "/red/iface", "r")))
{
fprintf(stderr, "Couldn't open iface file\n");
exit(1);
}
if (fgets(iface, STRING_SIZE, ifacefile))
{
if (iface[strlen(iface) - 1] == '\n')
iface[strlen(iface) - 1] = '\0';
}
fclose (ifacefile);
if (!VALID_DEVICE(iface))
{
fprintf(stderr, "Bad iface: %s\n", iface);
exit(1);
}
if (!(fwdfile = fopen(CONFIG_ROOT "/xtaccess/config", "r")))
{
fprintf(stderr, "Couldn't open xtaccess settings file\n");
exit(1);
}
safe_system("/sbin/iptables -F XTACCESS");
while (fgets(s, STRING_SIZE, fwdfile) != NULL)
{
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
count = 0;
protocol = NULL;
remip = NULL;
destip = NULL;
locport = NULL;
enabled = NULL;
information = NULL;
result = strtok(s, ",");
while (result)
{
if (count == 0)
protocol = result;
else if (count == 1)
remip = result;
else if (count == 2)
locport = result;
else if (count == 3)
enabled = result;
else if (count == 4)
destip = result;
else
information = result;
count++;
result = strtok(NULL, ",");
}
if (!(protocol && remip && locport && enabled))
break;
if (!VALID_PROTOCOL(protocol))
{
fprintf(stderr, "Bad protocol: %s\n", protocol);
exit(1);
}
if (!VALID_IP_AND_MASK(remip))
{
fprintf(stderr, "Bad remote IP: %s\n", remip);
exit(1);
}
if (!VALID_PORT_RANGE(locport))
{
fprintf(stderr, "Bad local port: %s\n", locport);
exit(1);
}
/* check for destination ip in config file. If it's there
* and it's not 0.0.0.0, use it; else use the current
* local ip address. (This makes sure we can use old-style
* config files without the destination ip) */
if (!destip || !strcmp(destip, "0.0.0.0"))
destip = locip;
if (!VALID_IP(destip))
{
fprintf(stderr, "Bad destination IP: %s\n", remip);
exit(1);
}
if (strcmp(enabled, "on") == 0)
{
memset(command, 0, STRING_SIZE);
snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A XTACCESS -i %s -p %s -s %s -d %s --dport %s -j ACCEPT",
iface, protocol, remip, destip, locport);
safe_system(command);
}
}
return 0;
}

9
src/nash/CVS/Entries Normal file
View File

@@ -0,0 +1,9 @@
/Makefile/1.1/Tue Dec 30 17:40:08 2003//TIPCOP_v1_4_0
/linux_fs.h/1.1/Tue Dec 30 17:40:08 2003//TIPCOP_v1_4_0
/mkinitrd/1.3/Tue Dec 30 20:50:26 2003//TIPCOP_v1_4_0
/mount_by_label.c/1.1/Tue Dec 30 17:40:08 2003//TIPCOP_v1_4_0
/mount_by_label.h/1.1/Tue Dec 30 17:40:08 2003//TIPCOP_v1_4_0
/nash.8/1.1/Tue Dec 30 17:40:08 2003//TIPCOP_v1_4_0
/nash.c/1.1/Tue Dec 30 17:40:08 2003//TIPCOP_v1_4_0
/sample-rc/1.1/Tue Dec 30 17:40:08 2003//TIPCOP_v1_4_0
D

1
src/nash/CVS/Repository Normal file
View File

@@ -0,0 +1 @@
ipcop/src/nash

Some files were not shown because too many files have changed in this diff Show More