summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-11-09 17:51:27 +0000
committerbrian <brian@FreeBSD.org>1997-11-09 17:51:27 +0000
commit59161ba72e6fdf26776f6ecd1b0c6e2f163fb186 (patch)
tree29ec5c26fc2e68e7fc68a670b77b59d6dc2afa7a /usr.sbin/ppp
parent61fdf2fa6dba16e9069d05fc167888ed82c5093c (diff)
downloadFreeBSD-src-59161ba72e6fdf26776f6ecd1b0c6e2f163fb186.zip
FreeBSD-src-59161ba72e6fdf26776f6ecd1b0c6e2f163fb186.tar.gz
Add the "!include" syntax.
Return 0 from "show" commands.
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r--usr.sbin/ppp/command.c73
-rw-r--r--usr.sbin/ppp/ppp.835
-rw-r--r--usr.sbin/ppp/ppp.8.m435
-rw-r--r--usr.sbin/ppp/systems.c128
4 files changed, 208 insertions, 63 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 00d10ce..da084a1 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: command.c,v 1.91 1997/11/08 00:28:06 brian Exp $
+ * $Id: command.c,v 1.92 1997/11/09 06:22:39 brian Exp $
*
*/
#include <sys/param.h>
@@ -411,18 +411,17 @@ ShowEscape()
fprintf(VarTerm, " 0x%02x", (code << 3) + bit);
fprintf(VarTerm, "\n");
}
- return 1;
+ return 0;
}
static int
ShowTimeout()
{
- if (!VarTerm)
- return 0;
- fprintf(VarTerm, " Idle Timer: %d secs LQR Timer: %d secs"
- " Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
- VarRetryTimeout);
- return 1;
+ if (VarTerm)
+ fprintf(VarTerm, " Idle Timer: %d secs LQR Timer: %d secs"
+ " Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
+ VarRetryTimeout);
+ return 0;
}
static int
@@ -451,7 +450,7 @@ ShowStopped()
fprintf(VarTerm, "\n");
- return 1;
+ return 0;
}
static int
@@ -464,47 +463,43 @@ ShowAuthKey()
#ifdef HAVE_DES
fprintf(VarTerm, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" );
#endif
- return 1;
+ return 0;
}
static int
ShowVersion()
{
- if (!VarTerm)
- return 0;
- fprintf(VarTerm, "%s - %s \n", VarVersion, VarLocalVersion);
- return 1;
+ if (VarTerm)
+ fprintf(VarTerm, "%s - %s \n", VarVersion, VarLocalVersion);
+ return 0;
}
static int
ShowInitialMRU()
{
- if (!VarTerm)
- return 0;
- fprintf(VarTerm, " Initial MRU: %ld\n", VarMRU);
- return 1;
+ if (VarTerm)
+ fprintf(VarTerm, " Initial MRU: %ld\n", VarMRU);
+ return 0;
}
static int
ShowPreferredMTU()
{
- if (!VarTerm)
- return 0;
- if (VarPrefMTU)
- fprintf(VarTerm, " Preferred MTU: %ld\n", VarPrefMTU);
- else
- fprintf(VarTerm, " Preferred MTU: unspecified\n");
- return 1;
+ if (VarTerm)
+ if (VarPrefMTU)
+ fprintf(VarTerm, " Preferred MTU: %ld\n", VarPrefMTU);
+ else
+ fprintf(VarTerm, " Preferred MTU: unspecified\n");
+ return 0;
}
static int
ShowReconnect()
{
- if (!VarTerm)
- return 0;
- fprintf(VarTerm, " Reconnect Timer: %d, %d tries\n",
- VarReconnectTimer, VarReconnectTries);
- return 1;
+ if (VarTerm)
+ fprintf(VarTerm, " Reconnect Timer: %d, %d tries\n",
+ VarReconnectTimer, VarReconnectTries);
+ return 0;
}
static int
@@ -533,21 +528,21 @@ ShowRedial()
fprintf(VarTerm, "\n");
- return 1;
+ return 0;
}
#ifndef NOMSEXT
static int
ShowMSExt()
{
- if (!VarTerm)
- return 0;
- fprintf(VarTerm, " MS PPP extention values \n");
- fprintf(VarTerm, " Primary NS : %s\n", inet_ntoa(ns_entries[0]));
- fprintf(VarTerm, " Secondary NS : %s\n", inet_ntoa(ns_entries[1]));
- fprintf(VarTerm, " Primary NBNS : %s\n", inet_ntoa(nbns_entries[0]));
- fprintf(VarTerm, " Secondary NBNS : %s\n", inet_ntoa(nbns_entries[1]));
- return 1;
+ if (VarTerm) {
+ fprintf(VarTerm, " MS PPP extention values \n");
+ fprintf(VarTerm, " Primary NS : %s\n", inet_ntoa(ns_entries[0]));
+ fprintf(VarTerm, " Secondary NS : %s\n", inet_ntoa(ns_entries[1]));
+ fprintf(VarTerm, " Primary NBNS : %s\n", inet_ntoa(nbns_entries[0]));
+ fprintf(VarTerm, " Secondary NBNS : %s\n", inet_ntoa(nbns_entries[1]));
+ }
+ return 0;
}
#endif
diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8
index c5f20d9..c3eafe2 100644
--- a/usr.sbin/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp.8
@@ -1,4 +1,4 @@
-.\" $Id: ppp.8,v 1.74 1997/11/09 06:22:46 brian Exp $
+.\" $Id: ppp.8,v 1.75 1997/11/09 13:18:51 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@@ -350,25 +350,32 @@ See the example definitions in
.Pa /etc/ppp/ppp.conf
is pretty simple).
-.Bl -bullet -compact
-
-.It
-Each line contains one command, label or comment.
+Each line contains one comment, inclusion, label or command:
+.Bl -bullet -compact
.It
A line starting with a
-.Sq #
+.Pq Dq #
character is treated as a comment line.
.It
+An inclusion is a line beginning with the word
+.Sq !include .
+It must have one argument - the file to include. You may wish to
+.Dq !include ~/.ppp.conf
+for compatibility with older versions of
+.Nm ppp .
+
+.It
A label name starts in the first column and is followed by
-a colon (:).
+a colon
+.Pq Dq \&: .
.It
A command line must contain a space or tab in the first column.
-
.El
+.Pp
The
.Pa /etc/ppp/ppp.conf
file should consist of at least a
@@ -423,12 +430,20 @@ connection is established. See the provided
.Dq pmdemand
example in
.Pa /etc/ppp/ppp.conf.sample
-which adds a default route. The string HISADDR is available as the IP
-address of the remote peer. Similarly, when a connection is closed, the
+which adds a default route. The strings
+.Dv HISADDR ,
+.Dv MYADDR
+and
+.Dv INTERFACE
+are available as the relevent IP addresses and interface name.
+Similarly, when a connection is closed, the
contents of the
.Pa /etc/ppp/ppp.linkdown
file are executed.
+Both of these files have the same format as
+.Pa /etc/ppp/ppp.conf .
+
.Sh BACKGROUND DIALING
If you want to establish a connection using
diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4
index c5f20d9..c3eafe2 100644
--- a/usr.sbin/ppp/ppp.8.m4
+++ b/usr.sbin/ppp/ppp.8.m4
@@ -1,4 +1,4 @@
-.\" $Id: ppp.8,v 1.74 1997/11/09 06:22:46 brian Exp $
+.\" $Id: ppp.8,v 1.75 1997/11/09 13:18:51 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@@ -350,25 +350,32 @@ See the example definitions in
.Pa /etc/ppp/ppp.conf
is pretty simple).
-.Bl -bullet -compact
-
-.It
-Each line contains one command, label or comment.
+Each line contains one comment, inclusion, label or command:
+.Bl -bullet -compact
.It
A line starting with a
-.Sq #
+.Pq Dq #
character is treated as a comment line.
.It
+An inclusion is a line beginning with the word
+.Sq !include .
+It must have one argument - the file to include. You may wish to
+.Dq !include ~/.ppp.conf
+for compatibility with older versions of
+.Nm ppp .
+
+.It
A label name starts in the first column and is followed by
-a colon (:).
+a colon
+.Pq Dq \&: .
.It
A command line must contain a space or tab in the first column.
-
.El
+.Pp
The
.Pa /etc/ppp/ppp.conf
file should consist of at least a
@@ -423,12 +430,20 @@ connection is established. See the provided
.Dq pmdemand
example in
.Pa /etc/ppp/ppp.conf.sample
-which adds a default route. The string HISADDR is available as the IP
-address of the remote peer. Similarly, when a connection is closed, the
+which adds a default route. The strings
+.Dv HISADDR ,
+.Dv MYADDR
+and
+.Dv INTERFACE
+are available as the relevent IP addresses and interface name.
+Similarly, when a connection is closed, the
contents of the
.Pa /etc/ppp/ppp.linkdown
file are executed.
+Both of these files have the same format as
+.Pa /etc/ppp/ppp.conf .
+
.Sh BACKGROUND DIALING
If you want to establish a connection using
diff --git a/usr.sbin/ppp/systems.c b/usr.sbin/ppp/systems.c
index e3f9282..715cb11 100644
--- a/usr.sbin/ppp/systems.c
+++ b/usr.sbin/ppp/systems.c
@@ -17,13 +17,15 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: systems.c,v 1.20 1997/11/09 13:18:18 brian Exp $
+ * $Id: systems.c,v 1.21 1997/11/09 14:18:53 brian Exp $
*
* TODO:
*/
#include <sys/param.h>
#include <netinet/in.h>
+#include <ctype.h>
+#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -43,6 +45,8 @@
#include "server.h"
#include "systems.h"
+#define issep(ch) ((ch) == ' ' || (ch) == '\t')
+
FILE *
OpenSecret(char *file)
{
@@ -62,6 +66,105 @@ CloseSecret(FILE * fp)
fclose(fp);
}
+/* Move string from ``from'' to ``to'', interpreting ``~'' and $.... */
+static void
+InterpretArg(char *from, char *to)
+{
+ const char *env;
+ char *ptr, *startto, *endto;
+ int len;
+
+ startto = to;
+ endto = to + LINE_LEN - 1;
+
+ while(issep(*from))
+ from++;
+ if (*from == '~') {
+ ptr = strchr(++from, '/');
+ len = ptr ? ptr - from : strlen(from);
+ if (len == 0) {
+ if ((env = getenv("HOME")) == NULL)
+ env = _PATH_PPP;
+ strncpy(to, env, endto - to);
+ } else {
+ struct passwd *pwd;
+
+ strncpy(to, from, len);
+ to[len] = '\0';
+ pwd = getpwnam(to);
+ if (pwd)
+ strncpy(to, pwd->pw_dir, endto-to);
+ else
+ strncpy(to, _PATH_PPP, endto - to);
+ endpwent();
+ }
+ *endto = '\0';
+ to += strlen(to);
+ from += len;
+ }
+
+ while (to < endto && *from != '\0') {
+ if (*from == '$') {
+ if (from[1] == '$') {
+ *to = '\0'; /* For an empty var name below */
+ from += 2;
+ } else if (from[1] == '{') {
+ ptr = strchr(from+2, '}');
+ if (ptr) {
+ len = ptr - from - 2;
+ if (endto - to < len )
+ len = endto - to;
+ if (len) {
+ strncpy(to, from+2, len);
+ to[len] = '\0';
+ from = ptr+1;
+ } else {
+ *to++ = *from++;
+ continue;
+ }
+ } else {
+ *to++ = *from++;
+ continue;
+ }
+ } else {
+ ptr = to;
+ for (from++; (isalnum(*from) || *from == '_') && ptr < endto; from++)
+ *ptr++ = *from;
+ *ptr = '\0';
+ }
+ if (*to == '\0')
+ *to++ = '$';
+ else if ((env = getenv(to)) != NULL) {
+ strncpy(to, env, endto - to);
+ *endto = '\0';
+ to += strlen(to);
+ }
+ } else
+ *to++ = *from++;
+ }
+ while (to > startto) {
+ to--;
+ if (!issep(*to)) {
+ to++;
+ break;
+ }
+ }
+ *to = '\0';
+}
+
+#define CTRL_UNKNOWN (0)
+#define CTRL_INCLUDE (1)
+
+static int
+DecodeCtrlCommand(char *line, char *arg)
+{
+ if (!strncasecmp(line, "include", 7) && issep(line[7])) {
+ InterpretArg(line+8, arg);
+ return CTRL_INCLUDE;
+ }
+ return CTRL_UNKNOWN;
+}
+
int
SelectSystem(char *name, char *file)
{
@@ -73,7 +176,10 @@ SelectSystem(char *name, char *file)
char filename[200];
int linenum;
- snprintf(filename, sizeof filename, "%s/%s", _PATH_PPP, file);
+ if (*file == '/')
+ snprintf(filename, sizeof filename, "%s", file);
+ else
+ snprintf(filename, sizeof filename, "%s/%s", _PATH_PPP, file);
fp = ID0fopen(filename, "r");
if (fp == NULL) {
LogPrintf(LogDEBUG, "SelectSystem: Can't open %s.\n", filename);
@@ -100,10 +206,24 @@ SelectSystem(char *name, char *file)
exit(1);
}
*wp = '\0';
- if (strcmp(cp, name) == 0) {
+ if (*cp == '!') {
+ char arg[LINE_LEN];
+ switch (DecodeCtrlCommand(cp+1, arg)) {
+ case CTRL_INCLUDE:
+ LogPrintf(LogCOMMAND, "%s: Including \"%s\"\n", filename, arg);
+ n = SelectSystem(name, arg);
+ LogPrintf(LogCOMMAND, "%s: Done include of \"%s\"\n", filename, arg);
+ if (!n)
+ return 0; /* got it */
+ break;
+ default:
+ LogPrintf(LogCOMMAND, "%s: %s: Invalid command\n", name, cp);
+ break;
+ }
+ } else if (strcmp(cp, name) == 0) {
while (fgets(line, sizeof(line), fp)) {
cp = line;
- if (*cp == ' ' || *cp == '\t') {
+ if (issep(*cp)) {
n = strspn(cp, " \t");
cp += n;
len = strlen(cp);
OpenPOWER on IntegriCloud