2001-06-13 21:52:19 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
|
|
|
|
* Internet Initiative Japan, Inc (IIJ)
|
|
|
|
* All rights reserved.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
2001-06-13 21:52:19 +00:00
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
|
1997-11-09 17:51:27 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <pwd.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-05-08 11:07:56 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1998-06-15 19:06:25 +00:00
|
|
|
#include "defs.h"
|
1997-11-22 03:37:54 +00:00
|
|
|
#include "command.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "log.h"
|
1997-11-09 06:22:49 +00:00
|
|
|
#include "id.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "systems.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-09 17:51:27 +00:00
|
|
|
#define issep(ch) ((ch) == ' ' || (ch) == '\t')
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
FILE *
|
1997-11-22 03:37:54 +00:00
|
|
|
OpenSecret(const char *file)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char line[100];
|
|
|
|
|
2001-03-23 11:43:22 +00:00
|
|
|
snprintf(line, sizeof line, "%s/%s", PPP_CONFDIR, file);
|
1997-11-09 06:22:49 +00:00
|
|
|
fp = ID0fopen(line, "r");
|
|
|
|
if (fp == NULL)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "OpenSecret: Can't open %s.\n", line);
|
1997-08-25 00:29:32 +00:00
|
|
|
return (fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-09 20:02:29 +00:00
|
|
|
CloseSecret(FILE *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
1997-11-09 17:51:27 +00:00
|
|
|
/* Move string from ``from'' to ``to'', interpreting ``~'' and $.... */
|
2000-03-14 01:47:31 +00:00
|
|
|
const char *
|
1999-12-20 20:30:25 +00:00
|
|
|
InterpretArg(const char *from, char *to)
|
1997-11-09 17:51:27 +00:00
|
|
|
{
|
|
|
|
char *ptr, *startto, *endto;
|
2000-03-14 01:47:31 +00:00
|
|
|
struct passwd *pwd;
|
|
|
|
int len, instring;
|
|
|
|
const char *env;
|
1997-11-09 17:51:27 +00:00
|
|
|
|
2000-03-14 01:47:31 +00:00
|
|
|
instring = 0;
|
1997-11-09 17:51:27 +00:00
|
|
|
startto = to;
|
|
|
|
endto = to + LINE_LEN - 1;
|
|
|
|
|
|
|
|
while(issep(*from))
|
|
|
|
from++;
|
1999-12-20 20:30:25 +00:00
|
|
|
|
2000-03-14 01:47:31 +00:00
|
|
|
while (*from != '\0') {
|
|
|
|
switch (*from) {
|
|
|
|
case '"':
|
|
|
|
instring = !instring;
|
|
|
|
*to++ = *from++;
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
switch (*++from) {
|
|
|
|
case '$':
|
|
|
|
case '~':
|
|
|
|
break; /* Swallow the escapes */
|
|
|
|
|
|
|
|
default:
|
|
|
|
*to++ = '\\'; /* Pass the escapes on, maybe skipping \# */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*to++ = *from++;
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
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;
|
|
|
|
}
|
1997-11-09 17:51:27 +00:00
|
|
|
} else {
|
|
|
|
*to++ = *from++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2000-03-14 01:47:31 +00:00
|
|
|
ptr = to;
|
|
|
|
for (from++; (isalnum(*from) || *from == '_') && ptr < endto; from++)
|
|
|
|
*ptr++ = *from;
|
|
|
|
*ptr = '\0';
|
1997-11-09 17:51:27 +00:00
|
|
|
}
|
2000-03-14 01:47:31 +00:00
|
|
|
if (*to == '\0')
|
|
|
|
*to++ = '$';
|
|
|
|
else if ((env = getenv(to)) != NULL) {
|
|
|
|
strncpy(to, env, endto - to);
|
|
|
|
*endto = '\0';
|
|
|
|
to += strlen(to);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '~':
|
|
|
|
ptr = strchr(++from, '/');
|
|
|
|
len = ptr ? ptr - from : strlen(from);
|
|
|
|
if (len == 0)
|
|
|
|
pwd = getpwuid(ID0realuid());
|
|
|
|
else {
|
|
|
|
strncpy(to, from, len);
|
|
|
|
to[len] = '\0';
|
|
|
|
pwd = getpwnam(to);
|
|
|
|
}
|
|
|
|
if (pwd == NULL)
|
|
|
|
*to++ = '~';
|
|
|
|
else {
|
|
|
|
strncpy(to, pwd->pw_dir, endto - to);
|
|
|
|
*endto = '\0';
|
|
|
|
to += strlen(to);
|
|
|
|
from += len;
|
|
|
|
}
|
|
|
|
endpwent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*to++ = *from++;
|
|
|
|
break;
|
1999-12-20 20:30:25 +00:00
|
|
|
}
|
1997-11-09 17:51:27 +00:00
|
|
|
}
|
1999-12-20 20:30:25 +00:00
|
|
|
|
1997-11-09 17:51:27 +00:00
|
|
|
while (to > startto) {
|
|
|
|
to--;
|
|
|
|
if (!issep(*to)) {
|
|
|
|
to++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*to = '\0';
|
1999-12-20 20:30:25 +00:00
|
|
|
|
|
|
|
return from;
|
1997-11-09 17:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CTRL_UNKNOWN (0)
|
|
|
|
#define CTRL_INCLUDE (1)
|
|
|
|
|
|
|
|
static int
|
|
|
|
DecodeCtrlCommand(char *line, char *arg)
|
|
|
|
{
|
1999-12-20 20:30:25 +00:00
|
|
|
const char *end;
|
|
|
|
|
1997-11-09 17:51:27 +00:00
|
|
|
if (!strncasecmp(line, "include", 7) && issep(line[7])) {
|
1999-12-20 20:30:25 +00:00
|
|
|
end = InterpretArg(line+8, arg);
|
|
|
|
if (*end && *end != '#')
|
2002-04-22 13:44:47 +00:00
|
|
|
log_Printf(LogWARN, "usage: !include filename\n");
|
1999-12-20 20:30:25 +00:00
|
|
|
else
|
|
|
|
return CTRL_INCLUDE;
|
1997-11-09 17:51:27 +00:00
|
|
|
}
|
|
|
|
return CTRL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
1998-10-31 17:38:47 +00:00
|
|
|
/*
|
|
|
|
* Initialised in system_IsValid(), set in ReadSystem(),
|
|
|
|
* used by system_IsValid()
|
|
|
|
*/
|
1998-04-10 13:19:23 +00:00
|
|
|
static int modeok;
|
1997-11-11 22:58:14 +00:00
|
|
|
static int userok;
|
1998-04-10 13:19:23 +00:00
|
|
|
static int modereq;
|
1997-11-11 22:58:14 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
int
|
1997-11-22 03:37:54 +00:00
|
|
|
AllowUsers(struct cmdargs const *arg)
|
1997-11-11 22:58:14 +00:00
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
/* arg->bundle may be NULL (see system_IsValid()) ! */
|
1997-11-11 22:58:14 +00:00
|
|
|
int f;
|
1999-12-20 20:30:40 +00:00
|
|
|
struct passwd *pwd;
|
1997-11-11 22:58:14 +00:00
|
|
|
|
2000-07-12 23:13:52 +00:00
|
|
|
if (userok == -1)
|
|
|
|
userok = 0;
|
|
|
|
|
1999-12-30 03:36:11 +00:00
|
|
|
pwd = getpwuid(ID0realuid());
|
1999-12-20 20:30:40 +00:00
|
|
|
if (pwd != NULL)
|
1998-04-14 23:17:24 +00:00
|
|
|
for (f = arg->argn; f < arg->argc; f++)
|
1999-12-20 20:30:40 +00:00
|
|
|
if (!strcmp("*", arg->argv[f]) || !strcmp(pwd->pw_name, arg->argv[f])) {
|
1997-11-11 22:58:14 +00:00
|
|
|
userok = 1;
|
|
|
|
break;
|
|
|
|
}
|
1999-12-20 20:30:40 +00:00
|
|
|
endpwent();
|
1997-11-11 22:58:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-11-22 03:37:54 +00:00
|
|
|
AllowModes(struct cmdargs const *arg)
|
1997-11-11 22:58:14 +00:00
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
/* arg->bundle may be NULL (see system_IsValid()) ! */
|
1998-05-15 23:58:30 +00:00
|
|
|
int f, mode, allowed;
|
1997-11-11 22:58:14 +00:00
|
|
|
|
|
|
|
allowed = 0;
|
1998-04-14 23:17:24 +00:00
|
|
|
for (f = arg->argn; f < arg->argc; f++) {
|
1998-05-15 23:58:30 +00:00
|
|
|
mode = Nam2mode(arg->argv[f]);
|
|
|
|
if (mode == PHYS_NONE || mode == PHYS_ALL)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "allow modes: %s: Invalid mode\n", arg->argv[f]);
|
1998-05-15 23:58:30 +00:00
|
|
|
else
|
|
|
|
allowed |= mode;
|
1997-11-11 22:58:14 +00:00
|
|
|
}
|
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
modeok = modereq & allowed ? 1 : 0;
|
1997-11-11 22:58:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-02-04 01:03:36 +00:00
|
|
|
static char *
|
|
|
|
strip(char *line)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(line);
|
|
|
|
while (len && (line[len-1] == '\n' || line[len-1] == '\r' ||
|
|
|
|
issep(line[len-1])))
|
|
|
|
line[--len] = '\0';
|
|
|
|
|
|
|
|
while (issep(*line))
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if (*line == '#')
|
|
|
|
*line = '\0';
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xgets(char *buf, int buflen, FILE *fp)
|
|
|
|
{
|
|
|
|
int len, n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
while (fgets(buf, buflen-1, fp)) {
|
|
|
|
n++;
|
|
|
|
buf[buflen-1] = '\0';
|
|
|
|
len = strlen(buf);
|
|
|
|
while (len && (buf[len-1] == '\n' || buf[len-1] == '\r'))
|
|
|
|
buf[--len] = '\0';
|
|
|
|
if (len && buf[len-1] == '\\') {
|
|
|
|
buf += len - 1;
|
|
|
|
buflen -= len - 1;
|
|
|
|
if (!buflen) /* No buffer space */
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1999-02-02 09:35:30 +00:00
|
|
|
/* Values for ``how'' in ReadSystem */
|
|
|
|
#define SYSTEM_EXISTS 1
|
|
|
|
#define SYSTEM_VALIDATE 2
|
|
|
|
#define SYSTEM_EXEC 3
|
|
|
|
|
1999-12-23 21:43:00 +00:00
|
|
|
static char *
|
|
|
|
GetLabel(char *line, const char *filename, int linenum)
|
|
|
|
{
|
1999-12-27 11:43:31 +00:00
|
|
|
char *argv[MAXARGS];
|
|
|
|
int argc, len;
|
|
|
|
|
|
|
|
argc = MakeArgs(line, argv, MAXARGS, PARSE_REDUCE);
|
|
|
|
|
|
|
|
if (argc == 2 && !strcmp(argv[1], ":"))
|
|
|
|
return argv[0];
|
|
|
|
|
|
|
|
if (argc != 1 || (len = strlen(argv[0])) < 2 || argv[0][len-1] != ':') {
|
|
|
|
log_Printf(LogWARN, "Bad label in %s (line %d) - missing colon\n",
|
1999-12-23 21:43:00 +00:00
|
|
|
filename, linenum);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-12-27 11:43:31 +00:00
|
|
|
argv[0][len-1] = '\0'; /* Lose the ':' */
|
1999-12-23 21:43:00 +00:00
|
|
|
|
1999-12-27 11:43:31 +00:00
|
|
|
return argv[0];
|
1999-12-23 21:43:00 +00:00
|
|
|
}
|
|
|
|
|
1999-03-09 20:39:03 +00:00
|
|
|
/* Returns -2 for ``file not found'' and -1 for ``label not found'' */
|
|
|
|
|
1997-11-11 22:58:14 +00:00
|
|
|
static int
|
1998-02-02 19:32:16 +00:00
|
|
|
ReadSystem(struct bundle *bundle, const char *name, const char *file,
|
1999-02-02 09:35:30 +00:00
|
|
|
struct prompt *prompt, struct datalink *cx, int how)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
1999-12-23 21:43:00 +00:00
|
|
|
char *cp;
|
1997-11-04 01:17:05 +00:00
|
|
|
int n, len;
|
1997-11-09 14:18:55 +00:00
|
|
|
char line[LINE_LEN];
|
2001-03-08 23:51:50 +00:00
|
|
|
char filename[PATH_MAX];
|
1997-05-10 01:22:19 +00:00
|
|
|
int linenum;
|
1997-11-11 22:58:14 +00:00
|
|
|
int argc;
|
1998-06-15 19:06:25 +00:00
|
|
|
char *argv[MAXARGS];
|
1997-11-11 22:58:14 +00:00
|
|
|
int allowcmd;
|
1998-02-04 01:03:36 +00:00
|
|
|
int indent;
|
|
|
|
char arg[LINE_LEN];
|
1999-09-06 08:16:33 +00:00
|
|
|
struct prompt *op;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-09 17:51:27 +00:00
|
|
|
if (*file == '/')
|
|
|
|
snprintf(filename, sizeof filename, "%s", file);
|
|
|
|
else
|
2001-03-23 11:43:22 +00:00
|
|
|
snprintf(filename, sizeof filename, "%s/%s", PPP_CONFDIR, file);
|
1997-11-09 06:22:49 +00:00
|
|
|
fp = ID0fopen(filename, "r");
|
1995-01-31 06:29:58 +00:00
|
|
|
if (fp == NULL) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogDEBUG, "ReadSystem: Can't open %s.\n", filename);
|
1999-03-09 20:39:03 +00:00
|
|
|
return -2;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogDEBUG, "ReadSystem: Checking %s (%s).\n", name, filename);
|
1997-05-10 01:22:19 +00:00
|
|
|
|
|
|
|
linenum = 0;
|
1998-02-04 01:03:36 +00:00
|
|
|
while ((n = xgets(line, sizeof line, fp))) {
|
|
|
|
linenum += n;
|
|
|
|
if (issep(*line))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cp = strip(line);
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (*cp) {
|
1998-02-04 01:03:36 +00:00
|
|
|
case '\0': /* empty/comment */
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1998-02-04 01:03:36 +00:00
|
|
|
|
|
|
|
case '!':
|
|
|
|
switch (DecodeCtrlCommand(cp+1, arg)) {
|
|
|
|
case CTRL_INCLUDE:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogCOMMAND, "%s: Including \"%s\"\n", filename, arg);
|
1999-02-02 09:35:30 +00:00
|
|
|
n = ReadSystem(bundle, name, arg, prompt, cx, how);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogCOMMAND, "%s: Done include of \"%s\"\n", filename, arg);
|
2000-04-03 19:56:49 +00:00
|
|
|
if (!n) {
|
|
|
|
fclose(fp);
|
1998-02-04 01:03:36 +00:00
|
|
|
return 0; /* got it */
|
2000-04-03 19:56:49 +00:00
|
|
|
}
|
1998-02-04 01:03:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: %s: Invalid command\n", filename, cp);
|
1998-02-04 01:03:36 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1998-02-04 01:03:36 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
default:
|
1999-12-23 21:43:00 +00:00
|
|
|
if ((cp = GetLabel(cp, filename, linenum)) == NULL)
|
|
|
|
continue;
|
1998-02-04 01:03:36 +00:00
|
|
|
|
|
|
|
if (strcmp(cp, name) == 0) {
|
|
|
|
/* We're in business */
|
2000-04-03 19:56:49 +00:00
|
|
|
if (how == SYSTEM_EXISTS) {
|
|
|
|
fclose(fp);
|
1999-02-02 09:35:30 +00:00
|
|
|
return 0;
|
2000-04-03 19:56:49 +00:00
|
|
|
}
|
1998-02-04 01:03:36 +00:00
|
|
|
while ((n = xgets(line, sizeof line, fp))) {
|
|
|
|
linenum += n;
|
|
|
|
indent = issep(*line);
|
|
|
|
cp = strip(line);
|
|
|
|
|
1999-12-23 21:43:00 +00:00
|
|
|
if (*cp == '\0') /* empty / comment */
|
1998-02-04 01:03:36 +00:00
|
|
|
continue;
|
|
|
|
|
1999-12-23 21:43:00 +00:00
|
|
|
if (!indent) { /* start of next section */
|
|
|
|
if (*cp != '!' && how == SYSTEM_EXEC)
|
1999-12-27 11:43:31 +00:00
|
|
|
cp = GetLabel(cp, filename, linenum);
|
1998-02-04 01:03:36 +00:00
|
|
|
break;
|
1998-10-17 12:28:03 +00:00
|
|
|
}
|
1998-02-04 01:03:36 +00:00
|
|
|
|
|
|
|
len = strlen(cp);
|
2000-03-14 01:47:31 +00:00
|
|
|
if ((argc = command_Expand_Interpret(cp, len, argv, cp - line)) < 0)
|
1999-12-20 20:30:02 +00:00
|
|
|
log_Printf(LogWARN, "%s: %d: Syntax error\n", filename, linenum);
|
|
|
|
else {
|
|
|
|
allowcmd = argc > 0 && !strcasecmp(argv[0], "allow");
|
1999-12-20 20:30:30 +00:00
|
|
|
if ((how != SYSTEM_EXEC && allowcmd) ||
|
|
|
|
(how == SYSTEM_EXEC && !allowcmd)) {
|
1999-12-20 20:30:02 +00:00
|
|
|
/*
|
|
|
|
* Disable any context so that warnings are given to everyone,
|
|
|
|
* including syslog.
|
|
|
|
*/
|
|
|
|
op = log_PromptContext;
|
|
|
|
log_PromptContext = NULL;
|
|
|
|
command_Run(bundle, argc, (char const *const *)argv, prompt,
|
|
|
|
name, cx);
|
|
|
|
log_PromptContext = op;
|
|
|
|
}
|
1999-09-06 08:16:33 +00:00
|
|
|
}
|
1997-11-09 17:51:27 +00:00
|
|
|
}
|
1998-02-04 01:03:36 +00:00
|
|
|
|
|
|
|
fclose(fp); /* everything read - get out */
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-10-31 17:38:47 +00:00
|
|
|
const char *
|
1998-05-01 19:26:12 +00:00
|
|
|
system_IsValid(const char *name, struct prompt *prompt, int mode)
|
1997-11-11 22:58:14 +00:00
|
|
|
{
|
1998-02-02 19:32:16 +00:00
|
|
|
/*
|
|
|
|
* Note: The ReadSystem() calls only result in calls to the Allow*
|
|
|
|
* functions. arg->bundle will be set to NULL for these commands !
|
|
|
|
*/
|
1999-03-09 20:39:03 +00:00
|
|
|
int def, how, rs;
|
2000-07-12 23:13:52 +00:00
|
|
|
int defuserok;
|
1998-10-31 17:38:47 +00:00
|
|
|
|
|
|
|
def = !strcmp(name, "default");
|
1999-02-02 09:35:30 +00:00
|
|
|
how = ID0realuid() == 0 ? SYSTEM_EXISTS : SYSTEM_VALIDATE;
|
2000-07-12 23:13:52 +00:00
|
|
|
userok = -1;
|
1997-11-11 22:58:14 +00:00
|
|
|
modeok = 1;
|
1998-04-10 13:19:23 +00:00
|
|
|
modereq = mode;
|
1998-10-31 17:38:47 +00:00
|
|
|
|
1999-03-09 20:39:03 +00:00
|
|
|
rs = ReadSystem(NULL, "default", CONFFILE, prompt, NULL, how);
|
|
|
|
|
2000-07-12 23:13:52 +00:00
|
|
|
defuserok = userok;
|
|
|
|
userok = -1;
|
|
|
|
|
1999-03-09 20:39:03 +00:00
|
|
|
if (!def) {
|
|
|
|
if (rs == -1)
|
|
|
|
rs = 0; /* we don't care that ``default'' doesn't exist */
|
|
|
|
|
|
|
|
if (rs == 0)
|
|
|
|
rs = ReadSystem(NULL, name, CONFFILE, prompt, NULL, how);
|
1999-02-02 09:35:30 +00:00
|
|
|
|
1999-03-09 20:39:03 +00:00
|
|
|
if (rs == -1)
|
|
|
|
return "Configuration label not found";
|
|
|
|
|
|
|
|
if (rs == -2)
|
2001-03-23 11:43:22 +00:00
|
|
|
return PPP_CONFDIR "/" CONFFILE " : File not found";
|
1999-03-09 20:39:03 +00:00
|
|
|
}
|
1998-10-31 17:38:47 +00:00
|
|
|
|
2000-07-12 23:13:52 +00:00
|
|
|
if (userok == -1)
|
|
|
|
userok = defuserok;
|
|
|
|
|
1999-02-02 09:35:30 +00:00
|
|
|
if (how == SYSTEM_EXISTS)
|
|
|
|
userok = modeok = 1;
|
1998-10-31 17:38:47 +00:00
|
|
|
|
|
|
|
if (!userok)
|
1999-02-02 09:35:30 +00:00
|
|
|
return "User access denied";
|
1998-10-31 17:38:47 +00:00
|
|
|
|
|
|
|
if (!modeok)
|
1999-02-02 09:35:30 +00:00
|
|
|
return "Mode denied for this label";
|
1998-10-31 17:38:47 +00:00
|
|
|
|
|
|
|
return NULL;
|
1997-11-11 22:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-05-01 19:26:12 +00:00
|
|
|
system_Select(struct bundle *bundle, const char *name, const char *file,
|
1998-06-15 19:05:51 +00:00
|
|
|
struct prompt *prompt, struct datalink *cx)
|
1997-11-11 22:58:14 +00:00
|
|
|
{
|
|
|
|
userok = modeok = 1;
|
1998-04-10 13:19:23 +00:00
|
|
|
modereq = PHYS_ALL;
|
1999-02-02 09:35:30 +00:00
|
|
|
return ReadSystem(bundle, name, file, prompt, cx, SYSTEM_EXEC);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|