1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
|
/*
* PPP User command processing module
*
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
*
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the Internet Initiative Japan, Inc. The name of the
* IIJ may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.21 1996/10/07 10:01:17 sos Exp $
*
*/
#include <sys/types.h>
#include <ctype.h>
#include <termios.h>
#include <sys/wait.h>
#include <time.h>
#include "fsm.h"
#include "phase.h"
#include "lcp.h"
#include "ipcp.h"
#include "modem.h"
#include "filter.h"
#include "command.h"
#include "hdlc.h"
#include "vars.h"
#include "auth.h"
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/route.h>
#include "os.h"
#include <paths.h>
extern int MakeArgs();
extern void Cleanup(), TtyTermMode(), PacketMode();
extern int EnableCommand(), DisableCommand(), DisplayCommand();
extern int AcceptCommand(), DenyCommand();
extern int LocalAuthCommand();
extern int LoadCommand(), SaveCommand();
extern int ChangeParity(char *);
extern int SelectSystem();
extern int ShowRoute();
extern void TtyOldMode(), TtyCommandMode();
extern struct pppvars pppVars;
extern struct cmdtab const SetCommands[];
struct in_addr ifnetmask;
static int ShowCommand(), TerminalCommand(), QuitCommand();
static int CloseCommand(), DialCommand(), DownCommand();
static int SetCommand(), AddCommand(), DeleteCommand();
static int ShellCommand();
static int
HelpCommand(list, argc, argv, plist)
struct cmdtab *list;
int argc;
char **argv;
struct cmdtab *plist;
{
struct cmdtab *cmd;
int n;
char c;
if (argc > 0) {
for (cmd = plist; cmd->name; cmd++) {
if (strcmp(cmd->name, *argv) == 0 && (cmd->lauth & VarLocalAuth)) {
if (plist == SetCommands)
printf("set ");
printf("%s %s\n", cmd->name, cmd->syntax);
return(1);
}
}
return(1);
}
n = 0;
for (cmd = plist; cmd->func; cmd++) {
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
c = (n & 1)? '\n' : '\t';
printf(" %-8s: %-20s%c", cmd->name, cmd->helpmes, c);
n++;
}
}
if (n & 1)
printf("\n");
return(1);
}
int
IsInteractive()
{
char *mes = NULL;
if (mode & MODE_AUTO)
mes = "Working in auto mode.";
else if (mode & MODE_DIRECT)
mes = "Working in direct mode.";
else if (mode & MODE_DEDICATED)
mes = "Working in dedicated mode.";
if (mes) {
printf("%s\n", mes);
return(0);
}
return(1);
}
static int
DialCommand(cmdlist, argc, argv)
struct cmdtab *cmdlist;
int argc;
char **argv;
{
int tries;
if (LcpFsm.state > ST_CLOSED) {
printf("LCP state is [%s]\n", StateNames[LcpFsm.state]);
return(1);
}
if (!IsInteractive())
return(1);
if (argc > 0) {
if (SelectSystem(*argv, CONFFILE) < 0) {
printf("%s: not found.\n", *argv);
return(1);
}
}
tries = 0;
do {
printf("Dial attempt %u\n", ++tries);
modem = OpenModem(mode);
if (modem < 0) {
printf("failed to open modem.\n");
modem = 0;
break;
}
if (DialModem()) {
sleep(1);
ModemTimeout();
PacketMode();
break;
}
} while (VarDialTries == 0 || tries < VarDialTries);
return(1);
}
static int
ShellCommand(cmdlist, argc, argv)
struct cmdtab *cmdlist;
int argc;
char **argv;
{
const char *shell;
pid_t shpid;
if((shell = getenv("SHELL")) == 0) {
shell = _PATH_BSHELL;
}
#ifdef SHELL_ONLY_INTERACTIVELY
#ifndef HAVE_SHELL_CMD_WITH_ANY_MODE
if( mode != MODE_INTER) {
fprintf(stdout,
"Can start an shell only in interactive mode\n");
return(1);
}
#else
if(argc == 0 && !(mode & MODE_INTER)) {
fprintf(stderr,
"Can start an interactive shell only in interactive mode\n");
return(1);
}
#endif /* HAVE_SHELL_CMD_WITH_ANY_MODE */
#endif /* SHELL_ONLY_INTERACTIVELY */
if((shpid = fork()) == 0) {
int dtablesize, i ;
for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++)
(void)close(i);
/*
* We are running setuid, we should change to
* real user for avoiding security problems.
*/
if (setgid(getgid()) < 0) {
perror("setgid");
exit(1);
}
if (setuid(getuid()) < 0) {
perror("setuid");
exit(1);
}
TtyOldMode();
if(argc > 0) {
/* substitute pseudo args */
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "HISADDR") == 0) {
argv[i] = strdup(inet_ntoa(IpcpInfo.his_ipaddr));
}
if (strcmp(argv[i], "MYADDR") == 0) {
argv[i] = strdup(inet_ntoa(IpcpInfo.want_ipaddr));
}
}
execvp(argv[0], argv);
}
else
execl(shell, shell, NULL);
fprintf(stdout, "exec() of %s failed\n", argc > 0? argv[0]: shell);
exit(255);
}
if( shpid == (pid_t)-1 ) {
fprintf(stdout, "Fork failed\n");
} else {
int status;
(void)waitpid(shpid, &status, 0);
}
TtyCommandMode(1);
return(0);
}
static char StrOption[] = "option ..";
static char StrRemote[] = "[remote]";
char StrNull[] = "";
struct cmdtab const Commands[] = {
{ "accept", NULL, AcceptCommand, LOCAL_AUTH,
"accept option request", StrOption},
{ "add", NULL, AddCommand, LOCAL_AUTH,
"add route", "dest mask gateway"},
{ "close", NULL, CloseCommand, LOCAL_AUTH,
"Close connection", StrNull},
{ "delete", NULL, DeleteCommand, LOCAL_AUTH,
"delete route", "ALL | dest gateway [mask]"},
{ "deny", NULL, DenyCommand, LOCAL_AUTH,
"Deny option request", StrOption},
{ "dial", "call", DialCommand, LOCAL_AUTH,
"Dial and login", StrRemote},
{ "disable", NULL, DisableCommand, LOCAL_AUTH,
"Disable option", StrOption},
{ "display", NULL, DisplayCommand, LOCAL_AUTH,
"Display option configs", StrNull},
{ "enable", NULL, EnableCommand, LOCAL_AUTH,
"Enable option", StrOption},
{ "passwd", NULL, LocalAuthCommand,LOCAL_NO_AUTH,
"Password for manipulation", StrOption},
{ "load", NULL, LoadCommand, LOCAL_AUTH,
"Load settings", StrRemote},
{ "save", NULL, SaveCommand, LOCAL_AUTH,
"Save settings", StrNull},
{ "set", "setup", SetCommand, LOCAL_AUTH,
"Set parameters", "var value"},
{ "shell", "!", ShellCommand, LOCAL_AUTH,
"Run a subshell", "[sh command]"},
{ "show", NULL, ShowCommand, LOCAL_AUTH,
"Show status and statictics", "var"},
{ "term", NULL, TerminalCommand,LOCAL_AUTH,
"Enter to terminal mode", StrNull},
{ "quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
"Quit PPP program", "[all]"},
{ "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
"Display this message", "[command]", (void *)Commands },
{ NULL, "down", DownCommand, LOCAL_AUTH,
"Generate down event", StrNull},
{ NULL, NULL, NULL },
};
extern int ReportCcpStatus();
extern int ReportLcpStatus();
extern int ReportIpcpStatus();
extern int ReportProtStatus();
extern int ReportCompress();
extern int ShowModemStatus();
extern int ReportHdlcStatus();
extern int ShowMemMap();
static char *LogLevelName[] = {
LM_PHASE, LM_CHAT, LM_LQM, LM_LCP,
LM_TCPIP, LM_HDLC, LM_ASYNC, LM_LINK,
LM_CONNECT, LM_CARRIER,
};
static int ShowDebugLevel()
{
int i;
printf("%02x: ", loglevel);
for (i = LOG_PHASE; i < MAXLOGLEVEL; i++) {
if (loglevel & (1 << i))
printf("%s ", LogLevelName[i]);
}
printf("\n");
return(1);
}
static int ShowEscape()
{
int code, bit;
if (EscMap[32]) {
for (code = 0; code < 32; code++) {
if (EscMap[code]) {
for (bit = 0; bit < 8; bit++) {
if (EscMap[code] & (1<<bit)) {
printf(" 0x%02x", (code << 3) + bit);
}
}
}
}
printf("\n");
}
return(1);
}
static int ShowTimeout()
{
printf(" Idle Timer: %d secs LQR Timer: %d secs Retry Timer: %d secs\n",
VarIdleTimeout, VarLqrTimeout, VarRetryTimeout);
return(1);
}
static int ShowAuthKey()
{
printf("AuthName = %s\n", VarAuthName);
printf("AuthKey = %s\n", VarAuthKey);
return(1);
}
static int ShowVersion()
{
extern char VarVersion[];
extern char VarLocalVersion[];
printf("%s - %s \n", VarVersion, VarLocalVersion);
return(1);
}
static int ShowLogList()
{
ListLog();
return(1);
}
static int ShowRedial()
{
printf(" Redial Timer: ");
if (VarRedialTimeout >= 0) {
printf(" %d seconds, ", VarRedialTimeout);
}
else {
printf(" Random 0 - %d seconds, ", REDIAL_PERIOD);
}
if (VarDialTries)
printf("%d dial tries", VarDialTries);
printf("\n");
return(1);
}
#ifdef MSEXT
static int ShowMSExt()
{
printf(" MS PPP extention values \n" );
printf(" Primary NS : %s\n", inet_ntoa( ns_entries[0] ));
printf(" Secondary NS : %s\n", inet_ntoa( ns_entries[1] ));
printf(" Primary NBNS : %s\n", inet_ntoa( nbns_entries[0] ));
printf(" Secondary NBNS : %s\n", inet_ntoa( nbns_entries[1] ));
return(1);
}
#endif /* MSEXT */
extern int ShowIfilter(), ShowOfilter(), ShowDfilter(), ShowAfilter();
struct cmdtab const ShowCommands[] = {
{ "afilter", NULL, ShowAfilter, LOCAL_AUTH,
"Show keep Alive filters", StrOption},
{ "auth", NULL, ShowAuthKey, LOCAL_AUTH,
"Show auth name/key", StrNull},
{ "ccp", NULL, ReportCcpStatus, LOCAL_AUTH,
"Show CCP status", StrNull},
{ "compress", NULL, ReportCompress, LOCAL_AUTH,
"Show compression statictics", StrNull},
{ "debug", NULL, ShowDebugLevel, LOCAL_AUTH,
"Show current debug level", StrNull},
{ "dfilter", NULL, ShowDfilter, LOCAL_AUTH,
"Show Demand filters", StrOption},
{ "escape", NULL, ShowEscape, LOCAL_AUTH,
"Show escape characters", StrNull},
{ "hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH,
"Show HDLC error summary", StrNull},
{ "ifilter", NULL, ShowIfilter, LOCAL_AUTH,
"Show Input filters", StrOption},
{ "ipcp", NULL, ReportIpcpStatus, LOCAL_AUTH,
"Show IPCP status", StrNull},
{ "lcp", NULL, ReportLcpStatus, LOCAL_AUTH,
"Show LCP status", StrNull},
{ "log", NULL, ShowLogList, LOCAL_AUTH,
"Show log records", StrNull},
{ "mem", NULL, ShowMemMap, LOCAL_AUTH,
"Show memory map", StrNull},
{ "modem", NULL, ShowModemStatus, LOCAL_AUTH,
"Show modem setups", StrNull},
{ "ofilter", NULL, ShowOfilter, LOCAL_AUTH,
"Show Output filters", StrOption},
{ "proto", NULL, ReportProtStatus, LOCAL_AUTH,
"Show protocol summary", StrNull},
{ "route", NULL, ShowRoute, LOCAL_AUTH,
"Show routing table", StrNull},
{ "timeout", NULL, ShowTimeout, LOCAL_AUTH,
"Show Idle timeout value", StrNull},
{ "redial", NULL, ShowRedial, LOCAL_AUTH,
"Show Redial timeout value", StrNull},
#ifdef MSEXT
{ "msext", NULL, ShowMSExt, LOCAL_AUTH,
"Show MS PPP extention values", StrNull},
#endif /* MSEXT */
{ "version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH,
"Show version string", StrNull},
{ "help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH,
"Display this message", StrNull, (void *)ShowCommands},
{ NULL, NULL, NULL },
};
struct cmdtab *
FindCommand(cmds, str, pmatch)
struct cmdtab *cmds;
char *str;
int *pmatch;
{
int nmatch = 0;
int len = strlen(str);
struct cmdtab *found = NULL;
while (cmds->func) {
if (cmds->name && strncmp(str, cmds->name, len) == 0) {
nmatch++;
found = cmds;
} else if (cmds->alias && strncmp(str, cmds->alias, len) == 0) {
nmatch++;
found = cmds;
}
cmds++;
}
*pmatch = nmatch;
return(found);
}
int
FindExec(cmdlist, argc, argv)
struct cmdtab *cmdlist;
int argc;
char **argv;
{
struct cmdtab *cmd;
int val = 1;
int nmatch;
cmd = FindCommand(cmdlist, *argv, &nmatch);
if (nmatch > 1)
printf("Ambiguous.\n");
else if (cmd && ( cmd->lauth & VarLocalAuth ) )
val = (cmd->func)(cmd, --argc, ++argv, cmd->args);
else
printf("what?\n");
return(val);
}
void
Prompt(flag)
int flag;
{
char *pconnect, *pauth;
if (!(mode & MODE_INTER))
return;
if (flag) printf("\n");
if ( VarLocalAuth == LOCAL_AUTH )
pauth = " ON ";
else
pauth = " on ";
if (IpcpFsm.state == ST_OPENED && phase == PHASE_NETWORK)
pconnect = "PPP";
else
pconnect = "ppp";
printf("%s%s%s> ", pconnect, pauth, VarShortHost);
fflush(stdout);
}
void
DecodeCommand(buff, nb, prompt)
char *buff;
int nb;
int prompt;
{
char *vector[20];
char **argv;
int argc, val;
char *cp;
val = 1;
if (nb > 0) {
cp = buff + strcspn(buff, "\r\n");
if (cp)
*cp = '\0';
{
argc = MakeArgs(buff, &vector);
argv = vector;
if (argc > 0)
val = FindExec(Commands, argc, argv);
}
}
if (val && prompt)
Prompt(0);
}
static int
ShowCommand(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int val = 1;
if (argc > 0)
val = FindExec(ShowCommands, argc, argv);
else
printf("Use ``show ?'' to get a list.\n");
return(val);
}
static int
TerminalCommand()
{
if (LcpFsm.state > ST_CLOSED) {
printf("LCP state is [%s]\n", StateNames[LcpFsm.state]);
return(1);
}
if (!IsInteractive())
return(1);
modem = OpenModem(mode);
if (modem < 0) {
printf("failed to open modem.\n");
modem = 0;
return(1);
}
printf("Enter to terminal mode.\n");
printf("Type `~?' for help.\n");
TtyTermMode();
return(0);
}
static int
QuitCommand(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
if (mode & (MODE_DIRECT|MODE_DEDICATED|MODE_AUTO)) {
if (argc > 0 && (VarLocalAuth & LOCAL_AUTH)) {
Cleanup(EX_NORMAL);
} else {
VarLocalAuth = LOCAL_NO_AUTH;
close(netfd);
close(1);
dup2(2, 1); /* Have to have something here or the modem will be 1 */
netfd = -1;
mode &= ~MODE_INTER;
}
} else
Cleanup(EX_NORMAL);
return(1);
}
static int
CloseCommand()
{
LcpClose();
return(1);
}
static int
DownCommand()
{
LcpDown();
return(1);
}
static int SetModemSpeed(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int speed;
if (argc > 0) {
if (strcmp(*argv, "sync") == 0) {
VarSpeed = 0;
return(1);
}
speed = atoi(*argv);
if (IntToSpeed(speed) != B0) {
VarSpeed = speed;
return(1);
}
printf("invalid speed.\n");
}
return(1);
}
static int SetRedialTimeout(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int timeout;
int tries;
if (argc == 1 || argc == 2 ) {
if (strcasecmp(argv[0], "random") == 0) {
VarRedialTimeout = -1;
printf("Using random redial timeout.\n");
srandom(time(0));
}
else {
timeout = atoi(argv[0]);
if (timeout >= 0) {
VarRedialTimeout = timeout;
}
else {
printf("invalid redial timeout\n");
printf("Usage: %s %s\n", list->name, list->syntax);
}
}
if (argc == 2) {
tries = atoi(argv[1]);
if (tries >= 0) {
VarDialTries = tries;
}
else {
printf("invalid retry value\n");
printf("Usage: %s %s\n", list->name, list->syntax);
}
}
}
else {
printf("Usage: %s %s\n", list->name, list->syntax);
}
return(1);
}
static int SetModemParity(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int parity;
if (argc > 0) {
parity = ChangeParity(*argv);
if (parity < 0)
printf("Invalid parity.\n");
else
VarParity = parity;
}
return(1);
}
static int
SetDebugLevel(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int level, w;
for (level = 0; argc-- > 0; argv++) {
if (isdigit(**argv)) {
w = atoi(*argv);
if (w < 0 || w >= MAXLOGLEVEL) {
printf("invalid log level.\n");
break;
} else
level |= (1 << w);
} else {
for (w = 0; w < MAXLOGLEVEL; w++) {
if (strcasecmp(*argv, LogLevelName[w]) == 0) {
level |= (1 << w);
continue;
}
}
}
}
loglevel = level;
return(1);
}
static int
SetEscape(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int code;
for (code = 0; code < 33; code++)
EscMap[code] = 0;
while (argc-- > 0) {
sscanf(*argv++, "%x", &code);
code &= 0xff;
EscMap[code >> 3] |= (1 << (code&7));
EscMap[32] = 1;
}
return(1);
}
static int
SetInitialMRU(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int mru;
if (argc > 0) {
mru = atoi(*argv);
if (mru < 100)
printf("given value is too small.\n");
else if (mru > MAX_MRU)
printf("given value is too big.\n");
else
VarMRU = mru;
}
return(1);
}
static int
SetIdleTimeout(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
if (argc-- > 0) {
VarIdleTimeout = atoi(*argv++);
if (argc-- > 0) {
VarLqrTimeout = atoi(*argv++);
if (VarLqrTimeout < 1)
VarLqrTimeout = 30;
if (argc > 0) {
VarRetryTimeout = atoi(*argv);
if (VarRetryTimeout < 1 || VarRetryTimeout > 10)
VarRetryTimeout = 3;
}
}
}
return(1);
}
struct in_addr
GetIpAddr(cp)
char *cp;
{
struct hostent *hp;
struct in_addr ipaddr;
hp = gethostbyname(cp);
if (hp && hp->h_addrtype == AF_INET)
bcopy(hp->h_addr, &ipaddr, hp->h_length);
else if (inet_aton(cp, &ipaddr) == 0)
ipaddr.s_addr = 0;
return(ipaddr);
}
static int
SetInterfaceAddr(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
DefMyAddress.ipaddr.s_addr = DefHisAddress.ipaddr.s_addr = 0L;
if (argc > 0) {
ParseAddr(argc, argv++,
&DefMyAddress.ipaddr, &DefMyAddress.mask, &DefMyAddress.width);
if (--argc > 0) {
ParseAddr(argc, argv++,
&DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width);
if (--argc > 0) {
ifnetmask = GetIpAddr(*argv);
if (--argc > 0) {
ParseAddr(argc, argv++,
&DefTriggerAddress.ipaddr,
&DefTriggerAddress.mask,
&DefTriggerAddress.width);
}
}
}
}
/*
* For backwards compatibility, 0.0.0.0 means any address.
*/
if (DefMyAddress.ipaddr.s_addr == 0) {
DefMyAddress.mask.s_addr = 0;
DefMyAddress.width = 0;
}
if (DefHisAddress.ipaddr.s_addr == 0) {
DefHisAddress.mask.s_addr = 0;
DefHisAddress.width = 0;
}
if ((mode & MODE_AUTO) ||
((mode & MODE_DEDICATED) && dstsystem)) {
OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask);
}
return(1);
}
#ifdef MSEXT
void
SetMSEXT(pri_addr, sec_addr, argc, argv)
struct in_addr *pri_addr;
struct in_addr *sec_addr;
int argc;
char **argv;
{
int dummyint;
struct in_addr dummyaddr;
pri_addr->s_addr = sec_addr->s_addr = 0L;
if( argc > 0 ) {
ParseAddr(argc, argv++, pri_addr, &dummyaddr, &dummyint);
if( --argc > 0 )
ParseAddr(argc, argv++, sec_addr, &dummyaddr, &dummyint);
else
sec_addr->s_addr = pri_addr->s_addr;
}
/*
* if the primary/secondary ns entries are 0.0.0.0 we should
* set them to either the localhost's ip, or the values in
* /etc/resolv.conf ??
*
* up to you if you want to implement this...
*/
}
static int
SetNS(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
SetMSEXT(&ns_entries[0], &ns_entries[1], argc, argv);
return(1);
}
static int
SetNBNS(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
SetMSEXT(&nbns_entries[0], &nbns_entries[1], argc, argv);
return(1);
}
#endif /* MS_EXT */
#define VAR_AUTHKEY 0
#define VAR_DIAL 1
#define VAR_LOGIN 2
#define VAR_AUTHNAME 3
#define VAR_DEVICE 4
#define VAR_ACCMAP 5
#define VAR_PHONE 6
static int
SetVariable(list, argc, argv, param)
struct cmdtab *list;
int argc;
char **argv;
int param;
{
u_long map;
if (argc > 0) {
switch (param) {
case VAR_AUTHKEY:
strncpy(VarAuthKey, *argv, sizeof(VarAuthKey)-1);
break;
case VAR_AUTHNAME:
strncpy(VarAuthName, *argv, sizeof(VarAuthName)-1);
break;
case VAR_DIAL:
strncpy(VarDialScript, *argv, sizeof(VarDialScript)-1);
break;
case VAR_LOGIN:
strncpy(VarLoginScript, *argv, sizeof(VarDialScript)-1);
break;
case VAR_DEVICE:
strncpy(VarDevice, *argv, sizeof(VarDevice)-1);
break;
case VAR_ACCMAP:
sscanf(*argv, "%lx", &map);
VarAccmap = map;
break;
case VAR_PHONE:
strncpy(VarPhoneList, *argv, sizeof(VarPhoneList)-1);
strcpy(VarPhoneCopy, VarPhoneList);
VarNextPhone = VarPhoneCopy;
break;
}
}
return(1);
}
static int SetOpenMode(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
if (argc > 0) {
if (strcmp(*argv, "active") == 0)
VarOpenMode = OPEN_ACTIVE;
else if (strcmp(*argv, "passive") == 0)
VarOpenMode = OPEN_PASSIVE;
else
printf("Invalid mode.\n");
}
return(1);
}
static char StrChatStr[] = "chat-script";
static char StrValue[] = "value";
extern int SetIfilter(), SetOfilter(), SetDfilter(), SetAfilter();
struct cmdtab const SetCommands[] = {
{ "accmap", NULL, SetVariable, LOCAL_AUTH,
"Set accmap value", "hex-value", (void *)VAR_ACCMAP},
{ "afilter", NULL, SetAfilter, LOCAL_AUTH,
"Set keep Alive filter", "..."},
{ "authkey", "key", SetVariable, LOCAL_AUTH,
"Set authentication key", "key", (void *)VAR_AUTHKEY},
{ "authname", NULL, SetVariable, LOCAL_AUTH,
"Set authentication name", "name", (void *)VAR_AUTHNAME},
{ "debug", NULL, SetDebugLevel, LOCAL_AUTH,
"Set debug level", StrValue},
{ "device", "line", SetVariable, LOCAL_AUTH,
"Set modem device name", "device-name", (void *)VAR_DEVICE},
{ "dfilter", NULL, SetDfilter, LOCAL_AUTH,
"Set demand filter", "..."},
{ "dial", NULL, SetVariable, LOCAL_AUTH,
"Set dialing script", StrChatStr, (void *)VAR_DIAL},
{ "escape", NULL, SetEscape, LOCAL_AUTH,
"Set escape characters", "hex-digit ..."},
{ "ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH,
"Set destination address", "[src-addr [dst-addr [netmask [trg-addr]]]]"},
{ "ifilter", NULL, SetIfilter, LOCAL_AUTH,
"Set input filter", "..."},
{ "login", NULL, SetVariable, LOCAL_AUTH,
"Set login script", StrChatStr, (void *)VAR_LOGIN },
{ "mru", "mtu", SetInitialMRU, LOCAL_AUTH,
"Set Initial MRU value", StrValue },
{ "ofilter", NULL, SetOfilter, LOCAL_AUTH,
"Set output filter", "..." },
{ "openmode", NULL, SetOpenMode, LOCAL_AUTH,
"Set open mode", "[active|passive]"},
{ "parity", NULL, SetModemParity, LOCAL_AUTH,
"Set modem parity", "[odd|even|none]"},
{ "phone", NULL, SetVariable, LOCAL_AUTH,
"Set telephone number(s)", "phone1[:phone2[...]]", (void *)VAR_PHONE },
{ "speed", NULL, SetModemSpeed, LOCAL_AUTH,
"Set modem speed", "speed"},
{ "timeout", NULL, SetIdleTimeout, LOCAL_AUTH,
"Set Idle timeout", StrValue},
{ "redial", NULL, SetRedialTimeout, LOCAL_AUTH,
"Set Redial timeout", "value|random [dial_attempts]"},
#ifdef MSEXT
{ "ns", NULL, SetNS, LOCAL_AUTH,
"Set NameServer", "pri-addr [sec-addr]"},
{ "nbns", NULL, SetNBNS, LOCAL_AUTH,
"Set NetBIOS NameServer", "pri-addr [sec-addr]"},
#endif /* MSEXT */
{ "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
"Display this message", StrNull, (void *)SetCommands},
{ NULL, NULL, NULL },
};
static int
SetCommand(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
int val = 1;
if (argc > 0)
val = FindExec(SetCommands, argc, argv);
else
printf("Use `set ?' to get a list or `set ? <var>' for syntax help.\n");
return(val);
}
static int
AddCommand(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
struct in_addr dest, gateway, netmask;
if (argc == 3) {
dest = GetIpAddr(argv[0]);
netmask = GetIpAddr(argv[1]);
if (strcmp(argv[2], "HISADDR") == 0)
gateway = IpcpInfo.his_ipaddr;
else
gateway = GetIpAddr(argv[2]);
OsSetRoute(RTM_ADD, dest, gateway, netmask);
} else {
printf("Usage: %s %s\n", list->name, list->syntax);
}
return(1);
}
static int
DeleteCommand(list, argc, argv)
struct cmdtab *list;
int argc;
char **argv;
{
struct in_addr dest, gateway, netmask;
if (argc >= 2) {
dest = GetIpAddr(argv[0]);
if (strcmp(argv[1], "HISADDR") == 0)
gateway = IpcpInfo.his_ipaddr;
else
gateway = GetIpAddr(argv[1]);
netmask.s_addr = 0;
if (argc == 3) {
if (inet_aton(argv[1], &netmask) == 0) {
printf("bad netmask value.\n");
return(1);
}
}
OsSetRoute(RTM_DELETE, dest, gateway, netmask);
} else if (argc == 1 && strcmp(argv[0], "ALL") == 0) {
DeleteIfRoutes(0);
} else {
printf("Usage: %s %s\n", list->name, list->syntax);
}
return(1);
}
|