diff options
author | brian <brian@FreeBSD.org> | 1997-05-10 01:22:19 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-05-10 01:22:19 +0000 |
commit | 82bac13560d095243e9988bfb770da73089749c1 (patch) | |
tree | 262cfd051516c08f29f6f133a950e9de9f2d42fd /usr.sbin/ppp/systems.c | |
parent | 1da867bda76bc701006945dfbc4733f550c91c2d (diff) | |
download | FreeBSD-src-82bac13560d095243e9988bfb770da73089749c1.zip FreeBSD-src-82bac13560d095243e9988bfb770da73089749c1.tar.gz |
Tidy up the code - bounds checking, return
value checking etc.
Submitted by: eivind
Diffstat (limited to 'usr.sbin/ppp/systems.c')
-rw-r--r-- | usr.sbin/ppp/systems.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/usr.sbin/ppp/systems.c b/usr.sbin/ppp/systems.c index 0e7be24..dc59e3c 100644 --- a/usr.sbin/ppp/systems.c +++ b/usr.sbin/ppp/systems.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: systems.c,v 1.9 1997/02/22 16:10:56 peter Exp $ * * TODO: */ @@ -47,8 +47,14 @@ static void SetUserId() { if (!usermode) { - setreuid(euid, uid); - setregid(egid, gid); + if (setreuid(euid, uid) == -1) { + logprintf("unable to setreuid!\n"); + exit(1); + } + if (setregid(egid, gid) == -1) { + logprintf("unable to setregid!\n"); + exit(1); + } usermode = 1; } } @@ -57,8 +63,14 @@ static void SetPppId() { if (usermode) { - setreuid(uid, euid); - setregid(gid, egid); + if (setreuid(uid, euid) == -1) { + logprintf("unable to setreuid!\n"); + exit(1); + } + if (setregid(gid, egid) == -1) { + logprintf("unable to setregid!\n"); + exit(1); + } usermode = 0; } } @@ -110,30 +122,35 @@ char *file; int val = -1; u_char olauth; char line[200]; + char filename[200]; + int linenum; fp = NULL; cp = getenv("HOME"); if (cp) { SetUserId(); - snprintf(line, sizeof line, "%s/.%s", cp, file); - fp = fopen(line, "r"); + snprintf(filename, sizeof filename, "%s/.%s", cp, file); + fp = fopen(filename, "r"); } if (fp == NULL) { SetPppId(); /* fix from pdp@ark.jr3uom.iijnet.or.jp */ - snprintf(line, sizeof line, "%s/%s", _PATH_PPP, file); - fp = fopen(line, "r"); + snprintf(filename, sizeof filename, "%s/%s", _PATH_PPP, file); + fp = fopen(filename, "r"); } if (fp == NULL) { #ifdef DEBUG - fprintf(stderr, "can't open %s.\n", line); + fprintf(stderr, "can't open %s.\n", filename); #endif SetPppId(); return(-1); } #ifdef DEBUG - fprintf(stderr, "checking %s (%s).\n", name, line); + fprintf(stderr, "checking %s (%s).\n", name, filename); #endif + + linenum = 0; while (fgets(line, sizeof(line), fp)) { + linenum++; cp = line; switch (*cp) { case '#': /* comment */ @@ -143,6 +160,11 @@ char *file; break; default: wp = strpbrk(cp, ":\n"); + if (wp == NULL) { + fprintf(stderr, "Bad rule in %s (line %d) - missing colon.\n", + filename, linenum); + exit(1); + } *wp = '\0'; if (strcmp(cp, name) == 0) { while (fgets(line, sizeof(line), fp)) { @@ -196,8 +218,6 @@ char **argv; return(1); } -extern struct in_addr ifnetmask; - int SaveCommand(list, argc, argv) struct cmdtab *list; |