📄 ppp_port.c
字号:
/* ppp_port.c
* Copyright 2001 By InterNiche Technologies Inc. All rights reserved
*/
#include "ipport.h"
#ifdef USE_PPP /* whole file can be ifdeffed out */
#include "ppp_port.h"
#include "mppp.h"
#include "ip.h"
#include "nvparms.h" /* to access nvparms definition */
#ifdef IN_MENUS
#include "menu.h"
#endif /* IN_MENUS */
#ifdef IN_MENUS
extern int ppp_logfile(void * pio);
extern int ppplogcons(void * pio);
struct menu_op pppmenu[] = {
"ppp", stooges, "PPP Commands",
"pfile", ppp_logfile, "log PPP events to file ppp.log",
"pcons", ppplogcons, "log PPP events to console",
NULL, NULL, NULL,
};
#endif /* IN_MENUS */
/* PPP's Configuration global variables that are initialized later
* on and also read these from NVRAM.
*/
struct PPPCfg pppcfg;
#ifdef INCLUDE_NVPARMS
extern struct nvparm_info ppp_nvformats[];
extern struct nvparm_format ppp_format;
struct ppp_nvparam ppp_nvparms;
#endif /* INCLUDE_NVPARMS */
/* FUNCTION: ppp_setup()
*
* PARAMS: NONE
*
* RETURNS: Error Code or 0 for OK
*/
int ppp_setup(void)
{
int e = 0;
#ifdef IN_MENUS
/* install the PPP commands */
install_menu(&pppmenu[0]);
#endif /* IN_MENUS */
#ifdef INCLUDE_NVPARMS
e = install_nvformat(&ppp_format, nv_formats);
if(e)
{
dprintf("unable to install PPP NVPARMS, reconfigure nv_formats[]\n");
dtrap("ppp_port 0\n");
}
#endif /* INCLUDE_NVPARMS */
return e;
}
#ifdef CHAP_SUPPORT
/* FUNCTION: get_secret()
*
* get_secret() - get the CHAP secret stored in NVRAM. Secret is
* copied to a buffer passed by caller, and length of valid chars is
* put in passed int.
*
*
* PARAM1: int unit IN - unit (ifppp) number
* PARAM2: char * resp_name, IN
* PARAM3: char * rhostname, IN
* PARAM4: char * out_buffer, OUT - buffer to put chap secret in
* PARAM5: int * out_buflen, OUT - length of secret
* PARAM6: int flags IN
*
* RETURNS: Returns TRUE if OK, FALSE if problems
* extracting or copying secret.
*/
int
get_secret(M_PPP mppp, /* IN - PPP link */
char * resp_name, /* IN */
char * rhostname, /* IN */
char * out_buffer, /* OUT - buffer to put chap secret in */
int * out_buflen, /* OUT - length of secret */
int flags)
{
int secret_len;
secret_len = strlen(pppcfg.secret);
if (secret_len >= MAXSECRETLEN)
{
Printu_Net("CHAP error: secret too big.\n");
dtrap("ppp_port 1\n"); /* programming error reading nv file? */
return FALSE;
}
strcpy(out_buffer, pppcfg.secret);
*out_buflen = strlen(pppcfg.secret);
USE_ARG(flags);
USE_ARG(rhostname);
USE_ARG(resp_name);
USE_ARG(mppp);
return TRUE;
}
#endif /* CHAP_SUPPORT */
#ifdef PAP_SUPPORT
/* FUNCTION: check_passwd()
*
* check_passwd() - called from PAP server to check peer-supplied
* username/password. This version just calls the demo package user
* database, you can replace it with something more complex if
* needed.
*
*
* PARAM1: int unit
* PARAM2: char * ruser
* PARAM3: int userlen
* PARAM4: char * rpasswd
* PARAM5: int rpasswdlen
* PARAM6: char ** msg
* PARAM7: int * msglen
*
* RETURNS: Return code of UPAP_AUTHACK if OK, UPAP_AUTHNAK if not.
* msg parms are for return to client.
*/
int
check_passwd(M_PPP mppp, char * ruser, int userlen,
char * rpasswd, int rpasswdlen, char ** msg, int * msglen)
{
int code; /* return code */
char tmp1, tmp2;
USE_ARG(mppp); /* We don;t need the link in this example */
tmp1 = *(ruser + userlen); /* save byte after user name */
*(ruser + userlen) = 0; /* null terminate user name for test */
tmp2 = *(rpasswd + rpasswdlen); /* same with password */
*(rpasswd + rpasswdlen) = 0;
if (check_permit(ruser, rpasswd, PPP_USER, NULL))
{
*msg = "PAP access OK";
*msglen = strlen(*msg);
code = UPAP_AUTHACK;
}
else
{
*msg = "PAP access failed, bad user or password";
*msglen = strlen(*msg);
code = UPAP_AUTHNAK;
}
/* restrore bytes we clobbered */
*(ruser + userlen) = tmp1;
*(rpasswd + rpasswdlen) = tmp2;
return code;
}
#endif /* PAP_SUPPORT */
#ifdef INCLUDE_NVPARMS
/* Please see nvparms.h and nvparms.c regarding the usage of
* the following datatypes and functions.
*/
struct nvparm_info ppp_nvformats[] =
{
{"PPP Console Logging: %s\n", NVBOOL , NVBND_NOOP , \
&ppp_nvparms.ppp_ConsoleLog, NULL, },
{"PPP File Logging: %s\n" , NVBOOL , NVBND_NOOP , \
&ppp_nvparms.ppp_FileLog , NULL, },
{"PPP keepalive: %u\n" , NVUNSHORT, NVBND_NOOP , \
&ppp_nvparms.ppp_keepalive , NULL, },
{"PPP client timeout: %u\n" , NVUNSHORT, NVBND_NOOP , \
&ppp_nvparms.ppp_client_tmo, NULL, },
#ifdef PPP_VJC
{"PPP VJ request: %s\n" , NVBOOL , NVBND_NOOP , \
&ppp_nvparms.ppp_request_vj, NULL, },
#endif /* PPP_VJC */
#ifdef CHAP_SUPPORT
{"CHAP secret: %s\n" , NVSTRING , MAX_NVSTRING, \
&ppp_nvparms.secret[0] , NULL, },
{"require CHAP: %s\n" , NVBOOL , NVBND_NOOP , \
&ppp_nvparms.require_chap , NULL, },
#endif /* CHAP_SUPPORT */
#ifdef PAP_SUPPORT
{"require PAP: %s\n" , NVBOOL , NVBND_NOOP , \
&ppp_nvparms.require_pap , NULL, },
#endif /* PAP_SUPPORT */
{"User Name: %s\n" , NVSTRING , MAX_NVSTRING, \
&ppp_nvparms.username[0] , NULL, },
{"Password: %s\n" , NVSTRING , MAX_NVSTRING, \
&ppp_nvparms.password[0] , NULL, },
{"Idle line timeout: %u\n" , NVUNSHORT, NVBND_NOOP , \
&ppp_nvparms.line_tmo , NULL, },
{"login file: %s\n" , NVSTRING , MAX_NVSTRING, \
&ppp_nvparms.loginfile[0] , NULL, },
{"log server file: %s\n" , NVSTRING , MAX_NVSTRING, \
&ppp_nvparms.logservefile[0], NULL, },
};
#define NUMPPP_FORMATS \
(sizeof(ppp_nvformats)/sizeof(struct nvparm_info))
/* FUNCTION: ppp_nvset()
*
* PARAM1: NV_FILE * fp
*
* RETURNS: Silent return of 0 for OK
*/
int ppp_nvset(NV_FILE * fp)
{
int i = 0;
/* PPP option section: */
nv_fprintf(fp, ppp_nvformats[i++].pattern, \
ppp_nvparms.ppp_ConsoleLog?"YES":"NO");
nv_fprintf(fp, ppp_nvformats[i++].pattern, \
ppp_nvparms.ppp_FileLog?"YES":"NO");
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.ppp_keepalive);
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.ppp_client_tmo);
#ifdef PPP_VJC
nv_fprintf(fp, ppp_nvformats[i++].pattern, \
ppp_nvparms.ppp_request_vj?"YES":"NO");
#endif /* PPP_VJC */
#ifdef CHAP_SUPPORT
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.secret);
nv_fprintf(fp, ppp_nvformats[i++].pattern, \
ppp_nvparms.require_chap?"YES":"NO");
#endif /* CHAP_SUPPORT */
#ifdef PAP_SUPPORT
nv_fprintf(fp, ppp_nvformats[i++].pattern, \
ppp_nvparms.require_pap?"YES":"NO");
#endif /* PAP_SUPPORT */
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.username);
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.password);
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.line_tmo);
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.loginfile);
nv_fprintf(fp, ppp_nvformats[i++].pattern, ppp_nvparms.logservefile);
return 0;
}
struct nvparm_format ppp_format =
{
NUMPPP_FORMATS,
&ppp_nvformats[0],
ppp_nvset,
NULL
};
#endif /* INCLUDE_NVPARMS */
#endif /* USE_PPP - whole file can be ifdeffed out */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -