summaryrefslogtreecommitdiff
path: root/src/startup.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2024-11-07 18:02:08 +0000
committerGitHub <noreply@github.com>2024-11-07 18:02:08 +0000
commit196fdd7fdf6dcf751b7364c59e34278bfd0193e3 (patch)
treecfeff0991481c8281e24cf1698b20a76854059a4 /src/startup.ml
parentdd9271b4304c6b1a5a2576821d1b2b8fd3aa6bf5 (diff)
parent9b90d3cc4da72c13ef4270150e4b547ff03fc813 (diff)
downloadvyconf-196fdd7fdf6dcf751b7364c59e34278bfd0193e3.tar.gz
vyconf-196fdd7fdf6dcf751b7364c59e34278bfd0193e3.zip
Merge pull request #11 from jestabro/vyconf-minimal
T6718: use the vyconf daemon for validation of set commands
Diffstat (limited to 'src/startup.ml')
-rw-r--r--src/startup.ml36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/startup.ml b/src/startup.ml
index cea5f02..db0d719 100644
--- a/src/startup.ml
+++ b/src/startup.ml
@@ -33,7 +33,7 @@ let setup_logger daemonize log_file template =
(** Load the config file or panic if it fails *)
let load_daemon_config path =
- let result = Vyconf_config.load path in
+ let result = Vyconfd_config.Vyconf_config.load path in
match result with
| Ok cfg -> cfg
| Error err ->
@@ -41,7 +41,13 @@ let load_daemon_config path =
(** Check if appliance directories exist and panic if they don't *)
let check_dirs dirs =
- let res = Directories.test dirs in
+ let res = Vyconfd_config.Directories.test dirs in
+ match res with
+ | Ok _ -> ()
+ | Error err -> panic err
+
+let check_validators_dir dirs =
+ let res = Vyconfd_config.Directories.test_validators_dir dirs in
match res with
| Ok _ -> ()
| Error err -> panic err
@@ -61,6 +67,7 @@ let create_socket sockfile =
let backlog = 10 in
let%lwt sock = socket PF_UNIX SOCK_STREAM 0 |> Lwt.return in
let%lwt () = Lwt_unix.bind sock @@ ADDR_UNIX(sockfile) in
+ let%lwt () = Lwt_unix.chmod sockfile 0o775 in
listen sock backlog;
Lwt.return sock
@@ -75,11 +82,21 @@ let create_server accept_connection sock =
let load_config file =
try
let chan = open_in file in
- let config = Curly_parser.config Curly_lexer.token (Lexing.from_channel chan) in
+ let s = really_input_string chan (in_channel_length chan) in
+ let config = Vyos1x.Parser.from_string s in
Ok config
with
| Sys_error msg -> Error msg
- | Curly_parser.Error -> Error "Parse error"
+ | Vyos1x.Util.Syntax_error (opt, msg) ->
+ begin
+ match opt with
+ | None ->
+ let out = Printf.sprintf "Parse error: %s\n" msg
+ in Error out
+ | Some (line, pos) ->
+ let out = Printf.sprintf "Parse error: %s line %d pos %d\n" msg line pos
+ in Error out
+ end
(** Load the appliance configuration file or the fallback config *)
let load_config_failsafe main fallback =
@@ -99,10 +116,10 @@ let load_config_failsafe main fallback =
(* Load interface definitions from a directory into a reference tree *)
let load_interface_definitions dir =
- let open Reference_tree in
+ let open Vyos1x.Reference_tree in
let relative_paths = FileUtil.ls dir in
let absolute_paths =
- try Ok (List.map Util.absolute_path relative_paths)
+ try Ok (List.map Vyos1x.Util.absolute_path relative_paths)
with Sys_error no_dir_msg -> Error no_dir_msg
in
let load_aux tree file =
@@ -114,3 +131,10 @@ let load_interface_definitions dir =
| Error msg -> Error msg end
with Bad_interface_definition msg -> Error msg
+module I = Vyos1x.Internal.Make(Vyos1x.Reference_tree)
+
+let read_reference_tree file =
+ try
+ let reftree = I.read_internal file in
+ Ok reftree
+ with Sys_error msg -> Error msg