* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define RCSID "$Id: options.c,v 1.94 2004/11/04 09:46:50 paulus Exp $"
+#define RCSID "$Id: options.c,v 1.100 2006/06/18 11:26:00 paulus Exp $"
#include <ctype.h>
#include <stdio.h>
#ifdef PPP_FILTER
#include <pcap.h>
/*
- * DLT_PPP_WITH_DIRECTION is in current libpcap cvs, and should be in
- * libpcap-0.8.4. Until that is released, use DLT_PPP - but that means
+ * There have been 3 or 4 different names for this in libpcap CVS, but
+ * this seems to be what they have settled on...
+ * For older versions of libpcap, use DLT_PPP - but that means
* we lose the inbound and outbound qualifiers.
*/
-#ifndef DLT_PPP_WITH_DIRECTION
-#define DLT_PPP_WITH_DIRECTION DLT_PPP
+#ifndef DLT_PPP_PPPD
+#ifdef DLT_PPP_WITHDIRECTION
+#define DLT_PPP_PPPD DLT_PPP_WITHDIRECTION
+#else
+#define DLT_PPP_PPPD DLT_PPP
#endif
#endif
+#endif /* PPP_FILTER */
#include "pppd.h"
#include "pathnames.h"
OPT_PRIOSUB | OPT_A2CLR | 1, &nodetach },
{ "holdoff", o_int, &holdoff,
- "Set time in seconds before retrying connection", OPT_PRIO },
+ "Set time in seconds before retrying connection",
+ OPT_PRIO, &holdoff_specified },
{ "idle", o_int, &idle_time_limit,
"Set time in seconds before disconnecting idle link", OPT_PRIO },
"Stop after parsing, printing, and checking options", 1 },
{ "child-timeout", o_int, &child_wait,
- "Number of seconds to wait for child processes at exit" },
+ "Number of seconds to wait for child processes at exit",
+ OPT_PRIO },
#ifdef HAVE_MULTILINK
{ "multilink", o_bool, &multilink,
#endif
#ifdef PPP_FILTER
- { "pass-filter", 1, setpassfilter,
+ { "pass-filter", o_special, setpassfilter,
"set filter for packets to pass", OPT_PRIO },
- { "active-filter", 1, setactivefilter,
+ { "active-filter", o_special, setactivefilter,
"set filter for active pkts", OPT_PRIO },
#endif
option_t *opt;
int oldpriv, n;
char *oldsource;
+ uid_t euid;
char *argv[MAXARGS];
char args[MAXARGS][MAXWORDLEN];
char cmd[MAXWORDLEN];
- if (check_prot)
- seteuid(getuid());
+ euid = geteuid();
+ if (check_prot && seteuid(getuid()) == -1) {
+ option_error("unable to drop privileges to open %s: %m", filename);
+ return 0;
+ }
f = fopen(filename, "r");
err = errno;
- if (check_prot)
- seteuid(0);
+ if (check_prot && seteuid(euid) == -1)
+ fatal("unable to regain privileges");
if (f == NULL) {
errno = err;
if (!must_exist) {
char **argv;
{
pcap_t *pc;
- int ret = 0;
+ int ret = 1;
- pc = pcap_open_dead(DLT_PPP_WITH_DIRECTION, 65535);
+ pc = pcap_open_dead(DLT_PPP_PPPD, 65535);
if (pcap_compile(pc, &pass_filter, *argv, 1, netmask) == -1) {
option_error("error in pass-filter expression: %s\n",
pcap_geterr(pc));
- ret = 1;
+ ret = 0;
}
pcap_close(pc);
char **argv;
{
pcap_t *pc;
- int ret = 0;
+ int ret = 1;
- pc = pcap_open_dead(DLT_PPP_WITH_DIRECTION, 65535);
+ pc = pcap_open_dead(DLT_PPP_PPPD, 65535);
if (pcap_compile(pc, &active_filter, *argv, 1, netmask) == -1) {
option_error("error in active-filter expression: %s\n",
pcap_geterr(pc));
- ret = 1;
+ ret = 0;
}
pcap_close(pc);
char **argv;
{
int fd, err;
+ uid_t euid;
- if (!privileged_option)
- seteuid(getuid());
+ euid = geteuid();
+ if (!privileged_option && seteuid(getuid()) == -1) {
+ option_error("unable to drop permissions to open %s: %m", *argv);
+ return 0;
+ }
fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
if (fd < 0 && errno == EEXIST)
fd = open(*argv, O_WRONLY | O_APPEND);
err = errno;
- if (!privileged_option)
- seteuid(0);
+ if (!privileged_option && seteuid(euid) == -1)
+ fatal("unable to regain privileges: %m");
if (fd < 0) {
errno = err;
option_error("Can't open log file %s: %m", *argv);