Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 26 additions & 40 deletions pppd/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,14 @@ static int scan_authfile(FILE *, char *, char *, char *,
struct wordlist **, struct wordlist **,
char *);
static void free_wordlist (struct wordlist *);
static void auth_script (char *);
static void auth_script (char *, const char*);
static void auth_script_done (void *);
static void set_allowed_addrs (int, struct wordlist *, struct wordlist *);
static int some_ip_ok (struct wordlist *);
static int setupapfile (char **);
static int privgroup (char **);
static int set_noauth_addr (char **);
static int set_permitted_number (char **);
static void check_access (int, const char *);
static int wordlist_count (struct wordlist *);
static void check_maxoctets (void *);

Expand Down Expand Up @@ -516,6 +515,7 @@ setupapfile(char **argv)
uid_t euid;
char u[MAXNAMELEN], p[MAXSECRETLEN];
char *fname;
int check_res;

lcp_allowoptions[0].neg_upap = 1;

Expand All @@ -530,14 +530,19 @@ setupapfile(char **argv)
return 0;
}
ufile = fopen(fname, "r");
check_res = ufile && ppp_check_access(fileno(ufile), fname, PPP_FT_SECRET);
if (seteuid(euid) == -1)
fatal("unable to regain privileges: %m");
if (ufile == NULL) {
ppp_option_error("unable to open user login data file %s", fname);
free(fname);
return 0;
}
check_access(fileno(ufile), fname);
if (!check_res) {
fclose(ufile);
free(fname);
return 0;
}
uafname = fname;

/* get username */
Expand Down Expand Up @@ -785,7 +790,7 @@ link_down(int unit)
if (auth_script_state == s_up && auth_script_pid == 0) {
ppp_get_link_stats(NULL);
auth_script_state = s_down;
auth_script(path_auth_down);
auth_script(path_auth_down, "auth-up");
}
}
if (!mp_on())
Expand Down Expand Up @@ -933,7 +938,7 @@ network_phase(int unit)
auth_state = s_up;
if (auth_script_state == s_down && auth_script_pid == 0) {
auth_script_state = s_up;
auth_script(path_auth_up);
auth_script(path_auth_up, "auth-up");
}
}

Expand Down Expand Up @@ -1551,12 +1556,11 @@ check_passwd(int unit,
} else {
int fd = fileno(f);

if (!ppp_check_access(fd, filename, 0)) {
if (!ppp_check_access(fd, filename, PPP_FT_SECRET)) {
fclose(f);
ppp_explicit_bzero(passwd, sizeof(passwd));
return UPAP_AUTHNAK;
}
check_access(fd, filename);
if (scan_authfile(f, user, our_name, secret, &addrs, &opts, filename) < 0) {
warn("no PAP secret found for %s", user);
} else {
Expand Down Expand Up @@ -1657,11 +1661,10 @@ null_login(int unit)
if (f == NULL)
return 0;
fd = fileno(f);
if (!ppp_check_access(fd, filename, 0)) {
if (!ppp_check_access(fd, filename, PPP_FT_SECRET)) {
fclose(f);
return 0;
}
check_access(fd, filename);

i = scan_authfile(f, "", our_name, secret, &addrs, &opts, filename);
ret = i >= 0 && secret[0] == 0;
Expand Down Expand Up @@ -1707,7 +1710,10 @@ get_pap_passwd(char *passwd)
f = fopen(filename, "r");
if (f == NULL)
return 0;
check_access(fileno(f), filename);
if (!ppp_check_access(fileno(f), filename, PPP_FT_SECRET)) {
fclose(f);
return 0;
}
ret = scan_authfile(f, user,
(remote_name[0]? remote_name: NULL),
secret, NULL, NULL, filename);
Expand Down Expand Up @@ -1745,7 +1751,7 @@ have_pap_secret(int *lacks_ipp)
if (f == NULL)
return 0;

if (!ppp_check_access(fileno(f), filename, 0)) {
if (!ppp_check_access(fileno(f), filename, PPP_FT_SECRET)) {
fclose(f);
return 0;
}
Expand Down Expand Up @@ -1791,7 +1797,7 @@ have_chap_secret(char *client, char *server,
if (f == NULL)
return 0;

if (!ppp_check_access(fileno(f), filename, 0)) {
if (!ppp_check_access(fileno(f), filename, PPP_FT_SECRET)) {
fclose(f);
return 0;
}
Expand Down Expand Up @@ -1853,11 +1859,10 @@ get_secret(int unit, char *client, char *server,
}

fd = fileno(f);
if (!ppp_check_access(fd, filename, 0)) {
if (!ppp_check_access(fd, filename, PPP_FT_SECRET)) {
fclose(f);
return 0;
}
check_access(fd, filename);

ret = scan_authfile(f, client, server, secbuf, &addrs, &opts, filename);
fclose(f);
Expand Down Expand Up @@ -2133,23 +2138,6 @@ auth_number(void)
return 0;
}

/*
* check_access - complain if a secret file has too-liberal permissions.
*/
static void
check_access(int fd, const char *filename)
{
struct stat sbuf;

if (fstat(fd, &sbuf) < 0) {
warn("cannot stat secret file %s: %m", filename);
} else if ((sbuf.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
warn("Warning - secret file %s has world and/or group access",
filename);
}
}


/*
* scan_authfile - Scan an authorization file for a secret suitable
* for authenticating `client' on `server'. The return value is -1
Expand Down Expand Up @@ -2246,11 +2234,10 @@ scan_authfile(FILE *f, char *client, char *server,
continue;
}
fd = fileno(sf);
if (!ppp_check_access(fd, atfile, 0)) {
if (!ppp_check_access(fd, atfile, PPP_FT_SECRET)) {
fclose(sf);
continue;
}
check_access(fd, atfile);
if (!getword(sf, word, &xxx, atfile)) {
warn("no secret in indirect secret file %s", atfile);
fclose(sf);
Expand Down Expand Up @@ -2358,13 +2345,13 @@ auth_script_done(void *arg)
case s_up:
if (auth_state == s_down) {
auth_script_state = s_down;
auth_script(path_auth_down);
auth_script(path_auth_down, "auth-down");
}
break;
case s_down:
if (auth_state == s_up) {
auth_script_state = s_up;
auth_script(path_auth_up);
auth_script(path_auth_up, "auth-up");
}
break;
}
Expand All @@ -2375,7 +2362,7 @@ auth_script_done(void *arg)
* interface-name peer-name real-user tty speed
*/
static void
auth_script(char *script)
auth_script(char *script, const char* name)
{
char strspeed[32];
struct passwd *pw;
Expand All @@ -2400,7 +2387,7 @@ auth_script(char *script)
argv[6] = ipparam;
argv[7] = NULL;

auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL, 0);
auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL, 0, name);
}


Expand All @@ -2423,7 +2410,7 @@ have_eaptls_secret_server(char *client, char *server,
if (f == NULL)
return 0;

if (!ppp_check_access(fileno(f), filename, 0)) {
if (!ppp_check_access(fileno(f), filename, PPP_FT_SECRET)) {
fclose(f);
return 0;
}
Expand Down Expand Up @@ -2707,11 +2694,10 @@ get_eaptls_secret(int unit, char *client, char *server,
}

fd = fileno(fp);
if (!ppp_check_access(fd, filename, 0)) {
if (!ppp_check_access(fd, filename, PPP_FT_SECRET)) {
fclose(fp);
return 0;
}
check_access(fd, filename);

ret = scan_authfile_eaptls(fp, client, server, clicertfile, servcertfile,
cacertfile, pkfile, &addrs, &opts, filename);
Expand Down
20 changes: 10 additions & 10 deletions pppd/ipcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ struct protent ipcp_protent = {
};

static void ipcp_clear_addrs (int, u_int32_t, u_int32_t);
static void ipcp_script (char *, int); /* Run an up/down script */
static void ipcp_script (char *, int, const char *); /* Run an up/down script */
static void ipcp_script_done (void *);

/*
Expand Down Expand Up @@ -1822,7 +1822,7 @@ ip_demand_conf(int u)
}
if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
return 0;
ipcp_script(path_ippreup, 1);
ipcp_script(path_ippreup, 1, "ip-pre-up");
if (!sifup(u))
return 0;
if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
Expand Down Expand Up @@ -1985,7 +1985,7 @@ ipcp_up(fsm *f)
ifindex = if_nametoindex(ifname);

/* run the pre-up script, if any, and wait for it to finish */
ipcp_script(path_ippreup, 1);
ipcp_script(path_ippreup, 1, "ip-pre-up");

/* check if preup script renamed the interface */
if (!if_indextoname(ifindex, ifname)) {
Expand Down Expand Up @@ -2048,7 +2048,7 @@ ipcp_up(fsm *f)
*/
if (ipcp_script_state == s_down && ipcp_script_pid == 0) {
ipcp_script_state = s_up;
ipcp_script(path_ipup, 0);
ipcp_script(path_ipup, 0, "ip-up");
}
}

Expand Down Expand Up @@ -2097,7 +2097,7 @@ ipcp_down(fsm *f)
/* Execute the ip-down script */
if (ipcp_script_state == s_up && ipcp_script_pid == 0) {
ipcp_script_state = s_down;
ipcp_script(path_ipdown, 0);
ipcp_script(path_ipdown, 0, "ip-down");
}
}

Expand Down Expand Up @@ -2146,13 +2146,13 @@ ipcp_script_done(void *arg)
case s_up:
if (ipcp_fsm[0].state != OPENED) {
ipcp_script_state = s_down;
ipcp_script(path_ipdown, 0);
ipcp_script(path_ipdown, 0, "ip-down");
}
break;
case s_down:
if (ipcp_fsm[0].state == OPENED) {
ipcp_script_state = s_up;
ipcp_script(path_ipup, 0);
ipcp_script(path_ipup, 0, "ip-down");
}
break;
}
Expand All @@ -2164,7 +2164,7 @@ ipcp_script_done(void *arg)
* interface-name tty-name speed local-IP remote-IP.
*/
static void
ipcp_script(char *script, int wait)
ipcp_script(char *script, int wait, const char* name)
{
char strspeed[32], strlocal[32], strremote[32];
char *argv[8];
Expand All @@ -2182,10 +2182,10 @@ ipcp_script(char *script, int wait)
argv[6] = ipparam;
argv[7] = NULL;
if (wait)
run_program(script, argv, 0, NULL, NULL, 1);
run_program(script, argv, 0, NULL, NULL, 1, name);
else
ipcp_script_pid = run_program(script, argv, 0, ipcp_script_done,
NULL, 0);
NULL, 0, name);
}

/*
Expand Down
14 changes: 7 additions & 7 deletions pppd/ipv6cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ struct protent ipv6cp_protent = {
};

static void ipv6cp_clear_addrs (int, eui64_t, eui64_t);
static void ipv6cp_script (char *);
static void ipv6cp_script (char *, const char *);
static void ipv6cp_script_done (void *);

/*
Expand Down Expand Up @@ -1400,7 +1400,7 @@ ipv6cp_up(fsm *f)
*/
if (ipv6cp_script_state == s_down && ipv6cp_script_pid == 0) {
ipv6cp_script_state = s_up;
ipv6cp_script(path_ipv6up);
ipv6cp_script(path_ipv6up, "ipv6-ip");
}
}

Expand Down Expand Up @@ -1451,7 +1451,7 @@ ipv6cp_down(fsm *f)
/* Execute the ipv6-down script */
if (ipv6cp_script_state == s_up && ipv6cp_script_pid == 0) {
ipv6cp_script_state = s_down;
ipv6cp_script(path_ipv6down);
ipv6cp_script(path_ipv6down, "ipv6-down");
}
}

Expand Down Expand Up @@ -1489,13 +1489,13 @@ ipv6cp_script_done(void *arg)
case s_up:
if (ipv6cp_fsm[0].state != OPENED) {
ipv6cp_script_state = s_down;
ipv6cp_script(path_ipv6down);
ipv6cp_script(path_ipv6down, "ipv6-down");
}
break;
case s_down:
if (ipv6cp_fsm[0].state == OPENED) {
ipv6cp_script_state = s_up;
ipv6cp_script(path_ipv6up);
ipv6cp_script(path_ipv6up, "ipv6-up");
}
break;
}
Expand All @@ -1507,7 +1507,7 @@ ipv6cp_script_done(void *arg)
* interface-name tty-name speed local-LL remote-LL.
*/
static void
ipv6cp_script(char *script)
ipv6cp_script(char *script, const char* name)
{
char strspeed[32], strlocal[64], strremote[64];
char *argv[8];
Expand All @@ -1526,7 +1526,7 @@ ipv6cp_script(char *script)
argv[7] = NULL;

ipv6cp_script_pid = run_program(script, argv, 0, ipv6cp_script_done,
NULL, 0);
NULL, 0, name);
}

/*
Expand Down
Loading
Loading