On 04/01/18(Thu) 12:30, Stuart Henderson wrote:
> On 2018/01/04 12:47, Martin Pieuchot wrote:
> [...] 
> >                 So I don't understand why I have to pass '-K' in
> > every of the machine I setup.  If I don't specify any policy file, then
> > I'd assume isakmpd(8) would do the right thing.
> > 
> > Diff below makes '-K' the default if isakmpd.policy doesn't exist AND
> > you didn't specify a "Policy-file".
> 
> I have to say I'm not too keen on this. At the moment -K is "danger!
> flows are not checked against policy".

In that case could we check for the policy/-K flag before forking?
Currently isakmpd fails silently if I forgot one of the two.  With the
diff below if will correctly display: isakmpd(failed).

ok?

Index: isakmpd.c
===================================================================
RCS file: /cvs/src/sbin/isakmpd/isakmpd.c,v
retrieving revision 1.107
diff -u -p -r1.107 isakmpd.c
--- isakmpd.c   15 Jan 2018 09:54:48 -0000      1.107
+++ isakmpd.c   15 Jan 2018 10:08:31 -0000
@@ -395,6 +395,9 @@ main(int argc, char *argv[])
 
        closefrom(STDERR_FILENO + 1);
 
+       /* Check if policies are correct before forking. */
+       policy_check();
+
        /*
         * Make sure init() won't alloc fd 0, 1 or 2, as daemon() will close
         * them.
Index: policy.c
===================================================================
RCS file: /cvs/src/sbin/isakmpd/policy.c,v
retrieving revision 1.99
diff -u -p -r1.99 policy.c
--- policy.c    15 Jan 2018 09:54:48 -0000      1.99
+++ policy.c    15 Jan 2018 10:08:31 -0000
@@ -1921,6 +1921,35 @@ bad:
 }
 
 void
+policy_check(void)
+{
+       char            *policy_file;
+       int              fd;
+
+       /* Do we want to use the policy modules?  */
+       if (ignore_policy ||
+           strncmp("yes", conf_get_str("General", "Use-Keynote"), 3))
+               return;
+
+       /* Get policy file from configuration.  */
+       policy_file = conf_get_str("General", "Policy-file");
+
+       /* Open policy file.  */
+       fd = monitor_open(policy_file, O_RDONLY, 0);
+       if (fd == -1)
+               log_fatal("%s: open (\"%s\", O_RDONLY) failed", __func__,
+                   policy_file);
+
+       /* Check file modes */
+       if (check_file_secrecy_fd(fd, policy_file, NULL)) {
+               close(fd);
+               log_fatal("%s: cannot read %s", __func__, policy_file);
+       }
+
+       close(fd);
+}
+
+void
 policy_init(void)
 {
        char           *ptr, *policy_file;
@@ -1937,8 +1966,6 @@ policy_init(void)
 
        /* Get policy file from configuration.  */
        policy_file = conf_get_str("General", "Policy-file");
-       if (!policy_file)
-               policy_file = CONF_DFLT_POLICY_FILE;
 
        /* Open policy file.  */
        fd = monitor_open(policy_file, O_RDONLY, 0);
Index: policy.h
===================================================================
RCS file: /cvs/src/sbin/isakmpd/policy.h,v
retrieving revision 1.17
diff -u -p -r1.17 policy.h
--- policy.h    5 Aug 2007 09:43:09 -0000       1.17
+++ policy.h    15 Jan 2018 10:08:31 -0000
@@ -46,6 +46,7 @@ extern struct exchange *policy_exchange;
 extern struct sa *policy_sa;
 extern struct sa *policy_isakmp_sa;
 
+extern void     policy_check(void);
 extern void     policy_init(void);
 extern char    *policy_callback(char *);
 extern int      keynote_cert_init(void);

Reply via email to