Deleted Added
full compact
systems.c (31068) systems.c (31070)
1/*
2 * System configuration routines
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * System configuration routines
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: systems.c,v 1.19 1997/11/09 06:22:48 brian Exp $
20 * $Id: systems.c,v 1.20 1997/11/09 13:18:18 brian Exp $
21 *
22 * TODO:
23 */
24#include <sys/param.h>
25#include <netinet/in.h>
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
31
32#include "mbuf.h"
33#include "log.h"
34#include "id.h"
35#include "defs.h"
36#include "timer.h"
37#include "fsm.h"
38#include "loadalias.h"
39#include "command.h"
40#include "ipcp.h"
41#include "pathnames.h"
42#include "vars.h"
43#include "server.h"
44#include "systems.h"
45
46FILE *
47OpenSecret(char *file)
48{
49 FILE *fp;
50 char line[100];
51
52 snprintf(line, sizeof line, "%s/%s", _PATH_PPP, file);
53 fp = ID0fopen(line, "r");
54 if (fp == NULL)
55 LogPrintf(LogWARN, "OpenSecret: Can't open %s.\n", line);
56 return (fp);
57}
58
59void
60CloseSecret(FILE * fp)
61{
62 fclose(fp);
63}
64
65int
66SelectSystem(char *name, char *file)
67{
68 FILE *fp;
69 char *cp, *wp;
70 int n, len;
71 u_char olauth;
21 *
22 * TODO:
23 */
24#include <sys/param.h>
25#include <netinet/in.h>
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
31
32#include "mbuf.h"
33#include "log.h"
34#include "id.h"
35#include "defs.h"
36#include "timer.h"
37#include "fsm.h"
38#include "loadalias.h"
39#include "command.h"
40#include "ipcp.h"
41#include "pathnames.h"
42#include "vars.h"
43#include "server.h"
44#include "systems.h"
45
46FILE *
47OpenSecret(char *file)
48{
49 FILE *fp;
50 char line[100];
51
52 snprintf(line, sizeof line, "%s/%s", _PATH_PPP, file);
53 fp = ID0fopen(line, "r");
54 if (fp == NULL)
55 LogPrintf(LogWARN, "OpenSecret: Can't open %s.\n", line);
56 return (fp);
57}
58
59void
60CloseSecret(FILE * fp)
61{
62 fclose(fp);
63}
64
65int
66SelectSystem(char *name, char *file)
67{
68 FILE *fp;
69 char *cp, *wp;
70 int n, len;
71 u_char olauth;
72 char line[200];
72 char line[LINE_LEN];
73 char filename[200];
74 int linenum;
75
76 snprintf(filename, sizeof filename, "%s/%s", _PATH_PPP, file);
77 fp = ID0fopen(filename, "r");
78 if (fp == NULL) {
79 LogPrintf(LogDEBUG, "SelectSystem: Can't open %s.\n", filename);
80 return (-1);
81 }
82 LogPrintf(LogDEBUG, "SelectSystem: Checking %s (%s).\n", name, filename);
83
84 linenum = 0;
85 while (fgets(line, sizeof(line), fp)) {
86 linenum++;
87 cp = line;
88 switch (*cp) {
89 case '#': /* comment */
90 break;
91 case ' ':
92 case '\t':
93 break;
94 default:
95 wp = strpbrk(cp, ":\n");
96 if (wp == NULL) {
97 LogPrintf(LogWARN, "Bad rule in %s (line %d) - missing colon.\n",
98 filename, linenum);
99 ServerClose();
100 exit(1);
101 }
102 *wp = '\0';
103 if (strcmp(cp, name) == 0) {
104 while (fgets(line, sizeof(line), fp)) {
105 cp = line;
106 if (*cp == ' ' || *cp == '\t') {
107 n = strspn(cp, " \t");
108 cp += n;
109 len = strlen(cp);
110 if (!len)
111 continue;
112 if (cp[len-1] == '\n')
113 cp[--len] = '\0';
114 if (!len)
115 continue;
116 LogPrintf(LogCOMMAND, "%s: %s\n", name, cp);
117 olauth = VarLocalAuth;
118 if (VarLocalAuth == LOCAL_NO_AUTH)
119 VarLocalAuth = LOCAL_AUTH;
120 DecodeCommand(cp, len, 0);
121 VarLocalAuth = olauth;
122 } else if (*cp == '#') {
123 continue;
124 } else
125 break;
126 }
127 fclose(fp);
128 return (0);
129 }
130 break;
131 }
132 }
133 fclose(fp);
134 return -1;
135}
136
137int
138LoadCommand(struct cmdtab const * list, int argc, char **argv)
139{
140 char *name;
141
142 if (argc > 0)
143 name = *argv;
144 else
145 name = "default";
146
147 if (SelectSystem(name, CONFFILE) < 0) {
148 LogPrintf(LogWARN, "%s: not found.\n", name);
149 return -1;
150 }
151 return 0;
152}
153
154int
155SaveCommand(struct cmdtab const *list, int argc, char **argv)
156{
157 LogPrintf(LogWARN, "save command is not implemented (yet).\n");
158 return 1;
159}
73 char filename[200];
74 int linenum;
75
76 snprintf(filename, sizeof filename, "%s/%s", _PATH_PPP, file);
77 fp = ID0fopen(filename, "r");
78 if (fp == NULL) {
79 LogPrintf(LogDEBUG, "SelectSystem: Can't open %s.\n", filename);
80 return (-1);
81 }
82 LogPrintf(LogDEBUG, "SelectSystem: Checking %s (%s).\n", name, filename);
83
84 linenum = 0;
85 while (fgets(line, sizeof(line), fp)) {
86 linenum++;
87 cp = line;
88 switch (*cp) {
89 case '#': /* comment */
90 break;
91 case ' ':
92 case '\t':
93 break;
94 default:
95 wp = strpbrk(cp, ":\n");
96 if (wp == NULL) {
97 LogPrintf(LogWARN, "Bad rule in %s (line %d) - missing colon.\n",
98 filename, linenum);
99 ServerClose();
100 exit(1);
101 }
102 *wp = '\0';
103 if (strcmp(cp, name) == 0) {
104 while (fgets(line, sizeof(line), fp)) {
105 cp = line;
106 if (*cp == ' ' || *cp == '\t') {
107 n = strspn(cp, " \t");
108 cp += n;
109 len = strlen(cp);
110 if (!len)
111 continue;
112 if (cp[len-1] == '\n')
113 cp[--len] = '\0';
114 if (!len)
115 continue;
116 LogPrintf(LogCOMMAND, "%s: %s\n", name, cp);
117 olauth = VarLocalAuth;
118 if (VarLocalAuth == LOCAL_NO_AUTH)
119 VarLocalAuth = LOCAL_AUTH;
120 DecodeCommand(cp, len, 0);
121 VarLocalAuth = olauth;
122 } else if (*cp == '#') {
123 continue;
124 } else
125 break;
126 }
127 fclose(fp);
128 return (0);
129 }
130 break;
131 }
132 }
133 fclose(fp);
134 return -1;
135}
136
137int
138LoadCommand(struct cmdtab const * list, int argc, char **argv)
139{
140 char *name;
141
142 if (argc > 0)
143 name = *argv;
144 else
145 name = "default";
146
147 if (SelectSystem(name, CONFFILE) < 0) {
148 LogPrintf(LogWARN, "%s: not found.\n", name);
149 return -1;
150 }
151 return 0;
152}
153
154int
155SaveCommand(struct cmdtab const *list, int argc, char **argv)
156{
157 LogPrintf(LogWARN, "save command is not implemented (yet).\n");
158 return 1;
159}